perf(agc): allocate Windows write-tracking stamps on demand #6701
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6701"
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 eljackjoestar-cmd on 2026-10-16T05:17:07Z.
What
Windows write tracking eagerly allocated three generation arrays for every 64 KiB block in the 1000 GiB guest arena, even when almost all ranges were unused. Reuse the existing Linux sparse leaf layout on Windows, adding the Windows untracked-hint stamps to each leaf. Allocate a leaf only when a store stamps one of its blocks; reading an absent leaf returns zero and does not allocate. Range checks use the existing leaf walk and skip absent leaves.
Each touched 4 GiB guest region adds 768 KiB of stamp metadata. The existing coverage table remains dense. The tracking mutex, generations, CPU-versus-driver store distinction and import behavior remain unchanged. No graphics settings or shader semantics change.
Related/overlap: #6266 adds coarse summaries in
WriteTracker::stampandunchanged. This patch changes Windows stamp storage to the existing leaves; that summary optimization is separate and must retain the sparse storage when combined. No open PR implementing this Windows allocation change was found. This does not include the deferred-import settling of #6678.Tested
Windows 11 26300, Ryzen 7 7800X3D, 32 GiB RAM, WinLibs GCC 15.2 UCRT, Release. Component benchmarks used main
5d9dcc42d. The topic is now rebased onto main332b0b1b7 atfe95848f254e60ecd270e6bc996028ab2f3d5fb1; the measured production GuestMemory.cpp blob remains byte-identical (f5dd7b0f386a676ab03abc60e6858272e8ea9f96). Original benchmark baselines below are preserved. The component measurements below are CPU-only; a separate gameplay integration comparison follows.agc_write_tracking_metadata_commitwith main's production code fails:write-tracker initialization: 208940 KiB private commit for 1000 GiB guest arena, thenwrite tracking committed dense generation tables for untouched guest ranges.write-tracker initialization: 16552 KiB private commit for 1000 GiB guest arena. Queries of 250 untouched 4 GiB regions must not allocate leaves.agc_write_tracking,agc_write_tracking_metadata_commitandagc_write_watch_coverage: 3/3 pass, 0.31 s in the verbose run. Final checks also pass.CPU-only before/after measurements: seven alternating pairs on the same machine, identical compiler/dependencies, each process pinned to logical CPU 2. Values below are medians; initialization memory is the increase in process private commit, measured after reserving the guest arena and before/after initializing the tracker.
5d9dcc42dThe hot check is slightly slower in this sample, while empty-range scans and initialization improve. These are component measurements, not whole-game memory or FPS measurements. No game or Vulkan device was started. As more guest regions are stamped, leaves allocate and the memory saving decreases; a touched 4 GiB region adds 768 KiB.
Benchmark provenance: baseline
5d9dcc42d2ec5401aebd089028b8d4d7410a77b4; candidate3ba2b03045059a18ee8300d67d92280164e55496. The pre-rebase PR head24f2ac4098ddfb9f71989f34d0a3990444ebe8b3only removes blank lines from the test relative to that candidate; the measured productionGuestMemory.cppblob is identical (f5dd7b0f386a676ab03abc60e6858272e8ea9f96).Raw before/after samples (seven alternating pairs)
Pair order alternated before→after, after→before. Commit values are bytes; times are per query except initialization.
git diff --checkpass.In-game integration comparison (16 October)
Lost Soul Aside (PPSA26358), same PC and RTX 5070, fullscreen, 3840x2160 render resolution and unchanged quality settings. Baseline integration
825f012166e17ed358cf98f68814e3c816dab316on main5d9dcc42d; candidatedc9e14c22afbccee1bd6c9ebd4ae5ed6e169e574is that integration plus this exact topic commit. Only the patchedlibSceAgcDriver.prxchanged in the installed runtime; all other 132 manifest files were byte-identical. This is a comparison within the gameplay integration, not a stock-main compatibility test. The unrelated deferred import settling of #6678 is excluded on both sides.Both runs used the same shared warm shader cache,
-onethread, normal guest clock, import budget 12288 MiB, texture cache 1024 MiB, copied-buffer staging, writable staging cap 8192 KiB, unused device pool 256 MiB, automatic title double-X, bounded logs and the existing resource guard. Profilers, samplers and GPU timing were off; no builds or other GPU tests ran concurrently. Each was deliberately stopped after its gameplay window; neither crashed or hit the guard. No graphics settings were reduced.Opening combat HUD directly verified with game-window PrintWindow captures. One sequential pair, 29 resource/title samples in each approximately 60-second window:
The title remains around 1–2 FPS in gameplay. This does not fix its overall performance problem. Combat AI, camera/animation and frame progression differ, so this single pair does not establish a causal whole-game FPS improvement or that the entire observed 442 MiB difference comes from this patch. The controlled component memory saving is the 187.88 MiB figure above. Rendering artifacts remain visible on both sides; audio correctness was not independently measured.
Integration checks after the full runtime build:
agc_write_tracking,agc_write_tracking_metadata_commit,agc_write_watch_coverage,agc_driver_host_import_windows,agc_driver_store_over_untracked,agc_driver_untracked_snapshot_hint: 6/6 pass, 1.86 s, GPU checks on RTX 5070.Current-main integration recheck after the rebase: write tracking, metadata commit, storage upload lifetime, split write-back, exact storage snapshot pixels and graphics checks: 6/6 pass,7.16s on the same RTX5070. The integration includes the retained gameplay fixes and local diagnostic timing; this is not a new exact-topic benchmark. Conventions and diff whitespace checks pass on the clean rebased topic.
Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T05:32:34Z.
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/Execution/src/GuestMemory.cppL919core/libs/prx/libSceAgcDriver/CMakeLists.txtL646Some 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/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T19:52:49Z.
Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;mainc84249186vsmain+ this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (45-47 ms of idle gaps per frame).mainAbove
mainin both rounds (mainwas flat at 6.60), with the idle gaps 2 ms shorter per frame. 0 fatal.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T12:07:29Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (driver 596.21), Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2, Release. PR head
fe95848f2merged on main673f7406c(clean), alone and stacked with #6598 (also clean). This adds the commit-charge measurement in titles.agc_write_trackingandagc_write_tracking_metadata_commit,--repeat until-fail:3: 3 of 3 each,write-tracker initialization: 16552 KiB private commit for 1000 GiB guest arena. Negative control: withGuestMemory.cppfrom main and the tests kept,agc_write_tracking_metadata_commitfails with208940 KiB private commit for 1000 GiB guest arena/write tracking committed dense generation tables for untouched guest ranges; restored, it passes.libspass on the stack. 25 related tests (write watch, registration preparation, allagc_driver_prepared_*, host import, untracked hints; serial) pass. Non-GPU suite (878 tests): 874 pass, 2 skipped;hardware_oracle_comparetimed out under load andguest_memoryfailed once under-j8(0xc0000409, alibkerneltest that does not load the driver); both pass serially.tools/check_conventions.pyandgit diff --checkpass.PrivateUsage, cross-checked withGet-Process) and working set every 5 s. Medians, MiB:RetroArch: -187 MiB private and -184 MiB working set at 30 s, the same at 60 s, i.e. the 188 MiB of dense tables, whole. PPSA99005: working set -183 / -186 MiB at 30 / 60 s (-185 at 10 s); private bytes -182 / -119 / -112 MiB at 10 / 30 / 60 s, smaller only because that title's own commit varies by 100 to 200 MiB between runs (per-run values at 30 s: main 3697 to 3850, PR 3541 to 3617). The working set moves too because main fills the tables with
vector::assign, which touches every page.GuestMemory.cpp(its WindowscoarseBlocksvector would have to move into the sharedLeaf, which its Linux branch already does). #6759 conflicts inhinted()and writestracker.hintBlocks[block] = 0directly, which no longer exists after this PR.agc_driver_*GPU suite. System-wide commit was no use as a signal on this shared host (it moved by several GiB per run from other work).Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T07:54:26Z.
Review: CHANGES_REQUESTED
Thanks, the sparse-leaf approach reads correctly and the new tests pin the right values (cross-leaf boundary, untouched-leaf queries, commit under 64 MiB).
Blocking: this conflicts with
mainsince192d95c5d(coarse 64-block summaries). On Windowsmainnow has a densecoarseBlocksvector,coarseStampOf, andstamp()/unchanged()that indexblocks[...]directly. Please rebase so that:LeafcarriescoarseBlocks(LeafBlocks / CoarseBlocks) next toblocks,cpuBlocksand the WindowshintBlocks, and the dense WindowscoarseBlocksvector and itsassignininitializeare gone;coarseStampOf,stamp()andunchanged()use the leaves on both platforms, and an absent leaf reads as 0 without allocating;stampWatchedPart/storedOvercode frommainkeeps working on top of that (no directblocks[...]access).After the rebase, rerun
agc_write_tracking,agc_write_tracking_metadata_commitandagc_write_watch_coverageon Windows, and check the untouched-leaf query test still shows no allocation with the coarse summaries inside the leaf.The
perflabel bot also asks for theaps5-summary.jsonllines frommainand from the change, plus thetools/trace_digest.pyoutput.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T12:21:32Z.
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 adriadam10 on 2026-10-19T20:17:00Z.
Rebase checked against the earlier points:
Leafnow carriescoarseBlocksnext toblocks/cpuBlocks(andhintBlockson Windows),coarseStampOf/stamp()/unchanged()go through the leaves on both platforms with absent leaves reading as 0 without allocating, and nothing indexesblocks[...]directly any more. The commit-charge and cross-leaf tests pin the right values; merged.