fix(recompiler): accept whole-quad mask halves from separate expansions in stencil replay #9370

Closed
TheSovietWaffle wants to merge 1 commit from upstream-pr/9370 into main
TheSovietWaffle commented 2026-10-21 19:31:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-21T19:31:09Z.


What

On devices without VK_EXT_shader_stencil_export, MaskReplaySafety accepts an own-lane mask built from WqmU64 only when both 32-bit halves are extracted from the same WqmU64 value. Onimusha: Way of the Sword (PPSA27836) has a stencil-exporting pixel shader that expands the same mask twice: once for the low word and once for the high word, each with its own Ballot(true) / WqmU64. The two expansions are identical but are separate IR values, so the mask was refused.

A quad never straddles bit 32, so the low half of WQM(m1) depends only on m1's low word, and the high half of WQM(m2) only on m2's high word. The pair is therefore WQM(m1.low, m2.high). wqmHalves() now matches that shape (and the same-value shape as before, which is the case m1 == m2):

  • maskStable requires both source masks to be replay-stable in full, so every value feeding either expansion is still checked and restricted, including the half that is dropped;
  • helper provenance (helpers) is checked on the halves actually used, (m1.low, m2.high).

Wave32 behaves as before: only the low half is read.

This is one of several gaps the Onimusha shader hits (it also needs #8145, and further changes after this one), so no title is claimed to be unblocked.

Tested

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

  • agc_masked_select, three new cases: a stencil export selected by a whole-quad mask whose low half comes from one expansion of the predicate and whose high half from a second expansion is replay-safe; the same with a helper-dependent mask in only the high half, or only the low half, is refused. On main the first fails (stencil replay admits whole-quad mask halves taken from separate expansions of one mask) and the two refusals pass, as expected.
  • The Onimusha request (shader_2111c51800, dumped with APS5_DUMP_SHADERS) checked offline with PrepareResourceProgram + StencilReplaySafe on a local stack of #8145, #9017, #9030 and this change: without this change it stops at an own-lane mask (CompositeExtractU64 halves of two different WqmU64 values); with it, every own-lane mask is accepted and it stops at the next gap (the optional body behind block 0's s_cbranch_execz).
  • 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); #9017 and #9030 touch the same file in helpers() and optionalBody(), not these branches.

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 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:4957218334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9370). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-21T19:31:09Z. --- ### What On devices without `VK_EXT_shader_stencil_export`, `MaskReplaySafety` accepts an own-lane mask built from `WqmU64` only when both 32-bit halves are extracted from the same `WqmU64` value. Onimusha: Way of the Sword (PPSA27836) has a stencil-exporting pixel shader that expands the same mask twice: once for the low word and once for the high word, each with its own `Ballot(true)` / `WqmU64`. The two expansions are identical but are separate IR values, so the mask was refused. A quad never straddles bit 32, so the low half of `WQM(m1)` depends only on `m1`'s low word, and the high half of `WQM(m2)` only on `m2`'s high word. The pair is therefore `WQM(m1.low, m2.high)`. `wqmHalves()` now matches that shape (and the same-value shape as before, which is the case `m1 == m2`): - `maskStable` requires both source masks to be replay-stable in full, so every value feeding either expansion is still checked and restricted, including the half that is dropped; - helper provenance (`helpers`) is checked on the halves actually used, `(m1.low, m2.high)`. Wave32 behaves as before: only the low half is read. This is one of several gaps the Onimusha shader hits (it also needs #8145, and further changes after this one), so no title is claimed to be unblocked. ### Tested Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main `1896871ba`. - `agc_masked_select`, three new cases: a stencil export selected by a whole-quad mask whose low half comes from one expansion of the predicate and whose high half from a second expansion is replay-safe; the same with a helper-dependent mask in only the high half, or only the low half, is refused. On main the first fails (`stencil replay admits whole-quad mask halves taken from separate expansions of one mask`) and the two refusals pass, as expected. - The Onimusha request (`shader_2111c51800`, dumped with `APS5_DUMP_SHADERS`) checked offline with `PrepareResourceProgram` + `StencilReplaySafe` on a local stack of #8145, #9017, #9030 and this change: without this change it stops at an own-lane mask (`CompositeExtractU64` halves of two different `WqmU64` values); with it, every own-lane mask is accepted and it stops at the next gap (the optional body behind block 0's `s_cbranch_execz`). - 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); #9017 and #9030 touch the same file in `helpers()` and `optionalBody()`, not these branches. ### 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 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 19:52:36 +00:00 (Migrated from github.com)

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


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 9266 core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp L1068
core/shader/recompiler/StencilReplay.cpp L190-201, L288-297
PR 9317 core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp L1068
core/shader/recompiler/StencilReplay.cpp L190-201, L288-297

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:6325135070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9370#issuecomment-6325135070). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T19:52:36Z. --- <!-- 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 9266](https://www.github.com/boykopovar/AnyPS5/pull/9266) | `core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp` [L1068](https://github.com/boykopovar/AnyPS5/blob/3594eee9f3a2a6e41c06f827fe1443c0f58aa5ac/core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp#L1068)<br>`core/shader/recompiler/StencilReplay.cpp` [L190-201](https://github.com/boykopovar/AnyPS5/blob/3594eee9f3a2a6e41c06f827fe1443c0f58aa5ac/core/shader/recompiler/StencilReplay.cpp#L190-L201), [L288-297](https://github.com/boykopovar/AnyPS5/blob/3594eee9f3a2a6e41c06f827fe1443c0f58aa5ac/core/shader/recompiler/StencilReplay.cpp#L288-L297) | | | | [PR 9317](https://www.github.com/boykopovar/AnyPS5/pull/9317) | `core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp` [L1068](https://github.com/boykopovar/AnyPS5/blob/3594eee9f3a2a6e41c06f827fe1443c0f58aa5ac/core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp#L1068)<br>`core/shader/recompiler/StencilReplay.cpp` [L190-201](https://github.com/boykopovar/AnyPS5/blob/3594eee9f3a2a6e41c06f827fe1443c0f58aa5ac/core/shader/recompiler/StencilReplay.cpp#L190-L201), [L288-297](https://github.com/boykopovar/AnyPS5/blob/3594eee9f3a2a6e41c06f827fe1443c0f58aa5ac/core/shader/recompiler/StencilReplay.cpp#L288-L297) | | | 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 07:04:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T07:04:29Z.

