From b013798e320e23b2529b1367c4af065dfc7757a3 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 15 Jul 2026 11:02:54 +0100 Subject: [PATCH] Fix some SPIR-V disassembled if()s exiting too early * If the merge block is the main body of the if that implies there is fall- through to the else case, it is more confusing but equivalent to putting the merge block as the else case as the merge block doesn't have to be after the if. --- .../driver/shaders/spirv/spirv_disassemble.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp index 600b890b4..c220c6ada 100644 --- a/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_disassemble.cpp @@ -789,6 +789,20 @@ rdcstr Reflector::Disassemble(const rdcstr &entryPoint, RDCASSERTEQUAL(nextit.opcode(), Op::Label); OpLabel decodedlabel(nextit); + // if the next label was the merge target that implies that we will eventually go from + // that flow into the other case, not a strict if/else but an if() ... + // For our purposes use the other label as merge target since that's when we will clean up the if() + if(decodedbranch.trueLabel == decodedlabel.result && + decodedbranch.trueLabel == cfg.mergeTarget) + { + cfg.mergeTarget = decodedbranch.falseLabel; + } + else if(decodedbranch.falseLabel == decodedlabel.result && + decodedbranch.falseLabel == cfg.mergeTarget) + { + cfg.mergeTarget = decodedbranch.trueLabel; + } + if(decodedbranch.trueLabel == decodedlabel.result || decodedbranch.falseLabel == decodedlabel.result) {