Sign in to follow this  

GLSL #pragma optimize(off) has no effect.

This topic is 1775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites

#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.

Share this post


Link to post
Share on other sites

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;

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this