Review: CHANGES_REQUESTED


I ran the focused regression on head c619555ebf58954bfd7d87ea2a680ef7966bf561:

  • Configured a Release build with cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON. The submodule checkouts used are at the exact gitlink revisions pinned by this head.
  • cmake --build build --target agc_masked_select_tests -j2: passed, including compilation of the changed StencilReplay.cpp.
  • ctest --test-dir build -R '^agc_masked_select$' --output-on-failure: passed 1/1.
  • Negative control: keeping the new test and temporarily substituting the parent commit's StencilReplay.cpp made that exact new case fail; restoring the PR source made it pass again.
  • python3 tools/check_conventions.py --base upstream/main --head refs/review/9370 and git diff --check upstream/main...HEAD: passed. Current-main merge-tree is clean.

The focused IR test supports the logic change. I could not run the required Vulkan validation comparison here: this container has no GPU device. The PR's same-machine tests on main and the change are useful, but CONTRIBUTING.md requires the focused AGC/shader tests on both with VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, then a VUID comparison. The PR explicitly says the validation layer was unavailable on its test host. Please rerun that comparison on a machine with the layer and attach the exact logs/results; the local IR test does not replace it.

Please also bring the branch up to current main (it is 514 commits behind) and refresh the overlap report. The current tools/pr_overlap.py --base main scan reports shared/conflicting test hunks with #8145 and #9017, and both MaskedSelect.cpp and StencilReplay.cpp conflicts with #9266 and #9317. I manually checked the implementation overlap: #9266 pairs structurally equivalent WQM evaluations, while this PR accepts separately expanded halves after validating each source; these are related and touch the same safety gates. #9317 is explicitly stacked on #9017, #9030 and #9266. The scan also cannot compare #6879's shared MaskedSelect.cpp; its test additions are adjacent to this PR's additions. Please coordinate merge order with those authors, preserve each test, and list any agreed prerequisites under Depends on.

