diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index b409ba3fbd..d9c6895328 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1836,7 +1836,7 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, break; } } - if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_6 && needSizeId) { + if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_2 && needSizeId) { std::vector dimConstId; for (int dim = 0; dim < 3; ++dim) { bool specConst = (glslangIntermediate->getLocalSizeSpecId(dim) != glslang::TQualifier::layoutNotSet); @@ -1844,7 +1844,6 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, if (specConst) { builder.addDecoration(dimConstId.back(), spv::Decoration::SpecId, glslangIntermediate->getLocalSizeSpecId(dim)); - needSizeId = true; } } builder.addExecutionModeId(shaderEntry, spv::ExecutionMode::LocalSizeId, dimConstId); @@ -1984,7 +1983,7 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, break; } case EShLangTask: - case EShLangMesh: + case EShLangMesh: { if(isMeshShaderExt) { builder.addCapability(spv::Capability::MeshShadingEXT); builder.addExtension(spv::E_SPV_EXT_mesh_shader); @@ -1992,7 +1991,14 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, builder.addCapability(spv::Capability::MeshShadingNV); builder.addExtension(spv::E_SPV_NV_mesh_shader); } - if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_6) { + bool needSizeId = false; + for (int dim = 0; dim < 3; ++dim) { + if ((glslangIntermediate->getLocalSizeSpecId(dim) != glslang::TQualifier::layoutNotSet)) { + needSizeId = true; + break; + } + } + if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_2 && needSizeId) { std::vector dimConstId; for (int dim = 0; dim < 3; ++dim) { bool specConst = (glslangIntermediate->getLocalSizeSpecId(dim) != glslang::TQualifier::layoutNotSet); @@ -2024,7 +2030,7 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion, builder.addExecutionMode(shaderEntry, (spv::ExecutionMode)mode); } break; - + } default: break; } diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 845020afa2..738eb53bc9 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -7202,17 +7202,21 @@ void TParseContext::setLayoutQualifier(const TSourceLoc& loc, TPublicType& publi return; } if (spvVersion.spv != 0) { - if (id == "local_size_x_id") { - publicType.shaderQualifiers.localSizeSpecId[0] = value; - return; - } - if (id == "local_size_y_id") { - publicType.shaderQualifiers.localSizeSpecId[1] = value; - return; - } - if (id == "local_size_z_id") { - publicType.shaderQualifiers.localSizeSpecId[2] = value; - return; + static const char * const specIds[] = { + "local_size_x_id", + "local_size_y_id", + "local_size_z_id", + }; + + for (std::size_t i = 0; i < std::size(specIds); i++) { + if (id == specIds[i]) { + if (spvVersion.spv >= glslang::EShTargetSpv_1_2) + publicType.shaderQualifiers.localSizeSpecId[i] = value; + else + error(loc, "requires SPIR-V 1.2", id.c_str(), ""); + + return; + } } } }