perf(agc): skip heap mirror blocks whose bytes already match guest memory #16188
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16188"
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 sktharunbalaji13-cmd on 2026-11-05T20:24:52Z.
What
An address-based build refreshes every 64 KiB block of a heap mirror whose tracker stamp is newer than the mirror's generation. Blocks that the driver itself stamped after writing GPU results back to guest memory are flagged the same way as blocks the title wrote, so a resident or plain heap mirror copied them again although it already held those bytes, then staged them and transferred them to the GPU. In Ghost of Tsushima about 1340 to 1370 of the roughly 2040 blocks flagged per build were byte-identical re-copies.
compareBlocknow compares the guest bytes with the mirror before copying. When they match it advances the block's generation without copying andcompareBlocksdoes not mark the resident block changed, so no staging copy or GPU transfer follows. A block whose bytes differ is copied exactly as before. Sparse fill blocks, unbound resident blocks and mirrors without write watching (generation 0) keep their previous behaviour: an unwatched mirror has no record of which bytes changed, every one of its blocks is flagged on every build, andagc_heap_mirror_unwatch*require all of them to be copied. The first commit compared those blocks too and failedagc_heap_mirror_unwatchandagc_heap_mirror_unwatch_no_space_cachein the Windows check; the second commit restricts the comparison to blocks with a nonzero generation.New regression tests
a block stamped without a byte changeinBdaResources.cpp(heapMirrorTests) and inResidentHeapMirror.cpp(ResidentTests) stamp a block withMarkWrittenand require that the next build compares it without copying it.tools/pr_overlap.pycould not compare the 26 open PRs that conflict withmainand touch these files, so I read their patches: none skips a copy by comparing first. #15296 (needs rebase) rewrites the resident branch ofcompareBlockto drop the host copy; it does not change the plain heap path or the stamped-block case.Tested
Windows 11 26200, AMD Ryzen 7 7840HS, 16 GB RAM, NVIDIA GeForce RTX 4060 Laptop GPU (8 GB), driver 617.42.
Focused tests,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "agc_(heap_mirror|sparse_heap_mirror|address_copy_cap|address_space_unwatched|sparse_buffer|driver_graphics|graphics_profile|driver_address_space_teardown|driver_resident_heap_mirror|driver_address_draw_space_reuse|driver_host_import_windows)" -V:agc_heap_mirror_unwatch*,agc_sparse_heap_mirror_*andagc_address_copy_cap*GuestBufferMemory.cppchange reverted (same new tests, run with the nine-test patternagc_driver_(address_draw_space_reuse|host_import_windows|resident_heap_mirror|graphics|address_space_teardown)before the second commit):agc_driver_resident_heap_mirrorandagc_driver_graphicsfail, the other seven passVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERSGhost of Tsushima Director's Cut (PPSA02225), same launch and scene,
APS5_TRACE_SECONDS=60:25,APS5_PROFILE_DRAW=1, four 145 s runs back to back, alternating without and with this change. The two builds are local scratch builds of one tree that differ only in this change:d842941d04e3without it,f3222bb7c416with both commits of this PR. That tree also holds the known-zero scan fix from #15967 that this title needs on 16 GB RAM, the joined-import fix from #16130, trace counters and unmerged depth-surface experiments that are not part of this PR (a read touch before a depth range takes its write generation,APS5_SOFT_DEPTH_CHECKS=1, last-writer-wins publication over colour targets); the scratch commits are local. This branch is rebased onc4469b60daand the change applies there without edits.d842941d04e3d842941d04e3f3222bb7c416f3222bb7c416Per build, the change takes the copied blocks from about 1340 to 1370 of the roughly 2040 flagged blocks down to about 130, which is what it is meant to do. The effect on the frame rate of this title is modest and noisy with two runs per build: presents in the 25 s window 89 and 93 without, 101 and 105 with (+13 % on average), frame time p50 187 and 184 ms without, 156 and 171 ms with, GPU busy per present 67.0 and 70.8 ms without, 51.5 and 56.6 ms with. Every run also contains one frame of 5.3 to 6.4 s, with and without the change, and with about 100 frames in a window the p99 column is just the second slowest frame, so it does not separate the builds. Mirror prepare per build (46 to 62 ms) did not change beyond the spread between the two runs of one build; compare per build is 1 to 2 ms shorter. The window still averages only 3.6 to 4.2 fps: this PR removes wasted copies, and the rest of the frame time is the per-build work left under the GPU mutex.
An earlier A B A B pair on the same machine, from one build with the change compiled out for A and in for B (memcmp-2026-11-06), agrees: copied blocks per build 1127 and 1135 become 144 and 125, and presents in the window go from 102 and 85 to 144 and 135.
trace_digest.py summary lines (without this change C1a, C1b, then with it C3a, C3b)
trace_digest.py output (first lines of each run)
C1a
C1b
C3a
C3b
Traces, digests, the fps and
[address]lines of all four runs and the ctest logs: https://github.com/sktharunbalaji13-cmd/AnyPS5/tree/evidence/got-ram-logo/ghost-of-tsushima/commits-2026-11-06Checklist
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, OpenCode, Command Code and Gemini