fix(shader): keep runtime image mode switches inside continue targets #1964

Merged
CouchRiv merged 1 commit from upstream-pr/1964 into main 2026-10-10 06:06:24 +00:00
CouchRiv commented 2026-10-09 03:05:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T03:05:16Z.


What

Fixes #1921. A shader that samples an image inside a loop's last block can't be prepared:

ShaderRecompiler::Recompile: SPIR-V validation before optimization failed: level=2 word=5010:
The continue construct with the continue target '44[%44]' is not structurally post dominated by the back-edge block '2492[%2492]'

When an image has several runtime modes, the instruction becomes an OpSwitch over the modes. The default case, and the case of a mode turned off by specialization, end in OpUnreachable. If the instruction sits in the loop latch, that block is the SPIR-V continue target, and the OpUnreachable exits mean the back-edge block no longer post-dominates it, so spirv-val rejects the loop.

Inside a continue target, those two cases now branch to the merge with an undefined result instead, like cd158c6b already does for BDA faults there. Outside continue targets nothing changes, and an enabled mode runs as before. Both cases were already undefined behaviour with OpUnreachable, and the descriptor code never selects them.

#757 also edits this switch: it sends the image table default to the merge, but non-table images keep OpUnreachable, so the issue's stack (main + #757 + #1836) can still hit this. Whichever merges second needs a small rebase.

Tested

Linux (CachyOS), RTX 4070 Ti and Radeon 610M (RADV), SPIRV-Tools on.

  • agc_shader_memory has two new loops whose latch samples a multi-mode image, one through a 2D-array image and one through a bindless image table. Both fail on main with the error above and pass with this change.
  • Full ctest: 497/497 on NVIDIA and on RADV.
  • check_conventions.py passes.

