Skip to content

fix(agc): draw a stencil replacement against a known stencil value as an inversion - #7725

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/stencil-known-replace
Oct 21, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/stencil-known-replace

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

DB_STENCILREFMASK holds a test value (STENCILTESTVAL) and a separate operation value (STENCILOPVAL). REPLACE_OP, ONES and REPLACE_TEST write a value that can differ from the test value on bits the compare reads, while Vulkan has one reference for both. Such a face threw stencil replacement ... is unsupported. Ghost of Tsushima (PPSA02225) stops on one at its splash screen: an EQUAL test against 0xff whose pass operation is REPLACE_OP with 0x40, both masks 0xff.

Some compares fix the stencil value wherever an operation runs:

  • on pass and depth fail: EQUAL, LEQUAL against the largest masked value, GEQUAL against 0;
  • on fail: NOTEQUAL, LESS against 0, GREATER against the largest masked value.

There, if every written bit is also compared, the written bits hold the test value, so writing value is the same as inverting the bits where it differs from the test value. The face becomes an INVERT whose write mask is (test ^ value) & writeMask, and its reference stays the test value for the compare.

  • The operations of a face share its write mask, so this only applies when every operation that isn't KEEP becomes the same inversion (for example REPLACE_OP on both pass and depth fail). Any other combination still throws, now with its own message.
  • A replacement that agrees with the test value on the compared bits takes the existing path (one reference) as before. A pixel shader that exports the stencil test value is unchanged.

Tested

