perf(agc): share collect walks between threads after the caller's ordering point #17786

Merged
klosixgaming-arch merged 7 commits from upstream-pr/17786 into main 2026-11-17 03:17:10 +00:00
klosixgaming-arch commented 2026-11-09 15:55:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-11-09T15:55:30Z.


What

Queue worker 0 and the draw committer spend a large share of their time in Windows write-watch walks (GetWriteWatch through collectWindowsWrites). These walks check whether the game's CPU wrote a surface before a draw or dispatch reads it. On Cyberpunk 2077's character creator a diagnostic counted about 280,000 walks per 10 s over 166 GB of address range, taking 3.1 s. Only 0.7% of them found a CPU write. The same 3-64 MB render targets were walked hundreds of times, because the collect memo is per thread and is reset at every ordering point (about 1,400 per 10 s).

This change shares walks between threads by the time they started:

  • Each completed memoized walk records its start time in a shared map. Before walking, a collect checks that map. When any thread walked the same range strictly after the caller's ordering point (and the unwatch serial and allocation mapping still match), the collect skips its walk. Shared hits are not copied into the per-thread memo ring, so the ring keeps only the thread's own walks.
  • A submission's ordering point is the time the game called Submit (enqueuedAt), not the time the worker reaches it. With the usual backlog of a few hundred ms, this lets walks made while earlier submissions ran serve the later ones. A submission with a rewind tail uses the current time. When a submission does not bump the epoch (it was enqueued before the last bump), its point is raised to its submit time.
  • A WAIT_REG_MEM that a label stored by this driver satisfies takes the ordering point of the queue that stored it. A queue's point never moves earlier. The rules for that inheritance:
    • The satisfying store must be the newest matching entry of the label's history, and every newer entry must be an ordered driver store.
    • No CPU write may have touched the label since that store. Each label store records the tracker generation, and the check uses UnchangedSinceCollected.
    • Stores whose value comes from memory (COPY_DATA, DMA_DATA, 0x83, commitStore) never pass on a point.
    • Late recorder hits, landing waits and waits held at submit keep the old behaviour (current time).
    • A predicated packet publishes its read time as the queue's point.
    • Labels the CPU wrote keep the current time.
  • The draw committer follows the worker's point through the epoch token (a 4096-slot ring of token and point).
  • APS5_NO_SHARED_COLLECT_WALKS turns the lookups off, and APS5_AB can toggle it. With APS5_PROFILE_DRAW, an [epoch] line reports per queue how many ordering points fell at the bump and how far back the rest lie.

Why a shared walk is never too old

A collect takes a shared walk only when the walk started strictly after the caller's ordering point (started > since). The start time is read before the walk takes the tracker lock and calls GetWriteWatch, so the walk reports every CPU store that was visible before its start. Both times come from steady_clock. So it is enough that every CPU store a packet must see is visible before the packet's point:

  1. Stores before Submit. Submit reads enqueuedAt while it holds the driver's submit mutex. Taking the mutex makes the submitting thread's earlier stores visible first. A store by another thread is ordered before the submission only if the guest synchronized it with the submitting thread before Submit, and x64 makes a store visible to all threads at once. So these stores are visible before enqueuedAt, and a walk that started after it reports them.
  2. Stores after Submit and before the worker reaches the packet. On the GPU, such a store is ordered before a packet only through a WAIT_REG_MEM that a label stored after the store satisfies. A packet that no such wait orders is not ordered after the store on hardware either: the GPU may read the memory before or after it. Such a packet may take a walk made between Submit and the store. For the packets after the wait:
    • The CPU stored the label. The worker sees the value only once the CPU's label store is visible, and x64 makes the CPU's earlier stores visible before it. The wait's ordering point is the current time, which is after the store. A walk made before the store started before that point, so it cannot serve these packets.
    • Another queue stored the label (an ordered driver store, with no CPU write to the label since, as above). The packets inherit that queue's published point. The writer published its point (publishQueueSince at each of its ordering points; a predicated packet also publishes its read time) before it ran the label's packet, and it records the store in the label history after that. The waiting worker finds the store in the history under the same mutex before it reads the published point. So it reads a point at least as late as the writer's point at the label store, and by the same two cases on the writer's queue, every CPU store the label store was ordered after was visible before that point. The published point is a running maximum. A later point than needed only costs a walk.
    • This queue stored the label. As on main, there is no new ordering point. The queue's own earlier point already covers what the label store was ordered after.
  3. Everything else takes the current time: a submission with a rewind tail, late recorder hits, landing waits, waits held at submit, labels whose value came from memory, labels the CPU wrote since the driver's store, and a draw-committer token whose ring slot was overwritten. On each thread, a point never moves earlier and never past the current time.

CheckStoreAfterSubmit in agc_collect_memo_generation pins case 2.

Tested

Body Type on current main, 2026-11-15

Cyberpunk 2077 (PPSA03974) 02.120.000, character creator Body Type, 3200x1800; Windows 11 (10.0.26200), RTX 5090 (NVIDIA 617.42), Ryzen 9 9950X3D. Both builds are main b39603dbdc + #19071 (the game only reaches the creator with it); the change is merged on top. Each line is the 20 s trace window opened about 80 s after entering the creator, one boot each, the same environment on both sides.

main + #19071 (262be96458), 136 presents in the window:

{"commit":"262be96458b9","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":5148,"ms":20122.874},"presents":136,"frame_ms":{"p50":146.163,"p90":159.123,"p99":174.569,"max":184.194},"gpu_busy_ms_per_present":34.750,"worker_busy_pct":{"queue worker 0x0":99.015,"queue worker 0x23":99.848},"phase_totals_ms":{"Driver.Completion":9.253,"Driver.Dispatch":11633.138,"Driver.Dispatch.capture_resources":492.551,"Driver.Dispatch.decode_key_device_setup":118.250,"Driver.Dispatch.lookup_cache":84.688,"Driver.Dispatch.materialize":120.716,"Driver.Dispatch.prepared_invocation":87.444,"Driver.Draw":2343.280,"Driver.Draw.device_setup":49.600,"Driver.Draw.draw_enqueued":369.312,"Driver.Draw.post_compile_prepare":18.165,"Driver.Draw.prepare":137.098,"Driver.Draw.shader_compile_and_link":1750.003,"Driver.EndSubmission":410.628,"Driver.Packet":39596.973,"Driver.Packet.device_lock":43.654,"Driver.Packet.dispatch":18688.162,"Driver.Packet.draw":2354.748,"Driver.Packet.execute":165.861,"Driver.Packet.flip_flush":0.382,"Driver.Packet.flush_between_packets":308.698,"Driver.Packet.memory_wait":16555.698,"Driver.Packet.pipeline_drain":995.397,"Driver.Packet.pipeline_prepare":69.406,"Driver.Packet.prepare_memory":92.799,"Driver.Packet.rendering_wait":0.201,"Driver.Present":118.028,"Driver.Present.acquire_image":2.683,"Driver.Present.device_setup":0.119,"Driver.Present.gpu_mutex_wait":0.954,"Driver.Present.inflight_wait":0.557,"Driver.Present.present_display_buffer":24.429,"Driver.Present.queue_present":83.541,"Driver.Present.release_and_callback":0.169,"Driver.Present.render_fence_wait":5.058,"Driver.Present.resize":0.356,"Driver.Present.validate":0.054,"Driver.Suspend":0.033,"GpuMutex.wait.copy":9.628,"GpuMutex.wait.dispatch":1395.623,"GpuMutex.wait.draw":253.664,"GpuMutex.wait.end":260.739,"GpuMutex.wait.fill":104.233,"GpuMutex.wait.flush":21.594,"GpuMutex.wait.hook":3011.188,"GpuMutex.wait.indirect":44.177,"GpuMutex.wait.label":315.496,"GpuMutex.wait.other":91.788,"GpuMutex.wait.present":0.573,"GpuMutex.wait.wait":5.090,"Graphics.Draw":7475.813,"Graphics.Draw.draw_and_resource_release":6958.001,"Graphics.Draw.index_upload":124.894,"Graphics.Draw.validate":119.879,"Graphics.Draw.vertex_upload":259.086,"Graphics.DrawWithRecipe":229.820,"Graphics.DrawWithRecipe.draw_and_resource_release":150.832,"Graphics.DrawWithRecipe.index_upload":0.083,"Graphics.DrawWithRecipe.validate":1.012,"Graphics.DrawWithRecipe.vertex_upload":0.605,"Recorder.Reap":146.317,"Recorder.Submit":931.159,"Recorder.Sync":487.369,"Recorder.WaitSerial":1007.418,"Resources.Complete":193.153,"Resources.Prepare":106.945,"Shader.DrawStage":1550.089,"Shader.DrawStage.capture_resources":1169.403,"Shader.DrawStage.materialize":293.753,"Shader.DrawStage.prepared_invocation":80.115,"Shader.ResolveAbi":96.093,"Shader.ResolveGraphicsAbi":18.714,"Shader.ResolveGraphicsStagesAbi":96.054,"VideoOut.Flip":143.933,"VideoOut.Flip.completion_mutex_wait":0.230,"VideoOut.Flip.config_mutex_wait":0.017,"VideoOut.Flip.frame_limit":0.104,"VideoOut.Flip.notify_game":14.205,"VideoOut.Flip.present":119.756,"VideoOut.Flip.validate":0.208,"VideoOut.Flip.vblank_wait":0.128,"VideoOut.Flip.window_prepare":0.299,"VideoOut.Flip.window_title":8.848,"VideoOut.Readiness":0.480,"VideoOut.Readiness.locks_validate":0.203,"Vulkan.Acquire":2.469,"Vulkan.Acquire.acquire_fence_wait":0.301,"Vulkan.Acquire.acquire_image":1.636,"Vulkan.Acquire.fence_reset":0.392,"Vulkan.Acquire.retired_swapchains":0.079,"Vulkan.Dispatch":5299.200,"Vulkan.Dispatch.command_record":493.646,"Vulkan.Dispatch.shader_resources":4792.257,"Vulkan.DispatchRecipe":512.100,"Vulkan.DispatchRecipe.command_record":493.763,"Vulkan.DrawFromRecipe":230.726,"Vulkan.Present":11.240,"Vulkan.Present.command_record_scale":5.475,"Vulkan.Present.pixel_upload":0.545,"Vulkan.Present.queue_submit":5.094,"Vulkan.QueuePresent":83.150,"Vulkan.QueuePresent.queue_present":82.940,"Vulkan.Retire":5.038,"Vulkan.Retire.wait":2.912},"top_phases_ms_per_frame":{"Driver.Packet":291.154,"Driver.Packet.dispatch":137.413,"Driver.Packet.memory_wait":121.733,"Driver.Dispatch":85.538,"Graphics.Draw":54.969,"Graphics.Draw.draw_and_resource_release":51.162,"Vulkan.Dispatch":38.965,"Vulkan.Dispatch.shader_resources":35.237},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":2785,"Graphics.Barrier.dcc-clear":4896,"Graphics.Barrier.dcc-keys":2176,"Graphics.Barrier.dispatch-lead":47353,"Graphics.Barrier.dispatch-trail":40772,"Graphics.Barrier.draw":24921,"Graphics.Barrier.fill":7943,"Graphics.Barrier.fill-clear":3808,"Graphics.Barrier.indirect-args":9970,"Graphics.Barrier.input-mirror":253,"Graphics.Barrier.label-run":46157,"Graphics.Barrier.present-blit":544,"Graphics.Barrier.shadow-publish":6258,"Graphics.Barrier.staging-in":15386,"Graphics.Barrier.staging-out":6664,"Graphics.Barrier.storage-upload":30938,"Graphics.Barrier.storage-writeback":45180,"Graphics.BarrierMerged.copy":563,"Graphics.BarrierMerged.dispatch-lead":13359,"Graphics.BarrierMerged.fill":2389,"Graphics.BarrierMerged.shadow-publish":6254,"Graphics.BarrierMerged.staging-in":4606,"Graphics.BarrierMerged.staging-out":6664,"Graphics.BarrierMerged.storage-writeback":13529,"Graphics.Copy":17803,"Graphics.Copy.bytes":43738646544,"Graphics.RenderPass":11159,"Graphics.RenderPass.Close.command":7250,"Graphics.RenderPass.Close.image":935,"Graphics.RenderPass.Close.new-batch":2974,"Graphics.RenderPass.Continued":22499},"trace_dropped":false,"trace":"aps5-trace-262be96458b9-48624.json.gz"}

This PR on the same base (e66d0510c5), 145 presents in the window:

{"commit":"e66d0510c55e","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":5269,"ms":20087.295},"presents":145,"frame_ms":{"p50":135.035,"p90":157.094,"p99":187.988,"max":205.423},"gpu_busy_ms_per_present":33.766,"worker_busy_pct":{"queue worker 0x0":98.903,"queue worker 0x23":99.845},"phase_totals_ms":{"Driver.Completion":9.820,"Driver.Dispatch":11448.224,"Driver.Dispatch.capture_resources":505.894,"Driver.Dispatch.decode_key_device_setup":126.495,"Driver.Dispatch.lookup_cache":90.856,"Driver.Dispatch.materialize":124.359,"Driver.Dispatch.prepared_invocation":90.797,"Driver.Draw":2432.020,"Driver.Draw.device_setup":51.471,"Driver.Draw.draw_enqueued":385.448,"Driver.Draw.post_compile_prepare":18.963,"Driver.Draw.prepare":145.994,"Driver.Draw.shader_compile_and_link":1810.589,"Driver.EndSubmission":356.255,"Driver.Packet":39557.025,"Driver.Packet.device_lock":48.741,"Driver.Packet.dispatch":18329.904,"Driver.Packet.draw":2444.195,"Driver.Packet.execute":169.810,"Driver.Packet.flip_flush":0.372,"Driver.Packet.flush_between_packets":304.915,"Driver.Packet.memory_wait":16854.945,"Driver.Packet.pipeline_drain":909.072,"Driver.Packet.pipeline_prepare":73.834,"Driver.Packet.prepare_memory":99.961,"Driver.Packet.rendering_wait":0.220,"Driver.Present":128.671,"Driver.Present.acquire_image":3.048,"Driver.Present.device_setup":0.130,"Driver.Present.gpu_mutex_wait":0.866,"Driver.Present.inflight_wait":0.452,"Driver.Present.present_display_buffer":29.712,"Driver.Present.queue_present":86.786,"Driver.Present.release_and_callback":0.177,"Driver.Present.render_fence_wait":7.012,"Driver.Present.resize":0.345,"Driver.Present.validate":0.042,"Driver.Suspend":0.036,"GpuMutex.wait.copy":10.918,"GpuMutex.wait.dispatch":1322.768,"GpuMutex.wait.draw":276.350,"GpuMutex.wait.end":195.752,"GpuMutex.wait.fill":145.511,"GpuMutex.wait.flush":23.594,"GpuMutex.wait.hook":2873.594,"GpuMutex.wait.indirect":61.113,"GpuMutex.wait.label":330.817,"GpuMutex.wait.other":84.954,"GpuMutex.wait.present":0.484,"GpuMutex.wait.wait":5.718,"Graphics.Draw":6741.942,"Graphics.Draw.draw_and_resource_release":6176.689,"Graphics.Draw.index_upload":133.006,"Graphics.Draw.validate":136.353,"Graphics.Draw.vertex_upload":280.042,"Graphics.DrawWithRecipe":291.456,"Graphics.DrawWithRecipe.draw_and_resource_release":186.330,"Graphics.DrawWithRecipe.index_upload":0.120,"Graphics.DrawWithRecipe.validate":1.279,"Graphics.DrawWithRecipe.vertex_upload":0.810,"Graphics.Submit":0.263,"Graphics.Submit.command_end":0.022,"Graphics.Submit.queue_submit":0.230,"Graphics.Wait":7.299,"Graphics.Wait.fence_wait":7.135,"Recorder.Reap":163.698,"Recorder.Submit":984.931,"Recorder.Sync":473.255,"Recorder.WaitSerial":1144.413,"Resources.Complete":236.672,"Resources.Prepare":82.382,"Shader.DrawStage":1562.367,"Shader.DrawStage.capture_resources":1160.028,"Shader.DrawStage.materialize":310.534,"Shader.DrawStage.prepared_invocation":84.848,"Shader.ResolveAbi":80.477,"Shader.ResolveGraphicsAbi":21.738,"Shader.ResolveGraphicsStagesAbi":110.092,"VideoOut.Flip":151.035,"VideoOut.Flip.completion_mutex_wait":0.201,"VideoOut.Flip.config_mutex_wait":0.017,"VideoOut.Flip.frame_limit":0.116,"VideoOut.Flip.notify_game":8.598,"VideoOut.Flip.present":130.640,"VideoOut.Flip.validate":0.230,"VideoOut.Flip.vblank_wait":0.136,"VideoOut.Flip.window_prepare":0.354,"VideoOut.Flip.window_title":10.612,"VideoOut.Readiness":0.474,"VideoOut.Readiness.locks_validate":0.185,"Vulkan.Acquire":2.836,"Vulkan.Acquire.acquire_fence_wait":0.309,"Vulkan.Acquire.acquire_image":1.828,"Vulkan.Acquire.fence_reset":0.299,"Vulkan.Acquire.retired_swapchains":0.084,"Vulkan.Dispatch":5523.207,"Vulkan.Dispatch.command_record":474.416,"Vulkan.Dispatch.shader_resources":5034.179,"Vulkan.DispatchRecipe":657.362,"Vulkan.DispatchRecipe.command_record":622.965,"Vulkan.DrawFromRecipe":292.588,"Vulkan.Present":12.031,"Vulkan.Present.command_record_scale":5.647,"Vulkan.Present.pixel_upload":0.679,"Vulkan.Present.queue_submit":5.551,"Vulkan.QueuePresent":86.429,"Vulkan.QueuePresent.queue_present":86.178,"Vulkan.Retire":7.222,"Vulkan.Retire.wait":4.673},"top_phases_ms_per_frame":{"Driver.Packet":272.807,"Driver.Packet.dispatch":126.413,"Driver.Packet.memory_wait":116.241,"Driver.Dispatch":78.953,"Graphics.Draw":46.496,"Graphics.Draw.draw_and_resource_release":42.598,"Vulkan.Dispatch":38.091,"Vulkan.Dispatch.shader_resources":34.718},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":2881,"Graphics.Barrier.dcc-clear":5220,"Graphics.Barrier.dcc-keys":2320,"Graphics.Barrier.dispatch-lead":49993,"Graphics.Barrier.dispatch-trail":43480,"Graphics.Barrier.draw":25543,"Graphics.Barrier.fill":8858,"Graphics.Barrier.fill-clear":4060,"Graphics.Barrier.indirect-args":10594,"Graphics.Barrier.input-mirror":299,"Graphics.Barrier.label-run":47400,"Graphics.Barrier.present-blit":580,"Graphics.Barrier.shadow-publish":4935,"Graphics.Barrier.staging-in":15995,"Graphics.Barrier.staging-out":6972,"Graphics.Barrier.storage-upload":32970,"Graphics.Barrier.storage-writeback":48136,"Graphics.BarrierMerged.copy":617,"Graphics.BarrierMerged.dispatch-lead":14675,"Graphics.BarrierMerged.fill":2610,"Graphics.BarrierMerged.shadow-publish":4925,"Graphics.BarrierMerged.staging-in":4921,"Graphics.BarrierMerged.staging-out":6972,"Graphics.BarrierMerged.storage-writeback":14516,"Graphics.Copy":18473,"Graphics.Copy.bytes":44912231512,"Graphics.RenderPass":11439,"Graphics.RenderPass.Close.command":7392,"Graphics.RenderPass.Close.image":1106,"Graphics.RenderPass.Close.new-batch":2941,"Graphics.RenderPass.Continued":24354},"trace_dropped":false,"trace":"aps5-trace-e66d0510c55e-48936.json.gz"}

In-run A/B on this PR's build, APS5_AB=10:APS5_NO_SHARED_COLLECT_WALKS from 150 s, phases after 200 s (Body Type): n 14 B-A -8.39 +- 0.39 presents/10 s (-11.6% +- 0.5) A 72.2 B 63.8. B turns shared walks off, so the PR is A. Shared walks off costs -11.6% +- 0.5; in other words this PR is worth about +13% here.

Traces, the two summary lines, tools/trace_digest.py output (digest-mbase1.txt, digest-m17786a.txt) and the A/B phases: https://github.com/klosixgaming-arch/AnyPS5/releases/tag/perf-captures-2026-11-15

Windows, NVIDIA GeForce RTX 5090. Cyberpunk 2077 (PPSA03974), character creator Body Type screen, 20 s windows.

