Skip to content

Commit 5c16ae7

Browse files
[SPIRV] Fix NonSemanticDebugInfo to include all files (microsoft#6935)
Previously, we fixed the SPIRV OpenCL debug info to always represent all include files, even those that only have preprocessor definitions. This work was merged in microsoft#6094. This PR applies the same fix to the NonSemantic debug info, and resolves microsoft#6907
1 parent c0c01e9 commit 5c16ae7

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

tools/clang/lib/SPIRV/EmitVisitor.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,6 @@ void EmitVisitor::emitDebugLine(spv::Op op, const SourceLocation &loc,
385385
debugColumnEnd = columnEnd;
386386
}
387387

388-
if ((emittedSource[fileId] == 0) && (spvOptions.debugInfoVulkan)) {
389-
SpirvDebugSource *src = new (context) SpirvDebugSource(fileName, "");
390-
visit(src);
391-
spvInstructions.push_back(src);
392-
}
393-
394388
curInst.clear();
395389
if (!spvOptions.debugInfoVulkan) {
396390
curInst.push_back(static_cast<uint32_t>(spv::Op::OpLine));

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
661661

662662
// Rich DebugInfo DebugSource
663663
if (spirvOptions.debugInfoRich) {
664-
auto *dbgSrc =
665-
spvBuilder.createDebugSource(mainSourceFile->getString(), source);
664+
auto *dbgSrc = spvBuilder.createDebugSource(mainSourceFile->getString());
666665
// spvContext.getDebugInfo().insert() inserts {string key, RichDebugInfo}
667666
// pair and returns {{string key, RichDebugInfo}, true /*Success*/}.
668667
// spvContext.getDebugInfo().insert().first->second is a RichDebugInfo.
@@ -839,17 +838,23 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
839838
return;
840839

841840
// Add source instruction(s)
842-
if ((spirvOptions.debugInfoSource || spirvOptions.debugInfoFile) &&
843-
!spirvOptions.debugInfoVulkan) {
841+
if (spirvOptions.debugInfoSource || spirvOptions.debugInfoFile) {
844842
std::vector<llvm::StringRef> fileNames;
845843
fileNames.clear();
846844
const auto &sm = context.getSourceManager();
847845
// Add each include file from preprocessor output
848846
for (unsigned int i = 0; i < sm.getNumLineTableFilenames(); i++) {
849-
fileNames.push_back(sm.getLineTableFilename(i));
847+
llvm::StringRef file = sm.getLineTableFilename(i);
848+
if (spirvOptions.debugInfoVulkan) {
849+
getOrCreateRichDebugInfoImpl(file);
850+
} else {
851+
fileNames.push_back(file);
852+
}
853+
}
854+
if (!spirvOptions.debugInfoVulkan) {
855+
spvBuilder.setDebugSource(spvContext.getMajorVersion(),
856+
spvContext.getMinorVersion(), fileNames);
850857
}
851-
spvBuilder.setDebugSource(spvContext.getMajorVersion(),
852-
spvContext.getMinorVersion(), fileNames);
853858
}
854859

855860
if (spirvOptions.enableMaximalReconvergence) {
@@ -1046,6 +1051,11 @@ RichDebugInfo *
10461051
SpirvEmitter::getOrCreateRichDebugInfo(const SourceLocation &loc) {
10471052
const StringRef file =
10481053
astContext.getSourceManager().getPresumedLoc(loc).getFilename();
1054+
return getOrCreateRichDebugInfoImpl(file);
1055+
}
1056+
1057+
RichDebugInfo *
1058+
SpirvEmitter::getOrCreateRichDebugInfoImpl(llvm::StringRef file) {
10491059
auto &debugInfo = spvContext.getDebugInfo();
10501060
auto it = debugInfo.find(file);
10511061
if (it != debugInfo.end())

tools/clang/lib/SPIRV/SpirvEmitter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SpirvEmitter : public ASTConsumer {
7474
/// created, we just return RichDebugInfo containing it. Otherwise,
7575
/// create DebugSource and DebugCompilationUnit for loc and return it.
7676
RichDebugInfo *getOrCreateRichDebugInfo(const SourceLocation &loc);
77+
RichDebugInfo *getOrCreateRichDebugInfoImpl(llvm::StringRef file);
7778

7879
void doDecl(const Decl *decl);
7980
void doStmt(const Stmt *stmt, llvm::ArrayRef<const Attr *> attrs = {});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %dxc -T ps_6_0 -E main -Zi %s -spirv -fspv-debug=vulkan-with-source | FileCheck %s
2+
3+
// CHECK: [[main:%[0-9]+]] = OpString
4+
// CHECK-SAME: shader.debug.opsource.include.hlsl
5+
// CHECK: [[file1:%[0-9]+]] = OpString
6+
// CHECK-SAME: spirv.debug.opsource.include-file.hlsli
7+
// CHECK: [[file1string:%[0-9]+]] = OpString "#define UBER_TYPE(x) x ## Type
8+
// CHECK: [[mainstring:%[0-9]+]] = OpString "// RUN: %dxc -T ps_6_0 -E main -Zi %s -spirv -fspv-debug=vulkan-with-source | FileCheck %s
9+
10+
// CHECK: DebugSource [[file1]] [[file1string]]
11+
// CHECK: DebugSource [[main]] [[mainstring]]
12+
13+
#include "spirv.debug.opsource.include-file.hlsli"
14+
15+
struct ColorType
16+
{
17+
float4 position : SV_POSITION;
18+
float4 color : COLOR;
19+
};
20+
21+
float4 main(UBER_TYPE(Color) input) : SV_TARGET
22+
{
23+
return input.color;
24+
}

tools/clang/tools/dxcompiler/dxcompilerobj.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,7 @@ class DxcCompiler : public IDxcCompiler3,
610610
// pre-seeding with #line directives. We invoke Preprocess() here
611611
// first for such case. Then we invoke the compilation process over the
612612
// preprocessed source code.
613-
if (!isPreprocessing && opts.GenSPIRV && opts.DebugInfo &&
614-
!opts.SpirvOptions.debugInfoVulkan) {
613+
if (!isPreprocessing && opts.GenSPIRV && opts.DebugInfo) {
615614
// Convert source code encoding
616615
CComPtr<IDxcBlobUtf8> pOrigUtf8Source;
617616
IFC(hlsl::DxcGetBlobAsUtf8(pSourceEncoding, m_pMalloc,

0 commit comments

Comments
 (0)