From 80f43f43466a46a5795ad44e5096d99e12c2a0da Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Wed, 16 Jul 2025 08:29:13 -0700 Subject: Strip debug info only for the SpvOpExtInst of debug import type (#7779) --- source/slang/slang-emit.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index aaefdaee0..1657a2980 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -2209,6 +2209,10 @@ SlangResult emitSPIRVFromIR( class SpirvInstructionHelper { public: + // The result id of the OpExtInstImport instruction, eg.g %2 below + // %2 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" + uint32_t m_nonSemanticDebugInfoExtSetId = 0; + // The index of the SPIRV words in the blob. // The first 5 words are the header as defined by the SPIRV spec. enum SpvWordIndex @@ -2351,6 +2355,7 @@ static SlangResult stripDbgSpirvFromArtifact( NonSemanticShaderDebugInfo100DebugNoScope, NonSemanticShaderDebugInfo100DebugInlinedAt, NonSemanticShaderDebugInfo100DebugLocalVariable, + NonSemanticShaderDebugInfo100DebugGlobalVariable, NonSemanticShaderDebugInfo100DebugInlinedVariable, NonSemanticShaderDebugInfo100DebugDeclare, NonSemanticShaderDebugInfo100DebugValue, @@ -2395,6 +2400,15 @@ static SlangResult stripDbgSpirvFromArtifact( return; } } + else if (inst.getOpCode() == SpvOpExtInstImport) + { + // looking for result id of "OpExtInstImport "NonSemantic.Shader.DebugInfo.100" + auto importName = inst.getStringFromInst(); + if (importName == "NonSemantic.Shader.DebugInfo.100") + { + spirvInstructionHelper.m_nonSemanticDebugInfoExtSetId = inst.getOperand(0); + } + } }); // Iterate over the instructions from the artifact and add them to the list @@ -2415,14 +2429,19 @@ static SlangResult stripDbgSpirvFromArtifact( foundDebugString = true; } if (!foundDebugString) + { return; + } } // Also check if the instruction is an extended instruction containing DebugInfo. if (inst.getOpCode() == SpvOpExtInst) { - // Ignore this if the instruction contains DebugInfo. - if (debugExtInstNumbers.contains(inst.getOperand(3))) + // Ignore this if the instruction contains DebugInfo and is from the debug import + if (debugExtInstNumbers.contains(inst.getOperand(3)) && + inst.getOperand(2) == spirvInstructionHelper.m_nonSemanticDebugInfoExtSetId) + { return; + } } // Otherwise this is a non-debug instruction and should be included. spirvWordsList.addRange( -- cgit v1.2.3