perf: heavy 3D titles are bound by per-draw work in the draw path; a direct path that reads descriptors on the GPU #17533

Open
opened 2026-11-08 20:41:00 +00:00 by XatiX · 0 comments
XatiX commented 2026-11-08 20:41:00 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by XatiX on 2026-11-08T20:41:00Z.


Measured 2026-11-03 to 2026-11-08 on an RTX 5080 (driver 617.42), Ryzen 7 9800X3D, Windows 11, Release builds. Estimates are marked as such.

Summary

Heavy 3D titles in AnyPS5 are limited by the CPU work done for each draw, on one queue worker thread. The work per draw grows with the guest data the draw's shaders read (descriptors, image tables), and correctness is kept by proving on the CPU, draw by draw, that this data has not changed. In the heaviest title measured, the GPU timeline is also nearly full, but mostly with overhead the same per-draw model creates (render pass breaks with full barriers, storage image copies), not with shader work. A week of tuning on Age of Mythology: Retold took the title screen from 7965 to about 324 ms per frame, but the remaining cost is spread over many steps that are all part of the design. Removing every CPU cost that has a known fix would leave an estimated 10 to 15 fps of CPU headroom in that title, and its GPU timeline would cap it near 4 fps until the pass and copy overhead goes too. 30 or 60 fps in heavy titles needs a different per-draw model, not further tuning.

What the titles show

Title Draws per frame Result Limit
AoM: Retold, title screen (stack with 25 local commits) about 830 about 3 fps (324 ms per frame) queue worker 100 %; GPU timeline 200 to 280 ms per frame, of which about 40 ms in shaders
FF Resonance, gameplay (main) many; 55k pipeline drains per 10 s 20 to 27 fps queue worker 99 %, Driver.Packet 45 to 60 ms, GPU 18 to 31 ms
LEGO Builder's Journey, first level (main) about 20 fps Driver.Packet about 50 ms, GPU about 26 ms
Divinity: Original Sin 2 about 23 fps CPU-bound
Mewgenics, battle board 650 to 900 8 to 23 fps depending on fixes draw input copies, per-draw work

In FF Resonance and LEGO the GPU has time to spare and the queue worker does not. In AoM both are near their limit, the GPU mostly with overhead (limit 6 below).

Where a draw's time goes

AoM, title screen, worker samples (about 390 µs per draw in all):

Step Share of the worker
The recompiler's image-table resolution (ResolveImageTables): about 27,000 image records per resolution, redone because the 14,000-entry table moves every frame 12 %
Revalidating a cached draw's resources (ShaderResources::Revalidate, table covers, per-texture proofs) 11 %
Shader resource builds 8 to 11 %
Memory capture of the shader's descriptors and table snapshots (ShaderMemory::Capture, TableSnapshotter) 7 %
Building the resource cache key (AppendContentKey) 7 %
tagVariantRuns (variant relocation) 7 %
Descriptor set writes (writeDrawSets): about 36,500 vkUpdateDescriptorSets per 10 s, 267 million descriptors, each set rewritten whole 6 %
Recording (recordDraw) and the rest remainder

No step is above 12 %. Each one exists because of the same model.

The structural limits

  1. Per-draw work scales with guest data, not with what changed. A draw captures the descriptors its shaders read, specializes the shader's resources to them (Materialize), and keys its caches on them. A shader that indexes a 14,000-entry image table makes every draw read, hash, resolve or prove 14,000 entries. The caches avoid rebuilding, but a cache hit still has to prove the inputs current, and the proof touches the same data.

  2. Correctness is proven per draw on the CPU. Reuse is allowed only after write-watch stamps, collect epochs and proof serials show nothing changed. These proofs are invalidated broadly: until this week every GPU mutex hold by the queue worker (one per draw) dropped them (GpuMutexType::acquired), so nearly every check was a full one. Narrowing that (local change, not in main) gained 5 %; the checks remain per draw.

  3. One thread does the work. The draw pipeline can hand recording to a committer and stage materialization to a finisher, but indirect draws mostly skip it (APS5_NO_PIPELINED_INDIRECT, finisher hand-off requires !drawParameters.indirect), and AoM's draws are 98 % DRAW_INDEX_INDIRECT. Even fully pipelined, three threads divide the cost; they do not remove it.

  4. Descriptors are written on the CPU per draw. A draw that reuses a build while its fault record is busy, or whose snapshot buffers moved, gets a complete new descriptor set, including every image-table descriptor. A pool of pre-written sets cut a quarter of these writes and changed nothing measurable; the remaining writes come from per-draw buffer snapshots.

  5. Guest memory is not cheap to read from the GPU on the most common platform. NVIDIA's Windows driver reads host imports far slower than its own buffers (164 against 45 ms of draws per frame, Astro Bot, ARCHITECTURE.md), so draw inputs are copied per draw instead of read in place.

  6. The GPU timeline fills with per-draw overhead. AoM, per frame (APS5_PROFILE_GPU; gpu_busy_ms_per_present is the first-to-last-command span of each batch): 200 to 280 ms of batch time, of which about 40 ms is shader programs. About 300 render passes per frame each begin after a full ALL_COMMANDS barrier; the draw ranges take about 108 ms, about 68 ms more than their shaders. Storage images are written back to guest memory and uploaded again, about 300 MiB of copies per frame (about 21 ms). Half of the pass breaks came from indirect draws that never needed one (fixed locally: 19,600 → 10,300 passes per 10 s), the rest from commands and hazards between draws.

  7. Batching and budgets add stalls. Example fixed this week: a depth plane copy counted its reused 32 MiB staging buffer against the batch's 512 MiB budget at every refresh, which forced 417 early submits and 336 GPU fence waits per 10 s (about 9 % of AoM's frame). Such issues are fixable one by one, but they come from the same per-draw bookkeeping.

