From 3225778615fd9d7e23fd11b71a05097d59ba0247 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Thu, 21 Mar 2024 23:41:47 +0800 Subject: [PATCH] Fix an issue of getExtBuiltins() This function is used to import SPIR-V extended instruction set. It mistakenly treated the name of SPIR-V extended instruction set as the name of SPIR-V extension. For example, when we have such code getExtBuiltins("NonSemantic.DebugBreak") 'NonSemantic.DebugBreak' is added to SPIR-V extension. Rather, the SPIR-V extension name should be 'SPV_KHR_non_semantics_info'. Therefore, we must avoid this since the name of SPIR-V extended instruction set is not necessarily equal to that of relevant SPIR-V extension. Adding a SPIR-V extension must be done by calling addExtension() explicitly outside this function. This change also fixes disassembly issues of debugBreak(). --- SPIRV/GlslangToSpv.cpp | 1 - SPIRV/disassemble.cpp | 5 +++++ .../spv.intrinsicsDebugBreak.frag.out | 22 +++++++++++++++++++ Test/spv.intrinsicsDebugBreak.frag | 9 ++++++++ gtests/Spv.FromFile.cpp | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Test/baseResults/spv.intrinsicsDebugBreak.frag.out create mode 100644 Test/spv.intrinsicsDebugBreak.frag diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index baf3fd762..1294855ae 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -10222,7 +10222,6 @@ spv::Id TGlslangToSpvTraverser::getExtBuiltins(const char* name) if (extBuiltinMap.find(name) != extBuiltinMap.end()) return extBuiltinMap[name]; else { - builder.addExtension(name); spv::Id extBuiltins = builder.import(name); extBuiltinMap[name] = extBuiltins; return extBuiltins; diff --git a/SPIRV/disassemble.cpp b/SPIRV/disassemble.cpp index 2a368b2c0..ab77610c4 100644 --- a/SPIRV/disassemble.cpp +++ b/SPIRV/disassemble.cpp @@ -80,6 +80,7 @@ enum ExtInstSet { GLSLextNVInst, OpenCLExtInst, NonSemanticDebugPrintfExtInst, + NonSemanticDebugBreakExtInst, NonSemanticShaderDebugInfo100 }; @@ -506,6 +507,8 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, extInstSet = OpenCLExtInst; } else if (strcmp("NonSemantic.DebugPrintf", name) == 0) { extInstSet = NonSemanticDebugPrintfExtInst; + } else if (strcmp("NonSemantic.DebugBreak", name) == 0) { + extInstSet = NonSemanticDebugBreakExtInst; } else if (strcmp("NonSemantic.Shader.DebugInfo.100", name) == 0) { extInstSet = NonSemanticShaderDebugInfo100; } else if (strcmp(spv::E_SPV_AMD_shader_ballot, name) == 0 || @@ -533,6 +536,8 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")"; } else if (extInstSet == NonSemanticDebugPrintfExtInst) { out << "(DebugPrintf)"; + } else if (extInstSet == NonSemanticDebugBreakExtInst) { + out << "(DebugBreak)"; } else if (extInstSet == NonSemanticShaderDebugInfo100) { out << "(" << NonSemanticShaderDebugInfo100GetDebugNames(entrypoint) << ")"; } diff --git a/Test/baseResults/spv.intrinsicsDebugBreak.frag.out b/Test/baseResults/spv.intrinsicsDebugBreak.frag.out new file mode 100644 index 000000000..d5367618b --- /dev/null +++ b/Test/baseResults/spv.intrinsicsDebugBreak.frag.out @@ -0,0 +1,22 @@ +spv.intrinsicsDebugBreak.frag +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 8 + + Capability Shader + Extension "SPV_KHR_non_semantic_info" + 1: ExtInstImport "GLSL.std.450" + 6: ExtInstImport "NonSemantic.DebugBreak" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" + ExecutionMode 4 OriginUpperLeft + Source GLSL 460 + SourceExtension "GL_EXT_spirv_intrinsics" + Name 4 "main" + 2: TypeVoid + 3: TypeFunction 2 + 4(main): 2 Function None 3 + 5: Label + 7: 2 ExtInst 6(NonSemantic.DebugBreak) 1(DebugBreak) + Return + FunctionEnd diff --git a/Test/spv.intrinsicsDebugBreak.frag b/Test/spv.intrinsicsDebugBreak.frag new file mode 100644 index 000000000..861f20ed3 --- /dev/null +++ b/Test/spv.intrinsicsDebugBreak.frag @@ -0,0 +1,9 @@ +#version 460 +#extension GL_EXT_spirv_intrinsics : enable + +spirv_instruction (extensions = ["SPV_KHR_non_semantic_info"], set = "NonSemantic.DebugBreak", id = 1) +void debugBreak(); + +void main() { + debugBreak(); +} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index bfd1ff4c1..93cf08dc3 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -418,6 +418,7 @@ INSTANTIATE_TEST_SUITE_P( "spv.int64.frag", "spv.intcoopmat.comp", "spv.intOps.vert", + "spv.intrinsicsDebugBreak.frag", "spv.intrinsicsSpirvByReference.vert", "spv.intrinsicsSpirvDecorate.frag", "spv.intrinsicsSpirvDecorateId.comp",