Reduce CPU lock contention across shadow merges, refreshes, and card sync #1157

Closed
github-bot wants to merge 3 commits from github-bot/gh-1157 into main AGit
Owner

@⁠mikael-jarvinen on GitHub · 2026-11-28 14:30 UTC · original
mikael-jarvinen:pr-cpu-merging-stripes-and-batch → main · +514 −205 · 7 files · 3 commits · closed without merging

Summary

Reduces CPU lock contention and per-submission overhead across the landing, refresh, batching, and card-sync hot paths:

  1. 64-stripe Shadow::merging locks (crates/victory-gpu/src/shadow.rs):

    • Replaces the single whole-buffer Shadow::merging RwLock<()> with a lazily initialized 64-stripe array indexed by 64 KiB page (page & 63) and bitmask lock helpers (merge_read_mask / merge_write_mask).
    • Card-backed merge_under_writes locks only the single stripe for each page it touches instead of blocking concurrent landings on unrelated pages of the same large heap copy.
    • Replaces wide()'s mutex+condvar completion counter with an atomic AtomicUsize + park/unpark, shares one Arc closure across wide_each workers instead of cloning Arc per item, skips by_parts when parts_written is empty, switches Shadow::take to AVX2-accelerated word_runs, and lowers copy_all parallelization threshold to > 512 KiB with >= 4 ranges.
  2. Unified Shadow::copy_state RwLock + batched watch::JournalRead & lock-free KEPT (crates/victory-gpu/src/shadow.rs, crates/victory-gpu/src/watch.rs, crates/victory-gpu/src/host.rs, apps/victory/src/play.rs):

    • Combines Shadow::copied and Shadow::ranged under one RwLock<CopyState> so concurrent nothing_new checks share read access instead of serializing on two mutexes.
    • Adds watch::JournalRead (amortizing JOURNAL read lock across Batch::refresh_front and Batch::flush_all), an atomic KEPT mirror (watch::is_kept()) to skip redundant ask_ahead/ask_ahead_done work while ask_once stands, sorted/merged binary search in ahead_contains, 64-bit word scanning in Blocks::all_set(), and yield_now() in unlocked guard-fault waits (VICTORY_FAULT_UNLOCKED=1 enabled in play.rs).
  3. Batched card-step CBV updates, Batch hot-path dedup, and merged card sync (crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/host/card_steps.rs, crates/victory-gpu/src/host.rs):

    • Replaces per-slot descriptor::constant_slot calls with descriptor::constant_slots_batch + HostHeap::constant_at_with_base (one SHADER_HEAPS read lock, cached last HostHeap, hoisted base GPU VA) and pre-buckets 8-way parallel CBV updates once before spawning workers.
    • Adds a 1-entry inline Batch::last_ahead cache and single-pass Batch::note_gpu_write deduplication (building declared inline and skipping redundant Shadow::writing locks and a second step walk).
    • Narrows CARD_WORK lock scope in card_before and batches sync into the main ExecuteCommandLists submission when flown && relay_copy().

Verification

  • cargo clippy -p victory-gpu -p victory --all-targets --locked — 0 warnings in touched code
  • cargo clippy -p victory-gpu --all-targets --all-features --locked — 0 warnings in touched code
  • cargo test -p victory-gpu --lib --locked — 453 passed, 0 failed
  • cargo xtask policy — 294 files ok
  • cargo build --release -p victory — clean release build (0 warnings)

A/B Benchmark vs origin/main (63b902f)

Tested on RTX 3080 10 GB, 1440p DLSS Performance, identical 115 s scripted launch (VICTORY_WARMUP_RESTART=0, VICTORY_POOL_STATS=1, VICTORY_KEYS=25:Enter,...,55:Enter):

