How to debug a vertex program

I’m using ARB_vertex_program extension in my program. But how do i debug a program?

Write values you want to debug to the output primary color. This will allow you to visualize the value.

Well, if the output position isn’t right, then the output color isn’t going to show up in the frame buffer.

I suggest starting with a simple multiply by MVP, a 4-instruction program taken from the extension spec. This should work. If it doesn’t, try your geometry with the fixed function pipeline as a diagnostic.

Once you have that simple step working, add the next step (say, normals, or texture coordinates, or whatever). Look at the geometry again. Then keep going. Once you have the basic gometry path working, you can put other things (tangent basis, etc) into output color (and turn off texturing) for additional debugging info.

Unfortunately, there are not good debugging tools avaliable for shaders. Granted, such tools would require a software-renderer in order to work.

Originally posted by Korval:
Unfortunately, there are not good debugging tools avaliable for shaders. Granted, such tools would require a software-renderer in order to work.

Enter Mesa3D…

Actually, the Direct3D RefRast has integration with MS Visual Studio to allow debugging of their shaders.

It’s… not fast, though. However, if you’re careful about your shaders, porting shaders between the platforms is easy, so this is a possibility if you’re really against the wall.

At some point, we’ll have GPUs capable of generating interrupts, suspend/resume, restartable instructions, etc, and can treat the GPU just like the second target machine it is. Except the AGP bus is a faster connection than the 38400 baud cable traditionally used for remote debugging :slight_smile:

At some point, we’ll have GPUs capable of generating interrupts, suspend/resume, restartable instructions, etc, and can treat the GPU just like the second target machine it is.

Sure… if you spend $4000 on nVidia’s special debugging version of their hardware. They certainly aren’t going to provide such facilities for free on all their chipsets; space on GPU’s is at a premium. That space could have gone to a useful feature or performance optimization.