I am wondering is there a difference in performance between using floating point textures as my 2D float4 array vs just passing in 2D float4 arrays?

2D float arrays eliminate the need to do texture look ups to get the colour value, but i am not sure if perhaps textures have some kinda performance boost on GPUs that an array would not due to what ever clever optimisations GPUs can do.


It depends on what you’re doing. If any given thread of your shader is working with data from multiple nearby pixels, like by sampling from fractional between-pixel locations or doing some calculation involving a pixel’s immediate neighbors, then you should probably use a texture: the GPU can do some caching and even load multiple values in a single operation in that case. If your threads are more independent and working on individual values, an array is fine.

  • $\begingroup$ In my case i'm not using adjacent pixels, but i do a lot texture sampling, im curious if a texture sample is more expensive than just access the float array. $\endgroup$ – user10332 Mar 22 at 22:06
  • $\begingroup$ If you’re using texture filtering—i.e. reading from somewhere other than the center of any given pixel—then using the actual texture-sampling hardware for the interpolation will be faster than reading individual values and interpolating them yourself. Otherwise, I’d use an array. $\endgroup$ – Noah Witherspoon Mar 23 at 0:00
  • 1
    $\begingroup$ Textures are optimised for accessing neighbouring pixels and are usually encoded in some space filling curve like Morton order. If you are accessing the array in a linear fashion then this optimisation will lower cache efficiency. $\endgroup$ – PaulHK Apr 23 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.