perf(host): overlap send upload copies with sync/check D3D12 recording in card_before #1403

Closed
qlfu wants to merge 1 commit from upstream-pr/1403 into main
qlfu commented 2026-11-28 19:10:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T19:10:28Z.


Summary

Overlaps CPU upload copies/word scatters with D3D12 command list recording inside Host::card_before (crates/victory-gpu/src/host.rs, crates/victory-gpu/src/host/send.rs, crates/victory-gpu/src/shadow.rs):

  1. Split send::take into send::prepare + Prepared::run_job (host/send.rs):
    • send::prepare computes upload buffer offsets and acquires the upload Memory buffer upfront without copying bytes yet.
    • Replaces single-threaded < 4 MiB shadow::copy_all calls (~1.1 MB/submission fell below the 4 MiB threshold on almost every submission) with chunk_moves (MOVE_CHUNK_BYTES = 256 KiB), splitting large runs and grouping small runs into parallel copy jobs alongside the 4,096-run word-scatter jobs.
    • Removes now-unused shadow::copy_all.
  2. Single each_under parallel wave in Host::card_before (host.rs):
    • Computes CardRange plans and pops both sync and check command lists before launching one crate::land::each_under wave that executes record_sync (index 0), record_check (index 1), and all send::Prepared scatter/memcpy jobs concurrently.
    • record_sync only references memory.buffer COM handles and precomputed offsets (never memory.data), and self.queue.ExecuteCommandLists runs strictly on the submitting thread after each_under joins (guaranteeing full memory visibility of all upload writes before GPU submission, while still holding QUEUE_ORDER).
    • Preserves the upcheck::on() diagnostics path sequentially so upcheck::record still runs before own.record.
  3. Minor card_before cleanups:
    • Skips decl_ranges.clone() + sort_unstable() when decl_ranges.len() <= 1.
    • Caches the last bound Shadow in record_check to skip redundant GetGPUVirtualAddress() + SetComputeRootShaderResourceView/UAV calls for consecutive spans of the same shadow, and updates CARD_PASSES[2] once per list.

Correctness & Safety

  • All writes to memory.data target disjoint offsets and complete before each_under returns and before ExecuteCommandLists executes on self.queue.
  • sync and check use distinct free-threaded D3D12 command allocators and command lists at unique job indices (0 and 1).
  • QUEUE_ORDER remains locked from card_dirty(sent_as) through self.queue.ExecuteCommandLists(&[Some(sync_cmd)]).
  • Added unit test host::send::tests::chunk_moves_splits_large_and_groups_small.

Verification

  • cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked and --all-features: 0 warnings in modified files.
  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored.
  • cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory: exit 0.

Clean Idle-PC 90s A/B Benchmark (RTX 4070 Ti 12 GB + Ryzen 7 5700X, -FrameGen, vs origin/main)

Metric origin/main This PR Delta
card_mem (copies in the card's memory) median 9.70 ms (21.3 MB) 8.40 ms (23.3 MB) -1.30 ms (-13.4%; -20.7% per MB)
card_mem mean 10.13 ms 8.86 ms -1.27 ms (-12.5%)
Relay fetch_wait 7.10 ms 6.30 ms -0.80 ms (-11.3%)
Relay land_all total 24.75 ms 22.30 ms -2.45 ms (-9.9%)
Submitting thread sub_all median 50.85 ms 49.90 ms -0.95 ms
GPU busy / Title present-wait 71% / 14.05 ms 73% / 13.40 ms +2 pp / -0.65 ms
WARNs / ERRORs 0 / 0 0 / 0 Clean
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5543653938 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1403). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-28T19:10:28Z. --- ## Summary Overlaps CPU upload copies/word scatters with D3D12 command list recording inside `Host::card_before` (`crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/host/send.rs`, `crates/victory-gpu/src/shadow.rs`): 1. **Split `send::take` into `send::prepare` + `Prepared::run_job` (`host/send.rs`):** - `send::prepare` computes upload buffer offsets and acquires the upload `Memory` buffer upfront without copying bytes yet. - Replaces single-threaded `< 4 MiB` `shadow::copy_all` calls (`~1.1 MB/submission` fell below the `4 MiB` threshold on almost every submission) with `chunk_moves` (`MOVE_CHUNK_BYTES = 256 KiB`), splitting large runs and grouping small runs into parallel copy jobs alongside the 4,096-run word-scatter jobs. - Removes now-unused `shadow::copy_all`. 2. **Single `each_under` parallel wave in `Host::card_before` (`host.rs`):** - Computes `CardRange` plans and pops both `sync` and `check` command lists before launching one `crate::land::each_under` wave that executes `record_sync` (index 0), `record_check` (index 1), and all `send::Prepared` scatter/memcpy jobs concurrently. - `record_sync` only references `memory.buffer` COM handles and precomputed offsets (never `memory.data`), and `self.queue.ExecuteCommandLists` runs strictly on the submitting thread **after** `each_under` joins (guaranteeing full memory visibility of all upload writes before GPU submission, while still holding `QUEUE_ORDER`). - Preserves the `upcheck::on()` diagnostics path sequentially so `upcheck::record` still runs before `own.record`. 3. **Minor `card_before` cleanups:** - Skips `decl_ranges.clone()` + `sort_unstable()` when `decl_ranges.len() <= 1`. - Caches the last bound `Shadow` in `record_check` to skip redundant `GetGPUVirtualAddress()` + `SetComputeRootShaderResourceView`/`UAV` calls for consecutive spans of the same shadow, and updates `CARD_PASSES[2]` once per list. ### Correctness & Safety - All writes to `memory.data` target disjoint offsets and complete before `each_under` returns and before `ExecuteCommandLists` executes on `self.queue`. - `sync` and `check` use distinct free-threaded D3D12 command allocators and command lists at unique job indices (`0` and `1`). - `QUEUE_ORDER` remains locked from `card_dirty(sent_as)` through `self.queue.ExecuteCommandLists(&[Some(sync_cmd)])`. - Added unit test `host::send::tests::chunk_moves_splits_large_and_groups_small`. ## Verification - `cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked` and `--all-features`: 0 warnings in modified files. - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: **455 passed, 0 failed, 36 ignored**. - `cargo +1.98.1-x86_64-pc-windows-msvc build --release --locked -p victory`: exit `0`. ## Clean Idle-PC 90s A/B Benchmark (RTX 4070 Ti 12 GB + Ryzen 7 5700X, `-FrameGen`, vs `origin/main`) | Metric | `origin/main` | This PR | Delta | |---|---:|---:|---:| | `card_mem` (`copies in the card's memory`) median | `9.70 ms` (`21.3 MB`) | **`8.40 ms`** (`23.3 MB`) | **`-1.30 ms` (`-13.4%`; `-20.7%` per MB)** | | `card_mem` mean | `10.13 ms` | **`8.86 ms`** | **`-1.27 ms` (`-12.5%`)** | | Relay `fetch_wait` | `7.10 ms` | **`6.30 ms`** | **`-0.80 ms` (`-11.3%`)** | | Relay `land_all` total | `24.75 ms` | **`22.30 ms`** | **`-2.45 ms` (`-9.9%`)** | | Submitting thread `sub_all` median | `50.85 ms` | **`49.90 ms`** | **`-0.95 ms`** | | GPU busy / Title present-wait | `71%` / `14.05 ms` | **`73%` / `13.40 ms`** | **`+2 pp` / `-0.65 ms`** | | WARNs / ERRORs | `0 / 0` | `0 / 0` | Clean |
Lancito01 commented 2026-11-28 21:05:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lancito01 on 2026-11-28T21:05:07Z.


Data point: RTX 3080 / 32 GB, Series S mode, main 9ce3cf9e + #938 + this PR (cherry-picks cleanly). Prison prologue scenes (~4.1k draws, 70 frames): 66.5 ms/frame median (61-79), preparing 52.3, copies 28.5 ms / 86 MB. Without it: 65.4 ms, copies 28.3 ms. No visual problems, no crash in ~12 min, but no measurable change on this setup. One run each.

AI-assisted (Claude).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7245760542 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1403#issuecomment-7245760542). Originally posted by [Lancito01](https://github.com/Lancito01) on 2026-11-28T21:05:07Z. --- Data point: RTX 3080 / 32 GB, Series S mode, main 9ce3cf9e + #938 + this PR (cherry-picks cleanly). Prison prologue scenes (~4.1k draws, 70 frames): 66.5 ms/frame median (61-79), preparing 52.3, copies 28.5 ms / 86 MB. Without it: 65.4 ms, copies 28.3 ms. No visual problems, no crash in ~12 min, but no measurable change on this setup. One run each. *AI-assisted (Claude).*
qlfu commented 2026-11-28 22:18:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T22:18:54Z.


Rebased onto \main\ (\923e38c), preserving \

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246648769 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1403#issuecomment-7246648769). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-28T22:18:54Z. --- Rebased onto \main\ (\923e38c\), preserving \
meonline42 commented 2026-11-29 09:18:03 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by meonline42 on 2026-11-29T09:18:03Z.


Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below).

Machine: Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x.
Base: main at e1f2eb6, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path).
Method: each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second victory_gpu::host lines by draws per frame.

Build (stacked, each on top of the one above) fps median ms/frame, 6,000-6,999 draws ms/frame, 12,000-12,999 draws
main e1f2eb6 16 57.9 (n=3) -
+ #1403 #1279 #2049 #1937 17 56.8 (n=22) 77.6 (n=4)
+ #1988 with VICTORY_PRESENT_QUEUE=1 18 55.9 (n=24) 75.5 (n=10)
#1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue 18 55.0 (n=26) 74.0 (n=8)
  • Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup.
  • No crashes or visible problems in any run, but standing still doesn't exercise much.
  • #1937: the launcher here already set VICTORY_SPANS_QUICK=1, so its default flip made no difference in this run.
  • #128: a full release build took 4 min 23 s on the 5900X.
  • On this machine, most of the frame is still preparing: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between 923e38c and e1f2eb6.

Posted by Claude Code on behalf of the machine's owner.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253671018 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1403#issuecomment-7253671018). Originally posted by [meonline42](https://github.com/meonline42) on 2026-11-29T09:18:03Z. --- Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below). **Machine:** Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x. **Base:** `main` at `e1f2eb6`, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path). **Method:** each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second `victory_gpu::host` lines by draws per frame. | Build (stacked, each on top of the one above) | fps median | ms/frame, 6,000-6,999 draws | ms/frame, 12,000-12,999 draws | |---|---|---|---| | `main` e1f2eb6 | 16 | 57.9 (n=3) | - | | + #1403 #1279 #2049 #1937 | 17 | 56.8 (n=22) | 77.6 (n=4) | | + #1988 with `VICTORY_PRESENT_QUEUE=1` | 18 | 55.9 (n=24) | 75.5 (n=10) | | #1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue | 18 | 55.0 (n=26) | 74.0 (n=8) | - Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup. - No crashes or visible problems in any run, but standing still doesn't exercise much. - #1937: the launcher here already set `VICTORY_SPANS_QUICK=1`, so its default flip made no difference in this run. - #128: a full release build took 4 min 23 s on the 5900X. - On this machine, most of the frame is still `preparing`: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between `923e38c` and `e1f2eb6`. Posted by Claude Code on behalf of the machine's owner.
Marsietiss commented 2026-11-29 13:49:48 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Marsietiss on 2026-11-29T13:49:48Z.


An RTX 5080 result to go with the 3080 and 3090 tests above. It isn't a test of this PR alone.

What we tested: our tree had diverged, so we ported the idea by hand (send upload copies overlapping the sync/check recording). We turned it on and off together with a separate port of the idea in https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1400. RTX 5080 16 GB, Ryzen 9 9950X3D, Series S mode, 1080p.

Result: live on/off test at one fixed spot, 3 cycles with 5 samples each:

Both changes Frame time Draws Per 1k draws
on 40.8 ms 3.70k 11.02 ms
off 42.1 ms 3.58k 11.75 ms

That's about 6% less time per draw with both on.

Limits: we can't say how much came from each change, and this is our own port, not this PR's code. The draw counts differed a little, so compare the per-draw numbers. We only tested one fairly light scene. Our notes don't include a separate picture check for these two switches.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7256832630 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1403#issuecomment-7256832630). Originally posted by [Marsietiss](https://github.com/Marsietiss) on 2026-11-29T13:49:48Z. --- An RTX 5080 result to go with the 3080 and 3090 tests above. **It isn't a test of this PR alone.** **What we tested:** our tree had diverged, so we ported the idea by hand (send upload copies overlapping the sync/check recording). We turned it on and off together with a separate port of the idea in https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1400. RTX 5080 16 GB, Ryzen 9 9950X3D, Series S mode, 1080p. **Result:** live on/off test at one fixed spot, 3 cycles with 5 samples each: | Both changes | Frame time | Draws | Per 1k draws | |---|---|---|---| | on | 40.8 ms | 3.70k | 11.02 ms | | off | 42.1 ms | 3.58k | 11.75 ms | That's about 6% less time per draw with both on. **Limits:** we can't say how much came from each change, and this is our own port, not this PR's code. The draw counts differed a little, so compare the per-draw numbers. We only tested one fairly light scene. Our notes don't include a separate picture check for these two switches.
qlfu commented 2026-11-30 00:12:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T00:12:50Z.


Closing as superseded by upstream main (41adb551) and follow-up #3395:

  • #2509 replaced the < 4 MiB single-threaded copy path in host/send.rs with parallel_copy_work + pack_copy_tasks.
  • VICTORY_SEND_BESIDE=1 already overlaps send::take copies with sync/check recording across the submission.
  • host.rs record_check moved to batched card_batch_pass dispatches.
  • Remaining send::take overhead (zero-alloc scoped scatter + WC 512 B burst + BAR parallel threshold) is carried in #3395.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265067223 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1403#issuecomment-7265067223). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T00:12:50Z. --- Closing as superseded by upstream `main` (`41adb551`) and follow-up `#3395`: - `#2509` replaced the `< 4 MiB` single-threaded copy path in `host/send.rs` with `parallel_copy_work` + `pack_copy_tasks`. - `VICTORY_SEND_BESIDE=1` already overlaps `send::take` copies with `sync`/`check` recording across the submission. - `host.rs` `record_check` moved to batched `card_batch_pass` dispatches. - Remaining `send::take` overhead (zero-alloc scoped scatter + WC 512 B burst + BAR parallel threshold) is carried in `#3395`.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!1403
No description provided.