watch: move guard/alias VirtualProtect outside GUARDS mutex and batch Bits/publish #3760

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

@⁠ScymicX on GitHub · 2026-11-30 06:10 UTC · original
ScymicX:perf/watch-unlocked-protect-and-batch-bits → main · +727 −17 · 1 files · 3 commits · closed without merging

What it changes

guard() previously held the global GUARDS mutex across all VirtualProtect, elsewhere, uncommitted_end, and aliased-view protect_alias calls, stalling concurrent refresh worker threads and any locked write-fault path behind OS page-table walks. In addition, writes_with allocated a Vec<usize> and updated PUBLISHED page by page on every guarded refresh.

This PR moves both primary and aliased-view VirtualProtect calls outside GUARDS and batches Bits / PUBLISHED updates per 64-block word (enabled by default; VICTORY_WATCH_UNLOCKED_PROTECT=0 falls back to the existing guard + publish path):

  • Concurrency & lock ordering (PROTECT_GATE + PROTECTING):
    • Strict lock order: MAPPING -> Asking -> PROTECT_GATE -> GUARDS -> OPENED.
    • guard_with_pub / protect_unlocked hold PROTECT_GATE.read() while running elsewhere, uncommitted_end, and VirtualProtect outside GUARDS; mutators (title_memory_allocated, look_at_holes, writing, kernel_writing, title_memory_written, views_mapped, title_memory_splitting, title_memory_remapped, title_memory_unmapping, title_memory_freed, title_memory_made_real) take PROTECT_GATE.write().
    • soft_runs(...) is read under GUARDS before dropping the lock so concurrent title_memory_made_real cannot be missed.
    • PROTECTING marks in-flight primary and alias blocks before dropping GUARDS (with RAII ClearProtecting / ClearProtectingSlice guards). Fault handlers (on_write, opened_for_writing, came_back) spin briefly on wait_protecting, and open_unlocked returns false if PROTECTING is set so racing faults take the safe locked/settled path.
    • If a block is opened concurrently while GUARDS is released, restore_rw reverts its protection; for aliased blocks, pending_clean re-verifies all all_others (g.protected, g.aliased, !failed_aliases, !OPENING, !PROTECTING || alias_to_vp_set, !BESIDE, !unsettled) before marking a block clean.
  • Word-batched bitmaps & publish:
    • Bits::{ensure_piece, set_word, clear_word, set_all} and word-level Blocks::{insert_all, diff_into}.
    • Hoisted BESIDE/OPENING/TOLD/PROTECTING piece lookups and cached g.protected/g.clean/now_instant in guard_with_pub.
    • publish_pairs avoids the Vec<usize> allocation in writes_with and updates PUBLISHED per 64-block word, only called when guard_with_pub reports any_publishable.

How it was tested

  • GPU and profile: NVIDIA GeForce RTX 5070 Ti, Xbox Series X, 1440p, DLSS Balanced, frame generation off (v2026.11.28.01 baseline).
  • Before: With alias VirtualProtect running inside GUARDS, guard: GUARDS mutex wait summed across worker threads reached 18.51 ms/frame.
  • After: Moving primary and alias VirtualProtect outside GUARDS + batching Bits/publish_pairs reduced guard: GUARDS mutex wait to ~2.8 ms/frame.
  • cargo test passed for the crates it touches: yes
    • cargo test --locked -p victory-gpu --lib watch:: -- --test-threads=1: 65 passed, 0 failed.
    • cargo test --locked -p victory-gpu --lib watch::many_askers_tests: 10 passed, 0 failed (default ON) and 10 passed, 0 failed (VICTORY_WATCH_UNLOCKED_PROTECT=0).
    • Race stress test watch::many_askers_tests::no_write_to_resting_views_is_lost_between_askers: 30 consecutive runs, 0 failures (runs=30 fails=0).
    • cargo clippy -p victory-gpu --no-deps --all-targets --locked and --all-features: 0 warnings in touched/new code.
    • cargo xtask policy --staged: passed.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2655, #2814 (merged fault-spin backoff, preserved), #3268, #3502, #3604. Complementary to our separate PRs #3753 (shadow.rs landing bitmap) and #3756 (watch.rs lock-free WRITTEN_EPOCHS journal).
**@⁠ScymicX** on GitHub · 2026-11-30 06:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760) `ScymicX:perf/watch-unlocked-protect-and-batch-bits` → `main` · +727 −17 · 1 files · 3 commits · closed without merging ## What it changes `guard()` previously held the global `GUARDS` mutex across all `VirtualProtect`, `elsewhere`, `uncommitted_end`, and aliased-view `protect_alias` calls, stalling concurrent refresh worker threads and any locked write-fault path behind OS page-table walks. In addition, `writes_with` allocated a `Vec<usize>` and updated `PUBLISHED` page by page on every guarded refresh. This PR moves both primary and aliased-view `VirtualProtect` calls outside `GUARDS` and batches `Bits` / `PUBLISHED` updates per 64-block word (enabled by default; `VICTORY_WATCH_UNLOCKED_PROTECT=0` falls back to the existing `guard` + `publish` path): - **Concurrency & lock ordering (`PROTECT_GATE` + `PROTECTING`)**: - Strict lock order: `MAPPING -> Asking -> PROTECT_GATE -> GUARDS -> OPENED`. - `guard_with_pub` / `protect_unlocked` hold `PROTECT_GATE.read()` while running `elsewhere`, `uncommitted_end`, and `VirtualProtect` outside `GUARDS`; mutators (`title_memory_allocated`, `look_at_holes`, `writing`, `kernel_writing`, `title_memory_written`, `views_mapped`, `title_memory_splitting`, `title_memory_remapped`, `title_memory_unmapping`, `title_memory_freed`, `title_memory_made_real`) take `PROTECT_GATE.write()`. - `soft_runs(...)` is read under `GUARDS` before dropping the lock so concurrent `title_memory_made_real` cannot be missed. - `PROTECTING` marks in-flight primary and alias blocks before dropping `GUARDS` (with RAII `ClearProtecting` / `ClearProtectingSlice` guards). Fault handlers (`on_write`, `opened_for_writing`, `came_back`) spin briefly on `wait_protecting`, and `open_unlocked` returns `false` if `PROTECTING` is set so racing faults take the safe locked/settled path. - If a block is opened concurrently while `GUARDS` is released, `restore_rw` reverts its protection; for aliased blocks, `pending_clean` re-verifies all `all_others` (`g.protected`, `g.aliased`, `!failed_aliases`, `!OPENING`, `!PROTECTING || alias_to_vp_set`, `!BESIDE`, `!unsettled`) before marking a block `clean`. - **Word-batched bitmaps & publish**: - `Bits::{ensure_piece, set_word, clear_word, set_all}` and word-level `Blocks::{insert_all, diff_into}`. - Hoisted `BESIDE`/`OPENING`/`TOLD`/`PROTECTING` piece lookups and cached `g.protected`/`g.clean`/`now_instant` in `guard_with_pub`. - `publish_pairs` avoids the `Vec<usize>` allocation in `writes_with` and updates `PUBLISHED` per 64-block word, only called when `guard_with_pub` reports `any_publishable`. ## How it was tested - **GPU and profile**: NVIDIA GeForce RTX 5070 Ti, Xbox Series X, 1440p, DLSS Balanced, frame generation off (`v2026.11.28.01` baseline). - **Before**: With alias `VirtualProtect` running inside `GUARDS`, `guard: GUARDS mutex wait` summed across worker threads reached **18.51 ms/frame**. - **After**: Moving primary and alias `VirtualProtect` outside `GUARDS` + batching `Bits`/`publish_pairs` reduced `guard: GUARDS mutex wait` to **~2.8 ms/frame**. - `cargo test` passed for the crates it touches: **yes** - `cargo test --locked -p victory-gpu --lib watch:: -- --test-threads=1`: **65 passed, 0 failed**. - `cargo test --locked -p victory-gpu --lib watch::many_askers_tests`: **10 passed, 0 failed** (default ON) and **10 passed, 0 failed** (`VICTORY_WATCH_UNLOCKED_PROTECT=0`). - Race stress test `watch::many_askers_tests::no_write_to_resting_views_is_lost_between_askers`: **30 consecutive runs, 0 failures** (`runs=30 fails=0`). - `cargo clippy -p victory-gpu --no-deps --all-targets --locked` and `--all-features`: 0 warnings in touched/new code. - `cargo xtask policy --staged`: passed. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2655, #2814 (merged fault-spin backoff, preserved), #3268, #3502, #3604. Complementary to our separate PRs #3753 (`shadow.rs` landing bitmap) and #3756 (`watch.rs` lock-free `WRITTEN_EPOCHS` journal).
Reduce GUARDS mutex contention during concurrent refresh workers and
title write faults by moving VirtualProtect (both primary block runs and
aliased views) outside the GUARDS mutex, and batch Bits / PUBLISHED
updates per 64-block word (VICTORY_WATCH_UNLOCKED_PROTECT=0 disables).

- Add PROTECT_GATE (RwLock) and PROTECTING bitset (strict lock order:
  MAPPING -> Asking -> PROTECT_GATE -> GUARDS -> OPENED) so guard_with_pub
  / protect_unlocked run VirtualProtect, elsewhere, and uncommitted_end
  under shared read access while mutators (unmap/free/remap/split/open)
  take exclusive write access and fault handlers spin briefly on
  wait_protecting.
- Pre-mark PROTECTING/PROTECTED/g.protected before releasing GUARDS,
  protect primary runs via protect_unlocked, then protect aliased views
  outside GUARDS with RAII ClearProtectingSlice and full all_others
  re-verification before inserting into g.clean.
- Add word-batched Bits::{set_word, clear_word, set_all},
  Blocks::{insert_all, diff_into}, and publish_pairs to eliminate
  per-page PUBLISHED atomics and Vec allocations in writes_with.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 06:13:37 +00:00
Author
Owner

@⁠Yoruiopz on GitHub · 2026-11-30 09:42 UTC · original · edited 2026-11-30 10:15 UTC

I reproduced an ownership regression on exact head 2789218a. In open_unlocked, OPENING.swap_on returns true when another fault already owns the bit. The combined early-return branch then clears that other opener's bit. A guard or a third fault can observe the still-active opening as idle. This branch is shared by both VICTORY_WATCH_UNLOCKED_PROTECT settings.

The asset-free Windows fixture holds the first opener's claim on a real allocated block, exercises the competing fault entry, and checks that the first claim survives. It failed on the unmodified production logic and passed with this two-check correction. The correction leaves an existing claim alone and clears only a claim taken by the current caller when PROTECTING requires fallback.

All 66 watch tests passed with VICTORY_WATCH_UNLOCKED_PROTECT=1 and again with 0.

Preliminary in-game comparison

I built the exact PR head plus the small ownership correction as a single locked Windows diagnostics executable. Same RTX 5070 Laptop, copied porch checkpoint, warm cache, Series S with DLSS Ultra Performance and frame generation off. Only VICTORY_WATCH_UNLOCKED_PROTECT changed.

I used three corresponding host reports around 17–28 seconds after the world entered, with roughly 5,200 draws per frame in both modes. These numbers are medians of those reports.

Mode Rendered FPS CPU prepare Copy time Aggregate GUARDS wait across host threads
0 20.2 39.3 ms 22.0 ms 48.74 ms/frame
1 22.9 33.5 ms 16.1 ms 5.21 ms/frame

The enabled session lost Windows foreground shortly after two screenshots confirmed the expected porch pose, so the longer camera-qualified comparison and frame-time percentiles are incomplete. Both modes still show the separately tracked porch arm artifact. The aggregate lock time measures worker contention and is separate from wall-clock frame time.

Series X with 2x DLSS FG

I tested the corrected guard code on the same .05 base with the explicit 1080p startup fix and #3811, using one Windows diagnostics executable. Both processes used the same copied save, warmed cache, DLSS Performance (960×540 to 1920×1080), 2x DLSS frame generation, and the 15 rendered FPS cap. VICTORY_AB was clear. Only VICTORY_WATCH_UNLOCKED_PROTECT changed.

Foreground was polled for the duration. The enabled attempt lost focus after 15.46 seconds, so I compared an interior 14-second interval before that loss to the same world time in the disabled run. The initial screenshots matched the same porch pose. Both windows contain 210 rendered-frame intervals, with median draws 5,787 and 5,750. A later complete enabled window advanced to a much heavier scene and is excluded.

Measurement Disabled Enabled
Native cadence 15.0 FPS 15.0 FPS
Native frame p95 75.2 ms about 69.7 ms
Native frame p99 98.6 ms 98.4 ms
CPU preparation (host reports) 35.1 ms 33.1 ms
Aggregate GUARDS wait 60.7 ms/frame 12.8 ms/frame
DLSS plugin shown rate 30.0 FPS 29.6 FPS

The enabled p95 is 68.3–70.9 ms using either endpoint for the CSV clock alignment. The shown rate uses complete plugin reporting intervals, not individual display-frame timings. This supports lower guard contention in a second profile. The short matched window shows modest improvement at the cap and leaves steadiness under higher load unverified.

Protection protocol mode

The diagnostics toggle currently allows VICTORY_AB to switch which protection implementation and which publication path writes_with chooses. The legacy and unlocked implementations use the same protection bookkeeping, and the legacy path does not honor PROTECTING during an unlocked protection change. A live flip can therefore mix protocols across workers, or within one call if its two flag reads differ. The performance cases above explicitly clear VICTORY_AB and set the mode before each process.

I isolated the setting at first use in a follow-up commit. Default-on and exact =0 behavior stay the same. The regression launches fresh child processes with VICTORY_AB targeting this switch and checks unset, =0, and =1. The old selector failed the extracted regression. The integrated Windows regression and all 70 watch tests passed in both fresh switch modes after correction.

**@⁠Yoruiopz** on GitHub · 2026-11-30 09:42 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7274583638) · edited 2026-11-30 10:15 UTC I reproduced an ownership regression on exact head 2789218a. In open_unlocked, OPENING.swap_on returns true when another fault already owns the bit. The combined early-return branch then clears that other opener's bit. A guard or a third fault can observe the still-active opening as idle. This branch is shared by both VICTORY_WATCH_UNLOCKED_PROTECT settings. The asset-free Windows fixture holds the first opener's claim on a real allocated block, exercises the competing fault entry, and checks that the first claim survives. It failed on the unmodified production logic and passed with [this two-check correction](https://github.com/Yoruiopz/VIctory-NVIDIA/commit/0677bc050380cfea0190124b9498fb4a070b7518). The correction leaves an existing claim alone and clears only a claim taken by the current caller when PROTECTING requires fallback. All 66 watch tests passed with VICTORY_WATCH_UNLOCKED_PROTECT=1 and again with 0. ### Preliminary in-game comparison I built the exact PR head plus the small ownership correction as a single locked Windows diagnostics executable. Same RTX 5070 Laptop, copied porch checkpoint, warm cache, Series S with DLSS Ultra Performance and frame generation off. Only VICTORY_WATCH_UNLOCKED_PROTECT changed. I used three corresponding host reports around 17–28 seconds after the world entered, with roughly 5,200 draws per frame in both modes. These numbers are medians of those reports. | Mode | Rendered FPS | CPU prepare | Copy time | Aggregate GUARDS wait across host threads | | --- | ---: | ---: | ---: | ---: | | 0 | 20.2 | 39.3 ms | 22.0 ms | 48.74 ms/frame | | 1 | 22.9 | 33.5 ms | 16.1 ms | 5.21 ms/frame | The enabled session lost Windows foreground shortly after two screenshots confirmed the expected porch pose, so the longer camera-qualified comparison and frame-time percentiles are incomplete. Both modes still show the separately tracked porch arm artifact. The aggregate lock time measures worker contention and is separate from wall-clock frame time. ### Series X with 2x DLSS FG I tested the corrected guard code on the same .05 base with the explicit 1080p startup fix and #3811, using one Windows diagnostics executable. Both processes used the same copied save, warmed cache, DLSS Performance (960×540 to 1920×1080), 2x DLSS frame generation, and the 15 rendered FPS cap. VICTORY_AB was clear. Only VICTORY_WATCH_UNLOCKED_PROTECT changed. Foreground was polled for the duration. The enabled attempt lost focus after 15.46 seconds, so I compared an interior 14-second interval before that loss to the same world time in the disabled run. The initial screenshots matched the same porch pose. Both windows contain 210 rendered-frame intervals, with median draws 5,787 and 5,750. A later complete enabled window advanced to a much heavier scene and is excluded. | Measurement | Disabled | Enabled | | --- | ---: | ---: | | Native cadence | 15.0 FPS | 15.0 FPS | | Native frame p95 | 75.2 ms | about 69.7 ms | | Native frame p99 | 98.6 ms | 98.4 ms | | CPU preparation (host reports) | 35.1 ms | 33.1 ms | | Aggregate GUARDS wait | 60.7 ms/frame | 12.8 ms/frame | | DLSS plugin shown rate | 30.0 FPS | 29.6 FPS | The enabled p95 is 68.3–70.9 ms using either endpoint for the CSV clock alignment. The shown rate uses complete plugin reporting intervals, not individual display-frame timings. This supports lower guard contention in a second profile. The short matched window shows modest improvement at the cap and leaves steadiness under higher load unverified. ### Protection protocol mode The diagnostics toggle currently allows VICTORY_AB to switch which protection implementation and which publication path writes_with chooses. The legacy and unlocked implementations use the same protection bookkeeping, and the legacy path does not honor PROTECTING during an unlocked protection change. A live flip can therefore mix protocols across workers, or within one call if its two flag reads differ. The performance cases above explicitly clear VICTORY_AB and set the mode before each process. I isolated the setting at first use in [a follow-up commit](https://github.com/Yoruiopz/VIctory-NVIDIA/commit/bec76b4f8b876f2621cb22b847b67807094f54b6). Default-on and exact =0 behavior stay the same. The regression launches fresh child processes with VICTORY_AB targeting this switch and checks unset, =0, and =1. The old selector failed the extracted regression. The integrated Windows regression and all 70 watch tests passed in both fresh switch modes after correction.
Author
Owner

@⁠ihyajb on GitHub · 2026-11-30 11:27 UTC · original

Whole-process stalls of 2.2–2.7 s with this PR (busy-wait in wait_protecting)

Tested this PR merged with ten other open PRs (#3733, #3850, #3832, #3848, #3750, #3753, #3705, #3694, #3762, #3726) on 41adb551, diagnostics build, Series S profile, DLSS + FG, 5-minute standing runs from one save.

  • With VICTORY_WATCH_UNLOCKED_PROTECT on (default): a single frame of 2.2–2.7 s every 2–4 minutes, in all 4 runs.
  • Same build, only VICTORY_WATCH_UNLOCKED_PROTECT=0: none (worst frame 163 ms).
  • Stock 41adb551 (3 runs): none (worst 499 ms).

A sampling profiler with per-round timestamps took 3–7 samples during each long frame instead of ~250, so its own thread was stalled too: the whole process stops, not one waiting thread.

Likely cause: wait_protecting (called from the write-fault handler on the title's threads) is a pure spin_loop(). When several title threads fault on a block in PROTECTING, they can occupy every core while the helper whose VirtualProtect clears the bit doesn't get scheduled, until Windows' starvation boost runs it. I didn't catch a stack inside a stall (the profiler couldn't sample), so this is inferred. But changing only this loop to spin briefly, then yield_now(), then sleep(200µs) removed the stalls in 2 runs (worst 153 / 142 ms), with no change in frame rate:

fn wait_protecting(block: usize) {
    let mut tries = 0u32;
    while PROTECTING.any(block, block + 1) {
        if tries < 256 {
            std::hint::spin_loop();
        } else if tries < 320 {
            std::thread::yield_now();
        } else {
            std::thread::sleep(std::time::Duration::from_micros(200));
        }
        tries = tries.saturating_add(1);
    }
}

cargo test -p victory-gpu --lib watch::: 66 passed. One or two runs per configuration, so the numbers are indicative rather than statistical.

Found with Claude Code.

**@⁠ihyajb** on GitHub · 2026-11-30 11:27 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7277056727) **Whole-process stalls of 2.2–2.7 s with this PR (busy-wait in `wait_protecting`)** Tested this PR merged with ten other open PRs (#3733, #3850, #3832, #3848, #3750, #3753, #3705, #3694, #3762, #3726) on 41adb551, diagnostics build, Series S profile, DLSS + FG, 5-minute standing runs from one save. - With `VICTORY_WATCH_UNLOCKED_PROTECT` on (default): a single frame of 2.2–2.7 s every 2–4 minutes, in all 4 runs. - Same build, only `VICTORY_WATCH_UNLOCKED_PROTECT=0`: none (worst frame 163 ms). - Stock 41adb551 (3 runs): none (worst 499 ms). A sampling profiler with per-round timestamps took 3–7 samples during each long frame instead of ~250, so its own thread was stalled too: the whole process stops, not one waiting thread. Likely cause: `wait_protecting` (called from the write-fault handler on the title's threads) is a pure `spin_loop()`. When several title threads fault on a block in `PROTECTING`, they can occupy every core while the helper whose `VirtualProtect` clears the bit doesn't get scheduled, until Windows' starvation boost runs it. I didn't catch a stack inside a stall (the profiler couldn't sample), so this is inferred. But changing only this loop to spin briefly, then `yield_now()`, then `sleep(200µs)` removed the stalls in 2 runs (worst 153 / 142 ms), with no change in frame rate: ```rust fn wait_protecting(block: usize) { let mut tries = 0u32; while PROTECTING.any(block, block + 1) { if tries < 256 { std::hint::spin_loop(); } else if tries < 320 { std::thread::yield_now(); } else { std::thread::sleep(std::time::Duration::from_micros(200)); } tries = tries.saturating_add(1); } } ``` `cargo test -p victory-gpu --lib watch::`: 66 passed. One or two runs per configuration, so the numbers are indicative rather than statistical. Found with Claude Code.
Address review findings on #3760:
- Split open_unlocked's OPENING.swap_on(block) and PROTECTING.any(...)
  checks so a competing fault does not clear another opener's OPENING bit.
- Add spin/yield/sleep backoff to wait_protecting to prevent whole-process
  starvation stalls when multiple title threads fault on a PROTECTING block.
- Read VICTORY_WATCH_UNLOCKED_PROTECT once via OnceLock instead of
  toggled! so VICTORY_AB cannot mix legacy and unlocked protocols mid-run.
- Add regression test watch::tests::open_unlocked_preserves_existing_opening_claim.
Author
Owner

@⁠ScymicX on GitHub · 2026-11-30 13:43 UTC · original

Thank you @⁠Yoruiopz and @⁠ihyajb for catching those issues — all three fixes are now pushed in 8bdc117:

  1. open_unlocked OPENING ownership (@Yoruiopz): Split OPENING.swap_on(block) from PROTECTING.any(block, block + 1) so a competing fault returns false without clearing another opener's OPENING bit; only a caller that claimed OPENING itself clears it on PROTECTING fallback.
  2. wait_protecting backoff (@ihyajb): Replaced the pure spin_loop() with bounded spin (< 256) -> thread::yield_now() (< 320) -> thread::sleep(200µs) to avoid thread-starvation stalls when multiple title threads fault on a PROTECTING block.
  3. Process-start OnceLock (@Yoruiopz): unlocked_protect() now caches VICTORY_WATCH_UNLOCKED_PROTECT via OnceLock at first read instead of crate::toggled!, so VICTORY_AB cannot mix legacy and unlocked protocols mid-run.
  4. Regression test: Added watch::tests::open_unlocked_preserves_existing_opening_claim covering both the competing-claim preservation and the PROTECTING fallback clear.

Verified locally on 8bdc117:

  • cargo test --locked -p victory-gpu --lib watch:: -- --test-threads=1: 66 passed, 0 failed (default ON) and 66 passed, 0 failed (VICTORY_WATCH_UNLOCKED_PROTECT=0).
  • cargo test --locked -p victory-gpu --lib watch::many_askers_tests: 10 passed, 0 failed + 20 consecutive runs of no_write_to_resting_views_is_lost_between_askers (runs=20 fails=0).
  • cargo clippy -p victory-gpu --no-deps --all-targets --locked (+ --all-features): 0 warnings in touched/new code; cargo xtask policy --staged: passed.
**@⁠ScymicX** on GitHub · 2026-11-30 13:43 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7280264787) Thank you @⁠Yoruiopz and @⁠ihyajb for catching those issues — all three fixes are now pushed in `8bdc117`: 1. **`open_unlocked` `OPENING` ownership (`@Yoruiopz`)**: Split `OPENING.swap_on(block)` from `PROTECTING.any(block, block + 1)` so a competing fault returns `false` without clearing another opener's `OPENING` bit; only a caller that claimed `OPENING` itself clears it on `PROTECTING` fallback. 2. **`wait_protecting` backoff (`@ihyajb`)**: Replaced the pure `spin_loop()` with bounded spin (`< 256`) -> `thread::yield_now()` (`< 320`) -> `thread::sleep(200µs)` to avoid thread-starvation stalls when multiple title threads fault on a `PROTECTING` block. 3. **Process-start `OnceLock` (`@Yoruiopz`)**: `unlocked_protect()` now caches `VICTORY_WATCH_UNLOCKED_PROTECT` via `OnceLock` at first read instead of `crate::toggled!`, so `VICTORY_AB` cannot mix legacy and unlocked protocols mid-run. 4. **Regression test**: Added `watch::tests::open_unlocked_preserves_existing_opening_claim` covering both the competing-claim preservation and the `PROTECTING` fallback clear. Verified locally on `8bdc117`: - `cargo test --locked -p victory-gpu --lib watch:: -- --test-threads=1`: **66 passed, 0 failed** (default ON) and **66 passed, 0 failed** (`VICTORY_WATCH_UNLOCKED_PROTECT=0`). - `cargo test --locked -p victory-gpu --lib watch::many_askers_tests`: **10 passed, 0 failed** + 20 consecutive runs of `no_write_to_resting_views_is_lost_between_askers` (`runs=20 fails=0`). - `cargo clippy -p victory-gpu --no-deps --all-targets --locked` (+ `--all-features`): 0 warnings in touched/new code; `cargo xtask policy --staged`: passed.
Author
Owner

@⁠mstrmoos on GitHub · 2026-11-30 19:22 UTC · original

Picked onto our branch with #3753, #3756, #3760, #3881, #3832, #3858 and four that have since merged (#3818, #3850, #3874, #3871). #3760 needed a hand merge on top of the others.

All of victory-gpu's and victory-shader's tests passed. On the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run, the frame median went from 40.4 to 39.1 ms for the whole set. I didn't measure the PRs one by one, so this is evidence of no regression rather than this PR's own gain. Screenshots looked clean.

**@⁠mstrmoos** on GitHub · 2026-11-30 19:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7289290093) Picked onto our branch with #3753, #3756, #3760, #3881, #3832, #3858 and four that have since merged (#3818, #3850, #3874, #3871). #3760 needed a hand merge on top of the others. All of victory-gpu's and victory-shader's tests passed. On the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run, the frame median went from 40.4 to 39.1 ms for the whole set. I didn't measure the PRs one by one, so this is evidence of no regression rather than this PR's own gain. Screenshots looked clean.
Author
Owner

@⁠paales on GitHub · 2026-11-30 23:09 UTC · original

Written by 🤖:

In-game numbers for this PR. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Scene: a story save that loads into a mission cutscene in the city, the interview skipped at 35 s into a montage of quick cuts; 82 s from the first scene frame.

I applied only this PR's watch.rs change (8bdc117b and 2789218a against main) onto my build (main 84bd61e2 with #3918, #1727, #3553, #3043, #4207, #4138, #720 and the write-watch part of #2647). One conflict, in writes_with: the allocation-free kernel_written_into of #2647 kept, and guard_with_pub or guard chosen by unlocked_protect() as in this PR.

A profile of the submitting thread in the montage without this PR (a sampler that stops the thread only to copy its stack, about 3 % of the time) had 13 % of it waiting in watch::waited under watch::guards (from guard and publish_range). With the PR, one run each:

without with this PR
the submitting thread, first 35 s 25.7 ms 37.7 ms
the submitting thread, montage 29.9 ms 28.4 ms
frames per second, first 35 s / montage 29.4 / 26.7 27.6 / 26.6
seconds with a frame over 100 ms 14 17
the longest frame 266 ms 3,372 ms

Within the spread of single runs on this PC, except the first 35 s, which were slower. I did not take it into my build.

**@⁠paales** on GitHub · 2026-11-30 23:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7294786426) _Written by 🤖:_ In-game numbers for this PR. PC: RTX 5070 Ti 16 GB, Ryzen 9 5900X, 32 GB, Windows 11. Series X, 1440p, DLSS Performance, frame generation off, 30 fps cap. Scene: a story save that loads into a mission cutscene in the city, the interview skipped at 35 s into a montage of quick cuts; 82 s from the first scene frame. I applied only this PR's `watch.rs` change (8bdc117b and 2789218a against `main`) onto my build (`main` 84bd61e2 with #3918, #1727, #3553, #3043, #4207, #4138, #720 and the write-watch part of #2647). One conflict, in `writes_with`: the allocation-free `kernel_written_into` of #2647 kept, and `guard_with_pub` or `guard` chosen by `unlocked_protect()` as in this PR. A profile of the submitting thread in the montage without this PR (a sampler that stops the thread only to copy its stack, about 3 % of the time) had 13 % of it waiting in `watch::waited` under `watch::guards` (from `guard` and `publish_range`). With the PR, one run each: | | without | with this PR | | --- | --- | --- | | the submitting thread, first 35 s | 25.7 ms | 37.7 ms | | the submitting thread, montage | 29.9 ms | 28.4 ms | | frames per second, first 35 s / montage | 29.4 / 26.7 | 27.6 / 26.6 | | seconds with a frame over 100 ms | 14 | 17 | | the longest frame | 266 ms | 3,372 ms | Within the spread of single runs on this PC, except the first 35 s, which were slower. I did not take it into my build.
Author
Owner

@⁠upipibi on GitHub · 2026-12-01 00:35 UTC · original · edited 2026-12-01 04:40 UTC

Edited 2026-12-01 01:43Z: the cause below is now traced and a fix tested. The window I first suggested (the OPENING/PROTECTING order) was wrong: changing that order didn't help (7 of 14 runs still died). I've replaced that part.

Race review of #3760 at c3470bdb (with 8bdc117): with VICTORY_WATCH_UNLOCKED_PROTECT on (the default), a title write to view memory can crash the process with 0xc0000005. This happens in release builds too. It never happened with the switch off or on main. A 4-line change to the fault handler stops it (below).

Test. One 16 MiB view of a section is used, set up as the many-askers tests do. Four threads guard all of it with writes(at, end, true) in a loop, as refreshes do. 48 threads write random pages of it for 20 s, faulting on guarded blocks. One more thread calls writing() before a store. All of this is CPU-only: no GPU, no game files.

the test (in many_askers_tests, #[ignore], run with REVIEW_WRITERS=48)
#[test]
#[ignore = "review stress, run by hand"]
fn review_title_side_waits_while_refreshes_guard() {
    use std::sync::atomic::{AtomicBool, AtomicU64, Ordering::Relaxed};
    use std::time::{Duration, Instant};
    let _one = crate::watch::one_view_test();
    const PAGES: usize = 256;
    let env = |k: &str, d: u64| std::env::var(k).ok().and_then(|v| v.parse().ok()).unwrap_or(d);
    let writers_n = env("REVIEW_WRITERS", 8) as usize;
    let secs = env("REVIEW_SECS", 20);
    // SAFETY: a view of a section of our own.
    let at = unsafe {
        let section = CreateFileMappingW(-1isize as _, std::ptr::null(), PAGE_READWRITE, 0, (PAGES * PAGE) as u32, std::ptr::null());
        crate::title_memory_section(section as usize, (PAGES * PAGE) as u64, true);
        let at = MapViewOfFile(section, FILE_MAP_WRITE, 0, 0, PAGES * PAGE).Value as usize;
        assert!(at != 0 && at.is_multiple_of(PAGE));
        super::title_memory_remapped(at, PAGES * PAGE);
        crate::title_memory_view(at, PAGES * PAGE, section as usize, 0);
        at
    };
    let end = at + PAGES * PAGE;
    let stop = AtomicBool::new(false);
    let worst = [const { AtomicU64::new(0) }; 3];
    let note = |i: usize, d: Duration| {
        worst[i].fetch_max(d.as_micros() as u64, Relaxed);
    };
    std::thread::scope(|s| {
        for _ in 0..4 {
            let (stop, note) = (&stop, &note);
            s.spawn(move || {
                while !stop.load(Relaxed) {
                    let t = Instant::now();
                    let _ = writes(at, end, true);
                    note(2, t.elapsed());
                }
            });
        }
        {
            let (stop, note) = (&stop, &note);
            s.spawn(move || {
                let mut k = 0usize;
                while !stop.load(Relaxed) {
                    k = (k * 7 + 3) % PAGES;
                    let t = Instant::now();
                    super::writing(at + k * PAGE, PAGE);
                    note(1, t.elapsed());
                    // SAFETY: committed memory of ours.
                    unsafe { ((at + k * PAGE + 4096) as *mut u64).write_volatile(k as u64) };
                    std::thread::sleep(Duration::from_micros(200));
                }
            });
        }
        let writers: Vec<_> = (0..writers_n)
            .map(|t| {
                let note = &note;
                s.spawn(move || {
                    let mut seed = t as u64 * 7919 + 1;
                    let until = Instant::now() + Duration::from_secs(secs);
                    while Instant::now() < until {
                        seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
                        let page = (seed >> 33) as usize % PAGES;
                        let t0 = Instant::now();
                        // SAFETY: committed memory of ours.
                        unsafe { ((at + page * PAGE + t * 8) as *mut u64).write_volatile(1) };
                        note(0, t0.elapsed());
                    }
                })
            })
            .collect();
        for w in writers {
            w.join().unwrap();
        }
        stop.store(true, Relaxed);
    });
    println!("worst_us: title_write={} writing={} guarded_ask={}", worst[0].load(Relaxed), worst[1].load(Relaxed), worst[2].load(Relaxed));
    super::title_memory_unmapping(at, PAGES * PAGE);
}

Results. This PR was merged onto main 7d93ee07 (clean merge). Ryzen 9 5950X (16 cores, 32 threads), Windows 11. Faults take no lock in all runs (VICTORY_FAULT_UNLOCKED default).

build writer threads runs process died with 0xc0000005
main 7d93ee07, same test, debug 48 5 0
this PR, =0, debug 48 3 0
this PR, =1 (default), debug 48 14 8
this PR, =1, release 48 8 2
this PR, =1, 8 writer threads, debug 8 3 0
this PR + the change below, =1, release 48 14 0
this PR + the change below, =1, debug 48 14 0

With the change, watch:: still passes: 70 passed, 0 failed, three runs with =1 and one with =0. In the runs that finished, the worst single wait for a title write was lower with =1 (18–37 ms) than with =0 or on main (36–117 ms). So the gain this PR is after does show up here.

The cause (traced). I added a temporary lock-free ring of per-block events (marked, made read-only, opened, settled, clean, fault, give-up) and dumped the failing block's history when the handler gave up.

At the give-up, the books say the block is open while the page is PAGE_READONLY:

before_open: g.protected=false PROTECTED=false clean=false protect=0x2 OPENING=false OPEN_DONE=false

The give-up falls inside another thread's guard of the same block: after it marked the block (g.protected, PROTECTING) and its VirtualProtect(PAGE_READONLY) outside GUARDS had landed, and before it marked the block clean.

The faulting thread's last look has two steps that aren't one moment. First it finds nothing to open under the lock, because the books still had the block open (another fault opened it and was settled). Then it asks writable(at) after letting go of the lock, for example in came_back (watch.rs:4824, open(&mut guards(), at, at + 1) != 0 || writable(at)). A guard that marks the block and protects it between those two steps leaves both answers "no", so the handler returns EXCEPTION_CONTINUE_SEARCH.

main has the same two steps (came_back, watch.rs:4145 there). There, though, the guard's whole change of protection happens inside the lock and is short. With this PR, four guards make their protection changes concurrently, outside the lock, and the window is hit easily.

A change that holds here. Count the guards taken outside the lock. A write fault that is about to give up makes the write again if a guard began since it faulted; the next fault then finds the block guarded and opens it:

--- a/crates/victory-gpu/src/watch.rs
+++ b/crates/victory-gpu/src/watch.rs
@@ -2034,4 +2034,10 @@
 static PROTECTING: Bits = Bits::new();
 
+/// Counts the guards taken outside `GUARDS`; a
+/// write fault that is about to give up retries the write instead if one
+/// began since it faulted (its look at the books and at the page were then
+/// not of the same moment).
+static GUARD_GEN: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
+
 #[inline]
 fn wait_protecting(block: usize) {
@@ -3585,4 +3591,5 @@
         g.protected.insert_all(from..to);
     }
+    GUARD_GEN.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
     drop(g);
     let prepared = protect_unlocked(&to_protect, &to_cover, &soft);
@@ -5277,4 +5284,5 @@
         let at = r.ExceptionInformation[1];
         let block = at / BLOCK;
+        let gen0 = GUARD_GEN.load(std::sync::atomic::Ordering::SeqCst);
         wait_protecting(block);
         // Descriptor heap hooks: the hooked view heap is written through its hooks
@@ -5398,4 +5406,5 @@
             Some(exit) => fail(exit),
             None if came_back(at, true) => EXCEPTION_CONTINUE_EXECUTION,
+            None if GUARD_GEN.load(std::sync::atomic::Ordering::SeqCst) != gen0 => EXCEPTION_CONTINUE_EXECUTION,
             None => EXCEPTION_CONTINUE_SEARCH,
         }

That's 0 of 28 runs against 10 of 22 without it. It only adds a retry on a path that otherwise ends the process. If a page were read-only for some other reason, the write would be retried only while guards keep beginning, then give up as before. The author may prefer to close the gap in came_back and the tries themselves, for example by looking at the page while holding the lock and with no guard in flight.

Not tested: the game, and aliased views (the test uses one view).

Update (2026-12-01): the fix is now a pull request into this branch, ScymicX/VIctory-NVIDIA#1. It adds the stress test (ignored by default) and the retry, bounded by the existing again(at, 8), so a page that is read-only for another reason still faults out after eight tries. Merged onto main 5fabb46e, release: 4 of 8 runs crashed without it, 0 of 14 with it.

Tested with the help of Claude Code (Claude Opus 5.5).

**@⁠upipibi** on GitHub · 2026-12-01 00:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7296510517) · edited 2026-12-01 04:40 UTC *Edited 2026-12-01 01:43Z: the cause below is now traced and a fix tested. The window I first suggested (the `OPENING`/`PROTECTING` order) was wrong: changing that order didn't help (7 of 14 runs still died). I've replaced that part.* Race review of #3760 at c3470bdb (with 8bdc117): **with `VICTORY_WATCH_UNLOCKED_PROTECT` on (the default), a title write to view memory can crash the process with 0xc0000005**. This happens in release builds too. It never happened with the switch off or on `main`. A 4-line change to the fault handler stops it (below). **Test.** One 16 MiB view of a section is used, set up as the many-askers tests do. Four threads guard all of it with `writes(at, end, true)` in a loop, as refreshes do. 48 threads write random pages of it for 20 s, faulting on guarded blocks. One more thread calls `writing()` before a store. All of this is CPU-only: no GPU, no game files. <details><summary>the test (in <code>many_askers_tests</code>, <code>#[ignore]</code>, run with <code>REVIEW_WRITERS=48</code>)</summary> ```rust #[test] #[ignore = "review stress, run by hand"] fn review_title_side_waits_while_refreshes_guard() { use std::sync::atomic::{AtomicBool, AtomicU64, Ordering::Relaxed}; use std::time::{Duration, Instant}; let _one = crate::watch::one_view_test(); const PAGES: usize = 256; let env = |k: &str, d: u64| std::env::var(k).ok().and_then(|v| v.parse().ok()).unwrap_or(d); let writers_n = env("REVIEW_WRITERS", 8) as usize; let secs = env("REVIEW_SECS", 20); // SAFETY: a view of a section of our own. let at = unsafe { let section = CreateFileMappingW(-1isize as _, std::ptr::null(), PAGE_READWRITE, 0, (PAGES * PAGE) as u32, std::ptr::null()); crate::title_memory_section(section as usize, (PAGES * PAGE) as u64, true); let at = MapViewOfFile(section, FILE_MAP_WRITE, 0, 0, PAGES * PAGE).Value as usize; assert!(at != 0 && at.is_multiple_of(PAGE)); super::title_memory_remapped(at, PAGES * PAGE); crate::title_memory_view(at, PAGES * PAGE, section as usize, 0); at }; let end = at + PAGES * PAGE; let stop = AtomicBool::new(false); let worst = [const { AtomicU64::new(0) }; 3]; let note = |i: usize, d: Duration| { worst[i].fetch_max(d.as_micros() as u64, Relaxed); }; std::thread::scope(|s| { for _ in 0..4 { let (stop, note) = (&stop, &note); s.spawn(move || { while !stop.load(Relaxed) { let t = Instant::now(); let _ = writes(at, end, true); note(2, t.elapsed()); } }); } { let (stop, note) = (&stop, &note); s.spawn(move || { let mut k = 0usize; while !stop.load(Relaxed) { k = (k * 7 + 3) % PAGES; let t = Instant::now(); super::writing(at + k * PAGE, PAGE); note(1, t.elapsed()); // SAFETY: committed memory of ours. unsafe { ((at + k * PAGE + 4096) as *mut u64).write_volatile(k as u64) }; std::thread::sleep(Duration::from_micros(200)); } }); } let writers: Vec<_> = (0..writers_n) .map(|t| { let note = &note; s.spawn(move || { let mut seed = t as u64 * 7919 + 1; let until = Instant::now() + Duration::from_secs(secs); while Instant::now() < until { seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407); let page = (seed >> 33) as usize % PAGES; let t0 = Instant::now(); // SAFETY: committed memory of ours. unsafe { ((at + page * PAGE + t * 8) as *mut u64).write_volatile(1) }; note(0, t0.elapsed()); } }) }) .collect(); for w in writers { w.join().unwrap(); } stop.store(true, Relaxed); }); println!("worst_us: title_write={} writing={} guarded_ask={}", worst[0].load(Relaxed), worst[1].load(Relaxed), worst[2].load(Relaxed)); super::title_memory_unmapping(at, PAGES * PAGE); } ``` </details> **Results.** This PR was merged onto `main` 7d93ee07 (clean merge). Ryzen 9 5950X (16 cores, 32 threads), Windows 11. Faults take no lock in all runs (`VICTORY_FAULT_UNLOCKED` default). | build | writer threads | runs | process died with 0xc0000005 | |---|---|---|---| | `main` 7d93ee07, same test, debug | 48 | 5 | 0 | | this PR, `=0`, debug | 48 | 3 | 0 | | this PR, `=1` (default), debug | 48 | 14 | **8** | | this PR, `=1`, release | 48 | 8 | **2** | | this PR, `=1`, 8 writer threads, debug | 8 | 3 | 0 | | this PR + the change below, `=1`, release | 48 | 14 | 0 | | this PR + the change below, `=1`, debug | 48 | 14 | 0 | With the change, `watch::` still passes: 70 passed, 0 failed, three runs with `=1` and one with `=0`. In the runs that finished, the worst single wait for a title write was lower with `=1` (18–37 ms) than with `=0` or on `main` (36–117 ms). So the gain this PR is after does show up here. **The cause (traced).** I added a temporary lock-free ring of per-block events (marked, made read-only, opened, settled, clean, fault, give-up) and dumped the failing block's history when the handler gave up. At the give-up, the books say the block is open while the page is `PAGE_READONLY`: ``` before_open: g.protected=false PROTECTED=false clean=false protect=0x2 OPENING=false OPEN_DONE=false ``` The give-up falls inside another thread's guard of the same block: after it marked the block (`g.protected`, `PROTECTING`) and its `VirtualProtect(PAGE_READONLY)` outside `GUARDS` had landed, and before it marked the block clean. The faulting thread's last look has two steps that aren't one moment. First it finds nothing to open under the lock, because the books still had the block open (another fault opened it and was settled). Then it asks `writable(at)` after letting go of the lock, for example in `came_back` (watch.rs:4824, `open(&mut guards(), at, at + 1) != 0 || writable(at)`). A guard that marks the block and protects it between those two steps leaves both answers "no", so the handler returns `EXCEPTION_CONTINUE_SEARCH`. `main` has the same two steps (`came_back`, watch.rs:4145 there). There, though, the guard's whole change of protection happens inside the lock and is short. With this PR, four guards make their protection changes concurrently, outside the lock, and the window is hit easily. **A change that holds here.** Count the guards taken outside the lock. A write fault that is about to give up makes the write again if a guard began since it faulted; the next fault then finds the block guarded and opens it: ```diff --- a/crates/victory-gpu/src/watch.rs +++ b/crates/victory-gpu/src/watch.rs @@ -2034,4 +2034,10 @@ static PROTECTING: Bits = Bits::new(); +/// Counts the guards taken outside `GUARDS`; a +/// write fault that is about to give up retries the write instead if one +/// began since it faulted (its look at the books and at the page were then +/// not of the same moment). +static GUARD_GEN: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + #[inline] fn wait_protecting(block: usize) { @@ -3585,4 +3591,5 @@ g.protected.insert_all(from..to); } + GUARD_GEN.fetch_add(1, std::sync::atomic::Ordering::SeqCst); drop(g); let prepared = protect_unlocked(&to_protect, &to_cover, &soft); @@ -5277,4 +5284,5 @@ let at = r.ExceptionInformation[1]; let block = at / BLOCK; + let gen0 = GUARD_GEN.load(std::sync::atomic::Ordering::SeqCst); wait_protecting(block); // Descriptor heap hooks: the hooked view heap is written through its hooks @@ -5398,4 +5406,5 @@ Some(exit) => fail(exit), None if came_back(at, true) => EXCEPTION_CONTINUE_EXECUTION, + None if GUARD_GEN.load(std::sync::atomic::Ordering::SeqCst) != gen0 => EXCEPTION_CONTINUE_EXECUTION, None => EXCEPTION_CONTINUE_SEARCH, } ``` That's 0 of 28 runs against 10 of 22 without it. It only adds a retry on a path that otherwise ends the process. If a page were read-only for some other reason, the write would be retried only while guards keep beginning, then give up as before. The author may prefer to close the gap in `came_back` and the tries themselves, for example by looking at the page while holding the lock and with no guard in flight. Not tested: the game, and aliased views (the test uses one view). **Update (2026-12-01):** the fix is now a pull request into this branch, ScymicX/VIctory-NVIDIA#1. It adds the stress test (ignored by default) and the retry, bounded by the existing `again(at, 8)`, so a page that is read-only for another reason still faults out after eight tries. Merged onto `main` 5fabb46e, release: 4 of 8 runs crashed without it, 0 of 14 with it. *Tested with the help of Claude Code (Claude Opus 5.5).*
Author
Owner

@⁠Lyrnc on GitHub · 2026-12-01 15:24 UTC · original

Tested on our bench. It cuts the submitting thread's refreshes by about 2.5 ms a frame at the same scene load, and the frame time follows by up to about 1 ms in most of the walk.

Setup

  • RTX 5080 16 GB, Ryzen 7 9800X3D (8 cores, 16 threads), 32 GB, Windows 11. Series X profile, 2560x1440, DLSS Quality, frame generation off, ray tracing off.
  • Release builds: main 5fabb46e, and main + this PR (head c3470bdb merged locally; clean merge, watch.rs only). Same shader cache for both.
  • One fixed 5-minute walk, sent as keys from the moment the world shows, 420 s a run. Two runs per build, alternating with main and with #4877 (tested in the same rounds, comment there). Medians of the per-second lines over world+30..330 s.
  • The walk's path drifts after about 3 minutes, so the runs do not show the same scene (median draws a frame 6.9k-8.7k). The second table compares the 5-second windows at matched draws.

Medians per run

main 1 main 2 #3760 1 #3760 2
fps (frame times) 26.7 27.6 30.0 28.8
frame time p50 / p95 / p99 (ms) 35.4 / 61.5 / 75.4 35.3 / 59.9 / 71.1 32.3 / 54.6 / 68.0 32.6 / 55.1 / 69.9
frames over 50 ms, per 1,000 137 147 80 82
draws a frame 8,665 8,230 6,869 7,580
submitting thread worked (ms) 34.2 33.0 30.9 30.9
its submissions ("preparing") 32.0 30.8 28.9 28.9
of them refreshes 12.5 12.0 9.5 9.4
the title's threads waited at presents 2.5 2.7 1.6 1.7

At matched load (both runs of each build, medians of the 5-second windows in each band of draws a frame)

draws a frame frame ms main / #3760 refreshes main / #3760 submissions main / #3760
3,000-6,000 30.9 / 30.4 10.6 / 8.6 28.3 / 27.0
6,000-8,000 34.6 / 32.3 11.7 / 9.1 30.6 / 28.5
8,000-10,000 37.1 / 37.3 12.7 / 10.1 32.0 / 31.1
10,000-13,000 39.1 / 38.7 12.8 / 10.4 32.1 / 30.6

What it shows

  • The refreshes drop by 2.0 to 2.6 ms a frame in every band, and the submitting thread works 1.4 to 2.1 ms less.
  • Frame time drops by up to 2.3 ms in the 6,000-8,000 band, and stays within about 0.5 ms elsewhere. On this walk, the title's threads wait only 2.5-2.7 ms a frame at presents for the submitting thread on main, so that's about the most a submitting-thread cut can give back here. With this PR the wait is 1.6-2.1 ms.
  • Why we looked here: on a diagnostics build of main, same walk, the refreshes in front of a submission took 10.3 ms of the submitting thread's time a frame. That was about 1,040 changed spans a frame, 46 ms of thread time over the 7 refreshing threads, and all threads waited about 36 ms a frame for the guards' lock (69 ms on a camera turn).
  • No crash or device removal in the 4 runs; each has the same one Streamline error line early on, main's too. We didn't check the picture closely: release builds, no captures.
  • Outside load: the OS card budget stayed at 15.2 GB in all 4 runs; the PC was paging lightly (page-ins 300-2,100 a second, median), most in the first main run.

