perf(agc): reconcile host imports from logged allocation changes #26581

Merged
consolelogout merged 2 commits from upstream-pr/26581 into main 2026-11-25 02:03:07 +00:00
consolelogout commented 2026-11-24 06:05:37 +00:00 (Migrated from github.com)

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) whenever GuestAllocationsGeneration moved. Every guest malloc, free and realloc moves 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.

  • libc: the registry keeps a bounded log of the spans each generation changed (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 whose shared_ptr identity 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).
  • AGC: before HostImportFor, HostImportJoinedFor, HostImportSerial and HostImportsReconciledUnchanged refresh, refreshedFromLoggedChanges does what refreshImports would 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 with sameRange against 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 snapshot changedSpans diffs against is left as it was, so a later full refresh still covers the skipped spans.
  • guest_allocations_changes covers 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 mutation parameter of GuestAllocationsRegisterMainImage and GuestAllocationsRegisterImage, 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, main 38d22efc06 against b2d741e3cb. 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):

run commit presents frame p50 / p90 / p99 ms GPU busy per present
main 38d22efc06 294 33.5 / 36.5 / 41.6 8.1 ms
this PR b2d741e3cb 600 16.7 / 17.0 / 17.3 4.6 ms
main 38d22efc06 291 33.6 / 36.7 / 43.2 8.2 ms
this PR b2d741e3cb 600 16.7 / 17.0 / 17.2 4.6 ms

trace_digest.py of the first two, ms per frame:

thread main this PR
draw committer busy 29.2 (86 %): Graphics.Draw 18.2, Recorder.Sync 10.9 7.0 (42 %): Recorder.Sync 6.0, Graphics.Draw 0.8
queue worker 0x0 busy 13.9 (41 %) 1.1 (7 %)
presenter wait 0.4 15.5 (vsync)

On the first commit (bc7af2bbec), with APS5_PROFILE_DRAW=1, the draw phases vertex and lookup fell 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 with APS5_DUMP_FRAMES showed 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:

run commit presents frame p50 / p90 ms GPU busy per present
this PR b2d741e3cb 210 47.1 / 51.9 15.9 ms
main 38d22efc06 203 48.7 / 50.6 16.3 ms
this PR b2d741e3cb 208 47.6 / 49.7 16.1 ms

Across the session main ran from 187 to 211 presents (7 runs), the first commit from 191 to 206 (3 runs) and the code of b2d741e3cb from 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, SuperTuxKart main, SuperTuxKart this PR); the four traces are attached:

