host/shadow: coalesce pending-gap watches, lock-free sifting, parallel preludes, and ASK_FIRST fix #2656

Merged
0x4e454f merged 1 commit from upstream-pr/2656 into main 2026-11-30 14:12:01 +00:00
0x4e454f commented 2026-11-29 15:37:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0x4e454f on 2026-11-29T15:37:46Z.


Summary

Reduces CPU refresh and submission-preparation overhead on the submitting thread through four independent improvements (tested with VICTORY_PORT_CONSTANTS=0, where the 174 MB heap lives in VRAM):

Changes

  1. Coalesced watch::writes() across pending shader-write gaps (Shadow::update_free_gaps in shadow.rs):
    • Previously, Shadow::update_ranges called update_free -> watch::writes() separately for every gap between pending GPU-write ranges. On a 174 MB heap with 20+ pending ranges, this triggered thousands of redundant ASKING/GUARDS/JOURNAL lock round-trips per second.
    • update_free_gaps calls watch::writes() once for the full [first_gap.0, last_gap.1) span and slices the sorted written-page list per gap via partition_point.
    • Also adds a lock-free has_pending fast-path before locking self.pending.
  2. VICTORY_ASK_FIRST=1 range population & sk_more gating (host.rs):
    • Populates atch.ranges before sk_first and only calls sk_more(&batch.ranges) when own.is_some(), cutting sked for more from 10.5/19.0 -> 2.1/20.4 per frame.
  3. Lock-free sifting & zero-Arc scoped worker fan-out (host.rs):
    • Enables VICTORY_FLUSH_SIFT and VICTORY_FRONT_SIFT by default using lock-free Shadow::nothing_new_with and wide_each_scoped (eliminating per-item Arc clones).
  4. Parallel prelude command-list recording & default VICTORY_THIN_THREADS scaling (host.rs, list/thin.rs):
    • Splits HostList::prelude into plan_prelude +
      ecord_prelude and records multiple preludes in parallel via wide_each_scoped when GPU detiling is not active.
    • Scales default VICTORY_THIN_THREADS to (available_parallelism / 2).clamp(2, 8).

Measured Impact (GTA 6 Series S open world, VICTORY_PORT_CONSTANTS=0)

  • 174 MB heap refresh hits (10 s): 6,705 -> 3,358 (-50%)

efreshes per frame (wall-clock): 26.2–28.6 ms -> 19.4–20.7 ms (-7.5 ms/frame)

  • VICTORY_ASK_FIRST sked for more: 10.5/19.0 -> 2.1/20.4 per frame

Verification

  • cargo test -p victory-gpu --locked --lib shadow:: -- --test-threads=1 — 71 passed, 0 failed (5 ignored)
  • Release build play-tested in open world with zero visual regressions.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5552269468 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2656). Originally posted by [0x4e454f](https://github.com/0x4e454f) on 2026-11-29T15:37:46Z. --- ## Summary Reduces CPU refresh and submission-preparation overhead on the submitting thread through four independent improvements (tested with VICTORY_PORT_CONSTANTS=0, where the 174 MB heap lives in VRAM): ### Changes 1. **Coalesced watch::writes() across pending shader-write gaps (Shadow::update_free_gaps in shadow.rs)**: - Previously, Shadow::update_ranges called update_free -> watch::writes() separately for every gap between pending GPU-write ranges. On a 174 MB heap with 20+ pending ranges, this triggered thousands of redundant ASKING/GUARDS/JOURNAL lock round-trips per second. - update_free_gaps calls watch::writes() once for the full [first_gap.0, last_gap.1) span and slices the sorted written-page list per gap via partition_point. - Also adds a lock-free has_pending fast-path before locking self.pending. 2. **VICTORY_ASK_FIRST=1 range population & sk_more gating (host.rs)**: - Populates atch.ranges before sk_first and only calls sk_more(&batch.ranges) when own.is_some(), cutting sked for more from **10.5/19.0 -> 2.1/20.4** per frame. 3. **Lock-free sifting & zero-Arc scoped worker fan-out (host.rs)**: - Enables VICTORY_FLUSH_SIFT and VICTORY_FRONT_SIFT by default using lock-free Shadow::nothing_new_with and wide_each_scoped (eliminating per-item Arc clones). 4. **Parallel prelude command-list recording & default VICTORY_THIN_THREADS scaling (host.rs, list/thin.rs)**: - Splits HostList::prelude into plan_prelude + ecord_prelude and records multiple preludes in parallel via wide_each_scoped when GPU detiling is not active. - Scales default VICTORY_THIN_THREADS to (available_parallelism / 2).clamp(2, 8). ## Measured Impact (GTA 6 Series S open world, VICTORY_PORT_CONSTANTS=0) - 174 MB heap refresh hits (10 s): **6,705 -> 3,358** (**-50%**) - efreshes per frame (wall-clock): **26.2–28.6 ms -> 19.4–20.7 ms** (**-7.5 ms/frame**) - VICTORY_ASK_FIRST sked for more: **10.5/19.0 -> 2.1/20.4** per frame ## Verification - cargo test -p victory-gpu --locked --lib shadow:: -- --test-threads=1 — **71 passed, 0 failed** (5 ignored) - Release build play-tested in open world with zero visual regressions.
BitWuehler commented 2026-11-29 16:41:33 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by BitWuehler on 2026-11-29T16:41:33Z.


Tested on Linux (CachyOS) / GE-Proton 11-14 (vkd3d-proton master) / Ryzen 7 9800X3D (8c/16t) / RTX 5080 16 GB (driver 620.73.04) stacked on 829188e9 + #2647 + #2665 with VICTORY_ASK_FIRST=1 (Series X profile, 1440p, DLSS Quality):

  • Only 4 small, straightforward conflict hunks in host.rs against #2647 (kept #2647's incremental copy_spans_extend alongside #2656's ASK_FIRST skip); shadow.rs and list/thin.rs merged cleanly.
  • Zero visual regressions across interior, vehicle, and diner scenes.
  • Worst-case frame-time hitches dropped substantially vs. the immediately preceding run (without #2656/#2665/ASK_FIRST):
    • frame_ms: 95.2 ms avg / 7084 ms max -> 52.6 ms avg / 589 ms max
    • prep_ms max: 161.6 ms -> 115.9 ms
    • copies_ms max: 72.5 ms -> 52.0 ms
    • Per-draw prep efficiency: 6.71 ms -> 6.35 ms per 1,000 draws (avg 5,586 draws/frame, max 43.8 fps).

(Test summary compiled with AI assistance.)

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7259102615 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2656#issuecomment-7259102615). Originally posted by [BitWuehler](https://github.com/BitWuehler) on 2026-11-29T16:41:33Z. --- Tested on **Linux (CachyOS) / GE-Proton 11-14 (`vkd3d-proton master`) / Ryzen 7 9800X3D (8c/16t) / RTX 5080 16 GB (driver 620.73.04)** stacked on `829188e9` + #2647 + #2665 with `VICTORY_ASK_FIRST=1` (Series X profile, 1440p, DLSS Quality): - Only 4 small, straightforward conflict hunks in `host.rs` against #2647 (kept #2647's incremental `copy_spans_extend` alongside #2656's `ASK_FIRST` skip); `shadow.rs` and `list/thin.rs` merged cleanly. - Zero visual regressions across interior, vehicle, and diner scenes. - Worst-case frame-time hitches dropped substantially vs. the immediately preceding run (without #2656/#2665/`ASK_FIRST`): - `frame_ms`: **95.2 ms avg / 7084 ms max -> 52.6 ms avg / 589 ms max** - `prep_ms` max: **161.6 ms -> 115.9 ms** - `copies_ms` max: **72.5 ms -> 52.0 ms** - Per-draw prep efficiency: **6.71 ms -> 6.35 ms per 1,000 draws** (avg 5,586 draws/frame, max **43.8 fps**). *(Test summary compiled with AI assistance.)*
tillo88 commented 2026-11-29 17:53:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tillo88 on 2026-11-29T17:53:56Z.


Tested this PR in game on top of 829188e9 (its base): it crashes for me, 2 runs out of 2, at the same place.

  • Route: load a save at the start of the game, prison cutscene, then the plane cutscene right after it. Crash during the plane cutscene, about 2.5 min after load.
  • Error: a host command list did not close (0x80070057): a command recorded into it was invalid
  • The same route on 829188e9 alone, and with #2665, passes this point every time (4 runs today).
  • Before the crash the prison cutscene ran like the base (38-47 fps), then at the cut the submitting thread went to ~50 ms a frame and fps fell to ~13.
  • My guess, not verified: the parallel prelude recording (change 4), since it is the part that records commands from several threads.

Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing builder off.
Logs (both runs, colour codes and game path stripped): attached.
pr2656-crash-logs.zip

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7260049777 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2656#issuecomment-7260049777). Originally posted by [tillo88](https://github.com/tillo88) on 2026-11-29T17:53:56Z. --- Tested this PR in game on top of 829188e9 (its base): it crashes for me, 2 runs out of 2, at the same place. - Route: load a save at the start of the game, prison cutscene, then the plane cutscene right after it. Crash during the plane cutscene, about 2.5 min after load. - Error: `a host command list did not close (0x80070057): a command recorded into it was invalid` - The same route on 829188e9 alone, and with #2665, passes this point every time (4 runs today). - Before the crash the prison cutscene ran like the base (38-47 fps), then at the cut the submitting thread went to ~50 ms a frame and fps fell to ~13. - My guess, not verified: the parallel prelude recording (change 4), since it is the part that records commands from several threads. Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing builder off. Logs (both runs, colour codes and game path stripped): attached. [pr2656-crash-logs.zip](https://github.com/user-attachments/files/35578902/pr2656-crash-logs.zip)
CopiiDeco commented 2026-11-30 00:00:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CopiiDeco on 2026-11-30T00:00:10Z.


A second data point for the crash above, from another rig: the same error, a host command list did not close (The parameter is incorrect. (0x80070057)): a command recorded into it was invalid, about a minute into the opening cutscene.

Rig: Ryzen 5 5600X (6C/12T), RTX 3080 10 GB (driver 616.92), 32 GB, Windows 11 26200; diagnostics build, Series S, DLSS Performance, frame generation off, ray tracing off.
Stack: main 829188e9 + #2776 + this PR + #2647 + #2745 + #2655. The same stack without #2655 passed one run, and a run with VICTORY_D3D12_DEBUG=1 did not reproduce it in 5 minutes, so it is intermittent here (which would fit a race, e.g. in the parallel prelude recording, as guessed above). Not narrowed down further on my side.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7264887124 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2656#issuecomment-7264887124). Originally posted by [CopiiDeco](https://github.com/CopiiDeco) on 2026-11-30T00:00:10Z. --- A second data point for the crash above, from another rig: the same error, `a host command list did not close (The parameter is incorrect. (0x80070057)): a command recorded into it was invalid`, about a minute into the opening cutscene. **Rig:** Ryzen 5 5600X (6C/12T), RTX 3080 10 GB (driver 616.92), 32 GB, Windows 11 26200; diagnostics build, Series S, DLSS Performance, frame generation off, ray tracing off. **Stack:** main 829188e9 + #2776 + this PR + #2647 + #2745 + #2655. The same stack without #2655 passed one run, and a run with `VICTORY_D3D12_DEBUG=1` did not reproduce it in 5 minutes, so it is intermittent here (which would fit a race, e.g. in the parallel prelude recording, as guessed above). Not narrowed down further on my side.
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!2656
No description provided.