fix(recompiler): let optional-body merges reach vetted ballots and wave branches in stencil replay #9394

Closed
TheSovietWaffle wants to merge 1 commit from upstream-pr/9394 into main
TheSovietWaffle commented 2026-10-21 20:23:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-21T20:23:08Z.


What

On devices without VK_EXT_shader_stencil_export, MaskReplaySafety::optionalBody refuses an EXEC- or VCC-skipped body when a merge phi is quadObserved: when the merged value reaches a sampler or LOD query, a ballot, a whole-quad mask, a lane-crossing read, shared memory, or any branch condition. The derivative case is the reason for the check (an inactive helper lane's coordinates must not change for a kept lane's implicit LOD; the existing optionalPixelBody refusals cover it).

Two of those users are already checked by the mask analysis itself, and helperObserved already treats them that way:

  • a ballot that MaskReplaySafety has restricted: its masks were proven stable (maskStable), its whole-quad expansions have their helper provenance checked (helpers), and every user of a restricted value must itself be restricted, an own-lane mask, or a reference;
  • an EXEC/VCC branch condition: every such branch goes through control().

quadObserved now skips restricted users and EXEC/VCC branch conditions, like helperObserved. It still refuses derivatives, unrestricted ballots and whole-quad masks, lane-crossing reads, shared memory, and scalar branches.

Onimusha: Way of the Sword (PPSA27836) needs this: the "lane is done" flag merged after an s_cbranch_execz body in its stencil-exporting pixel shader feeds the next s_cbranch_execz and the ballot that builds the export mask.

