2
$\begingroup$

So I need to have a texture size for my compute shader. I found this function in GLSL to query this inside the shader:

ivec2 textureSize = imageSize(outputImage)

My question is, is this less efficient than passing the texture size as a push constant for instance?

Also is there an increased cost if for instance I put this inside a loop and call it multiple times in the same shader invocation?

$\endgroup$

1 Answer 1

3
$\begingroup$

In order for the GPU to work with textures through samplers, the driver needs to know the textures dimensions, and a good implementation will be able to access those dimension much more easily/quickly then passing them around in buffers or as push constants. If the shader is already accessing the texture then those values should be sitting in the cache or a register.

Based on that I would always use the shader function and would only change to another method if profiling data showed otherwise. (It is always best to profile, blanket statements about performance are almost always wrong for some implementation)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.