fix(shader-recompiler): admit first-lane reads of wave-uniform values in stencil replay #18322

Merged
mrfelek merged 2 commits from upstream-pr/18322 into main 2026-11-16 05:53:40 +00:00
mrfelek commented 2026-11-11 08:15:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-11-11T08:15:48Z.


What

On a device without VK_EXT_shader_stencil_export, stencil reference replay refuses every pixel shader that has a ReadFirstLane. This PR admits a ReadFirstLane whose value every lane of the wave holds alike, so which lane it reads makes no difference between replay passes.

  • The proof's wave-uniform walk moves out of MaskReplaySafety into WaveUniformValues, which the lane-op check and the mask proof now share.
  • The walk also accepts:
    • raw scalar memory reads (ReadConstBuffer of a ScalarBuffer, LoadAddressU32 of a ScalarAddress), when their own operands are uniform;
    • descriptor handles;
    • FPRecip32 / FPRecipIFlag32.
  • Exec-skip predicates built from those values are now uniform for the mask proof too.
  • ReadLane stays refused. Its shuffle can name an inactive lane.
  • The stencil replay debt entry names the exception.

PPSA03671 hits this with v_readfirstlane_b32 in an unsigned divide by a scalar buffer value. That pixel shader then stops at the mask proof, on an s_cbranch_execz body whose exec-restoring export tail the structurizer duplicated. That is left for a separate change, so this PR doesn't unblock the title alone.

Tested