Metric origin/main (63b902f) This PR (833e4fd) Delta
Landing wait_title_bytes (last 2 windows) 11.36 / 8.29 ms 0.46 / 0.44 ms −95%
Landing merge_all (last 2 windows) 18.01 / 16.87 ms 7.43 / 7.97 ms −56%
Landing merge_wall (last 2 windows) 6.02 / 5.83 ms 3.80 / 3.40 ms −39%
Heavy 5k-draw back time 9.9–13.8 ms 8.5–8.6 ms −29%
Submitting under (merge_under_writes, last 5) 6.1–8.3 ms 3.6–6.5 ms −41% (last window)
Submitting card (card_before + card_steps, last 5) 5.1–6.2 ms 3.9–4.9 ms −21%
3D prep median (5k-draw best) 33.5 ms (28.6 ms) 31.7 ms (25.1 ms) −1.8 ms (−3.5 ms)
3D copies median 15.6 ms 14.4 ms −1.2 ms
Non-Streamline errors / faults 0 0 —

(Note: During the PR run Windows DXGI dynamically lowered the process VRAM budget to 8,207 MB vs 8,679 MB in baseline, increasing GPU wait on unpatched 10 GB VRAM; all CPU-side metrics improved substantially across every phase.)

**@⁠mikael-jarvinen** on GitHub · 2026-11-28 14:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157) `mikael-jarvinen:pr-cpu-merging-stripes-and-batch` → `main` · +514 −205 · 7 files · 3 commits · closed without merging ## Summary Reduces CPU lock contention and per-submission overhead across the landing, refresh, batching, and card-sync hot paths: 1. **64-stripe `Shadow::merging` locks (`crates/victory-gpu/src/shadow.rs`):** - Replaces the single whole-buffer `Shadow::merging` `RwLock<()>` with a lazily initialized 64-stripe array indexed by 64 KiB page (`page & 63`) and bitmask lock helpers (`merge_read_mask` / `merge_write_mask`). - Card-backed `merge_under_writes` locks only the single stripe for each page it touches instead of blocking concurrent landings on unrelated pages of the same large heap copy. - Replaces `wide()`'s mutex+condvar completion counter with an atomic `AtomicUsize` + `park`/`unpark`, shares one `Arc` closure across `wide_each` workers instead of cloning `Arc` per item, skips `by_parts` when `parts_written` is empty, switches `Shadow::take` to AVX2-accelerated `word_runs`, and lowers `copy_all` parallelization threshold to `> 512 KiB` with `>= 4` ranges. 2. **Unified `Shadow::copy_state` `RwLock` + batched `watch::JournalRead` & lock-free `KEPT` (`crates/victory-gpu/src/shadow.rs`, `crates/victory-gpu/src/watch.rs`, `crates/victory-gpu/src/host.rs`, `apps/victory/src/play.rs`):** - Combines `Shadow::copied` and `Shadow::ranged` under one `RwLock<CopyState>` so concurrent `nothing_new` checks share read access instead of serializing on two mutexes. - Adds `watch::JournalRead` (amortizing `JOURNAL` read lock across `Batch::refresh_front` and `Batch::flush_all`), an atomic `KEPT` mirror (`watch::is_kept()`) to skip redundant `ask_ahead`/`ask_ahead_done` work while `ask_once` stands, sorted/merged binary search in `ahead_contains`, 64-bit word scanning in `Blocks::all_set()`, and `yield_now()` in unlocked guard-fault waits (`VICTORY_FAULT_UNLOCKED=1` enabled in `play.rs`). 3. **Batched card-step CBV updates, `Batch` hot-path dedup, and merged card sync (`crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/host/card_steps.rs`, `crates/victory-gpu/src/host.rs`):** - Replaces per-slot `descriptor::constant_slot` calls with `descriptor::constant_slots_batch` + `HostHeap::constant_at_with_base` (one `SHADER_HEAPS` read lock, cached last `HostHeap`, hoisted base GPU VA) and pre-buckets 8-way parallel CBV updates once before spawning workers. - Adds a 1-entry inline `Batch::last_ahead` cache and single-pass `Batch::note_gpu_write` deduplication (building `declared` inline and skipping redundant `Shadow::writing` locks and a second step walk). - Narrows `CARD_WORK` lock scope in `card_before` and batches `sync` into the main `ExecuteCommandLists` submission when `flown && relay_copy()`. ## Verification - `cargo clippy -p victory-gpu -p victory --all-targets --locked` — 0 warnings in touched code - `cargo clippy -p victory-gpu --all-targets --all-features --locked` — 0 warnings in touched code - `cargo test -p victory-gpu --lib --locked` — **453 passed, 0 failed** - `cargo xtask policy` — **294 files ok** - `cargo build --release -p victory` — clean release build (0 warnings) ## A/B Benchmark vs `origin/main` (`63b902f`) Tested on RTX 3080 10 GB, 1440p DLSS Performance, identical 115 s scripted launch (`VICTORY_WARMUP_RESTART=0`, `VICTORY_POOL_STATS=1`, `VICTORY_KEYS=25:Enter,...,55:Enter`): | Metric | `origin/main` (`63b902f`) | This PR (`833e4fd`) | Delta | |---|---:|---:|---:| | Landing `wait_title_bytes` (last 2 windows) | `11.36 / 8.29 ms` | **`0.46 / 0.44 ms`** | **−95%** | | Landing `merge_all` (last 2 windows) | `18.01 / 16.87 ms` | **`7.43 / 7.97 ms`** | **−56%** | | Landing `merge_wall` (last 2 windows) | `6.02 / 5.83 ms` | **`3.80 / 3.40 ms`** | **−39%** | | Heavy 5k-draw `back` time | `9.9–13.8 ms` | **`8.5–8.6 ms`** | **−29%** | | Submitting `under` (`merge_under_writes`, last 5) | `6.1–8.3 ms` | **`3.6–6.5 ms`** | **−41% (last window)** | | Submitting `card` (`card_before` + `card_steps`, last 5) | `5.1–6.2 ms` | **`3.9–4.9 ms`** | **−21%** | | 3D `prep` median (5k-draw best) | `33.5 ms` (`28.6 ms`) | **`31.7 ms` (`25.1 ms`)** | **−1.8 ms (`−3.5 ms`)** | | 3D `copies` median | `15.6 ms` | **`14.4 ms`** | **−1.2 ms** | | Non-Streamline errors / faults | `0` | **`0`** | — | *(Note: During the PR run Windows DXGI dynamically lowered the process VRAM budget to `8,207 MB` vs `8,679 MB` in baseline, increasing GPU wait on unpatched 10 GB VRAM; all CPU-side metrics improved substantially across every phase.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:44:04 +00:00
Author
Owner

@⁠cxy0072019-sketch on GitHub · 2026-11-28 15:01 UTC · original

Tested 63b902f and 833e4fd on an RTX 5070 Ti 16 GB and i5‑14600KF under Windows. Both diagnostics release builds used a copy of the same Series S Gear Up checkpoint at 1920×1080 output, 720p internal, with DLSS and frame generation off. The initial emulator caches had identical SHA‑256 manifests, and each run began with its own driver cache. The candidate uses the VICTORY_FAULT_UNLOCKED=1 preset from the PR.

Settled balcony view 63b902f 833e4fd
Rendered FPS, median 16.75 17.20
CPU preparation, ms/frame 47.05 44.50
Copies, ms/frame 27.40 23.40
Copy back, ms/frame 11.75 11.50
Draws/frame, median 5,336 5,318
Median of one-second p95 frame times, ms 70.9 68.8

These are the last three matched-camera windows after pipeline compilation settled, totaling 8 and 9 complete five-second samples. CPU preparation was lower in all three windows. The two runs showed the same visible character, house, and water rendering in the sampled view. This is one restart pair in one scene. Test automation and analysis were AI-assisted.

**@⁠cxy0072019-sketch** on GitHub · 2026-11-28 15:01 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157#issuecomment-7241137719) Tested `63b902f` and `833e4fd` on an RTX 5070 Ti 16 GB and i5‑14600KF under Windows. Both diagnostics release builds used a copy of the same Series S Gear Up checkpoint at 1920×1080 output, 720p internal, with DLSS and frame generation off. The initial emulator caches had identical SHA‑256 manifests, and each run began with its own driver cache. The candidate uses the `VICTORY_FAULT_UNLOCKED=1` preset from the PR. | Settled balcony view | `63b902f` | `833e4fd` | | --- | ---: | ---: | | Rendered FPS, median | 16.75 | 17.20 | | CPU preparation, ms/frame | 47.05 | 44.50 | | Copies, ms/frame | 27.40 | 23.40 | | Copy back, ms/frame | 11.75 | 11.50 | | Draws/frame, median | 5,336 | 5,318 | | Median of one-second p95 frame times, ms | 70.9 | 68.8 | These are the last three matched-camera windows after pipeline compilation settled, totaling 8 and 9 complete five-second samples. CPU preparation was lower in all three windows. The two runs showed the same visible character, house, and water rendering in the sampled view. This is one restart pair in one scene. Test automation and analysis were AI-assisted.
Author
Owner

@⁠Aniseto on GitHub · 2026-11-28 15:20 UTC · original

Ran the full victory-gpu library suite at 833e4fd on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (48a229cea 2026-09-01, pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.

VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked -- --test-threads=1
453 passed; 0 failed; 36 ignored; 0 measured; 0 filtered out      (exit 0)

The count matches the author's suite run. Tests cover the striped merge locks, the batched journal reads and lock-free KEPT path among the rest of the crate. This is a correctness run, not an FPS or latency measurement; the PR's 115 s scripted A/B on an RTX 3080 was not repeated here. The thread already has a 5070 Ti A/B from another tester; this adds an independent full-suite count.

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 - checked out the PR's head commit in a detached worktree, built it, ran the command above, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-28 15:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157#issuecomment-7241394094) Ran the full `victory-gpu` library suite at `833e4fd` on an NVIDIA Blackwell desktop part: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (48a229cea 2026-09-01, pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build. ``` VICTORY_D3D12_ADAPTER=NVIDIA cargo test -p victory-gpu --lib --locked -- --test-threads=1 453 passed; 0 failed; 36 ignored; 0 measured; 0 filtered out (exit 0) ``` The count matches the author's suite run. Tests cover the striped merge locks, the batched journal reads and lock-free `KEPT` path among the rest of the crate. This is a correctness run, not an FPS or latency measurement; the PR's 115 s scripted A/B on an RTX 3080 was not repeated here. The thread already has a 5070 Ti A/B from another tester; this adds an independent full-suite count. 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** - checked out the PR's head commit in a detached worktree, built it, ran the command above, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠POMXARK on GitHub · 2026-11-28 16:51 UTC · original

@⁠mikael-jarvinen

Tested a selective port of the five pieces of this PR that do not overlap with #1094 (keeping lock-free 3-level PageEpochs, SeqLock ranged, single-lock wide_each_scoped, and Arc card_dirty) on an RTX 5080 + 8C/16T CPU.

Test Setup & Honest Disclosure

  • Hardware: AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Windows 11.
  • Profile: Series X, 2560×1440, DLSS Quality + DLSS MFG 4×, default 4 MiB windows, warm shader cache.
  • Base branch: v2026.11.28.02 (2a66ef1) + AVX2/ThinLTO + #516 + #340 + #81 + #666 + #801 + #834 + #1094 + #1038 (WATCH_LARGE_XMEM=1).
  • Subset tested from #1157:
    1. 64-stripe Shadow::merging locks + copy_stale empty-map skip + atomic Done in wide().
    2. descriptor::constant_slots_batch + 8-way parallel CBV updates.
    3. Batch::last_ahead 1-entry cache + single-pass Batch::note_gpu_write.
    4. Narrower CARD_WORK lock + merging CardPlan::sync into the main ExecuteCommandLists (flown && relay_copy()).
    5. Blocks::all_set() 64-bit word scan + unlocked guard() fast path.
  • Caveat on route variance: The 20-minute run included interactive play through heavier late sections (up to ~11.2k draws/frame) plus a brief window focus switch mid-run, so raw overall FPS is not a strict apples-to-apples A/A route match; draw-count-matched buckets and per-phase submitting thread medians are reported below.

Results (232/232 victory-gpu release tests PASS; 20-minute run, 0 errors)

Metric (3D only) Baseline (#1094 + #1038) + #1157 selective port Delta
Engine / D3D12 / guest errors 0 0 clean
1k–4k draws p50 FPS 18.80 (copies 16.4 ms) 15.60 (copies 17.5 ms) -17.0%
4k–7k draws p50 FPS 15.40 (copies 21.3 ms) 13.10 (copies 26.6 ms) -14.9%
7k–10k draws p50 FPS 10.50 (copies 39.5 ms) 10.00 (copies 40.9 ms) -4.8%
submitting total (median) 57.7 ms 68.1 ms +10.4 ms
under (shadow merge lock) 3.4 ms 4.8 ms +1.4 ms
steps (refreshes) 27.9 ms (17.5 ms) 31.2 ms (21.7 ms) +3.3 ms (+4.2 ms)
card / send 8.5 ms / 1.9 ms 7.7 ms / 2.5 ms -0.8 ms / +0.6 ms
heaps_pre / heaps_end 1.0 ms / 0.7 ms 1.7 ms / 1.1 ms +0.7 ms / +0.4 ms
1s frame_times med / p95 / p99 61.0 / 80.4 / 90.4 ms 67.7 / 93.7 / 107.8 ms +6.7 / +13.3 / +17.4 ms

Observations & Takeaway

  • Stability & visuals: 0 D3D12/engine/guest errors and clean visuals across the entire 20-minute run (232/232 unit tests PASS).
  • Why this subset regressed on 8C/16T when stacked on #1094:
    • card dropped 8.5 -> 7.7 ms (-0.8 ms), but send rose 1.9 -> 2.5 ms (+0.6 ms), leaving near-zero net gain (-0.2 ms) from merging CardPlan::sync into ExecuteCommandLists.
    • On 8C/16T with #1094 already eliminating contention on PageEpochs/ranged, acquiring bitmask-indexed stripes across the 64-entry Shadow::merging array raised under (3.4 -> 4.8 ms), and the 8-way parallel CBV descriptor batching increased thread wakeup/sync overhead (heaps_pre + heaps_end: 1.7 -> 2.8 ms).
  • Native Xbox GDK / D3D12 angle: Rather than adding finer CPU mutex stripes around shadow merges and CPU-side CBV re-copies, a larger win on host D3D12 comes from reducing the number of host shadow ranges that need merging at all — e.g., honoring Xbox PAGE_GRAPHICS_READONLY / XMEM_CPU allocation classes at XMemAlloc* time (skipping GPU readback/shadow tracking on read-only or CPU-only pages) and using D3D12 Relaxed Format Casting (CreatePlacedResource2) / Enhanced Barriers where console views alias without needing separate host shadow copies.
**@⁠POMXARK** on GitHub · 2026-11-28 16:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157#issuecomment-7242571575) @⁠mikael-jarvinen Tested a **selective port** of the five pieces of this PR that do not overlap with `#1094` (keeping lock-free 3-level `PageEpochs`, SeqLock `ranged`, single-lock `wide_each_scoped`, and `Arc` `card_dirty`) on an RTX 5080 + 8C/16T CPU. ### Test Setup & Honest Disclosure - **Hardware:** AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Windows 11. - **Profile:** Series X, 2560×1440, DLSS Quality + DLSS MFG 4×, default `4 MiB` windows, warm shader cache. - **Base branch:** `v2026.11.28.02` (`2a66ef1`) + AVX2/ThinLTO + `#516` + `#340` + `#81` + `#666` + `#801` + `#834` + `#1094` + `#1038` (`WATCH_LARGE_XMEM=1`). - **Subset tested from #1157:** 1. 64-stripe `Shadow::merging` locks + `copy_stale` empty-map skip + atomic `Done` in `wide()`. 2. `descriptor::constant_slots_batch` + 8-way parallel CBV updates. 3. `Batch::last_ahead` 1-entry cache + single-pass `Batch::note_gpu_write`. 4. Narrower `CARD_WORK` lock + merging `CardPlan::sync` into the main `ExecuteCommandLists` (`flown && relay_copy()`). 5. `Blocks::all_set()` 64-bit word scan + unlocked `guard()` fast path. - **Caveat on route variance:** The 20-minute run included interactive play through heavier late sections (up to ~11.2k draws/frame) plus a brief window focus switch mid-run, so raw overall FPS is not a strict apples-to-apples A/A route match; draw-count-matched buckets and per-phase `submitting thread` medians are reported below. ### Results (`232/232` `victory-gpu` release tests PASS; 20-minute run, `0` errors) | Metric (3D only) | Baseline (`#1094` + `#1038`) | + #1157 selective port | Delta | |---|---:|---:|---:| | Engine / D3D12 / guest errors | `0` | `0` | clean | | `1k–4k` draws p50 FPS | `18.80` (`copies 16.4 ms`) | `15.60` (`copies 17.5 ms`) | `-17.0%` | | `4k–7k` draws p50 FPS | `15.40` (`copies 21.3 ms`) | `13.10` (`copies 26.6 ms`) | `-14.9%` | | `7k–10k` draws p50 FPS | `10.50` (`copies 39.5 ms`) | `10.00` (`copies 40.9 ms`) | `-4.8%` | | `submitting` total (median) | `57.7 ms` | `68.1 ms` | `+10.4 ms` | | `under` (shadow merge lock) | `3.4 ms` | `4.8 ms` | `+1.4 ms` | | `steps` (`refreshes`) | `27.9 ms` (`17.5 ms`) | `31.2 ms` (`21.7 ms`) | `+3.3 ms` (`+4.2 ms`) | | `card` / `send` | `8.5 ms` / `1.9 ms` | `7.7 ms` / `2.5 ms` | `-0.8 ms` / `+0.6 ms` | | `heaps_pre` / `heaps_end` | `1.0 ms` / `0.7 ms` | `1.7 ms` / `1.1 ms` | `+0.7 ms` / `+0.4 ms` | | `1s frame_times` med / p95 / p99 | `61.0 / 80.4 / 90.4 ms` | `67.7 / 93.7 / 107.8 ms` | `+6.7 / +13.3 / +17.4 ms` | ### Observations & Takeaway - **Stability & visuals:** `0` D3D12/engine/guest errors and clean visuals across the entire 20-minute run (`232/232` unit tests PASS). - **Why this subset regressed on 8C/16T when stacked on `#1094`:** - `card` dropped `8.5 -> 7.7 ms` (`-0.8 ms`), but `send` rose `1.9 -> 2.5 ms` (`+0.6 ms`), leaving near-zero net gain (`-0.2 ms`) from merging `CardPlan::sync` into `ExecuteCommandLists`. - On 8C/16T with `#1094` already eliminating contention on `PageEpochs`/`ranged`, acquiring bitmask-indexed stripes across the 64-entry `Shadow::merging` array raised `under` (`3.4 -> 4.8 ms`), and the 8-way parallel CBV descriptor batching increased thread wakeup/sync overhead (`heaps_pre + heaps_end`: `1.7 -> 2.8 ms`). - **Native Xbox GDK / D3D12 angle:** Rather than adding finer CPU mutex stripes around shadow merges and CPU-side CBV re-copies, a larger win on host D3D12 comes from reducing the number of host shadow ranges that need merging at all — e.g., honoring Xbox `PAGE_GRAPHICS_READONLY` / `XMEM_CPU` allocation classes at `XMemAlloc*` time (skipping GPU readback/shadow tracking on read-only or CPU-only pages) and using D3D12 Relaxed Format Casting (`CreatePlacedResource2`) / Enhanced Barriers where console views alias without needing separate host shadow copies.
Live in-process VICTORY_AB at ~6,780 draws/frame confirmed reviewer feedback that fanning out constant_slots_batch across 8 threads at ops.len() >= 256 regresses frame time (+1.64 ms mean, +2.40 ms p90) and CPU prep (+1.96 ms). Running constant_slots_batch inline avoids 8-Vec scatter allocations, worker wakeup sync, and descriptor-heap cache-line contention.
Author
Owner

@⁠mikael-jarvinen on GitHub · 2026-11-28 18:30 UTC · original

Thanks @⁠POMXARK for catching the 8-way parallel CBV regression (and @⁠cxy0072019-sketch and @⁠Aniseto for the independent 5070 Ti runs)!

Live VICTORY_AB confirmation & fix pushed

We wired an in-process VICTORY_AB toggle on the 8-way constant_slots_batch fan-out (ops.len() >= 256) and ran a paired 10-phase standing-scene A/B at ~6,780 draws/frame on RTX 3080 10 GB (Series X 1440p, DLSS Performance, FG off):

constant_slots_batch mode Draws/fr Frame mean Frame med Frame p90 CPU prep plan heaps (pre+end)
Inline (single-thread) 6,781 49.90 ms 49.26 ms 57.76 ms 45.56 ms 6.34 ms 2.57 ms
8-way parallel (>= 256) 6,777 51.54 ms (+1.64 ms) 50.60 ms (+1.34 ms) 60.16 ms (+2.40 ms) 47.52 ms (+1.96 ms) 6.80 ms (+0.46 ms) 3.11 ms (+0.54 ms)

Your diagnosis was spot-on: once constant_slots_batch acquires SHADER_HEAPS once and caches the HostHeap, fanning out >= 256 slots into 8 Vecs across worker threads adds more scatter/wakeup/cache-line overhead than it saves.

  • Fix pushed to pr-cpu-merging-stripes-and-batch: Removed the 8-way parallel fan-out in crates/victory-gpu/src/host/card_steps.rs, running constant_slots_batch inline directly.
  • Verification: cargo test -p victory-gpu --lib (453 passed, 0 failed), cargo xtask policy (294 files ok).
**@⁠mikael-jarvinen** on GitHub · 2026-11-28 18:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157#issuecomment-7243843508) Thanks @⁠POMXARK for catching the 8-way parallel CBV regression (and @⁠cxy0072019-sketch and @⁠Aniseto for the independent 5070 Ti runs)! ### Live `VICTORY_AB` confirmation & fix pushed We wired an in-process `VICTORY_AB` toggle on the 8-way `constant_slots_batch` fan-out (`ops.len() >= 256`) and ran a paired 10-phase standing-scene A/B at ~6,780 draws/frame on RTX 3080 10 GB (Series X 1440p, DLSS Performance, FG off): | `constant_slots_batch` mode | Draws/fr | Frame mean | Frame med | Frame p90 | CPU `prep` | `plan` | `heaps` (`pre+end`) | |---|---:|---:|---:|---:|---:|---:|---:| | **Inline (single-thread)** | 6,781 | **49.90 ms** | **49.26 ms** | **57.76 ms** | **45.56 ms** | **6.34 ms** | **2.57 ms** | | **8-way parallel (`>= 256`)** | 6,777 | 51.54 ms (`+1.64 ms`) | 50.60 ms (`+1.34 ms`) | 60.16 ms (`+2.40 ms`) | 47.52 ms (`+1.96 ms`) | 6.80 ms (`+0.46 ms`) | 3.11 ms (`+0.54 ms`) | Your diagnosis was spot-on: once `constant_slots_batch` acquires `SHADER_HEAPS` once and caches the `HostHeap`, fanning out `>= 256` slots into 8 `Vec`s across worker threads adds more scatter/wakeup/cache-line overhead than it saves. - **Fix pushed to `pr-cpu-merging-stripes-and-batch`:** Removed the 8-way parallel fan-out in `crates/victory-gpu/src/host/card_steps.rs`, running `constant_slots_batch` inline directly. - **Verification:** `cargo test -p victory-gpu --lib` (`453 passed, 0 failed`), `cargo xtask policy` (`294 files ok`).
Live in-process VICTORY_AB at ~6,750 draws/frame showed holding CardPlan::sync until the main ExecuteCommandLists batch regressed wall frame time by +1.34 ms mean / +1.52 ms med / +1.90 ms p90 and CPU prep by +1.50 ms by delaying GPU kick-off. Restoring immediate ExecuteCommandLists recovers that latency cleanly while keeping the narrowed CARD_WORK lock scope.
Author
Owner

@⁠mikael-jarvinen on GitHub · 2026-11-28 18:48 UTC · original

Follow-up after a second live in-process VICTORY_AB sweep on RTX 3080 (~6,750 draws/frame, 9 steady phases): we also tested the CardPlan::sync merge (batch_sync = flown && relay_copy()) that @⁠POMXARK flagged as near-neutral (card -0.8 / send +0.6 ms):

CardPlan::sync mode Draws/fr Frame mean Frame med Frame p90 CPU prep card send
Immediate ExecuteCommandLists 6,754 48.84 ms 48.28 ms 56.10 ms 46.23 ms 5.46 ms 1.33 ms
Batched into main submission 6,747 50.17 ms (+1.34 ms) 49.80 ms (+1.52 ms) 58.00 ms (+1.90 ms) 47.73 ms (+1.50 ms) 4.66 ms (−0.80 ms) 1.62 ms (+0.29 ms)

Holding the upload/rehash sync list until the main ExecuteCommandLists saves −0.80 ms in card_before on paper, but delays GPU kick-off and regresses wall-clock frame time by +1.34 ms mean / +1.90 ms p90.

  • Fix pushed to pr-cpu-merging-stripes-and-batch: Removed CardPlan::sync batching in crates/victory-gpu/src/host.rs, restoring immediate ExecuteCommandLists for the sync list (keeping the narrowed CARD_WORK lock scope).
  • Verification: cargo test -p victory-gpu --lib (453 passed, 0 failed), cargo xtask policy (294 files ok).
**@⁠mikael-jarvinen** on GitHub · 2026-11-28 18:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157#issuecomment-7244070050) Follow-up after a second live in-process `VICTORY_AB` sweep on RTX 3080 (`~6,750` draws/frame, 9 steady phases): we also tested the `CardPlan::sync` merge (`batch_sync = flown && relay_copy()`) that @⁠POMXARK flagged as near-neutral (`card -0.8 / send +0.6 ms`): | `CardPlan::sync` mode | Draws/fr | Frame mean | Frame med | Frame p90 | CPU `prep` | `card` | `send` | |---|---:|---:|---:|---:|---:|---:|---:| | **Immediate `ExecuteCommandLists`** | 6,754 | **48.84 ms** | **48.28 ms** | **56.10 ms** | **46.23 ms** | 5.46 ms | **1.33 ms** | | **Batched into main submission** | 6,747 | 50.17 ms (`+1.34 ms`) | 49.80 ms (`+1.52 ms`) | 58.00 ms (`+1.90 ms`) | 47.73 ms (`+1.50 ms`) | 4.66 ms (`−0.80 ms`) | 1.62 ms (`+0.29 ms`) | Holding the upload/rehash `sync` list until the main `ExecuteCommandLists` saves `−0.80 ms` in `card_before` on paper, but delays GPU kick-off and regresses wall-clock frame time by `+1.34 ms` mean / `+1.90 ms` p90. - **Fix pushed to `pr-cpu-merging-stripes-and-batch`:** Removed `CardPlan::sync` batching in `crates/victory-gpu/src/host.rs`, restoring immediate `ExecuteCommandLists` for the sync list (keeping the narrowed `CARD_WORK` lock scope). - **Verification:** `cargo test -p victory-gpu --lib` (`453 passed, 0 failed`), `cargo xtask policy` (`294 files ok`).
github-bot closed this pull request 2026-11-28 19:25:01 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-28 19:22 UTC · original

Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

**@⁠trustno1-coder** on GitHub · 2026-11-28 19:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1157#issuecomment-7244502077) Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

Pull request closed

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!1157
No description provided.