Use uv or 0 for 1x1 texture reads?

  • Posts: 177
2 years 3 months ago #1 by luluco250
Is there any notable difference between using regular coordinates or 0.0 in tex2D() when reading from a 1x1 texture?
I had heard some time ago that simple uv reads were more optimized than offset coordinates. Does that also apply to static coordinates?

And maybe someone will suggest tex2Dfetch(), that has never worked with me, throws errors on some compilers.

Please Log in or Create an account to join the conversation.

  • Posts: 1221
2 years 3 months ago #2 by Marty McFly
iirc independent texture reads (constant value as offset) are almost for free. You can try this out by reading a texture a lot of times with a loop, a) only computing the offset with the loop variable (then you have fixed coordinates) and b) by adding texcoord to it so it's dependant. Compare performance of both.

Please Log in or Create an account to join the conversation.

  • Posts: 177
2 years 3 months ago #3 by luluco250
Well after testing it there seems to be absolutely no difference, at least not in DX9. I guess I'll go with 0 since it's quicker to write.

Please Log in or Create an account to join the conversation.

  • Posts: 3740
2 years 2 months ago #4 by crosire
tex2Dfetch would technically the best solution, since it skips interpolation, which has no effect on a 1x1 texture (only in Dx10+ and OpenGL). What sort of errors do you get with it.

Please Log in or Create an account to join the conversation.

  • Posts: 177
2 years 2 months ago - 2 years 2 months ago #5 by luluco250

crosire wrote: tex2Dfetch would technically the best solution, since it skips interpolation, which has no effect on a 1x1 texture (only in Dx10+ and OpenGL). What sort of errors do you get with it.


Well ages ago when I tried to use it I got strange compiler errors, specially under OpenGL. Testing it now it works as long as the second argument is an explicit int4, if I just write 0 it doesn't work, complaining about "incorrect number of arguments to numeric-type constructor", but (int4)0 does, which is odd. This is happening under DX9, which according to you shouldn't have any effect anyway.

Please Log in or Create an account to join the conversation.

  • Posts: 3740
2 years 2 months ago #6 by crosire
tex2Dfetch works correctly in OpenGL now.

Please Log in or Create an account to join the conversation.