In trying to optimize my Metal rendering performance in the fragment shader, I've noticed that there are several ways to read from a texture, depending on the scenario. I was wondering if the texture read approach has performance implications.
Here are three different alternatives I've tried:
- Using
tex2D.read()without a sampler (usesuint2coordinates). - Using
tex2D.sample()with pixel coordinates (usesfloat2coordinates) - Using
tex2D.sample()with normalized coordinates (usesfloat2coordinates).
Should I expect performance differences in iOS between these options?
They are generally similar. One might require more work than another to convert between uint2 / float2 for the coordinate, but this effect should be minor.
Read has undefined behavior for reading outside the image, so that is something to consider.