fix(shader): isolate terminating paths from loop continuations #2311
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2311"
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 JulioCacko on 2026-10-09T15:17:29Z.
What
Runtime image operations can emit terminating paths inside a guest loop's continuation. Record emitted
OpLoopMergeoffsets and move the SPIR-V continuation to a separate backedge block only when the emitted instruction range containsOpUnreachable,OpReturn,OpReturnValue,OpKill, orOpTerminateInvocation. Preserve the semantic guest CFG and patch phi predecessors to the actual block exit labels.This is a SPIR-V structural correction, not a change to RDNA instruction semantics. The rule comes from the SPIR-V specification's structured-control-flow restrictions on continue constructs: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_structured_control_flow. Tests cover patch offsets across vector growth, invalid offsets/IDs, terminating opcodes, unchanged guest instruction ranges, and a runtime image loop's three stores plus untouched exit row in wave32 and wave64.
Tested
Windows 11 x64, MinGW GCC, RelWithDebInfo, SPIRV-Tools enabled, NVIDIA GeForce RTX 3070. Focused build passed;
agc_spirv_module,agc_structurizer, andagc_driver_runtime_imagespassed 3/3 (0.15 s, 0.14 s, 0.80 s) withANYPS5_REQUIRE_VULKAN=1, no skips. The branch/title/body conventions check passed. Built and tested with the integrated contribution set on upstreamd70b8998; this branch contains only the loop correction. Synthetic regression results do not establish Demon's Souls presentation or gameplay.Checklist
main; open-PR overlap checked before submissionImported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T20:01:01Z.
Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at
fc56e7b3:/tmp/anyps5_build) with zero warnings/errors.python3 tools/check_conventions.py --base origin/main --head HEAD-> PASS (0 errors).SpirvModule.cpp,Structurizer.cpp, andRuntimeImages.cpp. Isolates terminating blocks from loop continuations, generating valid SPIR-V control flow graphs for Vulkan validation.LGTM!
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:01:59Z.
Review: CHANGES_REQUESTED
Thanks. I built it merged onto current
mainand ran the full libSceAgc/libSceAgcDriver ctest (293/293 green), but the new tests don't show the bug:tests/execution/RuntimeImages.cpp:22(RunLoop, wave32 and wave64): with the fourSpirvBackendsources reverted tomain,agc_driver_runtime_imagesstill passes on RADV. The loop it builds never yields a terminating path inside a continuation onmain, so neither the structural check (lines 53-62) nor the stored values (lines 67-74) exercise the change.tests/Structurizer.cpp:81: the PR changes nothing in the structurizer, so this case passes onmainas well and tests nothing of this PR.tests/SpirvModule.cpp(the new helpers) depends on the change, and it pins the helper API, not the failing case.Please add a case that fails on
main: a guest loop whose shader (a runtime image op, as you describe) really emitsOpUnreachable/OpKill/... in the continue block, and check it fails onmain(e.g.spirv-valon the output,ANYPS5_ENABLE_SPIRV_TOOLS, or a before/after log of the validation error on your RTX 3070). Also state which driver rejects themainSPIR-V.Smaller point:
core/libs/prx/libSceAgcDriver/CMakeLists.txt:701adds the include directory for the test outside theif(BUILD_TESTING)block and not next to the target definition; move it there.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T01:25:24Z.
Tested head
fc56e7b39159against current main2b831510be94on both platforms, with the repository's pinned SPIRV-Tools enabled:agc_structurizer,agc_spirv_module, andagc_driver_runtime_images3/3 passed, no skips (1.14 s).Both runs used the default pipeline configuration;
APS5_NO_PIPELINE_LTOwas unset.The branch needs an update for current main. For this local validation I resolved the conflicts in
SpirvModule.hppby retaining main's helper-function API alongside the new loop-patching API, and inSpirvFlowEmitter.cppby retaining main'scontinueTargethandling alongside the new instruction-range tracking. The newRunLoopfixture also needs the fifthgpuargument inGuestAllocations::Mutation().Add(...); I usedtruefor its GPU-written texture allocation. These adaptations were needed before the test results above could be obtained.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:32:43Z.
Thanks for the work. I rebased this onto current
mainand tried to get a case that fails without it:tests/execution/RuntimeImages.cpp(RunLoop): with the fourSpirvBackendsources reverted tomain, the test still passes. I also moved the image op into the latch block of a do-while loop (the continue target itself); it still passes onmain, structural check included.mainby33603bf8a("keep runtime image mode switches inside continue targets"):EmitImagereadsstate.continueTargetand doesn't emitOpUnreachablethere, so no terminating path ends up in a continue construct. This PR adds a second mechanism (separate back-edge block +OpLoopMergepatching) for the same case.SpirvModule.cpp,Structurizer.cpp) only pin the new helpers, not a failing shader.Closing as a duplicate of work already on
main. If you have a shader that still produces a terminating op inside a continue construct on currentmain(aspirv-valerror or a driver rejection, with the driver named), please reopen or open a new PR with that case as the test.Pull request closed