Debug HLSL with PIX

Source: Internet
Author: User

The shader debugging problem is the biggest headache for many beginners who learn DirectX. General compilers, including vs, do not support shader debugging. Fortunately, Microsoft has a pix, which is quite powerful, not just debug. Here we will summarize the debug functions.

The debugging principle of pix is very different from that of General debugging. It first runs the program and records all the shader variables, registers, and so on in each step, and then calls it out, to simulate the DirectX process.

Pay attention to the following issues before using the PIX to debug the shader code.

1 is to add the following lines of code to the HLSL function compiled by directx11 (note the bold part of the Code ):

DWORD dwshaderflags = d3dcompile_enable_strictness;

# If defined (Debug) | defined (_ Debug)

// Set the d3dcompile_debug flag to embed debug information in the shaders.

// Setting this flag improves the shader debugging experience, but still allows

// The shaders to be optimized and to run exactly the way they will run in

// The release configuration of this program.

Dwshaderflags | = d3dcompile_debug;

Dwshaderflags | = d3dcompile_skip_optimization;

# Endif

HR = d3dx11compilefromfile (L "basiceffect. HLSL", pdefines, null, szentrypoint, szshadermodel, dwshaderflags, null, null, ppblobout, & perrorblob, null );

If it is directx10, it is changed:

DWORD shaderflags = d3d10_shader_enable_strictness;

# If defined (Debug) | defined (_ Debug)

Shaderflags | = d3d10_shader_debug;

Shaderflags | = d3d10_shader_skip_optimization;

# Endif

2. Pay attention to file path issues, such as HLSL and texture. By default, these files are stored in the same folder as the EXE file. When reading these files, if the absolute path of the system is used, it is not a problem. Otherwise, the files will be put in the same folder as the exe.

Then we started to use the PIX. Open the PIX, open file-> new experiment, and select the program to debug:

Here we chose the single-frame mode to facilitate debugging.

Click Start experiment.

Open the selected program and press F12 to capture all data of the current frame. Turn off the selected program, and the PIX will automatically enter the editing and debugging mode.

Here we can choose to go to the render tab to debug a certain pixel of the current frame, or go to the mesh tab to view vertex data, including vertex data before and after entering the vertex shader, changes after entering the geometry shader (this must be viewed under the draw CILS command ).

First try to enter the mesh tab: select a draw () command and click mesh to view the data of the following vertices:

Click the prim of postvs vtx or postgs to enter the shader code for calculating this vertex or primitive. Here we select P0 under prim to enter the geometry shader state for debugging P0:

Then we can start line-by-line shader code debugging.

Let's make a summary here, and you can explore it slowly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.