perf(agc): copy a staged region in from the previous use's device shadow when nothing wrote it since #16648
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16648"
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 SP4C3B4R-8 on 2026-11-07T12:46:10Z.
What
A staged region (a written buffer element inside a host import that the work reads through a device-local copy) is copied in from the import before every use and copied back after it. When the same range is staged again and nothing wrote it since the previous use's copy-back, that use's device-local buffer already holds the import's bytes, so the copy-in now reads it (a device-to-device copy) instead of the import across the bus, and records nothing when the build reuses the same buffer.
GuestBufferMemory::NoteCarriedShadows, called fromShaderResources::MarkGpuWritesafter the copy-backs and the pending-write notes, remembers per staged range the device buffer, the recorder, the range's newest write note and the tracker generation.recordGpuCopiestakes the entry for the same range and uses it only when the recorder is the same, no newer write note overlaps the range (Recorder::NewestWriteNote), and a collect of the range finds no CPU store since (CollectWrites+UnchangedSince); otherwise it copies from the import as before. Entries are taken once, and the table is dropped when it holds more than 256 ranges or 512 MiB. A use whose copy-backs run after a dispatch run (AfterRun) has not copied back yet when the note is taken and is not remembered.APS5_NO_CARRIED_SHADOWS=1turns it off.In ASTRO BOT's Sky Garden one 3.85 MiB range is staged about 16 times per frame by consecutive dispatches; it was half of all staged bytes.
Tested
Windows 11 Pro 10.0.26300, Ryzen 7 7800X3D, RTX 5070 Ti (NVIDIA 610.88).
ctest --test-dir build -R "^(agc_adaptive_staging|agc_driver_recorder|guest_buffer_reuse|agc_recorder_kept_bytes)$" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 4/4 pass on main1be701e166and on this branch, noVUID-in either log, the layer was found.-lvl underwater_aerial_garden, warm shader cache,APS5_NO_LABEL_READBACK_STORE=1in both arms,APS5_TRACE_SECONDS=110:60. Same frames as main by eye.1be701e166565040b136APS5_PROFILE_GPU, separate runs)Two earlier pairs without a usable commit in the summary (cmake had a stale git path): main 3.98 / 4.00 fps, this change 4.47 / 4.29.
Summary lines:
trace_digest main
seconds 110:60 from present 1237: 239 presents, frame p50 252.2 / p90 257.4 / p99 262.7 / max 299.6 ms, GPU busy 155.4 ms per present
NVIDIA GeForce RTX 5070 Ti, NVIDIA 610.88, Windows 10.0.26300, 3840x2160, commit
1be701e166, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 513.6, Driver.Packet.memory_wait 483.9, Driver.WorkerWait 250.5, Driver.WorkerWait.dequeue_order 247.0, batch 156.1, Graphics.Draw 33.3, Graphics.Draw.draw_and_resource_release 18.7, Driver.Packet.draw 12.8, Driver.Draw 12.7, Driver.Packet.prepare_memory 11.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest this PR
seconds 110:60 from present 1271: 266 presents, frame p50 226.6 / p90 232.3 / p99 238.7 / max 281.1 ms, GPU busy 132.7 ms per present
NVIDIA GeForce RTX 5070 Ti, NVIDIA 610.88, Windows 10.0.26300, 3840x2160, commit
565040b136, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 461.5, Driver.Packet.memory_wait 435.5, Driver.WorkerWait 225.5, Driver.WorkerWait.dequeue_order 222.3, batch 132.7, Graphics.Draw 25.9, Graphics.Draw.draw_and_resource_release 16.9, Driver.Packet.prepare_memory 11.2, Driver.Packet.draw 10.0, Driver.Draw 9.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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_01DuBfeZmGjNp1afSULCNKSu