Visual Studio Graphics Analyzer - Skipping shader's lines of code when stepping, variables "Not in scope"

I’m using the Debug->Graphics->Start Graphics Debugging feature in Visual Studio to kick off the graphics analyzer.

My issue is that when stepping through shader code, a whole lot of variables show up as “Not in scope” when hovered over, and even more importantly perhaps is that large portions of the code are simply skipped over when stepping through code. I’m guessing that maybe there is some optimization going on which changes the flow of code? If so, it would be helpful to turn off during development/debugging if thats the case.

Workflow/info:

  • I have an empty C++ VS project setup
    to start the Unity editor when I
    start graphics debugging.
  • The shaders have the
    enable_d3d11_debug_symbols define
    enabled.
  • I capture a frame from within the VS
    graphics analyzer, then select a
    pixel to debug.
  • I drill down to the appropriate
    Pixel/Vert shader and click the
    green arrow which opens up the
    associated shader source file and
    begin debugging.

Overall, I’m using the technique described here, except I’m simply running the Unity Editor through Visual Studio instead of making a standalone build…this speeds up testing changes as I don’t need to constantly do builds to see changes.

Debugging works as expected aside from many variables not being in scope to inspect, and skipping over (sometimes) significant portions of code, but those are pretty large issues as they keep me from getting insight into how pretty big chunks of the code is working.

Any help would be greatly appreciated.

Edit

I got a response over on MSDN suggesting to pass the shader compiler the D3DCOMPILE_SKIP_OPTIMIZATION flag. I have also seen it suggested to additionally use D3DCOMPILE_PREFER_FLOW_CONTROL and D3DCOMPILE_DEBUG (although Unity’s enable_d3d11_debug_symbols may already do this one).

Does anyone know how to pass shader compiler flags in Unity? I might make a new question to directly ask this question.

Well, the Editor adds a lot of code under and on top of your game… that’s what’s probably not in-scope: editor internals. Also, at this point the Standard Shader is an ungodly amalgam of code, constantly re-arranging itself based on the needs of a particular material, so finding that certain variables are optimized out of debugging is not too surprising.

The editor definitely runs things different than a standalone build. For example, the Profiler. Most likely, that’s what you’re seeing, especially if you don’t see it during build. Unfortunately, I don’t think there is a way around this… Unity has it’s own profiler, but in my experience, it’s never been particularly good for debugging, preferring logging instead.

The bottom line is that I doubt this will work in-editor without significant work from Unity themselves, and I don’t see that happening anytime soon, but you’re welcome to submit the suggestion to their feedback website.