fix(shader): keep image mode switches valid inside loops #2124

Closed
nikhilpanchal1 wants to merge 1 commit from upstream-pr/2124 into main
nikhilpanchal1 commented 2026-10-09 09:29:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikhilpanchal1 on 2026-10-09T09:29:40Z.


What

Fixes #1921.

Runtime image mode switches can terminate inside a loop's continue construct, causing SPIR-V validation to fail. Route invalid/default and disabled-mode edges to the switch merge, with an undefined result where needed. Valid image behavior and host-side descriptor rejection are unchanged.

This stays in one emitter, with no helper function, loop-context flag or intermediate result phis. Alternative to #1964.

Tested

Linux x86_64, GCC 12.2, Release, Mesa llvmpipe 26.1.6.

  • Full build and runtime libraries; CTest: 479 passed, 27 environment skips, one pre-existing denormal failure matching baseline.
  • Read/write/atomic and indirect-loop regressions across wave32/64, SPIR-V versions and all three optimizer settings; 34 resource execution scenarios.
  • 36 cross-stage and 9 additional 64-bit atomic preparations. Validation-disabled regression passes; the same test fails with the upstream emitter.
  • Conventions, test registration and whitespace checks pass.

No physical-GPU, Windows or original-title replay. Direct-read coverage starts at SPIR-V 1.4 because of an existing 1.3 FMASK limitation.

Checklist

  • Based on current main (d9484c71).
  • No other open PR implements the same functions — #1964 overlaps
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source — none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4798608542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2124). Originally posted by [nikhilpanchal1](https://github.com/nikhilpanchal1) on 2026-10-09T09:29:40Z. --- ### What Fixes #1921. Runtime image mode switches can terminate inside a loop's continue construct, causing SPIR-V validation to fail. Route invalid/default and disabled-mode edges to the switch merge, with an undefined result where needed. Valid image behavior and host-side descriptor rejection are unchanged. This stays in one emitter, with no helper function, loop-context flag or intermediate result phis. Alternative to #1964. ### Tested Linux x86_64, GCC 12.2, Release, Mesa llvmpipe 26.1.6. - Full build and runtime libraries; CTest: 479 passed, 27 environment skips, one pre-existing denormal failure matching baseline. - Read/write/atomic and indirect-loop regressions across wave32/64, SPIR-V versions and all three optimizer settings; 34 resource execution scenarios. - 36 cross-stage and 9 additional 64-bit atomic preparations. Validation-disabled regression passes; the same test fails with the upstream emitter. - Conventions, test registration and whitespace checks pass. No physical-GPU, Windows or original-title replay. Direct-read coverage starts at SPIR-V 1.4 because of an existing 1.3 FMASK limitation. ### Checklist - [x] Based on current `main` (`d9484c71`). - [ ] No other open PR implements the same functions — #1964 overlaps - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source — none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 23:00:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T23:00:20Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#757 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1595-1596, L1602-1603, L1605-1617, L1619-1622, L1628-1630
#758 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1595-1596, L1602-1603, L1605-1617, L1619-1622, L1628-1630
#1964 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1593, L1599, L1602, L1610-1615, L1619-1622, L1629-1630
#2311 core/libs/prx/libSceAgcDriver/tests/execution/RuntimeImages.cpp L7, L15-17, L52-53
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090711937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2124#issuecomment-6090711937). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T23:00:20Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #757 | `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` [L1595-1596](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1595-L1596), [L1602-1603](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1602-L1603), [L1605-1617](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1605-L1617), [L1619-1622](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1619-L1622), [L1628-1630](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1628-L1630) | | | | #758 | `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` [L1595-1596](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1595-L1596), [L1602-1603](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1602-L1603), [L1605-1617](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1605-L1617), [L1619-1622](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1619-L1622), [L1628-1630](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1628-L1630) | | | | #1964 | `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` [L1593](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1593), [L1599](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1599), [L1602](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1602), [L1610-1615](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1610-L1615), [L1619-1622](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1619-L1622), [L1629-1630](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1629-L1630) | | | | #2311 | `core/libs/prx/libSceAgcDriver/tests/execution/RuntimeImages.cpp` [L7](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/libs/prx/libSceAgcDriver/tests/execution/RuntimeImages.cpp#L7), [L15-17](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/libs/prx/libSceAgcDriver/tests/execution/RuntimeImages.cpp#L15-L17), [L52-53](https://github.com/boykopovar/AnyPS5/blob/001124896d578e208b94f10a68ee53ecdc4e082f/core/libs/prx/libSceAgcDriver/tests/execution/RuntimeImages.cpp#L52-L53) | | |
popcoder565 commented 2026-10-10 05:21:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-10T05:21:45Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 6653457d, merged onto main bc40a6b5a together with #1960 and #1959.

  • This PR's tests pass: agc_shader_control_flow, agc_driver_runtime_images and agc_driver_runtime_images_wave64.
  • Full ctest: 609 of 609 in two of three runs. In the other, amd64_only_windows (a relinker test) segfaulted once under -j 8; it then passed 10 of 10 on its own.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094165489 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2124#issuecomment-6094165489). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-10T05:21:45Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `6653457d`, merged onto `main` bc40a6b5a together with #1960 and #1959. - This PR's tests pass: `agc_shader_control_flow`, `agc_driver_runtime_images` and `agc_driver_runtime_images_wave64`. - Full ctest: 609 of 609 in two of three runs. In the other, `amd64_only_windows` (a relinker test) segfaulted once under `-j 8`; it then passed 10 of 10 on its own. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
oneandonlydean commented 2026-10-10 05:46:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:46:48Z.


Closing: #1964 fixes #1921 the same way, came first, and has a title that gets past the stop. If this catches a case #1964 misses, a test for that case on top of #1964 is welcome.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094341098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2124#issuecomment-6094341098). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:46:48Z. --- Closing: #1964 fixes #1921 the same way, came first, and has a title that gets past the stop. If this catches a case #1964 misses, a test for that case on top of #1964 is welcome.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2124
No description provided.