Quellcode durchsuchen

[SPIR-V] Handle debugInfo for composite types across source files (#4654)

This fixes a crash when generating source debugInfo for composite types
across multiple source files.
Greg Fischer vor 3 Jahren
Ursprung
Commit
a0b1b84747

+ 15 - 2
tools/clang/lib/SPIRV/DebugTypeVisitor.cpp

@@ -54,8 +54,21 @@ SpirvDebugTypeComposite *DebugTypeVisitor::createDebugTypeComposite(
 
   RichDebugInfo *debugInfo = &spvContext.getDebugInfo().begin()->second;
   const char *file = sm.getPresumedLoc(loc).getFilename();
-  if (file)
-    debugInfo = &spvContext.getDebugInfo()[file];
+  if (file) {
+    auto &debugInfoMap = spvContext.getDebugInfo();
+    auto it = debugInfoMap.find(file);
+    if (it != debugInfoMap.end()) {
+      debugInfo = &it->second;
+    } else {
+      auto *dbgSrc = spvBuilder.createDebugSource(file);
+      setDefaultDebugInfo(dbgSrc);
+      auto dbgCompUnit = spvBuilder.createDebugCompilationUnit(dbgSrc);
+      setDefaultDebugInfo(dbgCompUnit);
+      debugInfo =
+          &debugInfoMap.insert({file, RichDebugInfo(dbgSrc, dbgCompUnit)})
+               .first->second;
+    }
+  }
   return spvContext.getDebugTypeComposite(
       type, name, debugInfo->source, line, column,
       /* parent */ debugInfo->compilationUnit, linkageName, 3u, tag);

+ 30 - 0
tools/clang/test/CodeGenSPIRV/shader.debug.file.composite.hlsl

@@ -0,0 +1,30 @@
+// RUN: %dxc -E MainPs -T ps_6_0 -fspv-target-env=vulkan1.1 -fspv-debug=vulkan-with-source
+
+// Just check that compilation completes
+// CHECK: %MainPs = OpFunction %void None
+
+#line 43 "lpv_debug.fxc"
+struct PS_INPUT
+{
+
+    float3 vPositionWithOffsetWs : TEXCOORD0 ;
+
+} ;
+
+#line 430 "csgo_common_ps_code.fxc"
+struct PS_OUTPUT
+{
+    float4 vColor : SV_Target0 ;
+} ;
+
+#line 135 "lpv_debug_grid.vfx"
+PS_OUTPUT MainPs ( PS_INPUT i )
+{
+    float3 v = i . vPositionWithOffsetWs ;
+
+    PS_OUTPUT o ;
+    o . vColor . rgba = float4 ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
+    return o ;
+
+}
+

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -3146,6 +3146,9 @@ TEST_F(FileTest, ShaderDebugInfoLineBranch) {
 TEST_F(FileTest, ShaderDebugInfoLineComposite) {
   runFileTest("shader.debug.line.composite.hlsl");
 }
+TEST_F(FileTest, ShaderDebugInfoFileComposite) {
+  runFileTest("shader.debug.file.composite.hlsl");
+}
 TEST_F(FileTest, ShaderDebugInfoLineInclude) {
   runFileTest("shader.debug.line.include.hlsl");
 }