perf(agc): store only the depth plane units a read overlaps #9026
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9026"
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 milescoviello on 2026-10-21T10:03:25Z.
What
Fixes #8840. A depth plane that a draw wrote is stored into guest memory when a read overlaps it. Until now, every such store copied the whole plane into its mirror, marked every unit pending and wrote the whole plane back. In Super Meat Boy 3D (PPSA31162), a small buffer whose range ends a few KiB into a 3840x2160 plane did this about 240 times a frame: 1,500 to 1,900 write-backs of the 31.9 MiB plane per 10 s. The measurements on #8840 put nearly all of that time in the write-back and the recorder wait before it, not in recording the mirror copy.
This stores only the 64 KiB units a read overlaps. @MarcZX10 set out on #8840 what that needs, and this implements those parts together:
SW_64KB_Z_Xis one 128x128 tile of a 4-byte plane. The pipe/bank XOR only permutes bytes inside a block, so a unit's texels are one rectangle. A new tiling test checks this for a 3840x2160 plane. A draw that writes depth marks every unit stale. A buffer upload, aGuestBuffersV#, an image lookup or a pending-store flush stores the stale units it overlaps, and the plane stays registered as stale until no unit is. A color target or a written storage image over the plane still stores all of it (DepthPlaneScope::Whole), since the surface is retired right after.StoreDepthPlanecopies the selected units' rectangles (StorageTexture::UnitRects) into the mirror, edge tiles clipped to the plane.MarkUnitsWrittenmarks only them pending, and the write-back covers their hull. A mirror without block units, or one with DCC, falls back to the whole plane.SyncFromMemorykept one plane-wide generation. It now keeps one per unit and asksGuestMemory::ChangedBlockswhich units the guest wrote since. Only those units are reloaded from memory and dropped from the stale set, so the guest's write wins there, as it did for the whole plane before. Untouched stale units keep their GPU depth. A store notes the generation of the units it wrote.retireStoringStalefirst stores the stale units the guest didn't overwrite.A plane whose address isn't 64 KiB aligned keeps one unit, the whole plane.
APS5_DEPTH_PLANE_WHOLE_STORErestores whole-plane stores everywhere, as a kill switch.DepthPlaneStoreCounts()counts stores, units and bytes for the test. The debt entry "Depth planes in guest memory" andENVIRONMENT.mdare updated.Tested
Ubuntu 24.04, GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02, on
main1381826358. The branch was then rebased ontomainb6fe513b9a. The only conflict was inDepthSurface.hpp, where #6683's two new declarations sit next to the changedFlushDepthPlanesone. On that base, the 31 depth tests pass 3 of 3 (32 with #6683's newagc_driver_sample_order_recipe_depth_locations, which fails here onmaintoo). The captures the perf label asks for are on this base as well.New execution test
agc_driver_depth_plane_partial_store(tests/execution/DepthPlanePartialStore.cpp). The plane is 384x200 D32 with the Z_X swizzle, six 64 KiB tiles, filled with 1.0, and a draw writes 0.5 over it:TextureTilingadds the Z_X check: no address bit of a 4-byte element reads x or y bits past one 128x128 tile, and sampled elements of a 3840x2160 plane fall in the 64 KiB unit of their tile.The new test ran all seven cases here, with write watching on (it says so when a case can't run).
Suites:
^agc_: 858 of 858 pass.depth|Depth|db_copy|DbCopy|^agc_driver_graphics$pass 3 of 3.main1381826358passes 30 of 30 and this head 31 of 31, with no VUID on either.@simonbbby ran the new test independently at
7bf7be589don an RTX 3090, RADV (gfx1036, Mesa 25.2.8) and lavapipe: 3 of 3 everywhere.APS5_NO_HOST_IMPORT=1(the copied-buffer configuration). With default imports on RADV and lavapipe, the memory isn't watched, and the test says so.APS5_DEPTH_PLANE_WHOLE_STORE=1makes the test fail on all three witha read ending 3 KiB into the stale plane did not store exactly its first 64 KiB unit, and it passes again without the switch.agc_driver_depth_storageandagc_driver_graphics, with the new tiling assertions, pass on each.Super Meat Boy 3D (PPSA31162), level 1-1 with the scripted route, release libs, 12 GB cap. Each 60 s run is measured in 10 s windows. Base (
mainf894ba69d3) and this change on it (ced0e2ac7b, the same two commits before the rebase) were run alternately, four pairs:depth plane storewrite-backs per 10 sEvery run of this change came out between 33 and 46 presents per 10 s, with the draw committer at 20 to 26 us per draw. That's the top of the fast group in #8840 (30 to 42). Base hit the slow mode of #8840 once (pair 1). In the other three base runs, depth plane stores were few, but the committer took 40 to 89 us per draw and presents were 15 to 27. I haven't tracked down what holds those base runs back. This change has more stores, but smaller ones, about 4 MiB each. The other services' CPU load on the machine was similar for both sides: 4.2 to 6.8 cores for this change, 4.7 to 6.5 for base. Level 1-1 renders the same on both: the in-level screenshots of pairs 2 and 4 match.
main745b394629on an RTX 4070 SUPER (NVIDIA 616.92, Windows 11, MinGW-w64 GCC 15.2.0 r7, Release).libSceAgcDriver,agc_driver_graphics_testsandagc_driver_depth_plane_partial_store_testsbuild without errors. The 29 tests those executables register on Windows, the newagc_driver_depth_plane_partial_storeamong them, pass twice (--repeat until-fail:2).Not tested: Intel; a title on AMD or Windows; other titles with stale depth planes.
Checklist
main; no other open PR implements the same functions (neighbouring lines: #6727 inDepthSurface.hpp, #7705 inENVIRONMENT.md, #8423 in the same debt section)NotImplemented_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
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T10:03:37Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T10:21:50Z.
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/Graphics/include/DepthSurface.hppL23-24docs/dev/ENVIRONMENT.mdL109docs/dev/debt/libSceAgcDriver.mdL80-81Some 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.
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/TextureTiling.cppdocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mddocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/ENVIRONMENT.mdcore/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppdocs/dev/ENVIRONMENT.mdImported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T11:01:55Z.
Captures, as the perf label asks.
Setup. Super Meat Boy 3D (PPSA31162), level 1-1 on the scripted route. Release libs, 12 GB cap, RTX 4070 Ti, driver 595.99.02, Linux.
APS5_TRACE_SECONDS=210:10falls inside the level, andAPS5_TRACE_SUMMARY_EVERY=10was set. The two sides aremainb6fe513b9aand this PR's head7bf7be589don it. Traces, full summary files and digests are in this release.This base run came up in the middle mode (22 to 26 presents per 10 s), not the slow one. Two earlier untraced pairs on the same two builds:
mainpresents per 10 smaindepth plane write-backs per 10 sThe 210:10 window:
mainThe PR's trace reports dropped events. Queue worker 0x0's event buffer filled 9.6 s into the 10 s window, and 11,952 events were lost; the summary line's
trace_dropped_threadshas the details.main's summary line:This PR's summary line:
tools/trace_digest.py,mainseconds 210:10 from present 1294: 23 presents, frame p50 428.1 / p90 526.0 / p99 562.6 / max 562.6 ms, GPU busy 105.4 ms per present
NVIDIA GeForce RTX 4070 Ti, NVIDIA 595.99.02, Linux 6.8.0-147-generic, 3840x2160, commit
b6fe513b9a, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 823.8, Driver.Packet.memory_wait 437.9, Driver.Packet.draw 269.4, Driver.Draw 268.2, Graphics.Draw 203.1, Graphics.Draw.draw_and_resource_release 187.6, batch 105.4, Resources.Complete 96.9, Driver.Draw.prepare 78.8, Driver.Draw.draw_enqueued 62.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.py, this PRseconds 210:10 from present 1355: 37 presents, frame p50 271.5 / p90 315.3 / p99 321.6 / max 321.6 ms, GPU busy 106.7 ms per present
NVIDIA GeForce RTX 4070 Ti, NVIDIA 595.99.02, Linux 6.8.0-147-generic, 3840x2160, commit
7bf7be589d, dropped: yesSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 479.3, Driver.Packet.memory_wait 269.9, Driver.Packet.draw 116.0, Driver.Draw 114.9, batch 106.2, Graphics.Draw 74.5, Graphics.Draw.draw_and_resource_release 61.5, Driver.Packet.dispatch 46.5, Driver.Dispatch 42.2, Driver.Draw.prepare 35.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-21T12:25:36Z.
Independent Linux check at exact head
7bf7be589d68688bdb74e41a240b4a3ce1881f0f, including AMD and the CPU-write cases through the supported copied path:agc_driver_depth_plane_partial_store_testsAPS5_NO_HOST_IMPORT=1APS5_NO_HOST_IMPORT=1The no-host-import runs use the documented copied-buffer configuration, not a forced import-watch override. Neither “not exercised” message appears in those logs. Thus they check unit 4 retaining the CPU's 0.75 and being reloaded into GPU depth (the LESS draw's exact coverage assertion), plus unit 2 retaining the CPU write while the other stale units survive retirement. They do not supply that coverage under RADV's default import policy.
Negative control:
APS5_DEPTH_PLANE_WHOLE_STORE=1makes the same test exit 1 on all three ICDs witha read ending 3 KiB into the stale plane did not store exactly its first 64 KiB unit. Fresh processes without the switch pass again on all three. This distinguishes the partial-store behavior from the PR's whole-plane fallback; it is not a separate main checkout comparison.agc_driver_depth_storage_testsalso passes on each ICD, andagc_driver_graphics_testspasses, including the newRunTextureTilingTeststile-address assertions.Ubuntu 24.04.3, GCC 13.3, Release; RTX 3090 / NVIDIA 595.99.02; gfx1036 (
1002:13c0) / RADV Mesa 25.2.8; lavapipe Mesa 25.2.8 / LLVM 20.1.2.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1. No Khronos validation layer available here, no title execution or performance measurement. No source edits; checkout remains clean at the exact head.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T12:31:53Z.
Thanks @simonbbby, that is a thorough check. The
APS5_NO_HOST_IMPORT=1runs cover the two guest-write cases on RADV and lavapipe, which their default import policy leaves unwatched, and the whole-store control shows the test catches the difference. I added it to the Tested section and the GPU line.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T17:51:21Z.
Windows run of
7bf7be589dmerged ontomain745b394629(ac0c200863, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON. RTX 4070 SUPER, NVIDIA 616.92 (ANYPS5_GPU=4070).Built
libSceAgcDriver,agc_driver_graphics_testsandagc_driver_depth_plane_partial_store_testswith no errors. The build prints twomemcmpbound warnings, whichmainprints the same way fromGraphics/src/PipelineLibrary.cpp, a file this PR does not change.ctest --repeat until-fail:2on the 29 tests these executables register on Windows: all pass on both repeats. The 29 include the newagc_driver_depth_plane_partial_store. Not run: a title.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T17:52:59Z.
Thanks @ycbuzi, that covers Windows for the build and the tests, including the new partial-store test. I added it to the Tested section and the GPU line.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T19:31:06Z.
Checked the per-unit stale state, partial copy of the Z_X tiles, per-unit guest-write precedence and the retire path against the diff, and re-checked it merged onto current
main(the new idle-publish wait inTexture.cppdoesn't overlap the depth plane store path). The new test pins the memory contents per unit, and it fails withAPS5_DEPTH_PLANE_WHOLE_STORE=1(@simonbbby's negative control on three GPUs). Linux and Windows runs by @simonbbby and @ycbuzi cover the tests on NVIDIA, RADV, lavapipe and Windows; merged.