Jump to content

  • Log In with Google      Sign In   
  • Create Account


GLSL #pragma optimize(off) has no effect.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 08 March 2013 - 08:44 PM

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.



Sponsor:

#2 johnchapman   Members   -  Reputation: 508

Like
0Likes
Like

Posted 09 March 2013 - 04:05 AM

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



#3 Hodgman   Moderators   -  Reputation: 27685

Like
1Likes
Like

Posted 09 March 2013 - 05:32 AM

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;



#4 mhagain   Crossbones+   -  Reputation: 7436

Like
0Likes
Like

Posted 09 March 2013 - 06:52 AM

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


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 09 March 2013 - 11:45 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS