• Advertisement
Sign in to follow this  

glsl Code Removal and Debugging

This topic is 462 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

How do you all generally deal with glsl code removal? Every time I have ever dealt with glsl shaders dead code removal has made debugging a pain. Unused attributes or uniforms being removed triggers asserts or debug checks when modifying or prototyping shaders. To make things worse different versions of glsl compilers will strip out dead code differently, causing different problems on different machines for debug builds. How does one usually deal with this?

Share this post


Link to post
Share on other sites
Advertisement

I just write my code to expect and tolerate missing attributes and uniforms. In Rapture, I have an ubershader system - that is, I write a vertex/fragment shader pair, and compile it multiple times with different #defines. I keep my ubershaders relatively small and focused, and have 10-20 in a project (e.g. one for skinning, one for 2D, one for particles), some ubershaders have just a single permutation, some have over 100.

 

In the context of such a system, you have to consider any listed attributes or uniforms as a list of possible attributes/uniforms. For each real OpenGL shader that is created by the ubershader system, I have to separately evaluate which attributes and uniforms are present. So if any unexpected dead code removal hides something, then it's not even an unusual case for my system to deal with.

Share this post


Link to post
Share on other sites
OK take for example there is a mismatch between attributes. Maybe we specify from C to expect a position, color and normal attribute for vertices. But we are currently tweaking the shader and not using the color attribute, so dead code removal gets rid of it. Right now I am just asserting in C upon detecting the shader only has 2 attributes. What would be a graceful way to handle this? Perhaps only bind the two attributes that were present and ignore the third, effectively wasting some memory for the color attribute in C?

Share this post


Link to post
Share on other sites

OK take for example there is a mismatch between attributes. Maybe we specify from C to expect a position, color and normal attribute for vertices. But we are currently tweaking the shader and not using the color attribute, so dead code removal gets rid of it. Right now I am just asserting in C upon detecting the shader only has 2 attributes. What would be a graceful way to handle this? Perhaps only bind the two attributes that were present and ignore the third, effectively wasting some memory for the color attribute in C?

 

Yeah, if your code is supplying three attributes, but your shader only consumes two, it's reasonable just to ignore the third unused one. It'd be appropriate to printf a performance warning or something, because it's not something you'd expect to happen in normal usage scenarios (e.g. it might only happen when you've removed chunks of shader code for debugging, but shouldn't really happen in finalized code).

Share this post


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

  • Advertisement