Skip to content

Commit

Permalink
llpc: trim NonSemantic.Shader.DebugInfo.100
Browse files Browse the repository at this point in the history
The -trim-debug-info option should also trim this more advanced debug
info when set (which is the default).
  • Loading branch information
nhaehnle committed Nov 13, 2023
1 parent 2a6f20f commit 909e511
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions llpc/test/shaderdb/debug_info/FunctionCall.pipe
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
; RUN: amdllpc -trim-debug-info=false -filetype=asm -o - -gfxip 11.0 %s | FileCheck -check-prefixes=NOTRIM %s
; RUN: amdllpc -trim-debug-info=true -filetype=asm -o - -gfxip 11.0 %s | FileCheck -check-prefixes=TRIM %s

; Just a simple sanity check that the compiler ran through and produced *some* debug info
; NOTRIM: .loc 1 11 0 prologue_end

; TRIM-NOT: .loc
; TRIM: s_endpgm

[CsSpirv]
; Compiled with glslangValidator --target-env vulkan1.3 -gVS
; SPIR-V
Expand Down
30 changes: 24 additions & 6 deletions llpc/util/llpcShaderModuleHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ unsigned ShaderModuleHelper::trimSpirvDebugInfo(const BinaryData *spvBin, llvm::
codeBuffer = codeBuffer.drop_front(sizeof(Vkgc::SpirvHeader) / wordSize);
}

unsigned nonSemanticShaderDebug = ~0;

// Copy SPIR-V instructions
while (codePos < end) {
unsigned opCode = (codePos[0] & OpCodeMask);
unsigned wordCount = (codePos[0] >> WordCountShift);
bool skip = false;
switch (opCode) {
case OpSource:
case OpSourceContinued:
Expand All @@ -266,21 +269,36 @@ unsigned ShaderModuleHelper::trimSpirvDebugInfo(const BinaryData *spvBin, llvm::
case OpLine:
case OpNop:
case OpNoLine:
case OpModuleProcessed: {
// Skip debug instructions
case OpModuleProcessed:
skip = true;
break;
case OpExtInstImport: {
unsigned id = codePos[1];
const char *name = reinterpret_cast<const char *>(&codePos[2]);
if (!strcmp(name, "NonSemantic.Shader.DebugInfo.100")) {
nonSemanticShaderDebug = id;
skip = true;
}
break;
}
default: {
// Copy other instructions
case OpExtInst: {
unsigned set = codePos[3];
if (set == nonSemanticShaderDebug)
skip = true;
break;
}
default:
break;
}

if (!skip) {
if (writeCode) {
assert(codePos + wordCount <= end);
assert(wordCount <= codeBuffer.size());
memcpy(codeBuffer.data(), codePos, wordCount * wordSize);
codeBuffer = codeBuffer.drop_front(wordCount);
}
totalSizeInWords += wordCount;
break;
}
}

codePos += wordCount;
Expand Down

0 comments on commit 909e511

Please sign in to comment.