perf: GTA V Story, queue 0 spends a third of its time waiting for GPU writes it reads while preparing dispatches #5694

Closed
opened 2026-10-14 07:09:58 +00:00 by tibzejoker · 0 comments
tibzejoker commented 2026-10-14 07:09:58 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T07:09:58Z.


Title and scene

PPSA04264 (GTA V), the Story prologue inside the bank, about 100 s after the first 3D frame. Window 3840x2160.

What is slow or what changed

Queue worker 0 is the critical path: it is busy 94 % of each frame, and the other queues mostly wait on it (Driver.Packet.memory_wait). About a third of worker 0's time is spent waiting for the GPU while it prepares dispatches. That happens when the CPU reads guest memory that recorded GPU work is still writing. The GPU writes are real: the bytes read after the wait have almost always changed.

Stack samples of worker 0 (APS5_SAMPLE_WORKER, 8,967 samples over the 150 s of Story; menu and loading subtracted; symbolized with nm):

share of worker 0 path
31 % Recorder::SyncThrough, all callers: ShaderMemory::page → GuestMemory::Read → FlushForAccess (17.7 %), and StorageTexture::compareUntracked (10.7 %)
15.6 % inside that, waiting for GpuMutex in syncThroughUnlocked, plus about 15 % of fence waits in the NVIDIA driver
7.7 % recordQueuedLabelsFromHook waiting for GpuMutex, reached from ShaderMemory::page reads
18 % memcmp/memcpy: EqualsCommitted in ShaderResources::resolveImageTables (7.1 %, from #757's table check), compareUntracked (6.4 %), captureGuestBytes (2.9 %)

The [hooksync] lines (APS5_PROFILE_DRAW=1) come from a separate run of the same scene on the same stack, at 180 s:

[hooksync] 216 pending-write syncs waited 2633 ms (10 s); read bytes after the wait: unchanged 2 (target open 0, in flight unsignaled 1, signaled 1), changed 64; stores 0, unchecked 150; targets: 213 open, 1 already signaled, 275 batches finished; noted range: <=4K 31 <=64K 40 <=1M 5 <=16M 133 <=256M 7; access: <=4K 31 <=64K 35 <=1M 5 <=16M 115 <=256M 30; top by wait (queue packet site frames: count/ms, unchanged open/unsignaled/signaled, changed, stores, avg range/access): [0x0 DISPATCH_DIRECT capture +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 9/1326ms u0/0/0 c9 s0 0K/4K] [0x0 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 66/814ms u0/0/0 c0 s0 7272K/10352K] [0x28 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 20/100ms u0/0/0 c0 s0 4096K/13517K] [0x38 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 22/80ms u0/0/0 c0 s0 4096K/14150K] [0x0 DISPATCH_DIRECT texture-compare +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 35/65ms u0/0/0 c35 s0 64K/64K] [0x0 DRAW_INDEX_2 unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 24/56ms u0/0/0 c0 s0 4096K/4096K] [0x30 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 8/47ms u0/0/0 c0 s0 4096K/12800K] [0x0 DRAW_INDEX_AUTO unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 10/46ms u0/0/0 c0 s0 2176K/13056K] [0x28 DISPATCH_INDIRECT indirect-args +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 4/29ms u0/1/0 c3 s0 0K/0K] [0x28 DISPATCH_DIRECT dispatch-cache +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 1/21ms u0/0/0 c1 s0 0K/0K]
[hooksync] recorded-store syncs (10 s): 12 waited 17 ms, 6 batches in flight at them; skipped (cpu-written blocks) 0 / flushed 12 / evicted stale 0; flushed later after a skip 0 (by the same site 0); C4 every block CPU-written: yes 0 / no 12 / unclassified 0 (publish only 0); bytes after the wait: changed 0, unchanged 0, unchecked 12; images overlapped: dead 0 / live 12 (no consumer proof for 2 presents); by queue packet site (count/ms, skipped, cpu-written yes/no, changed/unchanged, dead/live): [0x38 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 5/7ms k0 y0/n5 c0/u0 d0/l5] [0x28 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 3/4ms k0 y0/n3 c0/u0 d0/l3] [0x30 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 2/3ms k0 y0/n2 c0/u0 d0/l2] [0x20 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 2/3ms k0 y0/n2 c0/u0 d0/l2]

So it's about 210 pending-write syncs per 10 s, waiting 2 to 2.6 s in all. In 64-74 of the 66-76 checked cases, the bytes read after the wait had changed. Two kinds stand out:

  • Large ranges (about 10 MB on average) read while preparing DISPATCH_DIRECT on queue 0.
  • Shader-memory captures (the capture site): 5-10 syncs per 10 s on single 4 KiB pages cost 0.5-1.3 s. GTA's JobManager kernels write V# blocks on the GPU that later dispatches take their descriptors from (see #3055), so capturing those descriptors on the CPU has to wait for the producing batch.

I'm not proposing a fix here. The capture-side waits look structural to me, since GTA builds descriptors on the GPU and AnyPS5 resolves them on the CPU before recording the dispatch. #1193 makes captures of pages with no pending GPU writes cheaper, but leaves these pages as they are.

Stack: main d8888df9b plus #757 (4dcf657a2), fdfawef324's #448 port, #1186 and #1189, plus a local change that skips dispatches whose shader fails to compile; none did in this run.

Summary lines

{"commit":"616f09bb41d8","dirty":false,"env":{"APS5_SAMPLE_WORKER":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"260:10"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"seconds 260:10","first_present":2932,"ms":10885.473},"presents":12,"frame_ms":{"p50":894.420,"p90":961.612,"p99":961.730,"max":961.730},"gpu_busy_ms_per_present":265.163,"worker_busy_pct":{"queue worker 0x0":99.827,"queue worker 0x30":25.723,"queue worker 0x20":84.311,"queue worker 0x28":47.744,"queue worker 0x38":54.195},"top_phases_ms_per_frame":{"Driver.Packet":2822.799,"Driver.Packet.memory_wait":1472.359,"Driver.Packet.dispatch":1045.286,"Driver.Dispatch":1029.074,"Vulkan.Dispatch":580.002,"Vulkan.Dispatch.shader_resources":567.225,"Resources.Complete":565.219,"Driver.Packet.draw":297.651},"trace_dropped":false,"trace":"aps5-trace-616f09bb41d8-49688.json.gz"}

Traces

Digest

Threads (ms per frame)

thread busy wait untraced in slices < 20 us largest
queue worker 0x0 853.0 (94 %) 46.1 (5 %) 8.1 83.3 Driver.Packet 894.1, Driver.Rewind 2.1
presenter 2.8 (0 %) 0.0 (0 %) 904.3 0.0 Driver.Present 2.8
queue worker 0x30 67.0 (7 %) 200.7 (22 %) 639.4 0.0 Driver.Packet 233.3, Driver.EndSubmission 0.0
queue worker 0x20 93.2 (10 %) 744.3 (82 %) 69.6 5.1 Driver.Packet 764.0, Driver.EndSubmission 0.0
queue worker 0x28 149.9 (17 %) 676.2 (75 %) 81.0 1.4 Driver.Packet 432.8, Driver.EndSubmission 0.0
queue worker 0x38 168.1 (19 %) 703.9 (78 %) 35.1 0.0 Driver.Packet 491.6, Driver.EndSubmission 0.0
gpu 246.7 (27 %) 0.0 (0 %) 660.5 0.0 batch 246.7

Largest slices (ms per frame, inclusive, all threads): Driver.Packet 2815.9, Driver.Packet.memory_wait 1472.2, Driver.Packet.dispatch 1044.2, Driver.Dispatch 1027.8, Driver.WorkerWait 881.6, Driver.WorkerWait.idle_and_completion_poll 881.6, Vulkan.Dispatch 579.3, Vulkan.Dispatch.shader_resources 566.7, Resources.Complete 564.8, Driver.Packet.draw 296.0

Capture

  • The caches were warm: Story had already run on this build, and the title was restarted.
  • APS5_SAMPLE_WORKER was set together with the trace, and stdout went to a log file. The [hooksync] numbers come from a separate run with APS5_PROFILE_DRAW=1.
  • All captures are from the same machine, scene and settings: RTX 4090, NVIDIA 616.92, Windows 11.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5843538770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5694). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-14T07:09:58Z. --- ### Title and scene PPSA04264 (GTA V), the Story prologue inside the bank, about 100 s after the first 3D frame. Window 3840x2160. ### What is slow or what changed Queue worker 0 is the critical path: it is busy 94 % of each frame, and the other queues mostly wait on it (`Driver.Packet.memory_wait`). About a third of worker 0's time is spent waiting for the GPU while it prepares dispatches. That happens when the CPU reads guest memory that recorded GPU work is still writing. The GPU writes are real: the bytes read after the wait have almost always changed. Stack samples of worker 0 (`APS5_SAMPLE_WORKER`, 8,967 samples over the 150 s of Story; menu and loading subtracted; symbolized with `nm`): | share of worker 0 | path | |---|---| | 31 % | `Recorder::SyncThrough`, all callers: `ShaderMemory::page` → `GuestMemory::Read` → `FlushForAccess` (17.7 %), and `StorageTexture::compareUntracked` (10.7 %) | | 15.6 % | inside that, waiting for `GpuMutex` in `syncThroughUnlocked`, plus about 15 % of fence waits in the NVIDIA driver | | 7.7 % | `recordQueuedLabelsFromHook` waiting for `GpuMutex`, reached from `ShaderMemory::page` reads | | 18 % | `memcmp`/`memcpy`: `EqualsCommitted` in `ShaderResources::resolveImageTables` (7.1 %, from #757's table check), `compareUntracked` (6.4 %), `captureGuestBytes` (2.9 %) | The `[hooksync]` lines (`APS5_PROFILE_DRAW=1`) come from a separate run of the same scene on the same stack, at 180 s: ``` [hooksync] 216 pending-write syncs waited 2633 ms (10 s); read bytes after the wait: unchanged 2 (target open 0, in flight unsignaled 1, signaled 1), changed 64; stores 0, unchecked 150; targets: 213 open, 1 already signaled, 275 batches finished; noted range: <=4K 31 <=64K 40 <=1M 5 <=16M 133 <=256M 7; access: <=4K 31 <=64K 35 <=1M 5 <=16M 115 <=256M 30; top by wait (queue packet site frames: count/ms, unchanged open/unsignaled/signaled, changed, stores, avg range/access): [0x0 DISPATCH_DIRECT capture +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 9/1326ms u0/0/0 c9 s0 0K/4K] [0x0 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 66/814ms u0/0/0 c0 s0 7272K/10352K] [0x28 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 20/100ms u0/0/0 c0 s0 4096K/13517K] [0x38 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 22/80ms u0/0/0 c0 s0 4096K/14150K] [0x0 DISPATCH_DIRECT texture-compare +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 35/65ms u0/0/0 c35 s0 64K/64K] [0x0 DRAW_INDEX_2 unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 24/56ms u0/0/0 c0 s0 4096K/4096K] [0x30 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 8/47ms u0/0/0 c0 s0 4096K/12800K] [0x0 DRAW_INDEX_AUTO unknown +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 10/46ms u0/0/0 c0 s0 2176K/13056K] [0x28 DISPATCH_INDIRECT indirect-args +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 4/29ms u0/1/0 c3 s0 0K/0K] [0x28 DISPATCH_DIRECT dispatch-cache +0x0/+0x0/+0x0/+0x0/+0x0/+0x0: 1/21ms u0/0/0 c1 s0 0K/0K] [hooksync] recorded-store syncs (10 s): 12 waited 17 ms, 6 batches in flight at them; skipped (cpu-written blocks) 0 / flushed 12 / evicted stale 0; flushed later after a skip 0 (by the same site 0); C4 every block CPU-written: yes 0 / no 12 / unclassified 0 (publish only 0); bytes after the wait: changed 0, unchanged 0, unchecked 12; images overlapped: dead 0 / live 12 (no consumer proof for 2 presents); by queue packet site (count/ms, skipped, cpu-written yes/no, changed/unchanged, dead/live): [0x38 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 5/7ms k0 y0/n5 c0/u0 d0/l5] [0x28 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 3/4ms k0 y0/n3 c0/u0 d0/l3] [0x30 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 2/3ms k0 y0/n2 c0/u0 d0/l2] [0x20 DISPATCH_DIRECT unknown +0x0/+0x0/+0x0: 2/3ms k0 y0/n2 c0/u0 d0/l2] ``` So it's about 210 pending-write syncs per 10 s, waiting 2 to 2.6 s in all. In 64-74 of the 66-76 checked cases, the bytes read after the wait had changed. Two kinds stand out: - Large ranges (about 10 MB on average) read while preparing `DISPATCH_DIRECT` on queue 0. - Shader-memory captures (the `capture` site): 5-10 syncs per 10 s on single 4 KiB pages cost 0.5-1.3 s. GTA's JobManager kernels write V# blocks on the GPU that later dispatches take their descriptors from (see #3055), so capturing those descriptors on the CPU has to wait for the producing batch. I'm not proposing a fix here. The capture-side waits look structural to me, since GTA builds descriptors on the GPU and AnyPS5 resolves them on the CPU before recording the dispatch. #1193 makes captures of pages with no pending GPU writes cheaper, but leaves these pages as they are. Stack: `main` d8888df9b plus #757 (4dcf657a2), fdfawef324's #448 port, #1186 and #1189, plus a local change that skips dispatches whose shader fails to compile; none did in this run. ### Summary lines ```json {"commit":"616f09bb41d8","dirty":false,"env":{"APS5_SAMPLE_WORKER":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"260:10"},"gpu":"NVIDIA GeForce RTX 4090","driver":"NVIDIA 616.92","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"seconds 260:10","first_present":2932,"ms":10885.473},"presents":12,"frame_ms":{"p50":894.420,"p90":961.612,"p99":961.730,"max":961.730},"gpu_busy_ms_per_present":265.163,"worker_busy_pct":{"queue worker 0x0":99.827,"queue worker 0x30":25.723,"queue worker 0x20":84.311,"queue worker 0x28":47.744,"queue worker 0x38":54.195},"top_phases_ms_per_frame":{"Driver.Packet":2822.799,"Driver.Packet.memory_wait":1472.359,"Driver.Packet.dispatch":1045.286,"Driver.Dispatch":1029.074,"Vulkan.Dispatch":580.002,"Vulkan.Dispatch.shader_resources":567.225,"Resources.Complete":565.219,"Driver.Packet.draw":297.651},"trace_dropped":false,"trace":"aps5-trace-616f09bb41d8-49688.json.gz"} ``` ### Traces - Trace: https://github.com/tibzejoker/AnyPS5/releases/download/perf-gta-story-sync-20261014/aps5-trace-616f09bb41d8-49688.json.gz - Worker 0 stacks, symbolized, collapsed format for speedscope.app: https://github.com/tibzejoker/AnyPS5/releases/download/perf-gta-story-sync-20261014/gta-story-worker0.collapsed.txt ### Digest **Threads** (ms per frame) | thread | busy | wait | untraced | in slices < 20 us | largest | |---|---|---|---|---|---| | queue worker 0x0 | 853.0 (94 %) | 46.1 (5 %) | 8.1 | 83.3 | Driver.Packet 894.1, Driver.Rewind 2.1 | | presenter | 2.8 (0 %) | 0.0 (0 %) | 904.3 | 0.0 | Driver.Present 2.8 | | queue worker 0x30 | 67.0 (7 %) | 200.7 (22 %) | 639.4 | 0.0 | Driver.Packet 233.3, Driver.EndSubmission 0.0 | | queue worker 0x20 | 93.2 (10 %) | 744.3 (82 %) | 69.6 | 5.1 | Driver.Packet 764.0, Driver.EndSubmission 0.0 | | queue worker 0x28 | 149.9 (17 %) | 676.2 (75 %) | 81.0 | 1.4 | Driver.Packet 432.8, Driver.EndSubmission 0.0 | | queue worker 0x38 | 168.1 (19 %) | 703.9 (78 %) | 35.1 | 0.0 | Driver.Packet 491.6, Driver.EndSubmission 0.0 | | gpu | 246.7 (27 %) | 0.0 (0 %) | 660.5 | 0.0 | batch 246.7 | **Largest slices** (ms per frame, inclusive, all threads): Driver.Packet 2815.9, Driver.Packet.memory_wait 1472.2, Driver.Packet.dispatch 1044.2, Driver.Dispatch 1027.8, Driver.WorkerWait 881.6, Driver.WorkerWait.idle_and_completion_poll 881.6, Vulkan.Dispatch 579.3, Vulkan.Dispatch.shader_resources 566.7, Resources.Complete 564.8, Driver.Packet.draw 296.0 ### Capture - The caches were warm: Story had already run on this build, and the title was restarted. - `APS5_SAMPLE_WORKER` was set together with the trace, and stdout went to a log file. The `[hooksync]` numbers come from a separate run with `APS5_PROFILE_DRAW=1`. - All captures are from the same machine, scene and settings: RTX 4090, NVIDIA 616.92, Windows 11. AI-assisted (Claude Code).
Sign in to join this conversation.
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#5694
No description provided.