perf(agc): reuse unchanged draw input snapshots across draws #276
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/276"
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 oneandonlydean on 2026-10-01T21:36:38Z.
What
A recorded draw binds a CPU copy of each read-only guest buffer it reads in place (
ShaderResources::PrepareDrawBindings, from #76), and the copy is made for every draw. When the draws of a frame bind the same large buffers many times, most of the draw's time goes into those copies.The recorder now keeps the snapshots in a cache (
Recorder::ReusableDrawSnapshot/KeepDrawSnapshot), keyed by guest address and size, least recently used first, under a 256 MiB budget and 1024 entries. A later draw of the same range binds the kept copy, which is immutable once filled, only while both of these hold:GuestMemory::UnchangedSinceholds for the write generation collected right before the copy. A CPU store (stamped by a later collect) or a driver or GPU store (MarkWritten) fails it.Anything else makes the next draw copy again. Unwatched memory has no generation and is copied for every draw, as before. The draw collects its range before the lookup, so every store made so far is stamped before the check. A recency list, in which each entry holds its own position, gives the eviction victim and moves a used entry to the back in O(1).
The proof is the write tracker from #121 plus the registry generation from the recorder in #5. The misaligned-snapshot range from #202 (
item.address - item.adjustment) is the key, so the reused copy covers the same bytes the shader offset points into.Measured in PPSA21564 on my integration branch:
std::_Rb_tree_incrementwas 8% of the graphics queue worker's samples. The O(1) recency list removes that.Tested
agc_driver_recorder_tests. This is a GPU test that is built but not part of ctest, like the other recorder tests.drawSnapshotReuseTestsmakes a write-watched, host-imported range and binds it throughPrepareDrawBindingstwice. It requires the same snapshot both times. It then requires a new copy holding the new bytes after a CPU store, aMarkWrittenstore and a registry mutation, and requires the recopied input to be kept. On current main it fails with "an unchanged draw input was copied again"; with this branch it passes.drawSnapshotEvictionTestschecks the least recently used order at the entry cap and that replacing an entry evicts nothing else. It also checks that a budget-sized snapshot evicts the rest and that a CPU store drops a kept snapshot. It uses the new API, so it has no main counterpart.ctest --test-dir build --timeout 120: 96/96 pass on current main with this branch.agc_driver_recorder_tests,agc_driver_graphics_testsandagc_structurizer_testspass when run directly.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository