PDA

View Full Version : Cost of textureSize



Kiwaiii
10-31-2011, 07:42 AM
Hi,

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

tksuoran
10-31-2011, 08: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.

anisotropic
10-31-2011, 10: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).

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