Finally, the title-specific report in this PR and its test stack are for Onimusha PPSA27836 (#5769), while the checklist says Unblocks: none and the Game bring-up discussion's open-PR table does not list this change. Please reconcile that tracking with CONTRIBUTING.md: if this fixes the recorded shader stop even though another gate remains, name the title/discussion on the checklist and update the bring-up list; otherwise explain why the title-specific evidence does not count as a fix to that stop.

Current hosted conventions, eligibility, intake, labels and report checks pass. Product Linux/Windows and other relinker/platform checks are skipped, so they do not provide Vulkan or full-build validation for this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5610404431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9370#pullrequestreview-5610404431). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T07:04:29Z. **Review:** CHANGES_REQUESTED --- I ran the focused regression on head `c619555ebf58954bfd7d87ea2a680ef7966bf561`: - Configured a Release build with `cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON`. The submodule checkouts used are at the exact gitlink revisions pinned by this head. - `cmake --build build --target agc_masked_select_tests -j2`: passed, including compilation of the changed `StencilReplay.cpp`. - `ctest --test-dir build -R '^agc_masked_select$' --output-on-failure`: passed 1/1. - Negative control: keeping the new test and temporarily substituting the parent commit's `StencilReplay.cpp` made that exact new case fail; restoring the PR source made it pass again. - `python3 tools/check_conventions.py --base upstream/main --head refs/review/9370` and `git diff --check upstream/main...HEAD`: passed. Current-main merge-tree is clean. The focused IR test supports the logic change. I could not run the required Vulkan validation comparison here: this container has no GPU device. The PR's same-machine tests on main and the change are useful, but `CONTRIBUTING.md` requires the focused AGC/shader tests on both with `VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, then a VUID comparison. The PR explicitly says the validation layer was unavailable on its test host. Please rerun that comparison on a machine with the layer and attach the exact logs/results; the local IR test does not replace it. Please also bring the branch up to current `main` (it is 514 commits behind) and refresh the overlap report. The current `tools/pr_overlap.py --base main` scan reports shared/conflicting test hunks with #8145 and #9017, and both `MaskedSelect.cpp` and `StencilReplay.cpp` conflicts with #9266 and #9317. I manually checked the implementation overlap: #9266 pairs structurally equivalent WQM evaluations, while this PR accepts separately expanded halves after validating each source; these are related and touch the same safety gates. #9317 is explicitly stacked on #9017, #9030 and #9266. The scan also cannot compare #6879's shared `MaskedSelect.cpp`; its test additions are adjacent to this PR's additions. Please coordinate merge order with those authors, preserve each test, and list any agreed prerequisites under `Depends on`. Finally, the title-specific report in this PR and its test stack are for Onimusha PPSA27836 (#5769), while the checklist says `Unblocks: none` and the Game bring-up discussion's open-PR table does not list this change. Please reconcile that tracking with `CONTRIBUTING.md`: if this fixes the recorded shader stop even though another gate remains, name the title/discussion on the checklist and update the bring-up list; otherwise explain why the title-specific evidence does not count as a fix to that stop. Current hosted conventions, eligibility, intake, labels and report checks pass. Product Linux/Windows and other relinker/platform checks are skipped, so they do not provide Vulkan or full-build validation for this change.
TheSovietWaffle commented 2026-10-22 09:09:36 +00:00 (Migrated from github.com)

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


Closing in favour of #9266. I checked the Onimusha request (shader_2111c51800, PPSA27836) offline on #9317's branch (which carries #9017, #9030 and #9266) plus #8145: every own-lane mask is accepted there, including the low/high whole-quad halves this PR was written for, so #9266's structural pairing covers this shader and a second rule isn't needed.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337072871 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9370#issuecomment-6337072871). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-22T09:09:36Z. --- Closing in favour of #9266. I checked the Onimusha request (`shader_2111c51800`, PPSA27836) offline on #9317's branch (which carries #9017, #9030 and #9266) plus #8145: every own-lane mask is accepted there, including the low/high whole-quad halves this PR was written for, so #9266's structural pairing covers this shader and a second rule isn't needed. 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!9370
No description provided.