is it potentially hurtful to declare unused uniforms, vertex attributes and samplers in GLSL source code? I currently just include (via include files to reduce code duplication) all those that are inbuilt to my engine, in every shader, regardless of whether they are actually used by the shader code.
This is the result of me doing a pretty much 1:1 conversion from HLSL, where I know unused variables will not actually be compiled in and will not hurt.
AFAIK, the GLSL spec allows for device-specific optimization but doesn’t require it.
The assumption that this will likely be done is built into the API however. For instance, for uniforms you have: glGetActiveUniform(), which returns only those uniforms which weren’t optimized out in your shader compile/link because none of your code for that compile/link was using them.
Like you, we have lots of unused uniforms, varyings, etc. in the shader code that gets thrown at the compiler (shared included code for many ubershader permutations). Only the required stuff ends up being pulled in and runs beautifully on NVidia (haven’t really tried others in a while).
Ends up being a lot simpler/cleaner letting the compiler throw out the unused code than manage all that on the application side. Especially since "if"s based on constant expressions effectively behave like #ifs. So instead of having to do ugly stuff like this in your code:
# if OPTION2 == WHO
# elif OPTION2 == ME
you just do this:
const bool OPTION1 = false;
const int OPTION2 = WHO;
if ( OPTION1 )
if ( OPTION2 == WHO )
else if ( OPTION2 == ME )
which ends up being optimized to this:
Thanks for the answer! Yeah, I’ve as well had things running fine on NVidia & AMD hardware, but I’m still looking whether I can do something about Intel performance, and whether it’s something related to this.
Checked the active uniforms & attributes on Intel hardware, anything unused did not show up.
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.