Skip to content

perf(agc): re-check only the host imports a registry change can reach - #9402

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
janzezno:perf/incremental-import-refresh
Oct 27, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
janzezno:perf/incremental-import-refresh

Conversation

@janzezno

@janzezno janzezno commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

refreshImports re-checked every live host import, and every remembered failure and refusal, each time the guest allocation registry changed. A title that maps memory often pays that walk constantly. SuperTuxKart (PPSA69421) maps about 1650 times a second at its menu. With #8091's budget fix, about 440 imports (~1.1 GiB) stay live there, and the walk alone costs ~118 ms of CPU per second on the frame's critical path. The frame rate falls as the import budget grows: ~34 FPS with the default budget, ~48 FPS with APS5_HOST_IMPORT_MIB=128.

This PR makes the refresh incremental:

  • The import table keeps the (address, bytes, weak_ptr) of every range in the lease it was last checked against. The snapshot holds weak_ptrs because a lease pins its ranges: unmap waits while use_count() != 1.
  • A refresh merges that snapshot with the new lease by range identity (owner_before, as sameRun does). The result is the address spans whose ranges were added, removed or replaced, whatever mutation did it, including backing renewals.
  • Only imports whose import window ([base / window * window, max(that + window, base + bytes))) touches a changed span are checked again. These are found with a lower_bound on the import map plus one predecessor; imports never overlap, as peekImport already relies on. importRun, exactRun and joinedRun read only ranges inside that span. The scan carries a cursor across the changed spans, so each import is checked at most once per refresh even when several separate spans fall in one window.
  • Imports made since the last refresh are always checked. A thread can make an import from a lease taken before another thread's refresh, and the next diff would not show that range. They are kept as a set of distinct bases (pendingImports); retiring an import removes its base, so the set never holds more than the live imports.
  • Every import is checked, as before, when the window is 0 or the window or the effective budget changed since the last refresh.
  • check is the only place either walk retires an import, so fix(agc): put a retired import's unchanged ranges back in the write watch #8926's handling of retired imports (now on main) sits there: check notes the unwatched ranges of each import it retires, and those ranges go back in the write watch once after both walks.
  • Remembered failures, failed joins, failed blocks and refusals are dropped by the same window test. Every use site already validates them with sameRun, so this is cleanup only.

One behaviour differs, and it is recorded in docs/dev/debt/libSceAgcDriver.md. An unchanged import whose run could now be larger, because a remembered refusal no longer holds, is kept until its window changes. A request that needs the larger run still retires it (wouldRetireImport). On main, any registry change anywhere retired it. Under a 128 MiB budget in SuperTuxKart, main retired and re-made the same three still-valid single-range imports about 1650 times a second for this reason.

New test agc_windowed_import_refresh (128 KiB window, three windows):

  • a continuing range added inside an import's window, outside the import's own bytes, retires it;
  • an import in another window survives;
  • re-mapping a range retires its import only.

It passes on main and on this PR. It fails when the window query is narrowed to lower_bound(begin): "an import whose window gained a continuing range was kept".

Two local probes (not in this PR) checked the review follow-ups:

  • 32 single-range imports in one 8 MiB window, then 32 separate ranges added between them in one mutation: the refresh made 1024 checks before the cursor and 32 with it.
  • SuperTuxKart with fix(agc): pin the import ceiling only on memory exhaustion #8091 counted the pending set at each of ~12,000 refreshes per 5 s. With a 128 MiB budget (71 live imports, 107,397 made in 50 s) and with the default budget (440 live), it never held more than 1 entry or more than the live imports.

Tested

Arch Linux (kernel 7.2.11), Ryzen 5 7500F, AMD Radeon RX 7900 GRE, RADV Mesa 26.2.5, on main 716cb74e08. SuperTuxKart (PPSA69421 00.001.000, catalog sha256 f2240bf0…b712a), relinked with --trap-sdk-syscall-stubs. Main menu with no input, headless gamescope --backend headless -W 1920 -H 1080, APS5_TRACE_SUMMARY_EVERY=10, 70 s runs. Each side's first run creates the game's configuration and starts in a different first-launch scene, so it only warms the shader caches and is not counted. Then four rounds of one run per side, main first. The FPS is the presents in the last 8 s of each run (VideoOut telemetry).

Why #8091 is applied on both sides. On RADV, plain main lowers the import budget after memfd-backed imports are refused (#8091). The menu then randomly settles in a GPU-bound ~3 FPS mode, with GPU ~90% busy and a CPU nearly idle, or a fast mode with ~74 MiB of imports. Both sides do this: on plain main eaff876, main ran 2.9 / 2.7 / 3.3 FPS and this PR 1.0 / 3.2 / 53.7 FPS. That noise hides the walk. Both builds below therefore carry #8091's one-line production change in importRunAt. This PR does not depend on #8091.

Side FPS, last 8 s, rounds 2-4 Round 1 GPU busy per present
main + #8091 32.5 / 32.3 / 32.1 30.5 1.9 ms
this PR + #8091 36.8 / 36.8 / 36.5 32.3 1.9 ms

Round 1 started right after this PR's build finished (load average 12.7) and is slower on both sides, so it is listed apart; the fourth round was added for that reason. On the previous base 1e20650e84 the same protocol gave 32.3 / 32.3 / 32.2 on main and 39.7 / 38.5 / 38.5 with this PR, and on b7d1d47a5f 37.2 / 35.9 / 36.8 and 51.8 / 54.0 / 53.2.

main was built from 716cb74e08 and this PR from its pushed head 90b365b5b9, each with #8091's one-line change uncommitted, so both sides' summary lines show as dirty. tools/trace_digest.py of the first clean run (round 2) of each side (summary files of all runs attached):

main + #8091

6 intervals, 0.0 to 60.1 s, 1790 presents
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit 716cb74 (dirty)

# seconds presents p50 p90 p99 max GPU busy busiest worker largest phase
1 0-10 195 31.1 97.1 350.2 1386.4 1.9 3 % Graphics.Draw 3.4
2 10-20 323 30.8 31.9 34.4 52.1 1.9 5 % Graphics.Draw 2.8
3 20-30 318 31.3 33.1 34.9 35.6 1.9 5 % Graphics.Draw 2.9
4 30-40 309 32.1 34.1 39.3 44.3 1.9 5 % Graphics.Draw 3.0
5 40-50 322 31.0 31.6 33.0 33.7 1.9 4 % Graphics.Draw 2.7
6 50-60 323 30.9 31.4 35.0 45.9 1.9 4 % Graphics.Draw 2.7
p99 ms  @_____  0-350.2
gpu ms  @@@@@@  0-1.9
this PR + #8091

6 intervals, 0.0 to 60.1 s, 2051 presents
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit 90b365b (dirty)

