GLSL #pragma optimize(off) has no effect.

Started by
3 comments, last by ill 11 years, 1 month ago

As I'm developing, I like to experiment with forcing certain values in my shader code to something so I can see what's going on.

This would cause the GLSL compiler to optimize out certain uniforms making my game code itself crash, meaning if I change a tiny thing in my shader I have to comment out huge blocks in my C++ code as well, which is a nightmare.

I just want, for the sake of debugging, to disable GLSL compiler optimization. I read in many places that #pragma optimize(off) should do the trick. I place this at the top of my file but my GTX 480 still optimizes out unused uniforms.

Advertisement

#pragma optimize isn't in the spec, so probably isn't supported on your implementation.

I think the best solution will be to make your application code more robust, e.g. check to see if glGetAttribLocation() returns -1 to avoid enabling attributes that have been optimized out, etc.

As above, make your C++ code more robust tongue.png

I've been in this situation before though, where a non-robust game engine would crash due to shader changes, and the workaround that I came up with was to ensure that any uniforms that I "removed" temporarily would still contribute to the result somewhat.

e.g. finalColor.b += clamp(my_uniform,0,1)*0.001;

The other option is to use uniform buffer objects with the std140 layout, which guarantees that uniforms will never be optimized out.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Well my C++ code is built specifically to log an error and crash when I use bad parameters to help me catch bugs in the code.

I thought of another way, which I'm surprised works and isn't optimized out.

I write


max(0.0, min(0.0, uniformOrAttrGoesHere)) + 1.0 

to keep the uniform "used" but still forceable to be 1.0 if I just want to see some white pixels for example.

This topic is closed to new replies.

Advertisement