perf(agc): stage recorded draws' written buffers in device memory #15887
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15887"
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 TripyFox on 2026-11-04T22:12:59Z.
What
Recorded draws now get the device-local staging that dispatches already use. If a recorded draw writes a buffer element inside a host import, or does atomics on one, and the element fits the staging window, the element is copied to a device-local buffer. The draw is bound to that copy, and
RecordCopyBackscopies the changed bytes back. Recorded draws already reachRecordCopyBacksthroughMarkGpuWrites.Staging is not used in three cases:
HasStagedCopies). It is rebuilt unstaged, the same way a build with moved ranges is today, because a CPU-side store cannot write a device-local copy.APS5_NO_DRAW_STAGING=1keeps draws' elements in place. The new row is in docs/dev/ENVIRONMENT.md, the Device-local staging debt entry names recorded draws, and a new Draw device-local staging debt entry records the per-use whole-element copy.Cause, from #15560: ASTRO BOT's clustered light assignment is a pixel shader that
ds_appends on GDS. It scatters 8 B and 12 B node records into 8 MiB and 12 MiB buffers. Those buffers are host imports in system RAM, so every store crosses the bus. The draw took about 16 ms of GPU time per frame on an RTX 5090. The atomic is not the cost. In a RenderDoc replay of the same frame, three variants show this:With this change the draw takes 8.6 ms (
APS5_PROFILE_GPU=1, attribution only). The 12 MiB buffer stays in host memory because it exceeds the 8 MiB written-staging window on a discrete GPU.Tested
Windows 11, NVIDIA GeForce RTX 5090, driver 621.01, Ryzen 7 9800X3D, ASTRO BOT (PPSA21567) 01.019.000, Crash Site, 3840x2160, no input.
The A/B/A/B runs were 240 s each with
APS5_TRACE_SUMMARY_EVERY=10 APS5_TRACE_BENCH=1after a warm-up run, in the order main, change, change, main. The figures are means over the intervals from 40 to 240 s.tools/performance_compare.pyon matched 10 s intervals at about 150 s:On a local stack of open PRs (#15569, #9712, #15456, #10678, #15682) with
APS5_NO_LABEL_READBACK_STORE=1, the same change gave p50 −5.7 ms (−7.6 %) and GPU busy −5.1 ms (−11.8 %).GPU tests: Windows 11, RTX 5090, 621.01, with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.New
agc_driver_recorded_draw_staging. A recorded pixel draw appends to the GDS and stores one record per fragment, by the returned index, into a 256 KiB guest buffer. The test checks four things:It runs a fresh build, a reused build, and a draw whose device-local heap reports full. That last run must refuse a staging shadow (
StagingShadowsRefused). On main, that check fails because draws never try to stage; the functional checks pass there.APS5_TRACE_STAGING=1shows the node buffer staged on the change and not withAPS5_NO_DRAW_STAGING=1orAPS5_SYNC_DRAWS=1. It passes withAPS5_NO_DRAW_STAGING=1,APS5_SYNC_DRAWS=1andAPS5_DRAW_TRANSITIONS=1, which takes the rebuild-unstaged branch. It also passed 5 of 5 repeated runs.36 related execution tests, the same on main and on the change, also with
APS5_NO_DRAW_STAGING=1: 35 pass, andagc_driver_vertex_elected_atomic_maxskips because the device runs vertex programs in subgroups. The tests are:Validation: no
VUID-messages on main or on the change.On the rebased branch (main
b611e634f7): all 37 tests pass with validation, also withAPS5_NO_DRAW_STAGING=1, and noVUID-messages appear.tools/check_conventions.py --base origin/mainreports "All conventions checks passed."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)Follow-up, not in this PR: the frame has six draws that bind the same two node buffers. Each staged use copies the whole element in and back. A 16 MiB draw window removes the GDS draw's cost entirely (<0.13 ms), but the extra copies cost 6.1 ms in and 8.8 ms out per frame. One device-local copy shared across consecutive GPU users, with CPU-write and foreign-user hazard checks, would keep most of the remaining ~8 ms.
🤖 Generated with Claude Code