perf(agc): remember structural host import misses #7457
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7457"
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 moong15 on 2026-10-18T08:14:34Z.
What
HostImportForrepeats the full lookup for guest ranges that cannot be imported because no registered run covers them. Every repeat takes the guest allocations lease, refreshes the imports and walks the run (refreshImports,importRun), then falls back to the copy path with the same result.This change remembers those structural misses in a 256-entry, 4-way set-associative table of exact
[begin, end)ranges (64 sets; a range already stored is not stored again, a full set evicts its oldest entry). A repeated lookup for a stored range returns null before the lease is taken.Each entry is stamped with the device, the host import alignment, the registry generation, the forget serial, the import epoch, the insert count and the miss policy count. A miss is stored only when the registry generation matches the refreshed generation, and only with an even forget serial. Any new import, retirement, clear, extraction, window change or
failedBlockswrite moves the stamp, so a stored miss is never returned for a range that has since become importable. Committing pages of a reserved heap goes through the registry and bumps its generation.APS5_NO_IMPORT_MISS_MEMO=1disables the table.The table only holds misses where no registered run covers the range. On
mainthat path touches none ofrefusals,failedBlocks,failedorcounts.remembered, which only describe ranges where a run exists, so the two do not overlap.HostImportForandimportAccesspassmain'sImportRequesterthrough. The[buffers]profile line (APS5_PROFILE_DRAW) reports hits, structural misses, stores, evictions and resets.Tests:
agc_import_miss_memoandagc_import_miss_memo_offcheck the proof stamp, the runtime invalidation for each bump point, set eviction, and a miss recorded over a half-committed reserved window that must import once the rest is committed, with the table on and off.Tested
Windows 11 (10.0.26300), AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Ryzen 7 9800X3D, 3840x2160, Stellar Blade (PPSA13197, 01.014.001).
GPU tests on
main1a3a1b2e0and on this PR bef945671, same machine,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -j1 -V -R "^agc_(import_miss_memo|import_miss_memo_off|host_import|driver_host_import|driver_registration|sparse_run_import)":main16 of 16, this PR 18 of 18 (the two extra are the memo tests);agc_host_import_sparseskips on both (Linux only). Neither log containswas not found but was requested, and neither has aVUID-line.What this removes, from one diagnostic pair in the same session (
main, then this PR,APS5_PROFILE_DRAW=1andAPS5_SAMPLE_WORKER; these runs are not used for the frame numbers below):[buffers]import lookup time at 300,000 uploads fell from 8,111 ms to 7,105 ms (27.0 to 23.7 us per upload, -12 %).HostImportForonmainand 0.41 % with the change. In this scene the lookup is a small part of upload cost next to the guest reads, so a frame-rate change is not expected here.Performance: Stellar Blade gameplay,
APS5_TRACE_SECONDS=400:90(90 s from 400 s after the first present), warm caches (a warm-up run first),APS5_PREBUILD_THREADS=16on both, noAPS5_PROFILE_*.main1a3a1b2e0and this PR bef945671 alternated in one session on the same machine, runs in order 1-6.Driver.Packet.memory_waitms per framemainmainmainmainThe difference in means (+7 %) is inside the run-to-run spread: run 2 (PR) is slower than run 1 (
main), and themainruns alone range from 5.17 to 6.26 fps. GPU busy time per present is unchanged.Summary lines, in run order:
Traces: 1, 2, 3, 4, 5, 6
1 main: trace_digest aps5-trace-1a3a1b2e0ecb-10416.json.gz
seconds 400:90 from present 4210: 531 presents, frame p50 159.9 / p90 187.2 / p99 236.7 / max 1247.2 ms, GPU busy 91.8 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
1a3a1b2e0e, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 319.0, Driver.Packet.memory_wait 167.3, batch 91.9, Graphics.Draw 77.0, Graphics.Draw.draw_and_resource_release 67.4, Driver.Packet.draw 66.1, Driver.Draw 65.8, Driver.Packet.dispatch 44.3, Driver.Dispatch 42.5, Driver.Draw.shader_compile_and_link 29.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
2 PR: trace_digest aps5-trace-bef945671ea8-28528.json.gz
seconds 400:90 from present 4388: 498 presents, frame p50 179.8 / p90 194.8 / p99 248.6 / max 310.6 ms, GPU busy 93.3 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 3840x2160, commit bef945671ea8, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 342.9, Driver.Packet.memory_wait 178.4, Graphics.Draw 103.4, Graphics.Draw.draw_and_resource_release 93.0, batch 93.0, Driver.Packet.draw 87.1, Driver.Draw 86.8, Driver.Draw.draw_enqueued 31.1, Driver.Packet.dispatch 29.1, Driver.Packet.device_lock 28.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
3 main: trace_digest aps5-trace-1a3a1b2e0ecb-9892.json.gz
seconds 400:90 from present 4381: 465 presents, frame p50 184.8 / p90 247.7 / p99 285.7 / max 384.4 ms, GPU busy 93.8 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
1a3a1b2e0e, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 366.3, Driver.Packet.memory_wait 191.7, batch 93.9, Graphics.Draw 87.0, Graphics.Draw.draw_and_resource_release 77.2, Driver.Packet.draw 69.2, Driver.Draw 68.8, Driver.Packet.dispatch 55.8, Driver.Dispatch 54.0, Vulkan.Dispatch 37.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
4 PR: trace_digest aps5-trace-bef945671ea8-5488.json.gz
seconds 400:90 from present 3943: 533 presents, frame p50 165.5 / p90 184.4 / p99 246.4 / max 361.0 ms, GPU busy 93.7 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 3840x2160, commit bef945671ea8, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 317.5, Driver.Packet.memory_wait 167.0, batch 93.7, Graphics.Draw 86.5, Graphics.Draw.draw_and_resource_release 76.5, Driver.Packet.draw 69.8, Driver.Draw 69.4, Driver.Packet.dispatch 32.3, Driver.Draw.shader_compile_and_link 32.2, Driver.Packet.device_lock 30.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
5 main: trace_digest aps5-trace-1a3a1b2e0ecb-19584.json.gz
seconds 400:90 from present 4312: 563 presents, frame p50 157.5 / p90 172.0 / p99 229.2 / max 317.5 ms, GPU busy 92.2 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
1a3a1b2e0e, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 300.3, Driver.Packet.memory_wait 158.2, batch 92.4, Graphics.Draw 81.5, Graphics.Draw.draw_and_resource_release 72.2, Driver.Packet.draw 66.2, Driver.Draw 65.9, Driver.Packet.dispatch 30.3, Driver.Draw.shader_compile_and_link 28.8, Driver.Dispatch 28.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
6 PR: trace_digest aps5-trace-bef945671ea8-14012.json.gz
seconds 400:90 from present 4559: 633 presents, frame p50 140.0 / p90 154.1 / p99 197.9 / max 306.2 ms, GPU busy 84.9 ms per present
AMD Radeon RX 9070 XT, AMD proprietary driver 26.8.1 (LLPC), Windows 10.0.26300, 3840x2160, commit bef945671ea8, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 265.1, Driver.Packet.memory_wait 140.7, batch 85.1, Graphics.Draw 75.3, Graphics.Draw.draw_and_resource_release 66.3, Driver.Packet.draw 61.4, Driver.Draw 61.1, Driver.Draw.shader_compile_and_link 27.4, Driver.Packet.device_lock 25.9, Driver.Packet.dispatch 24.0
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Diagnostic pair summary lines (profiled, not used above)
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 screamm on 2026-10-18T15:50:58Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (driver 596.21), Ryzen 7 5700X, WinLibs MinGW-w64 GCC 15.2 r7, Release. Head
ec12c0bd0merged on maina62c724c3(clean). The main runs use the same tree withGuestBufferMemory.cpp/.hpptaken froma62c724c3.libspass.agc_import_miss_memoandagc_import_miss_memo_offrun the runtime part (import miss memo runtime invalidation: ok); neither skips on alignment.HostImportFor:agc_import_miss_memofails witha repeated import miss did not follow the memo switch;_offpasses.++state.insertedremoved: it fails withimport creation left a structural miss memo standing.-R '^agc_(host_import|driver_host_import|driver_registration)'(-j1): 12 pass, 1 skipped (agc_host_import_sparse, Linux only). Non-GPU suite: 933 of 939, 2 skipped; 4 load timeouts (check_main_sync,configure_seed,hardware_oracle_compare,conventions_env_reference) pass serially.git diff --checkis clean, butcheck_conventions.py --base origin/mainreports one error on current main:[env-reference] ... APS5_NO_IMPORT_MISS_MEMO is read here but has no row in docs/dev/ENVIRONMENT.md. The branch's base predates that rule, which is why CI passed. A row indocs/dev/ENVIRONMENT.mdfixes it.Stale answers: I read the invalidation paths.
GuestAllocations::Mutation, which bumps the monotonic registry generation, so a remap never returns to an old stamp.Containsis consulted only under the!importsStalegate, the condition main already uses for lock-free hits.inserted; retirements, eviction, clear and device changes moveepoch; window changes and new unaliased spans movemissPolicy.nullptr, so the worst case of a stale entry is the copy path, never wrong memory.Titles: PPSA13197 is not available to me. I ran the two local homebrews that use host imports: 60 s each, no input, order PR / PR with
APS5_NO_IMPORT_MISS_MEMO=1/ main, twice, withAPS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1 APS5_TRACE_SUMMARY_EVERY=10. Medians over the 10 s windows. The PR prints no memo counter, so I used main's[buffers] ... import lookup X msline.[gpu]errors in any of the 16 runs.[ps5-agc] submission retirement failed; terminating application before cleanupcame with no driver error before it. The other three PR runs and all six memo-off/main runs ran the full 60 s. I cannot tie it to this change from 4 runs, but I am reporting it.Suggestion: a 10 s profile field for
ImportMissMemoCounters()hits and stores would let testers confirm the memo is answering on a title.Not checked: AMD, Intel, Linux; PPSA13197; the full
^agc_driver_pass; the open PRs the overlap bot lists on the same lines.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T01:50:12Z.
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 CnRJay on 2026-10-19T17:51:00Z.
Review: COMMENTED
Good PR: the cost is shown at the source (lease time 4.13 s to 0.07 s, import step 6.81 s to 1.30 s, 1.05M of 1.05M structural misses answered) and the frame result is an ABBA over a cutscene that is the same each run, +31% and +32% in each adjacent pair. The invalidation list (device, alignment, registry generation, forget serial, import epoch, insert count, miss policy count) is thorough. Questions on what it doesn't list.
agc_sparse_run_importdeal with). Pages committed on demand do not change the registry generation. Does committing pages bump one of the stamps? If not, a miss recorded while the tail of a reserved heap was uncommitted keeps being served after the title commits it, and that range goes down the copy path for good. Please add a test: record a miss over a half-committed reserved window, commit the rest, and require the next lookup to import.[begin, end). A title with more than 256 distinct missing ranges per generation evicts continuously and pays the lookup plus the cache cost. State the replacement policy and the hit rate on a scene with many ranges; the one profiled number is 100% on a fixed spot.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T09:02:54Z.
Review: CHANGES_REQUESTED
Thanks for the work and the numbers. This needs a rebase on current main that involves logic, so we can't do it mechanically:
GuestBufferMemory.cpp/.hppafter #6457/#6479/#6730:HostImportForandimportAccessnow take anImportRequester, the catch inimportAllocationreturnsfailedImport()/failedBlockImport(), and main already remembers refusals and failed blocks (state.refusals,state.failedBlocks,counts.remembered). Please rebase and decide how the miss memo composes with those: passrequesterthrough, keep the unaliased-spanmissPolicybump in the newfailedBlockImportpath, and say what the memo covers that the existing remembered failures don't.perflabel bot asks for theaps5-summary.jsonllines of main and of the change, traces, andtools/trace_digest.pyoutput.Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-20T17:31:19Z.
Rebased onto
main1a3a1b2e0(head bef945671). Answers in order.@adriadam10: composition with the remembered failures
HostImportForandimportAccesstake main'sImportRequesterand pass it through.importAllocationusesfailedImport()/failedBlockImport(). ThemissPolicybump that sat on the old unaliased-span path now sits insidefailedBlockImport, so it moves on everyfailedBlockswrite.refusals/failedBlocksdon't: it only stores misses where no registered run covers the range (!runCovers). Onmainthat path callsfindImportand touches none ofrefusals,failedBlocks,failedorcounts.remembered. So every such lookup still pays for the lease,refreshImportsandimportRun; the memo returns before all three. Refusals and failed blocks only ever describe ranges where a run exists, so the two sets don't overlap.runCoversdepends on the registry lease, the import window andfailedBlocks. Each of these moves a stamp field, so a memo entry can't outlive the state it was computed from. It does not depend on refusals:runCoverspasses budget 0, sostillRefusedis false.@CnRJay: committing pages of a reserved heap
mutation.AddinDirectMemory.cpp, which bumps the registry generation, and the generation is part of the stamp.VirtualQuerycheck. That is the path where a run exists, so they are never memoized.importMissMemoCommitTests:main, an import that failed on uncommitted pages stays instate.faileduntil the registry changes, so committing those pages alone never retries the import. I left that alone here.@CnRJay: replacement policy and hit rate
[buffers]profile line (APS5_PROFILE_DRAW) now printsH hits of N structural misses (P%), S stores, E evictions, R resets.Numbers
The body now has
main1a3a1b2e0against this PR bef945671, three alternating pairs in one session (runs 1-6). The scene is Stellar Blade gameplay, a 90 s window from 400 s after the first present, with whole traces, summary lines andtrace_digest.pyoutput. This replaces the old off-switch ABBA and covers the longer-ABBA question. Means:main5.77 fps, PR 6.16 fps. That difference is inside the run-to-run spread (run 2, PR, is slower than run 1,main), so I'm not claiming a frame-rate gain from this scene. The old +31% came from the off switch on one build, and I'd discount it.What the change removes is shown at the source in the body. The
[buffers]import lookup time falls 12% per upload (27.0 to 23.7 us at 300,000 uploads). In this scene the lookup is a small part of upload cost: queue worker 0 spends about 0.4% of its samples inHostImportFor.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T20:19:23Z.
Review: CHANGES_REQUESTED
Thanks for the rebase and for answering each point; the composition with
failedBlocks/refusals, the stamp fields, the commit test and the 4-way table all read correctly.The remaining problem is the benefit:
mainvs 6.16 fps here, inside the run-to-run spread, andHostImportForgoes from 0.44 % to 0.41 % of queue worker 0 samples. You also discount the earlier +31 %, which came from the off switch on a single build.nullptrimport from a missed stamp field outweighs a 12 % per-upload lookup saving.Please either show a scene or workload where the structural-miss lookup is a measurable share of frame time, with
tools/trace_digest.pysummaries ofmainand of the change from the same machine and scene, or close this PR. If you find such a scene, the implementation itself needs nothing else from us.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T01:59:56Z.
Review: CHANGES_REQUESTED
Still blocked on the benefit from the previous review, and nothing changed since:
mainvs 6.16 fps here, inside the run-to-run spread, andHostImportForis 0.44 % vs 0.41 % of queue worker 0 samples. The earlier +31 % came from the off switch on a single build.nullptrimport from a missed stamp field outweighs the 12 % per-upload lookup saving.Please show a scene or workload where the structural-miss lookup is a measurable share of frame time, with
tools/trace_digest.pysummaries ofmainand of the change from the same machine and scene, or close this PR. The branch also conflicts withmainnow; rebase once there is a case for the change. If one is found, the implementation itself needs nothing else from us.Pull request closed