Linux 7.3, RTX 3080 Ti, NVIDIA 615.71.09 (no VK_EXT_shader_stencil_export).

  • agc_masked_select_tests has four new cases holding seven checks:
    • a first-lane read of a scalar-buffer value is admitted;
    • first-lane reads of LaneId, a vector-buffer read and FragCoord are refused;
    • ReadLane of a uniform value is still refused;
    • an ExecZero skip on a scalar-buffer predicate is proven, and one on a vector-buffer predicate is not.
  • The two admit cases fail with main's StencilReplay.cpp, and all cases pass with this change.
  • ctest -R 'stencil|masked_select|read_first_lane|pixel_helper_lanes|exec_host_lanes|permlane16' -V with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, on main and on this branch:
    • 19 of 20 pass on both. agc_driver_stencil_ref_export is skipped, since the device lacks the extension.
    • No VUID- lines and no missing-layer line in either log.
  • Offline, through PrepareResourceProgram, the logged PPSA03671 pixel shader's one ReadFirstLane is uniform, and the shader is now refused only by the mask proof.

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
  • GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 615.71.09, Linux 7.3
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5256096851 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18322). Originally posted by [mrfelek](https://github.com/mrfelek) on 2026-11-11T08:15:48Z. --- ### What On a device without `VK_EXT_shader_stencil_export`, stencil reference replay refuses every pixel shader that has a `ReadFirstLane`. This PR admits a `ReadFirstLane` whose value every lane of the wave holds alike, so which lane it reads makes no difference between replay passes. - The proof's wave-uniform walk moves out of `MaskReplaySafety` into `WaveUniformValues`, which the lane-op check and the mask proof now share. - The walk also accepts: - raw scalar memory reads (`ReadConstBuffer` of a `ScalarBuffer`, `LoadAddressU32` of a `ScalarAddress`), when their own operands are uniform; - descriptor handles; - `FPRecip32` / `FPRecipIFlag32`. - Exec-skip predicates built from those values are now uniform for the mask proof too. - `ReadLane` stays refused. Its shuffle can name an inactive lane. - The stencil replay debt entry names the exception. PPSA03671 hits this with `v_readfirstlane_b32` in an unsigned divide by a scalar buffer value. That pixel shader then stops at the mask proof, on an `s_cbranch_execz` body whose exec-restoring export tail the structurizer duplicated. That is left for a separate change, so this PR doesn't unblock the title alone. ### Tested Linux 7.3, RTX 3080 Ti, NVIDIA 615.71.09 (no `VK_EXT_shader_stencil_export`). - `agc_masked_select_tests` has four new cases holding seven checks: - a first-lane read of a scalar-buffer value is admitted; - first-lane reads of `LaneId`, a vector-buffer read and `FragCoord` are refused; - `ReadLane` of a uniform value is still refused; - an `ExecZero` skip on a scalar-buffer predicate is proven, and one on a vector-buffer predicate is not. - The two admit cases fail with `main`'s `StencilReplay.cpp`, and all cases pass with this change. - `ctest -R 'stencil|masked_select|read_first_lane|pixel_helper_lanes|exec_host_lanes|permlane16' -V` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, on `main` and on this branch: - 19 of 20 pass on both. `agc_driver_stencil_ref_export` is skipped, since the device lacks the extension. - No `VUID-` lines and no missing-layer line in either log. - Offline, through `PrepareResourceProgram`, the logged PPSA03671 pixel shader's one `ReadFirstLane` is uniform, and the shader is now refused only by the mask proof. ### 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 - [x] GPUs tested: NVIDIA GeForce RTX 3080 Ti, driver 615.71.09, Linux 7.3 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-12 16:31:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T16:31:25Z.

Review: COMMENTED


Reviewed the first-lane stencil replay change — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head 115288655cf9d34f0947f709f2bff2e890f76b51, base main. Read from the pinned diff; no merge preview and no build.
  • Read the diff hunks of the three changed files, plus the helpers they call at head.
  • Commands:
python3 repo_read.py search "IsRuntimeUniformOp"
python3 repo_read.py search "bool IsRawRead"
python3 repo_read.py cat core/shader/recompiler/StencilReplay.cpp 1 60
python3 repo_read.py cat core/shader/recompiler/Optimization/src/SrtWalker/SrtInstructionPredicates.cpp 1 173
python3 repo_read.py cat core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtInstructionPredicates.hpp 1 20

Results

Check Result Note
Build and unit tests not run No build in this review
Author's ctest run not run Author-reported, not repeated
Diff read passed Three files, changed hunks and helpers

Findings

Blocking

None.

Non-blocking

  1. docs/dev/debt/libSceAgcDriver.md:172: the debt entry says "user data, scalar memory reads and arithmetic on them". The walk in core/shader/recompiler/StencilReplay.cpp also accepts descriptor handles, ReadConst, float compares, and the select and compare ops of IsRuntimeUniformOp. The entry should name that set.
  2. core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp:963: the description says "five new cases". The diff adds four run( registrations holding seven checks, so neither count matches.
  3. core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp:986: const auto exportUnder =[] drops the space before [] that the other lambdas keep. The line changes only in whitespace.

The uniform walk (WaveUniformValues::Uniform) refuses cycles and deep chains by caching a refusal. That is conservative. I found no path in the code I read that admits a lane-varying value to ReadFirstLane. ReadLane stays refused.

Not verified

  • Build, agc_masked_select_tests, and the ctest set. The claims that the two admit cases fail on main and that 19 of 20 tests pass are the author's and were not run here.
  • The offline PPSA03671 result, that the shader is now refused only by the mask proof.
  • Console behaviour. The description does not claim it.
  • Read scope: the three files were read as their changed hunks and the helpers above. The rest of MaskedSelect.cpp and StencilReplay.cpp, including the mask proof body and the call sites of uniform, was not read. The full texts in files/ were not read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5878181189 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18322#pullrequestreview-5878181189). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T16:31:25Z. **Review:** COMMENTED --- # Reviewed the first-lane stencil replay change — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head `115288655cf9d34f0947f709f2bff2e890f76b51`, base `main`. Read from the pinned diff; no merge preview and no build. - Read the diff hunks of the three changed files, plus the helpers they call at head. - Commands: ``` python3 repo_read.py search "IsRuntimeUniformOp" python3 repo_read.py search "bool IsRawRead" python3 repo_read.py cat core/shader/recompiler/StencilReplay.cpp 1 60 python3 repo_read.py cat core/shader/recompiler/Optimization/src/SrtWalker/SrtInstructionPredicates.cpp 1 173 python3 repo_read.py cat core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtInstructionPredicates.hpp 1 20 ``` ## Results | Check | Result | Note | |---|---|---| | Build and unit tests | not run | No build in this review | | Author's ctest run | not run | Author-reported, not repeated | | Diff read | passed | Three files, changed hunks and helpers | ## Findings ### Blocking None. ### Non-blocking 1. `docs/dev/debt/libSceAgcDriver.md:172`: the debt entry says "user data, scalar memory reads and arithmetic on them". The walk in `core/shader/recompiler/StencilReplay.cpp` also accepts descriptor handles, `ReadConst`, float compares, and the select and compare ops of `IsRuntimeUniformOp`. The entry should name that set. 2. `core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp:963`: the description says "five new cases". The diff adds four `run(` registrations holding seven checks, so neither count matches. 3. `core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp:986`: `const auto exportUnder =[]` drops the space before `[]` that the other lambdas keep. The line changes only in whitespace. The uniform walk (`WaveUniformValues::Uniform`) refuses cycles and deep chains by caching a refusal. That is conservative. I found no path in the code I read that admits a lane-varying value to `ReadFirstLane`. `ReadLane` stays refused. ## Not verified - Build, `agc_masked_select_tests`, and the ctest set. The claims that the two admit cases fail on `main` and that 19 of 20 tests pass are the author's and were not run here. - The offline PPSA03671 result, that the shader is now refused only by the mask proof. - Console behaviour. The description does not claim it. - Read scope: the three files were read as their changed hunks and the helpers above. The rest of `MaskedSelect.cpp` and `StencilReplay.cpp`, including the mask proof body and the call sites of `uniform`, was not read. The full texts in `files/` were not read. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-14 02:01:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T02:01:56Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the focused tests and conservative uniformity checks support the stated admission rule.

What I ran

Reviewed head bf98c25574268e1e3796de1359ca80690c2ed2be. No test or build commands were run; repo_read.py was used to inspect the prepared diff and targeted source ranges. The author reports running tests on Linux 7.3 with an RTX 3080 Ti and NVIDIA 615.71.09; those runs were not independently verified.

Results

Check Result Note
Diff and changed source passed All three changed files were read.
Targeted logic review passed First-lane values require recursively uniform operands.
Tests and build not run Results in the PR description are author-reported.

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or builds were run. Test execution and the reported GPU behavior were not independently verified. All changed files listed as reviewed in manifest.json were read: core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp, core/shader/recompiler/StencilReplay.cpp, and docs/dev/debt/libSceAgcDriver.md. files.json was not available through the reader; the manifest lists all three changed files as included, with none excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5900679987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18322#pullrequestreview-5900679987). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T02:01:56Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the focused tests and conservative uniformity checks support the stated admission rule. ## What I ran Reviewed head `bf98c25574268e1e3796de1359ca80690c2ed2be`. No test or build commands were run; `repo_read.py` was used to inspect the prepared diff and targeted source ranges. The author reports running tests on Linux 7.3 with an RTX 3080 Ti and NVIDIA 615.71.09; those runs were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source | passed | All three changed files were read. | | Targeted logic review | passed | First-lane values require recursively uniform operands. | | Tests and build | not run | Results in the PR description are author-reported. | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or builds were run. Test execution and the reported GPU behavior were not independently verified. All changed files listed as reviewed in `manifest.json` were read: `core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp`, `core/shader/recompiler/StencilReplay.cpp`, and `docs/dev/debt/libSceAgcDriver.md`. `files.json` was not available through the reader; the manifest lists all three changed files as included, with none excluded. ## To get this to a good state Nothing is required.
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!18322
No description provided.