baldurk / renderdoc

RenderDoc is a stand-alone graphics debugging tool.
https://renderdoc.org
MIT License
8.99k stars 1.35k forks source link

Shader source attachment is no longer visible for Vulkan with Dolphin #2673

Closed Pokechu22 closed 2 years ago

Pokechu22 commented 2 years ago

Description

Captures from Dolphin have no source attachment when opened in RenderDoc v1.21, though they did in the past. This seems to be related to Dolphin not setting a source file name (see #2337), as setting one does result in it working, but this still prevents using captures from older versions of Dolphin (and older versions of RenderDoc).

diff --git a/Source/Core/VideoCommon/Spirv.cpp b/Source/Core/VideoCommon/Spirv.cpp
index 0fc22e1731..c909ee33a2 100644
--- a/Source/Core/VideoCommon/Spirv.cpp
+++ b/Source/Core/VideoCommon/Spirv.cpp
@@ -124,8 +124,9 @@ CompileShaderToSPV(EShLanguage stage, APIType api_type,
   if (g_ActiveConfig.bEnableValidationLayer)
   {
     // Attach the source code to the SPIR-V for tools like RenderDoc.
     intermediate->addSourceText(pass_source_code, pass_source_code_length);
+    intermediate->setSourceFile("Generated");

     options.generateDebugInfo = true;
     options.disableOptimizer = true;
     options.optimizeSize = false;

Steps to reproduce

  1. Launch Dolphin via RenderDoc.
  2. Under Graphics, set the backend to Vulkan on the general tab, and check "Enable API Validation Layers" on the advanced tab (which also enables source attachment, see dolphin-emu/dolphin#9996)
  3. Open the Lesson08 test case
  4. Wait for the capture to complete
  5. Stop emulation and close Dolphin
  6. In renderdoc, go to a draw, and then attempt to debug a pixel
  7. Observe that shader disassembly is present, but no source is present

This affects captures from previous versions of RenderDoc and Dolphin (including ones from some of my earlier bug reports, such as this one), not just ones saved with current Dolphin/RenderDoc.

Environment

I think this issue wasn't present in v1.20, but I'm not 100% certain of this. It definitely wasn't present in v1.19. My guess is that this is related to the "Vulkan: Don't generate an empty source file when an OpSource is encountered with no source, only a language (and/or filename)." change mentioned in v1.21's changelog.

baldurk commented 2 years ago

That should fix the issue I believe, though I would strongly suggest that you apply that diff on your side to give your files a default filename, as I wouldn't be surprised if other tools have bugs/issues around this since a file without a filename generally doesn't make sense. This is also likely to break in future in RenderDoc if you have multiple files without filenames as they'll no longer be distinguishable.

Pokechu22 commented 2 years ago

Thanks!

This is also likely to break in future in RenderDoc if you have multiple files without filenames as they'll no longer be distinguishable.

Wouldn't the same thing happen if all of the files have the exact same default filename? (For the most part, I haven't had any issue finding the right shader since I'm usually finding it by looking for a specific event and then debugging a specific pixel or vertex, so the name is irrelevant. Dolphin also has a lot of generated shaders, so looking through a big list of them wouldn't be super useful, but I imagine with more typical programs this is less of an issue.)

baldurk commented 2 years ago

To clarify I mean having multiple source files in the same SPIR-V module with the same filename would be a problem, but different modules with the same filename is totally fine (blank or not).

Pokechu22 commented 2 years ago

Done: dolphin-emu/dolphin#10945. I believe Dolphin currently only ever has one source file per module, but that is something to keep in mind.