fix(recompiler): pair structurally equivalent whole-quad evaluations in stencil replay #9266

Closed
akkadbakkad89 wants to merge 1 commit from upstream-pr/9266 into main
akkadbakkad89 commented 2026-10-21 16:57:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-21T16:57:41Z.


What

On devices without VK_EXT_shader_stencil_export, MaskReplaySafety only accepts a whole-quad (WqmU64) mask expansion when the low and high words extract the same WqmU64 node at indices 0 and 1. IrProgram::CreateValue does not intern values, so a title whose compiler emits s_wqm_b64 twice on equivalent ballot inputs produces two distinct WqmU64 nodes; a mask pairing extract(wqmA, 0) with extract(wqmB, 1) was refused even though the two evaluations are semantically identical.

This was observed on Assassin's Creed Shadows (PPSA20397, #8514): shader 0x407325e400 composes its own-lane mask from two same-block s_wqm_b64 instructions over ballot(exec) sources, captured via agc_shader_replay --materialize on a live RecompileRequest — the pairing gate reports paired=0 on object identity alone.

Both maskStable() and helpers() now pair the words through equivalentWqm(): two WqmU64s are equivalent when their source trees match opcode-for-opcode, treating same values and equal immediates as equal, and requiring any Ballot pair to sit in the same block with no execution-mask-affecting instruction (SetExec, SetExecLo, SetExecHi, Discard, Sendmsg, SetThreadBitScalarRegister, SetScalarMaskTag) between them. When a distinct high-side evaluation is accepted its node tree is added to restricted so the untracked-lane-op checks keep their strength.

This is one of several verifier gaps this shader hits; on its own it does not unblock the title (the EXEC-copy provenance is #9017's scope, multi-block optional bodies are #9030's, and a further quadObserved rejection of a merged phi feeding a nested execz condition remains — detail posted on #8514).

Tested

Windows 10 Pro 22H2, WinLibs GCC 15.2.0 r7, Debug, on main cecb540a6.

  • agc_masked_select, two new cases: a mask pairing extract(wqmA, 0) with extract(wqmB, 1) over structurally identical, same-block ballot trees is replay-safe (stencil replay pairs structurally equivalent whole-quad evaluations for split low and high words); the same pair separated by SetExecLo is refused (stencil replay refuses to pair whole-quad evaluations separated by an execution-mask change). Reverting the pairing relaxation makes the first fail while the second still passes; all pre-existing cases pass unchanged.
  • agc_shader_replay --materialize on the captured 0x407325e400 request (ANYPS5_NO_SHADER_CACHE=1): the two same-block WqmU64s now pair (paired=1, verified by instrumented build); the check then proceeds to the unrelated control()/optionalBody gate covered by #9030.
  • python3 tools/check_conventions.py --base origin/main: pass. python3 tools/pr_overlap.py --branch fix/stencil-replay-wqm-duplicates: no same-scope overlap (#9017 touches helpers()' ballot provenance, #9030 touches optionalBody — disjoint hunks).
  • Not run: Khronos validation layer (not installed), the title itself (still gated downstream).

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 — PPSA20397 also needs #9017, #9030 and a further merged-phi/exec-condition relaxation; see #8514
  • GPUs tested: shader recompiler path exercised via agc_masked_select + agc_shader_replay on NVIDIA RTX 3070, driver 581.80, Windows 10 22H2
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955269219 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9266). Originally posted by [akkadbakkad89](https://github.com/akkadbakkad89) on 2026-10-21T16:57:41Z. --- ### What On devices without `VK_EXT_shader_stencil_export`, `MaskReplaySafety` only accepts a whole-quad (`WqmU64`) mask expansion when the low and high words extract the *same* `WqmU64` node at indices 0 and 1. `IrProgram::CreateValue` does not intern values, so a title whose compiler emits `s_wqm_b64` twice on equivalent ballot inputs produces two distinct `WqmU64` nodes; a mask pairing `extract(wqmA, 0)` with `extract(wqmB, 1)` was refused even though the two evaluations are semantically identical. This was observed on Assassin's Creed Shadows (PPSA20397, #8514): shader `0x407325e400` composes its own-lane mask from two same-block `s_wqm_b64` instructions over `ballot(exec)` sources, captured via `agc_shader_replay --materialize` on a live `RecompileRequest` — the pairing gate reports `paired=0` on object identity alone. Both `maskStable()` and `helpers()` now pair the words through `equivalentWqm()`: two `WqmU64`s are equivalent when their source trees match opcode-for-opcode, treating same values and equal immediates as equal, and requiring any `Ballot` pair to sit in the same block with no execution-mask-affecting instruction (`SetExec`, `SetExecLo`, `SetExecHi`, `Discard`, `Sendmsg`, `SetThreadBitScalarRegister`, `SetScalarMaskTag`) between them. When a distinct high-side evaluation is accepted its node tree is added to `restricted` so the untracked-lane-op checks keep their strength. This is one of several verifier gaps this shader hits; on its own it does not unblock the title (the EXEC-copy provenance is #9017's scope, multi-block optional bodies are #9030's, and a further `quadObserved` rejection of a merged phi feeding a nested `execz` condition remains — detail posted on #8514). ### Tested Windows 10 Pro 22H2, WinLibs GCC 15.2.0 r7, Debug, on main `cecb540a6`. - `agc_masked_select`, two new cases: a mask pairing `extract(wqmA, 0)` with `extract(wqmB, 1)` over structurally identical, same-block ballot trees is replay-safe (`stencil replay pairs structurally equivalent whole-quad evaluations for split low and high words`); the same pair separated by `SetExecLo` is refused (`stencil replay refuses to pair whole-quad evaluations separated by an execution-mask change`). Reverting the pairing relaxation makes the first fail while the second still passes; all pre-existing cases pass unchanged. - `agc_shader_replay --materialize` on the captured `0x407325e400` request (ANYPS5_NO_SHADER_CACHE=1): the two same-block `WqmU64`s now pair (`paired=1`, verified by instrumented build); the check then proceeds to the unrelated `control()`/`optionalBody` gate covered by #9030. - `python3 tools/check_conventions.py --base origin/main`: pass. `python3 tools/pr_overlap.py --branch fix/stencil-replay-wqm-duplicates`: no same-scope overlap (#9017 touches `helpers()`' ballot provenance, #9030 touches `optionalBody` — disjoint hunks). - Not run: Khronos validation layer (not installed), the title itself (still gated downstream). ### 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 — PPSA20397 also needs #9017, #9030 and a further merged-phi/exec-condition relaxation; see #8514 - [x] GPUs tested: shader recompiler path exercised via `agc_masked_select` + `agc_shader_replay` on NVIDIA RTX 3070, driver 581.80, Windows 10 22H2 - [x] AI-assisted: yes

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