From fc6aea37483446372425aca8471f0e8bf7c3a910 Mon Sep 17 00:00:00 2001 From: amidescent <221220072+amidescent@users.noreply.github.com> Date: Sat, 9 Aug 2025 12:30:30 -0300 Subject: [SPIR-V] Emit control flags for `branch/flatten` decorations (#8134) Co-authored-by: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-emit-spirv.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 0449c6b88..aa4c3bec8 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3962,6 +3962,17 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex } } + SpvSelectionControlMask getSpvBranchSelectionControl(IRInst* inst) + { + if (inst->findDecorationImpl(kIROp_BranchDecoration)) + return SpvSelectionControlDontFlattenMask; + + if (inst->findDecorationImpl(kIROp_FlattenDecoration)) + return SpvSelectionControlFlattenMask; + + return SpvSelectionControlMaskNone; + } + // The instructions that appear inside the basic blocks of // functions are what we will call "local" instructions. // @@ -4269,7 +4280,11 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex { auto ifelseInst = as(inst); auto afterBlockID = getIRInstSpvID(ifelseInst->getAfterBlock()); - emitOpSelectionMerge(parent, nullptr, afterBlockID, SpvSelectionControlMaskNone); + emitOpSelectionMerge( + parent, + nullptr, + afterBlockID, + getSpvBranchSelectionControl(ifelseInst)); auto falseLabel = ifelseInst->getFalseBlock(); result = emitOpBranchConditional( parent, @@ -4284,7 +4299,11 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex { auto switchInst = as(inst); auto mergeBlockID = getIRInstSpvID(switchInst->getBreakLabel()); - emitOpSelectionMerge(parent, nullptr, mergeBlockID, SpvSelectionControlMaskNone); + emitOpSelectionMerge( + parent, + nullptr, + mergeBlockID, + getSpvBranchSelectionControl(switchInst)); result = emitInstCustomOperandFunc( parent, inst, -- cgit v1.2.3