Ubuntu 24.04, GCC 13.3, NVIDIA RTX 4070 Ti (595.99.02), on main 8a526d4.

  • New agc_driver_stencil_known_replace fills the stencil with a value, draws with one of the cases below, and then probes the stencil with an EQUAL draw that must cover exactly the filled pixels:
    • EQUAL 0xff, REPLACE_OP 0x40 on pass, then on pass and depth fail → 0x40;
    • EQUAL 0x25, ONES → 0xff;
    • EQUAL 0xff, REPLACE_OP 0x40 through write mask 0xf0 → 0x4f;
    • NOTEQUAL 0xff and GREATER 0xff, REPLACE_OP 0x40 on fail → 0x40, with no color written;
    • LEQUAL 0xff, REPLACE_OP 0x40 → 0x40.
    • On main with the new and changed tests, both fail: agc_driver_stencil_known_replace on stencil replacement 0x40 against test value 0xff, agc_driver_graphics on 0x05 against test value 0x02.
    • With the fix, both pass 3 of 3 on NVIDIA and once on lavapipe (llvmpipe, LLVM 20.1.2).
  • agc_driver_graphics: the decode case that expected the stencil replacement failure (EQUAL 2, REPLACE_OP 5) now expects INVERT with write mask 7 and reference 2. New decode cases cover depth fail, NOTEQUAL, LEQUAL and GREATER. The refusals that remain are checked: NOTEQUAL on pass, LESS on pass, a write mask wider than the compare mask, LEQUAL against 0x7f, and a ZERO beside the inversion.
  • The 29 tests matching stencil|depth|^agc_driver_graphics$|htile pass.
  • macOS: @jotitadev ran it on an Apple M2 Max under MoltenVK 1.4.2 and MoltenVK main + SPIRV-Cross Ratchet & Clank: Rift Apart: SIGSEGV since #861, an address-less 64 GiB reservation now takes the addresses the title hints next #2704 (x86-64 build under Rosetta, on their macOS build stack). agc_driver_stencil_known_replace runs there (no skip) and, like agc_driver_graphics, passes 3 of 3 on both drivers. With this PR's State.cpp hunks reverted, both fail with the refusals above. The rest of their ^agc suite is unchanged.
  • Windows: @xXPBSXx ran it merged onto main 676d423 with fix(libScePlayGo): list chunks 0 to 999 when only a scenario file is present #7726 (MinGW-w64, WinLibs): agc_driver_stencil_known_replace passes 3 of 3, and fails 3 of 3 with main's State.cpp.
  • AMD, Windows: @thuanquang ran it on an RX 6700 XT (RDNA 2), with this head merged onto main 7f596df. Without this PR, agc_driver_stencil_known_replace fails 3 of 3 on the 0x40 against test value 0xff refusal. With it, the test passes 3 of 3, and so does agc_driver_graphics. The other stencil tests pass except agc_driver_stencil_replay_no_gpl, which fails the same way without this PR (the GPL cache-order effect fix(agc): key shader modules by the pipeline library mode #6436 targets).
  • Intel and AMD, Windows: @savvaniss ran it on an Intel UHD 770 and an AMD RX 9070 XT, merged into main 6b8228b. The 22 tests built from the two test files pass 3 of 3. With only this PR's test changes, agc_driver_graphics and agc_driver_stencil_known_replace fail with the two refusals above.
  • Ghost of Tsushima (PPSA02225), together with fix(libScePlayGo): list chunks 0 to 999 when only a scenario file is present #7726, the PlayGo fix it needs to get that far: without this PR it stops at the splash screen on stencil replacement 0x40 against test value 0xff (masks 0xff/0xff), in 2 of 2 runs (23 s and 47 s in). A logging build showed the face: compare 2 (EQUAL), operations 0x040 (REPLACE_OP on pass). With this PR it draws past it and stops 41 s in at an unrelated check: a one-sample depth target under a 2x rasterizer with PS_ITER_SAMPLE.
  • Khronos validation, as CONTRIBUTING.md asks: Ubuntu's 1.3.275 layer loaded with VK_LAYER_PATH, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -V, RTX 4070 Ti, Linux. Neither log reports was not found but was requested by env var VK_INSTANCE_LAYERS. ^agc_driver_graphics$|stencil_known_replace on main 8a526d4 and this PR: agc_driver_graphics gives no validation messages on either. The new agc_driver_stencil_known_replace reports only VUID-VkDeviceCreateInfo-pNext-pNext (newer device extensions) and VUID-VkGraphicsPipelineCreateInfo-pLibraries-06681. This older layer reports both for every device-creating test on main too: 15 and 141 times over main's tessellation and journal tests, for example.
  • The same comparison under the LunarG SDK's 1.4.363 layer, the version Windows reviewers run: no validation messages on main 8a526d4 or with this PR. The 1.4.363 layer doesn't report the old layer's pNext-pNext and pLibraries-06681.

Checklist

🤖 Generated with Claude Code

… an inversion

DB_STENCILREFMASK holds a test value and a separate operation value, and
REPLACE_OP, ONES and REPLACE_TEST write a value that can differ from the
test value on bits the compare reads. Vulkan uses one reference for both,
so such a face threw. Ghost of Tsushima (PPSA02225) stops on one at its
splash screen (test value 0xff, operation value 0x40, both masks 0xff).

Some compares fix the stencil value wherever an operation runs: EQUAL on
pass and depth fail, NOTEQUAL on fail, and LEQUAL, GEQUAL, LESS or GREATER
against the largest or smallest masked value. There, if every written bit
is compared, the written bits hold the test value, so the replacement is
an INVERT whose write mask holds only the bits that differ from the value
written. The operations of a face share its write mask, so a face whose
other operations can't be drawn the same way still throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

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 1191 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5441 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5499 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5925 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
PR 6194 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6235 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6280 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6481 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6548 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6808 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8105 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8395 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8564 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9020 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp

@github-actions github-actions Bot added the agc libSceAgc* label Oct 19, 2026

@jotitadev jotitadev 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.

Apple GPU / MoltenVK run. agc_driver_stencil_known_replace runs on Metal (no skip) and passes. It fails without the fix with the refusal from the description. The full ^agc suite is unchanged.

Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Head c9fe929, PR diff applied cleanly. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704.

Tested: the tree is main a373e85 + mugurc's macOS series (ci/macos-series-2) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plain main (it doesn't build on macOS yet). Also in the same build: #7725, #7729, #7717, #7694, #7682, #7731 and #6815 (they applied cleanly together), plus a test-only patch that lets nine AGC fixtures load the Vulkan loader on macOS (branch jotitadev:fix/agc-tests-vulkan-loader-macos). Base on that tree: 40 ^agc failures with MoltenVK 1.4.2 and 26 with MoltenVK main + #2704.

  • agc_driver_stencil_known_replace (stencil replacements with a known stencil value passed) and agc_driver_graphics pass 3 of 3 on both drivers, as do the other stencil, depth and htile tests in the tree. Two multisample tests fail the same way as on the base.
  • With this PR's hunks of State.cpp reverted, both tests fail on both drivers. agc_driver_stencil_known_replace fails with stencil replacement 0x40 against test value 0xff (masks 0xff/0xff) is unsupported, and agc_driver_graphics with 0x05 against test value 0x02.
  • Full ^agc suite with the stack: the base failures on each driver, plus agc_driver_pooled_buffer_range and agc_performance_overlay, which only run because of the loader patch. Nothing from this PR.

GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704)

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@xXPBSXx

xXPBSXx commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Windows data point for c9fe9292d (this PR) merged onto main 676d42396 together with #7726 (42f4382bc) in one tree (f58459c78, both merges clean, git status empty): Windows 10 (10.0.19045), MinGW-w64 (WinLibs) toolchain, ctest -R '^agc_driver_stencil_known_replace$', one fresh process per run.