Current main cannot reach this screen on its own:

  • it crashes at boot (#15906; fixed by #16974);
  • it then aborts after the title on a storage write-back (#17791 plus the experimental APS5_CAPTURE_UNPROVEN_PENDING capture that my Cyberpunk tree carries).

So both builds below are main 364ceeba2f with #16974, #17791 and that capture commit. The change build adds only this PR's commit.

  • base: 953940831851
  • change: 2c128ce9c3dc

Same machine and session, same settings on both sides, caches warm, no APS5_PROFILE_*. Results:

build presents / 20 s p50 frame ms p99 frame ms
base, run 1 44 461.1 509.9
base, run 2 42 480.6 506.9
change, run 1 54 376.1 431.2
change, run 2 53 378.4 438.3

The median frame is 20% shorter (471 → 377 ms), and presents go up 24%.

Summary lines

{"commit":"953940831851","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3416,"ms":20388.947},"presents":44,"frame_ms":{"p50":461.09,"p90":489.692,"p99":509.872,"max":509.872},"gpu_busy_ms_per_present":69.18,"worker_busy_pct":{"queue worker 0x0":99.516,"queue worker 0x23":99.897},"top_phases_ms_per_frame":{"Driver.Packet":911.782,"Driver.Packet.dispatch":382.232,"Driver.Packet.memory_wait":369.796,"Driver.Dispatch":316.696,"Vulkan.Dispatch":204.429,"Vulkan.Dispatch.shader_resources":193.184,"Graphics.Draw":167.704,"Graphics.Draw.draw_and_resource_release":160.294},"owned_draw_counts":{"OwnedDraw.arena_check":1144,"OwnedDraw.arm_attempt":572,"OwnedDraw.arm_blocks_requested":660,"OwnedDraw.arm_success":572,"OwnedDraw.check_blocks_requested":1320,"OwnedDraw.invalidated":572,"OwnedDraw.proof_check":1144},"trace_dropped":false,"trace":"aps5-trace-953940831851-64872.json.gz"}
{"commit":"953940831851","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3964,"ms":20219.579},"presents":42,"frame_ms":{"p50":480.628,"p90":498.955,"p99":506.893,"max":506.893},"gpu_busy_ms_per_present":60.949,"worker_busy_pct":{"queue worker 0x0":99.46,"queue worker 0x23":99.848},"top_phases_ms_per_frame":{"Driver.Packet":944.429,"Driver.Packet.dispatch":397.328,"Driver.Packet.memory_wait":392.794,"Driver.Dispatch":325.224,"Vulkan.Dispatch":211.879,"Vulkan.Dispatch.shader_resources":199.033,"Graphics.Draw":174.836,"Graphics.Draw.draw_and_resource_release":166.422},"owned_draw_counts":{"OwnedDraw.arena_check":1722,"OwnedDraw.arm_attempt":798,"OwnedDraw.arm_blocks_requested":1050,"OwnedDraw.arm_success":798,"OwnedDraw.check_blocks_requested":2604,"OwnedDraw.invalidated":798,"OwnedDraw.proof_check":1722,"OwnedDraw.reused":126},"trace_dropped":false,"trace":"aps5-trace-953940831851-65136.json.gz"}
{"commit":"2c128ce9c3dc","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3732,"ms":20341.694},"presents":54,"frame_ms":{"p50":376.106,"p90":390.419,"p99":431.152,"max":431.152},"gpu_busy_ms_per_present":62.813,"worker_busy_pct":{"queue worker 0x0":99.482,"queue worker 0x23":99.897},"top_phases_ms_per_frame":{"Driver.Packet":740.425,"Driver.Packet.dispatch":327.461,"Driver.Packet.memory_wait":295.418,"Driver.Dispatch":267.285,"Vulkan.Dispatch":177.106,"Vulkan.Dispatch.shader_resources":168.251,"Graphics.Draw":129.708,"Graphics.Draw.draw_and_resource_release":122.768},"owned_draw_counts":{"OwnedDraw.arena_check":11772,"OwnedDraw.arm_attempt":5832,"OwnedDraw.arm_blocks_requested":6966,"OwnedDraw.arm_success":5832,"OwnedDraw.check_blocks_requested":14094,"OwnedDraw.invalidated":5832,"OwnedDraw.proof_check":11772,"OwnedDraw.reused":108},"trace_dropped":false,"trace":"aps5-trace-2c128ce9c3dc-52296.json.gz"}
{"commit":"2c128ce9c3dc","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3873,"ms":20207.624},"presents":53,"frame_ms":{"p50":378.423,"p90":397.613,"p99":438.265,"max":438.265},"gpu_busy_ms_per_present":62.407,"worker_busy_pct":{"queue worker 0x0":99.484,"queue worker 0x23":99.922},"top_phases_ms_per_frame":{"Driver.Packet":750.858,"Driver.Packet.dispatch":336.555,"Driver.Packet.memory_wait":300.586,"Driver.Dispatch":275.435,"Vulkan.Dispatch":184.354,"Vulkan.Dispatch.shader_resources":175.114,"Graphics.Draw":123.211,"Graphics.Draw.draw_and_resource_release":116.719},"owned_draw_counts":{"OwnedDraw.arena_check":4240,"OwnedDraw.arm_attempt":2120,"OwnedDraw.arm_blocks_requested":2332,"OwnedDraw.arm_success":2120,"OwnedDraw.check_blocks_requested":4664,"OwnedDraw.invalidated":2120,"OwnedDraw.proof_check":4240},"trace_dropped":false,"trace":"aps5-trace-2c128ce9c3dc-60524.json.gz"}

The four aps5-trace-*.json.gz files are named in the lines above. I will attach them to this PR.

In-run A/B

On my older Cyberpunk tree (f5fe807353 plus #11485, #10443 with APS5_SETTLE_FLOOR_KIB=64, and dispatch relocation), I ran an in-run A/B with:

  • APS5_AB=30:APS5_NO_SHARED_COLLECT_WALKS;
  • APS5_AB_START=170s;
  • APS5_PROFILE_DRAW=1.

There were 6 A and 6 B phases of 30 s, split with tools/ab_split.py:

metric                                  A          B        B-A    B/A-1   B vs neighbouring A: mean +- SE (SD, n)
presents/10s                        47.14      42.14      -5.01   -10.6%   -5.00 +- 0.17 (SD 0.41, n 6)
frame ms                           212.16     237.35     +25.18   +11.9%   +25.13 +- 0.76 (SD 1.87, n 6)
GPU busy ms/frame                   40.74      40.13      -0.61    -1.5%   -0.68 +- 0.30 (SD 0.74, n 6)
committer us/commit                 81.36      97.89     +16.54   +20.3%   +16.53 +- 0.28 (SD 0.68, n 6)

A is this change and B is the old behaviour, in the same process. Frame dumps of the Body Type screen render correctly in every run.

Tests:

  • agc_collect_memo_generation gains a cross-platform CheckSharedWalks. It covers reuse after an earlier point, a walk before the point, a raised point, sharing off, and points never moving earlier. It passes on Windows and fails when sharing is off.

  • agc_collect_memo_generation also gains CheckStoreAfterSubmit. Another queue walks the range after the submission's point, and then the CPU stores to it:

    • (i) a collect at the submission's point may take that walk;
    • (ii) a collect after a wait that the CPU released after its store walks again and sees the store;
    • (iii) so does a collect ordered by a later Submit, and one ordered by a point inherited from a queue that stored its label after the store.

    It passes on Windows (test commit 1c7b4446f5, before the merge of main). With started > since dropped from sharedWalkCovers, CheckSharedWalks fails, and with CheckStoreAfterSubmit run first, (ii) fails.

  • These also pass on Windows: agc_collect_*, agc_write_tracking*, agc_runtime_switches*, agc_driver_same_queue_label_wait*, agc_driver_finisher_label_order*, agc_driver_copied_writer_label_order*, agc_driver_unimported_label_order*, agc_driver_two_device_pending_store_label, agc_driver_wait_shutdown, agc_driver_fill_completion_labels*, agc_driver_alias_copy_label, agc_driver_label_after_import_copy, agc_driver_queue_zero_idle_wait, agc_driver_present_key_writer_wait, agc_predication_tests, agc_wait_on_address_size, agc_pipeline_queue_failure_wait, agc_driver_resource_cache_collect_refusals and the recorder tests.

  • agc_driver_pipelined_predicated_label_order and agc_driver_unregistered_label_behind_write_back did not build on my machine: their object dependency paths exceed the Windows path limit.

Known limit: under APS5_SUBMIT_PROGRESS, submitOpenWork records deferred labels as queue 0 stores. Such a label passes on queue 0's point instead of its own queue's.

Series

These PRs come from the same work on Cyberpunk 2077's character creator, Body Type screen, where the draw committer and queue worker 0 are the limit. They go together:

PR change gain on the series (in-run A/B)
this PR share collect walks between threads after the caller's ordering point +11.9%
#17766 (chitters2004) per-64 KiB block observation table; I measured this reuse model on top of #17786 +2.6%
#18078 reuse an equal untracked compare made after the caller's ordering point (needs #17786) +3.2%
#18075 reuse a storage image's import segments while the mapping and import table are unchanged +3.6%
#18076 prove an untracked storage image unchanged from an equal compare +2.7% on its first head; now a draft, because its fix for compared host imports removes the gain
#18102 reuse a walk after the ordering point when storage results become pending +4.2% (intro movie)

Each gain was measured with the earlier rows already in place, so the rows add up. The last row was measured on the intro movie, the others on Body Type; both scenes are limited by the same draw committer. Most of them are small or zero on main alone, because main is limited elsewhere on this screen; each PR says what it measured there. Not a PR: ANYPS5_PRESENT_MODE=mailbox gave +12 to 14% and immediate +18 to 21% on the same screen, because FIFO holds the flip that the next frame's rendering wait waits for.

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: NVIDIA GeForce RTX 5090, Windows
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5226808875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17786). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-11-09T15:55:30Z. --- ### What Queue worker 0 and the draw committer spend a large share of their time in Windows write-watch walks (`GetWriteWatch` through `collectWindowsWrites`). These walks check whether the game's CPU wrote a surface before a draw or dispatch reads it. On Cyberpunk 2077's character creator a diagnostic counted about 280,000 walks per 10 s over 166 GB of address range, taking 3.1 s. Only 0.7% of them found a CPU write. The same 3-64 MB render targets were walked hundreds of times, because the collect memo is per thread and is reset at every ordering point (about 1,400 per 10 s). This change shares walks between threads by the time they started: - Each completed memoized walk records its start time in a shared map. Before walking, a collect checks that map. When any thread walked the same range strictly after the caller's ordering point (and the unwatch serial and allocation mapping still match), the collect skips its walk. Shared hits are not copied into the per-thread memo ring, so the ring keeps only the thread's own walks. - A submission's ordering point is the time the game called `Submit` (`enqueuedAt`), not the time the worker reaches it. With the usual backlog of a few hundred ms, this lets walks made while earlier submissions ran serve the later ones. A submission with a rewind tail uses the current time. When a submission does not bump the epoch (it was enqueued before the last bump), its point is raised to its submit time. - A `WAIT_REG_MEM` that a label stored by this driver satisfies takes the ordering point of the queue that stored it. A queue's point never moves earlier. The rules for that inheritance: - The satisfying store must be the newest matching entry of the label's history, and every newer entry must be an ordered driver store. - No CPU write may have touched the label since that store. Each label store records the tracker generation, and the check uses `UnchangedSinceCollected`. - Stores whose value comes from memory (COPY_DATA, DMA_DATA, 0x83, `commitStore`) never pass on a point. - Late recorder hits, landing waits and waits held at submit keep the old behaviour (current time). - A predicated packet publishes its read time as the queue's point. - Labels the CPU wrote keep the current time. - The draw committer follows the worker's point through the epoch token (a 4096-slot ring of token and point). - `APS5_NO_SHARED_COLLECT_WALKS` turns the lookups off, and `APS5_AB` can toggle it. With `APS5_PROFILE_DRAW`, an `[epoch]` line reports per queue how many ordering points fell at the bump and how far back the rest lie. ### Why a shared walk is never too old A collect takes a shared walk only when the walk started strictly after the caller's ordering point (`started > since`). The start time is read before the walk takes the tracker lock and calls `GetWriteWatch`, so the walk reports every CPU store that was visible before its start. Both times come from `steady_clock`. So it is enough that every CPU store a packet must see is visible before the packet's point: 1. **Stores before `Submit`.** `Submit` reads `enqueuedAt` while it holds the driver's submit mutex. Taking the mutex makes the submitting thread's earlier stores visible first. A store by another thread is ordered before the submission only if the guest synchronized it with the submitting thread before `Submit`, and x64 makes a store visible to all threads at once. So these stores are visible before `enqueuedAt`, and a walk that started after it reports them. 2. **Stores after `Submit` and before the worker reaches the packet.** On the GPU, such a store is ordered before a packet only through a `WAIT_REG_MEM` that a label stored after the store satisfies. A packet that no such wait orders is not ordered after the store on hardware either: the GPU may read the memory before or after it. Such a packet may take a walk made between `Submit` and the store. For the packets after the wait: - **The CPU stored the label.** The worker sees the value only once the CPU's label store is visible, and x64 makes the CPU's earlier stores visible before it. The wait's ordering point is the current time, which is after the store. A walk made before the store started before that point, so it cannot serve these packets. - **Another queue stored the label** (an ordered driver store, with no CPU write to the label since, as above). The packets inherit that queue's published point. The writer published its point (`publishQueueSince` at each of its ordering points; a predicated packet also publishes its read time) before it ran the label's packet, and it records the store in the label history after that. The waiting worker finds the store in the history under the same mutex before it reads the published point. So it reads a point at least as late as the writer's point at the label store, and by the same two cases on the writer's queue, every CPU store the label store was ordered after was visible before that point. The published point is a running maximum. A later point than needed only costs a walk. - **This queue stored the label.** As on `main`, there is no new ordering point. The queue's own earlier point already covers what the label store was ordered after. 3. **Everything else takes the current time:** a submission with a rewind tail, late recorder hits, landing waits, waits held at submit, labels whose value came from memory, labels the CPU wrote since the driver's store, and a draw-committer token whose ring slot was overwritten. On each thread, a point never moves earlier and never past the current time. `CheckStoreAfterSubmit` in `agc_collect_memo_generation` pins case 2. ### Tested **Body Type on current `main`, 2026-11-15** Cyberpunk 2077 (PPSA03974) 02.120.000, character creator Body Type, 3200x1800; Windows 11 (10.0.26200), RTX 5090 (NVIDIA 617.42), Ryzen 9 9950X3D. Both builds are `main` `b39603dbdc` + #19071 (the game only reaches the creator with it); the change is merged on top. Each line is the 20 s trace window opened about 80 s after entering the creator, one boot each, the same environment on both sides. `main` + #19071 (`262be96458`), 136 presents in the window: ```json {"commit":"262be96458b9","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":5148,"ms":20122.874},"presents":136,"frame_ms":{"p50":146.163,"p90":159.123,"p99":174.569,"max":184.194},"gpu_busy_ms_per_present":34.750,"worker_busy_pct":{"queue worker 0x0":99.015,"queue worker 0x23":99.848},"phase_totals_ms":{"Driver.Completion":9.253,"Driver.Dispatch":11633.138,"Driver.Dispatch.capture_resources":492.551,"Driver.Dispatch.decode_key_device_setup":118.250,"Driver.Dispatch.lookup_cache":84.688,"Driver.Dispatch.materialize":120.716,"Driver.Dispatch.prepared_invocation":87.444,"Driver.Draw":2343.280,"Driver.Draw.device_setup":49.600,"Driver.Draw.draw_enqueued":369.312,"Driver.Draw.post_compile_prepare":18.165,"Driver.Draw.prepare":137.098,"Driver.Draw.shader_compile_and_link":1750.003,"Driver.EndSubmission":410.628,"Driver.Packet":39596.973,"Driver.Packet.device_lock":43.654,"Driver.Packet.dispatch":18688.162,"Driver.Packet.draw":2354.748,"Driver.Packet.execute":165.861,"Driver.Packet.flip_flush":0.382,"Driver.Packet.flush_between_packets":308.698,"Driver.Packet.memory_wait":16555.698,"Driver.Packet.pipeline_drain":995.397,"Driver.Packet.pipeline_prepare":69.406,"Driver.Packet.prepare_memory":92.799,"Driver.Packet.rendering_wait":0.201,"Driver.Present":118.028,"Driver.Present.acquire_image":2.683,"Driver.Present.device_setup":0.119,"Driver.Present.gpu_mutex_wait":0.954,"Driver.Present.inflight_wait":0.557,"Driver.Present.present_display_buffer":24.429,"Driver.Present.queue_present":83.541,"Driver.Present.release_and_callback":0.169,"Driver.Present.render_fence_wait":5.058,"Driver.Present.resize":0.356,"Driver.Present.validate":0.054,"Driver.Suspend":0.033,"GpuMutex.wait.copy":9.628,"GpuMutex.wait.dispatch":1395.623,"GpuMutex.wait.draw":253.664,"GpuMutex.wait.end":260.739,"GpuMutex.wait.fill":104.233,"GpuMutex.wait.flush":21.594,"GpuMutex.wait.hook":3011.188,"GpuMutex.wait.indirect":44.177,"GpuMutex.wait.label":315.496,"GpuMutex.wait.other":91.788,"GpuMutex.wait.present":0.573,"GpuMutex.wait.wait":5.090,"Graphics.Draw":7475.813,"Graphics.Draw.draw_and_resource_release":6958.001,"Graphics.Draw.index_upload":124.894,"Graphics.Draw.validate":119.879,"Graphics.Draw.vertex_upload":259.086,"Graphics.DrawWithRecipe":229.820,"Graphics.DrawWithRecipe.draw_and_resource_release":150.832,"Graphics.DrawWithRecipe.index_upload":0.083,"Graphics.DrawWithRecipe.validate":1.012,"Graphics.DrawWithRecipe.vertex_upload":0.605,"Recorder.Reap":146.317,"Recorder.Submit":931.159,"Recorder.Sync":487.369,"Recorder.WaitSerial":1007.418,"Resources.Complete":193.153,"Resources.Prepare":106.945,"Shader.DrawStage":1550.089,"Shader.DrawStage.capture_resources":1169.403,"Shader.DrawStage.materialize":293.753,"Shader.DrawStage.prepared_invocation":80.115,"Shader.ResolveAbi":96.093,"Shader.ResolveGraphicsAbi":18.714,"Shader.ResolveGraphicsStagesAbi":96.054,"VideoOut.Flip":143.933,"VideoOut.Flip.completion_mutex_wait":0.230,"VideoOut.Flip.config_mutex_wait":0.017,"VideoOut.Flip.frame_limit":0.104,"VideoOut.Flip.notify_game":14.205,"VideoOut.Flip.present":119.756,"VideoOut.Flip.validate":0.208,"VideoOut.Flip.vblank_wait":0.128,"VideoOut.Flip.window_prepare":0.299,"VideoOut.Flip.window_title":8.848,"VideoOut.Readiness":0.480,"VideoOut.Readiness.locks_validate":0.203,"Vulkan.Acquire":2.469,"Vulkan.Acquire.acquire_fence_wait":0.301,"Vulkan.Acquire.acquire_image":1.636,"Vulkan.Acquire.fence_reset":0.392,"Vulkan.Acquire.retired_swapchains":0.079,"Vulkan.Dispatch":5299.200,"Vulkan.Dispatch.command_record":493.646,"Vulkan.Dispatch.shader_resources":4792.257,"Vulkan.DispatchRecipe":512.100,"Vulkan.DispatchRecipe.command_record":493.763,"Vulkan.DrawFromRecipe":230.726,"Vulkan.Present":11.240,"Vulkan.Present.command_record_scale":5.475,"Vulkan.Present.pixel_upload":0.545,"Vulkan.Present.queue_submit":5.094,"Vulkan.QueuePresent":83.150,"Vulkan.QueuePresent.queue_present":82.940,"Vulkan.Retire":5.038,"Vulkan.Retire.wait":2.912},"top_phases_ms_per_frame":{"Driver.Packet":291.154,"Driver.Packet.dispatch":137.413,"Driver.Packet.memory_wait":121.733,"Driver.Dispatch":85.538,"Graphics.Draw":54.969,"Graphics.Draw.draw_and_resource_release":51.162,"Vulkan.Dispatch":38.965,"Vulkan.Dispatch.shader_resources":35.237},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":2785,"Graphics.Barrier.dcc-clear":4896,"Graphics.Barrier.dcc-keys":2176,"Graphics.Barrier.dispatch-lead":47353,"Graphics.Barrier.dispatch-trail":40772,"Graphics.Barrier.draw":24921,"Graphics.Barrier.fill":7943,"Graphics.Barrier.fill-clear":3808,"Graphics.Barrier.indirect-args":9970,"Graphics.Barrier.input-mirror":253,"Graphics.Barrier.label-run":46157,"Graphics.Barrier.present-blit":544,"Graphics.Barrier.shadow-publish":6258,"Graphics.Barrier.staging-in":15386,"Graphics.Barrier.staging-out":6664,"Graphics.Barrier.storage-upload":30938,"Graphics.Barrier.storage-writeback":45180,"Graphics.BarrierMerged.copy":563,"Graphics.BarrierMerged.dispatch-lead":13359,"Graphics.BarrierMerged.fill":2389,"Graphics.BarrierMerged.shadow-publish":6254,"Graphics.BarrierMerged.staging-in":4606,"Graphics.BarrierMerged.staging-out":6664,"Graphics.BarrierMerged.storage-writeback":13529,"Graphics.Copy":17803,"Graphics.Copy.bytes":43738646544,"Graphics.RenderPass":11159,"Graphics.RenderPass.Close.command":7250,"Graphics.RenderPass.Close.image":935,"Graphics.RenderPass.Close.new-batch":2974,"Graphics.RenderPass.Continued":22499},"trace_dropped":false,"trace":"aps5-trace-262be96458b9-48624.json.gz"} ``` This PR on the same base (`e66d0510c5`), 145 presents in the window: ```json {"commit":"e66d0510c55e","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":5269,"ms":20087.295},"presents":145,"frame_ms":{"p50":135.035,"p90":157.094,"p99":187.988,"max":205.423},"gpu_busy_ms_per_present":33.766,"worker_busy_pct":{"queue worker 0x0":98.903,"queue worker 0x23":99.845},"phase_totals_ms":{"Driver.Completion":9.820,"Driver.Dispatch":11448.224,"Driver.Dispatch.capture_resources":505.894,"Driver.Dispatch.decode_key_device_setup":126.495,"Driver.Dispatch.lookup_cache":90.856,"Driver.Dispatch.materialize":124.359,"Driver.Dispatch.prepared_invocation":90.797,"Driver.Draw":2432.020,"Driver.Draw.device_setup":51.471,"Driver.Draw.draw_enqueued":385.448,"Driver.Draw.post_compile_prepare":18.963,"Driver.Draw.prepare":145.994,"Driver.Draw.shader_compile_and_link":1810.589,"Driver.EndSubmission":356.255,"Driver.Packet":39557.025,"Driver.Packet.device_lock":48.741,"Driver.Packet.dispatch":18329.904,"Driver.Packet.draw":2444.195,"Driver.Packet.execute":169.810,"Driver.Packet.flip_flush":0.372,"Driver.Packet.flush_between_packets":304.915,"Driver.Packet.memory_wait":16854.945,"Driver.Packet.pipeline_drain":909.072,"Driver.Packet.pipeline_prepare":73.834,"Driver.Packet.prepare_memory":99.961,"Driver.Packet.rendering_wait":0.220,"Driver.Present":128.671,"Driver.Present.acquire_image":3.048,"Driver.Present.device_setup":0.130,"Driver.Present.gpu_mutex_wait":0.866,"Driver.Present.inflight_wait":0.452,"Driver.Present.present_display_buffer":29.712,"Driver.Present.queue_present":86.786,"Driver.Present.release_and_callback":0.177,"Driver.Present.render_fence_wait":7.012,"Driver.Present.resize":0.345,"Driver.Present.validate":0.042,"Driver.Suspend":0.036,"GpuMutex.wait.copy":10.918,"GpuMutex.wait.dispatch":1322.768,"GpuMutex.wait.draw":276.350,"GpuMutex.wait.end":195.752,"GpuMutex.wait.fill":145.511,"GpuMutex.wait.flush":23.594,"GpuMutex.wait.hook":2873.594,"GpuMutex.wait.indirect":61.113,"GpuMutex.wait.label":330.817,"GpuMutex.wait.other":84.954,"GpuMutex.wait.present":0.484,"GpuMutex.wait.wait":5.718,"Graphics.Draw":6741.942,"Graphics.Draw.draw_and_resource_release":6176.689,"Graphics.Draw.index_upload":133.006,"Graphics.Draw.validate":136.353,"Graphics.Draw.vertex_upload":280.042,"Graphics.DrawWithRecipe":291.456,"Graphics.DrawWithRecipe.draw_and_resource_release":186.330,"Graphics.DrawWithRecipe.index_upload":0.120,"Graphics.DrawWithRecipe.validate":1.279,"Graphics.DrawWithRecipe.vertex_upload":0.810,"Graphics.Submit":0.263,"Graphics.Submit.command_end":0.022,"Graphics.Submit.queue_submit":0.230,"Graphics.Wait":7.299,"Graphics.Wait.fence_wait":7.135,"Recorder.Reap":163.698,"Recorder.Submit":984.931,"Recorder.Sync":473.255,"Recorder.WaitSerial":1144.413,"Resources.Complete":236.672,"Resources.Prepare":82.382,"Shader.DrawStage":1562.367,"Shader.DrawStage.capture_resources":1160.028,"Shader.DrawStage.materialize":310.534,"Shader.DrawStage.prepared_invocation":84.848,"Shader.ResolveAbi":80.477,"Shader.ResolveGraphicsAbi":21.738,"Shader.ResolveGraphicsStagesAbi":110.092,"VideoOut.Flip":151.035,"VideoOut.Flip.completion_mutex_wait":0.201,"VideoOut.Flip.config_mutex_wait":0.017,"VideoOut.Flip.frame_limit":0.116,"VideoOut.Flip.notify_game":8.598,"VideoOut.Flip.present":130.640,"VideoOut.Flip.validate":0.230,"VideoOut.Flip.vblank_wait":0.136,"VideoOut.Flip.window_prepare":0.354,"VideoOut.Flip.window_title":10.612,"VideoOut.Readiness":0.474,"VideoOut.Readiness.locks_validate":0.185,"Vulkan.Acquire":2.836,"Vulkan.Acquire.acquire_fence_wait":0.309,"Vulkan.Acquire.acquire_image":1.828,"Vulkan.Acquire.fence_reset":0.299,"Vulkan.Acquire.retired_swapchains":0.084,"Vulkan.Dispatch":5523.207,"Vulkan.Dispatch.command_record":474.416,"Vulkan.Dispatch.shader_resources":5034.179,"Vulkan.DispatchRecipe":657.362,"Vulkan.DispatchRecipe.command_record":622.965,"Vulkan.DrawFromRecipe":292.588,"Vulkan.Present":12.031,"Vulkan.Present.command_record_scale":5.647,"Vulkan.Present.pixel_upload":0.679,"Vulkan.Present.queue_submit":5.551,"Vulkan.QueuePresent":86.429,"Vulkan.QueuePresent.queue_present":86.178,"Vulkan.Retire":7.222,"Vulkan.Retire.wait":4.673},"top_phases_ms_per_frame":{"Driver.Packet":272.807,"Driver.Packet.dispatch":126.413,"Driver.Packet.memory_wait":116.241,"Driver.Dispatch":78.953,"Graphics.Draw":46.496,"Graphics.Draw.draw_and_resource_release":42.598,"Vulkan.Dispatch":38.091,"Vulkan.Dispatch.shader_resources":34.718},"owned_draw_counts":{},"graphics_track":{"Graphics.Barrier.copy":2881,"Graphics.Barrier.dcc-clear":5220,"Graphics.Barrier.dcc-keys":2320,"Graphics.Barrier.dispatch-lead":49993,"Graphics.Barrier.dispatch-trail":43480,"Graphics.Barrier.draw":25543,"Graphics.Barrier.fill":8858,"Graphics.Barrier.fill-clear":4060,"Graphics.Barrier.indirect-args":10594,"Graphics.Barrier.input-mirror":299,"Graphics.Barrier.label-run":47400,"Graphics.Barrier.present-blit":580,"Graphics.Barrier.shadow-publish":4935,"Graphics.Barrier.staging-in":15995,"Graphics.Barrier.staging-out":6972,"Graphics.Barrier.storage-upload":32970,"Graphics.Barrier.storage-writeback":48136,"Graphics.BarrierMerged.copy":617,"Graphics.BarrierMerged.dispatch-lead":14675,"Graphics.BarrierMerged.fill":2610,"Graphics.BarrierMerged.shadow-publish":4925,"Graphics.BarrierMerged.staging-in":4921,"Graphics.BarrierMerged.staging-out":6972,"Graphics.BarrierMerged.storage-writeback":14516,"Graphics.Copy":18473,"Graphics.Copy.bytes":44912231512,"Graphics.RenderPass":11439,"Graphics.RenderPass.Close.command":7392,"Graphics.RenderPass.Close.image":1106,"Graphics.RenderPass.Close.new-batch":2941,"Graphics.RenderPass.Continued":24354},"trace_dropped":false,"trace":"aps5-trace-e66d0510c55e-48936.json.gz"} ``` In-run A/B on this PR's build, `APS5_AB=10:APS5_NO_SHARED_COLLECT_WALKS` from 150 s, phases after 200 s (Body Type): n 14 B-A -8.39 +- 0.39 presents/10 s (-11.6% +- 0.5) A 72.2 B 63.8. B turns shared walks off, so the PR is A. Shared walks off costs -11.6% +- 0.5; in other words this PR is worth about +13% here. Traces, the two summary lines, `tools/trace_digest.py` output (`digest-mbase1.txt`, `digest-m17786a.txt`) and the A/B phases: https://github.com/klosixgaming-arch/AnyPS5/releases/tag/perf-captures-2026-11-15 Windows, NVIDIA GeForce RTX 5090. Cyberpunk 2077 (PPSA03974), character creator Body Type screen, 20 s windows. Current `main` cannot reach this screen on its own: - it crashes at boot (#15906; fixed by #16974); - it then aborts after the title on a storage write-back (#17791 plus the experimental `APS5_CAPTURE_UNPROVEN_PENDING` capture that my Cyberpunk tree carries). So both builds below are `main` 364ceeba2f with #16974, #17791 and that capture commit. The change build adds only this PR's commit. - base: 953940831851 - change: 2c128ce9c3dc Same machine and session, same settings on both sides, caches warm, no `APS5_PROFILE_*`. Results: | build | presents / 20 s | p50 frame ms | p99 frame ms | |---|---|---|---| | base, run 1 | 44 | 461.1 | 509.9 | | base, run 2 | 42 | 480.6 | 506.9 | | change, run 1 | 54 | 376.1 | 431.2 | | change, run 2 | 53 | 378.4 | 438.3 | The median frame is 20% shorter (471 → 377 ms), and presents go up 24%. #### Summary lines ```json {"commit":"953940831851","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3416,"ms":20388.947},"presents":44,"frame_ms":{"p50":461.09,"p90":489.692,"p99":509.872,"max":509.872},"gpu_busy_ms_per_present":69.18,"worker_busy_pct":{"queue worker 0x0":99.516,"queue worker 0x23":99.897},"top_phases_ms_per_frame":{"Driver.Packet":911.782,"Driver.Packet.dispatch":382.232,"Driver.Packet.memory_wait":369.796,"Driver.Dispatch":316.696,"Vulkan.Dispatch":204.429,"Vulkan.Dispatch.shader_resources":193.184,"Graphics.Draw":167.704,"Graphics.Draw.draw_and_resource_release":160.294},"owned_draw_counts":{"OwnedDraw.arena_check":1144,"OwnedDraw.arm_attempt":572,"OwnedDraw.arm_blocks_requested":660,"OwnedDraw.arm_success":572,"OwnedDraw.check_blocks_requested":1320,"OwnedDraw.invalidated":572,"OwnedDraw.proof_check":1144},"trace_dropped":false,"trace":"aps5-trace-953940831851-64872.json.gz"} {"commit":"953940831851","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3964,"ms":20219.579},"presents":42,"frame_ms":{"p50":480.628,"p90":498.955,"p99":506.893,"max":506.893},"gpu_busy_ms_per_present":60.949,"worker_busy_pct":{"queue worker 0x0":99.46,"queue worker 0x23":99.848},"top_phases_ms_per_frame":{"Driver.Packet":944.429,"Driver.Packet.dispatch":397.328,"Driver.Packet.memory_wait":392.794,"Driver.Dispatch":325.224,"Vulkan.Dispatch":211.879,"Vulkan.Dispatch.shader_resources":199.033,"Graphics.Draw":174.836,"Graphics.Draw.draw_and_resource_release":166.422},"owned_draw_counts":{"OwnedDraw.arena_check":1722,"OwnedDraw.arm_attempt":798,"OwnedDraw.arm_blocks_requested":1050,"OwnedDraw.arm_success":798,"OwnedDraw.check_blocks_requested":2604,"OwnedDraw.invalidated":798,"OwnedDraw.proof_check":1722,"OwnedDraw.reused":126},"trace_dropped":false,"trace":"aps5-trace-953940831851-65136.json.gz"} {"commit":"2c128ce9c3dc","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3732,"ms":20341.694},"presents":54,"frame_ms":{"p50":376.106,"p90":390.419,"p99":431.152,"max":431.152},"gpu_busy_ms_per_present":62.813,"worker_busy_pct":{"queue worker 0x0":99.482,"queue worker 0x23":99.897},"top_phases_ms_per_frame":{"Driver.Packet":740.425,"Driver.Packet.dispatch":327.461,"Driver.Packet.memory_wait":295.418,"Driver.Dispatch":267.285,"Vulkan.Dispatch":177.106,"Vulkan.Dispatch.shader_resources":168.251,"Graphics.Draw":129.708,"Graphics.Draw.draw_and_resource_release":122.768},"owned_draw_counts":{"OwnedDraw.arena_check":11772,"OwnedDraw.arm_attempt":5832,"OwnedDraw.arm_blocks_requested":6966,"OwnedDraw.arm_success":5832,"OwnedDraw.check_blocks_requested":14094,"OwnedDraw.invalidated":5832,"OwnedDraw.proof_check":11772,"OwnedDraw.reused":108},"trace_dropped":false,"trace":"aps5-trace-2c128ce9c3dc-52296.json.gz"} {"commit":"2c128ce9c3dc","dirty":false,"env":{"APS5_CAPTURE_UNPROVEN_PENDING":"1","APS5_DUMP_FRAMES":"1000000","APS5_DUMP_FRAMES_EVERY":"40","APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"0:20","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 5090","driver":"NVIDIA 617.42","os":"Windows 10.0.26200","cpu":"AMD Ryzen 9 9950X3D 16-Core Processor","cpu_threads":32,"memory_mib":194197,"title_id":"PPSA03974","title":"Cyberpunk 2077","content_version":"02.120.000","resolution":"3200x1800","window":{"spec":"seconds 0:20","first_present":3873,"ms":20207.624},"presents":53,"frame_ms":{"p50":378.423,"p90":397.613,"p99":438.265,"max":438.265},"gpu_busy_ms_per_present":62.407,"worker_busy_pct":{"queue worker 0x0":99.484,"queue worker 0x23":99.922},"top_phases_ms_per_frame":{"Driver.Packet":750.858,"Driver.Packet.dispatch":336.555,"Driver.Packet.memory_wait":300.586,"Driver.Dispatch":275.435,"Vulkan.Dispatch":184.354,"Vulkan.Dispatch.shader_resources":175.114,"Graphics.Draw":123.211,"Graphics.Draw.draw_and_resource_release":116.719},"owned_draw_counts":{"OwnedDraw.arena_check":4240,"OwnedDraw.arm_attempt":2120,"OwnedDraw.arm_blocks_requested":2332,"OwnedDraw.arm_success":2120,"OwnedDraw.check_blocks_requested":4664,"OwnedDraw.invalidated":2120,"OwnedDraw.proof_check":4240},"trace_dropped":false,"trace":"aps5-trace-2c128ce9c3dc-60524.json.gz"} ``` The four `aps5-trace-*.json.gz` files are named in the lines above. I will attach them to this PR. #### In-run A/B On my older Cyberpunk tree (f5fe807353 plus #11485, #10443 with `APS5_SETTLE_FLOOR_KIB=64`, and dispatch relocation), I ran an in-run A/B with: - `APS5_AB=30:APS5_NO_SHARED_COLLECT_WALKS`; - `APS5_AB_START=170s`; - `APS5_PROFILE_DRAW=1`. There were 6 A and 6 B phases of 30 s, split with `tools/ab_split.py`: ``` metric A B B-A B/A-1 B vs neighbouring A: mean +- SE (SD, n) presents/10s 47.14 42.14 -5.01 -10.6% -5.00 +- 0.17 (SD 0.41, n 6) frame ms 212.16 237.35 +25.18 +11.9% +25.13 +- 0.76 (SD 1.87, n 6) GPU busy ms/frame 40.74 40.13 -0.61 -1.5% -0.68 +- 0.30 (SD 0.74, n 6) committer us/commit 81.36 97.89 +16.54 +20.3% +16.53 +- 0.28 (SD 0.68, n 6) ``` A is this change and B is the old behaviour, in the same process. Frame dumps of the Body Type screen render correctly in every run. Tests: - `agc_collect_memo_generation` gains a cross-platform `CheckSharedWalks`. It covers reuse after an earlier point, a walk before the point, a raised point, sharing off, and points never moving earlier. It passes on Windows and fails when sharing is off. - `agc_collect_memo_generation` also gains `CheckStoreAfterSubmit`. Another queue walks the range after the submission's point, and then the CPU stores to it: - (i) a collect at the submission's point may take that walk; - (ii) a collect after a wait that the CPU released after its store walks again and sees the store; - (iii) so does a collect ordered by a later `Submit`, and one ordered by a point inherited from a queue that stored its label after the store. It passes on Windows (test commit `1c7b4446f5`, before the merge of `main`). With `started > since` dropped from `sharedWalkCovers`, `CheckSharedWalks` fails, and with `CheckStoreAfterSubmit` run first, (ii) fails. - These also pass on Windows: `agc_collect_*`, `agc_write_tracking*`, `agc_runtime_switches*`, `agc_driver_same_queue_label_wait*`, `agc_driver_finisher_label_order*`, `agc_driver_copied_writer_label_order*`, `agc_driver_unimported_label_order*`, `agc_driver_two_device_pending_store_label`, `agc_driver_wait_shutdown`, `agc_driver_fill_completion_labels*`, `agc_driver_alias_copy_label`, `agc_driver_label_after_import_copy`, `agc_driver_queue_zero_idle_wait`, `agc_driver_present_key_writer_wait`, `agc_predication_tests`, `agc_wait_on_address_size`, `agc_pipeline_queue_failure_wait`, `agc_driver_resource_cache_collect_refusals` and the recorder tests. - `agc_driver_pipelined_predicated_label_order` and `agc_driver_unregistered_label_behind_write_back` did not build on my machine: their object dependency paths exceed the Windows path limit. Known limit: under `APS5_SUBMIT_PROGRESS`, `submitOpenWork` records deferred labels as queue 0 stores. Such a label passes on queue 0's point instead of its own queue's. ### Series These PRs come from the same work on Cyberpunk 2077's character creator, Body Type screen, where the draw committer and queue worker 0 are the limit. They go together: | PR | change | gain on the series (in-run A/B) | |---|---|---| | this PR | share collect walks between threads after the caller's ordering point | +11.9% | | #17766 (chitters2004) | per-64 KiB block observation table; I measured this reuse model on top of #17786 | +2.6% | | #18078 | reuse an equal untracked compare made after the caller's ordering point (needs #17786) | +3.2% | | #18075 | reuse a storage image's import segments while the mapping and import table are unchanged | +3.6% | | #18076 | prove an untracked storage image unchanged from an equal compare | +2.7% on its first head; now a draft, because its fix for compared host imports removes the gain | | #18102 | reuse a walk after the ordering point when storage results become pending | +4.2% (intro movie) | Each gain was measured with the earlier rows already in place, so the rows add up. The last row was measured on the intro movie, the others on Body Type; both scenes are limited by the same draw committer. Most of them are small or zero on `main` alone, because `main` is limited elsewhere on this screen; each PR says what it measured there. Not a PR: `ANYPS5_PRESENT_MODE=mailbox` gave +12 to 14% and `immediate` +18 to 21% on the same screen, because FIFO holds the flip that the next frame's rendering wait waits for. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5090, Windows - [x] AI-assisted: yes
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!17786
No description provided.