fix(recompiler): accept optional-body merges implied by the skip predicate in stencil replay #9393

Merged
TheSovietWaffle merged 1 commit from upstream-pr/9393 into main 2026-10-26 18:26:17 +00:00
TheSovietWaffle commented 2026-10-21 20:22:14 +00:00 (Migrated from github.com)

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


What

On devices without VK_EXT_shader_stencil_export, MaskReplaySafety::optionalBody accepts an EXEC- or VCC-skipped body when every merge phi's value from the body equals the skipped value on lanes that are inactive in the body (inactiveEquals). Lanes are inactive in the body exactly where the skip predicate P is false.

A body value that implies P is false on every inactive lane. When the phi's skipped value is P itself, that is also false there, so the two are equal on inactive lanes. inactiveEquals now accepts a Bool body value v when the skipped value is the predicate and GuardImplies(v, P) holds. The case that needs it is a lane's own bit of Ballot(P) (optionally intersected with a whole-quad active mask) merged with P: Onimusha: Way of the Sword (PPSA27836) has this as the "lane is done" flag of its stencil-exporting pixel shader, merged after an s_cbranch_execz body.

The existing rules (same value, select on the predicate, region phis) are unchanged.

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 inactiveEquals and two test cases).

Tested

  • Rebased 2026-10-26: on this head bf0589e28 (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 on a single-block EXEC-skipped body: merging a lane's own bit of Ballot(P) from the body with P from the skip is replay-safe; merging !P (true on inactive lanes) is refused. With #9317's StencilReplay.cpp the first fails (an optional wave body may merge a lane's own bit of the predicate's ballot with the skipped predicate) and the second passes; with this change both pass.

  • The Onimusha request (shader_2111c51800, dumped with APS5_DUMP_SHADERS) checked offline with PrepareResourceProgram + StencilReplaySafe on #9317 + #8145: without this rule block 0's merge phi of the "done" flag refuses in inactiveEquals; with it, that phi is accepted. The request still needs the ballot exemption I asked about on #9317 and a change for an early exit inside the optional body before it passes (details on #9317), so no title is claimed.

  • 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 the ballot exemption asked about on #9317 and an early-exit change for optional bodies)
  • 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:4957836728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9393). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-21T20:22:14Z. --- ### What On devices without `VK_EXT_shader_stencil_export`, `MaskReplaySafety::optionalBody` accepts an EXEC- or VCC-skipped body when every merge phi's value from the body equals the skipped value on lanes that are inactive in the body (`inactiveEquals`). Lanes are inactive in the body exactly where the skip predicate `P` is false. A body value that implies `P` is false on every inactive lane. When the phi's skipped value is `P` itself, that is also false there, so the two are equal on inactive lanes. `inactiveEquals` now accepts a Bool body value `v` when the skipped value is the predicate and `GuardImplies(v, P)` holds. The case that needs it is a lane's own bit of `Ballot(P)` (optionally intersected with a whole-quad active mask) merged with `P`: Onimusha: Way of the Sword (PPSA27836) has this as the "lane is done" flag of its stencil-exporting pixel shader, merged after an `s_cbranch_execz` body. The existing rules (same value, select on the predicate, region phis) are unchanged. 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 `inactiveEquals` and two test cases). ### Tested - Rebased 2026-10-26: on this head `bf0589e28` (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 on a single-block EXEC-skipped body: merging a lane's own bit of `Ballot(P)` from the body with `P` from the skip is replay-safe; merging `!P` (true on inactive lanes) is refused. With #9317's `StencilReplay.cpp` the first fails (`an optional wave body may merge a lane's own bit of the predicate's ballot with the skipped predicate`) and the second passes; with this change both pass. - The Onimusha request (`shader_2111c51800`, dumped with `APS5_DUMP_SHADERS`) checked offline with `PrepareResourceProgram` + `StencilReplaySafe` on #9317 + #8145: without this rule block 0's merge phi of the "done" flag refuses in `inactiveEquals`; with it, that phi is accepted. The request still needs the ballot exemption I asked about on #9317 and a change for an early exit inside the optional body before it passes (details on #9317), so no title is claimed. - 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 the ballot exemption asked about on #9317 and an early-exit change for optional bodies) - [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)
xXPBSXx commented 2026-10-21 23:59:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T23:59:40Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only agc_masked_select_tests; ctest -N -R agc_masked_select lists exactly one test.

PR head tested: 61d4817df599177df2a618c20d4a951fa86677da.

