From 180d6b13c6794a0bbb209df023301701cda15158 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 12 Jun 2024 09:39:20 -0700 Subject: Fix duplicate SPIRV decorations. (#4346) * Fix duplicate `DescriptorSet` decorations. * Fix duplicate `Block` decoration. --- source/slang/slang-emit-spirv.cpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 10c263793..df60feecf 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2139,6 +2139,7 @@ struct SPIRVEmitContext { bool needDefaultSetBindingDecoration = false; bool hasExplicitSetBinding = false; + bool isDescirptorSetDecorated = false; for (auto rr : layout->getOffsetAttrs()) { UInt index = rr->getOffset(); @@ -2200,32 +2201,40 @@ struct SPIRVEmitContext nullptr, varInst, SpvLiteralInteger::from32(int32_t(index))); - if (space) + if (!isDescirptorSetDecorated) + { + if (space) + { + emitOpDecorateDescriptorSet( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + varInst, + SpvLiteralInteger::from32(int32_t(space))); + isDescirptorSetDecorated = true; + } + else + { + needDefaultSetBindingDecoration = true; + } + } + break; + case LayoutResourceKind::RegisterSpace: + if (!isDescirptorSetDecorated) { emitOpDecorateDescriptorSet( getSection(SpvLogicalSectionID::Annotations), nullptr, varInst, - SpvLiteralInteger::from32(int32_t(space))); + SpvLiteralInteger::from32(int32_t(index))); + hasExplicitSetBinding = true; + isDescirptorSetDecorated = true; } - else - { - needDefaultSetBindingDecoration = true; - } - break; - case LayoutResourceKind::RegisterSpace: - emitOpDecorateDescriptorSet( - getSection(SpvLogicalSectionID::Annotations), - nullptr, - varInst, - SpvLiteralInteger::from32(int32_t(index))); - hasExplicitSetBinding = true; break; default: break; } } - if (needDefaultSetBindingDecoration && !hasExplicitSetBinding) + if (needDefaultSetBindingDecoration && !hasExplicitSetBinding && !isDescirptorSetDecorated) { emitOpDecorateDescriptorSet( getSection(SpvLogicalSectionID::Annotations), -- cgit v1.2.3