fix(recompiler): let optional-body merges reach ballots that helper lanes cannot contribute to #9906

Merged
TheSovietWaffle merged 1 commit from upstream-pr/9906 into main 2026-10-27 01:28:31 +00:00
TheSovietWaffle commented 2026-10-22 21:08:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-22T21:08:47Z.


What

On devices without VK_EXT_shader_stencil_export, MaskReplaySafety::optionalBody refuses an EXEC- or VCC-skipped body when a merge phi is quadObserved. Since #9317 a merged value may reach a Ballot only when every use of that ballot funnels into a lane's own bit (ownBitBallot), which bounds what is read.

This adds the dual case, which bounds what is written: a ballot whose argument onHelper proves false on every helper lane. Helper lanes then contribute zero to every word of that ballot whatever the merged value holds on them, so its words are a function of real lanes only, and any consumer (an any-active early-exit gate, the export mask's merge phis) observes nothing about helper lanes. The exemption only applies to ballots the mask analysis has already restricted (they sit in a stable mask chain whose maskStable/helpers checks passed); any other ballot still goes through the funnel or is refused.

Onimusha: Way of the Sword (PPSA27836) needs this: after its discard, Ballot(ownLane(liveWords) && !killed) (with liveWords a ballot of non-helper lanes masked by the whole-quad active lanes) feeds both an any-active exit gate and the export mask's merge phis. @akkadbakkad89 agreed on #9317 that it should land as its own change on top of #9317.

This branch is rebased onto main 570089a80, which now carries #9317 (merged as def1f5dd9); the diff is this PR's own commit (one line in quadObserved and two test cases).

Tested

  • Rebased 2026-10-26: on this head 83d2093a9 (main 570089a80), with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1 on the RTX 3080, agc_masked_select, agc_driver_sample_mask_depth_stencil, agc_driver_stencil_known_replace, agc_driver_stencil_null_feedback, agc_driver_stencil_ref_export_unused, agc_driver_stencil_replay and agc_driver_stencil_replay_no_gpl pass and agc_driver_stencil_ref_export skips (no VK_EXT_shader_stencil_export); tools/check_conventions.py --base origin/main passes. The results below were taken on the earlier #9317 base.
    Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on #9317's head 92ebac241.

  • agc_masked_select, two new cases: an optional body's merged value reaches Ballot(own(live) && merged != 0), whose low word is also kept outside the own-bit funnel. With live a ballot of the non-helper lanes it is replay-safe; with live a ballot that helper lanes are in, it is refused. With #9317's StencilReplay.cpp the first fails (an optional wave body may merge a value into a ballot whose argument is false on every helper lane); with this change both pass.

  • The Onimusha request (shader_2111c51800, dumped with APS5_DUMP_SHADERS) checked offline with PrepareResourceProgram + StencilReplaySafe on #9317 + #8145 + #9393 + #9904 + #9905 + this change: the request passes.

  • With ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1, on #9317 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 #9317 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 passes with no errors (its one warning, debt-length on docs/dev/debt/libSceAgcDriver.md, is in #9317's entry, which this PR does not touch) and git diff --check passes. tools/pr_overlap.py was not run (no gh on this host).

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 #9393, #9904 and #9905)
  • 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:4974149383 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9906). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-22T21:08:47Z. --- ### What On devices without `VK_EXT_shader_stencil_export`, `MaskReplaySafety::optionalBody` refuses an EXEC- or VCC-skipped body when a merge phi is `quadObserved`. Since #9317 a merged value may reach a `Ballot` only when every use of that ballot funnels into a lane's own bit (`ownBitBallot`), which bounds what is *read*. This adds the dual case, which bounds what is *written*: a ballot whose argument `onHelper` proves false on every helper lane. Helper lanes then contribute zero to every word of that ballot whatever the merged value holds on them, so its words are a function of real lanes only, and any consumer (an any-active early-exit gate, the export mask's merge phis) observes nothing about helper lanes. The exemption only applies to ballots the mask analysis has already `restricted` (they sit in a stable mask chain whose `maskStable`/`helpers` checks passed); any other ballot still goes through the funnel or is refused. Onimusha: Way of the Sword (PPSA27836) needs this: after its discard, `Ballot(ownLane(liveWords) && !killed)` (with `liveWords` a ballot of non-helper lanes masked by the whole-quad active lanes) feeds both an any-active exit gate and the export mask's merge phis. @akkadbakkad89 agreed on #9317 that it should land as its own change on top of #9317. This branch is rebased onto `main` `570089a80`, which now carries #9317 (merged as `def1f5dd9`); the diff is this PR's own commit (one line in `quadObserved` and two test cases). ### Tested - Rebased 2026-10-26: on this head `83d2093a9` (main `570089a80`), with `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1` on the RTX 3080, `agc_masked_select`, `agc_driver_sample_mask_depth_stencil`, `agc_driver_stencil_known_replace`, `agc_driver_stencil_null_feedback`, `agc_driver_stencil_ref_export_unused`, `agc_driver_stencil_replay` and `agc_driver_stencil_replay_no_gpl` pass and `agc_driver_stencil_ref_export` skips (no `VK_EXT_shader_stencil_export`); `tools/check_conventions.py --base origin/main` passes. The results below were taken on the earlier #9317 base. Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on #9317's head `92ebac241`. - `agc_masked_select`, two new cases: an optional body's merged value reaches `Ballot(own(live) && merged != 0)`, whose low word is also kept outside the own-bit funnel. With `live` a ballot of the non-helper lanes it is replay-safe; with `live` a ballot that helper lanes are in, it is refused. With #9317's `StencilReplay.cpp` the first fails (`an optional wave body may merge a value into a ballot whose argument is false on every helper lane`); with this change both pass. - The Onimusha request (`shader_2111c51800`, dumped with `APS5_DUMP_SHADERS`) checked offline with `PrepareResourceProgram` + `StencilReplaySafe` on #9317 + #8145 + #9393 + #9904 + #9905 + this change: the request passes. - With `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`, on #9317 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 #9317 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` passes with no errors (its one warning, `debt-length` on `docs/dev/debt/libSceAgcDriver.md`, is in #9317's entry, which this PR does not touch) and `git diff --check` passes. `tools/pr_overlap.py` was not run (no `gh` on this host). ### 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 #9393, #9904 and #9905) - [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)
