3
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\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$ – wduk Mar 22 '19 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 '19 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 '19 at 2:36
  • $\begingroup$ Just a follow up but by neighbours do you means pixels directly next to each other? What if you want to sample say [x,y] and [x+5,y-5] or something further away? Would arrays then be a wiser choice? $\endgroup$ – wduk Jul 12 at 2:32
  • $\begingroup$ In general the farther away your samples are the less benefit you’ll get from the spatial encoding. Within 5px I would guess a texture would still be optimal; 50px, probably not. $\endgroup$ – Noah Witherspoon Jul 13 at 19:57

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.