perf(agc): hash the pages of an import window on several threads #10655
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10655"
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 thuanquang on 2026-10-24T15:21:36Z.
What
GuestMemory::ImportWatchedhashes every watched page of an import run before the import and, after it, compares every page the import reports written with those hashes to tell the import's own reports from CPU stores made during the import. Both passes ran on the calling thread, which is the draw path when a draw needs a new host import.Both passes now split their pages over up to four threads (
std::jthread; at most half the hardware threads; at least 1024 pages, 4 MiB, per thread, so small imports stay on the calling thread). Each thread writes its own hash or result slots. The checks after the import now run once the walk has returned instead of from its callback, so they still hash each page after the walk reset its write watch, and a CPU store in the window is caught as before. Nothing else changes: the same pages are hashed and stamped with the same kinds.Why
On Windows the first touch of write-watched memory that was never touched faults each page in, and on an RX 6700 XT system (Ryzen 5 5600X) that costs more than hashing it. A standalone loop over 64 MiB of fresh
MEM_WRITE_WATCHmemory with this hash took 33 to 67 ms on one thread and 12 to 20 ms on four; over resident pages 7 to 13 ms on one thread and about 3.3 ms on four. Locking those fresh pages instead (VirtualLock) costs 47 to 57 ms, so skipping the first pass would only move the faults into the import.PPSA14363 (METAL GEAR SOLID - Master Collection Version, own dump) creates such imports at first use in the launcher's Master Book. On
main379b1dca32a sampled run attributed 35 to 45 ms of the 79 to 107 ms frame at the book's open to this hashing. Onmain2dc8e456b5the open frame is about 43 ms with or without this change, and the difference shows at the first page turn instead (below). I did not repeat the sampled attribution on2dc8e456b5.Tested
Current head
d1564becdb:maincbaacd2910merged in. OnlyGuestMemory.cppconflicted:mainadded a step that saves the bytes of spans leaving the watch (beforeUnwatch), right after the per-page hashing this PR replaces withHashPages. Both are kept: the spans are checked and hashed byHashPagesfirst, thenmain's save step runs unchanged. On this head the build is clean,agc_write_trackingandagc_write_tracking_metadata_commitpass 3 of 3, andctest -R "^(agc|shader)_"passes 1069 of 1072: the failures areagc_host_import_cut_lifetime,agc_driver_depth_plane_partial_storeandagc_driver_sample_order_grid_reference, the same three that failed onmainhere at the previous merge. The measurements below are from the head before these merges.Windows 11 26200, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, onmain2dc8e456b5.New check in
agc_write_tracking,CheckImportWindowAcrossThreads: a 16 MiB import window with one unwatched 64 KiB block in the middle and a distinct mark at the start of every page. Inside the window it rewrites the same byte on every watched page and stores new bytes in four blocks spread over the range. Every block must come out written or unchanged as stored, so both passes run on three threads here and a hash or result placed for the wrong page fails it.main'sGuestMemory.cppbefore the rebase (379b1dca32; the threads change no result).379b1dca32): placing each first-pass hash by its position in the page list instead of its address fails it at block 131, the first block after the unwatched one; checking the pages in reverse order after the import failsCheckImportWindow.agc_write_trackingandagc_write_tracking_metadata_commitpass 3 of 3.ctest -R "^(agc|shader)_"on this head passes 1001 of 1004; the 3 failures are thesample_ordertestsmainfails on this GPU.PPSA14363 (own dump), the launcher's Master Book from one stored save: the book opens at 61 s, then four R1 page turns at 81, 91, 101 and 111 s, all at fixed times after the first present. Same machine and scene for every run: RX 6700 XT, warm caches, the gpu and build locks held, nothing else on the GPU,
APS5_TRACE_SUMMARY_EVERY=10andAPS5_TRACE_SECONDS=78:40(a 40 s trace window over the four turns) and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. Base:main2dc8e456b513; candidate: this PR atd3d5e2f262f0(the head before the merge ofmainbelow). OnlylibSceAgcDriver.prxdiffers between the runs, checked by hash; thecommitfield of each summary line is the commit that library was built from. Six runs, alternating:Graphics.Draw.draw_and_resource_release2dc8e456b513d3d5e2f262f0d3d5e2f262f02dc8e456b5132dc8e456b513d3d5e2f262f0In every run
tools/trace_digest.pynames the first page turn as the slowest frame of the window, and that frame is spent inGraphics.Draw.draw_and_resource_releaseon the draw committer (last column): 73.7 to 113.0 ms onmain, 63.5 to 79.6 ms with this change. The other turns stay under 66 ms in both. In an earlier batch of 110 s runs over the open and two turns, the turn window's longest frame was 82.1 to 228.1 ms onmainagainst 61.0 to 63.7 ms with this change.Summary lines of runs 1 (
main) and 2 (this PR):The six traces are on our fork, at https://github.com/thuanquang/AnyPS5/tree/evidence/10655-traces. They hold only emulator scope and thread names and timings, and the summary lines above and the
trace_digest.pyresults come from them unchanged. Run 6's trace hastrace_dropped: true: the queue worker's buffer filled 35.8 s into the window. Its numbers in the table don't depend on the lost events (https://github.com/boykopovar/AnyPS5/pull/10655#issuecomment-6395559556).Not tested: Linux and macOS (the change has no platform branch; the Linux write watch reports runs to the same callback), other GPUs, and a title whose imports are under 4 MiB per thread.
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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:31:35Z.
Review: CHANGES_REQUESTED
I reviewed the parallel hashing and post-import write-stamp changes. The worker ranges are disjoint; hash results are stored by guest-page offset rather than worker order; write-run results are collected and hashed after the write-watch walk returns; and the new test includes an unwatched block between watched spans.
git diff --checkpasses. The reported focused Windows tests and GPU measurements are author-reported; hosted product jobs were skipped and I did not run them locally.The required performance evidence is still missing. This
perfPR has no pairedaps5-summary.jsonllines and no attached traces ortrace_digest.pyoutput; the repository requires those even though the current report includes frame-time observations and says the title traces cannot be shared. Please supply compliant evidence or remove the performance claim and resolve theperf numbers missingstatus. I found no separate correctness blocker in the reviewed diff.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:27:36Z.
Review: COMMENTED
The updated description now includes a same-machine/same-scene main-versus-head comparison, full summary lines with
trace_dropped: false, and trace-digest results; that addresses the missing paired-summary evidence from my prior review. The remaining repository requirement is to attach the performance traces:CONTRIBUTING.mdexplicitly requires the captures with the summary lines. The description says they are not attached because they come from a commercial title. Please attach the required traces, or remove the speed claim andperfclassification and retain this as a correctness-focused change. I have not independently reproduced the reported Windows GPU runs.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T22:30:49Z.
Review: DISMISSED
Reviewed exact head
85372834be8de468e4b9aa4f143ecca12f60b07b. The merge from currentmainadds no production change; the parallel page walk and post-import write-watch checks remain as previously reviewed. The new RADV report is a useful no-regression check across three GPU generations, with the focused tests passing and no new validation errors reported.The PR still carries the
perftitle/label and a measured title-performance claim, while its description says the traces are not attached.CONTRIBUTING.mdrequires the trace captures with the paired summaries. Please attach the required captures, or remove the measured speed claim andperfclassification and keep the PR scoped as a correctness-focused implementation. The latest RADV results validate behavior but do not replace the required main-versus-change performance traces. I have not run the Windows GPU comparison locally.