debugging GLSL shaders

hi

what’s the best way to debug values with a shader? For example , let’s say my vertex shader only had a simple line gl_Position=gl_Vertex;

And I wanted to see what the value was in gl_Position

I am using opengl , Visual Studio 8, Windows OS.

There doesn’t seem to be a good debugger out there and everyone mentions some sort of coding hack. Can someone give me a good example of how to acheive this using a coding hack/technique (preferably code examples) so i can see the values in shader variables?

It’s really hard to debug complex shaders without knowing what values you are seeing per line.

thanks

You can use transform feedback to read gl_Position into a buffer, map that for reading, and print out the values. You can also assign temporary outputs to a vertex shader and read those back if you’re still stuck. If you have multiple vertex stages (vertex, tess c/e, geometry) you can inspect intermediate results by dropping some of the stages temporarily until you’re sure that the shader stage is producing the correct output.

It’s a bit of extra work to set up but for me at least, it’s saved a lot of time pouring through shader code.

For debugging vertex shaders, per-GL4, I would use transform feedback to capture various values, the catch is that you have a limited number of “slots” in which to save values.

For fragment shaders, your best bet is to use http://www.opengl.org/registry/specs/ARB/shader_image_load_store.txt as follows:

[ol]
[li]Decide which values you wish to see per-pixel, N[/li][li]Decide how many such values you wish to store per pixel, T[/li][li]make 2d-texture array of NT layers[/li][li]make a single uint8 texture[/li][li]when it is time to save debug values, increment via atomic op the uint8 image, which returns the integer before incrrement, call it A, and store the values you want in the 2d-image array at indices NA, NA+1,…, NA+N-1.[/li][/ol]

Yep this be a hack, and a horror memory hungry one too. I am waiting for some GL-shader tool to do this exactly to get to see those debug values, but, still waiting.