Cost of textureSize


I’ve a stupid question: what is the cost of textureSize ?

My concern: if we know at compilation time the size of texture, does it worth to bake the size as a “#define” or a “const int” ?

Thanks :slight_smile:

You may be able to choose particular filtering kernels and code paths when texture sizes are known in advance. Thus not using textureSize could win in some cases.

In simpler cases where textureSize is not involved in selecting which code paths to use, I’d say it is pretty safe to assume textureSize doesn’t have a cost. There might be a partial recompilation of the program when used with different kind of textures. But that cost could be there even if you did not use textureSize.

Most cards implement textureSize as access to uniform value, so:

  • shader which uses textureSize will use one more hidden uniform
  • the cost of textureSize will be O(1), or “0” (all shaders that use samplers already use some other uniform values, uniform values are stored in the memory that is immediate to execution unit).

Thanks for those answers !