perf(agc): exclude only an import's own pages from the write watch and settle partial-block imports in the background #12378
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12378"
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 BunnyFl on 2026-10-28T12:03:42Z.
What
On Windows, a host import that stays compared takes its pages off the write watch through
WriteWatchCoverage::Exclude, which excluded every 64 KiB tracker block the import touches. The other pages of those blocks then left the watch with it, and collects over them were refused and fell to full revalidation walks. In a played DEATHLOOP session of about 5 minutes, about 94 % of the refused collects were on such neighbouring pages (#12329).Two changes, as discussed on #12329, and two fixes the first one needs:
WriteWatchCoverage::Excludeexcludes only the 4 KiB pages a range touches.CoversandRestorealready work per page. Each excluded page now keeps the generation of its own latest exclusion (excludedGenerationsholds 16 per block instead of one), so a later mapping of one page restores it even when a newer import excluded another page of the same block, and a stale mapping still can't restore a newer one.ExcludedSpanis unchanged: the unwatch hook still gets every 64 KiB block the pages touch, so pending storage results in those blocks are saved as before.importRunAt), not only markedsettleOnDemand(#9941).rewatchSettledImportsreturns its own pages; the existing guards still apply: it stays compared while a live storage image overlaps the span, or while another compared import shares a 64 KiB block with it.UntrackedHint's walk (walkHints) gives a CPU stamp to the pages it clears that are still on the watch (oneandonlydean's finding). With change 1,hinted()accepts a block an import only partly covers, and the walk clears the write-watch marks of the block's still-watched pages too; a covered range over such a page then found no mark and kept a stale copy. Every marked page still stamps the block hint, and a pagecoveragestill covers also gets the stampwalkWriteswould give it.stampWatchedPartskips a block thatblockPartWatchedreports unwatched, and on Windows that checked only the first and last page of the written range in the block. With change 1, a block whose two ends are excluded can still have watched pages between them; aMarkWrittenorMarkPossiblyWrittenacross it stamped nothing, soUnchangedSinceover a middle page could stay true after the write.blockPartWatchednow checks every page of the range.Tests:
agc_write_watch_coverageasserts the page policy: an import excludes only its own pages, a range crossing into an imported page is not covered, the other pages of the block stay covered,ExcludedSpanstill returns the whole block. New: a same-block, different-generation case (MarcZX10's regression on #12329): an older page restores while a newer page of the same block stays excluded, and a stale mapping does not restore the newer one. With page exclusion but one generation per block (my first version) it fails ona newer import of another page in the block kept an older page excluded; withmain's header it fails onan import unwatched pages of its block outside it.agc_write_tracking_rewatch_import_pages: the two cases that asserted the pages around an import (before it, and the reserved page past it) stay unwatched after a rewatch now assert they keep the state they had before the import. Withmain's header the revised test fails onunwatching an import ending inside a block changed the page past it. A collect over a reserved, uncommitted page still fails and falls back to the comparison, so treating that page as covered hides no write.tests/Recorder.cppcase (m): an import of whole and partial 64 KiB blocks now returns to the watch through the deferred settle before its first use (the first use submits no settle read; onmainit submits one); the case with a compared import in its last 64 KiB block is still refused.agc_hint_partial_block_store_{cached,uncached}(tests/Recorder.cpp): import pages 0-5 of a block, collect page 8, store to page 8 from the CPU, takeUntrackedHintover pages 4-9, thenUnchangedSinceover page 8 must fail. Without change 3 both fail ona hint walk across a partial-block import consumed a CPU store to a watched page; without theUntrackedHintcall they pass there too.agc_interior_watched_driver_write_{complete,possible}(tests/Recorder.cpp): exclude pages 0-5 and 12-15 of a block, collect page 8, then aMarkWrittenorMarkPossiblyWrittenacross the whole block, andUnchangedSinceover page 8 must fail. Without change 4 they fail ona complete driver write across a block with both ends excluded was not recorded on its watched interior pageanda possible driver write across a block with both ends excluded was not recorded on its watched interior page.agc_shared_block_rewatch_{cached,uncached}(tests/Recorder.cpp, ebosido444-ai's case): two imports exclude pages 0-5 and 8-11 of one block;Rewatchof the first, asrewatchSettledImportsdoes after its settle, must return pages 0-7 only, keep each of pages 8-11 excluded, keep the block unproven, and collect a CPU store to page 6;Rewatchof the second then returns the whole block. Onmainboth fail at their second check (two imports in one block excluded pages outside both), sincemainexcludes the whole block; their first check, that both imports are excluded, passes there.docs/dev/debt/libSceAgcDriver.mdanddocs/dev/ARCHITECTURE.mddescribe the page exclusion and the deferred read of partial-block imports.Tested
Windows 11 Pro 10.0.26200, AMD Radeon RX 9070 XT (driver 32.0.32015.7029), Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Head480ca2dff1is this branch withmainbb04a4f1eamerged in (this PR's diff is the same as on the earlier head9d619dee3e, rebased ontomain3a2b919816, which includes #8930'sWriteChangedchange); base ismainbb04a4f1eawith onlyagc_shared_block_rewatch_*added (tests/Recorder.cppand its registration inCMakeLists.txt, uncommitted, which is why its summary lines below say"dirty":true; no library source differs frommain).Focused tests, serial,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, 3 runs on each side alternating base and change:agc_write_watch_coverage,agc_write_tracking,agc_write_tracking_rewatch_import_pages,agc_import_alias_shared,agc_import_watch,agc_import_watch_other_family, everyagc_import_settle_*,agc_storage_kept_unit_settle,agc_storage_baseline_settled,agc_hint_mapping_history_{cached,uncached},agc_partial_watch_restoration,agc_collect_mapping_history_{map,ring,shared,uncached},agc_shared_block_rewatch_{cached,uncached}, and on the change alsoagc_hint_partial_block_store_{cached,uncached}andagc_interior_watched_driver_write_{complete,possible}(new here):VUID-linesmainbb04a4f1eaagc_shared_block_rewatch_{cached,uncached}at their second check (mainexcludes whole blocks)480ca2dff1Case (m) differs in every run: over the import of whole and partial 64 KiB blocks,
1 settle reads submitted, 1 back in the write watchonmainand0 settle reads submitted, 0 backhere, both accepted; over the compared import in its last 64 KiB block,1 settle reads submitted, 0 backonmainand0 settle reads submitted, 0 backhere, both refused.tools/check_conventions.py --base upstream/main: all checks pass.Performance, DEATHLOOP (PPSA01670 01.405.000), opening cutscene from a fresh save with scripted pad input, 3840x2160, captured as the Performance report form asks:
APS5_TRACE_FRAMESonly, no otherAPS5_TRACE_*/APS5_PROFILE_*switch (the otherAPS5_*variables in the lines areAPS5_FORCE_SDRand the scripted pad input), caches warm, one warm-up run, then 2 + 2 captures alternating base and change. Basemain3a2b919816, change9d619dee3e; the title was relinked with3a2b919816's relinker for both. Thetrace_digestoutput is in the comment below, with the traces attached there. These captures were taken before the merge ofbb04a4f1ea: this PR's diff is unchanged by it, butmainchanged 39 library source files underlibSceAgcDriverin between (none of the three this PR changes), so they measure this change on3a2b919816.aps5-summary.jsonllines (base 1, change 1, base 2, change 2, in capture order):With the default event buffers the 600-present windows don't fit: every line has
trace_dropped: true, withqueue worker 0x0full 35 to 59 s anddraw committer60 to 122 s into the window, and no thread's totals table filled (totals_full: false). So the summary lines' totals are complete, and so are the presents, but the traces (and thetrace_digestthread tables) hold those two threads' slices only up to the point their buffer filled. The draw counts the earlier comparisons used to find the cut into the cutscene are among the lost slices, so the cut is now found from frame times alone: the first present interval over 400 ms after the window's longest interval (the loading frame, 17 to 28 s here). On the four previous traces, taken withAPS5_TRACE_EVENTS=3145728and complete buffers, this finds the same interval as the draw-count rule and gives identical figures. The cut's first present moves between runs (the pad script is timed in seconds), so each window starts on the loading screen (APS5_TRACE_FRAMES=1650:600on base,2100:600on change). Over the same 300 present intervals in every trace, from 60 to 360 after the cut:Whole window, from the summary lines' totals:
Driver.Packet.memory_wait860.3 / 944.6 ms per frame on base vs 467.2 / 394.2 on change; GPU busy per present 51.8 / 46.8 vs 65.3 / 56.0.Earlier, with
APS5_TRACE_EVENTS=3145728added (so not to the form), same scene and builds: over 313 matched intervals, mean frame 252.9 / 239.6 ms on base and 92.0 / 92.7 ms on change. Onmain319621ba2ewith41eef2d043(306 matched intervals, the cut found with "under 100 draws" since one base trace had 66 draws just before its cut): 255.4 / 254.9 ms vs 93.5 / 98.4 ms; onmain2227f13661withafe34f6dbb(297 matched intervals): 290.4 / 268.2 ms vs 97.6 / 95.6 ms; all with that switch. With tibzejoker's port of #6192 on both arms, onmain3a40945e62: frame p50 196.9 / 168.2 ms on base and 95.7 / 94.0 ms on change. Before that (10 s summaries, details on #12329), page exclusion alone on plainmaindid not move the cutscene in one run each.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-28T12:05:46Z.
Review: CHANGES_REQUESTED
Reviewed the performance report and current PR body. The paired runs and reported per-frame measurements are useful, but this
perf(agc)PR does not yet meet the repository’s required performance-report evidence: I cannot find theaps5-summary.jsonlline formainand the line for this change, links/attachments for the two traces, or the output oftools/trace_digest.py. Please add those required artifacts for the same machine and scene before this is ready for approval. I have not assessed the performance claim as complete from the summary table alone.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T12:11:49Z.
Review: CHANGES_REQUESTED
The page-granular
WriteWatchCoveragelooks right on reading:Excludecovers the first/last page masks per block,Restorecompares each page against its own generation, the map entry is erased once a block has no excluded page, andExcludedSpanstill returns the whole block for the unwatch hook. The newWriteWatchCoverage,WriteTrackingandRecorderassertions pin values that only the change produces.What blocks it:
perfPR and the evidence is incomplete (same ask as thepr-labels-perfbot and @MarcZX10's review): paste theaps5-summary.jsonlline of the capture onmainand the one with the change, attach the two traces, and add the output oftools/trace_digest.pyfor both, from the same title, scene and machine. The table in### Testedis not a substitute for these.maintoo (or say that there is none), so the claim matches what would land.Once the artifacts are attached this is ready for another look.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:43:32Z.
Review: CHANGES_REQUESTED
The performance-report follow-up now includes the required summary lines, trace links, and
trace_digest.pyoutput; that resolves my earlier evidence request. I checked the exact current PR head5f0cd01b53against upstreammain17f8dfad51, though, and it is 181 commits behind the current base (4 commits ahead). The PR's recorded base is2227f13661, and its latest listed build/trace comparison uses oldermain750cf6cf48/2227f13661, not today's17f8dfad51.CONTRIBUTING requires branches to stay current with
main, and the performance claim needs a main/change comparison. Please rebase onto currentmain, rerun the focused write-watch suite on both sides with the required Vulkan-validation environment, and refresh the paired performance captures/digests against that same current base. The current Windows CI and the reported prior GPU runs are useful evidence, but they do not cover the intervening base changes. I did not independently run the suite in this session, so I am not approving this head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T23:38:26Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The new interior-page regressions address the reported write-stamping gap, but the test and performance evidence still uses a base that predates a relevant
GuestMemory.cppchange now onmain.What I ran
41eef2d0434e629e74c11d3034455e26f70d84bc; its recorded main merge is319621ba2e578bd053b0baba2877fe70520e0737. Currentmainis3a2b91981651569163768854a1fcdc7193b6667band includes merge commit33acc03447034b61424cc1c36143cc40ea02bad3for #8930.git merge-tree --write-tree upstream/main HEAD; the merge preview is clean (c187869a289ae7604192a1a4963a9ee3ed9e966b).python3 tools/check_conventions.py --base upstream/mainandgit diff --check upstream/main...HEAD: zero convention errors and a clean diff check. The convention checker reports a non-blocking debt-length warning for the 1,742-character entry indocs/dev/debt/libSceAgcDriver.md.python3 tools/pr_overlap.py --branch HEAD --repo boykopovar/AnyPS5 --base main; it scanned 1,361 open PRs. It reports older uncomparable PRs that conflict with the current base, so those rows need manual evaluation before treating the overlap report as exhaustive.tools/trace_digest.py --json --frames 0 --top 8on each. The queue-worker and largest-slice values match the posted digests for those two traces; I did not digest the second pair.F16ToF32Unpack,F64FmaSubnormalsandRegistrationPrepareShutdown; it does not establish that the new recorder regressions ran in hosted CI. I did not independently run the reported Windows/GPU suite.Results
c187869a289ae7604192a1a4963a9ee3ed9e966bFindings
Blocking
main319621ba2e. Current main includes #8930 (33acc03447034b61424cc1c36143cc40ea02bad3), which changescore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppinWriteChanged. This PR also changesGuestMemory.cppfor write-watch tracking. The clean merge preview shows the changes compose textually, but does not verify their combined behavior or updated performance baseline.Non-blocking
Sources
GuestMemory.cppNot verified
I did not run the Windows-only write-watch regressions, reproduce the GPU captures, or rerun the focused performance suite on a merge with current main. The author's reported Windows runs are for the earlier
319621ba2ebase.To get this to a good state
Rebase onto current
main, preserve both #8930's changed-byte write path and this PR's page-level watch tracking, then rerun the focused write-watch regressions and provide a fresh paired main/change performance report with both summary lines, traces andtrace_digest.pyoutput.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T03:11:16Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The code and current-main validation evidence address my earlier findings. I am keeping changes requested because the performance capture uses a prohibited trace switch and the traces are hosted in a separate repository instead of attached to this PR.
What I ran
9d619dee3e37dddf31d21fd897631a12c8c958eeagainst currentmain3a2b91981651569163768854a1fcdc7193b6667b.python3 tools/check_conventions.py --base upstream/main --head HEAD.git diff --check upstream/main...HEADandgit merge-tree --write-tree upstream/main HEAD.tools/trace_digest.pywith each summary line from the PR comment.Results
main777110a31fe78ec639500584b723a97ef853ee41mainand this head, RX 9070 XT; no missing-layer orVUID-linesThe author’s validation run reports 25/27 tests on the baseline because the two new shared-block regressions fail there, and 31/31 on the change. The paired test and performance results are author-run; I did not independently run Windows/Vulkan tests.
Negative control
Findings
Blocking
APS5_TRACE_EVENTS=3145728. The repository’s performance capture form permits choosingAPS5_TRACE_FRAMESorAPS5_TRACE_SECONDS, then explicitly requires no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. Please recapture the base and change pair following that procedure, replace all four summary lines, traces, digest outputs, and update the reported comparison from the new captures.Non-blocking
dirty: truebecause the new regression tests were added to its local tree. The report states production sources match currentmain; this does not appear to contaminate the performance comparison, but keep the baseline-only test changes explicit.Sources
All code links point to the reviewed commit
9d619dee3e37dddf31d21fd897631a12c8c958ee.Not verified
To get to a good state
Recapture with only the allowed trace-window switch among
APS5_TRACE_*/APS5_PROFILE_*, attach the four new traces to this PR, and replace the summary and digest outputs with those from the new captures.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T11:06:51Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The new report resolves the artifact issues from my prior review: it uses
APS5_TRACE_FRAMESonly, attaches the traces, and includes the digest output. The author also explains that the complete summary totals are retained even though event buffers overflow; the digest correctly marks the traces as dropped, so the per-thread event timelines are incomplete while the reported phase totals remain available.The PR is still based on
main3a2b919816, while currentmainisba5b5330b3. The intervening changes touch this PR's CMake registration, architecture and debt files. Please merge currentmainand run the focused registered test/conventions checks on the resulting exact head. The author’s path comparison indicates the measured production source is unchanged, so the existing captures can remain if the refreshed diff confirms that; please keep the dropped-event limitation explicit.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T17:33:21Z.
Review: APPROVED
Re-checked — new head, looks good
The current head integrates the latest base, preserves the reviewed implementation, and the exact-head validation and Windows CI pass.
What I ran
480ca2dff1fc0c079d3888b43e61b76471ffc40f, whose merge commit includes currentmain`bb04a4f1ea); GitHub reports it mergeable.git diff --check upstream/main...HEADon Linux; it passed with no output.gh pr checks 12378 --repo boykopovar/AnyPS5.Results
Unedited local diff-check output
Unedited hosted check output
Negative control
mainwith the new tests retainedFindings
Blocking
None found in the reviewed change.
Non-blocking
The DEATHLOOP trace captures report
trace_dropped: true; their summary totals and frame samples remain available, while the affected worker event timelines are incomplete. This limitation is disclosed in the report. The new GTA V data point is also author-reported and was not independently reproduced.Sources
Not verified