fix(agc): drop an unused stencil test value export from draws without a stencil test #5304
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5304"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-13T16:48:15Z.
What
Since
22d662edaa pixel shader withDB_SHADER_CONTROL.STENCIL_TEST_VAL_EXPORT_ENABLEneedsVK_EXT_shader_stencil_export, which NVIDIA's driver does not offer. On NVIDIA this stops Marvel's Wolverine (PPSA03671):sceAgcLinkShadersresolves the ABI of pixel shader0x11d01d0900(DB_SHADER_CONTROL bit 1 set), the driver prepares it right there, the recompile throwsa pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, which the device lacks, and the title aborts.The exported value is only the stencil test value: it feeds the stencil test and what
REPLACE_TESTwrites. In a draw without a stencil test it has no effect. So:Driver::decodeDrawclearsstencilRefExportEnablewhen the decoded state has no stencil test. The shader then has noFragStencilRefEXToutput, on every device. Early fragment tests stay off for it, as before.PlanRegistereddoes not prepare such a pixel shader when its ABI is resolved on a device without the extension, because the draw's stencil test is not known yet there. It is prepared at its first draw instead, like other shaders the ABI step cannot decide.Tested
Windows 11, RTX 3070 (no
VK_EXT_shader_stencil_export), GCC 15.2.0 UCRT, Release, on main0214069e3.agc_driver_stencil_ref_export_unused(GPU): registers a pixel shader that exports a stencil test value and a color, resolves its ABI withDB_SHADER_CONTROL=0x802andSPI_SHADER_Z_FORMAT=9, then draws it withDB_DEPTH_CONTROL=0and no depth target, and checks that the color target was written. On main it fails at the ABI resolve with the error above. With only thePlanRegisteredchange it fails at the draw with the same error. With both it passes. Not run on a device with the extension (none here); there only the draw-time change applies.agc_driver_stencil_ref_exportskips here: the device lacks the extension).tools/check_conventions.pypasses.682ef0c17plus #757 (rebased), #3633, #3846 and #4702 (current main does not reach this point without #757): without this change it aborts with the error above. With it, the title gets pastsceAgcLinkShadersand stops later at a separateGetImageResource dword 0 is not a valid runtime valuein another pixel shader, before any draw with the stencil-exporting shader. So the draw-time part is covered by the test, not yet by the title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Sam-mon7 on 2026-10-13T19:55:02Z.
Demon's Souls (PPSA01341 v1.07) stops on the same recompile error on NVIDIA, but in a draw that has the stencil test enabled, so the "no stencil test" rule here doesn't cover it.
Windows 11, RTX 4070 (driver 596.21, no
VK_EXT_shader_stencil_export), MinGW GCC 15.2 Release.shader 0x249f10800 stage 5: ... a pixel shader that exports the stencil reference needs VK_EXT_shader_stencil_export, which the device lacks.DB_SHADER_CONTROL=0x52(STENCIL_TEST_VAL_EXPORT_ENABLE),DB_DEPTH_CONTROL=0x007007e7(stencil enabled, STENCILFUNC and STENCILFUNC_BF = ALWAYS, depth test GEQUAL with writes),DB_STENCIL_CONTROL=0(every op KEEP),DB_STENCILREFMASK/_BF=0x01ffffff,SPI_SHADER_Z_FORMAT=9.compareMask != 0and the compare op is not ALWAYS or NEVER) or writes it (writeMask != 0and a fail, pass or depth-fail op is REPLACE). With that change the draw records and the title gets past body-type selection. That tree carries other local changes, so it is not an isolated run of this head.compareMaskorwriteMaskrespectively expects no export again.Happy for this to be folded in here, or to open it as a follow-up on top of this PR.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:08:25Z.
Review: COMMENTED
The reasoning holds: without a stencil test, the exported test value has no effect.
One pipeline-count side effect to check. The draw-time change (
if (!product->state.stencilTest) product->pixel.stencilRefExportEnable = false;) runs on every device, including ones that haveVK_EXT_shader_stencil_export.stencilRefExportEnabledecides whether the module has aFragStencilRefEXToutput, so it is part of what the pixel variant (and the pipeline) is keyed on. A title that uses one stencil-exporting pixel shader both with and without a stencil test then gets two variants and two pipeline sets wheremainhad one, on AMD and Intel, which currently work. It's an extra compile and an extra pipeline on first use for each such shader, so a small hitch, but it's paid on the devices that didn't need the change.Applying the clear only when the device lacks the extension (the same check
PlanRegistereddoes) keeps one variant on those devices, and gives NVIDIA the fix. If an unconditional clear is preferred because a shader without the export is cheaper (early tests could in principle be allowed), that's a separate decision and would want its own measurement.On Sam-mon7's Demon's Souls case: widening the rule to "the stencil test can't observe the value" (both faces
ALWAYSand every opKEEP, or a zero ref mask) is exact by the same argument and covers that stop too. It needs the full register set in the condition:STENCILFUNC/_BF, the fail/zfail/pass ops of both faces, andREPLACE_TESTinDB_STENCIL_CONTROL.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T05:52:23Z.
I have two verified follow-up commits based directly on this PR's current head dbd015ca95758df078d847f9c06395f646c348bd: compare the changes.
The predicate also omits the export when enabled stencil testing cannot consume the reference. It considers both faces, effective 8-bit masks, reachable depth/stencil operations, and preserves the export for dependent comparisons or reachable REPLACE writes. Unknown states remain conservative. The existing clear path and missing-extension refusal are preserved.
Commits available to cherry-pick:
Verification on this public branch: typed CPU checks cover 22 accepted and 12 dependent states, the old predicate fails the ALWAYS/KEEP regression, all four modified C++ units pass optimized syntax checks, and conventions pass against both this PR head and upstream/main. The native fixture extends the existing homebrew programs with full color/stencil readbacks and six dependent-state refusal cases; this public branch has not received a full build or GPU run.
Separate private integration evidence using the literal same production predicate: 20 expected native outcomes passed across the old/new drivers, including KEEP/INVERT, dependent refusals, reference-dependent replay controls, and GPL-disabled positive cases. Demon's Souls moved past the previous pixel-stage refusal to the full character-creation menu with a rendered knight model and no fatal error during a 905.7-second run. The first level is still unverified. Dreaming Sarah remained at 59.94 FPS in the steady-state check.
GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100. GPU/title results above are from the private integration, not a GPU execution of this public branch.
AI used: yes, Codex. Source implementation, independent adversarial review, CPU verification, and root-owned native/title verification completed before publication.
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T16:02:06Z.
Thanks all three. Rebased onto
maine34c47921, new head cbf496835:fix(agc): omit reference-independent stencil exports,test(agc): check draws with an unused stencil reference, your authorship kept). That covers @Sam-mon7's Demon's Souls state (both faces ALWAYS, every op KEEP).fix(agc): keep the stencil export on devices with VK_EXT_shader_stencil_export. The draw decode now drops the export only when the device lacks the extension, so AMD and Intel keep one pixel variant per shader as onmain. The debt entry indocs/dev/debt/libSceAgcDriver.mdis updated to the wider rule.Windows 11, MinGW GCC 15.2 Release, NVIDIA GeForce RTX 3070 (driver 617.14), no
VK_EXT_shader_stencil_export: full build,ctest1199/1199 (13 skipped: no device for those tests here), conventions check passes.agc_driver_graphicsreports 22 accepted states and 12 dependent countermodels, and all eightagc_driver_stencil_ref_export_unused_tests --caseruns pass on the GPU (keep and invert draw with full readbacks; the six dependent cases keep the extension refusal).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:49:26Z.
Checked the new head: the unused-reference predicate, the device-gated drop in
Driver::decodeDraw(devices withVK_EXT_shader_stencil_exportkeep one pixel variant), thePlanRegistereddeferral and the debt entry.agc_driver_graphicsandagc_driver_stencil_ref_export_unusedpass; both fail to build without the change.Added one commit on your branch: removed the code comment in
DrawDecode.cpp(no comments except technical debt). Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T19:16:30Z.
Review: COMMENTED
Run on a device that has
VK_EXT_shader_stencil_export, since the runs so far are on NVIDIA without it. @CnRJay's question was about that case.GPUs tested: Apple M2 Max, MoltenVK 1.4.2 (Vulkan 1.4.357), macOS 27.2, x86-64 under Rosetta
maindoes not run the GPU tests on macOS yet, so I tested onmacos-portatb7eb6b6b(mugurc/AnyPS5) plus theImportWatchedchange from #1, with this PR's own diff (merge-base..headcbf496835) applied. Notmain. The only later commit,30f56882f, removes a code comment inDrawDecode.cpp, so these results also hold for the current head. Release build, LunarG Vulkan SDK 1.4.363.0. Suite:ctest -R "^agc" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64" -j1 --timeout 30. Without the PR, 13 tests fail on this setup (7 with the #2704 build), all known macOS failures listed in #1.DrawDecode.cppandtests/Graphics.cppconflict with code that is onmainand not on the branch. I kept the branch's side and added only this PR's own lines:decodeDraw;stencilComparisonandstencilReferenceUnusedTests, with their call and the--unused-stencil-referenceswitch.The other files apply cleanly.
agc_driver_stencil_ref_export_unusedpasses.--case keepand--case invertpass. The six dependent cases are skipped by design (skipped: a dependent reference refusal requires a device without native stencil export).agc_driver_graphicspasses (22 accepted states, 12 dependent countermodels), and so doesagc_driver_stencil_ref_export.mainnever refused this shader. So this run shows that the "keep the export when the extension is present" path does not break anything. It does not exercise the fix itself.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:47:35Z.
Rebased onto current
main(one include conflict inShaderRegistry.cpp, kept both).agc_driver_graphics,agc_driver_stencil_ref_exportandagc_driver_stencil_ref_export_unusedpass on the rebased tree. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T19:51:48Z.
@adriadam10 thanks for rebasing. I rebased locally at the same time (onto
main9a22507ef) and only saw yours when my push was refused, so nothing of mine was pushed. My local tree has the same changes as your headea4378c5a, line for line. On it, on Windows 11 with an RTX 3070: ctest 1222/1223, where the one failure,guest_user_servicewith 0xc0000409, fails the same way on plainmain9a22507efhere. All eightagc_driver_stencil_ref_export_unused_tests --caseruns pass, and conventions pass.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T21:16:50Z.
Rebased onto current
mainagain: the only conflict was theSTENCIL_TEST_VAL_EXPORT_ENABLEline indocs/dev/debt/libSceAgcDriver.md, which #5466 changed. Kept main's wording (bounded replay on devices without the extension) and added theStencilReferenceUnuseddrop on top, in a separate docs commit.agc_driver_graphics,agc_driver_stencil_ref_exportandagc_driver_stencil_ref_export_unusedpass on the rebased tree. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T09:26:15Z.
Demon's Souls (PPSA01342) reaches this refusal on
main. Windows Server 2025, RTX 3060 12 GB (noVK_EXT_shader_stencil_export), driver 591.86.Build:
main2559e9623+ #5870 (boot abort) + #5828 (TYPE 0 T#s) + a follow-up of mine for static V#s with a nonzero TYPE (not opened yet, depends on #5828). That gets the title past its earlier stops into loading the first level from the debug start menu. 1,672 s in, it stops on:Our integration builds carry this PR's change (the
StencilReferenceUnuseddrop). On those, the title gets through the same level load and plays in the level, in runs over the last day of up to about 16 minutes in the level. None of them hit this refusal. An earlier capture of the same kind of draw showed stencil ALWAYS/KEEP on both faces with depth GEQUAL, which is the state this PR drops the export for. I did not decode this run's draw state, and I haven't runmain+ this PR alone.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T10:01:35Z.
Prepared an author-preserving rebase onto
main1db84d574, tip618b80067c43e43eb6b185168f14d9fcc94fabab.The conflict is next to the new quad coverage assignments in
DrawDecode.cpp. The resolution retains bothQuadPixelMask/QuadSampleMasksassignments and this PR's unchanged missing-extension stencil conditional. All six original author records, author dates and complete commit messages are preserved. A separately constructed expected merge tree matches exactly.Fresh CPU validation against the rebased
State.hpp: the literal production predicate and unchanged public sample oracle pass 22 accepted states and 12 dependent counterexamples; the older disable-only predicate fails the intended ALWAYS/KEEP case. Conventions pass against the exact new base. This is source/CPU verification, without a full driver link or native/GPU run on the rebased branch.One retained test caveat: the six manual dependent
--casemodes still require the old missing-extension error text. With #5466 on main, a dependent export may use replay or produce the newer replay-safety refusal. Those legacy assertions need validation/update; this rebase does not change their expectations or claim they pass.GPUs tested: none for this rebase (CPU only). Host: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100.
AI-assisted: yes
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T10:35:26Z.
Additional native verification: the default unused-export test passes full color/stencil readbacks on the RTX 3060. The replay suite also passes with and without graphics pipeline libraries. All three returned exit 0, in 1.17–1.28 seconds per process.
These ran in a fresh Release/O3 integration containing this PR's unchanged six commits, the earlier deferred-descriptor integration, #6259, and opt-in ownership diagnostics. This is separate from the current-main rebase branch offered above; it does not certify that branch's full driver build, the six legacy dependent
--casemodes, or title performance.GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100.
AI-assisted: yes
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:01:23Z.
Rebased onto current
mainagain: the only conflict was inDrawDecode.cpp, next to the newquadPixelMask/quadSampleMaskassignments (kept both). The previous Windows run failed onagc_interpolant_mapping, which printed "passed" and then hit the 120 s timeout on exit; this diff doesn't touch it.agc_driver_graphics,agc_driver_stencil_ref_exportandagc_driver_stencil_ref_export_unusedpass on the rebased tree. Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T11:13:30Z.
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.
main)core/libs/prx/libSceAgcDriver/tests/Graphics.cppL6755