perf(gpu): dedup GpuWrite/declared in Batch, reuse front_spans, zero-copy Arc card_dirty, 1-pass send::take #1345

Manually merged
github merged 1 commit from github-bot/gh-1345 into main 2026-11-29 08:21:58 +00:00 AGit
Owner

@⁠qlfu on GitHub · 2026-11-28 17:42 UTC · original
qlfu:pr/submit-batch-and-card-dirty-perf → main · +173 −56 · 4 files · 1 commits · merged 2026-11-29 08:16 UTC

Summary

Eliminates redundant Step::GpuWrite work, per-submission hash-table reallocations, and large Vec<(usize, usize)> clones/multi-pass scans in the card-copy submission path:

  1. Deduplicate Step::GpuWrite (shadow.writing) in Batch and reuse for declared (crates/victory-gpu/src/host.rs):
    • Added gpu_writes_seen, declared, and declared_at on Batch (capacity retained across submissions via SPARE_BATCH).
    • HostList::run_deferred now calls shadow.writing(*address, *len) once per unique (shadow, address, len) in a submission (avoiding thousands of redundant pending/flights lock acquisitions) and hands batch.take_declared() directly to Host::card_before, eliminating the extra 25,000-step walk + fresh HashSet allocation in declared_writes(runs).
    • Added an early return in Batch::flush_one when self.refreshes.is_empty() to skip hashing self.index on empty refresh batches.
    • Reused front_at, front_spans, and front_given scratch buffers on Batch via front_spans_into() instead of allocating a fresh ByCopy<usize> map and two vectors on every refresh_front().
  2. In-place joined() and zero-copy Arc sharing in card_dirty() (crates/victory-gpu/src/shadow.rs, crates/victory-gpu/src/host/upcheck.rs):
    • Updated joined() to merge overlapping/touching ranges in-place (skipping sort() when ranges.is_sorted()), avoiding a second full-size Vec allocation across 80,000–120,000 dirty ranges/frame.
    • Shared DirtyRanges = Arc<Vec<(usize, usize)>> between card_dirty() and SentRuns::note_joined(), replacing the per-submission ranges.clone() deep copy with an Arc::clone.
    • Added unit test joined_in_place_handles_sorted_and_unsorted_ranges.
  3. Single-pass planning in send::take() and piece fast-skip in card_before() rehash loop (crates/victory-gpu/src/host/send.rs, crates/victory-gpu/src/host.rs):
    • Collapsed send::take()'s three passes over dirty ranges (long runs, short word counts, and chunk slicing) into a single pass.
    • Added a current-piece end-offset fast-skip in card_before()'s rehash loop when joins is active, avoiding tens of thousands of repeated shadow.card_run(a, b) calls for consecutive small runs inside the same 64 KiB piece.

Benchmark (GTA VI, 90s steady gameplay, 1440p Series X, DLSS Quality, Ryzen 7 5700X + RTX 4070 Ti 12 GB)

Paired A/B on main (9ce3cf9) with -FrameGen (idle PC, D3D12 VRAM budget ~10,450 MB):

Metric (90s run unless noted) main (9ce3cf9) pr/submit-batch-and-card-dirty-perf (57bf736) Delta
Submitting thread for copies in the card's memory (per frame) 11.7 – 12.6 ms 8.7 – 11.4 ms -15% to -25%
Relay which pieces to fetch (reduced CARD_WORK stall) 6.00 – 7.05 ms 3.06 – 3.86 ms -45% to -49%
Median copy-back (back) 16.7 ms 14.0 ms -16.2% (-2.7 ms)
Median frame time 53.8 ms 52.9 ms -1.7%
Median FPS 18.6 18.9 +1.6%
Title present-wait 14.05 ms 13.5 ms -3.9%
Gameplay WARN / ERROR count 0 / 0 0 / 0 clean

Verification

  • cargo clippy -p victory-gpu --all-targets --locked and --all-features --locked: 0 warnings/errors in modified lines (host.rs, host/send.rs, host/upcheck.rs, shadow.rs).
  • cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored.
  • cargo build --release --locked -p victory: exit 0.
**@⁠qlfu** on GitHub · 2026-11-28 17:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1345) `qlfu:pr/submit-batch-and-card-dirty-perf` → `main` · +173 −56 · 4 files · 1 commits · merged 2026-11-29 08:16 UTC ### Summary Eliminates redundant `Step::GpuWrite` work, per-submission hash-table reallocations, and large `Vec<(usize, usize)>` clones/multi-pass scans in the card-copy submission path: 1. **Deduplicate `Step::GpuWrite` (`shadow.writing`) in `Batch` and reuse for `declared` (`crates/victory-gpu/src/host.rs`)**: - Added `gpu_writes_seen`, `declared`, and `declared_at` on `Batch` (capacity retained across submissions via `SPARE_BATCH`). - `HostList::run_deferred` now calls `shadow.writing(*address, *len)` once per unique `(shadow, address, len)` in a submission (avoiding thousands of redundant `pending`/`flights` lock acquisitions) and hands `batch.take_declared()` directly to `Host::card_before`, eliminating the extra 25,000-step walk + fresh `HashSet` allocation in `declared_writes(runs)`. - Added an early return in `Batch::flush_one` when `self.refreshes.is_empty()` to skip hashing `self.index` on empty refresh batches. - Reused `front_at`, `front_spans`, and `front_given` scratch buffers on `Batch` via `front_spans_into()` instead of allocating a fresh `ByCopy<usize>` map and two vectors on every `refresh_front()`. 2. **In-place `joined()` and zero-copy `Arc` sharing in `card_dirty()` (`crates/victory-gpu/src/shadow.rs`, `crates/victory-gpu/src/host/upcheck.rs`)**: - Updated `joined()` to merge overlapping/touching ranges in-place (skipping `sort()` when `ranges.is_sorted()`), avoiding a second full-size `Vec` allocation across 80,000–120,000 dirty ranges/frame. - Shared `DirtyRanges = Arc<Vec<(usize, usize)>>` between `card_dirty()` and `SentRuns::note_joined()`, replacing the per-submission `ranges.clone()` deep copy with an `Arc::clone`. - Added unit test `joined_in_place_handles_sorted_and_unsorted_ranges`. 3. **Single-pass planning in `send::take()` and piece fast-skip in `card_before()` rehash loop (`crates/victory-gpu/src/host/send.rs`, `crates/victory-gpu/src/host.rs`)**: - Collapsed `send::take()`'s three passes over `dirty` ranges (long runs, short word counts, and chunk slicing) into a single pass. - Added a current-piece end-offset fast-skip in `card_before()`'s rehash loop when `joins` is active, avoiding tens of thousands of repeated `shadow.card_run(a, b)` calls for consecutive small runs inside the same 64 KiB piece. ### Benchmark (GTA VI, 90s steady gameplay, 1440p Series X, DLSS Quality, Ryzen 7 5700X + RTX 4070 Ti 12 GB) Paired A/B on `main` (`9ce3cf9`) with `-FrameGen` (idle PC, D3D12 VRAM budget ~10,450 MB): | Metric (90s run unless noted) | `main` (`9ce3cf9`) | `pr/submit-batch-and-card-dirty-perf` (`57bf736`) | Delta | |---|---:|---:|---:| | Submitting thread `for copies in the card's memory` (per frame) | `11.7 – 12.6 ms` | `8.7 – 11.4 ms` | **-15% to -25%** | | Relay `which pieces to fetch` (reduced `CARD_WORK` stall) | `6.00 – 7.05 ms` | `3.06 – 3.86 ms` | **-45% to -49%** | | Median `copy-back` (`back`) | `16.7 ms` | `14.0 ms` | **-16.2% (-2.7 ms)** | | Median frame time | `53.8 ms` | `52.9 ms` | **-1.7%** | | Median FPS | `18.6` | `18.9` | **+1.6%** | | Title `present-wait` | `14.05 ms` | `13.5 ms` | **-3.9%** | | Gameplay `WARN` / `ERROR` count | `0` / `0` | `0` / `0` | clean | ### Verification - `cargo clippy -p victory-gpu --all-targets --locked` and `--all-features --locked`: 0 warnings/errors in modified lines (`host.rs`, `host/send.rs`, `host/upcheck.rs`, `shadow.rs`). - `cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: **455 passed, 0 failed, 36 ignored**. - `cargo build --release --locked -p victory`: exit `0`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 17:46:38 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-28 19:38 UTC · original

Ran the full victory-gpu library suite at 57bf736 on an NVIDIA Blackwell desktop part with an updated driver.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet: 455 passed, 0 failed, 36 ignored.

What this adds
The count matches the author's run. This covers the deduplicated Step::GpuWrite, reused front spans and zero-copy Arc card-dirty path. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti. It is a correctness run on the new driver, not an FPS measurement.

Not tested
A retail title, FPS/latency A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-28 19:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1345#issuecomment-7244702131) Ran the full victory-gpu library suite at `57bf736` on an NVIDIA Blackwell desktop part with an updated driver. **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40) - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (48a229cea 2026-09-01, pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 - Build: debug **Results** - `VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked -- --test-threads=1 --quiet`: 455 passed, 0 failed, 36 ignored. **What this adds** The count matches the author's run. This covers the deduplicated `Step::GpuWrite`, reused front spans and zero-copy `Arc` card-dirty path. The PR has no comments yet, so this is the first datapoint in the thread and the first from an RTX 5070 Ti. It is a correctness run on the new driver, not an FPS measurement. **Not tested** A retail title, FPS/latency A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - ran the commands above on this machine and wrote this report; no game data was used.
github-bot force-pushed github-bot/gh-1345 from 57bf736b08 to ef5aaf9d94 2026-11-28 20:57:13 +00:00 Compare
github manually merged commit 0d5b7de26f into main 2026-11-29 08:21:58 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/trustno1-coder--VIctory-NVIDIA!1345
No description provided.