Search code examples
c++visual-studio-2017windows-10directxhlsl

How do I launch the HLSL debugger in Visual Studio 2017?


I cant find the option to launch the HLSL Debugger in Visual Studio 2017.

The Microsoft document instructs to launch it from Graphics Pipeline Stages window or Graphics Pixel History

https://msdn.microsoft.com/en-us/library/hh873197.aspx

However, I have no idea what those are or how to get to them

When I set a breakpoint in hlsl code in visual studio IDE directly, it just shows "The Breakpoint will not currently be hit" over the empty red circle. I assume I need to open the hlsl code in the hlsl debugger for it to break on the line.

I'm running a new project template DirectX 11 App(Universal Windows) in x64 debug mode and setting breakpoints in both vertex and pixel shaders.

Thanks,


Solution

    1. Make sure that your shaders are compiled with debug support - with /Zi option if you are using HLSL compiler.
    2. Make sure that DX device is created with debug enabled (D3D11_CREATE_DEVICE_DEBUG flag).
    3. Start GFX debugging session by going to Main menu -> Debug -> Graphics -> Start Graphics debugging. This will make a window asking for elevated privileges to pop up, launch your program and show diag session window with "Capture frame" button and timeline.
    4. Now make your application display desired image and capture a frame(s) of iterest using corresponding button. Captured frame screenshot will appear in the list.
    5. Close your application. This will trigger finalization (some postprocessing) of diag session which will take some time.
    6. Click on the frame name (blue) in the list of captured frames. This will open VS graphics analyzer window - this is where you actually debug graphics.
    7. In the middle there will be a (reproduced) frame render screenshot - you can click anywhere on it and at the pixel history window there should be a list of draw calls modifying that pixel. By expanding this list you should be able to locate invocation of shader of interest. It should have "Play" triangle button starting shader debugging and jumping into shader code where you can inspect variables, set breakpoints and other stuff.
    8. Alternatively on the left there will be Event list that contains all the pipeline modification and draw (marked with brush) calls. Locate a draw call of interest there and select it. In the Pipeline stages window there should be a diagram with screenshots of products of each stage with a corresponding shader link and "Play" button that starts shader debugging.