Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: debugging GLSL shaders

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Oct 2012
    Posts
    41

    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

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    302
    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.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    578
    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:
    1. Decide which values you wish to see per-pixel, N
    2. Decide how many such values you wish to store per pixel, T
    3. make 2d-texture array of N*T layers
    4. make a single uint8 texture
    5. 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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •