perf(agc): reconcile host imports from logged allocation changes #26581
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26581"
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 consolelogout on 2026-11-24T06:05:37Z.
What
Host imports were reconciled with the allocation registry by building a lease of every readable range and diffing it against the last snapshot (
refreshImports,changedSpans) wheneverGuestAllocationsGenerationmoved. Every guestmalloc,freeandreallocmoves it, so a title that allocates while it draws paid two whole-registry passes per draw. Godot PS5 (#26456) makes about 2,400 allocations and 2,400 frees a second over a registry of about 156,000 ranges, and spent about 2.4 ms per draw there.GuestAllocationsChangesSince_nid_no_patch). A mutation logs what it asked for, the whole extent of every range that a protection or unmap re-creates, and every range whose backing is renewed after an unpin, so each range whoseshared_ptridentity changes lies inside a logged span. The log answers only when it is complete since the asked generation. It refuses after an overflow (16,384 spans), after an image registration (which records no spans), and while a mutation waits for a range's lease (retiring, which a lease leaves out).HostImportFor,HostImportJoinedFor,HostImportSerialandHostImportsReconciledUnchangedrefresh,refreshedFromLoggedChangesdoes whatrefreshImportswould do for the logged spans. It first gives up when a failed, refused, growth or sparse-run entry lies in a changed window, which needs only the merged spans. Otherwise it walks the imports of the changed windows and the pending imports the same way (each once), checks them withsameRangeagainst a lease of only the affected runs (GuestAllocationsAcquireMapped_nid_no_patch), re-unwatches the kept ones, recomputes their growth (desiredRun,growthAt,resetGrowthFloor) and clears the gate refusals. When an import changed, the window size changed, or the log refuses, it also gives up, and the full refresh runs as before. The snapshotchangedSpansdiffs against is left as it was, so a later full refresh still covers the skipped spans.guest_allocations_changescovers the log: added, protected, renewed, removed and invalidated spans, overflow, a retiring range under a lease, and an image registration.The second commit moves the give-up checks ahead of the lease. On SuperTuxKart (PPSA69421) the logged path gives up about 830 times every 2 s, each time because the title maps 64 KiB next to a run with a growth entry; leasing first made each give-up cost 12 us (about 0.25 ms per frame there) and the reordered checks cost 1.4 us, measured with local counters that are not part of this PR.
Overlap: #16879 and #18390 scope two other caches (draw input snapshots, image table stamps) to changed ranges through the invalidator, and #26335 adds a map-only generation. All three also name the
mutationparameter ofGuestAllocationsRegisterMainImageandGuestAllocationsRegisterImage, which conflicts textually here. If #16879 lands first, image registrations report their spans and could be logged instead of making the log refuse.Tested
Windows 10 22H2 (19045), RTX 4080 SUPER (NVIDIA 617.42), i5-11600, WinLibs GCC 15.2.0 r7, Release,
main38d22efc06againstb2d741e3cb. Caches warm, runs alternated in one session, nothing else set.Godot PS5 (PPSA99847) v0.2.10, Pong idle, converted as in #24732, 10 s windows from 20 s (
APS5_TRACE_SECONDS=20:10):38d22efc06b2d741e3cb38d22efc06b2d741e3cbtrace_digest.pyof the first two, ms per frame:Graphics.Draw18.2,Recorder.Sync10.9Recorder.Sync6.0,Graphics.Draw0.8On the first commit (
bc7af2bbec), withAPS5_PROFILE_DRAW=1, the draw phasesvertexandlookupfell from about 2,700 ms each per 10 s to 21 and 69 ms and the average draw from about 1,800 to 81 us, and frames dumped withAPS5_DUMP_FRAMESshowed the court, paddles, ball and score as on main.SuperTuxKart (PPSA69421) 00.001.000, the tutorial race with the pad timeline from #25912,
tools/title_run.py PPSA69421 --profile performance --trace-seconds 80:10 --seconds 110 --warmup-seconds 110:b2d741e3cb38d22efc06b2d741e3cbAcross the session
mainran from 187 to 211 presents (7 runs), the first commit from 191 to 206 (3 runs) and the code ofb2d741e3cbfrom 205 to 210 (4 runs, two of them built before it was committed), so this title shows no difference beyond the spread of one build. One run of the first commit, disturbed by the window losing focus, is left out.Summary lines (Godot
main, Godot this PR, SuperTuxKartmain, SuperTuxKart this PR); the four traces are attached:guest_allocations_changespasses on Windows and Linux. On WSL Ubuntu 26.04.1 (llvmpipe, Mesa 26.0.8, Vulkan validation layers 1.4.341), Debug: the host import, guest memory, recorder kept bytes, write tracking, image table cache and shader memory tests (ctest -R "guest_allocations|host_import|guest_memory_lifetime|scattered_runs|sparse_dma_buf|dma_buf_chunk_window|image_table_cache|linear_target_import|draw_allocations|recorder_kept_bytes|write_tracking|agc_shader_memory|guest_heap_lifetime|guest_memory_resource" -V) withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerpass 41 of 41 onmain38d22efc06, 42 of 42 onbc7af2bbecand 42 of 42 onb2d741e3cb; every log shows the loader inserting the layer (25 times), none haswas not found, and none has aVUID-line.The whole suite (6,725 tests) ran on the first commit before its rebase, against base
1c6db2e79e: 107 failed with-j10. The 107 again with-j3: 70 failed here and 68 onmainat that base. The extra ones wereagc_driver_queue_zero_quiet_interruptandagc_driver_viewport_index, and on a second-j3run here onlyagc_driver_linear_target_rectangle_bound.agc_driver_viewport_indexalso aborts onmainin 2 of 3 runs alone. Run alone here, the quiet interrupt test passes 10 of 10 under ctest and 5 of 5 with every core loaded, and the rectangle bound test 5 of 5; both pass on the RTX 4080 SUPER (4 of 4 and 3 of 3). The other failures fail onmaintoo, mostly llvmpipe aborts and timeouts.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)Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-24T10:48:35Z.
Review: COMMENTED
Tested on another title, where the registry is much larger: PS5SX2 (PPSA99203, vk-285-321), the PCSX2 port, in its "PS2 system menu" start-up. It's about 3.5 times faster here, and the image looks the same.
Setup: Windows 11 26300, NVIDIA GeForce RTX 2060 (driver 621.24), WinLibs GCC 15.2.0, Release. Local tree on
main00ede212a0with a few unrelated local changes, including #26600, which PS5SX2 needs to draw this scene, and the #1413 guard skipped. The PR's diff applies cleanly there (git apply). Caches warm.APS5_TRACE_SECONDS=70:20, alternating runs:Why it's slow without the PR. I added temporary counters in
GuestAllocationsAcquireandGuestAllocationsBegin, on the tree without the PR. In this scene they show:GuestAllocationsAcquirecalls per second, and every one rebuilt the lease.In PS5SX2's own menu, before the system menu starts, it is 46,933 ranges and about 1,700 mutations per second. I didn't count which call sites the mutations come from, so I can't say how much of it is heap traffic, as in #26456.
APS5_SAMPLE_COMMITTERon the same tree:GuestAllocationsAcquireis 29 % of the committer's samples, mostly_Rb_tree_incrementunder it, reached throughHostImportsReconciledUnchangedandHostImportFor. In the trace that is 3 to 4 draws per frame at about 35 ms each, split betweenindex_uploadanddraw_and_resource_release; the other ~100 draws per frame take about 0.2 ms.With the PR, those slow draws are gone. The largest remaining waits are the queue worker's
Driver.WorkerWait.idle_and_completion_poll, about 11 ms per batch.Image. Captured 2 minutes into the start-up of each run. The PR run had already reached the language selection screen, drawn correctly, at 3.6 FPS in the title bar. The run without it was still on the PlayStation logo at 2.4 FPS. Nothing was drawn wrongly in either.
Not run: the PR's own
guest_allocations_changestest, and the Vulkan validation layer.Traces of the four runs, in the table's order (without the PR, this PR, this PR, without the PR), and their summary lines:
AI-assisted: yes (Claude Code)