Tested

Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main 0c6a5bd59.

  • agc_masked_select, two new cases on the existing single-block optionalPixelBody: a merged value read only through an own-lane ballot export guard is replay-safe; the same value widened to its whole quad and used to select the stencil is still refused. On main the first fails (an optional wave body may merge a value that a vetted own-lane ballot guard reads); the second and the existing derivative refusals (... cannot change helper coordinates for later implicit samples, ... for LOD queries) pass on both.
  • The Onimusha request (shader_2111c51800, dumped with APS5_DUMP_SHADERS) checked offline with PrepareResourceProgram + StencilReplaySafe on a local stack of #8145, #9017, #9030, #9370 and #9393 (the inactiveEquals rule): with both, blocks 0 to 3 are accepted and it stops at block 8 (an early exit inside a skipped body), so no title is claimed.
  • With ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1, on main and on this change: agc_masked_select, agc_driver_sample_mask_depth_stencil, agc_driver_stencil_known_replace, agc_driver_stencil_null_feedback, agc_driver_stencil_ref_export, agc_driver_stencil_ref_export_unused, agc_driver_stencil_replay and agc_driver_stencil_replay_no_gpl pass on both GPUs below, except agc_driver_stencil_ref_export skipped on the RTX 3080 (no VK_EXT_shader_stencil_export). Results are identical on main and on this change.
  • Not run: the Khronos validation layer (not installed on this host, so VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation has nothing to load; neither log contains a VUID- line), a title.
  • tools/check_conventions.py --base origin/main and git diff --check pass. tools/pr_overlap.py was not run (no gh on this host); #9030 edits optionalBody, not quadObserved.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none (PPSA27836 #5769 needs this plus #8145, #9370, #9393 and further stencil replay changes)
  • GPUs tested: NVIDIA RTX 3080, 617.42, Windows 10 22H2; AMD Radeon RDNA 2 iGPU (1002:164e), 32.0.21045.5002, Windows 10 22H2
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4957847555 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9394). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-21T20:23:08Z. --- ### What On devices without `VK_EXT_shader_stencil_export`, `MaskReplaySafety::optionalBody` refuses an EXEC- or VCC-skipped body when a merge phi is `quadObserved`: when the merged value reaches a sampler or LOD query, a ballot, a whole-quad mask, a lane-crossing read, shared memory, or any branch condition. The derivative case is the reason for the check (an inactive helper lane's coordinates must not change for a kept lane's implicit LOD; the existing `optionalPixelBody` refusals cover it). Two of those users are already checked by the mask analysis itself, and `helperObserved` already treats them that way: - a ballot that `MaskReplaySafety` has restricted: its masks were proven stable (`maskStable`), its whole-quad expansions have their helper provenance checked (`helpers`), and every user of a restricted value must itself be restricted, an own-lane mask, or a reference; - an EXEC/VCC branch condition: every such branch goes through `control()`. `quadObserved` now skips restricted users and EXEC/VCC branch conditions, like `helperObserved`. It still refuses derivatives, unrestricted ballots and whole-quad masks, lane-crossing reads, shared memory, and scalar branches. Onimusha: Way of the Sword (PPSA27836) needs this: the "lane is done" flag merged after an `s_cbranch_execz` body in its stencil-exporting pixel shader feeds the next `s_cbranch_execz` and the ballot that builds the export mask. ### Tested Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main `0c6a5bd59`. - `agc_masked_select`, two new cases on the existing single-block `optionalPixelBody`: a merged value read only through an own-lane ballot export guard is replay-safe; the same value widened to its whole quad and used to select the stencil is still refused. On main the first fails (`an optional wave body may merge a value that a vetted own-lane ballot guard reads`); the second and the existing derivative refusals (`... cannot change helper coordinates for later implicit samples`, `... for LOD queries`) pass on both. - The Onimusha request (`shader_2111c51800`, dumped with `APS5_DUMP_SHADERS`) checked offline with `PrepareResourceProgram` + `StencilReplaySafe` on a local stack of #8145, #9017, #9030, #9370 and #9393 (the `inactiveEquals` rule): with both, blocks 0 to 3 are accepted and it stops at block 8 (an early exit inside a skipped body), so no title is claimed. - With `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`, on main and on this change: `agc_masked_select`, `agc_driver_sample_mask_depth_stencil`, `agc_driver_stencil_known_replace`, `agc_driver_stencil_null_feedback`, `agc_driver_stencil_ref_export`, `agc_driver_stencil_ref_export_unused`, `agc_driver_stencil_replay` and `agc_driver_stencil_replay_no_gpl` pass on both GPUs below, except `agc_driver_stencil_ref_export` skipped on the RTX 3080 (no `VK_EXT_shader_stencil_export`). Results are identical on main and on this change. - Not run: the Khronos validation layer (not installed on this host, so `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` has nothing to load; neither log contains a `VUID-` line), a title. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. `tools/pr_overlap.py` was not run (no `gh` on this host); #9030 edits `optionalBody`, not `quadObserved`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none (PPSA27836 #5769 needs this plus #8145, #9370, #9393 and further stencil replay changes) - [x] GPUs tested: NVIDIA RTX 3080, 617.42, Windows 10 22H2; AMD Radeon RDNA 2 iGPU (`1002:164e`), 32.0.21045.5002, Windows 10 22H2 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-21 20:39:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T20:39:21Z.


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
PR 7410 core/shader/recompiler/StencilReplay.cpp L452-453
PR 9317 core/shader/recompiler/StencilReplay.cpp L450, L452

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6879 core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326047390 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9394#issuecomment-6326047390). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T20:39:21Z. --- <!-- 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 | |---|---|---|---| | [PR 7410](https://www.github.com/boykopovar/AnyPS5/pull/7410) | `core/shader/recompiler/StencilReplay.cpp` [L452-453](https://github.com/boykopovar/AnyPS5/blob/0c6a5bd5938fde7bbc0bf720927c4584bd3e4700/core/shader/recompiler/StencilReplay.cpp#L452-L453) | | | | [PR 9317](https://www.github.com/boykopovar/AnyPS5/pull/9317) | `core/shader/recompiler/StencilReplay.cpp` [L450](https://github.com/boykopovar/AnyPS5/blob/0c6a5bd5938fde7bbc0bf720927c4584bd3e4700/core/shader/recompiler/StencilReplay.cpp#L450), [L452](https://github.com/boykopovar/AnyPS5/blob/0c6a5bd5938fde7bbc0bf720927c4584bd3e4700/core/shader/recompiler/StencilReplay.cpp#L452) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp` |
MarcZX10 commented 2026-10-22 05:48:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T05:48:36Z.

Review: CHANGES_REQUESTED


The focused red/green cases and the reported Windows NVIDIA/AMD runs are useful, and I did not find a concrete defect in the revised quadObserved checks on this head. I cannot approve it yet because several repository requirements remain unresolved:

  • This branch is based on 0c6a5bd593, while current main is 4a17c71757. Please rebase and refresh the conventions and overlap checks against current main.
  • The PR changes shader recompiler behavior, but its test report says VK_LAYER_KHRONOS_validation was unavailable, so there is no validation-layer VUID comparison. Please rerun the required paired main/change tests with ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1, and the Khronos layer enabled, and report the GPU/driver and VUID differences. The existing focused test results are valuable, but do not cover that required check.
  • Please coordinate the actual overlap with #9317, which changes the same quadObserved control/ballot logic, and #7410, which modifies the same cross-lane refusal condition. Agree on ordering/composition with those authors and update Depends on accordingly; the current checklist says none. Refresh the manual test-file comparison with #6879 after rebasing, since both touch MaskedSelect.cpp around the same test area.

The repository's hosted eligibility, conventions, intake, labels, and report checks pass. Product build jobs were skipped by CI. I did not run a local shader/GPU test in this environment. Please post the refreshed test report even if the validation layer remains unavailable, and state that limitation clearly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609781079 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9394#pullrequestreview-5609781079). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T05:48:36Z. **Review:** CHANGES_REQUESTED --- The focused red/green cases and the reported Windows NVIDIA/AMD runs are useful, and I did not find a concrete defect in the revised `quadObserved` checks on this head. I cannot approve it yet because several repository requirements remain unresolved: - This branch is based on `0c6a5bd593`, while current `main` is `4a17c71757`. Please rebase and refresh the conventions and overlap checks against current `main`. - The PR changes shader recompiler behavior, but its test report says `VK_LAYER_KHRONOS_validation` was unavailable, so there is no validation-layer VUID comparison. Please rerun the required paired main/change tests with `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1`, and the Khronos layer enabled, and report the GPU/driver and VUID differences. The existing focused test results are valuable, but do not cover that required check. - Please coordinate the actual overlap with #9317, which changes the same `quadObserved` control/ballot logic, and #7410, which modifies the same cross-lane refusal condition. Agree on ordering/composition with those authors and update `Depends on` accordingly; the current checklist says none. Refresh the manual test-file comparison with #6879 after rebasing, since both touch `MaskedSelect.cpp` around the same test area. The repository's hosted eligibility, conventions, intake, labels, and report checks pass. Product build jobs were skipped by CI. I did not run a local shader/GPU test in this environment. Please post the refreshed test report even if the validation layer remains unavailable, and state that limitation clearly.
TheSovietWaffle commented 2026-10-22 09:11:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-22T09:11:26Z.


Closing: #9317 implements the quadObserved relaxation with the exemption tied to each branch's own proof, which is stricter than this PR's blanket EXEC/VCC exemption. Details and the one extra case Onimusha needs are on #9317.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337107472 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9394#issuecomment-6337107472). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-22T09:11:26Z. --- Closing: #9317 implements the `quadObserved` relaxation with the exemption tied to each branch's own proof, which is stricter than this PR's blanket EXEC/VCC exemption. Details and the one extra case Onimusha needs are on #9317. AI-assisted: yes (Claude Code).

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!9394
No description provided.