Просмотр исходного кода

[spirv] support non-existing header file include (#3167)

Jaebaek Seo 4 лет назад
Родитель
Сommit
b793c337a3

+ 15 - 8
tools/clang/lib/SPIRV/EmitVisitor.cpp

@@ -521,14 +521,21 @@ bool EmitVisitor::visit(SpirvSource *inst) {
       }
     }
 
-    // Note: in order to improve performance and avoid multiple copies, we
-    // encode this (potentially large) string directly into the debugFileBinary.
-    const auto &words = string::encodeSPIRVString(firstSnippet.getValue());
-    const auto numWordsInInstr = curInst.size() + words.size();
-    curInst[0] |= static_cast<uint32_t>(numWordsInInstr) << 16;
-    debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
-                           curInst.end());
-    debugFileBinary.insert(debugFileBinary.end(), words.begin(), words.end());
+    if (firstSnippet.hasValue()) {
+      // Note: in order to improve performance and avoid multiple copies, we
+      // encode this (potentially large) string directly into the
+      // debugFileBinary.
+      const auto &words = string::encodeSPIRVString(firstSnippet.getValue());
+      const auto numWordsInInstr = curInst.size() + words.size();
+      curInst[0] |= static_cast<uint32_t>(numWordsInInstr) << 16;
+      debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
+                             curInst.end());
+      debugFileBinary.insert(debugFileBinary.end(), words.begin(), words.end());
+    } else {
+      curInst[0] |= static_cast<uint32_t>(curInst.size()) << 16;
+      debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),
+                             curInst.end());
+    }
   } else {
     curInst[0] |= static_cast<uint32_t>(curInst.size()) << 16;
     debugFileBinary.insert(debugFileBinary.end(), curInst.begin(),

+ 15 - 0
tools/clang/test/CodeGenSPIRV/spirv.debug.source.non.existing.file.hlsl

@@ -0,0 +1,15 @@
+// Run: %dxc -T ps_6_0 -E main -Zi
+
+// CHECK: OpString "non_existing_file.txt"
+
+#line 1 "non_existing_file.txt"
+
+struct PSInput
+{
+  float4 color : COLOR;
+};
+
+float4 main(PSInput input) : SV_TARGET
+{
+  return input.color;
+}

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

@@ -1559,6 +1559,9 @@ TEST_F(FileTest, SpirvLegalizationTextureBuffer) {
 TEST_F(FileTest, SpirvDebugOpSource) {
   runFileTest("spirv.debug.opsource.hlsl");
 }
+TEST_F(FileTest, SpirvDebugOpSourceNonExistingFile) {
+  runFileTest("spirv.debug.source.non.existing.file.hlsl");
+}
 
 TEST_F(FileTest, SpirvDebugOpLine) { runFileTest("spirv.debug.opline.hlsl"); }
 TEST_F(FileTest, SpirvDebugOpLineBranch) {