debugging GLSL shaders
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.
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...load_store.txt as follows:
- Decide which values you wish to see per-pixel, N
- Decide how many such values you wish to store per pixel, T
- make 2d-texture array of N*T layers
- make a single uint8 texture
- 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 N*A, N*A+1,..., N*A+N-1.
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.