fix(recompiler): give a loop's exit-tail branch a selection merge #275
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/275"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-01T21:36:33Z.
What
A conditional inside a loop with one target in the loop body and the other outside it is taken for a break and emitted without a merge. When the outside target is not the loop's merge but a tail of blocks that reaches it, SPIR-V has no construct for that branch:
spirv-valrejects the module ("Selection must be structured") and the driver is free to compile it into anything.Such a branch now merges at its in-body target when the tail is private to it: every tail block is dominated by the tail's first block, stays in the loop construct and leaves only for the loop's merge. The tail is then an
if (c) { tail; break; }, which the loop already allows.exitTailSelectionMergefinds these in the pass over loop-control conditionals, and their merges are reserved after every other construct's, so a merge block already taken leaves the branch as before.This builds on the structurizer from @boykopovar (
af2ff821) and its loop-control handling; nothing outsideStructurizer.cppchanges.Measured in PPSA21564 on my integration branch: all 13 programs whose V#s are read from GPU memory (the deferred lighting and ray-traced passes) had two such branches in their traversal loops. With this change none of the 74 dumped title programs has one, and the 209 modules of a title-to-cinematic run validate apart from three unrelated image-offset and entry-point errors.
Tested
agc_structurizer_tests(already in ctest asagc_structurizer) now also structures a loop that exits through one tail block and a loop with two exit tails, and requires every merge-less conditional to target its innermost loop's merge or continue. With the test change alone on current main it fails with "a loop exit through a tail block: block 3 branches to 4/5 without a merge, and neither is its loop's merge or continue"; with the fix it passes.ctest --test-dir build --timeout 120: 96/96 pass on current main with this branch.agc_driver_recorder_tests,agc_driver_graphics_testsandagc_structurizer_testspass when run directly.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository