gpu: lock-free refresh checks, single-lock scoped pool, and zero-clone card_dirty #1094

Closed
Bazovsky wants to merge 3 commits from upstream-pr/1094 into main
Bazovsky commented 2026-11-28 13:11:57 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bazovsky on 2026-11-28T13:11:57Z.


What is now true

Eliminates lock contention, per-flush heap allocations, and redundant range cloning on the victory-submit critical path (no new user switches; preserves all existing VICTORY_* behavior):

  • watch.rs:
    • Adds a 3-level lock-free PageEpochs table (WRITTEN_EPOCHS, 128 TiB coverage, specialized single-page fast path, plain Release store under the exclusive JOURNAL write lock) mirroring Journal::written.
    • Adds lock-free is_kept() (mirroring Journal::kept), reusable ahead_snapshot_into(&mut Vec<_>), and zero-lock nothing_new_with / zero-alloc nothing_new_single.
  • shadow.rs:
    • Replaces Shadow::copied: Mutex<Vec<u64>> and ranged: Mutex<[(usize, usize, u64); 2]> with copy_lock: Mutex<()> + copied: Box<[AtomicU64]> + SeqLock ranged + pending_len: AtomicUsize — shrinking Shadow while making Shadow::nothing_new_with completely lock-free on the common (no pending shader writes) path.
    • Adds zero-allocation, single-lock wide_each_scoped sharing Workers::queue (0 heap allocations vs ~21 in wide_each, 0 exit locks for non-last helpers, safe inline fallback if nested).
    • Replaces per-page Mutex<Done> allocations in Shadow::merge_under_writes with unique-index Slots.
    • Stores Arc<Vec<(usize, usize)>> in SentRuns and returns it from card_dirty(), avoiding cloning tens of thousands of dirty ranges per submission.
  • host.rs, host/send.rs, host/upcheck.rs:
    • Skips allocating ranges and locking JOURNAL in ask_ahead / ask_ahead_done when watch::is_kept() (VICTORY_ASK_ONCE=1) is already true.
    • Reuses Batch::ahead_snap across flushes, dispatches refresh_front / flush_all / refresh_ahead / fill / refresh_textures via wide_each_scoped (grain 1 after no-op filtering, grain 8 for large mixed flushes), and batches FLUSHES[2] atomic updates once per chunk instead of once per no-op.
  • land.rs:
    • Replaces per-item state.lock() in land::Pool with a lock-free AtomicUsize work counter (1 lock on batch entry/exit instead of 2 locks per item).

Relation to open PRs

Complements #126 (VICTORY_WIDE_CHUNK): rather than adding a chunk-size knob on top of the allocating wide_each + locked nothing_new, this removes the locks in nothing_new (JOURNAL, Shadow::pending/copied/ranged), removes per-flush heap allocations in Workers, and removes the card_dirty range clone and per-item land::Pool locking.

Does not change watch::writes or the guards lock contention tracked in #795: this PR takes locks off unchanged-range nothing_new checks, the Workers / land::Pool dispatch loops, and card_dirty cloning, while guarded ranges that miss nothing_new still go through watch::writes.

Measured on

  • Hardware: AMD Ryzen 9 9950X3D, NVIDIA RTX 5090 32 GB, 62 GB RAM, Windows 11.
  • Settings: 1440p SDR, DLSS Quality, Frame Generation OFF, warm pipeline cache, x86-64-v3 fat-LTO build, identical 90 s intro sequence (VICTORY_KEYS=10:Enter,13:Enter), steady 3D seconds in DLSS frames 100..1800 (<80 ms).

A/B with stable V-Cache placement (eliminating dual-CCD migration noise) — MEASURED

Configuration Median ms (FPS) p95 ms victory-submit refreshes / steps GPU busy
Baseline (with CCD0 placement) 25.90 ms (38.6 fps) 32.10 ms 25.70 ms 7.80 / 12.50 ms 63%
+ This PR (run 1) 24.20 ms (41.3 fps) 31.20 ms 23.80 ms 6.80 / 11.30 ms 67%
+ This PR (run 2) 23.60 ms (42.4 fps) 30.35 ms 23.50 ms 6.80 / 11.15 ms 67%
Delta (avg of 2 runs) −2.00 ms (+8.3% FPS) −1.32 ms −2.05 ms −1.00 / −1.28 ms +4 pp

On pure main (63b902f) + PR 1 (post-warmup matched heavy street scene, ~3,300 draws): refreshes dropped from 7.25 ms → 6.40 ms (−11.7%) and steps from 10.95 ms → 10.10 ms, with indoor shots reaching 16.1 ms (62 fps, refreshes = 4.5 ms).

