Keep unused shader variables for debugging?

I am trying to home in on an error in my shader by commented out code, but as I do this the unused shader variables are then not found by my glUniform location variables, and this makes it difficult to proceed.

Is there a way to turn off this shader optimization for debugging? I was hoping #pragma optimize(off) would do it, but I am still getting the same issue…

??

In the same situation I used the unused shader variable for outputing Alpha channel of my render target.
In my case Alpha channel is not required.

sampler2D UnusedTexture;
VS_OUTPUT main( VS_INPUT IN )
{
VS_OUTPUT OUT;
Out.color.a = text2D( UnusedTexture, IN.texture0 );
}

If u have a channel which is not required for ur output, then u can follow this work around.

Yeah, thanks. Thats about where I’m at too, the old:

Out.color = col + 0.000001*(val1 + val2 + val3 + …);

just to keep the variables active!!

Or you can use a condition which is always true or false, but which can be optimized directly by the compiler.

For instance :


uniform vec3 aNormalizedVector;

if(aNormalizedVector.z<2)
{
 run your test here
 return;
}

your regular code is here

but as I do this the unused shader variables are then not found by my glUniform location variables, and this makes it difficult to proceed.

Calling glUniform with -1 (the value returned from glGetUniformLocation if the uniform does not exist) is not considered an error. The command will execute and do nothing.

So there’s really no problem. Unless you have code detecting a -1 and creating an error based on that.

Or you can use a condition which is always true or false, but which can be optimized directly by the compiler.

Unless the compiler recompiles the code when you set a uniform (and apparently, they don’t do that anymore), there is no way for the compiler to know whether the branch will be taken or not. So nothing will be “optimized directly by the compiler.”

[quote=Alfonse Reinheart]

Unless the compiler recompiles the code when you set a uniform (and apparently, they don’t do that anymore), there is no way for the compiler to know whether the branch will be taken or not. So nothing will be “optimized directly by the compiler.”

My bad, I would say “can’t”

Good point. I do, indeed throw an exception here, which is the problem. I could just log an error instead. The trouble here is that I ?probably? then need to track down all my glUniform calls setting these variables? I haven’t tried to see what happens if I try to set a variable at location -1, but I am (perhaps wrongly) assuming it isn’t good!

In fact, my driver does not seem to care about setting variables at location -1 (at least it continues onward), so just logging the ‘not found’ error rather than throwing out seems to be a reasonable compromise!