Sign in to follow this  
robotech_er

how to debug glsl shader

Recommended Posts

Hi, I need some help on debugging glsl shader.

I spent some time on the glsl debuggers listed on the wiki, and found that glsldevil is right one i need, the only one can show current values of [color=#273D49][font=arial]variables in shader at runtime.[/font][/color]

However, glsldevil is not stable enough, and I have gone many dejected crashes.

So, everyone, any ideas to debug glsl? and I wonder how do the glsl veterans debug their shaders?

thanks in advance!!

Share this post


Link to post
Share on other sites
There aren't much tools for OpenGL as there is for Direct3D.
For OpenGL, you can write the value computed in your fragment shader to gl_FragColor.
You can even bind a FBO with a format of GL_RGBAF32 to get the full range of floating point values.

Share this post


Link to post
Share on other sites
Most shader debugging i've done is with "printf debugging" - that is, exiting early from the shader and returning some debug value that you can visualize to figure out what's up. Then just work your way through the shader until you figure out which calculation isn't returning what you expect, and go from there

This works better if you can hot-reload the shader while the game is running

Share this post


Link to post
Share on other sites
Thanks V-man and RDragon1. But how to do with vertex and geometry shader? it seems not convenient to directly write some thing visible in vs and gs. Is transform feedback a possible method?

Share this post


Link to post
Share on other sites
[quote name='robotech_er' timestamp='1310836214' post='4836048']
Is transform feedback a possible method?
[/quote]
Yes it is. In fact, that's what glslDevil uses AFAIK.

Another possibility is to channel the VS/GS data under investigation to a special debug fragment shader, which can then write the results into an FP32 target. Sometimes the geometry can be rendered as points in order to avoid problems with the interpolators of the rasterizer. Or a flat rasterization mode can be selected.

Share this post


Link to post
Share on other sites
If you are running on windows you could always look up some tools from NV or AMD depending on who made your GPU.

gDEBugger might also be an option regardless of what graphics card you are using (AMD recently brought it and integrated it into Visual Studio 2010), but I've not tried it recently myself so I don't know how well it'll do the job.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this