View Full Version : Cost of textureSize

10-31-2011, 06:42 AM

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 :)

10-31-2011, 07:04 AM
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.

10-31-2011, 09:05 AM
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).

11-01-2011, 02:33 PM
Thanks for those answers !