From bcbe33ad11512b67662490ecddec16b6aa342836 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 12 Jan 2023 12:41:19 +0100 Subject: [PATCH] Also consider NonSemantic ExtInst in block_is_noop. --- .../comp/loop-resolve-debug-semantics.gV.comp | 14 ++--------- spirv_common.hpp | 3 ++- spirv_cross.cpp | 24 ++++++++++++------- spirv_glsl.cpp | 3 ++- spirv_parser.cpp | 2 ++ 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/reference/shaders-no-opt/comp/loop-resolve-debug-semantics.gV.comp b/reference/shaders-no-opt/comp/loop-resolve-debug-semantics.gV.comp index 0d72cc1d..8b6a0321 100644 --- a/reference/shaders-no-opt/comp/loop-resolve-debug-semantics.gV.comp +++ b/reference/shaders-no-opt/comp/loop-resolve-debug-semantics.gV.comp @@ -8,19 +8,9 @@ layout(binding = 0, std430) buffer SSBO void main() { - int i = 0; - for (;;) + for (int i = 0; i < 4; i++) { - if (i < 4) - { - _64.v[i] += 10; - i++; - continue; - } - else - { - break; - } + _64.v[i] += 10; } } diff --git a/spirv_common.hpp b/spirv_common.hpp index 71b1eada..ba420e1d 100644 --- a/spirv_common.hpp +++ b/spirv_common.hpp @@ -644,7 +644,8 @@ struct SPIRExtension : IVariant SPV_AMD_shader_trinary_minmax, SPV_AMD_gcn_shader, NonSemanticDebugPrintf, - NonSemanticShaderDebugInfo + NonSemanticShaderDebugInfo, + NonSemanticGeneric }; explicit SPIRExtension(Extension ext_) diff --git a/spirv_cross.cpp b/spirv_cross.cpp index e55de88c..a126c287 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -1481,18 +1481,26 @@ bool Compiler::block_is_noop(const SPIRBlock &block) const switch (op) { // Non-Semantic instructions. - case OpNop: - case OpSourceContinued: - case OpSource: - case OpSourceExtension: - case OpName: - case OpMemberName: - case OpString: case OpLine: case OpNoLine: - case OpModuleProcessed: break; + case OpExtInst: + { + auto *ops = stream(i); + auto ext = get(ops[2]).ext; + + bool ext_is_nonsemantic_only = + ext == SPIRExtension::NonSemanticShaderDebugInfo || + ext == SPIRExtension::SPV_debug_info || + ext == SPIRExtension::NonSemanticGeneric; + + if (!ext_is_nonsemantic_only) + return false; + + break; + } + default: return false; } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 19ad07e7..6ec2c7a6 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -13320,7 +13320,8 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) emit_spv_amd_gcn_shader_op(ops[0], ops[1], ops[3], &ops[4], length - 4); } else if (ext == SPIRExtension::SPV_debug_info || - ext == SPIRExtension::NonSemanticShaderDebugInfo) + ext == SPIRExtension::NonSemanticShaderDebugInfo || + ext == SPIRExtension::NonSemanticGeneric) { break; // Ignore SPIR-V debug information extended instructions. } diff --git a/spirv_parser.cpp b/spirv_parser.cpp index 39bd1adf..01c2e381 100644 --- a/spirv_parser.cpp +++ b/spirv_parser.cpp @@ -295,6 +295,8 @@ void Parser::parse(const Instruction &instruction) spirv_ext = SPIRExtension::NonSemanticDebugPrintf; else if (ext == "NonSemantic.Shader.DebugInfo.100") spirv_ext = SPIRExtension::NonSemanticShaderDebugInfo; + else if (ext.find("NonSemantic.") == 0) + spirv_ext = SPIRExtension::NonSemanticGeneric; set(id, spirv_ext); // Other SPIR-V extensions which have ExtInstrs are currently not supported.