{"commit":"38d22efc0687","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA99847","title":"Godot PS5 Buffered Stdio Test M26 v0.2.10","content_version":"01.000.021","resolution":"1920x1080","window":{"spec":"seconds 20:10","first_present":529,"ms":10002.525},"presents":294,"frame_ms":{"p50":33.473,"p90":36.473,"p99":41.607,"max":43.307},"gpu_busy_ms_per_present":8.129,"worker_busy_pct":{"queue worker 0x0":41.242},"phase_totals_ms":{"Driver.Completion":2.758,"Driver.Draw":1918.932,"Driver.Draw.device_setup":10.057,"Driver.Draw.draw_enqueued":22.798,"Driver.Draw.post_compile_prepare":1.865,"Driver.Draw.prepare":13.735,"Driver.Draw.shader_compile_and_link":1867.761,"Driver.EndSubmission":0.883,"Driver.Packet":4121.398,"Driver.Packet.device_lock":1.990,"Driver.Packet.draw":1921.618,"Driver.Packet.execute":13.122,"Driver.Packet.flip_flush":0.763,"Driver.Packet.flush_between_packets":3.335,"Driver.Packet.pipeline_drain":2154.515,"Driver.Packet.pipeline_prepare":3.123,"Driver.Packet.prepare_memory":3.967,"Driver.Present":199.061,"Driver.Present.acquire_image":5.132,"Driver.Present.device_setup":0.148,"Driver.Present.gpu_mutex_wait":0.583,"Driver.Present.inflight_wait":0.850,"Driver.Present.present_display_buffer":39.204,"Driver.Present.queue_present":40.805,"Driver.Present.release_and_callback":0.449,"Driver.Present.render_fence_wait":111.065,"Driver.Present.resize":0.488,"Driver.Present.validate":0.110,"Driver.Suspend":0.212,"GpuMutex.wait.end":0.156,"GpuMutex.wait.present":0.006,"Graphics.Draw":5352.220,"Graphics.Draw.draw_and_resource_release":2673.124,"Graphics.Draw.index_upload":2667.106,"Graphics.Draw.validate":9.113,"Graphics.Draw.vertex_upload":1.517,"Graphics.DrawWithRecipe":48.423,"Graphics.DrawWithRecipe.draw_and_resource_release":45.953,"Graphics.DrawWithRecipe.index_upload":0.938,"Graphics.DrawWithRecipe.validate":0.866,"Graphics.DrawWithRecipe.vertex_upload":0.304,"Recorder.Reap":0.268,"Recorder.Submit":58.515,"Recorder.Sync":3196.381,"Shader.DrawStage":1826.325,"Shader.DrawStage.capture_resources":1798.887,"Shader.DrawStage.materialize":13.085,"Shader.DrawStage.prepared_invocation":13.524,"VideoOut.Flip":439.579,"VideoOut.Flip.completion_mutex_wait":0.262,"VideoOut.Flip.config_mutex_wait":0.043,"VideoOut.Flip.frame_limit":0.133,"VideoOut.Flip.notify_game":236.827,"VideoOut.Flip.present":199.407,"VideoOut.Flip.validate":0.318,"VideoOut.Flip.vblank_wait":0.154,"VideoOut.Flip.window_prepare":0.391,"VideoOut.Flip.window_title":1.213,"VideoOut.Readiness":0.867,"VideoOut.Readiness.locks_validate":0.348,"Vulkan.Acquire":4.825,"Vulkan.Acquire.acquire_fence_wait":0.794,"Vulkan.Acquire.acquire_image":2.990,"Vulkan.Acquire.fence_reset":0.823,"Vulkan.Acquire.retired_swapchains":0.126,"Vulkan.DrawFromRecipe":49.103,"Vulkan.Present":29.256,"Vulkan.Present.command_record_scale":12.311,"Vulkan.Present.pixel_upload":0.566,"Vulkan.Present.queue_submit":16.088,"Vulkan.QueuePresent":40.335,"Vulkan.QueuePresent.queue_present":39.867,"Vulkan.Retire":111.066,"Vulkan.Retire.wait":107.128},"top_phases_ms_per_frame":{"Graphics.Draw":18.205,"Driver.Packet":14.018,"Recorder.Sync":10.872,"Graphics.Draw.draw_and_resource_release":9.092,"Graphics.Draw.index_upload":9.072,"Driver.Packet.pipeline_drain":7.328,"Driver.Packet.draw":6.536,"Driver.Draw":6.527},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":4410,"Graphics.Barrier.present-blit":588,"Graphics.Barrier.storage-writeback":2646,"Graphics.RenderPass":1470,"Graphics.RenderPass.Close.command":882,"Graphics.RenderPass.Close.new-batch":588,"Graphics.RenderPass.Continued":2058},"trace_dropped":false,"trace":"aps5-trace-38d22efc0687-3332.json.gz"}
{"commit":"b2d741e3cb2f","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA99847","title":"Godot PS5 Buffered Stdio Test M26 v0.2.10","content_version":"01.000.021","resolution":"1920x1080","window":{"spec":"seconds 20:10","first_present":1135,"ms":10009.549},"presents":600,"frame_ms":{"p50":16.682,"p90":16.960,"p99":17.257,"max":17.602},"gpu_busy_ms_per_present":4.606,"worker_busy_pct":{"queue worker 0x0":7.423},"phase_totals_ms":{"Driver.Completion":0.665,"Driver.Draw":284.412,"Driver.Draw.device_setup":14.709,"Driver.Draw.draw_enqueued":51.939,"Driver.Draw.post_compile_prepare":2.838,"Driver.Draw.prepare":20.621,"Driver.Draw.shader_compile_and_link":189.761,"Driver.EndSubmission":1.226,"Driver.Packet":741.016,"Driver.Packet.device_lock":3.547,"Driver.Packet.draw":288.265,"Driver.Packet.execute":24.256,"Driver.Packet.flip_flush":0.851,"Driver.Packet.flush_between_packets":5.932,"Driver.Packet.pipeline_drain":394.847,"Driver.Packet.pipeline_prepare":5.601,"Driver.Packet.prepare_memory":6.202,"Driver.Present":255.815,"Driver.Present.acquire_image":8.983,"Driver.Present.device_setup":0.434,"Driver.Present.gpu_mutex_wait":2.472,"Driver.Present.inflight_wait":1.890,"Driver.Present.present_display_buffer":81.909,"Driver.Present.queue_present":66.288,"Driver.Present.release_and_callback":0.775,"Driver.Present.render_fence_wait":91.019,"Driver.Present.resize":1.355,"Driver.Present.validate":0.274,"Driver.Suspend":0.144,"GpuMutex.wait.flush":0.001,"GpuMutex.wait.present":1.293,"Graphics.Draw":477.834,"Graphics.Draw.draw_and_resource_release":442.824,"Graphics.Draw.index_upload":16.210,"Graphics.Draw.validate":14.181,"Graphics.Draw.vertex_upload":1.912,"Graphics.DrawWithRecipe":121.479,"Graphics.DrawWithRecipe.draw_and_resource_release":116.739,"Graphics.DrawWithRecipe.index_upload":1.821,"Graphics.DrawWithRecipe.validate":1.435,"Graphics.DrawWithRecipe.vertex_upload":0.776,"Recorder.Reap":0.485,"Recorder.Submit":114.652,"Recorder.Sync":3607.987,"Shader.DrawStage":124.207,"Shader.DrawStage.capture_resources":84.788,"Shader.DrawStage.materialize":18.342,"Shader.DrawStage.prepared_invocation":19.821,"VideoOut.Flip":9447.419,"VideoOut.Flip.completion_mutex_wait":0.529,"VideoOut.Flip.config_mutex_wait":0.053,"VideoOut.Flip.frame_limit":2.109,"VideoOut.Flip.notify_game":8.391,"VideoOut.Flip.present":258.056,"VideoOut.Flip.validate":0.539,"VideoOut.Flip.vblank_wait":9188.844,"VideoOut.Flip.window_prepare":1.593,"VideoOut.Flip.window_title":2.298,"VideoOut.Readiness":1.047,"VideoOut.Readiness.locks_validate":0.306,"Vulkan.Acquire":8.332,"Vulkan.Acquire.acquire_fence_wait":1.433,"Vulkan.Acquire.acquire_image":5.057,"Vulkan.Acquire.fence_reset":1.513,"Vulkan.Acquire.retired_swapchains":0.197,"Vulkan.DrawFromRecipe":122.887,"Vulkan.Present":55.383,"Vulkan.Present.command_record_scale":22.900,"Vulkan.Present.pixel_upload":0.986,"Vulkan.Present.queue_submit":30.970,"Vulkan.QueuePresent":65.460,"Vulkan.QueuePresent.queue_present":64.657,"Vulkan.Retire":91.117,"Vulkan.Retire.wait":83.799},"top_phases_ms_per_frame":{"VideoOut.Flip":15.746,"VideoOut.Flip.vblank_wait":15.315,"Recorder.Sync":6.013,"Driver.Packet":1.235,"Graphics.Draw":0.796,"Graphics.Draw.draw_and_resource_release":0.738,"Driver.Packet.pipeline_drain":0.658,"Driver.Packet.draw":0.480},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":9000,"Graphics.Barrier.present-blit":1200,"Graphics.Barrier.storage-writeback":5400,"Graphics.RenderPass":3000,"Graphics.RenderPass.Close.command":1800,"Graphics.RenderPass.Close.new-batch":1200,"Graphics.RenderPass.Continued":4200},"trace_dropped":false,"trace":"aps5-trace-b2d741e3cb2f-1192.json.gz"}
{"commit":"38d22efc0687","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PAD_RECORD":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"80:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 80:10","first_present":1580,"ms":10008.232},"presents":203,"frame_ms":{"p50":48.704,"p90":50.648,"p99":59.214,"max":74.517},"gpu_busy_ms_per_present":16.284,"worker_busy_pct":{"queue worker 0x0":5.540},"phase_totals_ms":{"Driver.Completion":1.422,"Driver.Draw":426.423,"Driver.Draw.device_setup":26.563,"Driver.Draw.draw_enqueued":91.908,"Driver.Draw.post_compile_prepare":6.657,"Driver.Draw.prepare":37.518,"Driver.Draw.shader_compile_and_link":255.198,"Driver.EndSubmission":3.002,"Driver.Packet":549.958,"Driver.Packet.device_lock":7.116,"Driver.Packet.draw":433.786,"Driver.Packet.execute":46.932,"Driver.Packet.flip_flush":0.252,"Driver.Packet.flush_between_packets":10.852,"Driver.Packet.pipeline_drain":9.941,"Driver.Packet.pipeline_prepare":11.234,"Driver.Packet.prepare_memory":10.826,"Driver.Present":101.196,"Driver.Present.acquire_image":2.976,"Driver.Present.device_setup":0.102,"Driver.Present.gpu_mutex_wait":0.353,"Driver.Present.inflight_wait":0.525,"Driver.Present.present_display_buffer":24.185,"Driver.Present.queue_present":68.614,"Driver.Present.release_and_callback":0.261,"Driver.Present.render_fence_wait":3.749,"Driver.Present.resize":0.270,"Driver.Present.validate":0.054,"Driver.Suspend":0.085,"Graphics.Draw":897.508,"Graphics.Draw.draw_and_resource_release":852.879,"Graphics.Draw.index_upload":19.838,"Graphics.Draw.validate":18.028,"Graphics.Draw.vertex_upload":2.747,"Graphics.DrawWithRecipe":935.372,"Graphics.DrawWithRecipe.draw_and_resource_release":884.839,"Graphics.DrawWithRecipe.index_upload":38.660,"Graphics.DrawWithRecipe.validate":5.666,"Graphics.DrawWithRecipe.vertex_upload":3.132,"Recorder.Reap":0.646,"Recorder.Submit":255.321,"Recorder.Sync":4586.739,"Shader.DrawStage":138.361,"Shader.DrawStage.capture_resources":92.027,"Shader.DrawStage.materialize":22.485,"Shader.DrawStage.prepared_invocation":22.203,"VideoOut.Flip":105.122,"VideoOut.Flip.completion_mutex_wait":0.150,"VideoOut.Flip.config_mutex_wait":0.019,"VideoOut.Flip.frame_limit":0.099,"VideoOut.Flip.notify_game":1.943,"VideoOut.Flip.present":101.391,"VideoOut.Flip.validate":0.220,"VideoOut.Flip.vblank_wait":0.112,"VideoOut.Flip.window_prepare":0.254,"VideoOut.Flip.window_title":0.831,"VideoOut.Readiness":0.392,"VideoOut.Readiness.locks_validate":0.152,"Vulkan.Acquire":2.768,"Vulkan.Acquire.acquire_fence_wait":0.446,"Vulkan.Acquire.acquire_image":1.738,"Vulkan.Acquire.fence_reset":0.420,"Vulkan.Acquire.retired_swapchains":0.104,"Vulkan.DrawFromRecipe":941.009,"Vulkan.Present":18.587,"Vulkan.Present.command_record_scale":7.701,"Vulkan.Present.pixel_upload":0.344,"Vulkan.Present.queue_submit":10.337,"Vulkan.QueuePresent":68.272,"Vulkan.QueuePresent.queue_present":67.866,"Vulkan.Retire":3.672,"Vulkan.Retire.wait":0.899},"top_phases_ms_per_frame":{"Recorder.Sync":22.595,"Vulkan.DrawFromRecipe":4.636,"Graphics.DrawWithRecipe":4.608,"Graphics.Draw":4.421,"Graphics.DrawWithRecipe.draw_and_resource_release":4.359,"Graphics.Draw.draw_and_resource_release":4.201,"Driver.Packet":2.709,"Driver.Packet.draw":2.137},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":20877,"Graphics.Barrier.present-blit":406,"Graphics.Barrier.storage-upload":2436,"Graphics.Barrier.storage-writeback":3654,"Graphics.RenderPass":6959,"Graphics.RenderPass.Close.command":609,"Graphics.RenderPass.Close.new-batch":6350,"Graphics.RenderPass.Continued":8476},"trace_dropped":false,"trace":"aps5-trace-38d22efc0687-25092.json.gz"}
{"commit":"b2d741e3cb2f","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PAD_RECORD":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"80:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 80:10","first_present":1341,"ms":10027.703},"presents":210,"frame_ms":{"p50":47.110,"p90":51.912,"p99":55.740,"max":68.831},"gpu_busy_ms_per_present":15.890,"worker_busy_pct":{"queue worker 0x0":5.913},"phase_totals_ms":{"Driver.Completion":1.477,"Driver.Draw":455.974,"Driver.Draw.device_setup":28.985,"Driver.Draw.draw_enqueued":96.310,"Driver.Draw.post_compile_prepare":7.335,"Driver.Draw.prepare":41.111,"Driver.Draw.shader_compile_and_link":273.442,"Driver.EndSubmission":3.567,"Driver.Packet":587.818,"Driver.Packet.device_lock":7.110,"Driver.Packet.draw":463.491,"Driver.Packet.execute":51.760,"Driver.Packet.flip_flush":0.279,"Driver.Packet.flush_between_packets":11.220,"Driver.Packet.pipeline_drain":10.394,"Driver.Packet.pipeline_prepare":11.907,"Driver.Packet.prepare_memory":11.423,"Driver.Present":117.227,"Driver.Present.acquire_image":3.020,"Driver.Present.device_setup":0.121,"Driver.Present.gpu_mutex_wait":0.371,"Driver.Present.inflight_wait":0.633,"Driver.Present.present_display_buffer":26.547,"Driver.Present.queue_present":82.121,"Driver.Present.release_and_callback":0.357,"Driver.Present.render_fence_wait":3.537,"Driver.Present.resize":0.312,"Driver.Present.validate":0.045,"Driver.Suspend":0.073,"Graphics.Draw":968.675,"Graphics.Draw.draw_and_resource_release":922.853,"Graphics.Draw.index_upload":19.859,"Graphics.Draw.validate":19.296,"Graphics.Draw.vertex_upload":2.883,"Graphics.DrawWithRecipe":1043.491,"Graphics.DrawWithRecipe.draw_and_resource_release":988.337,"Graphics.DrawWithRecipe.index_upload":41.866,"Graphics.DrawWithRecipe.validate":6.585,"Graphics.DrawWithRecipe.vertex_upload":3.409,"Recorder.Reap":0.649,"Recorder.Submit":264.772,"Recorder.Sync":4418.325,"Shader.DrawStage":145.426,"Shader.DrawStage.capture_resources":94.857,"Shader.DrawStage.materialize":23.922,"Shader.DrawStage.prepared_invocation":24.976,"VideoOut.Flip":121.360,"VideoOut.Flip.completion_mutex_wait":0.184,"VideoOut.Flip.config_mutex_wait":0.021,"VideoOut.Flip.frame_limit":0.110,"VideoOut.Flip.notify_game":2.282,"VideoOut.Flip.present":117.016,"VideoOut.Flip.validate":0.220,"VideoOut.Flip.vblank_wait":0.126,"VideoOut.Flip.window_prepare":0.282,"VideoOut.Flip.window_title":1.004,"VideoOut.Readiness":0.447,"VideoOut.Readiness.locks_validate":0.169,"Vulkan.Acquire":2.825,"Vulkan.Acquire.acquire_fence_wait":0.448,"Vulkan.Acquire.acquire_image":1.776,"Vulkan.Acquire.fence_reset":0.465,"Vulkan.Acquire.retired_swapchains":0.086,"Vulkan.DrawFromRecipe":1049.505,"Vulkan.Present":20.378,"Vulkan.Present.command_record_scale":8.414,"Vulkan.Present.pixel_upload":0.342,"Vulkan.Present.queue_submit":11.378,"Vulkan.QueuePresent":81.652,"Vulkan.QueuePresent.queue_present":81.090,"Vulkan.Retire":3.477,"Vulkan.Retire.wait":0.972},"top_phases_ms_per_frame":{"Recorder.Sync":21.040,"Vulkan.DrawFromRecipe":4.998,"Graphics.DrawWithRecipe":4.969,"Graphics.DrawWithRecipe.draw_and_resource_release":4.706,"Graphics.Draw":4.613,"Graphics.Draw.draw_and_resource_release":4.395,"Driver.Packet":2.799,"Driver.Packet.draw":2.207},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":21501,"Graphics.Barrier.present-blit":420,"Graphics.Barrier.storage-upload":2520,"Graphics.Barrier.storage-writeback":3780,"Graphics.RenderPass":7167,"Graphics.RenderPass.Close.command":630,"Graphics.RenderPass.Close.new-batch":6537,"Graphics.RenderPass.Continued":8820},"trace_dropped":false,"trace":"aps5-trace-b2d741e3cb2f-9944.json.gz"}

guest_allocations_changes passes 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) with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer pass 41 of 41 on main 38d22efc06, 42 of 42 on bc7af2bbec and 42 of 42 on b2d741e3cb; every log shows the loader inserting the layer (25 times), none has was not found, and none has a VUID- 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 on main at that base. The extra ones were agc_driver_queue_zero_quiet_interrupt and agc_driver_viewport_index, and on a second -j3 run here only agc_driver_linear_target_rectangle_bound. agc_driver_viewport_index also aborts on main in 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 on main too, mostly llvmpipe aborts and timeouts.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: Fixes #26456
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER, NVIDIA 617.42, Windows 10 22H2 (19045); llvmpipe (Mesa 26.0.8, LLVM 21.1.8), WSL2 Ubuntu 26.04.1
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5467035481 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26581). Originally posted by [consolelogout](https://github.com/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`) whenever `GuestAllocationsGeneration` moved. Every guest `malloc`, `free` and `realloc` moves 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. - **libc:** the registry keeps a bounded log of the spans each generation changed (`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 whose `shared_ptr` identity 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). - **AGC:** before `HostImportFor`, `HostImportJoinedFor`, `HostImportSerial` and `HostImportsReconciledUnchanged` refresh, `refreshedFromLoggedChanges` does what `refreshImports` would 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 with `sameRange` against 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 snapshot `changedSpans` diffs against is left as it was, so a later full refresh still covers the skipped spans. - `guest_allocations_changes` covers 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 `mutation` parameter of `GuestAllocationsRegisterMainImage` and `GuestAllocationsRegisterImage`, 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, `main` `38d22efc06` against `b2d741e3cb`. 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`): | run | commit | presents | frame p50 / p90 / p99 ms | GPU busy per present | |---|---|---|---|---| | main | 38d22efc0687 | 294 | 33.5 / 36.5 / 41.6 | 8.1 ms | | this PR | b2d741e3cb2f | 600 | 16.7 / 17.0 / 17.3 | 4.6 ms | | main | 38d22efc0687 | 291 | 33.6 / 36.7 / 43.2 | 8.2 ms | | this PR | b2d741e3cb2f | 600 | 16.7 / 17.0 / 17.2 | 4.6 ms | `trace_digest.py` of the first two, ms per frame: | thread | main | this PR | |---|---|---| | draw committer busy | 29.2 (86 %): `Graphics.Draw` 18.2, `Recorder.Sync` 10.9 | 7.0 (42 %): `Recorder.Sync` 6.0, `Graphics.Draw` 0.8 | | queue worker 0x0 busy | 13.9 (41 %) | 1.1 (7 %) | | presenter wait | 0.4 | 15.5 (vsync) | On the first commit (`bc7af2bbec`), with `APS5_PROFILE_DRAW=1`, the draw phases `vertex` and `lookup` fell 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 with `APS5_DUMP_FRAMES` showed 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`: | run | commit | presents | frame p50 / p90 ms | GPU busy per present | |---|---|---|---|---| | this PR | b2d741e3cb2f | 210 | 47.1 / 51.9 | 15.9 ms | | main | 38d22efc0687 | 203 | 48.7 / 50.6 | 16.3 ms | | this PR | b2d741e3cb2f | 208 | 47.6 / 49.7 | 16.1 ms | Across the session `main` ran from 187 to 211 presents (7 runs), the first commit from 191 to 206 (3 runs) and the code of `b2d741e3cb` from 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, SuperTuxKart `main`, SuperTuxKart this PR); the four traces are attached: ```json {"commit":"38d22efc0687","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA99847","title":"Godot PS5 Buffered Stdio Test M26 v0.2.10","content_version":"01.000.021","resolution":"1920x1080","window":{"spec":"seconds 20:10","first_present":529,"ms":10002.525},"presents":294,"frame_ms":{"p50":33.473,"p90":36.473,"p99":41.607,"max":43.307},"gpu_busy_ms_per_present":8.129,"worker_busy_pct":{"queue worker 0x0":41.242},"phase_totals_ms":{"Driver.Completion":2.758,"Driver.Draw":1918.932,"Driver.Draw.device_setup":10.057,"Driver.Draw.draw_enqueued":22.798,"Driver.Draw.post_compile_prepare":1.865,"Driver.Draw.prepare":13.735,"Driver.Draw.shader_compile_and_link":1867.761,"Driver.EndSubmission":0.883,"Driver.Packet":4121.398,"Driver.Packet.device_lock":1.990,"Driver.Packet.draw":1921.618,"Driver.Packet.execute":13.122,"Driver.Packet.flip_flush":0.763,"Driver.Packet.flush_between_packets":3.335,"Driver.Packet.pipeline_drain":2154.515,"Driver.Packet.pipeline_prepare":3.123,"Driver.Packet.prepare_memory":3.967,"Driver.Present":199.061,"Driver.Present.acquire_image":5.132,"Driver.Present.device_setup":0.148,"Driver.Present.gpu_mutex_wait":0.583,"Driver.Present.inflight_wait":0.850,"Driver.Present.present_display_buffer":39.204,"Driver.Present.queue_present":40.805,"Driver.Present.release_and_callback":0.449,"Driver.Present.render_fence_wait":111.065,"Driver.Present.resize":0.488,"Driver.Present.validate":0.110,"Driver.Suspend":0.212,"GpuMutex.wait.end":0.156,"GpuMutex.wait.present":0.006,"Graphics.Draw":5352.220,"Graphics.Draw.draw_and_resource_release":2673.124,"Graphics.Draw.index_upload":2667.106,"Graphics.Draw.validate":9.113,"Graphics.Draw.vertex_upload":1.517,"Graphics.DrawWithRecipe":48.423,"Graphics.DrawWithRecipe.draw_and_resource_release":45.953,"Graphics.DrawWithRecipe.index_upload":0.938,"Graphics.DrawWithRecipe.validate":0.866,"Graphics.DrawWithRecipe.vertex_upload":0.304,"Recorder.Reap":0.268,"Recorder.Submit":58.515,"Recorder.Sync":3196.381,"Shader.DrawStage":1826.325,"Shader.DrawStage.capture_resources":1798.887,"Shader.DrawStage.materialize":13.085,"Shader.DrawStage.prepared_invocation":13.524,"VideoOut.Flip":439.579,"VideoOut.Flip.completion_mutex_wait":0.262,"VideoOut.Flip.config_mutex_wait":0.043,"VideoOut.Flip.frame_limit":0.133,"VideoOut.Flip.notify_game":236.827,"VideoOut.Flip.present":199.407,"VideoOut.Flip.validate":0.318,"VideoOut.Flip.vblank_wait":0.154,"VideoOut.Flip.window_prepare":0.391,"VideoOut.Flip.window_title":1.213,"VideoOut.Readiness":0.867,"VideoOut.Readiness.locks_validate":0.348,"Vulkan.Acquire":4.825,"Vulkan.Acquire.acquire_fence_wait":0.794,"Vulkan.Acquire.acquire_image":2.990,"Vulkan.Acquire.fence_reset":0.823,"Vulkan.Acquire.retired_swapchains":0.126,"Vulkan.DrawFromRecipe":49.103,"Vulkan.Present":29.256,"Vulkan.Present.command_record_scale":12.311,"Vulkan.Present.pixel_upload":0.566,"Vulkan.Present.queue_submit":16.088,"Vulkan.QueuePresent":40.335,"Vulkan.QueuePresent.queue_present":39.867,"Vulkan.Retire":111.066,"Vulkan.Retire.wait":107.128},"top_phases_ms_per_frame":{"Graphics.Draw":18.205,"Driver.Packet":14.018,"Recorder.Sync":10.872,"Graphics.Draw.draw_and_resource_release":9.092,"Graphics.Draw.index_upload":9.072,"Driver.Packet.pipeline_drain":7.328,"Driver.Packet.draw":6.536,"Driver.Draw":6.527},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":4410,"Graphics.Barrier.present-blit":588,"Graphics.Barrier.storage-writeback":2646,"Graphics.RenderPass":1470,"Graphics.RenderPass.Close.command":882,"Graphics.RenderPass.Close.new-batch":588,"Graphics.RenderPass.Continued":2058},"trace_dropped":false,"trace":"aps5-trace-38d22efc0687-3332.json.gz"} {"commit":"b2d741e3cb2f","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"20:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA99847","title":"Godot PS5 Buffered Stdio Test M26 v0.2.10","content_version":"01.000.021","resolution":"1920x1080","window":{"spec":"seconds 20:10","first_present":1135,"ms":10009.549},"presents":600,"frame_ms":{"p50":16.682,"p90":16.960,"p99":17.257,"max":17.602},"gpu_busy_ms_per_present":4.606,"worker_busy_pct":{"queue worker 0x0":7.423},"phase_totals_ms":{"Driver.Completion":0.665,"Driver.Draw":284.412,"Driver.Draw.device_setup":14.709,"Driver.Draw.draw_enqueued":51.939,"Driver.Draw.post_compile_prepare":2.838,"Driver.Draw.prepare":20.621,"Driver.Draw.shader_compile_and_link":189.761,"Driver.EndSubmission":1.226,"Driver.Packet":741.016,"Driver.Packet.device_lock":3.547,"Driver.Packet.draw":288.265,"Driver.Packet.execute":24.256,"Driver.Packet.flip_flush":0.851,"Driver.Packet.flush_between_packets":5.932,"Driver.Packet.pipeline_drain":394.847,"Driver.Packet.pipeline_prepare":5.601,"Driver.Packet.prepare_memory":6.202,"Driver.Present":255.815,"Driver.Present.acquire_image":8.983,"Driver.Present.device_setup":0.434,"Driver.Present.gpu_mutex_wait":2.472,"Driver.Present.inflight_wait":1.890,"Driver.Present.present_display_buffer":81.909,"Driver.Present.queue_present":66.288,"Driver.Present.release_and_callback":0.775,"Driver.Present.render_fence_wait":91.019,"Driver.Present.resize":1.355,"Driver.Present.validate":0.274,"Driver.Suspend":0.144,"GpuMutex.wait.flush":0.001,"GpuMutex.wait.present":1.293,"Graphics.Draw":477.834,"Graphics.Draw.draw_and_resource_release":442.824,"Graphics.Draw.index_upload":16.210,"Graphics.Draw.validate":14.181,"Graphics.Draw.vertex_upload":1.912,"Graphics.DrawWithRecipe":121.479,"Graphics.DrawWithRecipe.draw_and_resource_release":116.739,"Graphics.DrawWithRecipe.index_upload":1.821,"Graphics.DrawWithRecipe.validate":1.435,"Graphics.DrawWithRecipe.vertex_upload":0.776,"Recorder.Reap":0.485,"Recorder.Submit":114.652,"Recorder.Sync":3607.987,"Shader.DrawStage":124.207,"Shader.DrawStage.capture_resources":84.788,"Shader.DrawStage.materialize":18.342,"Shader.DrawStage.prepared_invocation":19.821,"VideoOut.Flip":9447.419,"VideoOut.Flip.completion_mutex_wait":0.529,"VideoOut.Flip.config_mutex_wait":0.053,"VideoOut.Flip.frame_limit":2.109,"VideoOut.Flip.notify_game":8.391,"VideoOut.Flip.present":258.056,"VideoOut.Flip.validate":0.539,"VideoOut.Flip.vblank_wait":9188.844,"VideoOut.Flip.window_prepare":1.593,"VideoOut.Flip.window_title":2.298,"VideoOut.Readiness":1.047,"VideoOut.Readiness.locks_validate":0.306,"Vulkan.Acquire":8.332,"Vulkan.Acquire.acquire_fence_wait":1.433,"Vulkan.Acquire.acquire_image":5.057,"Vulkan.Acquire.fence_reset":1.513,"Vulkan.Acquire.retired_swapchains":0.197,"Vulkan.DrawFromRecipe":122.887,"Vulkan.Present":55.383,"Vulkan.Present.command_record_scale":22.900,"Vulkan.Present.pixel_upload":0.986,"Vulkan.Present.queue_submit":30.970,"Vulkan.QueuePresent":65.460,"Vulkan.QueuePresent.queue_present":64.657,"Vulkan.Retire":91.117,"Vulkan.Retire.wait":83.799},"top_phases_ms_per_frame":{"VideoOut.Flip":15.746,"VideoOut.Flip.vblank_wait":15.315,"Recorder.Sync":6.013,"Driver.Packet":1.235,"Graphics.Draw":0.796,"Graphics.Draw.draw_and_resource_release":0.738,"Driver.Packet.pipeline_drain":0.658,"Driver.Packet.draw":0.480},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":9000,"Graphics.Barrier.present-blit":1200,"Graphics.Barrier.storage-writeback":5400,"Graphics.RenderPass":3000,"Graphics.RenderPass.Close.command":1800,"Graphics.RenderPass.Close.new-batch":1200,"Graphics.RenderPass.Continued":4200},"trace_dropped":false,"trace":"aps5-trace-b2d741e3cb2f-1192.json.gz"} {"commit":"38d22efc0687","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PAD_RECORD":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"80:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 80:10","first_present":1580,"ms":10008.232},"presents":203,"frame_ms":{"p50":48.704,"p90":50.648,"p99":59.214,"max":74.517},"gpu_busy_ms_per_present":16.284,"worker_busy_pct":{"queue worker 0x0":5.540},"phase_totals_ms":{"Driver.Completion":1.422,"Driver.Draw":426.423,"Driver.Draw.device_setup":26.563,"Driver.Draw.draw_enqueued":91.908,"Driver.Draw.post_compile_prepare":6.657,"Driver.Draw.prepare":37.518,"Driver.Draw.shader_compile_and_link":255.198,"Driver.EndSubmission":3.002,"Driver.Packet":549.958,"Driver.Packet.device_lock":7.116,"Driver.Packet.draw":433.786,"Driver.Packet.execute":46.932,"Driver.Packet.flip_flush":0.252,"Driver.Packet.flush_between_packets":10.852,"Driver.Packet.pipeline_drain":9.941,"Driver.Packet.pipeline_prepare":11.234,"Driver.Packet.prepare_memory":10.826,"Driver.Present":101.196,"Driver.Present.acquire_image":2.976,"Driver.Present.device_setup":0.102,"Driver.Present.gpu_mutex_wait":0.353,"Driver.Present.inflight_wait":0.525,"Driver.Present.present_display_buffer":24.185,"Driver.Present.queue_present":68.614,"Driver.Present.release_and_callback":0.261,"Driver.Present.render_fence_wait":3.749,"Driver.Present.resize":0.270,"Driver.Present.validate":0.054,"Driver.Suspend":0.085,"Graphics.Draw":897.508,"Graphics.Draw.draw_and_resource_release":852.879,"Graphics.Draw.index_upload":19.838,"Graphics.Draw.validate":18.028,"Graphics.Draw.vertex_upload":2.747,"Graphics.DrawWithRecipe":935.372,"Graphics.DrawWithRecipe.draw_and_resource_release":884.839,"Graphics.DrawWithRecipe.index_upload":38.660,"Graphics.DrawWithRecipe.validate":5.666,"Graphics.DrawWithRecipe.vertex_upload":3.132,"Recorder.Reap":0.646,"Recorder.Submit":255.321,"Recorder.Sync":4586.739,"Shader.DrawStage":138.361,"Shader.DrawStage.capture_resources":92.027,"Shader.DrawStage.materialize":22.485,"Shader.DrawStage.prepared_invocation":22.203,"VideoOut.Flip":105.122,"VideoOut.Flip.completion_mutex_wait":0.150,"VideoOut.Flip.config_mutex_wait":0.019,"VideoOut.Flip.frame_limit":0.099,"VideoOut.Flip.notify_game":1.943,"VideoOut.Flip.present":101.391,"VideoOut.Flip.validate":0.220,"VideoOut.Flip.vblank_wait":0.112,"VideoOut.Flip.window_prepare":0.254,"VideoOut.Flip.window_title":0.831,"VideoOut.Readiness":0.392,"VideoOut.Readiness.locks_validate":0.152,"Vulkan.Acquire":2.768,"Vulkan.Acquire.acquire_fence_wait":0.446,"Vulkan.Acquire.acquire_image":1.738,"Vulkan.Acquire.fence_reset":0.420,"Vulkan.Acquire.retired_swapchains":0.104,"Vulkan.DrawFromRecipe":941.009,"Vulkan.Present":18.587,"Vulkan.Present.command_record_scale":7.701,"Vulkan.Present.pixel_upload":0.344,"Vulkan.Present.queue_submit":10.337,"Vulkan.QueuePresent":68.272,"Vulkan.QueuePresent.queue_present":67.866,"Vulkan.Retire":3.672,"Vulkan.Retire.wait":0.899},"top_phases_ms_per_frame":{"Recorder.Sync":22.595,"Vulkan.DrawFromRecipe":4.636,"Graphics.DrawWithRecipe":4.608,"Graphics.Draw":4.421,"Graphics.DrawWithRecipe.draw_and_resource_release":4.359,"Graphics.Draw.draw_and_resource_release":4.201,"Driver.Packet":2.709,"Driver.Packet.draw":2.137},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":20877,"Graphics.Barrier.present-blit":406,"Graphics.Barrier.storage-upload":2436,"Graphics.Barrier.storage-writeback":3654,"Graphics.RenderPass":6959,"Graphics.RenderPass.Close.command":609,"Graphics.RenderPass.Close.new-batch":6350,"Graphics.RenderPass.Continued":8476},"trace_dropped":false,"trace":"aps5-trace-38d22efc0687-25092.json.gz"} {"commit":"b2d741e3cb2f","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_PAD_RECORD":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"80:10"},"gpu":"NVIDIA GeForce RTX 4080 SUPER","driver":"NVIDIA 617.42","os":"Windows 10.0.19045","cpu":"11th Gen Intel(R) Core(TM) i5-11600 @ 2.80GHz","cpu_threads":12,"memory_mib":16220,"title_id":"PPSA69421","title":"SuperTuxKart","content_version":"00.001.000","resolution":"1920x1080","window":{"spec":"seconds 80:10","first_present":1341,"ms":10027.703},"presents":210,"frame_ms":{"p50":47.110,"p90":51.912,"p99":55.740,"max":68.831},"gpu_busy_ms_per_present":15.890,"worker_busy_pct":{"queue worker 0x0":5.913},"phase_totals_ms":{"Driver.Completion":1.477,"Driver.Draw":455.974,"Driver.Draw.device_setup":28.985,"Driver.Draw.draw_enqueued":96.310,"Driver.Draw.post_compile_prepare":7.335,"Driver.Draw.prepare":41.111,"Driver.Draw.shader_compile_and_link":273.442,"Driver.EndSubmission":3.567,"Driver.Packet":587.818,"Driver.Packet.device_lock":7.110,"Driver.Packet.draw":463.491,"Driver.Packet.execute":51.760,"Driver.Packet.flip_flush":0.279,"Driver.Packet.flush_between_packets":11.220,"Driver.Packet.pipeline_drain":10.394,"Driver.Packet.pipeline_prepare":11.907,"Driver.Packet.prepare_memory":11.423,"Driver.Present":117.227,"Driver.Present.acquire_image":3.020,"Driver.Present.device_setup":0.121,"Driver.Present.gpu_mutex_wait":0.371,"Driver.Present.inflight_wait":0.633,"Driver.Present.present_display_buffer":26.547,"Driver.Present.queue_present":82.121,"Driver.Present.release_and_callback":0.357,"Driver.Present.render_fence_wait":3.537,"Driver.Present.resize":0.312,"Driver.Present.validate":0.045,"Driver.Suspend":0.073,"Graphics.Draw":968.675,"Graphics.Draw.draw_and_resource_release":922.853,"Graphics.Draw.index_upload":19.859,"Graphics.Draw.validate":19.296,"Graphics.Draw.vertex_upload":2.883,"Graphics.DrawWithRecipe":1043.491,"Graphics.DrawWithRecipe.draw_and_resource_release":988.337,"Graphics.DrawWithRecipe.index_upload":41.866,"Graphics.DrawWithRecipe.validate":6.585,"Graphics.DrawWithRecipe.vertex_upload":3.409,"Recorder.Reap":0.649,"Recorder.Submit":264.772,"Recorder.Sync":4418.325,"Shader.DrawStage":145.426,"Shader.DrawStage.capture_resources":94.857,"Shader.DrawStage.materialize":23.922,"Shader.DrawStage.prepared_invocation":24.976,"VideoOut.Flip":121.360,"VideoOut.Flip.completion_mutex_wait":0.184,"VideoOut.Flip.config_mutex_wait":0.021,"VideoOut.Flip.frame_limit":0.110,"VideoOut.Flip.notify_game":2.282,"VideoOut.Flip.present":117.016,"VideoOut.Flip.validate":0.220,"VideoOut.Flip.vblank_wait":0.126,"VideoOut.Flip.window_prepare":0.282,"VideoOut.Flip.window_title":1.004,"VideoOut.Readiness":0.447,"VideoOut.Readiness.locks_validate":0.169,"Vulkan.Acquire":2.825,"Vulkan.Acquire.acquire_fence_wait":0.448,"Vulkan.Acquire.acquire_image":1.776,"Vulkan.Acquire.fence_reset":0.465,"Vulkan.Acquire.retired_swapchains":0.086,"Vulkan.DrawFromRecipe":1049.505,"Vulkan.Present":20.378,"Vulkan.Present.command_record_scale":8.414,"Vulkan.Present.pixel_upload":0.342,"Vulkan.Present.queue_submit":11.378,"Vulkan.QueuePresent":81.652,"Vulkan.QueuePresent.queue_present":81.090,"Vulkan.Retire":3.477,"Vulkan.Retire.wait":0.972},"top_phases_ms_per_frame":{"Recorder.Sync":21.040,"Vulkan.DrawFromRecipe":4.998,"Graphics.DrawWithRecipe":4.969,"Graphics.DrawWithRecipe.draw_and_resource_release":4.706,"Graphics.Draw":4.613,"Graphics.Draw.draw_and_resource_release":4.395,"Driver.Packet":2.799,"Driver.Packet.draw":2.207},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.draw":21501,"Graphics.Barrier.present-blit":420,"Graphics.Barrier.storage-upload":2520,"Graphics.Barrier.storage-writeback":3780,"Graphics.RenderPass":7167,"Graphics.RenderPass.Close.command":630,"Graphics.RenderPass.Close.new-batch":6537,"Graphics.RenderPass.Continued":8820},"trace_dropped":false,"trace":"aps5-trace-b2d741e3cb2f-9944.json.gz"} ``` `guest_allocations_changes` passes 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`) with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer` pass 41 of 41 on `main` 38d22efc06, 42 of 42 on `bc7af2bbec` and 42 of 42 on `b2d741e3cb`; every log shows the loader inserting the layer (25 times), none has `was not found`, and none has a `VUID-` 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 on `main` at that base. The extra ones were `agc_driver_queue_zero_quiet_interrupt` and `agc_driver_viewport_index`, and on a second `-j3` run here only `agc_driver_linear_target_rectangle_bound`. `agc_driver_viewport_index` also aborts on `main` in 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 on `main` too, mostly llvmpipe aborts and timeouts. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: Fixes #26456 - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4080 SUPER, NVIDIA 617.42, Windows 10 22H2 (19045); llvmpipe (Mesa 26.0.8, LLVM 21.1.8), WSL2 Ubuntu 26.04.1 - [x] AI-assisted: yes
Jazeupoi commented 2026-11-24 10:48:35 +00:00 (Migrated from github.com)

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 main 00ede212a0 with 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:

run presents frame p50 / p90 / p99 ms draw committer busy per frame GPU busy per present
without the PR 75 250.4 / 345.3 / 594.8 150.8 ms (56 %) 25.3 ms
this PR 265 68.5 / 109.6 / 165.2 24.5 ms (32 %) 10.4 ms
this PR 260 70.3 / 116.5 / 145.2 23.9 ms (31 %) 8.7 ms
without the PR 74 257.6 / 334.3 / 443.7 149.0 ms (55 %) 26.5 ms

Why it's slow without the PR. I added temporary counters in GuestAllocationsAcquire and GuestAllocationsBegin, on the tree without the PR. In this scene they show:

  • 175,525 ranges in the registry,
  • about 200 mutations per second,
  • about 23 GuestAllocationsAcquire calls 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_COMMITTER on the same tree: GuestAllocationsAcquire is 29 % of the committer's samples, mostly _Rb_tree_increment under it, reached through HostImportsReconciledUnchanged and HostImportFor. In the trace that is 3 to 4 draws per frame at about 35 ms each, split between index_upload and draw_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_changes test, 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6037839603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26581#pullrequestreview-6037839603). Originally posted by [Jazeupoi](https://github.com/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 `main` 00ede212a0 with 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: | run | presents | frame p50 / p90 / p99 ms | draw committer busy per frame | GPU busy per present | |---|---|---|---|---| | without the PR | 75 | 250.4 / 345.3 / 594.8 | 150.8 ms (56 %) | 25.3 ms | | this PR | 265 | 68.5 / 109.6 / 165.2 | 24.5 ms (32 %) | 10.4 ms | | this PR | 260 | 70.3 / 116.5 / 145.2 | 23.9 ms (31 %) | 8.7 ms | | without the PR | 74 | 257.6 / 334.3 / 443.7 | 149.0 ms (55 %) | 26.5 ms | **Why it's slow without the PR.** I added temporary counters in `GuestAllocationsAcquire` and `GuestAllocationsBegin`, on the tree without the PR. In this scene they show: - 175,525 ranges in the registry, - about 200 mutations per second, - about 23 `GuestAllocationsAcquire` calls 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_COMMITTER` on the same tree: `GuestAllocationsAcquire` is 29 % of the committer's samples, mostly `_Rb_tree_increment` under it, reached through `HostImportsReconciledUnchanged` and `HostImportFor`. In the trace that is 3 to 4 draws per frame at about 35 ms each, split between `index_upload` and `draw_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_changes` test, 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: - [aps5-trace-00ede212a077-7936.json.gz](https://github.com/user-attachments/files/35326935/aps5-trace-00ede212a077-7936.json.gz) - [aps5-trace-00ede212a077-13568.json.gz](https://github.com/user-attachments/files/35326938/aps5-trace-00ede212a077-13568.json.gz) - [aps5-trace-00ede212a077-10512.json.gz](https://github.com/user-attachments/files/35326937/aps5-trace-00ede212a077-10512.json.gz) - [aps5-trace-00ede212a077-4672.json.gz](https://github.com/user-attachments/files/35326934/aps5-trace-00ede212a077-4672.json.gz) - [aps5-summary.txt](https://github.com/user-attachments/files/35326932/aps5-summary.txt) AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!26581
No description provided.