Results (3 runs each):

  • PR head: agc_masked_select passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/shader/recompiler/StencilReplay.cpp with the version from the PR's merge base (0c6a5bd593), then rebuilt. The test fails 3/3 (ctest reports Failed). I restored the PR's files afterwards.

GPU: the run output has no Selected GPU line; no GPU claim is made.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329274805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9393#issuecomment-6329274805). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T23:59:40Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `agc_masked_select_tests`; `ctest -N -R agc_masked_select` lists exactly one test. **PR head tested:** `61d4817df599177df2a618c20d4a951fa86677da`. **Results (3 runs each):** - PR head: `agc_masked_select` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/shader/recompiler/StencilReplay.cpp` with the version from the PR's merge base (`0c6a5bd593`), then rebuilt. The test fails 3/3 (ctest reports Failed). I restored the PR's files afterwards. **GPU:** the run output has no `Selected GPU` line; no GPU claim is made. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 06:07:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T06:07:55Z.

Review: DISMISSED


The new inactiveEquals case is narrowly guarded by IrType::Bool, predicate identity, and GuardImplies, and the positive/negative regression cases are useful. I built agc_masked_select_tests on this head and ran agc_masked_select three times; all three passed. As a local paired check, I applied only the new test hunk to current main: the suite failed on the expected “own bit of the predicate's ballot” case. tools/check_conventions.py --base upstream/main and git diff --check also pass.

I cannot approve yet because the change still needs the repository-required follow-up:

  • Current main is 5a79f26450; this head is 442 commits behind. Please rebase and refresh the conventions and overlap checks.
  • This is a shader-recompiler change. The PR report says the Khronos validation layer was unavailable, so the required paired GPU run with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_LAYER_KHRONOS_validation has no VUID comparison. Please rerun the focused main/change tests with the layer and report GPU/driver details and VUID differences. The local unit test above is host-only; I could not run GPU tests here.
  • The refreshed overlap scan finds direct inactiveEquals overlap with open #9317. Please coordinate with that author and agree order/composition, then set Depends on accurately. The overlap tool could not compare #6879’s MaskedSelect.cpp; I manually confirmed it also adds tests in this file, so please refresh that test-area comparison after rebase.
  • The Tested section says the Onimusha shader still stops at quadObserved and explicitly relies on the separate #9394 change. Please keep the title result scoped to the combined changes and coordinate the dependency/order with #9394 so the checklist and unblocks claim reflect what is actually required.

Hosted eligibility, conventions, intake, labels, and report checks pass; product build jobs were skipped. The local focused test and author/independent Windows reports are positive evidence, but the Vulkan validation-layer requirement and current-main/overlap updates remain outstanding.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609921167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9393#pullrequestreview-5609921167). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T06:07:55Z. **Review:** DISMISSED --- The new `inactiveEquals` case is narrowly guarded by `IrType::Bool`, predicate identity, and `GuardImplies`, and the positive/negative regression cases are useful. I built `agc_masked_select_tests` on this head and ran `agc_masked_select` three times; all three passed. As a local paired check, I applied only the new test hunk to current `main`: the suite failed on the expected “own bit of the predicate's ballot” case. `tools/check_conventions.py --base upstream/main` and `git diff --check` also pass. I cannot approve yet because the change still needs the repository-required follow-up: - Current `main` is `5a79f26450`; this head is 442 commits behind. Please rebase and refresh the conventions and overlap checks. - This is a shader-recompiler change. The PR report says the Khronos validation layer was unavailable, so the required paired GPU run with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, and `VK_LAYER_KHRONOS_validation` has no VUID comparison. Please rerun the focused main/change tests with the layer and report GPU/driver details and VUID differences. The local unit test above is host-only; I could not run GPU tests here. - The refreshed overlap scan finds direct `inactiveEquals` overlap with open #9317. Please coordinate with that author and agree order/composition, then set `Depends on` accurately. The overlap tool could not compare #6879’s `MaskedSelect.cpp`; I manually confirmed it also adds tests in this file, so please refresh that test-area comparison after rebase. - The Tested section says the Onimusha shader still stops at `quadObserved` and explicitly relies on the separate #9394 change. Please keep the title result scoped to the combined changes and coordinate the dependency/order with #9394 so the checklist and unblocks claim reflect what is actually required. Hosted eligibility, conventions, intake, labels, and report checks pass; product build jobs were skipped. The local focused test and author/independent Windows reports are positive evidence, but the Vulkan validation-layer requirement and current-main/overlap updates remain outstanding.
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!9393
No description provided.