Ghost of Yōtei (PPSA26344) from the issue was not rerun: the loops above are synthetic, so whether this was the reporter's shader still needs their rerun.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4795429334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-09T03:05:16Z. --- ### What Fixes #1921. A shader that samples an image inside a loop's last block can't be prepared: ``` ShaderRecompiler::Recompile: SPIR-V validation before optimization failed: level=2 word=5010: The continue construct with the continue target '44[%44]' is not structurally post dominated by the back-edge block '2492[%2492]' ``` When an image has several runtime modes, the instruction becomes an `OpSwitch` over the modes. The default case, and the case of a mode turned off by specialization, end in `OpUnreachable`. If the instruction sits in the loop latch, that block is the SPIR-V continue target, and the `OpUnreachable` exits mean the back-edge block no longer post-dominates it, so spirv-val rejects the loop. Inside a continue target, those two cases now branch to the merge with an undefined result instead, like cd158c6b already does for BDA faults there. Outside continue targets nothing changes, and an enabled mode runs as before. Both cases were already undefined behaviour with `OpUnreachable`, and the descriptor code never selects them. #757 also edits this switch: it sends the image table default to the merge, but non-table images keep `OpUnreachable`, so the issue's stack (`main` + #757 + #1836) can still hit this. Whichever merges second needs a small rebase. ### Tested Linux (CachyOS), RTX 4070 Ti and Radeon 610M (RADV), SPIRV-Tools on. - `agc_shader_memory` has two new loops whose latch samples a multi-mode image, one through a 2D-array image and one through a bindless image table. Both fail on `main` with the error above and pass with this change. - Full ctest: 497/497 on NVIDIA and on RADV. - `check_conventions.py` passes. Ghost of Yōtei (PPSA26344) from the issue was not rerun: the loops above are synthetic, so whether this was the reporter's shader still needs their rerun. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [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 (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-09 03:11:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:11:07Z.


The reproducer and local GPU validation are documented, but this head currently has no upstream check runs (gh pr checks reports none). CONTRIBUTING says a fork PR with an action_required workflow needs maintainer approval before CI has actually run. Could you check whether the Build/Conventions workflows are waiting for approval and request a rerun if so?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6073469663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964#issuecomment-6073469663). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T03:11:07Z. --- The reproducer and local GPU validation are documented, but this head currently has no upstream check runs (`gh pr checks` reports none). CONTRIBUTING says a fork PR with an `action_required` workflow needs maintainer approval before CI has actually run. Could you check whether the Build/Conventions workflows are waiting for approval and request a rerun if so?
MarcZX10 commented 2026-10-09 03:14:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:14:28Z.


I checked the Actions API for this exact head: Build, Conventions and Progress report are marked action_required, so upstream CI has not run. Per CONTRIBUTING, a maintainer needs to approve those workflow runs; please request that approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6073510193 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964#issuecomment-6073510193). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T03:14:28Z. --- I checked the Actions API for this exact head: Build, Conventions and Progress report are marked `action_required`, so upstream CI has not run. Per CONTRIBUTING, a maintainer needs to approve those workflow runs; please request that approval.
CouchRiv commented 2026-10-09 03:15:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T03:15:06Z.


Same as #1962: the three runs on 33603bf finished as action_required with no jobs, so CI hasn't run yet:

They need a maintainer's approval; I can't rerun them from the fork. Locally, full ctest passes 497/497 on NVIDIA and on RADV, and check_conventions.py --base origin/main passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6073518175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964#issuecomment-6073518175). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-09T03:15:06Z. --- Same as #1962: the three runs on 33603bf finished as `action_required` with no jobs, so CI hasn't run yet: - Build: https://github.com/boykopovar/AnyPS5/actions/runs/37877645348 - Conventions: https://github.com/boykopovar/AnyPS5/actions/runs/37877645327 - Progress report: https://github.com/boykopovar/AnyPS5/actions/runs/37877645341 They need a maintainer's approval; I can't rerun them from the fork. Locally, full ctest passes 497/497 on NVIDIA and on RADV, and `check_conventions.py --base origin/main` passes.
popcoder565 commented 2026-10-09 15:23:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:23:36Z.


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 33603bf8, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: agc_shader_memory, agc_shader_bindless. None of them reported skipping a case.
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083892834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964#issuecomment-6083892834). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:23:36Z. --- 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 `33603bf8`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `agc_shader_memory`, `agc_shader_bindless`. None of them reported skipping a case. - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
github-actions[bot] commented 2026-10-09 21:48:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T21:48:08Z.


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/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L419-446
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1590-1591, L1602-1603, L1605-1617, L1619-1622, L1628-1630
#758 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L419-446
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp L1590-1591, L1602-1603, L1605-1617, L1619-1622, L1628-1630
#2311 core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp L815-816, L818-819
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089816658 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964#issuecomment-6089816658). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T21:48:08Z. --- <!-- 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/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L419-446](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L419-L446)<br>`core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` [L1590-1591](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1590-L1591), [L1602-1603](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1602-L1603), [L1605-1617](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1605-L1617), [L1619-1622](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1619-L1622), [L1628-1630](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1628-L1630) | | | | #758 | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` [L419-446](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L419-L446)<br>`core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` [L1590-1591](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1590-L1591), [L1602-1603](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1602-L1603), [L1605-1617](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1605-L1617), [L1619-1622](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1619-L1622), [L1628-1630](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1628-L1630) | | | | #2311 | `core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp` [L815-816](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp#L815-L816), [L818-819](https://github.com/boykopovar/AnyPS5/blob/292ecfb0bedb025c3dbe1b140133695887417b2d/core/shader/recompiler/SpirvBackend/src/SpirvFlowEmitter.cpp#L818-L819) | | |
adriadam10 commented 2026-10-10 06:06:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:06:21Z.


Checked: build + ctest on Linux with SPIRV-Tools on; agc_shader_memory passes with this change and fails without it (both new latch cases). The Phi/dominance in the continue-target path is correct, and behaviour outside continue targets is unchanged. Windows run by @popcoder565 also passes. Merging once CI is green.

Note: the other instance reported for Astro Bot (graphics-stage program) isn't covered here and needs its own follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094490405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1964#issuecomment-6094490405). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:06:21Z. --- Checked: build + ctest on Linux with SPIRV-Tools on; `agc_shader_memory` passes with this change and fails without it (both new latch cases). The Phi/dominance in the continue-target path is correct, and behaviour outside continue targets is unchanged. Windows run by @popcoder565 also passes. Merging once CI is green. Note: the other instance reported for Astro Bot (graphics-stage program) isn't covered here and needs its own follow-up.
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!1964
No description provided.