perf(agc): answer clear accesses at the top of the flush hook #18010
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18010"
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 meh7an on 2026-11-10T04:19:46Z.
What
The flush hook (
FlushForAccess) runs before every guest memory access the driver makes. On Sonic Origins' S3K menu page that is about 8,200 calls per frame, mostly from the draw committer'sCopyDrawInputand the queue worker'sGuestMemory::Read. Almost every call finds nothing to do, yet it loads the pending-write snapshot twice, lists the pending images into a vector and takes the unit shadow registry's mutex. This answers such an access at the top of the hook from copies the calling thread keeps; anything else takes the old path unchanged.ClearAccesschecks, in this order: no pending image over the range (the pending list's published snapshot, kept per thread while its version holds; an out-of-date snapshot falls through to the old path, which rebuilds it), no image being flushed (flushingCount == 0), no live unit shadow over the range, and no pending write over the range (the write snapshot, kept per thread whilepublishGenerationholds).UnregisterstoresflushingCountwith release after the store was recorded, and the hook loads it with acquire before it loadspublishGeneration, so an image found neither pending nor flushing is in the snapshot or has landed. A version-current pending snapshot was rebuilt under the registry mutex after any flusher that took an image out had storedflushingCountin the same critical section, so the load after the version check sees it.liveSerialis bumped under the registry mutex wherever units become live or stop being live (publish, mark, eviction, retire, a stale entry dropped, a device destroyed).currentLiveRangesbuilds the mergedUnitRangeof every live unit once per serial, under the mutex, and publishes it; threads keep ashared_ptr. It answers likeanyShadowedLockedfor every range: both skip shadows withliveUnits == 0, and the unit index rangeanyShadowedLockedwalks is exactly the set of units whose import-clipped range overlaps the access.ThreadScratch, with aHostThreadSlot<bool>saying whether any are noted, so the hook's first check no longer callsFlsGetValue(it showed in the profile under the hook). The deferred labels they are made from already live in a TEB slot, so both now have the same per-thread storage.hookCallsis counted only underAPS5_PROFILE_DRAW, the only place it is printed.APS5_NO_HOOK_CLEAR_ACCESS=1makes the hook run all of its checks on every access, as before (newENVIRONMENT.mdrow).3cd86e6ea7(S3K, 60 s) found the early return would fire on 99.99% of the committer's calls and 99.86% of the worker's. The rest were images being flushed and pending snapshots out of date; none overlapped a pending image, a live unit, a queued label or a pending write.DeferToMirror), which applies only when an image is pending over the range, so the two merge cleanly. #10193, #13928 and #13929 callQueuedLabelRanges().empty()in new code; that still compiles and agrees with the new slot.tools/pr_overlap.pyfailed closed: 24 open PRs that shareRecorder.cpp,Texture.cpp,tests/Recorder.cpporENVIRONMENT.mdcould not be compared, so they were compared by the symbol scan above.Tested
Windows 11 (10.0.26300), NVIDIA GeForce RTX 2080 Ti (driver 617.14), Sonic Origins (PPSA05324) menu on the S3K page, 3840x2160, default environment. The measuring base is plain main
f0d842158cand this commit on top of it.agc_hook_clear_access(agc_driver_recorder_tests --hook-clear-access-only), andagc_hook_clear_access_off(the same withAPS5_NO_HOOK_CLEAR_ACCESS=1). Each access goes throughGuestMemory::FlushGpuWritesand checks whether the hook answered it early, and the data: an access with nothing pending; beside and inside a pending write (inside: the hook waited for it); beside and over a queued label, with a recorder callback that notes a pending write (over: the label is recorded and its write waited for; once forgotten, the label is not recorded again); beside and over a live unit (over: the hook publishes it and the import holds its bytes); over a pending image on a unit that is not live (the hook stores the image's results). With the switch on, 6 accesses are answered early; with it off, none, and the data checks are the same.unitShadowTests(agc_unit_shadow,agc_driver_unit_shadow,agc_driver_unit_shadow_budget) now also requires the live-unit copy to agree withAnyShadowedOverlapsat all 19 range checks: marking, whole and partial publish, a stale unit dropped, eviction under the 8 MiB budget, retire.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -V, same machine and GPU):agc_driver_host_write_hook,agc_driver_host_write_pending_storage,agc_driver_idle_store_yields,agc_driver_storage_flush_ordering,agc_driver_storage_read_during_idle_store,agc_driver_store_idle_results(and_wake,_disabled),agc_unit_shadow,agc_idle_publish_wait,agc_driver_bda_reads_shadowed_results(and_per_build),agc_unit_shadow_completion_store,agc_driver_unit_shadow(and_budget),agc_small_tiled_shadow_labelpass on main (16/16) and on the change (18/18 with the two new tests). Neither log containswas not found but was requested by env var VK_INSTANCE_LAYERSor aVUID-line, and the logs are equal apart from timings and the new tests.agc_idle_publish_waitreports its block not watched on this machine in both.ctest -R "^agc_.*(label|queued|Queued)", the queued-label ranges changed storage for every caller) pass on the change under the same protocol,agc_driver_native_depth_driver_queued_fillskipped by its own device check; noVUID-line.tools/check_conventions.pyandtools/env_reference.py --checkpass. Full ctest was not run.Sampler (
APS5_SAMPLE_COMMITTERandAPS5_SAMPLE_WORKER, 60 s window, 3843 samples per thread):f0d842158c88490895b5FlushForAccessinclusive, draw committerFlushForAccessinclusive, queue workerSnapshotOverlaps/AccessKeptByCpu/PublishShadowsOnlyLiveUnitsClear9,PendingClearOnThread9That is about 0.4 ms per frame on the committer and 0.3 ms on the worker. The frame is bound by the committer and the GPU: the worker waits 28-30% of its samples in
DrawPipeline::Enqueue, the committer about 12%.Two traced runs per arm (
APS5_TRACE_SECONDS=200:15), in main, PR, PR, main order, both commit IDs in the summaries:f0d842158c88490895b5Graphics.Drawper frame (retained events)The saving shows in the sampler; frame time and FPS stay within the run-to-run spread, so no FPS change is claimed (the sampler runs read 15.80 on main and 15.06 on the PR, the PR run rising from 14.58). GPU busy is not claimed either. All four traces dropped events once the worker's buffer filled, equally in both arms; the slice figures cover retained events only. Other work on the machine was not excluded during the runs.
seconds 200:15 from present 4570: 219 presents, frame p50 67.7 / p90 71.9 / p99 76.9 / max 77.3 ms, GPU busy 36.5 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
f0d842158c, dropped: yesseconds 200:15 from present 4594: 212 presents, frame p50 70.4 / p90 75.2 / p99 81.1 / max 94.6 ms, GPU busy 35.0 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
88490895b5, dropped: yesseconds 200:15 from present 4645: 223 presents, frame p50 67.0 / p90 70.8 / p99 74.0 / max 74.6 ms, GPU busy 34.4 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
88490895b5, dropped: yesseconds 200:15 from present 4569: 217 presents, frame p50 68.2 / p90 73.1 / p99 82.7 / max 93.1 ms, GPU busy 35.5 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
f0d842158c, dropped: yesTraces (two runs per zip, each with its
aps5-summary.jsonl): m314-main-traces.zip (mainf0d842158c), m314-change-traces.zip (this PR88490895b5).trace_digest.py, main run 1
seconds 200:15 from present 4570: 219 presents, frame p50 67.7 / p90 71.9 / p99 76.9 / max 77.3 ms, GPU busy 36.5 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
f0d842158c, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 36.5, Graphics.Draw 26.9, Graphics.Draw.draw_and_resource_release 21.2, Driver.Packet 16.5, Driver.Packet.draw 12.5, Driver.Draw 12.2, VideoOut.Flip 10.7, Driver.Present 10.5, VideoOut.Flip.present 10.5, Recorder.WaitSerial 10.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, PR run 1
seconds 200:15 from present 4594: 212 presents, frame p50 70.4 / p90 75.2 / p99 81.1 / max 94.6 ms, GPU busy 35.0 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
88490895b5, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 34.9, Graphics.Draw 28.5, Graphics.Draw.draw_and_resource_release 21.9, Driver.Packet 16.8, Driver.Packet.draw 13.0, Driver.Draw 12.6, VideoOut.Flip 9.5, Driver.Present 9.3, VideoOut.Flip.present 9.3, Recorder.WaitSerial 9.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, PR run 2
seconds 200:15 from present 4645: 223 presents, frame p50 67.0 / p90 70.8 / p99 74.0 / max 74.6 ms, GPU busy 34.4 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
88490895b5, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 34.4, Graphics.Draw 26.4, Graphics.Draw.draw_and_resource_release 21.0, Driver.Packet 16.1, Driver.Packet.draw 12.4, Driver.Draw 12.0, VideoOut.Flip 10.0, Driver.Present 9.8, VideoOut.Flip.present 9.8, Recorder.WaitSerial 9.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, main run 2
seconds 200:15 from present 4569: 217 presents, frame p50 68.2 / p90 73.1 / p99 82.7 / max 93.1 ms, GPU busy 35.5 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
f0d842158c, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 35.5, Graphics.Draw 27.4, Graphics.Draw.draw_and_resource_release 21.4, Driver.Packet 16.6, Driver.Packet.draw 12.7, Driver.Draw 12.3, VideoOut.Flip 9.5, Driver.Present 9.4, VideoOut.Flip.present 9.4, Recorder.WaitSerial 9.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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)