fix(shader): keep Demon's Souls loop shader valid after optimization #4018

Merged
Mouhand-Kaddo merged 1 commit from upstream-pr/4018 into main 2026-10-12 04:29:22 +00:00
Mouhand-Kaddo commented 2026-10-11 21:28:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T21:28:36Z.


What

Demon's Souls (PPSA01342 v1.04) registers a compute shader that passes initial SPIR-V validation but fails after optimization. Captured on Windows main 0a8b1d32b with SPIRV-Tools enabled, and reproduced against current main 14a7e64dc:

[Shaders/ShaderRegistry.cpp:747 operator()] Shader 0x2488a8f00 could not be prepared after registration:
ShaderRecompiler::Recompile: SPIR-V validation after optimization failed:
level=2 word=508: The continue construct with the continue target '26[%26]' is not structurally post dominated by the back-edge block '45299[%45299]'

For a loop that branches back to its own instruction block, give its back edge a dedicated empty continue block. Isolating the semantic header then keeps the instruction block in the loop body. This prevents block merging from folding the continuation into the loop header when memory instructions emit nested selections. Optimization and validation remain enabled.

The regression recompiles a synthetic loop containing a buffer store for 32- and 64-lane subgroups, checks structured control flow, and compares guest instruction executions before and after structurization.

Overlap checked across open, merged and closed PRs. #1964 and closed #2311 address terminating image paths before optimization. Current main includes #2471 and still fails both this captured shader and the new synthetic regression after optimization; its handling of inner-loop latches is retained.

Tested

Windows 11, Radeon RX 6900 XT, MinGW GCC 15.2, Release, pinned SPIRV-Tools enabled:

  • Current-main construction: both the new synthetic regression and the private captured game shader fail with the continue-construct error after optimization. With the change, both pass.
  • After rebase onto 14a7e64dc: shader library build passed; agc_structurizer, agc_shader_control_flow and agc_spirv_optimizer passed 3/3 (1.47 s), including the newly merged control-flow cases.
  • Before rebase, on b3ae11201 plus the change: full Windows build passed; full ctest had 841 passes, 6 skips and 2 failures out of 849 (335.89 s). agc_driver_lds_mixed_width_atomics and agc_driver_pixel_interlock failed identically with main's original loop construction and with the fix. The five focused control-flow/optimizer/driver/shader-memory tests passed.
  • Private hardware Vulkan execution probe on b3ae11201 plus the change: a loop stores the correct final value after four iterations for all 64 threads, with guest wave32 and wave64. Vulkan was required; RX 6900 XT was selected.
  • Real legal game, cold shader cache, 181-second Windows startup run on 0a8b1d32b plus this change: no repeat of the captured error; initialization did not finish before the time limit. Main menu remains unverified. This does not establish a fix for the audio crash with SPIRV-Tools disabled.
  • Conventions and git diff --check: passed. Local tests were Windows-only.

The full Windows build on current main is blocked by Socket.cpp calling the non-Windows-only HostPoll helper. Build errors were reported on #3462; this PR contains only the shader fix and regression.

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 (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822494947 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4018). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T21:28:36Z. --- ### What Demon's Souls (PPSA01342 v1.04) registers a compute shader that passes initial SPIR-V validation but fails after optimization. Captured on Windows main `0a8b1d32b` with SPIRV-Tools enabled, and reproduced against current main `14a7e64dc`: ```text [Shaders/ShaderRegistry.cpp:747 operator()] Shader 0x2488a8f00 could not be prepared after registration: ShaderRecompiler::Recompile: SPIR-V validation after optimization failed: level=2 word=508: The continue construct with the continue target '26[%26]' is not structurally post dominated by the back-edge block '45299[%45299]' ``` For a loop that branches back to its own instruction block, give its back edge a dedicated empty continue block. Isolating the semantic header then keeps the instruction block in the loop body. This prevents block merging from folding the continuation into the loop header when memory instructions emit nested selections. Optimization and validation remain enabled. The regression recompiles a synthetic loop containing a buffer store for 32- and 64-lane subgroups, checks structured control flow, and compares guest instruction executions before and after structurization. Overlap checked across open, merged and closed PRs. #1964 and closed #2311 address terminating image paths before optimization. Current main includes #2471 and still fails both this captured shader and the new synthetic regression after optimization; its handling of inner-loop latches is retained. ### Tested Windows 11, Radeon RX 6900 XT, MinGW GCC 15.2, Release, pinned SPIRV-Tools enabled: - Current-main construction: both the new synthetic regression and the private captured game shader fail with the continue-construct error after optimization. With the change, both pass. - After rebase onto `14a7e64dc`: shader library build passed; `agc_structurizer`, `agc_shader_control_flow` and `agc_spirv_optimizer` passed 3/3 (1.47 s), including the newly merged control-flow cases. - Before rebase, on `b3ae11201` plus the change: full Windows build passed; full ctest had 841 passes, 6 skips and 2 failures out of 849 (335.89 s). `agc_driver_lds_mixed_width_atomics` and `agc_driver_pixel_interlock` failed identically with main's original loop construction and with the fix. The five focused control-flow/optimizer/driver/shader-memory tests passed. - Private hardware Vulkan execution probe on `b3ae11201` plus the change: a loop stores the correct final value after four iterations for all 64 threads, with guest wave32 and wave64. Vulkan was required; RX 6900 XT was selected. - Real legal game, cold shader cache, 181-second Windows startup run on `0a8b1d32b` plus this change: no repeat of the captured error; initialization did not finish before the time limit. Main menu remains unverified. This does not establish a fix for the audio crash with SPIRV-Tools disabled. - Conventions and `git diff --check`: passed. Local tests were Windows-only. The full Windows build on current main is blocked by `Socket.cpp` calling the non-Windows-only `HostPoll` helper. Build errors were reported on [#3462](https://github.com/boykopovar/AnyPS5/pull/3462#issuecomment-6113955777); this PR contains only the shader fix and regression. ### 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 (Codex)
Kikoarl commented 2026-10-11 21:51:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-11T21:51:40Z.


Tested on Linux (CachyOS x86_64, GCC) with an NVIDIA GeForce RTX 5060 Ti (Blackwell, driver 615.78.08, Vulkan 1.4):

  • Control-flow and structurizer suites pass 100%:
    • agc_structurizer: PASSED (0.02s)
    • agc_shader_control_flow: PASSED (0.12s)
    • agc_structurizer_intersection_off: PASSED (0.02s)
    • agc_driver_scalar_program_flow: PASSED (0.23s)
  • Verified live on Astro Bot (PPSA21567): 860+ shaders compiled and cached dynamically with zero SPIR-V validation warnings or runtime regressions.
  • tools/check_conventions.py passes clean.

Validates the loop continue block isolation on NVIDIA and Linux beyond the Windows/Radeon testbed. LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114198079 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4018#issuecomment-6114198079). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-11T21:51:40Z. --- Tested on **Linux (CachyOS x86_64, GCC)** with an **NVIDIA GeForce RTX 5060 Ti (Blackwell, driver 615.78.08, Vulkan 1.4)**: - Control-flow and structurizer suites pass 100%: - `agc_structurizer`: **PASSED** (0.02s) - `agc_shader_control_flow`: **PASSED** (0.12s) - `agc_structurizer_intersection_off`: **PASSED** (0.02s) - `agc_driver_scalar_program_flow`: **PASSED** (0.23s) - Verified live on *Astro Bot* (PPSA21567): 860+ shaders compiled and cached dynamically with zero SPIR-V validation warnings or runtime regressions. - `tools/check_conventions.py` passes clean. Validates the loop continue block isolation on NVIDIA and Linux beyond the Windows/Radeon testbed. LGTM!
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!4018
No description provided.