Checks

  • cargo test --locked --release -p victory-gpu --lib -- watch:: on main + this PR: 70 passed, 0 failed.
  • Note: the description still mentions publish_pairs. After the merge c3470bdb, the head calls main's publish_range, and publish_pairs is not in the tree.

Not tested: a camera turn (queued, results to follow only if they differ), ray tracing on, frame generation on, Series S, other scenes, other CPUs.

AI use: Claude Code (our agent) ran the builds, the bench and the tests, and wrote this; the numbers are from those runs.

**@⁠Lyrnc** on GitHub · 2026-12-01 15:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7315850650) Tested on our bench. It cuts the submitting thread's refreshes by about 2.5 ms a frame at the same scene load, and the frame time follows by up to about 1 ms in most of the walk. **Setup** - RTX 5080 16 GB, Ryzen 7 9800X3D (8 cores, 16 threads), 32 GB, Windows 11. Series X profile, 2560x1440, DLSS Quality, frame generation off, ray tracing off. - Release builds: `main` 5fabb46e, and `main` + this PR (head c3470bdb merged locally; clean merge, `watch.rs` only). Same shader cache for both. - One fixed 5-minute walk, sent as keys from the moment the world shows, 420 s a run. Two runs per build, alternating with `main` and with #4877 (tested in the same rounds, comment there). Medians of the per-second lines over world+30..330 s. - The walk's path drifts after about 3 minutes, so the runs do not show the same scene (median draws a frame 6.9k-8.7k). The second table compares the 5-second windows at matched draws. **Medians per run** | | main 1 | main 2 | #3760 1 | #3760 2 | |---|---:|---:|---:|---:| | fps (frame times) | 26.7 | 27.6 | 30.0 | 28.8 | | frame time p50 / p95 / p99 (ms) | 35.4 / 61.5 / 75.4 | 35.3 / 59.9 / 71.1 | 32.3 / 54.6 / 68.0 | 32.6 / 55.1 / 69.9 | | frames over 50 ms, per 1,000 | 137 | 147 | 80 | 82 | | draws a frame | 8,665 | 8,230 | 6,869 | 7,580 | | submitting thread worked (ms) | 34.2 | 33.0 | 30.9 | 30.9 | | its submissions ("preparing") | 32.0 | 30.8 | 28.9 | 28.9 | | of them refreshes | 12.5 | 12.0 | 9.5 | 9.4 | | the title's threads waited at presents | 2.5 | 2.7 | 1.6 | 1.7 | **At matched load** (both runs of each build, medians of the 5-second windows in each band of draws a frame) | draws a frame | frame ms main / #3760 | refreshes main / #3760 | submissions main / #3760 | |---|---|---|---| | 3,000-6,000 | 30.9 / 30.4 | 10.6 / 8.6 | 28.3 / 27.0 | | 6,000-8,000 | 34.6 / 32.3 | 11.7 / 9.1 | 30.6 / 28.5 | | 8,000-10,000 | 37.1 / 37.3 | 12.7 / 10.1 | 32.0 / 31.1 | | 10,000-13,000 | 39.1 / 38.7 | 12.8 / 10.4 | 32.1 / 30.6 | **What it shows** - The refreshes drop by 2.0 to 2.6 ms a frame in every band, and the submitting thread works 1.4 to 2.1 ms less. - Frame time drops by up to 2.3 ms in the 6,000-8,000 band, and stays within about 0.5 ms elsewhere. On this walk, the title's threads wait only 2.5-2.7 ms a frame at presents for the submitting thread on `main`, so that's about the most a submitting-thread cut can give back here. With this PR the wait is 1.6-2.1 ms. - Why we looked here: on a diagnostics build of `main`, same walk, the refreshes in front of a submission took 10.3 ms of the submitting thread's time a frame. That was about 1,040 changed spans a frame, 46 ms of thread time over the 7 refreshing threads, and all threads waited about 36 ms a frame for the guards' lock (69 ms on a camera turn). - No crash or device removal in the 4 runs; each has the same one Streamline error line early on, `main`'s too. We didn't check the picture closely: release builds, no captures. - Outside load: the OS card budget stayed at 15.2 GB in all 4 runs; the PC was paging lightly (page-ins 300-2,100 a second, median), most in the first `main` run. **Checks** - `cargo test --locked --release -p victory-gpu --lib -- watch::` on `main` + this PR: 70 passed, 0 failed. - Note: the description still mentions `publish_pairs`. After the merge c3470bdb, the head calls `main`'s `publish_range`, and `publish_pairs` is not in the tree. **Not tested:** a camera turn (queued, results to follow only if they differ), ray tracing on, frame generation on, Series S, other scenes, other CPUs. AI use: Claude Code (our agent) ran the builds, the bench and the tests, and wrote this; the numbers are from those runs.
github-bot closed this pull request 2026-12-01 18:51:20 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:48 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3760#issuecomment-7321597544) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

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