# seconds presents p50 p90 p99 max GPU busy busiest worker largest phase
1 0-10 225 27.6 70.9 242.5 1380.7 1.9 3 % Graphics.Draw 2.3
2 10-20 369 26.7 29.6 35.1 37.9 1.9 5 % Recorder.Submit 1.9
3 20-30 367 27.0 29.9 32.7 37.1 1.9 5 % Recorder.Submit 1.9
4 30-40 358 27.7 30.9 32.2 41.5 1.9 5 % Recorder.Submit 2.0
5 40-50 367 27.0 29.7 30.6 31.2 1.9 5 % Recorder.Submit 1.9
6 50-60 365 27.1 29.9 32.5 38.9 1.9 5 % Recorder.Submit 1.9
p99 ms  @_____  0-242.5
gpu ms  @@@@@@  0-1.9

Trace windows for the perf check. APS5_TRACE_SECONDS=40:10, same scene, machine and builds as the runs above. Two windows per side: main 322 / 326 presents, p50 31.1 / 30.7 ms, p99 32.2 / 31.6 ms; this PR 370 / 364 presents, p50 26.7 / 27.3 ms, p99 33.1 / 30.9 ms. The first PR window has one 43 ms frame, which puts its p99 and max above main's; the second does not. The first window of each side, with its trace attached (aps5-trace-716cb74e0871-151594 is main, aps5-trace-90b365b5b9f0-151903 is this PR):

main + #8091:

{"commit":"716cb74e0871","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"40:10","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"AMD Radeon RX 7900 GRE (RADV NAVI31)","driver":"radv Mesa 26.2.5-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 5 7500F 6-Core Processor","cpu_threads":12,"memory_mib":31744,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 40:10","first_present":1149,"ms":10026.366},"presents":322,"frame_ms":{"p50":31.120,"p90":31.659,"p99":32.202,"max":33.652},"gpu_busy_ms_per_present":1.884,"worker_busy_pct":{"queue worker 0x0":4.131},"top_phases_ms_per_frame":{"Graphics.Draw":2.800,"Vulkan.DrawFromRecipe":2.614,"Graphics.DrawWithRecipe":2.598,"Graphics.DrawWithRecipe.draw_and_resource_release":2.591,"Graphics.Draw.draw_and_resource_release":2.099,"Recorder.Submit":1.968,"Driver.Packet":1.267,"Driver.Packet.draw":0.863},"trace_dropped":false,"trace":"aps5-trace-716cb74e0871-151594.json.gz"}

this PR + #8091:

{"commit":"90b365b5b9f0","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"40:10","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"AMD Radeon RX 7900 GRE (RADV NAVI31)","driver":"radv Mesa 26.2.5-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 5 7500F 6-Core Processor","cpu_threads":12,"memory_mib":31744,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 40:10","first_present":1328,"ms":10022.000},"presents":370,"frame_ms":{"p50":26.698,"p90":29.304,"p99":33.106,"max":43.172},"gpu_busy_ms_per_present":1.885,"worker_busy_pct":{"queue worker 0x0":4.573},"top_phases_ms_per_frame":{"Recorder.Submit":1.885,"Graphics.Draw":1.777,"Vulkan.DrawFromRecipe":1.494,"Graphics.DrawWithRecipe":1.479,"Graphics.DrawWithRecipe.draw_and_resource_release":1.472,"Graphics.Draw.draw_and_resource_release":1.471,"Driver.Packet":1.220,"Driver.Packet.draw":0.830},"trace_dropped":false,"trace":"aps5-trace-90b365b5b9f0-151903.json.gz"}
tools/trace_digest.py, main + #8091

seconds 40:10 from present 1149: 322 presents, frame p50 31.1 / p90 31.7 / p99 32.2 / max 33.7 ms, GPU busy 1.9 ms per present
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit 716cb74 (dirty), dropped: no

{"commit":"716cb74e0871","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"40:10","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"AMD Radeon RX 7900 GRE (RADV NAVI31)","driver":"radv Mesa 26.2.5-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 5 7500F 6-Core Processor","cpu_threads":12,"memory_mib":31744,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 40:10","first_present":1149,"ms":10026.366},"presents":322,"frame_ms":{"p50":31.12,"p90":31.659,"p99":32.202,"max":33.652},"gpu_busy_ms_per_present":1.884,"worker_busy_pct":{"queue worker 0x0":4.131},"top_phases_ms_per_frame":{"Graphics.Draw":2.8,"Vulkan.DrawFromRecipe":2.614,"Graphics.DrawWithRecipe":2.598,"Graphics.DrawWithRecipe.draw_and_resource_release":2.591,"Graphics.Draw.draw_and_resource_release":2.099,"Recorder.Submit":1.968,"Driver.Packet":1.267,"Driver.Packet.draw":0.863},"trace_dropped":false,"trace":"aps5-trace-716cb74e0871-151594.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 1378: 33.7 ms at 7116 ms: Driver.WorkerWait (queue worker 0x0) 32.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 32.1, Graphics.Draw (draw committer) 3.4, Vulkan.DrawFromRecipe (draw committer) 3.0
  • present 1352: 32.7 ms at 6305 ms: Driver.WorkerWait (queue worker 0x0) 31.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 30.9, Graphics.Draw (draw committer) 3.1, Vulkan.DrawFromRecipe (draw committer) 2.8
  • present 1379: 32.2 ms at 7150 ms: Driver.WorkerWait (queue worker 0x0) 31.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 30.9, Graphics.Draw (draw committer) 3.3, Vulkan.DrawFromRecipe (draw committer) 2.9
  • present 1467: 32.2 ms at 9901 ms: Driver.WorkerWait (queue worker 0x0) 30.7, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 30.7, Graphics.Draw (draw committer) 3.1, Vulkan.DrawFromRecipe (draw committer) 2.9
  • present 1340: 32.2 ms at 5930 ms: Driver.WorkerWait (queue worker 0x0) 30.6, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 30.6, Vulkan.DrawFromRecipe (draw committer) 3.0, Graphics.DrawWithRecipe (draw committer) 2.9

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 0.0 (0 %) 0.0 (0 %) 31.1 0.3 Recorder.Sync 0.0
queue worker 0x0 0.4 (1 %) 29.7 (95 %) 1.0 3.4 Driver.Packet 0.4
draw committer 7.4 (24 %) 0.2 (1 %) 23.5 0.1 Graphics.Draw 2.8, Vulkan.DrawFromRecipe 2.6
presenter 0.3 (1 %) 0.0 (0 %) 30.8 0.1 VideoOut.Flip 0.3
gpu 1.9 (6 %) 0.0 (0 %) 29.3 0.0 batch 1.9

Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 29.7, Driver.WorkerWait.idle_and_completion_poll 29.7, Graphics.Draw 2.8, Vulkan.DrawFromRecipe 2.6, Graphics.DrawWithRecipe 2.6, Graphics.DrawWithRecipe.draw_and_resource_release 2.6, Graphics.Draw.draw_and_resource_release 2.1, Recorder.Submit 2.0, batch 1.9, Graphics.Draw.validate 0.7

Longest waits

  • Driver.WorkerWait (queue worker 0x0) 1.6 ms at 7137 ms, present 1378
  • Driver.WorkerWait (queue worker 0x0) 1.2 ms at 8204 ms, present 1412
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 3716 ms, present 1268
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 1445 ms, present 1195
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 9611 ms, present 1457
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 6014 ms, present 1342
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 7205 ms, present 1380
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 8141 ms, present 1410
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 8829 ms, present 1432
  • Driver.WorkerWait (queue worker 0x0) 1.1 ms at 8766 ms, present 1430

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 75908: 0.5 ms at 4646 ms, present 1298: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
  • batch 76793: 0.5 ms at 5110 ms, present 1313: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
  • batch 70834: 0.5 ms at 1971 ms, present 1212: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
  • batch 79969: 0.5 ms at 6790 ms, present 1367: GPU no ranges; recorded by Recorder.Submit (draw committer) 0.0, Vulkan.DrawFromRecipe (draw committer) 0.0, Graphics.DrawWithRecipe (draw committer) 0.0, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.0
  • batch 84405: 0.5 ms at 9143 ms, present 1442: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
tools/trace_digest.py, this PR + #8091

seconds 40:10 from present 1328: 370 presents, frame p50 26.7 / p90 29.3 / p99 33.1 / max 43.2 ms, GPU busy 1.9 ms per present
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit 90b365b (dirty), dropped: no

{"commit":"90b365b5b9f0","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"40:10","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":"<path>"},"gpu":"AMD Radeon RX 7900 GRE (RADV NAVI31)","driver":"radv Mesa 26.2.5-arch1.1","os":"Linux 7.2.11-arch1-1","cpu":"AMD Ryzen 5 7500F 6-Core Processor","cpu_threads":12,"memory_mib":31744,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 40:10","first_present":1328,"ms":10022.0},"presents":370,"frame_ms":{"p50":26.698,"p90":29.304,"p99":33.106,"max":43.172},"gpu_busy_ms_per_present":1.885,"worker_busy_pct":{"queue worker 0x0":4.573},"top_phases_ms_per_frame":{"Recorder.Submit":1.885,"Graphics.Draw":1.777,"Vulkan.DrawFromRecipe":1.494,"Graphics.DrawWithRecipe":1.479,"Graphics.DrawWithRecipe.draw_and_resource_release":1.472,"Graphics.Draw.draw_and_resource_release":1.471,"Driver.Packet":1.22,"Driver.Packet.draw":0.83},"trace_dropped":false,"trace":"aps5-trace-90b365b5b9f0-151903.json.gz"}

Slowest frames (largest slices inside each, inclusive)

  • present 1455: 43.2 ms at 3422 ms: Driver.WorkerWait (queue worker 0x0) 40.8, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 40.8, Graphics.Draw (draw committer) 2.5, Recorder.Submit (draw committer) 2.4
  • present 1574: 40.5 ms at 6630 ms: Driver.WorkerWait (queue worker 0x0) 38.3, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 38.2, Recorder.Submit (draw committer) 2.4, Graphics.Draw (draw committer) 2.4
  • present 1575: 37.3 ms at 6671 ms: Driver.WorkerWait (queue worker 0x0) 35.0, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 34.9, Recorder.Submit (draw committer) 2.6, Graphics.Draw (draw committer) 2.3
  • present 1456: 33.1 ms at 3465 ms: Driver.WorkerWait (queue worker 0x0) 31.3, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 31.2, Graphics.Draw (draw committer) 2.4, Recorder.Submit (draw committer) 2.1
  • present 1573: 31.2 ms at 6599 ms: Driver.WorkerWait (queue worker 0x0) 29.2, Driver.WorkerWait.idle_and_completion_poll (queue worker 0x0) 29.1, Recorder.Submit (draw committer) 2.0, batch (gpu) 1.9

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
title 0.0 (0 %) 0.0 (0 %) 27.1 0.3 Recorder.Sync 0.0
queue worker 0x0 0.4 (1 %) 25.7 (95 %) 1.0 3.3 Driver.Packet 0.4
draw committer 5.1 (19 %) 0.2 (1 %) 21.7 0.1 Recorder.Submit 1.9, Graphics.Draw 1.8
presenter 0.3 (1 %) 0.0 (0 %) 26.8 0.1 VideoOut.Flip 0.3
gpu 1.9 (7 %) 0.0 (0 %) 25.2 0.0 batch 1.9

Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 25.7, Driver.WorkerWait.idle_and_completion_poll 25.7, batch 1.9, Recorder.Submit 1.9, Graphics.Draw 1.8, Vulkan.DrawFromRecipe 1.5, Graphics.DrawWithRecipe 1.5, Graphics.DrawWithRecipe.draw_and_resource_release 1.5, Graphics.Draw.draw_and_resource_release 1.5, Driver.Packet 0.4

Longest waits

  • Driver.WorkerWait (queue worker 0x0) 3.1 ms at 3428 ms, present 1455
  • Driver.WorkerWait (queue worker 0x0) 2.7 ms at 3432 ms, present 1455
  • Driver.WorkerWait (queue worker 0x0) 2.4 ms at 6647 ms, present 1574
  • Driver.WorkerWait (queue worker 0x0) 1.8 ms at 3466 ms, present 1456
  • Driver.WorkerWait (queue worker 0x0) 1.6 ms at 6642 ms, present 1574
  • Driver.WorkerWait (queue worker 0x0) 1.5 ms at 3461 ms, present 1455
  • Driver.WorkerWait (queue worker 0x0) 1.5 ms at 3426 ms, present 1455
  • Driver.WorkerWait (queue worker 0x0) 1.5 ms at 6644 ms, present 1574
  • Driver.WorkerWait (queue worker 0x0) 1.4 ms at 6645 ms, present 1574
  • Driver.WorkerWait (queue worker 0x0) 1.4 ms at 6686 ms, present 1575

Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)

  • batch 96070: 0.5 ms at 8478 ms, present 1640: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.0, Graphics.DrawWithRecipe (draw committer) 0.0, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.0, Recorder.Submit (draw committer) 0.0
  • batch 79255: 0.5 ms at 730 ms, present 1355: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.0, Graphics.DrawWithRecipe (draw committer) 0.0, Recorder.Submit (draw committer) 0.0, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.0
  • batch 92294: 0.5 ms at 6721 ms, present 1576: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.0, Graphics.DrawWithRecipe (draw committer) 0.0, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.0, Recorder.Submit (draw committer) 0.0
  • batch 87820: 0.5 ms at 4672 ms, present 1500: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.0, Graphics.DrawWithRecipe (draw committer) 0.0, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.0, Recorder.Submit (draw committer) 0.0
  • batch 82333: 0.5 ms at 2122 ms, present 1407: GPU no ranges; recorded by Vulkan.DrawFromRecipe (draw committer) 0.1, Graphics.DrawWithRecipe (draw committer) 0.1, Graphics.DrawWithRecipe.draw_and_resource_release (draw committer) 0.1, Recorder.Submit (draw committer) 0.0
tools/performance_compare.py

Performance comparison

Capture Commit Trace Presents Window (ms)
baseline 716cb74 aps5-trace-716cb74e0871-151594.json.gz 322 10026.366
candidate 90b365b aps5-trace-90b365b5b9f0-151903.json.gz 370 10022.000
  • Compare captures from the same machine, title, content version and scene; matching recorded metadata cannot verify the physical machine or scene.
  • Changes are candidate minus baseline. A negative frame-time change means a shorter frame interval.
  • A missing top phase is unreported, not zero; its change is unavailable.
  • Recorded configuration differs; these measurements do not isolate the code change.
  • baseline: source tree is dirty or its state is unknown; the commit alone does not identify the build.
  • candidate: source tree is dirty or its state is unknown; the commit alone does not identify the build.

Configuration differences

Setting Baseline Candidate
window.first_present 1149 1328

Frame and GPU times (ms)

Metric Baseline Candidate Change Change (%)
frame_ms.p50 31.120 26.698 -4.422 -14.210
frame_ms.p90 31.659 29.304 -2.355 -7.439
frame_ms.p99 32.202 33.106 +0.904 +2.807
frame_ms.max 33.652 43.172 +9.520 +28.290
mean_frame_ms 31.138 27.086 -4.051 -13.011
gpu_busy_ms_per_present 1.884 1.885 +0.001 +0.053

Top phases (ms per frame)

Metric Baseline Candidate Change Change (%)
Driver.Packet 1.267 1.220 -0.047 -3.710
Driver.Packet.draw 0.863 0.830 -0.033 -3.824
Graphics.Draw 2.800 1.777 -1.023 -36.536
Graphics.Draw.draw_and_resource_release 2.099 1.471 -0.628 -29.919
Graphics.DrawWithRecipe 2.598 1.479 -1.119 -43.072
Graphics.DrawWithRecipe.draw_and_resource_release 2.591 1.472 -1.119 -43.188
Recorder.Submit 1.968 1.885 -0.083 -4.217
Vulkan.DrawFromRecipe 2.614 1.494 -1.120 -42.846

perf, measured on the previous base, 10 s from 40 s into a run, same scene, on 1e20650e84 + #8091: on main, _Rb_tree_increment 3.0%, importRunBounds 1.9%, leasedIndexContaining 1.5%, walkRun 1.1% and sameRange 0.7% of samples. With this PR, _Rb_tree_increment is 2.2%, refreshImports itself 0.8%, and importRunBounds, leasedIndexContaining, walkRun and sameRange are each 0.2% or less. clock_gettime is about 22% on both sides.

Other measurements (same machine and scene, menu, main eaff876 + #8091):

  • The walk is the whole cost. A local build that skipped the walk (unsafe, measurement only) ran ~50 FPS with 616 live imports. APS5_PROFILE_GPU=1 shows the same recorded GPU time per present on both sides (2.4 ms in 59 batches), and APS5_NO_DRAW_INPUTS_IN_PLACE=1 changes nothing. So this is not perf: Red Dead Redemption (PPSA30528) G-buffer draws spend ~100x their GPU time reading vertex/index data in place from host imports #5895's in-place read cost.
  • perf on that base: importRun 4.3%, _Rb_tree_increment 2.3%, leasedIndexContaining 1.8% and sameRange 1.6% of user samples. With this PR, importRun, leasedIndexContaining and sameRange stay under 0.3%. refreshImports itself is 1.7%: the lease diff is linear in the ~800 registered ranges, and the remembered failures and refusals are still iterated.
  • Equivalence check. A local check mode ran the full walk's sameRange for every import the incremental refresh skipped. With the default budget it found 0 differences in ~3.4M skipped checks. None of the skipped unwatched imports were back in the write watch, and no imports overlapped. With a 128 MiB budget, the only differences were the refusal-dependent run shapes described above.

AGC, shader recompiler: ctest --test-dir build -R "agc|shader|recompiler" -V -j6 with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, on main 7903201bb4 and on this change applied to it, same machine, without #8091. main has since moved to 716cb74e08 with documentation changes only. Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.

Overlap with open pull requests, from tools/pr_overlap.py on 3c4aab5acc, which reports none:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 7900 GRE (RADV NAVI31), Mesa 26.2.5, Arch Linux kernel 7.2.11
  • AI-assisted: yes

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@janzezno

janzezno commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Summary files (APS5_TRACE_SUMMARY_EVERY=10) of the six SuperTuxKart runs in the table above, on main 0c6a5bd:

GitHub does not accept .jsonl, so each file is a JSON array of its interval lines. To digest one with tools/trace_digest.py, convert it back first:

python3 -c "import json,sys; [print(json.dumps(r)) for r in json.load(open(sys.argv[1]))]" aps5-summary-main+8091-run1.json > run1.jsonl
python3 tools/trace_digest.py run1.jsonl

@github-actions github-actions Bot removed the perf numbers missing perf pull request without a before and after summary line label Oct 21, 2026
@janzezno

Copy link
Copy Markdown
Contributor Author

Traces of the two windows whose summary lines are in the description: main + #8091 (0c6a5bd) and this PR + #8091 (ceefc5b), APS5_TRACE_SECONDS=40:10.
aps5-trace-0c6a5bd5938f-742372.json.gz
aps5-trace-ceefc5bcdeac-742647.json.gz

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 1896 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 2434 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 4449 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5021 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5372 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6187 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6194 docs/dev/debt/libSceAgcDriver.md
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6273 docs/dev/debt/libSceAgcDriver.md
PR 6280 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6300 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6412 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6481 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6743 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6804 docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6918 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6926 docs/dev/debt/libSceAgcDriver.md
PR 6959 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 6970 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6971 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6973 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6977 docs/dev/debt/libSceAgcDriver.md
PR 6987 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6989 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6995 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7002 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7048 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 7201 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7256 docs/dev/debt/libSceAgcDriver.md
PR 7275 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7457 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 7514 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7604 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7642 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 8223 docs/dev/debt/libSceAgcDriver.md
PR 8246 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8319 docs/dev/debt/libSceAgcDriver.md
PR 8395 docs/dev/debt/libSceAgcDriver.md
PR 8484 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 8542 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 8592 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 8939 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9012 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9020 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9248 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9335 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9356 docs/dev/debt/libSceAgcDriver.md
PR 9387 docs/dev/debt/libSceAgcDriver.md
PR 9431 docs/dev/debt/libSceAgcDriver.md
PR 9432 docs/dev/debt/libSceAgcDriver.md
PR 9457 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9508 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9592 docs/dev/debt/libSceAgcDriver.md
PR 9633 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9672 docs/dev/debt/libSceAgcDriver.md
PR 9673 docs/dev/debt/libSceAgcDriver.md
PR 9674 docs/dev/debt/libSceAgcDriver.md
PR 9675 docs/dev/debt/libSceAgcDriver.md
PR 9676 docs/dev/debt/libSceAgcDriver.md
PR 9748 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9749 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9790 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9842 docs/dev/debt/libSceAgcDriver.md
PR 9852 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9891 docs/dev/debt/libSceAgcDriver.md
PR 9892 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 9893 docs/dev/debt/libSceAgcDriver.md
PR 9895 docs/dev/debt/libSceAgcDriver.md
PR 9897 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9950 docs/dev/debt/libSceAgcDriver.md
PR 9969 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10000 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10026 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10043 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10049 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10064 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 10193 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10194 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10233 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 10333 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
docs/dev/debt/libSceAgcDriver.md
PR 10359 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md
PR 10435 docs/dev/debt/libSceAgcDriver.md
PR 10442 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 10489 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10757 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10846 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 11351 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 11485 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 11551 docs/dev/debt/libSceAgcDriver.md
PR 11557 core/libs/prx/libSceAgcDriver/CMakeLists.txt
docs/dev/debt/libSceAgcDriver.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a substantial performance investigation. The report includes same-machine SuperTuxKart comparisons, traces, an equivalence check across millions of skipped validations, a large focused test set, and paired Vulkan validation results with matching VUIDs. git diff --check passes; GitHub reports the head mergeable, and eligibility, conventions, intake, labels, and report checks pass.

I’m requesting changes for the remaining contribution-rule items:

  • The benchmark and test descriptions use bases 0c6a5bd593 and eaff87674c; current main is 4a17c71757. Please rebase onto current main, rerun the focused AGC tests on the same machine and GPU with the required validation-layer settings on both current main and the change, compare VUIDs, and refresh the performance summaries/traces against that base.
  • Please coordinate the shared refresh-loop behavior with #8926 before merge. Your overlap analysis notes that #8926 re-inserts imports in this loop and that the incremental path must add those imports to pendingImports if both changes land. Agree on order with its author and reflect any prerequisite in Depends on:. Also refresh the overlap check and coordinate any actual same-line overlaps found in the import insertion, test registration, and debt entry with their authors; the current body records adjacent conflicts with #7261, #6820/#8104, and #7844, while the current overlap scan did not complete in my shared checkout due concurrent temporary-ref updates.

No local AGC test or GPU run was possible in this review environment. The reported older-base results are useful evidence, but the repository requires current-main validation for this change before it is ready.

@janzezno
janzezno force-pushed the perf/incremental-import-refresh branch from ceefc5b to 3b7c43e Compare October 22, 2026 18:29
@janzezno

Copy link
Copy Markdown
Contributor Author

@janzezno

Copy link
Copy Markdown
Contributor Author

@MarcZX10 rebased onto b7d1d47a5f; the head is now 3b7c43eb75. On that base I reran the focused AGC tests with the validation layer on main and on this change (same three failures, same VUIDs with the same counts) and the SuperTuxKart comparison with #8091 on both sides (36.6 → 53.0 FPS average over three runs each, same live imports). The new summary files and traces are attached above, and the description has the results.

On the overlaps: I moved the new lines away from the neighbouring edits in importRunAt, retireImport, the refreshImports reset, the test registration and the debt file, without changing what they do. pr_overlap now reports only #8926. Its current version records the ranges of retired imports and rewatches them after the loop, and it no longer re-inserts imports, so pendingImports is not involved anymore. I've posted in #8926 where its two additions go in this PR's loop and proposed that neither declares a dependency and the one that merges second rebases. I'll record the answer in the description.

@adriadam10 adriadam10 self-assigned this Oct 23, 2026
Dripl1x added a commit to Dripl1x/AnyPS5 that referenced this pull request Oct 24, 2026
…ves guest memory alone

An unimported queue-0 label synced the recorder before its CPU store, so
every batch had finished first. Only what that work does to guest memory
can tell the two orders apart: a batch that reads guest memory in place (a
store landing first would be read), writes it (the guest would read the old
bytes after seeing the label), or has completion actions. Work that leaves
guest memory alone, such as draws from copied inputs into host-side
targets, cannot be observed by the guest before or after the label.

Recorder::UnfinishedGuestTouch reports what the open batch and the in-flight
batches whose fences have not signaled still do: in-place reads, noted
writes and labels, stores or sample dumps still to record, and completion
actions (also of signaled batches, and of batches another thread is
finishing). WriteLabelOnGpu stores the label at once (reason 7) when nothing
is reported, and syncs as before otherwise. APS5_NO_EARLY_LABELS=1 always
syncs. APS5_PROFILE_DRAW prints an [early-labels] line with the counts by
reason.

The open batch is left open and the reap of finished batches is put off:
nothing depends on either before the store. The caller submits and reaps
through SubmitAfterEarlyLabel once the label is stored, its waiters woken
and an end-of-pipe interrupt delivered; every caller that stores a reason-7
label calls it (the committer's label commit through submitDueAfterCommit).
With no completion action in any unfinished batch the reap neither changes
the import table nor what the label waits for.

Draws noted every in-place region of their resources as read, also the
regions of read-only elements that PrepareDrawBindings bound to snapshots,
which the GPU never reads in place. MarkGpuWrites now leaves out a region
that only snapshotted allocations overlap (every buffer element is a
descriptor of one allocation; a BDA build gets no draw bindings and keeps
noting every region).

SuperTuxKart (PPSA69421) main menu without the tutorial prompt (about 33
draws a frame) on Windows 11, RTX 3070 Laptop, Ryzen 7 5800H; main 9d4fb4f with boykopovar#7464 and boykopovar#9402, this commit and three other
local changes (an idle spin of the queue worker and committer, Windows
imports over 64 KiB settled at the import, import refresh spans diffed in
place); protocol runs interleaved, 3 each. With APS5_NO_EARLY_LABELS=1:
58.69 / 59.28 / 57.44 FPS, 8 / 7 / 18 present intervals over 20 ms, and
38 / 171 / 8 of about 470 frames waited for their vblank. With early
labels: 59.94 FPS in all three (the title's vblank cap), no interval over
20 ms, every frame waited for its vblank, and the longest idle gap of
queue worker 0 and the committer per frame went from 0.4 ms to 6.7-7.0 ms
(median). APS5_PROFILE_DRAW, cumulative over a run: 27090 labels stored
at once, 58 waited (42 for an in-place read, 1 for a write, 15 for
completion actions). boykopovar#7464's branch on the same main (with boykopovar#7465 under it,
without boykopovar#9402 and the other changes): 48.75-49.89 FPS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dripl1x added a commit to Dripl1x/AnyPS5 that referenced this pull request Oct 24, 2026
…mport

A Windows import of private memory under 1 MiB was compared until its
deferred settle, and the deferred return to the write watch is skipped
while a live storage image overlaps the range (the rewatch stamps it as
a CPU store, which the image would take as a write over its results).
SuperTuxKart views its small textures (96 KiB to 352 KiB) from storage
images, so they stayed compared for good and every draw sampling one
took the full revalidation walk with a byte compare.

Imports larger than one 64 KiB block now settle at the import, as the
1 MiB ones did, and stay in the write watch; 64 KiB imports, the size a
title maps around every submission, keep the deferred settle. The cost
moves to the import: each new private import from 128 KiB up to 1 MiB
waits for its settle read (the [buffers] line's "settled inside their
window" counts them). APS5_SETTLE_FLOOR_KIB sets the floor (1024
restores the old one), and the retire test, which needs a 128 KiB
import on the deferred path, sets it so.

SuperTuxKart (PPSA69421) main menu without the tutorial prompt (about 33
draws a frame) on Windows 11, RTX 3070 Laptop, Ryzen 7 5800H; main 9d4fb4f with boykopovar#7464, boykopovar#9402 and three local changes (early
unimported labels, an idle spin of the queue worker and committer, import
refresh spans diffed in place) plus this one; protocol runs interleaved.
With APS5_SETTLE_FLOOR_KIB=1024: 59.94 / 59.94 FPS (a third run lost the
window focus and is left out), the same as with this change at the
title's vblank cap, and the longest idle gap of queue worker 0 and the
committer per frame 5.9 and 6.2 ms (median) against 6.7-7.0 ms. On an
earlier stack (main a0900b9 with boykopovar#7464, boykopovar#9402, two local direct-memory
changes and the other three changes named above; the menu with the tutorial
prompt, about 59 draws a frame), APS5_PROFILE_DRAW over
10 s with the old floor against this one:
revalidations 33583 in 1339 ms with 19435 full walks (19355 for a failed
collect) against 18287 in 315 ms with 204 (audits only), a draw recorded
in 104 us against 82, and dumped menu frames 0 to 6 of both matched within
a mean difference of 0.001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dripl1x

Dripl1x commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

@janzezno a small follow-up idea for changedSpans, in case it's useful to you: da0331051e, one commit on your head 3b7c43eb75 (branch).

Instead of building a new refreshed vector from the lease at every registry change, it walks both lists once and updates refreshed in place: an entry whose range is still the leased one (recognised by owner, owner_before both ways, which compares the control blocks without reading either range) stays; only removed, added and replaced ranges are read, and their entries are erased, inserted or replaced. The spans it returns are built the same way.

Tested on Windows 11, RTX 3070 Laptop, on your head plus this commit: every ctest entry of agc_driver_recorder_tests (75), agc_driver_guest_memory_lifetime_tests (6), agc_driver_host_import_windows_tests, agc_host_import_retire_tests and guest_memory_tests (2) passes. In SuperTuxKart's menu (PPSA69421, which maps and unmaps a 64 KiB block around every draw) I could not measure a difference beyond the run-to-run spread at the title's 60 FPS cap (longest idle gap of the queue worker and committer per frame 6.3–6.8 ms without it, 6.7–7.0 ms with it), so I'm not opening a PR for it. Take it into #9402 if you like it, or ignore it.

AI-assisted: yes (Claude Code).

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the incremental refresh against the current main (5e6ae6e3d): changedSpans, the window test, the predecessor and cursor across spans, pendingImports, and the keys of the remembered failures and refusals. No defect found in the code. Before merge:

  • The branch merges cleanly on current main, but the validation runs were on b7d1d47a5f. GuestBufferMemory.cpp changed on main since then (completeSpaceWrites, MarkDirectWrites, WriteBack). Please rerun ctest --test-dir build -R "agc|shader|recompiler" -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on current main and on this change, same machine and GPU, and compare the VUIDs.
  • Refresh the SuperTuxKart summaries and traces against that base, as requested in the review.
  • Put the agreed order with #8926 in the description once its author confirms it.

The open CHANGES_REQUESTED review needs a re-review after these before it can merge.

@janzezno
janzezno force-pushed the perf/incremental-import-refresh branch from 3b7c43e to c952eee Compare October 24, 2026 08:10
@janzezno

Copy link
Copy Markdown
Contributor Author

@Dripl1x thanks for looking at changedSpans and for measuring it. I'll leave it out of this PR. You measured no difference beyond the spread, and each erase or insert in the middle of refreshed moves the rest of the vector. A registry change that replaces many ranges at once then costs the changed count times the registered count, where rebuilding the vector stays linear in the registered count. The current form is what was reviewed, so I'd rather not change it now.

@github-actions github-actions Bot added the perf numbers missing perf pull request without a before and after summary line label Oct 24, 2026
@janzezno

janzezno commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@adriadam10 thanks for checking the code. I rebased onto main 1e20650e84 (new head c952eee967, the samediff as before) and redid the runs there. The description has the details.

Edit: the SuperTuxKart numbers, traces and summaries are from a rerun with this PR built from the pushed headc952eee967 instead of a work tree on 1e20650e84, so the two sides' summaries carry different commits for the perf label check. Same protocol, machine and scene.

@github-actions github-actions Bot removed the perf numbers missing perf pull request without a before and after summary line label Oct 24, 2026
@janzezno
janzezno requested a review from adriadam10 October 24, 2026 15:08
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@janzezno
janzezno force-pushed the perf/incremental-import-refresh branch from c952eee to 90b365b Compare October 26, 2026 16:05
@janzezno

Copy link
Copy Markdown
Contributor Author

@adriadam10 @MarcZX10 #8926 merged, so this is rebased onto main 716cb74e08 (head 90b365b5b9) as agreed with EagleBearerYS: check notes the unwatched ranges of each import it retires, and they go back in the write watch once after both walks. Since main had moved by about 2400 commits, I reran everything on the new base:

The body has the digests, the summary lines and the performance_compare output. The two traces and the summary files of all runs are attached.

Could you take another look when you have time?
aps5-trace-90b365b5b9f0-151903.json.gz
aps5-trace-716cb74e0871-151594.json.gz
summaries-716cb74e08-90b365b5b9.zip

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@adriadam10
adriadam10 dismissed MarcZX10’s stale review October 26, 2026 16:16

Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.

@ycbuzi

ycbuzi commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Windows run of 90b365b merged onto main 48c160c (5bde8d28f8, clean). CI skipped the windows and linux jobs on this head. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON, with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1.

GPU driver agc_driver_recorder_tests (91 ctest entries)
NVIDIA GeForce RTX 4070 SUPER 616.92 89 pass; agc_host_import_cut_lifetime fails; agc_windowed_import_refresh exits 0xc0000135
NVIDIA GeForce GTX 1650 SUPER 616.92 same
AMD Radeon (Ryzen 9 7900 iGPU) 32.0.21030.2001 same

Each log shows Vulkan device: with the selected GPU. The build had no errors or warnings.

  • agc_windowed_import_refresh can't start under ctest on Windows. It exits 0xc0000135 (DLL not found) in 0.01 s, before the test runs. The test isn't in the if(WIN32) list that prepends $<TARGET_FILE_DIR:libc> to PATH for the other recorder tests (agc_sparse_run_import, agc_host_import_retirement and the rest, core/libs/prx/libSceAgcDriver/CMakeLists.txt line 1818 on main). With build\core\libs\libs\unpatched prepended by hand, it passes on all three GPUs.

    I added the name to that list, after agc_sparse_run_import, on this head merged onto main 88795ed. ctest --show-only=json-v1 then lists the PATH property, and plain ctest --repeat until-fail:3 -R ^agc_windowed_import_refresh$ passes 3 of 3 on each GPU, about 1.6 to 1.8 s per run:

    -        set_tests_properties(agc_recorder_read_list agc_host_import_unmap agc_parked_import_unmap agc_host_import_retirement agc_sparse_run_import agc_sparse_run_import_copied ...
    +        set_tests_properties(agc_recorder_read_list agc_host_import_unmap agc_parked_import_unmap agc_host_import_retirement agc_sparse_run_import agc_windowed_import_refresh agc_sparse_run_import_copied ...
  • agc_host_import_cut_lifetime fails with the same message as on main (agc_host_import_cut_lifetime fails on Windows since the merge of #9159 #10746, since fix(agc): keep a rewatched import's memory compared once it is shared #9159). It isn't from this PR.

  • Control: with main's Graphics/src/GuestBufferMemory.cpp and the rest of this head, agc_windowed_import_refresh also passes on the 4070 (with the PATH prepended). That matches the description, which says the test passes on main and on this PR. It guards the window query and doesn't go red without the change.

Not run: SuperTuxKart or any other title, and the performance comparison.

AI-assisted: yes

@adriadam10
adriadam10 force-pushed the perf/incremental-import-refresh branch from 90b365b to aca41a2 Compare October 26, 2026 18:22
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
janzezno and others added 2 commits October 26, 2026 21:19
refreshImports checked every live host import, failure and refusal
again at each guest allocation registry change. A title that maps
memory often (SuperTuxKart, ~1650 maps a second) paid a walk that grew
with the live imports: ~34 FPS with ~1.1 GiB of imports on RADV.

The import table now keeps a weak_ptr snapshot of the ranges it was
last checked against and diffs it with the new lease. Only imports
whose import window touches a changed span, and imports made since the
last refresh, are checked again. Every import is checked when the window
is 0 or the window or budget changed. SuperTuxKart's menu goes from
~34 to ~45 FPS with the same imports live.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the perf/incremental-import-refresh branch from aca41a2 to 6bbc37b Compare October 26, 2026 20:45
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@janzezno
janzezno force-pushed the perf/incremental-import-refresh branch from 6bbc37b to a6eeb21 Compare October 26, 2026 21:58
@janzezno

Copy link
Copy Markdown
Contributor Author

@adriadam10 thanks for the rebase and the Windows PATH fix.

After that push the overlap bot started listing eight PRs (#6182, #6185, #6186, #9565, #9712, #9875, #9898, #11451). Each of them adds its own test to the same Windows set_tests_properties(... ENVIRONMENT_MODIFICATION "PATH=...") line, so whichever merges second would conflict. I've force-pushed your second commit with agc_windowed_import_refresh taking its PATH in its own if(WIN32) block right after its registration. It does the same thing and leaves the shared list untouched. The first commit is unchanged from your 0f4106768c, rebased onto fc7e583e6e, and your authorship on the second commit stays.

tools/pr_overlap.py on the new head now reports no comparable PRs, and check_conventions passes. I've updated the body's overlap section too: #9879 is merged, and I added a line about the PATH block. #8896 merged a few minutes ago and also changes GuestBufferMemory.cpp. It merges cleanly with this branch. Its recent-import cache is reset by retireImport's epoch bump, so imports that refreshImports retires can't stay cached.

@janzezno

Copy link
Copy Markdown
Contributor Author

One correction to my last comment: I haven't run the new if(WIN32) block on Windows, and the hosted Windows job skips this PR. It uses the same pattern as agc_host_import_second_mapping, but that's my reading of the CMake, not a test result. @ycbuzi, since your run found the 0xc0000135, could you rerun ctest -R agc_windowed_import_refresh -V on a6eeb21482? Thanks.

@adriadam10
adriadam10 merged commit 4297464 into boykopovar:main Oct 27, 2026
11 of 12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked against current main after #9879: gateRefusals is still cleared after the generation check, and its color-target imports go through importRunAt, which records them in pendingImports, so the incremental walk checks them. The rest of the diff is unchanged from the reviewed head. agc_windowed_import_refresh gets its Windows PATH in its own if(WIN32) block; thanks @ycbuzi for the 0xc0000135 diagnosis; merged.

Dripl1x added a commit to Dripl1x/AnyPS5 that referenced this pull request Nov 20, 2026
…mport

A Windows import of private memory under 1 MiB was compared until its
deferred settle, and the deferred return to the write watch is skipped
while a live storage image overlaps the range (the rewatch stamps it as
a CPU store, which the image would take as a write over its results).
SuperTuxKart views its small textures (96 KiB to 352 KiB) from storage
images, so they stayed compared for good and every draw sampling one
took the full revalidation walk with a byte compare.

Imports larger than one 64 KiB block now settle at the import, as the
1 MiB ones did, and stay in the write watch; 64 KiB imports, the size a
title maps around every submission, keep the deferred settle. The cost
moves to the import: each new private import from 128 KiB up to 1 MiB
waits for its settle read (the [buffers] line's "settled inside their
window" counts them). APS5_SETTLE_FLOOR_KIB sets the floor (1024
restores the old one), and the retire test, which needs a 128 KiB
import on the deferred path, sets it so.

SuperTuxKart (PPSA69421) main menu without the tutorial prompt (about 33
draws a frame) on Windows 11, RTX 3070 Laptop, Ryzen 7 5800H; main 9d4fb4f with boykopovar#7464, boykopovar#9402 and three local changes (early
unimported labels, an idle spin of the queue worker and committer, import
refresh spans diffed in place) plus this one; protocol runs interleaved.
With APS5_SETTLE_FLOOR_KIB=1024: 59.94 / 59.94 FPS (a third run lost the
window focus and is left out), the same as with this change at the
title's vblank cap, and the longest idle gap of queue worker 0 and the
committer per frame 5.9 and 6.2 ms (median) against 6.7-7.0 ms. On an
earlier stack (main a0900b9 with boykopovar#7464, boykopovar#9402, two local direct-memory
changes and the other three changes named above; the menu with the tutorial
prompt, about 59 draws a frame), APS5_PROFILE_DRAW over
10 s with the old floor against this one:
revalidations 33583 in 1339 ms with 19435 full walks (19355 for a failed
collect) against 18287 in 315 ms with 204 (audits only), a draw recorded
in 104 us against 82, and dumped menu frames 0 to 6 of both matched within
a mean difference of 0.001.


Rebased onto main as one commit from 90b9574, 63e9ee1 and 17cee29; the initial DCC committer test added on main since gets the same 1 MiB floor as the initial DCC test.
LeandroLP23 pushed a commit to LeandroLP23/AnyPS5 that referenced this pull request Nov 21, 2026
…ves guest memory alone

An unimported queue-0 label synced the recorder before its CPU store, so
every batch had finished first. Only what that work does to guest memory
can tell the two orders apart: a batch that reads guest memory in place (a
store landing first would be read), writes it (the guest would read the old
bytes after seeing the label), or has completion actions. Work that leaves
guest memory alone, such as draws from copied inputs into host-side
targets, cannot be observed by the guest before or after the label.

Recorder::UnfinishedGuestTouch reports what the open batch and the in-flight
batches whose fences have not signaled still do: in-place reads, noted
writes and labels, stores or sample dumps still to record, and completion
actions (also of signaled batches, and of batches another thread is
finishing). WriteLabelOnGpu stores the label at once (reason 7) when nothing
is reported, and syncs as before otherwise. APS5_NO_EARLY_LABELS=1 always
syncs. APS5_PROFILE_DRAW prints an [early-labels] line with the counts by
reason.

The open batch is left open and the reap of finished batches is put off:
nothing depends on either before the store. The caller submits and reaps
through SubmitAfterEarlyLabel once the label is stored, its waiters woken
and an end-of-pipe interrupt delivered; every caller that stores a reason-7
label calls it (the committer's label commit through submitDueAfterCommit).
With no completion action in any unfinished batch the reap neither changes
the import table nor what the label waits for.

Draws noted every in-place region of their resources as read, also the
regions of read-only elements that PrepareDrawBindings bound to snapshots,
which the GPU never reads in place. MarkGpuWrites now leaves out a region
that only snapshotted allocations overlap (every buffer element is a
descriptor of one allocation; a BDA build gets no draw bindings and keeps
noting every region).

SuperTuxKart (PPSA69421) main menu without the tutorial prompt (about 33
draws a frame) on Windows 11, RTX 3070 Laptop, Ryzen 7 5800H; main 9d4fb4f with boykopovar#7464 and boykopovar#9402, this commit and three other
local changes (an idle spin of the queue worker and committer, Windows
imports over 64 KiB settled at the import, import refresh spans diffed in
place); protocol runs interleaved, 3 each. With APS5_NO_EARLY_LABELS=1:
58.69 / 59.28 / 57.44 FPS, 8 / 7 / 18 present intervals over 20 ms, and
38 / 171 / 8 of about 470 frames waited for their vblank. With early
labels: 59.94 FPS in all three (the title's vblank cap), no interval over
20 ms, every frame waited for its vblank, and the longest idle gap of
queue worker 0 and the committer per frame went from 0.4 ms to 6.7-7.0 ms
(median). APS5_PROFILE_DRAW, cumulative over a run: 27090 labels stored
at once, 58 waited (42 for an in-place read, 1 for a write, 15 for
completion actions). boykopovar#7464's branch on the same main (with boykopovar#7465 under it,
without boykopovar#9402 and the other changes): 48.75-49.89 FPS.
Dripl1x added a commit to Dripl1x/AnyPS5 that referenced this pull request Nov 22, 2026
…ves guest memory alone

An unimported queue-0 label synced the recorder before its CPU store, so
every batch had finished first. Only what that work does to guest memory
can tell the two orders apart: a batch that reads guest memory in place (a
store landing first would be read), writes it (the guest would read the old
bytes after seeing the label), or has completion actions. Work that leaves
guest memory alone, such as draws from copied inputs into host-side
targets, cannot be observed by the guest before or after the label.

Recorder::UnfinishedGuestTouch reports what the open batch and the in-flight
batches whose fences have not signaled still do: in-place reads, noted
writes and labels, stores or sample dumps still to record, and completion
actions (also of signaled batches, and of batches another thread is
finishing). WriteLabelOnGpu stores the label at once (reason 7) when nothing
is reported, and syncs as before otherwise. APS5_NO_EARLY_LABELS=1 always
syncs. APS5_PROFILE_DRAW prints an [early-labels] line with the counts by
reason.

The open batch is left open and the reap of finished batches is put off:
nothing depends on either before the store. The caller submits and reaps
through SubmitAfterEarlyLabel once the label is stored, its waiters woken
and an end-of-pipe interrupt delivered; every caller that stores a reason-7
label calls it (the committer's label commit through submitDueAfterCommit).
With no completion action in any unfinished batch the reap neither changes
the import table nor what the label waits for.

Draws noted every in-place region of their resources as read, also the
regions of read-only elements that PrepareDrawBindings bound to snapshots,
which the GPU never reads in place. MarkGpuWrites now leaves out a region
that only snapshotted allocations overlap (every buffer element is a
descriptor of one allocation; a BDA build gets no draw bindings and keeps
noting every region).

SuperTuxKart (PPSA69421) main menu without the tutorial prompt (about 33
draws a frame) on Windows 11, RTX 3070 Laptop, Ryzen 7 5800H; main 9d4fb4f with boykopovar#7464 and boykopovar#9402, this commit and three other
local changes (an idle spin of the queue worker and committer, Windows
imports over 64 KiB settled at the import, import refresh spans diffed in
place); protocol runs interleaved, 3 each. With APS5_NO_EARLY_LABELS=1:
58.69 / 59.28 / 57.44 FPS, 8 / 7 / 18 present intervals over 20 ms, and
38 / 171 / 8 of about 470 frames waited for their vblank. With early
labels: 59.94 FPS in all three (the title's vblank cap), no interval over
20 ms, every frame waited for its vblank, and the longest idle gap of
queue worker 0 and the committer per frame went from 0.4 ms to 6.7-7.0 ms
(median). APS5_PROFILE_DRAW, cumulative over a run: 27090 labels stored
at once, 58 waited (42 for an in-place read, 1 for a write, 15 for
completion actions). boykopovar#7464's branch on the same main (with boykopovar#7465 under it,
without boykopovar#9402 and the other changes): 48.75-49.89 FPS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants