Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
mrfelek:fix/stencil-replay-uniform-first-lane
Nov 16, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
mrfelek:fix/stencil-replay-uniform-first-lane

Conversation

@mrfelek

@mrfelek mrfelek commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

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 18530 core/shader/recompiler/StencilReplay.cpp L962

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 4448 docs/dev/debt/libSceAgcDriver.md
PR 5372 docs/dev/debt/libSceAgcDriver.md
PR 5925 docs/dev/debt/libSceAgcDriver.md
PR 6186 docs/dev/debt/libSceAgcDriver.md
PR 6280 docs/dev/debt/libSceAgcDriver.md
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6481 docs/dev/debt/libSceAgcDriver.md
PR 6804 docs/dev/debt/libSceAgcDriver.md
PR 6808 docs/dev/debt/libSceAgcDriver.md
PR 7002 docs/dev/debt/libSceAgcDriver.md
PR 7256 docs/dev/debt/libSceAgcDriver.md
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7642 docs/dev/debt/libSceAgcDriver.md
PR 7689 core/shader/recompiler/StencilReplay.cpp
PR 8592 docs/dev/debt/libSceAgcDriver.md
PR 9335 docs/dev/debt/libSceAgcDriver.md
PR 9356 docs/dev/debt/libSceAgcDriver.md
PR 9387 docs/dev/debt/libSceAgcDriver.md
PR 9895 docs/dev/debt/libSceAgcDriver.md
PR 9950 docs/dev/debt/libSceAgcDriver.md
PR 10049 docs/dev/debt/libSceAgcDriver.md
PR 10193 docs/dev/debt/libSceAgcDriver.md
PR 10359 docs/dev/debt/libSceAgcDriver.md
PR 10743 docs/dev/debt/libSceAgcDriver.md
PR 10867 core/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp
PR 11551 docs/dev/debt/libSceAgcDriver.md
PR 11825 docs/dev/debt/libSceAgcDriver.md
PR 12904 docs/dev/debt/libSceAgcDriver.md
PR 13809 docs/dev/debt/libSceAgcDriver.md
PR 13863 docs/dev/debt/libSceAgcDriver.md
PR 13920 docs/dev/debt/libSceAgcDriver.md
PR 13928 docs/dev/debt/libSceAgcDriver.md
PR 13929 docs/dev/debt/libSceAgcDriver.md
PR 13963 docs/dev/debt/libSceAgcDriver.md
PR 14217 core/shader/recompiler/StencilReplay.cpp
PR 14944 docs/dev/debt/libSceAgcDriver.md
PR 15456 docs/dev/debt/libSceAgcDriver.md
PR 15529 docs/dev/debt/libSceAgcDriver.md
PR 15548 docs/dev/debt/libSceAgcDriver.md
PR 15621 docs/dev/debt/libSceAgcDriver.md
PR 16260 docs/dev/debt/libSceAgcDriver.md
PR 16483 docs/dev/debt/libSceAgcDriver.md
PR 17611 docs/dev/debt/libSceAgcDriver.md
PR 17915 docs/dev/debt/libSceAgcDriver.md
PR 17956 docs/dev/debt/libSceAgcDriver.md
PR 18139 docs/dev/debt/libSceAgcDriver.md
PR 18515 docs/dev/debt/libSceAgcDriver.md
PR 20084 docs/dev/debt/libSceAgcDriver.md
PR 20187 docs/dev/debt/libSceAgcDriver.md

@JJenkx

JJenkx commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 115288655c, merged onto main 71ce478956 (GPU merge 5ad4e851e8; CPU merge e662051a82). Setup: Windows 11 Enterprise 22621, AMD RX 6700 XT, AMD driver 26.10.1, MinGW-w64 GCC 15.2 UCRT, Release.

agc_masked_select passed in 3 of 3 runs in both setups:

  • GPU, through the shared Windows GPU FIFO with ANYPS5_REQUIRE_VULKAN=1. The binaries matched the hashes recorded at preparation, and the receipt shows exit 0 and app_count=0.
  • CPU, with Vulkan hidden.

AI-assisted: yes.

@Capmare

Capmare commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

#18530 changes the same line of StencilReplaySafe (the lane read ban) and adds a lanesFixed argument. The two changes complement each other. This PR admits first-lane reads of wave-uniform values on every device. #18530 allows every lane read and wave branch, but only on a device with PhysicalStorageBufferAddresses and Int64. I will rebase on whichever PR lands first.

@NathanFahey23

Copy link
Copy Markdown
Contributor

Windows NVIDIA check of head 115288655c, merged onto main 7014889b3e (8ea259e797, clean merge), since this PR has no Windows NVIDIA run yet.

Setup: Windows 11 Home 10.0.26300, i9-13900K, WinLibs GCC 15.2.0, Release, RTX 4080 (10de:2704, driver 32.0.16.2101), ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, Khronos validation layer loaded. GPU set: ctest -R '^(agc_|shader|video_out|guest_video)' --parallel 4.

  • main alone: 1692 of 1692 pass, no validation error.
  • With this PR: 1692 of 1692 pass, no validation error.

Not checked: no title was run.

AI-assisted: yes

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head 115288655c, merged onto main 28237a8567 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: agc_masked_select.
  • All of them pass in 3 of 3 runs.
  • Negative control: with this PR's code reverted to main (files it adds removed) and rebuilt, agc_masked_select fails in 2 of 2 runs, so the tests detect the change.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mrfelek

mrfelek commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks. All three are in bf98c25574: the debt entry now names the whole set the walk accepts (user data, the shader base, descriptors, constant and scalar memory reads, and IsRuntimeUniformOp's operations or float compares and reciprocals on them), the description says four new cases holding seven checks, and the lambda has its space back. No code change.

AI-assisted.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean
oneandonlydean merged commit 661372e into boykopovar:main Nov 16, 2026
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants