Windows over PCIe are not the GPU cost on an RTX 5070 Ti; the CPU side of host copies is (measurements and a proposal) #1187

Open
opened 2026-11-26 03:59:07 +00:00 by github-bot · 4 comments
Owner

@⁠Marukooh on GitHub · 2026-11-25 23:11 UTC · original

Host copies of title memory: the windows outside buffers are not why the card is slow on an RTX 5070 Ti, and what the CPU side costs

The test

VICTORY_CARD_WINDOWS_MB defaults to 0, so windows of title memory outside buffers (vertices, indices and constants from the title's allocator) stay in the PC's memory and shaders read them over PCIe. I ran the same build with VICTORY_TEXTURE_DROP_MIPS=1 (to leave room) at 0 and at 3072, 70 s each, in the prologue (2,500-6,000 draws a frame, pipelines ready; RTX 5070 Ti, Proton, vkd3d-proton):

windows frame GPU preparing card copies
PC memory 237.9 ms 111.5 ms 103.5 ms 97, 941 MB
card 234.1 ms 126.6 ms 80.4 ms 356, 2,017 MB

The windows did go to the card (+259 copies, +1,076 MB), but GPU time did not drop. On this card the PCIe reads of windows are not what the ~110 ms of GPU time is made of. Preparing went down by about 23 ms, but on five windows with different camera angles that is not settled.

Where a frame went before hoisted clamps (228 ms, 0b0074e + local work)

  • the pass over the bindless heap: 32-70 ms (20,000-61,000 slots);
  • copies of title memory into host copies: 51-59 ms, 204-208 MB;
  • sent up to card copies: 134-145 MB in about 420 ranges;
  • looking for shader writes: 265-393 hash passes and 102-129 compare passes, 53,000-56,000 pieces compared;
  • copy-back: 87-98 MB fetched, 67-79 MB written back, 46-50 ms on the landing thread;
  • settles: 105.6 ms a frame of the submitting thread waiting for the card (68.3 ms for a single "title memory changed under shader writes", 37.4 ms for 17 reads);
  • the card had nothing of ours queued for 87.9 ms of it.

With the argument clamps hoisted the card is down to about 50-58 ms a frame. The frame (about 155 ms) is now this CPU side: preparing about 80 ms and copy-back about 50 ms.

A proposal

Each of these costs grows with the memory a submission names, not with the memory that changed. Ideas, in the order I would measure them:

  1. Shader-written dirty pages. The translator already writes per-page fault notes into SLOT_FAULTS, and memory.rs itself suggests "a dirty-page mask written by the shader". With one store more per buffer store (dirty[page] = 1, or appended once per page), each submission knows exactly which 64 KiB pages it wrote. The hash and compare passes, the "before" twins and the assumption that shaders write only declared ranges would go. Writes through UAVs picked from the heap by index would be seen too.
  2. Push instead of pull. Send the pages the CPU dirtied, taken from the write-watch journal for all copies at once, at each submission, instead of finding per submission what it reads. That would take the heap pass and the per-view refreshes off the buffers. The copy could be a DMA from title memory opened in place (OpenExistingHeapFromAddress1 is in vkd3d-proton) instead of a CPU memcpy.
  3. An owner per page. Pages the GPU wrote are not fetched until the CPU touches them: a guard, then a wait for that page's writer only. A CPU write during a flight is merged at landing only where both sides wrote. Settles become waits for one fence that has usually passed.
  4. One mirror of the title's GPU address space. One buffer per title allocation, with the same offsets. That replaces per-buffer copies, 4 MiB windows and duplicates of nested buffers. Marvisak's sparse copies tried something like it, with tiles mapped during the frame, and on Wine/RADV they hung the card (Belobug #69). Mapping must stay out of the frame loop.

Measurements that would decide them: the share of fetched pages the CPU actually reads before the GPU writes them again, and the bytes declared written per submission against the pages actually written.

Related: #1184 (hoisted clamps), #1186 (per-call ranking of hot shaders).

**@⁠Marukooh** on GitHub · 2026-11-25 23:11 UTC · [original](https://github.com/fxceless/victory-fork/issues/1187) ## Host copies of title memory: the windows outside buffers are not why the card is slow on an RTX 5070 Ti, and what the CPU side costs ### The test `VICTORY_CARD_WINDOWS_MB` defaults to 0, so windows of title memory outside buffers (vertices, indices and constants from the title's allocator) stay in the PC's memory and shaders read them over PCIe. I ran the same build with `VICTORY_TEXTURE_DROP_MIPS=1` (to leave room) at `0` and at `3072`, 70 s each, in the prologue (2,500-6,000 draws a frame, pipelines ready; RTX 5070 Ti, Proton, vkd3d-proton): | windows | frame | GPU | preparing | card copies | |---|---:|---:|---:|---:| | PC memory | 237.9 ms | 111.5 ms | 103.5 ms | 97, 941 MB | | card | 234.1 ms | 126.6 ms | 80.4 ms | 356, 2,017 MB | The windows did go to the card (+259 copies, +1,076 MB), but GPU time did not drop. On this card the PCIe reads of windows are not what the ~110 ms of GPU time is made of. Preparing went down by about 23 ms, but on five windows with different camera angles that is not settled. ### Where a frame went before hoisted clamps (228 ms, `0b0074e` + local work) - the pass over the bindless heap: 32-70 ms (20,000-61,000 slots); - copies of title memory into host copies: 51-59 ms, 204-208 MB; - sent up to card copies: 134-145 MB in about 420 ranges; - looking for shader writes: 265-393 hash passes and 102-129 compare passes, 53,000-56,000 pieces compared; - copy-back: 87-98 MB fetched, 67-79 MB written back, 46-50 ms on the landing thread; - settles: 105.6 ms a frame of the submitting thread waiting for the card (68.3 ms for a single "title memory changed under shader writes", 37.4 ms for 17 reads); - the card had nothing of ours queued for 87.9 ms of it. With the argument clamps hoisted the card is down to about 50-58 ms a frame. The frame (about 155 ms) is now this CPU side: preparing about 80 ms and copy-back about 50 ms. ### A proposal Each of these costs grows with the memory a submission *names*, not with the memory that *changed*. Ideas, in the order I would measure them: 1. **Shader-written dirty pages.** The translator already writes per-page fault notes into `SLOT_FAULTS`, and `memory.rs` itself suggests "a dirty-page mask written by the shader". With one store more per buffer store (`dirty[page] = 1`, or appended once per page), each submission knows exactly which 64 KiB pages it wrote. The hash and compare passes, the "before" twins and the assumption that shaders write only declared ranges would go. Writes through UAVs picked from the heap by index would be seen too. 2. **Push instead of pull.** Send the pages the CPU dirtied, taken from the write-watch journal for all copies at once, at each submission, instead of finding per submission what it reads. That would take the heap pass and the per-view refreshes off the buffers. The copy could be a DMA from title memory opened in place (`OpenExistingHeapFromAddress1` is in vkd3d-proton) instead of a CPU memcpy. 3. **An owner per page.** Pages the GPU wrote are not fetched until the CPU touches them: a guard, then a wait for that page's writer only. A CPU write during a flight is merged at landing only where both sides wrote. Settles become waits for one fence that has usually passed. 4. **One mirror of the title's GPU address space.** One buffer per title allocation, with the same offsets. That replaces per-buffer copies, 4 MiB windows and duplicates of nested buffers. Marvisak's sparse copies tried something like it, with tiles mapped during the frame, and on Wine/RADV they hung the card (Belobug #69). Mapping must stay out of the frame loop. Measurements that would decide them: the share of fetched pages the CPU actually reads before the GPU writes them again, and the bytes declared written per submission against the pages actually written. Related: #1184 (hoisted clamps), #1186 (per-call ranking of hot shaders).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:07 +00:00
Author
Owner

@⁠BitWuehler on GitHub · 2026-11-26 00:01 UTC · original

Can confirm the exact same behavior on an RTX 5080 (16 GB, GE-Proton + vkd3d-proton) in world frames:

  • Enabling VICTORY_WINDOW_UPLOAD=1 + VICTORY_CARD_WINDOWS_MB=256 placed 57 windows (248 MB) into the GPU upload heap and turned down 1,152 for the 80% card room cap.
  • CPU preparing halved (122.1 ms -> 59.1 ms, copies 84.8 -> 43.8 ms, copying back 84.4 -> 44.8 ms), but card busy jumped from ~70% to 98% (12.8 ms idle) and median FPS dropped from 4.0 fps (peak 8.6) down to 1.1 fps (peak 2.8).

Note: Log analysis and write-up were AI-assisted based on local runtime measurements.

**@⁠BitWuehler** on GitHub · 2026-11-26 00:01 UTC · [original](https://github.com/fxceless/victory-fork/issues/1187#issuecomment-7178309583) Can confirm the exact same behavior on an **RTX 5080 (16 GB, GE-Proton + vkd3d-proton)** in world frames: - Enabling `VICTORY_WINDOW_UPLOAD=1` + `VICTORY_CARD_WINDOWS_MB=256` placed 57 windows (248 MB) into the GPU upload heap and turned down 1,152 for the 80% card room cap. - CPU `preparing` halved (`122.1 ms -> 59.1 ms`, `copies 84.8 -> 43.8 ms`, `copying back 84.4 -> 44.8 ms`), **but** card busy jumped from ~70% to **98%** (`12.8 ms` idle) and median FPS dropped from `4.0 fps` (peak `8.6`) down to `1.1 fps` (peak `2.8`). *Note: Log analysis and write-up were AI-assisted based on local runtime measurements.*
Author
Owner

@⁠spk-c on GitHub · 2026-11-26 01:08 UTC · original

We have two small, independent contributions to the CPU-side copy path, rather than changing memory placement or skipping writes:

  • #1229 streams readback selection flags into the union and reuses inflight ticket keys, removing redundant temporary collections. The synthetic parity regression passed.
  • #1230 optionally coalesces exactly adjacent source/destination copy ranges on the same resource. A synthetic case reduces 1,024 adjacent 64 KiB pieces to one copy command, with the same 64 MiB transferred and original piece bookkeeping/fences. All three synthetic tests passed.
  • #1231 adds opt-in heap/readback phase attribution so CPU preparation can be distinguished from fence waits and merging.

All three isolated contributions passed fork CI against the corrected baseline. They are not evidence of a frame-time improvement: no controlled runtime A/B, no change to the amount of data copied, and no claim that moving windows into VRAM helps. The next useful measurement is command count and phase time under matched workloads, alongside correctness. AI-assisted implementation and analysis.

**@⁠spk-c** on GitHub · 2026-11-26 01:08 UTC · [original](https://github.com/fxceless/victory-fork/issues/1187#issuecomment-7179476731) We have two small, independent contributions to the CPU-side copy path, rather than changing memory placement or skipping writes: - #1229 streams readback selection flags into the union and reuses inflight ticket keys, removing redundant temporary collections. The synthetic parity regression passed. - #1230 optionally coalesces exactly adjacent source/destination copy ranges on the same resource. A synthetic case reduces 1,024 adjacent 64 KiB pieces to one copy command, with the same 64 MiB transferred and original piece bookkeeping/fences. All three synthetic tests passed. - #1231 adds opt-in heap/readback phase attribution so CPU preparation can be distinguished from fence waits and merging. All three isolated contributions passed fork CI against the corrected baseline. They are not evidence of a frame-time improvement: no controlled runtime A/B, no change to the amount of data copied, and no claim that moving windows into VRAM helps. The next useful measurement is command count and phase time under matched workloads, alongside correctness. AI-assisted implementation and analysis.
Author
Owner

@⁠HLVM04 on GitHub · 2026-11-26 01:26 UTC · original · edited 2026-11-26 17:25 UTC

A Windows data point for the "the CPU side, not the card, is the frame" reading, same card (RTX 5070 Ti, Ryzen 7 9800X3D, Series S profile, native D3D12):

  • On a 9376fd6 stack (+ #798 #783 #799 #780 #770 #827), means after 60 s were 90 ms preparing, 43 ms on the GPU and 69 ms copying back, p50 149 ms. On our current stack the card is waited for about 1 ms a frame; the frame is CPU-bound.
  • On your 68 ms "title memory changed under shader writes" settle: on our stack the merge run cap was being hit by about 60,000 runs of 3 bytes a frame. Deferring those merges to the next submission (a local switch of ours) removed the settles, median 101 -> 91 ms. Raising VICTORY_MERGE_RUNS to 65536 instead was slower (119 ms).
  • Related to idea 3: VICTORY_SKIP_WC_BACK=1 (#868) took our copy-back from 18 to 2 ms with nothing visibly broken in 2 runs of 200 s (see the correction below). But about 17% of title buffer copies then read write-combined memory whose shader writes never come back, so they read stale bytes. So an owner-per-page scheme would also need to cover the title buffer copies the layer runs on the CPU, not only the title's own CPU reads.

Few runs each, scene variance applies.

Edit (2026-11-26), correction: on our stack VICTORY_SKIP_WC_BACK=1 does break the picture: the room's lamp light goes missing and rooms render dark. Our earlier runs were judged only by the character, not by the room lighting, so the "nothing visibly broken" above was wrong. Whether the stale title buffer copies are the cause is not checked.

Edit (2026-11-26), correction on the merge deferral: the local "defer merges past the run cap to the next submission" change above made draws read stale bytes: over-budget title changes under shader-written ranges landed a submission late (with ray tracing on, the main character's skin draw lost its geometry). Please don't copy it as described. Our replacement merges every run at once and joins nearby runs (gap of 64 bytes); it is as fast on our stack (in-world ~45–46 ms) and the skin draw is back with ray tracing on. Exact merging without the gap was ~300 ms a frame. The 101 → 91 ms figure above was for the old, deferring version.

**@⁠HLVM04** on GitHub · 2026-11-26 01:26 UTC · [original](https://github.com/fxceless/victory-fork/issues/1187#issuecomment-7179775357) · edited 2026-11-26 17:25 UTC A Windows data point for the "the CPU side, not the card, is the frame" reading, same card (RTX 5070 Ti, Ryzen 7 9800X3D, Series S profile, native D3D12): - On a 9376fd6 stack (+ #798 #783 #799 #780 #770 #827), means after 60 s were 90 ms preparing, 43 ms on the GPU and 69 ms copying back, p50 149 ms. On our current stack the card is waited for about 1 ms a frame; the frame is CPU-bound. - On your 68 ms "title memory changed under shader writes" settle: on our stack the merge run cap was being hit by about 60,000 runs of 3 bytes a frame. Deferring those merges to the next submission (a local switch of ours) removed the settles, median 101 -> 91 ms. Raising `VICTORY_MERGE_RUNS` to 65536 instead was slower (119 ms). - Related to idea 3: `VICTORY_SKIP_WC_BACK=1` (#868) took our copy-back from 18 to 2 ms ~~with nothing visibly broken~~ in 2 runs of 200 s (see the correction below). But about 17% of title buffer copies then read write-combined memory whose shader writes never come back, so they read stale bytes. So an owner-per-page scheme would also need to cover the title buffer copies the layer runs on the CPU, not only the title's own CPU reads. Few runs each, scene variance applies. **Edit (2026-11-26), correction:** on our stack `VICTORY_SKIP_WC_BACK=1` does break the picture: the room's lamp light goes missing and rooms render dark. Our earlier runs were judged only by the character, not by the room lighting, so the "nothing visibly broken" above was wrong. Whether the stale title buffer copies are the cause is not checked. **Edit (2026-11-26), correction on the merge deferral:** the local "defer merges past the run cap to the next submission" change above made draws read stale bytes: over-budget title changes under shader-written ranges landed a submission late (with ray tracing on, the main character's skin draw lost its geometry). Please don't copy it as described. Our replacement merges every run at once and joins nearby runs (gap of 64 bytes); it is as fast on our stack (in-world ~45–46 ms) and the skin draw is back with ray tracing on. Exact merging without the gap was ~300 ms a frame. The 101 → 91 ms figure above was for the old, deferring version.
Author
Owner

@⁠Marukooh on GitHub · 2026-11-26 17:34 UTC · original

Two local Series X follow-ups on RTX 5070 Ti / Proton, with warm pipelines:

  • For small ranges changed by the CPU under shader writes, a masked VRAM scatter in the existing sync list removed 6–21 ms/frame in the corresponding settle bucket. Submission-thread GPU waits fell from 30–48 to 5–10 ms, but preparation rose 13–23 ms and scatter alone did not improve total time. With sharded descriptor locks as well, two runs each gave 140.9 / 135.4 ms on the control and 115.3 / 115.6 ms on the combined variant. This is a local prototype before the latest main, with visual parity still open.
  • A broad in-place experiment reduced copies (123 → 80 MB/frame) and copy-back (71 → 41 MB/frame), but total frame time went from 126.9 to 200.6 ms. That experiment used a 2 GiB card-buffer minimum to route buffers through in-place memory. Keeping the 1 MiB minimum put almost none of the same buffers in place and measured 130.4 ms. Moving bytes off the relay can raise memory-access cost elsewhere, so I would check actual GPU queue times and keep residency per resource.

The focused readback and alias follow-ups are in #1348 and #1346.

**@⁠Marukooh** on GitHub · 2026-11-26 17:34 UTC · [original](https://github.com/fxceless/victory-fork/issues/1187#issuecomment-7199263950) Two local Series X follow-ups on RTX 5070 Ti / Proton, with warm pipelines: - For small ranges changed by the CPU under shader writes, a masked VRAM scatter in the existing sync list removed 6–21 ms/frame in the corresponding settle bucket. Submission-thread GPU waits fell from 30–48 to 5–10 ms, but preparation rose 13–23 ms and scatter alone did not improve total time. With sharded descriptor locks as well, two runs each gave 140.9 / 135.4 ms on the control and 115.3 / 115.6 ms on the combined variant. This is a local prototype before the latest main, with visual parity still open. - A broad in-place experiment reduced copies (123 → 80 MB/frame) and copy-back (71 → 41 MB/frame), but total frame time went from 126.9 to 200.6 ms. That experiment used a 2 GiB card-buffer minimum to route buffers through in-place memory. Keeping the 1 MiB minimum put almost none of the same buffers in place and measured 130.4 ms. Moving bytes off the relay can raise memory-access cost elsewhere, so I would check actual GPU queue times and keep residency per resource. The focused readback and alias follow-ups are in #1348 and #1346.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/fxceless--victory-fork#1187
No description provided.