CI / Tests

  • cargo run --locked -p xtask -- policy: 294 files ok
  • cargo xwin clippy --locked -p victory-gpu --all-targets -- -D warnings: 0 warnings (and 0 warnings in touched files under --all-features)
  • Native Windows unit tests: victory-gpu (455 passed, 0 failed, including new unit tests watch::parts_tests::page_epochs_checks_single_and_multi_page_ranges and shadow::wide_tests::wide_each_scoped_visits_every_index_once_and_handles_nesting), victory-hle (188 passed, 0 failed)
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5540464870 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094). Originally posted by [Bazovsky](https://github.com/Bazovsky) on 2026-11-28T13:11:57Z. --- ## What is now true Eliminates lock contention, per-flush heap allocations, and redundant range cloning on the `victory-submit` critical path (no new user switches; preserves all existing `VICTORY_*` behavior): - **`watch.rs`:** - Adds a 3-level lock-free `PageEpochs` table (`WRITTEN_EPOCHS`, 128 TiB coverage, specialized single-page fast path, plain `Release` store under the exclusive `JOURNAL` write lock) mirroring `Journal::written`. - Adds lock-free `is_kept()` (mirroring `Journal::kept`), reusable `ahead_snapshot_into(&mut Vec<_>)`, and zero-lock `nothing_new_with` / zero-alloc `nothing_new_single`. - **`shadow.rs`:** - Replaces `Shadow::copied: Mutex<Vec<u64>>` and `ranged: Mutex<[(usize, usize, u64); 2]>` with `copy_lock: Mutex<()>` + `copied: Box<[AtomicU64]>` + SeqLock `ranged` + `pending_len: AtomicUsize` — shrinking `Shadow` while making `Shadow::nothing_new_with` completely lock-free on the common (no pending shader writes) path. - Adds zero-allocation, single-lock `wide_each_scoped` sharing `Workers::queue` (0 heap allocations vs ~21 in `wide_each`, 0 exit locks for non-last helpers, safe inline fallback if nested). - Replaces per-page `Mutex<Done>` allocations in `Shadow::merge_under_writes` with unique-index `Slots`. - Stores `Arc<Vec<(usize, usize)>>` in `SentRuns` and returns it from `card_dirty()`, avoiding cloning tens of thousands of dirty ranges per submission. - **`host.rs`, `host/send.rs`, `host/upcheck.rs`:** - Skips allocating `ranges` and locking `JOURNAL` in `ask_ahead` / `ask_ahead_done` when `watch::is_kept()` (`VICTORY_ASK_ONCE=1`) is already true. - Reuses `Batch::ahead_snap` across flushes, dispatches `refresh_front` / `flush_all` / `refresh_ahead` / `fill` / `refresh_textures` via `wide_each_scoped` (grain `1` after no-op filtering, grain `8` for large mixed flushes), and batches `FLUSHES[2]` atomic updates once per chunk instead of once per no-op. - **`land.rs`:** - Replaces per-item `state.lock()` in `land::Pool` with a lock-free `AtomicUsize` work counter (1 lock on batch entry/exit instead of 2 locks per item). ### Relation to open PRs Complements #126 (`VICTORY_WIDE_CHUNK`): rather than adding a chunk-size knob on top of the allocating `wide_each` + locked `nothing_new`, this removes the locks in `nothing_new` (`JOURNAL`, `Shadow::pending`/`copied`/`ranged`), removes per-flush heap allocations in `Workers`, and removes the `card_dirty` range clone and per-item `land::Pool` locking. Does not change `watch::writes` or the `guards` lock contention tracked in #795: this PR takes locks off unchanged-range `nothing_new` checks, the `Workers` / `land::Pool` dispatch loops, and `card_dirty` cloning, while guarded ranges that miss `nothing_new` still go through `watch::writes`. ## Measured on - **Hardware:** AMD Ryzen 9 9950X3D, NVIDIA RTX 5090 32 GB, 62 GB RAM, Windows 11. - **Settings:** 1440p SDR, DLSS Quality, Frame Generation OFF, warm pipeline cache, `x86-64-v3` fat-LTO build, identical 90 s intro sequence (`VICTORY_KEYS=10:Enter,13:Enter`), steady 3D seconds in DLSS frames 100..1800 (`<80 ms`). ### A/B with stable V-Cache placement (eliminating dual-CCD migration noise) — `MEASURED` | Configuration | Median ms (FPS) | p95 ms | `victory-submit` | `refreshes` / `steps` | GPU busy | |---|---:|---:|---:|---:|---:| | Baseline (with CCD0 placement) | 25.90 ms (38.6 fps) | 32.10 ms | 25.70 ms | 7.80 / 12.50 ms | 63% | | **+ This PR (run 1)** | **24.20 ms (41.3 fps)** | **31.20 ms** | **23.80 ms** | **6.80 / 11.30 ms** | **67%** | | **+ This PR (run 2)** | **23.60 ms (42.4 fps)** | **30.35 ms** | **23.50 ms** | **6.80 / 11.15 ms** | **67%** | | Delta (avg of 2 runs) | **−2.00 ms (+8.3% FPS)** | **−1.32 ms** | **−2.05 ms** | **−1.00 / −1.28 ms** | **+4 pp** | On pure `main` (`63b902f`) + PR 1 (post-warmup matched heavy street scene, ~3,300 draws): `refreshes` dropped from `7.25 ms → 6.40 ms` (−11.7%) and `steps` from `10.95 ms → 10.10 ms`, with indoor shots reaching `16.1 ms` (62 fps, `refreshes = 4.5 ms`). ## CI / Tests - `cargo run --locked -p xtask -- policy`: `294 files ok` - `cargo xwin clippy --locked -p victory-gpu --all-targets -- -D warnings`: 0 warnings (and 0 warnings in touched files under `--all-features`) - Native Windows unit tests: `victory-gpu` (`455 passed, 0 failed`, including new unit tests `watch::parts_tests::page_epochs_checks_single_and_multi_page_ranges` and `shadow::wide_tests::wide_each_scoped_visits_every_index_once_and_handles_nesting`), `victory-hle` (`188 passed, 0 failed`)
jptorres96 commented 2026-11-28 13:38:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jptorres96 on 2026-11-28T13:38:47Z.


Ran this on Windows at befdec4 (base 63b902f), since CI does not run on fork PRs until approved. Ryzen 5 5600X, RTX 4080 SUPER, Windows build 26300, rustc 1.98.1.

  • cargo test --locked -p victory-gpu --lib -- --test-threads=1: 455 passed, 0 failed, 37 ignored, including the new page_epochs_checks_single_and_multi_page_ranges.
  • cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings: clean in both builds once the pre-existing manual_is_multiple_of at descriptor.rs:1234 is allowed. The workspace-wide run stops on errors that are already on main (emit/mod.rs:2768, gameinput.rs:1372), none in files this PR touches.

Read through the lock-free parts. I found nothing wrong in:

  • PageEpochs against Journal::written: note is the only writer of written and nothing removes from it, so the mirror stays complete.
  • the single-page fast path, which gives the same answer as the old ranged != 0 || all taken check followed by the written scan;
  • pending_len, which is stored under pending's lock at all three mutation sites;
  • land::Pool's shared counter. running still fences one batch from the next, and the idle wakeup can't be lost in either order.

One nit, in the ranged SeqLock writer (shadow.rs ~4693). seq + 1 is stored with Release and then the slots with Relaxed. Release orders what comes before the store, so the slot stores may move ahead of the odd sequence number. The usual form is store(seq + 1, Relaxed); fence(Release); before the slot stores. On x86 the hardware keeps stores in order, so this only matters if the compiler reorders them, but it costs nothing.

On #795. I ran the synthetic probe from there (probe-795, cherry-picked on top of this PR, diagnostics build). It times watch::writes per range, which this PR doesn't change, and the numbers match main:

Guarded view, 8 threads main this PR
Summed per frame 115 ms 131 ms
Waiting for the guards' lock 73.9 ms 84.1 ms
Per range (summed) 92 us 105 us

This PR comes out about 14% higher, a little above the ~10% spread between runs on main. From a single run I wouldn't call that a regression. So this PR takes locks off the nothing_new checks and the pools. The contention in #795 is in asking guarded ranges, and it is still there. That isn't a flaw in the PR, but it may be worth saying in the description, since the two read alike.

Synthetic only: no game files.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7240083454 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7240083454). Originally posted by [jptorres96](https://github.com/jptorres96) on 2026-11-28T13:38:47Z. --- Ran this on Windows at `befdec4` (base `63b902f`), since CI does not run on fork PRs until approved. Ryzen 5 5600X, RTX 4080 SUPER, Windows build 26300, rustc 1.98.1. - `cargo test --locked -p victory-gpu --lib -- --test-threads=1`: 455 passed, 0 failed, 37 ignored, including the new `page_epochs_checks_single_and_multi_page_ranges`. - `cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warnings`: clean in both builds once the pre-existing `manual_is_multiple_of` at `descriptor.rs:1234` is allowed. The workspace-wide run stops on errors that are already on `main` (`emit/mod.rs:2768`, `gameinput.rs:1372`), none in files this PR touches. **Read through the lock-free parts.** I found nothing wrong in: - `PageEpochs` against `Journal::written`: `note` is the only writer of `written` and nothing removes from it, so the mirror stays complete. - the single-page fast path, which gives the same answer as the old `ranged != 0 || all taken` check followed by the `written` scan; - `pending_len`, which is stored under `pending`'s lock at all three mutation sites; - `land::Pool`'s shared counter. `running` still fences one batch from the next, and the `idle` wakeup can't be lost in either order. One nit, in the `ranged` SeqLock writer (`shadow.rs` ~4693). `seq + 1` is stored with `Release` and then the slots with `Relaxed`. `Release` orders what comes *before* the store, so the slot stores may move ahead of the odd sequence number. The usual form is `store(seq + 1, Relaxed); fence(Release);` before the slot stores. On x86 the hardware keeps stores in order, so this only matters if the compiler reorders them, but it costs nothing. **On #795.** I ran the synthetic probe from there ([`probe-795`](https://github.com/jptorres96/VIctory-NVIDIA/commit/3f9891d4772fab77d1c51f328c10e51e2c285f77), cherry-picked on top of this PR, diagnostics build). It times `watch::writes` per range, which this PR doesn't change, and the numbers match `main`: | Guarded view, 8 threads | `main` | this PR | | --- | ---: | ---: | | Summed per frame | 115 ms | 131 ms | | Waiting for the guards' lock | 73.9 ms | 84.1 ms | | Per range (summed) | 92 us | 105 us | This PR comes out about 14% higher, a little above the ~10% spread between runs on `main`. From a single run I wouldn't call that a regression. So this PR takes locks off the `nothing_new` checks and the pools. The contention in #795 is in asking guarded ranges, and it is still there. That isn't a flaw in the PR, but it may be worth saying in the description, since the two read alike. Synthetic only: no game files.
Bazovsky commented 2026-11-28 14:48:07 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bazovsky on 2026-11-28T14:48:07Z.


Thanks for testing this on Windows and auditing the lock-free paths, @jptorres96!

  • Pushed 4acfbbb switching the SeqLock writer in Shadow::copy_stale (shadow.rs) to self.ranged_seq.store(seq + 1, Ordering::Relaxed); std::sync::atomic::fence(Ordering::Release); before the slot stores, matching the standard writer-side barrier.
  • Updated the PR description to clarify that this PR does not touch watch::writes or the guards lock contention tracked in #795.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7240941297 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7240941297). Originally posted by [Bazovsky](https://github.com/Bazovsky) on 2026-11-28T14:48:07Z. --- Thanks for testing this on Windows and auditing the lock-free paths, @jptorres96! - Pushed `4acfbbb` switching the SeqLock writer in `Shadow::copy_stale` (`shadow.rs`) to `self.ranged_seq.store(seq + 1, Ordering::Relaxed); std::sync::atomic::fence(Ordering::Release);` before the slot stores, matching the standard writer-side barrier. - Updated the PR description to clarify that this PR does not touch `watch::writes` or the `guards` lock contention tracked in #795.
POMXARK commented 2026-11-28 14:58:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T14:58:19Z.


Tested this PR in a 20-minute 1440p DLSS Quality + MFG 4x A/B run on Ryzen 7 5700X (8C/16T) + RTX 5080 (16 GB) + 32 GB RAM (VICTORY_WAIT_RESIDENT=0, VICTORY_RELAY=2, VICTORY_CARD_STEPS=2, VICTORY_THIN=1, VICTORY_JOIN_COPIES=1, VICTORY_JOIN_PARTS=8, VICTORY_LAND_SKIP=1).

Integration Notes

  • Applied all 6 files (watch.rs 3-level PageEpochs, shadow.rs SeqLock ranged + zero-alloc wide_each_scoped + Slots<Done> + Arc card_dirty, land.rs lock-free Pool, host.rs/send.rs/upcheck.rs).
  • Retained two local refinements from our previous lock-free baseline:
    1. O(log n) binary search on sorted ahead ranges inside nothing_new_with/nothing_new_single.
    2. Publishing self.copied[idx].store(now, Ordering::Release) after self.take_all(runs) completes in Shadow::copy_stale (rather than before take_all) so a concurrent lock-free reader cannot observe now before the copy bytes land.

Unit Tests & Stability

  • cargo test -p victory-gpu --lib -- watch:: shadow:: land:: host:: --test-threads=4 (WARP): 219/219 PASS (3.17 s), including page_epochs_checks_single_and_multi_page_ranges and wide_each_scoped_visits_every_index_once_and_handles_nesting.
  • 20-minute continuous 3D workload: 0 errors, 0 DeviceRemoved/DEVICE_HUNG, 0 guest exceptions, 0 bake stalls, 0 GPU>=50ms, 0 F>=500ms, visually clean output throughout.

20-Minute A/B Results (vs prior lock-free JournalRead + wide_chunks(32) baseline)

Metric Baseline + PR #1094 Delta
ALL 3D FPS (p50 / mean) 13.9 / 13.91 14.7 / 14.04 +5.8% p50
ALL 3D Prep / copies (p50) 58.1 / 29.7 ms 53.2 / 24.2 ms -4.9 / -5.5 ms
submitting prep refreshes (p50 / p90) 22.6 / 42.5 ms 17.7 / 38.8 ms -4.9 ms (-21.7%) / -3.7 ms
submitting prep steps (p50) 31.1 ms 27.2 ms -3.9 ms (-12.5%)
1s frame_times (med / p95 / p99) 62.8 / 82.9 / 94.7 ms 62.0 / 81.5 / 94.8 ms -0.8 / -1.4 / +0.1 ms
1k–4k draws/frame (p50 / copies) 17.90 FPS / 18.3 ms 17.90 FPS / 15.4 ms -2.9 ms copies
4k–7k draws/frame (p50 / copies) 13.40 FPS / 29.9 ms 13.75 FPS / 25.5 ms +2.6% / -4.4 ms
7k–10k draws/frame (p50 / copies) 11.05 FPS / 40.2 ms 10.65 FPS / 39.8 ms -3.6% / -0.4 ms
>=10k draws/frame (p50 / mean) 8.00 / 8.34 FPS 12.20 / 11.24 FPS +52.5% / +34.8%

Takeaway: Clear, measurable win even on top of an already lock-free copied + JournalRead baseline — eliminating the per-chunk JOURNAL read lock, BTreeMap lookups, and wide() heap allocations cut refreshes by 4.9 ms (-21.7%) and pushed ALL 3D median from 13.9 to 14.7 FPS. Suggest moving self.copied[...].store(now, Release) after self.take_all(runs) in copy_stale for strict lock-free reader ordering.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7241083113 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7241083113). Originally posted by [POMXARK](https://github.com/POMXARK) on 2026-11-28T14:58:19Z. --- Tested this PR in a 20-minute 1440p DLSS Quality + MFG 4x A/B run on **Ryzen 7 5700X (8C/16T) + RTX 5080 (16 GB) + 32 GB RAM** (`VICTORY_WAIT_RESIDENT=0`, `VICTORY_RELAY=2`, `VICTORY_CARD_STEPS=2`, `VICTORY_THIN=1`, `VICTORY_JOIN_COPIES=1`, `VICTORY_JOIN_PARTS=8`, `VICTORY_LAND_SKIP=1`). ### Integration Notes - Applied all 6 files (`watch.rs` 3-level `PageEpochs`, `shadow.rs` SeqLock `ranged` + zero-alloc `wide_each_scoped` + `Slots<Done>` + `Arc` `card_dirty`, `land.rs` lock-free `Pool`, `host.rs`/`send.rs`/`upcheck.rs`). - Retained two local refinements from our previous lock-free baseline: 1. `O(log n)` binary search on sorted `ahead` ranges inside `nothing_new_with`/`nothing_new_single`. 2. Publishing `self.copied[idx].store(now, Ordering::Release)` **after** `self.take_all(runs)` completes in `Shadow::copy_stale` (rather than before `take_all`) so a concurrent lock-free reader cannot observe `now` before the copy bytes land. ### Unit Tests & Stability - `cargo test -p victory-gpu --lib -- watch:: shadow:: land:: host:: --test-threads=4` (WARP): **219/219 PASS** (`3.17 s`), including `page_epochs_checks_single_and_multi_page_ranges` and `wide_each_scoped_visits_every_index_once_and_handles_nesting`. - 20-minute continuous 3D workload: **0 errors**, **0 `DeviceRemoved`/`DEVICE_HUNG`**, **0 guest exceptions**, **0 bake stalls**, **0 `GPU>=50ms`**, **0 `F>=500ms`**, visually clean output throughout. ### 20-Minute A/B Results (vs prior lock-free `JournalRead` + `wide_chunks(32)` baseline) | Metric | Baseline | + PR #1094 | Delta | |---|---:|---:|---:| | `ALL 3D` FPS (p50 / mean) | 13.9 / 13.91 | **14.7 / 14.04** | **+5.8%** p50 | | `ALL 3D` Prep / `copies` (p50) | 58.1 / 29.7 ms | **53.2 / 24.2 ms** | **-4.9 / -5.5 ms** | | `submitting prep` `refreshes` (p50 / p90) | 22.6 / 42.5 ms | **17.7 / 38.8 ms** | **-4.9 ms (-21.7%) / -3.7 ms** | | `submitting prep` `steps` (p50) | 31.1 ms | **27.2 ms** | **-3.9 ms (-12.5%)** | | `1s frame_times` (med / p95 / p99) | 62.8 / 82.9 / 94.7 ms | **62.0 / 81.5 / 94.8 ms** | **-0.8 / -1.4 / +0.1 ms** | | `1k–4k` draws/frame (p50 / `copies`) | 17.90 FPS / 18.3 ms | 17.90 FPS / **15.4 ms** | **-2.9 ms copies** | | `4k–7k` draws/frame (p50 / `copies`) | 13.40 FPS / 29.9 ms | **13.75 FPS / 25.5 ms** | **+2.6% / -4.4 ms** | | `7k–10k` draws/frame (p50 / `copies`) | 11.05 FPS / 40.2 ms | 10.65 FPS / **39.8 ms** | -3.6% / -0.4 ms | | `>=10k` draws/frame (p50 / mean) | 8.00 / 8.34 FPS | **12.20 / 11.24 FPS** | **+52.5% / +34.8%** | **Takeaway:** Clear, measurable win even on top of an already lock-free `copied` + `JournalRead` baseline — eliminating the per-chunk `JOURNAL` read lock, `BTreeMap` lookups, and `wide()` heap allocations cut `refreshes` by **4.9 ms (-21.7%)** and pushed `ALL 3D` median from `13.9` to **`14.7 FPS`**. Suggest moving `self.copied[...].store(now, Release)` after `self.take_all(runs)` in `copy_stale` for strict lock-free reader ordering.
KruIN689 commented 2026-11-28 16:43:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KruIN689 on 2026-11-28T16:43:13Z.


In-game comparison, as #1138 asked ("not yet compared in the game").

Setup:

  • RTX 5080 (driver 621.24), 47 GB RAM, Windows 11. My own copy.
  • Release builds of 63b902f, and of this PR's head (4acfbbb, on 63b902f).
  • Series X, 1440p, DLSS Quality, frame generation off.
  • Each run loads the same save, enters the world through the menus with scripted keys (VICTORY_KEYS_FILE), then stands still for 4 minutes.
  • Runs alternated between the two builds. I took the medians of the log's frame lines with more than 2,500 draws, leaving out the first 30 s in the world.
run fps ms/frame preparing copies submitting thread: refreshes
63b902f #1 24.6 40.8 28.6 14.6 ms, 59 MB 12.6 ms
63b902f #2 23.9 41.8 30.2 15.0 ms, 63 MB 12.8 ms
63b902f #3 26.7 37.4 27.3 11.6 ms, 51 MB 10.3 ms
#1094 #1 21.6 46.5 31.5 15.5 ms, 71 MB 12.7 ms
#1094 #2 29.0 34.4 25.5 12.9 ms, 58 MB 10.5 ms
#1094 #3 23.7 42.1 30.1 12.2 ms, 53 MB 10.9 ms
mean 25.1 vs 24.8 28.7 vs 29.0 11.9 vs 11.4

No difference I can measure in the game. Run-to-run spread is about ±3 fps, even standing at the same spot: traffic and pedestrians change the bytes copied a frame (51–71 MB). So any effect of the size the synthetic benchmark found (−9 to −11% of no-op refresh time, about 1 ms here) is inside the noise. The refresh time on the submitting thread overlaps between the two builds.

No errors, no device removal, no hangs in the three runs with this PR.

Not tested: walking or driving (more refresh work per frame), other CPUs, and the other PRs on this path.

AI use: Claude Code (Claude Opus 5.5) built both, ran and scripted the sessions, read the logs, and drafted this comment. I read it before posting.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7242459428 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7242459428). Originally posted by [KruIN689](https://github.com/KruIN689) on 2026-11-28T16:43:13Z. --- In-game comparison, as #1138 asked ("not yet compared in the game"). **Setup:** - RTX 5080 (driver 621.24), 47 GB RAM, Windows 11. My own copy. - Release builds of `63b902f`, and of this PR's head (`4acfbbb`, on `63b902f`). - Series X, 1440p, DLSS Quality, frame generation off. - Each run loads the same save, enters the world through the menus with scripted keys (`VICTORY_KEYS_FILE`), then **stands still** for 4 minutes. - Runs alternated between the two builds. I took the medians of the log's frame lines with more than 2,500 draws, leaving out the first 30 s in the world. | run | fps | ms/frame | preparing | copies | submitting thread: refreshes | |---|---:|---:|---:|---:|---:| | `63b902f` #1 | 24.6 | 40.8 | 28.6 | 14.6 ms, 59 MB | 12.6 ms | | `63b902f` #2 | 23.9 | 41.8 | 30.2 | 15.0 ms, 63 MB | 12.8 ms | | `63b902f` #3 | 26.7 | 37.4 | 27.3 | 11.6 ms, 51 MB | 10.3 ms | | #1094 #1 | 21.6 | 46.5 | 31.5 | 15.5 ms, 71 MB | 12.7 ms | | #1094 #2 | 29.0 | 34.4 | 25.5 | 12.9 ms, 58 MB | 10.5 ms | | #1094 #3 | 23.7 | 42.1 | 30.1 | 12.2 ms, 53 MB | 10.9 ms | | **mean** | 25.1 vs **24.8** | | 28.7 vs **29.0** | | 11.9 vs **11.4** | **No difference I can measure in the game.** Run-to-run spread is about ±3 fps, even standing at the same spot: traffic and pedestrians change the bytes copied a frame (51–71 MB). So any effect of the size the synthetic benchmark found (−9 to −11% of no-op refresh time, about 1 ms here) is inside the noise. The refresh time on the submitting thread overlaps between the two builds. No errors, no device removal, no hangs in the three runs with this PR. Not tested: walking or driving (more refresh work per frame), other CPUs, and the other PRs on this path. AI use: Claude Code (Claude Opus 5.5) built both, ran and scripted the sessions, read the logs, and drafted this comment. I read it before posting.
hasekenmustafa-ctrl commented 2026-11-28 18:35:51 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by hasekenmustafa-ctrl on 2026-11-28T18:35:51Z.


I ported this onto a downstream branch based on 63b902f and looked at the ordering point POMXARK raised. The head (4acfbbb) still stores the stamp before the copy, and I think that is a real race.

The race, in Shadow::copy_stale:

  • self.copied[page - base].store(now, Ordering::Release) happens inside the page walk, before self.take_all(runs) copies that page.
  • nothing_new_with / nothing_new_single now read copied without copy_lock.
  • So a lock-free check on another thread can see the new stamp, call the page unchanged, and skip its refresh while the copy still holds the old bytes. The card then reads them.
  • Before this PR that couldn't happen: the reader took the copied mutex, and copy_stale held it through take_all.

Fix: collect the pages to stamp during the walk, and store them after take_all returns. take_all's helpers are joined through wide's mutex, so their writes happen-before the Release store.

        let mut again_at: Vec<(usize, u64)> = Vec::new();
+       // Stamps become `now` only once their bytes are in the copy (after
+       // `take_all`): `nothing_new_with` reads them without `copy_lock`.
+       let mut stamp: Vec<usize> = Vec::new();
        for page in from / PAGE..=last {
            ...
                if (page * PAGE).max(start) >= from && ((page + 1) * PAGE).min(end) <= to {
-                   self.copied[page - base].store(now, Ordering::Release);
+                   stamp.push(page - base);
                }
            ...
        }
        ...
        let bytes = self.take_all(runs);
+       for i in stamp {
+           self.copied[i].store(now, Ordering::Release);
+       }

That is the only store of a now stamp ahead of its bytes that I found. merge_under_writes and the publish path store after their bytes.

Measured in game, walking. Setup:

  • Ryzen 7 9800X3D (8 cores), RTX 5080, Windows 11. My own copy.
  • Release builds started through play-nvidia.ps1 defaults: Series X, 1440p, DLSS Quality, frame generation off.
  • Every run starts from the same save. VICTORY_KEYS_FILE drives the same 240 s walk after a 30 s settle.
  • 3 runs each build, alternating. Medians of frame lines with more than 2,500 draws.
base + this PR + the fix above
submitting thread: refreshes 8.32 ms 7.43 ms (−11 %); the per-run ranges 8.1–8.5 and 7.2–7.7 don't overlap
copies 10.1 ms 9.0 ms
preparing 21.6 ms 20.9 ms
fps 34.5 34.6

On this CPU the saving doesn't reach the frame. That fits KruIN689's standing runs on a 9950X3D and POMXARK's larger gain on a 5700X with ~58 ms preparing. There were 0 crashes and 0 device removals in about an hour with the change.

AI use: Claude Code (Claude Opus 5.5) did the port, the review of the ordering and the fix, drove and measured the runs, and wrote this comment.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7243911607 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7243911607). Originally posted by [hasekenmustafa-ctrl](https://github.com/hasekenmustafa-ctrl) on 2026-11-28T18:35:51Z. --- I ported this onto a downstream branch based on `63b902f` and looked at the ordering point POMXARK raised. The head (`4acfbbb`) still stores the stamp before the copy, and I think that is a real race. **The race, in `Shadow::copy_stale`:** - `self.copied[page - base].store(now, Ordering::Release)` happens inside the page walk, before `self.take_all(runs)` copies that page. - `nothing_new_with` / `nothing_new_single` now read `copied` without `copy_lock`. - So a lock-free check on another thread can see the new stamp, call the page unchanged, and skip its refresh while the copy still holds the old bytes. The card then reads them. - Before this PR that couldn't happen: the reader took the `copied` mutex, and `copy_stale` held it through `take_all`. **Fix:** collect the pages to stamp during the walk, and store them after `take_all` returns. `take_all`'s helpers are joined through `wide`'s mutex, so their writes happen-before the Release store. ```rust let mut again_at: Vec<(usize, u64)> = Vec::new(); + // Stamps become `now` only once their bytes are in the copy (after + // `take_all`): `nothing_new_with` reads them without `copy_lock`. + let mut stamp: Vec<usize> = Vec::new(); for page in from / PAGE..=last { ... if (page * PAGE).max(start) >= from && ((page + 1) * PAGE).min(end) <= to { - self.copied[page - base].store(now, Ordering::Release); + stamp.push(page - base); } ... } ... let bytes = self.take_all(runs); + for i in stamp { + self.copied[i].store(now, Ordering::Release); + } ``` That is the only store of a `now` stamp ahead of its bytes that I found. `merge_under_writes` and the publish path store after their bytes. **Measured in game, walking.** Setup: - Ryzen 7 9800X3D (8 cores), RTX 5080, Windows 11. My own copy. - Release builds started through `play-nvidia.ps1` defaults: Series X, 1440p, DLSS Quality, frame generation off. - Every run starts from the same save. `VICTORY_KEYS_FILE` drives the same 240 s walk after a 30 s settle. - 3 runs each build, alternating. Medians of frame lines with more than 2,500 draws. | | base | + this PR + the fix above | |---|---:|---:| | submitting thread: refreshes | 8.32 ms | **7.43 ms (−11 %)**; the per-run ranges 8.1–8.5 and 7.2–7.7 don't overlap | | copies | 10.1 ms | 9.0 ms | | preparing | 21.6 ms | 20.9 ms | | fps | 34.5 | 34.6 | On this CPU the saving doesn't reach the frame. That fits KruIN689's standing runs on a 9950X3D and POMXARK's larger gain on a 5700X with ~58 ms preparing. There were 0 crashes and 0 device removals in about an hour with the change. AI use: Claude Code (Claude Opus 5.5) did the port, the review of the ordering and the fix, drove and measured the runs, and wrote this comment.
Bazovsky commented 2026-11-28 18:39:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bazovsky on 2026-11-28T18:39:39Z.


Thanks @POMXARK, @hasekenmustafa-ctrl, and @KruIN689 for auditing the ordering and running in-game A/B tests across different CPUs!

Fix pushed (be4e568)

  • Deferred self.copied[i].store(now, Ordering::Release) in Shadow::copy_stale (shadow.rs) until after self.take_all(runs) returns, collecting whole-page indices in stamp: Vec<usize> during the walk. Because take_all's wide_each joins through workers.queue's mutex before returning, all worker writes happen-before the Release store, which synchronizes with lock-free Acquire loads in nothing_new_with / nothing_new_single.
  • Re-audited the other two self.copied writers (merge_under_writes and landed) — both already publish after bytes are in place.
  • Re-verified on Windows after be4e568:
    • cargo run --locked -p xtask -- policy: 294 files ok
    • cargo xwin clippy --locked -p victory-gpu --all-targets (default & --all-features): 0 warnings (with -A clippy::manual-is-multiple-of)
    • Native Windows unit tests (victory-gpu --lib): 455 passed, 0 failed

Extended measurements & composability (Ryzen 9 9950X3D + RTX 5090, 1440p SDR DLSS Quality, FG OFF)

All runs below use identical 90 s warm-cache intro sequences (VICTORY_KEYS=10:Enter,13:Enter), steady 3D seconds in DLSS frames 100..1800 (<80 ms), with CCD0 V-Cache placement from #1093 active to eliminate cross-CCD jitter:

Configuration Median ms (FPS) p95 ms Submit thr Prep total ref / steps Thin trans CPU-sum GPU busy max DLSS (90 s)
main (63b902f, CACHE_CORES=0) 34.20 ms (29.2 fps) 43.10 ms 34.10 ms 32.80 ms 8.40 / 13.60 ms 163.7 ms 53% 1,612
Baseline + #1093 (CCD0 + submit core) 25.90 ms (38.6 fps) 32.10 ms 25.70 ms 25.00 ms 7.80 / 12.50 ms 115.2 ms 63% 1,878
+ #1094 (P2d_DEBLOAT) 24.20 ms (41.3 fps) 31.20 ms 23.80 ms 22.70 ms 6.80 / 11.30 ms 110.6 ms 67% 1,936
+ #1094 (P2d_ZNVER5) 24.10 ms (41.5 fps) 31.90 ms 24.70 ms 23.80 ms 7.30 / 11.90 ms 101.2 ms 68% 1,930
+ Follow-up downstream stack (sorted ahead + 64-stripe merging + AVX2 word_runs + L0 write-back HostList::scratch) 23.65 ms (42.3 fps) 32.75 ms 23.40 ms 22.80 ms 6.75 / 11.00 ms 101.9 ms 68% 1,949

Across all independent measurements so far, the refreshes CPU saving is consistent and scales with how CPU-bound the submission thread is:

  • Ryzen 7 5700X (@POMXARK): refreshes 22.6 → 17.7 ms (−21.7%), ALL 3D p50 +5.8%, >=10k draws +52.5%
  • Ryzen 7 9800X3D (@hasekenmustafa-ctrl, walking): refreshes 8.32 → 7.43 ms (−11%), copies 10.1 → 9.0 ms, preparing 21.6 → 20.9 ms
  • Ryzen 9 9950X3D (ours, with #1093 CCD0 placement): refreshes 7.80 → 6.80 ms (−12.8%), Prep 25.00 → 22.70 ms, frame median 25.90 → 24.20 ms (+7.0%)
  • Standing still (@KruIN689): refreshes mean 11.9 → 11.4 ms, within ±3 fps traffic/pedestrian spread

0 crashes and 0 device removals across 15+ full runs with #1094 active.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7243959868 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7243959868). Originally posted by [Bazovsky](https://github.com/Bazovsky) on 2026-11-28T18:39:39Z. --- Thanks @POMXARK, @hasekenmustafa-ctrl, and @KruIN689 for auditing the ordering and running in-game A/B tests across different CPUs! ### Fix pushed (`be4e568`) - Deferred `self.copied[i].store(now, Ordering::Release)` in `Shadow::copy_stale` (`shadow.rs`) until after `self.take_all(runs)` returns, collecting whole-page indices in `stamp: Vec<usize>` during the walk. Because `take_all`'s `wide_each` joins through `workers.queue`'s mutex before returning, all worker writes happen-before the `Release` store, which synchronizes with lock-free `Acquire` loads in `nothing_new_with` / `nothing_new_single`. - Re-audited the other two `self.copied` writers (`merge_under_writes` and `landed`) — both already publish after bytes are in place. - Re-verified on Windows after `be4e568`: - `cargo run --locked -p xtask -- policy`: `294 files ok` - `cargo xwin clippy --locked -p victory-gpu --all-targets` (default & `--all-features`): 0 warnings (with `-A clippy::manual-is-multiple-of`) - Native Windows unit tests (`victory-gpu --lib`): **455 passed, 0 failed** ### Extended measurements & composability (Ryzen 9 9950X3D + RTX 5090, 1440p SDR DLSS Quality, FG OFF) All runs below use identical 90 s warm-cache intro sequences (`VICTORY_KEYS=10:Enter,13:Enter`), steady 3D seconds in DLSS frames `100..1800` (`<80 ms`), with CCD0 V-Cache placement from #1093 active to eliminate cross-CCD jitter: | Configuration | Median ms (FPS) | p95 ms | `Submit thr` | `Prep total` | `ref` / `steps` | `Thin trans` CPU-sum | GPU busy | `max DLSS` (90 s) | |---|---:|---:|---:|---:|---:|---:|---:|---:| | `main` (`63b902f`, `CACHE_CORES=0`) | 34.20 ms (29.2 fps) | 43.10 ms | 34.10 ms | 32.80 ms | 8.40 / 13.60 ms | 163.7 ms | 53% | 1,612 | | Baseline + #1093 (CCD0 + submit core) | 25.90 ms (38.6 fps) | 32.10 ms | 25.70 ms | 25.00 ms | 7.80 / 12.50 ms | 115.2 ms | 63% | 1,878 | | **+ #1094 (`P2d_DEBLOAT`)** | **24.20 ms (41.3 fps)** | **31.20 ms** | **23.80 ms** | **22.70 ms** | **6.80 / 11.30 ms** | **110.6 ms** | **67%** | **1,936** | | **+ #1094 (`P2d_ZNVER5`)** | **24.10 ms (41.5 fps)** | **31.90 ms** | **24.70 ms** | **23.80 ms** | **7.30 / 11.90 ms** | **101.2 ms** | **68%** | **1,930** | | + Follow-up downstream stack (sorted `ahead` + 64-stripe `merging` + AVX2 `word_runs` + L0 write-back `HostList::scratch`) | **23.65 ms (42.3 fps)** | **32.75 ms** | **23.40 ms** | **22.80 ms** | **6.75 / 11.00 ms** | **101.9 ms** | **68%** | **1,949** | Across all independent measurements so far, the `refreshes` CPU saving is consistent and scales with how CPU-bound the submission thread is: - **Ryzen 7 5700X (@POMXARK):** `refreshes` `22.6 → 17.7 ms (−21.7%)`, `ALL 3D` p50 `+5.8%`, `>=10k` draws `+52.5%` - **Ryzen 7 9800X3D (@hasekenmustafa-ctrl, walking):** `refreshes` `8.32 → 7.43 ms (−11%)`, `copies` `10.1 → 9.0 ms`, `preparing` `21.6 → 20.9 ms` - **Ryzen 9 9950X3D (ours, with #1093 CCD0 placement):** `refreshes` `7.80 → 6.80 ms (−12.8%)`, `Prep` `25.00 → 22.70 ms`, frame median `25.90 → 24.20 ms (+7.0%)` - **Standing still (@KruIN689):** `refreshes` mean `11.9 → 11.4 ms`, within ±3 fps traffic/pedestrian spread 0 crashes and 0 device removals across 15+ full runs with #1094 active.
Rafa7046 commented 2026-11-28 19:22:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Rafa7046 on 2026-11-28T19:22:20Z.


Measured on a scripted run, RT off, main at e7d8150 with only this PR merged.

Setup: Ryzen 9 9950X3D, RTX 5080, Series X, 1440p, DLSS Performance, frame generation off. The script plays the prologue cutscenes, then stands one minute on Jason's boat. Four sessions of plain main ran the same afternoon, interleaved with the others.

Median fps Cutscenes Boat Submitting thread preparing (boat)
main, 4 sessions 37.8 / 36.2 / 36.3 / 35.6 53.4 / 51.2 / 50.0 / 51.5 38.7 / 36.0 / 37.9 / 36.1 19.6 / 21.2 / 19.2 / 20.2 ms
#1094, 2 sessions 38.3 / 38.4 54.3 / 53.0 39.6 / 39.6 18.0 / 18.9 ms

Both sessions are above all four references on median and boat fps, and below them on preparing time. That is about +1.9 fps median and +2.4 fps on the boat (+6%).

It was the only one of the thread/refresh PRs I measured this way that came out above the references. Each of the others, alone on the same main, stayed inside the references' spread or below it:

#1093 is in its own thread.

Measurements prepared with an AI assistant (Claude Code); the runs were played on my machine.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244494339 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7244494339). Originally posted by [Rafa7046](https://github.com/Rafa7046) on 2026-11-28T19:22:20Z. --- Measured on a scripted run, RT off, `main` at `e7d8150` with only this PR merged. **Setup:** Ryzen 9 9950X3D, RTX 5080, Series X, 1440p, DLSS Performance, frame generation off. The script plays the prologue cutscenes, then stands one minute on Jason's boat. Four sessions of plain `main` ran the same afternoon, interleaved with the others. | | Median fps | Cutscenes | Boat | Submitting thread preparing (boat) | |---|---:|---:|---:|---:| | `main`, 4 sessions | 37.8 / 36.2 / 36.3 / 35.6 | 53.4 / 51.2 / 50.0 / 51.5 | 38.7 / 36.0 / 37.9 / 36.1 | 19.6 / 21.2 / 19.2 / 20.2 ms | | #1094, 2 sessions | **38.3 / 38.4** | 54.3 / 53.0 | **39.6 / 39.6** | **18.0 / 18.9 ms** | Both sessions are above all four references on median and boat fps, and below them on preparing time. That is about +1.9 fps median and +2.4 fps on the boat (+6%). It was the only one of the thread/refresh PRs I measured this way that came out above the references. Each of the others, alone on the same `main`, stayed inside the references' spread or below it: - #1133 + #1134, #697, #933, #516, #1014; - #126 with `VICTORY_WIDE_CHUNK=8`: 32.6 fps on the boat, clearly worse. #1093 is in its own thread. Measurements prepared with an AI assistant (Claude Code); the runs were played on my machine.
trustno1-coder commented 2026-11-28 19:22:34 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244497171 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1094#issuecomment-7244497171). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T19:22:34Z. --- 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

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