'Is it faster to read from metal texture2D<float> or sample from it?
I am interested in processing a 2d image pixel-wise and need the fastest way to read pixel values from the image on metal as a texture2d. Is it faster to sample from the texture or directly read from it. Reading would require coordinate conversion from float2 to uint2 but if it doesn't need interpolation, that's certainly preferable.
Which is faster, sample or read? Also, what's the best sampler to use in this context?
Thanks a lot!
Solution 1:[1]
Sampling a texture, especially if it has mipmaps, can lead to a number of it’s texels read from memory, so it sounds like read should be faster. But at the same time, if your sampling locations are coherent, you will be hitting the same texels, which will be cached. Sampling also involves some averaging that needs to be done. But, the best way to answer the question which is faster is to measure. You can try to use Metal System Trace or Xcode GPU Debugger for that.
If you are processing texture pixel by pixel, I would suggest reading it instead of sampling for correctness purposes.
If you are on a TBDR device you can also use tile dispatches to run a thread per each pixel of an attachment
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JustSomeGuy |
