fix(agc): order driver stores over a depth plane by record order #15621
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15621"
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 Astronaut10 on 2026-11-03T22:11:33Z.
What
#12238 reloads a sampled single-sample D32 Z64KBX depth plane from guest memory when the tracker says the guest wrote it after its bind. The tracker also stamps the driver's own stores, by when they are stamped rather than when their results were recorded. In Astro Bot (PPSA21564) Aerial Garden a colour image aliasing a 1920x1080 depth plane is stored once per frame by the bind's own mirror refresh, after the bind took its generation, with results recorded before the bind; at the sample all 135 units look guest-written and the drawn depth is replaced by colour bytes, so the cloud sea and haze render as teal water.
This keeps #12238's reload and orders driver stores against depth draws:
NextRecordOrder).KeepNewerDepthUnitslets a driver store (storage image layer stores, the direct and copied-back branches ofGuestBufferMemory::WriteBack) invalidate only units whose last draw was recorded before it, asStorageTexture::StampKeepingNewerResultsalready does for storage images.SyncFromMemoryfirst stores pending images inside the plane (not its own mirror), so stores its refresh would trigger fall inside the bind's generation.GuestWriteAfterDrawCase) is still reloaded.markWrittenPages) carry no record order and are excluded from this fix; listed indocs/dev/debt/libSceAgcDriver.md.New test
AliasedStoreAfterDrawCase(image results pending over the plane, bind + draw, image stored, sample = drawn depth, plane store writes drawn depth to memory, plus the record-order guard called directly with a GPU write recorded before / after the draw; an imported-buffer completion is not exercised end to end). New ctest entryagc_driver_depth_plane_sampling_unimported(APS5_NO_HOST_IMPORT=1): with host imports on, the write-watch cases of this suite (#12238'sGuestWriteAfterDrawCaseand the new case) print "no write watch" and return without checking, while the rest of the suite runs; this entry runs them.Related: #15551 (open) changes the line after the one this adds in
GuestBufferMemory::MarkDirectWrites(the storage image write order taken under the tracker lock); the two order different things and compose, but whichever merges second needs a one-line rebase.Tested
Linux (CachyOS, kernel 7.3.0-4-cachyos), AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.5-arch3.1, Astro Bot PPSA21564 01.007.
On
main086c0686c8(this branch,eab4ee3ac6):ctest -R 'agc|guest_memory'withANYPS5_REQUIRE_VULKAN=1: the same statuses asmainplus the new entry (passed), 1,288 against 1,287.agc_driver_scattered_runsandagc_driver_tessellation(segfault) fail onmainas well.agc_driver_depth_plane_samplingand_evictingprint "no write watch" for the two write-watch cases;agc_driver_depth_plane_sampling_unimportedruns them and passes.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -V),mainand this branch: layer loaded in both (vulkaninforeports it; no "was not found but was requested" line), 244 and 245 passed, the same sixVUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605lines (all fromagc_driver_srgb8_color_target) and 20WARNING-VkImageSubresourceRange-layerCount-compatibilitylines in both; this branch adds noVUID-.APS5_DUMP_FRAMES=40, every 25th frame, one run per side):mainhas no cloud sea (bottom third 1-3 % white in all 11 in-level dumps; the first shows teal water where the clouds are), this branch has it (80, 71, 61, 50, 37, 21, 10, 6, 2 % in its 9 in-level dumps, falling as the camera leaves the clouds, the same course as on the earlier base). Frames available on request.On the earlier base
3ab5a11d66(the same change as450bc82830, before the rebase; the cost numbers below were not repeated on currentmain):GuestWriteAfterDrawCase(PPSA05684's regression case) passes; PPSA05684 itself was not run.APS5_PROFILE_DRAW, 2 runs per side, against the base with the line removed) puts the new code's own cost at about 3 ms per frame of draw-thread time, mostly waiting for the storeSyncFromMemorynow makes at the depth bind; that thread was about 74 % busy and the frame did not get longer, so it did not show on the critical path there.tools/trace_digest.pyof theaps5-summary.jsonlof one adjacent pair (APS5_TRACE_SUMMARY_EVERY=10, the level starts at about 19 s, the measured window is 40 s after it); the summary files of all eight runs are available on request. NoAPS5_TRACE_FRAMESwindow trace was captured for these runs.base
3ab5a11d66this change (450bc82830 on
3ab5a11d66)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)🤖 Generated with Claude Code
https://claude.ai/code/session_015W3M6Kw7yNRginUW6VUeE2
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T22:55:35Z.
Review: APPROVED
Reviewed — approved
The fix is now ordered by record order: storing a depth plane's pending aliasing images before
SyncFromMemorytakes its generation, and keeping units drawn after a driver store, restores the drawn depth. Each half is covered by a check inAliasedStoreAfterDrawCasethat fails when that half is disabled.What I ran
Head
eab4ee3ac6013f9d82b969ddd775ab1ee8fb929d,main1c8c0efc8c41314402e6966da5bef6ea3d639d10, merged tree9dd4f135b3e899321d23e326c68162fadb65808f(Debian 13 VM, GCC 14.2.0, lavapipe Mesa 26.1.6 / LLVM 19, no GPU).Results
git diff --checkcheck_conventions.pylibs(script)mainagc_driver_depth_plane_sampling/_evictingagc_driver_depth_plane_sampling_unimported(new)VUID-lines, no "was not found but was requested"agc_driver_image_gather_volumeVkSamplerCreateInfo-addressMode*VUID lines with the PR, the same 8 withmain's production files, so they come frommain. The PR does not touch sampler codeVUID lines, image_gather_volume, merged tree and main production files (identical)
Negative control
With
main's production files fully restored, the new test cannot build, because it callsNextRecordOrderandKeepNewerDepthUnits. So I disabled each half of the fix separately in the merged tree:StorePendingImages(resource)call inSyncFromMemory(core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp:1367) removed.agc_driver_depth_plane_sampling_unimportedfails:D32 plane drawn after an aliasing image's results were recorded, sampled after those results were stored: texel 0 read 0x3f800000, expected 0x3e800000KeepNewerDepthUnitsmade to always returnstamp()(DepthSurface.cpp:3206).agc_driver_depth_plane_sampling_unimportedfails:D32 plane sampled after a GPU write recorded before its draw completed: texel 0 read 0x3e800000, expected 0x3ec00000Both match the messages in the description. In both variants the two import-on entries still pass, because they skip these cases. Afterwards I restored the merged files, rebuilt, and reran the three entries (all passed).
git status --porcelainwas empty.Findings
Blocking
None.
Non-blocking
KeepNewerDepthUnitscalls in the test (core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp:410and:414). Two paths have no test that fails without them: the wrapper inStorageTexture::writeBackLayers(core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:6606-6626) and the twoGuestBufferMemory::WriteBackstamps. The description already says the imported-buffer completion is not exercised. Suggestion for a follow-up: a case where an image's results are recorded before a depth draw over the same plane and stored only after it, outside any bind, so that only thewriteBackLayerskeep protects the drawn units.KeepNewerDepthUnitstakesGpuMutexand thensurfacesMutex, the same order as the rest ofDepthSurface.cpp; both mutexes are recursive.stamp()runs outside both locks.FlushPendinggathers its list underpending.mutexafter takingGpuMutex, so calling the keep fromwriteBackLayersadds no inverted lock order that I could find. The post-stamp re-check usesUnchangedSinceCollected, which ignores driver stamps, asStampKeepingNewerResultsdoes.docs/dev/debt/libSceAgcDriver.mdstates the remaining gap (BDA completion stamps throughmarkWrittenPagescarry no record order). It links a file that exists (Graphics/src/BdaResources.cpp, which definesmarkWrittenPages) and is in the right debt file. No code comments were added.Not verified
GuestWriteAfterDrawCasepasses (in the unimported entry).markWrittenPages) and imported-buffer completion paths end to end.Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-06T09:24:49Z.
Review: APPROVED
Windows run with AMD's own driver, on the integrated Radeon of a Ryzen 7 7700X, and on an RTX 5070 Ti. The earlier AMD results here are RADV on Linux and the Windows ones are Intel and NVIDIA. Everything passes, both halves of the fix are covered on both GPUs, and nothing regresses.
Head
db1f5844d8merged ontomained41d86d32(clean merge, local only). Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, no missing-layer line,ANYPS5_GPUselecting the device, confirmed bySelected GPU:1002:164e, integrated), AMD 26.10.2 (32.0.21045.20006)10de:2c05), 621.01Depth-plane tests. All 16
agc_driver_depth_plane_*tests onmain, and the 17 on this PR (with_sampling_unimported), pass 3 of 3 on both GPUs. NoVUID-lines. Write watch works on both devices (host imports of write-watched memory keep the write watch: yes), so the two write-watch cases run in every entry: no "not checked" line, and_sampling_unimportedpasses instead of skipping.Red checks, each a local edit of the merged tree, 3 runs per GPU of
agc_driver_depth_plane_sampling,_sampling_evictingand_sampling_unimported:StorePendingImages(resource)removed from the syncD32 plane drawn after an aliasing image's results were recorded, sampled after those results were stored: texel 0 read 0x3f800000, expected 0x3e800000KeepNewerDepthUnitsreturningstamp()before it collects the units to keepD32 plane sampled after a GPU write recorded before its draw completed: texel 0 read 0x3e800000, expected 0x3ec00000A revert of the six driver files to
maindoesn't build, because the test callsNextRecordOrderandKeepNewerDepthUnitsdirectly. So these edits keep the functions and switch off one half each.Whole AGC set.
ctest -R '^agc' -j 8 --timeout 300: 1,387 of 1,389 pass on the RTX and 1,386 on the Radeon. Those are the same failures asmainon this machine, plus the new entry, which passes. All are tracked:agc_driver_direct_write_completion(#15564),agc_driver_quad_pixel_maskon the RTX (#14341), and on the Radeonagc_driver_scratch_pool(#15566) andagc_driver_sample_order_grid_reference(#9503).check_conventions.py --base mainpasses. Astro Bot itself isn't tested here.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:14:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected code and reported checks support merging.
What I ran
Reviewed head
db1f5844d8f379ce0c0770e82b3870d02d43cffe. No commands or tests were run in this review; the test and hardware results below are author-reported.Read
description.md,commits.md,manifest.json,diff.patch, and the full text ofDepthSurface.hpp,GuestBufferMemory.hpp,Texture.hpp,DepthSurface.cpp,GuestBufferMemory.cpp,agc_driver_depth_plane_sampling_tests.cmake,DepthPlaneSampling.cpp, andlibSceAgcDriver.md. Read the changed portions ofTexture.cppthroughrepo_read.py; its full text was excluded from the review folder for size.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full
Texture.cppfile was not read; targeted changed sections and nearby call sites were read throughrepo_read.py. No tests, builds, or console runs were performed independently. The reported test and Aerial Garden results were not independently verified.To get this to a good state
Nothing is required.