Debugging

DirectX8

Microsoft DirectX 8.1 (C++)

Debugging

MFC Pixel Shader Sample Application

You can use the MFCPixelShader Sample application to learn pixel shader instructions interactively. Programmed into this application are diffuse vertex colors and two texture images. The application has five working pixel shaders that you can select by pushing the buttons in the Shaders box. It includes a view window on the left to show the rendered result, an instruction window on the right to allow users to enter instructions for validation, and a third window to view debug output.

As an example, run the application and type the following instructions in the instruction window.

ps.1.0
tex t0
mov r0, t0

This results in the Microsoft® DirectX® 5 logo image in the rendered view window.

This shader applies a texture map. Notice that the compilation result text window says Success, which indicates that all the instructions are valid.

Next, remove the second instruction, which is the texture declaration. Once this is deleted, the compilation result says:

  (Statement 2) (Validation Error) Read of uninitialized components(*) in t0: *R/X/0 *G/Y/1 *B/Z/2 *A/W/3

This error identifies the statement that fails, Statement 2, and why it fails Uninitialized component in t0. You can fix this problem by adding Statement 2 again. When you do this, the shader works again.

This is a simple example but it illustrates the usefulness of the tool. By trying different instructions, registers, and instruction sequences, you can better understand pixel shaders and vertex shaders. The sample application also has an Open button, which supports loading of a shader file so that you can load any shader files you have already created.

Shader Debuggers

Some graphics chip companies provide a shader debugging tool on their Web sites. Find these tools by searching the Web or by reading the article listed below. You can attach a debugger to a program while it is running and use the debugger to step through a shader. By setting breakpoints, you can step through the shader code one line at a time and watch register state changes. For more information about vertex shaders and debugging tips, see Using Vertex Shaders: Part 1.

Texture Blending Debugging

Another sample application that is part of the software development kit (SDK) installation is MFCTex. This Microsoft Foundation Classes (MFC) application is a good way to learn how to perform multi-texture blending operations in the fixed function pipeline.

Diagnostic Support

Another option for help with debugging DirectX problems is to use the DirectX Diagnostic Viewer (DXDiag.exe) to create a dump of your machine. This is done by running DxDiag.exe after your machine has crashed and sending the dump to Microsoft, using either the Report button on the More Help tab or by sending it to [email protected]. The dump can be used to track down and reproduce the problem.

Additional debug information can be found at http://msdn.microsoft.com/directx