Why tuning cannot reach the goal

  • 60 fps is 16.7 ms per frame. With 800 to 2000 draws per frame, that is 8 to 20 µs of CPU per draw. Today a draw costs about 390 µs in AoM.
  • The tuning so far (AoM): 7965 → 2101 → 761 → 455 → 375 → 324 ms per frame. Each later step gave 5 to 10 %.
  • Estimate: removing every image-table cost (what #9508's GPU descriptor heap and #7642's device-side table lookups address: resolution, table proofs, table capture, table key words, descriptor writes; about 35 to 45 % together) leaves about 210 to 250 µs per draw. Spreading that perfectly over three threads gives about 60 to 70 ms per frame, about 15 fps.
  • On the GPU side, AoM's frame cannot go under its 200 to 280 ms of batch time while each draw tends to start its own render pass after a full barrier and storage images travel to guest memory and back every frame.
  • The remainder is the fixed per-draw path itself: decode, capture and proof of the other descriptors, the cache key and lookup, the build or revalidation, the descriptor set, recording. Halving all of it still leaves the target several times away.

What would reach it

The CPU must stop touching guest data per draw. Work has to follow memory changes (per page, per submission), and the GPU has to read descriptors and tables where the hardware does:

  • a device-local mirror of the guest memory the GPU uses, updated per dirty page once per submission and written back per GPU-written page;
  • shaders compiled per code and a small state key that read V#s, T#s, S#s and table records from that mirror at run time, with image and sampler descriptors found through a GPU-side table (T# words → descriptor heap slot) filled by the CPU when a key is first seen;
  • per draw, only register decode, a pipeline lookup, push constants and the draw call;
  • render passes that span every draw into the same targets, with barriers only where a real hazard exists, and GPU results kept on the GPU until the CPU actually reads them.

This is the model emulators that run comparable hardware at full speed use. I am prototyping it as a separate path beside the existing one, with a per-draw fallback to the existing path so every title keeps running, and will measure it on Divinity: Original Sin 2, FF Resonance, LEGO Builder's Journey and AoM. It is not meant as a pull request in its current form; the aim is to find out whether the model holds up in this codebase and to bring numbers back here.

  • #7895: the queue-0 committer bounds draw-heavy titles (Astro Bot, about 3,000 draws per frame, about 10 fps); the agreed direction there is preparation on helper threads with one recorder. That spreads the per-draw cost over more threads; this issue is about the cost itself.
  • #6754 (GTA V) and #11376 (Days Gone, CPU-bound at about 9 fps with the GPU idle): the same symptom in other titles.
  • #9508 and #7642: the GPU descriptor heap and device-side table lookups, which remove the image-table part of the cost (estimated above).

Feedback wanted

  • Is a guest memory mirror on the GPU, updated per dirty page per submission, acceptable as a direction, given the write watch and the host-import costs on NVIDIA Windows?
  • Are there correctness reasons, beyond the ones in ARCHITECTURE.md, why descriptors and tables must be captured and proven on the CPU rather than read by the shader?
  • Other titles' numbers for draws per frame and CPU per draw would show how general this is.

Summary line (AoM: Retold, title screen, the stack with 25 local commits)

{"commit":"761139f62c45","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 5080","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 9800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32404,"title_id":"PPSA18653","title":"Age of Mythology: Retold","content_version":"01.043.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":574,"ms":10063.605},"interval_start_s":52.200,"interval_end_s":62.264,"presents":31,"frame_ms":{"p50":324.452,"p90":331.883,"p99":336.471,"max":336.471},"gpu_busy_ms_per_present":279.647,"worker_busy_pct":{"queue worker 0x0":99.683},"top_phases_ms_per_frame":{"Driver.Packet":323.342,"Driver.Packet.draw":287.423,"Driver.Draw":287.255,"Driver.Draw.draw_and_resource_release":169.604,"Graphics.Draw":152.099,"Graphics.Draw.draw_and_resource_release":117.278,"Driver.Draw.shader_compile_and_link":89.469,"Shader.DrawStage":70.381},"trace_dropped":false,"trace":""}

The stack is listed in the bring-up discussion #15328. Worker samples and GPU profiles can be attached on request.

AI-assisted analysis and report: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6275397268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/17533). Originally posted by [XatiX](https://github.com/XatiX) on 2026-11-08T20:41:00Z. --- Measured 2026-11-03 to 2026-11-08 on an RTX 5080 (driver 617.42), Ryzen 7 9800X3D, Windows 11, Release builds. Estimates are marked as such. ## Summary Heavy 3D titles in AnyPS5 are limited by the CPU work done for each draw, on one queue worker thread. The work per draw grows with the guest data the draw's shaders read (descriptors, image tables), and correctness is kept by proving on the CPU, draw by draw, that this data has not changed. In the heaviest title measured, the GPU timeline is also nearly full, but mostly with overhead the same per-draw model creates (render pass breaks with full barriers, storage image copies), not with shader work. A week of tuning on Age of Mythology: Retold took the title screen from 7965 to about 324 ms per frame, but the remaining cost is spread over many steps that are all part of the design. Removing every CPU cost that has a known fix would leave an estimated 10 to 15 fps of CPU headroom in that title, and its GPU timeline would cap it near 4 fps until the pass and copy overhead goes too. 30 or 60 fps in heavy titles needs a different per-draw model, not further tuning. ## What the titles show | Title | Draws per frame | Result | Limit | |---|---|---|---| | AoM: Retold, title screen (stack with 25 local commits) | about 830 | about 3 fps (324 ms per frame) | queue worker 100 %; GPU timeline 200 to 280 ms per frame, of which about 40 ms in shaders | | FF Resonance, gameplay (`main`) | many; 55k pipeline drains per 10 s | 20 to 27 fps | queue worker 99 %, Driver.Packet 45 to 60 ms, GPU 18 to 31 ms | | LEGO Builder's Journey, first level (`main`) | | about 20 fps | Driver.Packet about 50 ms, GPU about 26 ms | | Divinity: Original Sin 2 | | about 23 fps | CPU-bound | | Mewgenics, battle board | 650 to 900 | 8 to 23 fps depending on fixes | draw input copies, per-draw work | In FF Resonance and LEGO the GPU has time to spare and the queue worker does not. In AoM both are near their limit, the GPU mostly with overhead (limit 6 below). ## Where a draw's time goes AoM, title screen, worker samples (about 390 µs per draw in all): | Step | Share of the worker | |---|---| | The recompiler's image-table resolution (`ResolveImageTables`): about 27,000 image records per resolution, redone because the 14,000-entry table moves every frame | 12 % | | Revalidating a cached draw's resources (`ShaderResources::Revalidate`, table covers, per-texture proofs) | 11 % | | Shader resource builds | 8 to 11 % | | Memory capture of the shader's descriptors and table snapshots (`ShaderMemory::Capture`, `TableSnapshotter`) | 7 % | | Building the resource cache key (`AppendContentKey`) | 7 % | | `tagVariantRuns` (variant relocation) | 7 % | | Descriptor set writes (`writeDrawSets`): about 36,500 `vkUpdateDescriptorSets` per 10 s, 267 million descriptors, each set rewritten whole | 6 % | | Recording (`recordDraw`) and the rest | remainder | No step is above 12 %. Each one exists because of the same model. ## The structural limits 1. **Per-draw work scales with guest data, not with what changed.** A draw captures the descriptors its shaders read, specializes the shader's resources to them (`Materialize`), and keys its caches on them. A shader that indexes a 14,000-entry image table makes every draw read, hash, resolve or prove 14,000 entries. The caches avoid rebuilding, but a cache hit still has to prove the inputs current, and the proof touches the same data. 2. **Correctness is proven per draw on the CPU.** Reuse is allowed only after write-watch stamps, collect epochs and proof serials show nothing changed. These proofs are invalidated broadly: until this week every GPU mutex hold by the queue worker (one per draw) dropped them (`GpuMutexType::acquired`), so nearly every check was a full one. Narrowing that (local change, not in main) gained 5 %; the checks remain per draw. 3. **One thread does the work.** The draw pipeline can hand recording to a committer and stage materialization to a finisher, but indirect draws mostly skip it (`APS5_NO_PIPELINED_INDIRECT`, finisher hand-off requires `!drawParameters.indirect`), and AoM's draws are 98 % `DRAW_INDEX_INDIRECT`. Even fully pipelined, three threads divide the cost; they do not remove it. 4. **Descriptors are written on the CPU per draw.** A draw that reuses a build while its fault record is busy, or whose snapshot buffers moved, gets a complete new descriptor set, including every image-table descriptor. A pool of pre-written sets cut a quarter of these writes and changed nothing measurable; the remaining writes come from per-draw buffer snapshots. 5. **Guest memory is not cheap to read from the GPU on the most common platform.** NVIDIA's Windows driver reads host imports far slower than its own buffers (164 against 45 ms of draws per frame, Astro Bot, ARCHITECTURE.md), so draw inputs are copied per draw instead of read in place. 6. **The GPU timeline fills with per-draw overhead.** AoM, per frame (`APS5_PROFILE_GPU`; `gpu_busy_ms_per_present` is the first-to-last-command span of each batch): 200 to 280 ms of batch time, of which about 40 ms is shader programs. About 300 render passes per frame each begin after a full `ALL_COMMANDS` barrier; the draw ranges take about 108 ms, about 68 ms more than their shaders. Storage images are written back to guest memory and uploaded again, about 300 MiB of copies per frame (about 21 ms). Half of the pass breaks came from indirect draws that never needed one (fixed locally: 19,600 → 10,300 passes per 10 s), the rest from commands and hazards between draws. 7. **Batching and budgets add stalls.** Example fixed this week: a depth plane copy counted its reused 32 MiB staging buffer against the batch's 512 MiB budget at every refresh, which forced 417 early submits and 336 GPU fence waits per 10 s (about 9 % of AoM's frame). Such issues are fixable one by one, but they come from the same per-draw bookkeeping. ## Why tuning cannot reach the goal - 60 fps is 16.7 ms per frame. With 800 to 2000 draws per frame, that is 8 to 20 µs of CPU per draw. Today a draw costs about 390 µs in AoM. - The tuning so far (AoM): 7965 → 2101 → 761 → 455 → 375 → 324 ms per frame. Each later step gave 5 to 10 %. - Estimate: removing every image-table cost (what #9508's GPU descriptor heap and #7642's device-side table lookups address: resolution, table proofs, table capture, table key words, descriptor writes; about 35 to 45 % together) leaves about 210 to 250 µs per draw. Spreading that perfectly over three threads gives about 60 to 70 ms per frame, about 15 fps. - On the GPU side, AoM's frame cannot go under its 200 to 280 ms of batch time while each draw tends to start its own render pass after a full barrier and storage images travel to guest memory and back every frame. - The remainder is the fixed per-draw path itself: decode, capture and proof of the other descriptors, the cache key and lookup, the build or revalidation, the descriptor set, recording. Halving all of it still leaves the target several times away. ## What would reach it The CPU must stop touching guest data per draw. Work has to follow memory changes (per page, per submission), and the GPU has to read descriptors and tables where the hardware does: - a device-local mirror of the guest memory the GPU uses, updated per dirty page once per submission and written back per GPU-written page; - shaders compiled per code and a small state key that read V#s, T#s, S#s and table records from that mirror at run time, with image and sampler descriptors found through a GPU-side table (T# words → descriptor heap slot) filled by the CPU when a key is first seen; - per draw, only register decode, a pipeline lookup, push constants and the draw call; - render passes that span every draw into the same targets, with barriers only where a real hazard exists, and GPU results kept on the GPU until the CPU actually reads them. This is the model emulators that run comparable hardware at full speed use. I am prototyping it as a separate path beside the existing one, with a per-draw fallback to the existing path so every title keeps running, and will measure it on Divinity: Original Sin 2, FF Resonance, LEGO Builder's Journey and AoM. It is not meant as a pull request in its current form; the aim is to find out whether the model holds up in this codebase and to bring numbers back here. ## Related - #7895: the queue-0 committer bounds draw-heavy titles (Astro Bot, about 3,000 draws per frame, about 10 fps); the agreed direction there is preparation on helper threads with one recorder. That spreads the per-draw cost over more threads; this issue is about the cost itself. - #6754 (GTA V) and #11376 (Days Gone, CPU-bound at about 9 fps with the GPU idle): the same symptom in other titles. - #9508 and #7642: the GPU descriptor heap and device-side table lookups, which remove the image-table part of the cost (estimated above). ## Feedback wanted - Is a guest memory mirror on the GPU, updated per dirty page per submission, acceptable as a direction, given the write watch and the host-import costs on NVIDIA Windows? - Are there correctness reasons, beyond the ones in ARCHITECTURE.md, why descriptors and tables must be captured and proven on the CPU rather than read by the shader? - Other titles' numbers for draws per frame and CPU per draw would show how general this is. ## Summary line (AoM: Retold, title screen, the stack with 25 local commits) ``` {"commit":"761139f62c45","dirty":false,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"NVIDIA GeForce RTX 5080","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","cpu":"AMD Ryzen 7 9800X3D 8-Core Processor","cpu_threads":16,"memory_mib":32404,"title_id":"PPSA18653","title":"Age of Mythology: Retold","content_version":"01.043.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":574,"ms":10063.605},"interval_start_s":52.200,"interval_end_s":62.264,"presents":31,"frame_ms":{"p50":324.452,"p90":331.883,"p99":336.471,"max":336.471},"gpu_busy_ms_per_present":279.647,"worker_busy_pct":{"queue worker 0x0":99.683},"top_phases_ms_per_frame":{"Driver.Packet":323.342,"Driver.Packet.draw":287.423,"Driver.Draw":287.255,"Driver.Draw.draw_and_resource_release":169.604,"Graphics.Draw":152.099,"Graphics.Draw.draw_and_resource_release":117.278,"Driver.Draw.shader_compile_and_link":89.469,"Shader.DrawStage":70.381},"trace_dropped":false,"trace":""} ``` The stack is listed in the bring-up discussion #15328. Worker samples and GPU profiles can be attached on request. AI-assisted analysis and report: yes (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#17533
No description provided.