Skip to content

Commit c1cf56b

Browse files
committed
[SPIRV] Fix NonSemanticDebugInfo to include all files
1 parent 737a12a commit c1cf56b

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci)
654654
// Rich DebugInfo DebugSource
655655
if (spirvOptions.debugInfoRich) {
656656
auto *dbgSrc =
657-
spvBuilder.createDebugSource(mainSourceFile->getString(), source);
657+
spvBuilder.createDebugSource(mainSourceFile->getString());
658658
// spvContext.getDebugInfo().insert() inserts {string key, RichDebugInfo}
659659
// pair and returns {{string key, RichDebugInfo}, true /*Success*/}.
660660
// spvContext.getDebugInfo().insert().first->second is a RichDebugInfo.
@@ -830,17 +830,23 @@ void SpirvEmitter::HandleTranslationUnit(ASTContext &context) {
830830
return;
831831

832832
// Add source instruction(s)
833-
if ((spirvOptions.debugInfoSource || spirvOptions.debugInfoFile) &&
834-
!spirvOptions.debugInfoVulkan) {
833+
if (spirvOptions.debugInfoSource || spirvOptions.debugInfoFile) {
835834
std::vector<llvm::StringRef> fileNames;
836835
fileNames.clear();
837836
const auto &sm = context.getSourceManager();
838837
// Add each include file from preprocessor output
839838
for (unsigned int i = 0; i < sm.getNumLineTableFilenames(); i++) {
840-
fileNames.push_back(sm.getLineTableFilename(i));
839+
llvm::StringRef file = sm.getLineTableFilename(i);
840+
if (spirvOptions.debugInfoVulkan) {
841+
getOrCreateRichDebugInfoImpl(file);
842+
} else {
843+
fileNames.push_back(file);
844+
}
845+
}
846+
if (!spirvOptions.debugInfoVulkan) {
847+
spvBuilder.setDebugSource(spvContext.getMajorVersion(),
848+
spvContext.getMinorVersion(), fileNames);
841849
}
842-
spvBuilder.setDebugSource(spvContext.getMajorVersion(),
843-
spvContext.getMinorVersion(), fileNames);
844850
}
845851

846852
if (spirvOptions.enableMaximalReconvergence) {
@@ -1032,6 +1038,11 @@ RichDebugInfo *
10321038
SpirvEmitter::getOrCreateRichDebugInfo(const SourceLocation &loc) {
10331039
const StringRef file =
10341040
astContext.getSourceManager().getPresumedLoc(loc).getFilename();
1041+
return getOrCreateRichDebugInfoImpl(file);
1042+
}
1043+
1044+
RichDebugInfo *
1045+
SpirvEmitter::getOrCreateRichDebugInfoImpl(llvm::StringRef file) {
10351046
auto &debugInfo = spvContext.getDebugInfo();
10361047
auto it = debugInfo.find(file);
10371048
if (it != debugInfo.end())

tools/clang/lib/SPIRV/SpirvEmitter.h

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

7677
void doDecl(const Decl *decl);
7778
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
@@ -620,8 +620,7 @@ class DxcCompiler : public IDxcCompiler3,
620620
// pre-seeding with #line directives. We invoke Preprocess() here
621621
// first for such case. Then we invoke the compilation process over the
622622
// preprocessed source code.
623-
if (!isPreprocessing && opts.GenSPIRV && opts.DebugInfo &&
624-
!opts.SpirvOptions.debugInfoVulkan) {
623+
if (!isPreprocessing && opts.GenSPIRV && opts.DebugInfo) {
625624
// Convert source code encoding
626625
CComPtr<IDxcBlobUtf8> pOrigUtf8Source;
627626
IFC(hlsl::DxcGetBlobAsUtf8(pSourceEncoding, m_pMalloc,

0 commit comments

Comments
 (0)