fix(agc): keep guest buffer offsets in shader data when stencil replay adds a push constant #9427
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9427"
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 TheSovietWaffle on 2026-10-21T21:44:46Z.
What
On devices without
VK_EXT_shader_stencil_export, stencil replay appends a four-byte dynamic reference to the pixel shader's push constants (RecompileresizespushConstants,BindingAllocatorputsstencilReferenceDwordright after the shader data, or at dword 0 when the layout keeps its shader data in a buffer).The second case was broken. When a pixel shader's shader data does not fit its push range (or it uses runtime images),
IrBindingLayout::UsesPushData()is false and the guest buffer offsets live in the shader-data buffer; the stencil reference is then the only push constant.ShaderResourcesdecided where the guest buffer offsets are with!push.empty(), so it looked for them in the four-byte reference and refused the draw withguest buffer offset lies outside the shader's push constants.It now counts only the shader-data part of the push constants: all of them without stencil replay, and the bytes before
stencilReferenceDwordwith it (the same ruleRecompileand the prepared-artifact check already use). A layout without push data then takes the shader-data buffer path, as it does without stencil replay.Found while running Onimusha: Way of the Sword (PPSA27836) on an RTX 3080 with a local stack of the open stencil replay changes: the first replayed draw failed this way.
Tested
Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main
a6dcea927.agc_driver_stencil_replay, new case: the finite-export shader with its color read bys_buffer_load_dwordthrough a buffer descriptor in user data, with the fragment push range shrunk to the reference dword so the shader data stays in a buffer; the replayed draw must color every pixel from the buffer. On main it fails on both GPUs withAGC graphics: guest buffer offset lies outside the shader's push constants; with this change it passes.ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, on main and on this change:agc_driver_stencil_replay,agc_driver_stencil_replay_no_gpl,agc_driver_stencil_ref_export,agc_driver_stencil_ref_export_unused,agc_driver_stencil_known_replace,agc_driver_stencil_null_feedback,agc_driver_sample_mask_depth_stencil,agc_masked_select,agc_driver_graphics,agc_driver_draw_cache_relocation, the fiveagc_driver_draw_cache_reuse*variants,agc_driver_prepared_graphicswith its threeprebuildvariants,agc_driver_prepared_unregistered_graphicsandguest_buffer_reuse(20 tests) pass on both GPUs below, exceptagc_driver_stencil_ref_exportskipped on the RTX 3080 (noVK_EXT_shader_stencil_export). Results are identical on main and on this change (main runs its ownStencilReplay.cpp, without the new case).VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationhas nothing to load; neither log contains aVUID-line).tools/check_conventions.py --base origin/mainandgit diff --checkpass.tools/pr_overlap.pywas not run (noghon this host).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)1002:164e), 32.0.21045.5002, Windows 10 22H2🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T23:21:47Z.
Review: COMMENTED
Confirmed
red→greenon Linux on two vendors (the PR's runs are both on Windows: RTX 3080 and an RDNA 2 iGPU).Tested
Ubuntu 26.04, GCC 15.2.0, Release,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, device selected withVK_ICD_FILENAMES, run as./agc_driver_stencil_replay_tests, onmaina6dcea927(this PR applies cleanly on it; head62a5b6cea).agc_driver_stencil_replaymaina6dcea927+ the PR's test only (ShaderResources.cppreverted)With
ShaderResources.cppreverted and the PR's new case kept, the run exits non-zero on both devices with:That is the
Requirethis PR relaxes: with the stencil-replay path the fragment push range is shrunk to the reference dword, so as_buffer_load_dwordof the color through a buffer descriptor in user data leaves the shader data in a buffer past the push constants. With the full PR, the new case ("dynamic reference keeps guest buffer offsets in shader data outside the push constants") colors every pixel from the buffer and passes on both devices.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:52:18Z.
Review: CHANGES_REQUESTED
This reproduces a real failure and adds a useful buffer-backed regression. There is, however, an earlier open PR (#8615) that implements the same fix in the same
ShaderResources::buildPreparebranch: it also replaces!push.empty()with a check of the shader-data bytes beforestencilReferenceDword, and routes the no-shader-data case throughdataByte. This is the same behavior, not just an adjacent edit, so the checklist claim that no open PR implements it is currently inaccurate. Please coordinate with #8615's author and the maintainers so the fix has one authoritative PR; if your buffer-offset variant adds distinct coverage, agree on transferring/combining that test without duplicating the implementation.The reported test runs cover the regression on Windows across an RTX 3080 and an AMD RDNA 2 iGPU, but the repository requires the paired AGC validation-layer run with
VK_LAYER_KHRONOS_validationloaded and aVUID-comparison. The description says that layer was unavailable. Please provide that paired run on a host where the layer is installed, and rerun the focused tests after updating from currentmain(the comparison base isa6dcea927, 53 commits behind the current tip).The hosted eligibility, conventions, intake, labels, and report checks pass; Linux/Windows product jobs are skipped. A separate reviewer reports Linux Vulkan runs on two vendors, but those are on the same older
a6dcea927baseline and do not replace the required validation-layer comparison. I did not run the tests locally because no matching checkout/build is available here.Imported from boykopovar/AnyPS5. Originally posted by Lindamea1 on 2026-10-22T08:12:31Z.
I'm the author of #8615. Its
buildPreparechange is the same as this one: it counts only the push bytes beforestencilReferenceDwordas shader data, and writes the offsets to the shader data buffer when there are none. #8615 already has the paired validation-layer run onmainand on the change (RTX 5090, Linux), and @ycbuzi ran its two stencil replay tests on Windows (RTX 4070 SUPER).Your case covers a route that #8615's doesn't. #8615's shader gets a shader data buffer only through its image, which needs registration modules (the pipeline library). With
APS5_NO_GPL=1its shader data fits in push constants, so withmain'sShaderResources.cppits case still passes inagc_driver_stencil_replay_no_gpl. Your shader's data is in a buffer because the push range is shrunk, so withmain'sShaderResources.cppyour case fails in both tests.I ran your case on top of #8615's change:
maind6eafa54d, RTX 5090 (595.99.02), Gentoo Linux, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1:agc_driver_stencil_replayandagc_driver_stencil_replay_no_gplpass. The layer loaded, and neither log has aVUID-line.ShaderResources.cppfrommain, both fail withAGC graphics: guest buffer offset lies outside the shader's push constants.To keep one implementation, either of these works for me:
Depends on: #8615.Which would you prefer? cc @MarcZX10
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-22T09:08:57Z.
@Lindamea1 thanks, option 1 works for me: please add the test case to #8615 as a separate commit with me as its author. I'll close this PR once it's there.
One note for the description: the case fails in both
agc_driver_stencil_replayandagc_driver_stencil_replay_no_gplwithmain'sShaderResources.cppbecause the fragment push range is shrunk to the reference dword (pixelPushBytes = 4), so its shader data is in a buffer with or without the pipeline library.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Lindamea1 on 2026-10-22T10:30:49Z.
@TheSovietWaffle Done: your test case is now the second commit of #8615 (
15803c7f1), with you as its author and its lines unchanged. I rewrote the commit message to describe only the test, since the fix is #8615's first commit. The description credits you and the Onimusha find (PPSA27836, #5769), includes your note on why the case fails in both tests (pixelPushBytes = 4), and cites your Windows runs and jotitadev's Linux runs from here.#8615 is rebased onto
main4777caca3. On that base, with the RTX 5090 (595.99.02, Gentoo Linux):ShaderResources.cppfrommain,agc_driver_stencil_replayandagc_driver_stencil_replay_no_gplboth fail withAGC graphics: guest buffer offset lies outside the shader's push constants. With the fix, both pass in 20 of 20 runs each.mainand on the branch (20 focused tests, listed in #8615's description) gives the same results on both: 19 pass andagc_driver_stencil_ref_exportskips. The layer loaded, and neither log has aVUID-line.It's in, so this one can be closed whenever you're ready. Thanks for the find and the test. cc @MarcZX10
AI-assisted: yes (Claude Code).
Pull request closed