Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metal texture read() vs sample() performance

Tags:

ios

gpu

metal

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:

  1. Using tex2D.read() without a sampler (uses uint2 coordinates).
  2. Using tex2D.sample() with pixel coordinates (uses float2 coordinates)
  3. Using tex2D.sample() with normalized coordinates (uses float2 coordinates).

Should I expect performance differences in iOS between these options?

like image 805
ldoogy Avatar asked Oct 28 '25 12:10

ldoogy


1 Answers

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.

like image 154
Ian Ollmann Avatar answered Oct 31 '25 02:10

Ian Ollmann