MarcZX10 commented 2026-10-23 05:50:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T05:50:54Z.

Review: APPROVED


Reviewed exact head 3740a402f2fac97794664f20bf87371a8404734d on the #9317 stack. This separately recognizes ballots proven false on helper lanes; the tests cover accepted proof and negative controls. The author reports paired validation-layer runs on NVIDIA and AMD with no new VUIDs, and combined title-request evidence with #9904/#9905. Current-main diff-check passes; conventions report no errors and only the inherited #9317 debt-length warning. Sync is clean apart from the shared debt file. Preserve this helper-lane proof alongside the complementary return-block and own-bit-phi changes; I found no duplicate implementation. I did not rerun the C++/GPU tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624436623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9906#pullrequestreview-5624436623). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T05:50:54Z. **Review:** APPROVED --- Reviewed exact head `3740a402f2fac97794664f20bf87371a8404734d` on the #9317 stack. This separately recognizes ballots proven false on helper lanes; the tests cover accepted proof and negative controls. The author reports paired validation-layer runs on NVIDIA and AMD with no new VUIDs, and combined title-request evidence with #9904/#9905. Current-main diff-check passes; conventions report no errors and only the inherited #9317 debt-length warning. Sync is clean apart from the shared debt file. Preserve this helper-lane proof alongside the complementary return-block and own-bit-phi changes; I found no duplicate implementation. I did not rerun the C++/GPU tests locally.
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!9906
No description provided.