Not tested: a title run, other GPUs, Linux.

AI-assisted (Claude Code).

@milescoviello

Copy link
Copy Markdown
Contributor Author

@jotitadev @xXPBSXx thank you both. jotitadev's MoltenVK runs on two drivers show the new test runs on Metal and catches the change there. xXPBSXx's Windows run, with the reverted State.cpp control, covers the MinGW build. Both are in the description now.

AI-assisted: yes (Claude Code)

@thuanquang

thuanquang commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

An AMD run: RX 6700 XT (gfx1031, RDNA 2), AMD driver 32.0.21045.5002, Windows 11 26200, WinLibs GCC 15.2.0 r7, Release. Base main 7f596df48 (with #7074 merged, which touches only f16 fma translation), then this PR's head c9fe9292d merged on top (clean).

@savvaniss

Copy link
Copy Markdown
Contributor

Intel and AMD Windows data: with this PR's test changes, agc_driver_graphics and the new agc_driver_stencil_known_replace fail on main and pass with the PR, on an Intel UHD 770 and an AMD RX 9070 XT.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. This head c9fe9292d merged into main 6b8228b2b. "Without" means only this PR's diff to tests/Graphics.cpp and the new tests/execution/StencilKnownReplace.cpp, applied to main 6b8228b2b.

Tests, ×3 UHD 770 RX 9070 XT
This head: the 22 tests built from those two files 22 of 22 pass 22 of 22 pass
Without agc_driver_graphics fails: stencil replacement 0x05 against test value 0x02 (masks 0xff/0xff) is unsupported; agc_driver_stencil_known_replace fails: stencil replacement 0x40 against test value 0xff (masks 0xff/0xff) is unsupported; the other 20 pass same

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

@thuanquang @savvaniss thank you both, the runs are in the description now. They cover RDNA 2, RDNA 4 and Intel on Windows, each failing without the fix and passing with it. Thanks also, thuanquang, for checking agc_driver_stencil_replay_no_gpl separately: it fails the same way without this PR, so that's #6436's cache-order issue and not this change.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Picking this up for our testing: it addresses the stop we see in PPSA03208 on current main, one of the titles we're bringing up, and we'd like to move it into main. We'll review, test and merge it under the normal process. Your comments and review are still very welcome, @adriadam10.

@oneandonlydean oneandonlydean self-assigned this Oct 20, 2026
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @oneandonlydean. It merges cleanly with current main, so I'll leave the branch alone while you test it, unless you'd like a rebase or a change.

AI-assisted: yes (Claude Code)

@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Title data point for this PR (data only).

Title: PPSA02225, 300 s per run through the runner, ANYPS5_GPU=4080; both .out logs show Selected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702 subgroup=32. Windows 10 Pro 10.0.19045, WinLibs GCC 15.2.0, Release, the relinker and all libs built from the same tree.

Baseline, main 50efb5c405 (run_120636.err):

[gpu] driver failure: AGC graphics: stencil replacement 0x40 against test value 0xff (masks 0xff/0xff) is unsupported

then FATAL: abort() (SIGABRT) (lines 234-238).

This PR (c9fe9292d8) merged into the same main (run_115819.err): the stencil stop does not occur. The run stops about the same place in the log on a different refusal:

what():  AGC graphics: a one-sample depth target under a multisampled rasterizer without MSAA_ENABLE is unsupported for points or lines and with alpha-to-coverage, PS_ITER_SAMPLE, a sample index or coverage input, a sample-mask export, or DB_EQAA Z interpolation or overrasterization

(lines 240-242). That is the area of #7729, #8115 and #8121, not of this PR.

One run each, so this shows that the draw gets past the stencil check with the PR, not that the title is fixed. I did not look at the picture, and I did not run the PR's tests on this machine.

Not run: other GPUs for this title, the PR's tests, other titles, the console.

AI-assisted (Claude Code).

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @xXPBSXx, that's the first Windows run of the title with this PR. It matches what I see on Linux. On main it aborts on the 0x40 against test value 0xff stencil refusal. With this PR it gets past it and stops on the one-sample depth target under a multisampled rasterizer, which in Ghost of Tsushima is a PS_ITER_SAMPLE depth-only pass.

That next stop is what #7729 handles. On Linux, with #7726, this PR and #7729, the title draws past both of those draws and stops later, at an unrelated check (it's in #7729's description). I added your run to the Tested section.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit d34da5d into boykopovar:main Oct 21, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants