GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u250) #849

Closed
Starchaser1024 wants to merge 3 commits from upstream-pr/849 into main
Starchaser1024 commented 2026-11-28 07:42:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-28T07:42:52Z.


Summary

Implements the GPU-side dirty-page bitmap noted at shadow.rs:3444 and discussed in #756, eliminating the full-range CPU snapshot (Shadow::before, up to 174 MiB per submission) and full-range CPU diff scan (find_all) on non-carded Shadow buffers while removing whole-copy snapshot lock contention across overlapping flights.

Design

  1. Global title-address-space 64 KiB dirty bitmap (SLOT_DIRTY = 251, 256 KiB):
    • Adds SLOT_DIRTY = 251 (u251 in ROOT_CBV_SPACE, DIRTY_WORDS = 65_536 dwords = 256 KiB) covering all 2^21 (2,097,152) 64 KiB pages below 128 GiB.
    • Indexing by 64 KiB title virtual page (addr >> 16) & (MEMORY_PAGES - 1) handles overlapping sub-views of the 174 MiB world heap at arbitrary offsets and multi-buffer dispatches in one bitmap without ambiguity.
  2. Shader store & atomic instrumentation (crates/victory-shader/src/emit/dirty.rs):
    • Instruments buffer_store_* (dword..dwordx4, byte, short, format, format_d16), buffer_atomic_* (32/64-bit, including cmpswap), global_store_*, and global_atomic_* (excluding image UAVs and SLOT_FAULTS).
    • Resolves exact 64-bit title addresses for:
      • Root UAVs (Source::Built): USER_ROOT_ADDRESS + signed constant/dynamic offset + unbiased byte offset (without USER_VIEW_BIAS, since USER_ROOT_ADDRESS already holds the unaligned low bits), guarded by non-zero base.
      • Static descriptor-table UAVs (Source::Loaded): USER_VIEW_ADDRESS + byte offset (using SLOT_TABLE_STRIDES element byte size for typed buffer_store_format_*), guarded by getDimensions (opcode 72) and non-zero view address so OOB or null-view stores dropped by hardware never mark pages dirty.
      • SLOT_MEMORY / spilled root_memory stores: 40-bit title address guarded by writable page mapping (page_there & !closed).
    • Marks both p0 = start >> 16 and p1 = (start + bytes - 1) >> 16, coalescing into one atomicBinOp.i32 (Or) when (p0 >> 5) == (p1 >> 5) and emitting a guarded second atomic only across 2 MiB word boundaries.
    • Dynamically indexed / waterfall / bindless ResourceHeap UAVs or shaders whose root signature with u251 + USER_*_ADDRESS would exceed the D3D12 root-dword budget (64 for Cs, 32 per stage for Vs/Ps/Ms) cleanly rerun lowering without SLOT_DIRTY (HostShader::dirty_tracked = false).
  3. Pooled DirtySlot & sparse per-piece DirtyBefore (crates/victory-gpu/src/dirty.rs, shadow.rs, host.rs, draw.rs):
    • HostList lazily acquires a zeroed 256 KiB DirtySlot from dirty::POOL when binding u251 and recycles it on reset, Drop, and Flight landing (zeroing only non-zero u64 words).
    • DirtyBefore keeps a sparse per-64KiB-piece baseline with per-piece locks across waited, relay_merge_dirty, land_dirty, and merge_under_writes (VICTORY_LATE_WAIT=2) paths, preserving dword-exact merge when CPU/DirectStorage and GPU write different dwords of the same 64 KiB page while taking 0 snapshot bytes during Shadow::writing_with(..., true).
    • Mixed tracked and untracked writes in the same submission are partitioned cleanly via Shadow::snapshotted and Shadow::outside.
    • Switches: VICTORY_DIRTY_BITMAP (default on, included in shader_cache build key and HostShader cache serialization; =0 falls back to Shadow::before) and VICTORY_DIRTY_CHECK=1 (runs both before and SLOT_DIRTY and verifies zero missed pieces).

Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11)

dirty::tests::bench_174mb_non_carded_shadow_dirty_bitmap_vs_before (174 MiB / 0x0AE0_0000 non-carded Shadow, 11 overlapping sub-view declarations per submission, 2 compute dispatches touching 8 dirty 64 KiB pages, 6 measured rounds after warm-up):

Profile VICTORY_DIRTY_BITMAP=0 (Shadow::before + find_all) VICTORY_DIRTY_BITMAP=1 (SLOT_DIRTY + DirtyBefore) Speedup
--release 15.656 ms median (15.681 ms mean) 0.110 ms median (0.114 ms mean) 141.8x (-15.55 ms / submission)
debug 16.246 ms median (15.976 ms mean) 0.404 ms median (0.427 ms mean) 40.2x
  • cargo test -p victory-shader --locked: 303 passed, 0 failed (5 new dxil.dll + RTX 5060 Ti + WARP execution tests in emit::dirty_tests covering overlapping sub-views, cross-64KiB-page and cross-2MiB-word stores, OOB drops, narrow byte/short + atomics, unaligned root UAV USER_VIEW_BIAS, SLOT_MEMORY read-only/unmapped guards, and root-budget/bindless fallbacks).
  • cargo test -p victory-gpu --locked: 458 passed, 0 failed (5 new tests in dirty::tests including concurrent CPU+GPU same-page preservation, VICTORY_DIRTY_CHECK=1 zero-missed-piece verification, mixed tracked/untracked + relay + land paths, and the 174 MiB benchmark).
  • cargo clippy --workspace --all-targets --all-features --locked: 0 warnings in all new and modified files.
  • cargo xtask policy: 297 files ok.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538001388 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/849). Originally posted by [Starchaser1024](https://github.com/Starchaser1024) on 2026-11-28T07:42:52Z. --- ## Summary Implements the GPU-side dirty-page bitmap noted at `shadow.rs:3444` and discussed in #756, eliminating the full-range CPU snapshot (`Shadow::before`, up to 174 MiB per submission) and full-range CPU diff scan (`find_all`) on non-carded `Shadow` buffers while removing whole-copy snapshot lock contention across overlapping flights. ### Design 1. **Global title-address-space 64 KiB dirty bitmap (`SLOT_DIRTY = 251`, `256 KiB`)**: - Adds `SLOT_DIRTY = 251` (`u251` in `ROOT_CBV_SPACE`, `DIRTY_WORDS = 65_536` dwords = `256 KiB`) covering all `2^21` (`2,097,152`) 64 KiB pages below `128 GiB`. - Indexing by 64 KiB title virtual page `(addr >> 16) & (MEMORY_PAGES - 1)` handles overlapping sub-views of the 174 MiB world heap at arbitrary offsets and multi-buffer dispatches in one bitmap without ambiguity. 2. **Shader store & atomic instrumentation (`crates/victory-shader/src/emit/dirty.rs`)**: - Instruments `buffer_store_*` (`dword..dwordx4`, `byte`, `short`, `format`, `format_d16`), `buffer_atomic_*` (32/64-bit, including `cmpswap`), `global_store_*`, and `global_atomic_*` (excluding image UAVs and `SLOT_FAULTS`). - Resolves exact 64-bit title addresses for: - **Root UAVs (`Source::Built`)**: `USER_ROOT_ADDRESS` + signed constant/dynamic offset + unbiased byte offset (without `USER_VIEW_BIAS`, since `USER_ROOT_ADDRESS` already holds the unaligned low bits), guarded by non-zero base. - **Static descriptor-table UAVs (`Source::Loaded`)**: `USER_VIEW_ADDRESS` + byte offset (using `SLOT_TABLE_STRIDES` element byte size for typed `buffer_store_format_*`), guarded by `getDimensions` (`opcode 72`) and non-zero view address so OOB or null-view stores dropped by hardware never mark pages dirty. - **`SLOT_MEMORY` / spilled `root_memory` stores**: 40-bit title address guarded by writable page mapping (`page_there & !closed`). - Marks both `p0 = start >> 16` and `p1 = (start + bytes - 1) >> 16`, coalescing into one `atomicBinOp.i32` (`Or`) when `(p0 >> 5) == (p1 >> 5)` and emitting a guarded second atomic only across 2 MiB word boundaries. - Dynamically indexed / waterfall / bindless `ResourceHeap` UAVs or shaders whose root signature with `u251` + `USER_*_ADDRESS` would exceed the D3D12 root-dword budget (`64` for `Cs`, `32` per stage for `Vs`/`Ps`/`Ms`) cleanly rerun lowering without `SLOT_DIRTY` (`HostShader::dirty_tracked = false`). 3. **Pooled `DirtySlot` & sparse per-piece `DirtyBefore` (`crates/victory-gpu/src/dirty.rs`, `shadow.rs`, `host.rs`, `draw.rs`)**: - `HostList` lazily acquires a zeroed `256 KiB` `DirtySlot` from `dirty::POOL` when binding `u251` and recycles it on `reset`, `Drop`, and `Flight` landing (zeroing only non-zero `u64` words). - `DirtyBefore` keeps a sparse per-64KiB-piece baseline with per-piece locks across waited, `relay_merge_dirty`, `land_dirty`, and `merge_under_writes` (`VICTORY_LATE_WAIT=2`) paths, preserving dword-exact merge when CPU/DirectStorage and GPU write different dwords of the same 64 KiB page while taking `0` snapshot bytes during `Shadow::writing_with(..., true)`. - Mixed tracked and untracked writes in the same submission are partitioned cleanly via `Shadow::snapshotted` and `Shadow::outside`. - Switches: `VICTORY_DIRTY_BITMAP` (default on, included in `shader_cache` build key and `HostShader` cache serialization; `=0` falls back to `Shadow::before`) and `VICTORY_DIRTY_CHECK=1` (runs both `before` and `SLOT_DIRTY` and verifies zero missed pieces). ## Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11) `dirty::tests::bench_174mb_non_carded_shadow_dirty_bitmap_vs_before` (`174 MiB` / `0x0AE0_0000` non-carded `Shadow`, `11` overlapping sub-view declarations per submission, `2` compute dispatches touching `8` dirty 64 KiB pages, `6` measured rounds after warm-up): | Profile | `VICTORY_DIRTY_BITMAP=0` (`Shadow::before` + `find_all`) | `VICTORY_DIRTY_BITMAP=1` (`SLOT_DIRTY` + `DirtyBefore`) | Speedup | | :--- | ---: | ---: | ---: | | `--release` | **15.656 ms** median (`15.681 ms` mean) | **0.110 ms** median (`0.114 ms` mean) | **141.8x** (`-15.55 ms` / submission) | | `debug` | **16.246 ms** median (`15.976 ms` mean) | **0.404 ms** median (`0.427 ms` mean) | **40.2x** | - `cargo test -p victory-shader --locked`: 303 passed, 0 failed (5 new `dxil.dll` + RTX 5060 Ti + WARP execution tests in `emit::dirty_tests` covering overlapping sub-views, cross-64KiB-page and cross-2MiB-word stores, OOB drops, narrow `byte`/`short` + atomics, unaligned root UAV `USER_VIEW_BIAS`, `SLOT_MEMORY` read-only/unmapped guards, and root-budget/bindless fallbacks). - `cargo test -p victory-gpu --locked`: 458 passed, 0 failed (5 new tests in `dirty::tests` including concurrent CPU+GPU same-page preservation, `VICTORY_DIRTY_CHECK=1` zero-missed-piece verification, mixed tracked/untracked + `relay` + `land` paths, and the 174 MiB benchmark). - `cargo clippy --workspace --all-targets --all-features --locked`: 0 warnings in all new and modified files. - `cargo xtask policy`: 297 files ok.
shiman1901 commented 2026-11-28 13:43:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by shiman1901 on 2026-11-28T13:43:35Z.


@Starchaser1024 Huge props for building this out so cleanly — 141.8x on the 174 MiB repro with 761 passing tests and the unified 256 KiB address-space map is an awesome design!

Saw @465d6a0eac's note below that #849 dropped a live fps-prs run to 1.8 FPS ("submitting thread waits for flights"), so we audited commit 759e1893 to find why the hot path was blocking. Found a concrete smoking gun in dirty.rs + host.rs that doesn't show up in unit tests / microbenches (which only use 1 list, not 632 live lists):

Why live gameplay stalls on victory-submit (1.8 FPS)

  1. Hot-path WaitForSingleObject(INFINITE) inside dirty::acquire():
    • When the slot pool is empty, HostList::dirty_gpu() -> dirty::acquire() calls host.shared_buffer_now(256 KiB) -> Host::mapped() (host.rs:313-315) -> synchronous WaitForSingleObject(event, INFINITE) right on the victory-submit thread.
  2. Why the pool constantly starves in real gameplay (double cause):
    • clone() instead of take(): dirty_slots_of(runs) clones list.dirty_slot(), while HostList.dirty keeps holding its own Arc<DirtySlot> until HostList::reset() (which sits behind bury_lag = 16/64 and the 512 idle-list pool). So when a Flight lands and calls dirty::release(), Arc::try_unwrap fails and the slot is NOT returned to the pool.
    • POOL_MAX = 128 vs ~632 live host lists (host.rs:780-781): Even when lists eventually reset, any slot beyond 128 is dropped instead of recycled — so every frame forces fresh shared_buffer_now -> Host::mapped() stalls (plus ~158 MiB across 632 × 256 KiB buffers).
  3. (Minor bonus catch) picked.written at host.rs:6225 still calls the old shadow.writing(...) rather than writing_with(..., false) — worth checking so mixed tracked/untracked submits don't unexpectedly snapshot 174 MiB.

Minimal fix to unblock live testing

  1. Make VICTORY_DIRTY_BITMAP opt-in (default 0) until live-validated with VICTORY_DIRTY_CHECK=1.
  2. Transfer ownership instead of cloning: take() the slot out of HostList on submit so Flight is the sole owner and try_unwrap succeeds immediately on landing (or even better, assign one slot per Flight/submission rather than per HostList, which drops peak concurrent slots from ~632 down to ~16–32!).
  3. Never allocate/call mapped() on the hot path: either pre-allocate a single shared buffer (e.g. N × 256 KiB suballocated by GPU VA offset, mapped once in Host::new — zero WaitForSingleObject ever!) or pre-warm the pool without discarding slots above 128, and have acquire() return None (graceful fallback to untracked) if exhausted instead of calling shared_buffer_now().

With that hot-path mapped() stall removed, #849 should actually deliver that microbench speedup in live gameplay without touching the submitting thread!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7240140692 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/849#issuecomment-7240140692). Originally posted by [shiman1901](https://github.com/shiman1901) on 2026-11-28T13:43:35Z. --- @Starchaser1024 Huge props for building this out so cleanly — 141.8x on the 174 MiB repro with 761 passing tests and the unified 256 KiB address-space map is an awesome design! Saw @465d6a0eac's note below that `#849` dropped a live `fps-prs` run to **1.8 FPS** ("submitting thread waits for flights"), so we audited commit `759e1893` to find why the hot path was blocking. Found a concrete smoking gun in `dirty.rs` + `host.rs` that doesn't show up in unit tests / microbenches (which only use 1 list, not 632 live lists): ### Why live gameplay stalls on `victory-submit` (1.8 FPS) 1. **Hot-path `WaitForSingleObject(INFINITE)` inside `dirty::acquire()`:** - When the slot pool is empty, `HostList::dirty_gpu()` -> `dirty::acquire()` calls `host.shared_buffer_now(256 KiB)` -> `Host::mapped()` (`host.rs:313-315`) -> synchronous **`WaitForSingleObject(event, INFINITE)`** right on the `victory-submit` thread. 2. **Why the pool constantly starves in real gameplay (double cause):** - **`clone()` instead of `take()`:** `dirty_slots_of(runs)` clones `list.dirty_slot()`, while `HostList.dirty` keeps holding its own `Arc<DirtySlot>` until `HostList::reset()` (which sits behind `bury_lag = 16/64` and the 512 idle-list pool). So when a `Flight` lands and calls `dirty::release()`, **`Arc::try_unwrap` fails** and the slot is NOT returned to the pool. - **`POOL_MAX = 128` vs ~632 live host lists (`host.rs:780-781`):** Even when lists eventually reset, any slot beyond 128 is dropped instead of recycled — so every frame forces fresh `shared_buffer_now` -> `Host::mapped()` stalls (plus ~158 MiB across 632 × 256 KiB buffers). 3. *(Minor bonus catch)* `picked.written` at `host.rs:6225` still calls the old `shadow.writing(...)` rather than `writing_with(..., false)` — worth checking so mixed tracked/untracked submits don't unexpectedly snapshot 174 MiB. ### Minimal fix to unblock live testing 1. **Make `VICTORY_DIRTY_BITMAP` opt-in (`default 0`)** until live-validated with `VICTORY_DIRTY_CHECK=1`. 2. **Transfer ownership instead of cloning:** `take()` the slot out of `HostList` on submit so `Flight` is the sole owner and `try_unwrap` succeeds immediately on landing (or even better, assign **one slot per Flight/submission** rather than per `HostList`, which drops peak concurrent slots from ~632 down to ~16–32!). 3. **Never allocate/call `mapped()` on the hot path:** either pre-allocate a single shared buffer (e.g. `N × 256 KiB` suballocated by GPU VA offset, mapped once in `Host::new` — zero `WaitForSingleObject` ever!) or pre-warm the pool without discarding slots above 128, and have `acquire()` return `None` (graceful fallback to untracked) if exhausted instead of calling `shared_buffer_now()`. With that hot-path `mapped()` stall removed, `#849` should actually deliver that microbench speedup in live gameplay without touching the submitting thread!
Starchaser1024 commented 2026-11-28 15:31:37 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-28T15:31:37Z.


Huge thanks @shiman1901 (and @465d6a0eac for the live fps-prs run)! That root-cause audit nailed the exact mismatch between single-list microbenches and 632 live HostLists in gameplay:

  1. dirty_slots_of cloned HostList.dirty, so HostList held onto a second Arc<DirtySlot> across bury_lag (16..64 submissions) and the 512-entry list::IDLE pool — causing Arc::try_unwrap inside dirty::release to fail on every Flight landing (and waited submissions didn't release immediately after hand_back either).
  2. Combined with POOL_MAX = 128 dropping anything past 128 on eventual reset(), dirty::acquire() fell through to shared_buffer_now(256 KiB) -> Host::mapped() -> synchronous WaitForSingleObject(INFINITE) on the submitting/recording path every frame.

Fixed in 481afd8:

  • Opt-in VICTORY_DIRTY_BITMAP=1 (default 0) + pre-warmed cache compatibility: off by default until live A/B numbers confirm the win, and shader_cache only hashes VICTORY_DIRTY_BITMAP=1 when enabled (matching VICTORY_EARLY_DEPTH=1) so existing pre-warmed caches stay untouched on default runs.
  • 16 MiB slab sub-allocator (64 × 256 KiB per slab, up to 16 slabs = 1,024 slots, zero eviction) + non-blocking sink_gpu() fallback: one shared_buffer_now(16 MiB) populates 63 usable slots + permanent sink slot 0 at once, release() never drops slab slots, and if all slabs are ever simultaneously checked out acquire() returns None without blocking while HostList::dirty_gpu() binds sink_gpu() and falls back cleanly to Shadow::before (dirty_overflowed, zero dropped draws, zero WaitForSingleObject).
  • Ownership transfer on submit (HostList::take_dirty_slot): dirty_slots_of moves the Arc<DirtySlot> out of HostList on submit (strong_count == 1), releasing immediately after hand_back on waited submits and succeeding Arc::try_unwrap 100% of the time on Flight landing without waiting for bury_lag or list::IDLE (Shadow::writing on picked.written already delegates to writing_with(..., false)).

Verified on RTX 5060 Ti (--release) with a new 650-live-HostList stress test (dirty::tests::six_hundred_fifty_live_lists_recycle_slots_on_landing_without_stalls: 650 live HostLists, 784 list executions across async VICTORY_RELAY=1 Flights while holding 512 submitted HostLists un-reset in a simulated BURY/IDLE queue):

  • slabs_allocated == 1 (1 × 16 MiB slab total across the entire 784-execution run, 0 slab allocations / 0 mapped() waits after submission 0), completing all 784 executions + DirtyBefore merges in 53.5 ms total (0.068 ms/list).

Ready for live A/B re-testing with VICTORY_DIRTY_BITMAP=1 (and VICTORY_DIRTY_CHECK=1)!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7241533367 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/849#issuecomment-7241533367). Originally posted by [Starchaser1024](https://github.com/Starchaser1024) on 2026-11-28T15:31:37Z. --- Huge thanks @shiman1901 (and @465d6a0eac for the live `fps-prs` run)! That root-cause audit nailed the exact mismatch between single-list microbenches and 632 live `HostList`s in gameplay: 1. `dirty_slots_of` cloned `HostList.dirty`, so `HostList` held onto a second `Arc<DirtySlot>` across `bury_lag` (16..64 submissions) and the 512-entry `list::IDLE` pool — causing `Arc::try_unwrap` inside `dirty::release` to fail on every `Flight` landing (and waited submissions didn't release immediately after `hand_back` either). 2. Combined with `POOL_MAX = 128` dropping anything past 128 on eventual `reset()`, `dirty::acquire()` fell through to `shared_buffer_now(256 KiB)` -> `Host::mapped()` -> synchronous `WaitForSingleObject(INFINITE)` on the submitting/recording path every frame. Fixed in `481afd8`: - **Opt-in `VICTORY_DIRTY_BITMAP=1` (default `0`) + pre-warmed cache compatibility**: off by default until live A/B numbers confirm the win, and `shader_cache` only hashes `VICTORY_DIRTY_BITMAP=1` when enabled (matching `VICTORY_EARLY_DEPTH=1`) so existing pre-warmed caches stay untouched on default runs. - **`16 MiB` slab sub-allocator (`64 × 256 KiB` per slab, up to `16` slabs = `1,024` slots, zero eviction) + non-blocking `sink_gpu()` fallback**: one `shared_buffer_now(16 MiB)` populates 63 usable slots + permanent sink slot 0 at once, `release()` never drops slab slots, and if all slabs are ever simultaneously checked out `acquire()` returns `None` without blocking while `HostList::dirty_gpu()` binds `sink_gpu()` and falls back cleanly to `Shadow::before` (`dirty_overflowed`, zero dropped draws, zero `WaitForSingleObject`). - **Ownership transfer on submit (`HostList::take_dirty_slot`)**: `dirty_slots_of` moves the `Arc<DirtySlot>` out of `HostList` on submit (`strong_count == 1`), releasing immediately after `hand_back` on waited submits and succeeding `Arc::try_unwrap` 100% of the time on `Flight` landing without waiting for `bury_lag` or `list::IDLE` (`Shadow::writing` on `picked.written` already delegates to `writing_with(..., false)`). Verified on **RTX 5060 Ti (`--release`)** with a new 650-live-`HostList` stress test (`dirty::tests::six_hundred_fifty_live_lists_recycle_slots_on_landing_without_stalls`: 650 live `HostList`s, 784 list executions across async `VICTORY_RELAY=1` `Flight`s while holding 512 submitted `HostList`s un-reset in a simulated `BURY`/`IDLE` queue): - **`slabs_allocated == 1`** (`1 × 16 MiB` slab total across the entire 784-execution run, `0` slab allocations / `0` `mapped()` waits after submission 0), completing all 784 executions + `DirtyBefore` merges in **53.5 ms total (`0.068 ms/list`)**. Ready for live A/B re-testing with `VICTORY_DIRTY_BITMAP=1` (and `VICTORY_DIRTY_CHECK=1`)!
shiman1901 commented 2026-11-28 15:34:44 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by shiman1901 on 2026-11-28T15:34:44Z.


@Starchaser1024 That turnaround is awesome — 1 slab across 784 async executions with 650 live lists, 0 mapped() stalls after submission 0, and 0.068 ms/list is super clean! Love the sink_gpu() non-blocking fallback and keeping pre-warmed caches intact when VICTORY_DIRTY_BITMAP is off.

@465d6a0eac if you get a chance to re-test 481afd8 on top of fps-prs with VICTORY_DIRTY_BITMAP=1 (and VICTORY_DIRTY_CHECK=1), curious to see how it holds up in live gameplay now that the mapped() stall is gone!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7241574717 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/849#issuecomment-7241574717). Originally posted by [shiman1901](https://github.com/shiman1901) on 2026-11-28T15:34:44Z. --- @Starchaser1024 That turnaround is awesome — 1 slab across 784 async executions with 650 live lists, 0 `mapped()` stalls after submission 0, and `0.068 ms/list` is super clean! Love the `sink_gpu()` non-blocking fallback and keeping pre-warmed caches intact when `VICTORY_DIRTY_BITMAP` is off. @465d6a0eac if you get a chance to re-test `481afd8` on top of `fps-prs` with `VICTORY_DIRTY_BITMAP=1` (and `VICTORY_DIRTY_CHECK=1`), curious to see how it holds up in live gameplay now that the `mapped()` stall is gone!
wojtek2407 commented 2026-11-28 18:42:12 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by wojtek2407 on 2026-11-28T18:42:12Z.


Test report for #849 at 481afd8, with two follow-up patches (happy to push them as a branch if you want them).

Hardware: RTX 4070 SUPER 12 GB (driver 610.88, Resizable BAR on, GPUUploadHeapSupported), i5-12400F, Windows 11 26200. Title build v1.0.2.1, launched with scripts/play-foxhound.ps1: Series X profile, 2560x1440, DLSS Quality, no F1 settings file. Standing still at one spot in the boat mission. Numbers are medians of the frame-rate lines over the last ~75 s of each run, after the pipeline queue was empty.

481afd8 with VICTORY_DIRTY_BITMAP=1: ~2.4 fps, then a crash

base 63b902f 481afd8, bitmap on
fps 22.2 2.4
frame 45 ms ~420 ms
CPU "preparing" 33 ms ~30 ms
card busy 78 % 98-99 %

The CPU side is fine. The card is saturated. The title crashed after ~3.5 min (VCRUNTIME140.dll+0x1cc66, read of 0x0). I did not establish whether the crash came from the bitmap or from running at 2 fps.

Probable cause: emit/dirty.rs emits one atomicBinOp OR per lane per store, and the slabs live in PC memory (shared_buffer_now: CUSTOM, WRITE_BACK, L0), so every one of those atomics crosses PCIe.

Patch 1: one atomic per wave (VICTORY_DIRTY_WAVE, on by default, part of the shader-cache key)

The lanes that hit the same dword as the first active lane OR their masks with waveActiveBit and send a single atomic. The other lanes still send one each. Pixel shaders keep one atomic per lane, because a helper lane could be the first lane and its UAV writes are dropped. New test: 64 lanes, each writing a page of its own, split across two bitmap dwords, checked on the hardware and on WARP, plus the SFI0 wave-ops flag.

Result: 16.6 fps, CPU preparing 24.8 ms, card 90 % busy.

Patch 2: slabs in card memory, counters, and the card compare

  • VICTORY_DIRTY_VRAM (on by default with the bitmap) allocates the slabs with mapped_card_buffer(…, true) (GPU_UPLOAD) when the driver supports it. CPU reads go through the BAR and are uncached, so a released slot is cleared whole with plain stores and never read. Result: 22.9 fps, the same as without the bitmap.
  • A counters line (declarations tracked/untracked, MB not snapshotted, pieces merged, slots refused) shows why there is no gain: 454 of ~490 declarations a frame are tracked, but only 5.9 MB a frame is saved. The bitmap replaces Shadow::before only for copies in PC memory. In this title nearly all written buffers are copies in card memory, and those are compared on the card (CARD_COMPARE, ~6,300 pieces of 64 KiB a frame).
  • VICTORY_DIRTY_CARD=check compiles CARD_COMPARE with DIRTY_CHECK. It joins the submission's slots on the card and counts, per piece, whether the page's bit was set and whether the piece changed. Measured over 160 frame-rate lines:
    • in ranges where every write is tracked: 6,266 pieces a frame, 5,783 (92 %) with no bit and unchanged, 0.00 changed without a bit;
    • in the other ranges (untracked lists, picked views): 33 pieces, of which 13 changed without a bit. So a range is only "clean" if all of its writes are tracked.
  • VICTORY_DIRTY_CARD=1 skips reading and hashing pieces that have no bit in clean ranges. The walk is empty, so the barrier stays uniform: an early return before GroupMemoryBarrierWithGroupSync failed FXC. differs is set to 0 and the hash is kept. Skipping is off while VICTORY_FETCH_CHECK is on. A/B with bitmap only vs bitmap plus skip: 22.7 / 22.2 vs 22.1 / 21.9 fps, 92 % of clean pieces skipped, no crash. There is no gain because the submitting thread (~43 of ~45 ms) bounds the frame, not the card.

Tests: cargo test --release --locked -p victory-shader --lib: 299 passed, 5 ignored. -p victory-gpu --lib: 461 passed, 36 ignored (once, watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view failed in a full run and passed 5/5 alone). New WARP test for the counting and skipping compare.

Not tested: AMD, cards without GPU_UPLOAD, Series S, moving or dense scenes, scenes bound by the card (where the skip should matter), VICTORY_DIRTY_CHECK=1 in game.

AI use: Claude Code (Claude Opus 5.5) wrote both patches and this report, and diagnosed the PCIe atomics. The runs were made on the PC above; the numbers come from their logs.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7243991292 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/849#issuecomment-7243991292). Originally posted by [wojtek2407](https://github.com/wojtek2407) on 2026-11-28T18:42:12Z. --- Test report for #849 at `481afd8`, with two follow-up patches (happy to push them as a branch if you want them). **Hardware**: RTX 4070 SUPER 12 GB (driver 610.88, Resizable BAR on, `GPUUploadHeapSupported`), i5-12400F, Windows 11 26200. Title build v1.0.2.1, launched with `scripts/play-foxhound.ps1`: Series X profile, 2560x1440, DLSS Quality, no F1 settings file. Standing still at one spot in the boat mission. Numbers are medians of the frame-rate lines over the last ~75 s of each run, after the pipeline queue was empty. **`481afd8` with `VICTORY_DIRTY_BITMAP=1`: ~2.4 fps, then a crash** | | base `63b902f` | `481afd8`, bitmap on | |---|---|---| | fps | 22.2 | 2.4 | | frame | 45 ms | ~420 ms | | CPU "preparing" | 33 ms | ~30 ms | | card busy | 78 % | 98-99 % | The CPU side is fine. The card is saturated. The title crashed after ~3.5 min (`VCRUNTIME140.dll+0x1cc66`, read of `0x0`). I did not establish whether the crash came from the bitmap or from running at 2 fps. Probable cause: `emit/dirty.rs` emits one `atomicBinOp` OR per lane per store, and the slabs live in PC memory (`shared_buffer_now`: CUSTOM, WRITE_BACK, L0), so every one of those atomics crosses PCIe. **Patch 1: one atomic per wave (`VICTORY_DIRTY_WAVE`, on by default, part of the shader-cache key)** The lanes that hit the same dword as the first active lane OR their masks with `waveActiveBit` and send a single atomic. The other lanes still send one each. Pixel shaders keep one atomic per lane, because a helper lane could be the first lane and its UAV writes are dropped. New test: 64 lanes, each writing a page of its own, split across two bitmap dwords, checked on the hardware and on WARP, plus the SFI0 wave-ops flag. Result: **16.6 fps**, CPU preparing 24.8 ms, card 90 % busy. **Patch 2: slabs in card memory, counters, and the card compare** - **`VICTORY_DIRTY_VRAM`** (on by default with the bitmap) allocates the slabs with `mapped_card_buffer(…, true)` (GPU_UPLOAD) when the driver supports it. CPU reads go through the BAR and are uncached, so a released slot is cleared whole with plain stores and never read. Result: **22.9 fps**, the same as without the bitmap. - **A counters line** (declarations tracked/untracked, MB not snapshotted, pieces merged, slots refused) shows why there is no gain: 454 of ~490 declarations a frame are tracked, but only **5.9 MB a frame** is saved. The bitmap replaces `Shadow::before` only for copies in PC memory. In this title nearly all written buffers are copies in card memory, and those are compared on the card (`CARD_COMPARE`, ~6,300 pieces of 64 KiB a frame). - **`VICTORY_DIRTY_CARD=check`** compiles `CARD_COMPARE` with `DIRTY_CHECK`. It joins the submission's slots on the card and counts, per piece, whether the page's bit was set and whether the piece changed. Measured over 160 frame-rate lines: - in ranges where every write is tracked: 6,266 pieces a frame, **5,783 (92 %) with no bit and unchanged, 0.00 changed without a bit**; - in the other ranges (untracked lists, picked views): 33 pieces, of which 13 changed without a bit. So a range is only "clean" if all of its writes are tracked. - **`VICTORY_DIRTY_CARD=1`** skips reading and hashing pieces that have no bit in clean ranges. The walk is empty, so the barrier stays uniform: an early return before `GroupMemoryBarrierWithGroupSync` failed FXC. `differs` is set to 0 and the hash is kept. Skipping is off while `VICTORY_FETCH_CHECK` is on. A/B with bitmap only vs bitmap plus skip: **22.7 / 22.2 vs 22.1 / 21.9 fps**, 92 % of clean pieces skipped, no crash. There is no gain because the submitting thread (~43 of ~45 ms) bounds the frame, not the card. **Tests**: `cargo test --release --locked -p victory-shader --lib`: 299 passed, 5 ignored. `-p victory-gpu --lib`: 461 passed, 36 ignored (once, `watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view` failed in a full run and passed 5/5 alone). New WARP test for the counting and skipping compare. **Not tested**: AMD, cards without GPU_UPLOAD, Series S, moving or dense scenes, scenes bound by the card (where the skip should matter), `VICTORY_DIRTY_CHECK=1` in game. **AI use**: Claude Code (Claude Opus 5.5) wrote both patches and this report, and diagnosed the PCIe atomics. The runs were made on the PC above; the numbers come from their logs.
Starchaser1024 commented 2026-11-29 02:36:08 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Starchaser1024 on 2026-11-29T02:36:08Z.


Huge thanks @wojtek2407 for that phenomenal live-gameplay diagnosis and A/B test report on RTX 4070 SUPER (and confirming 0.00 missed pieces across ~1,000,000+ pieces / 92% clean CARD_COMPARE pieces in live play)!

Rebased onto current main (0338ec6, moving SLOT_DIRTY to 250 / u250 alongside upstream SLOT_SAMPLED = 251 and SLOT_MEET = 252) and integrated all three upgrades in 37c2f61:

  1. Wave-coalesced dirty atomics (VICTORY_DIRTY_WAVE, default 1 when VICTORY_DIRTY_BITMAP=1, registered in shader_cache::ELSEWHERE):
    • Non-pixel stages coalesce lanes targeting the first active lane's bitmap dword via waveReadLaneFirst.i32 + waveActiveBit.i32 (Or) + waveIsFirstLane, leaving only lanes on a different dword to issue individual atomics, while pixel shaders preserve per-lane atomics so quad helper lanes cannot drop UAV stores.
  2. GPU_UPLOAD VRAM slabs + telemetry (VICTORY_DIRTY_VRAM, default 1):
    • Allocates the 16 MiB slabs via mapped_card_buffer(SLAB_BYTES, true) (D3D12_HEAP_TYPE_GPU_UPLOAD) when supported so shader atomics stay in local VRAM L2 instead of crossing PCIe, clearing released VRAM slots with pure write-combining stores (write_bytes, zero uncached BAR reads) and falling back automatically to shared_buffer_now when GPU_UPLOAD is unavailable.
    • Added periodic frame-summary telemetry (dirty::line) counting tracked/untracked declarations, MiB not snapshotted, pieces merged, CARD_COMPARE clean pieces skipped, and sink fallbacks.
  3. VICTORY_DIRTY_CARD (=1 clean-piece skip, =check accuracy counter; off when VICTORY_FETCH_CHECK is on):
    • Joins multi-list DirtySlots on the GPU (DIRTY_MERGE, cs_5_1) when dirty_slots.len() > 1 (or binds the single slot directly as SRV(t1)), marks a CardRange eligible only when all writes to that copy in the submission are tracked, and sets steps = 0 inside CARD_COMPARE for clean pieces while keeping GroupMemoryBarrierWithGroupSync uniform (preserving stored baseline hashes without FXC early-return errors).

Verified on RTX 5060 Ti 16 GB + WARP + dxil.dll + FXC cs_5_1 (399 victory-shader + 597 victory-gpu lib tests passing):

  • 256 MiB carded Shadow CARD_COMPARE (4,096 pieces, 8 dirty): 1.085 ms -> 0.283 ms (3.83x speedup) with VICTORY_DIRTY_CARD=1, and 0 missed pieces under VICTORY_DIRTY_CARD=check (including skewed +0x4008 copies and 6-list DIRTY_MERGE).
  • 174 MiB non-carded Shadow (11 overlapping views, 8 dirty pages): 15.914 ms -> 0.226 ms (70.4x speedup) with VICTORY_DIRTY_WAVE=1 + GPU_UPLOAD VRAM slab.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7249530550 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/849#issuecomment-7249530550). Originally posted by [Starchaser1024](https://github.com/Starchaser1024) on 2026-11-29T02:36:08Z. --- Huge thanks @wojtek2407 for that phenomenal live-gameplay diagnosis and A/B test report on RTX 4070 SUPER (and confirming **0.00 missed pieces across ~1,000,000+ pieces / 92% clean `CARD_COMPARE` pieces** in live play)! Rebased onto current `main` (`0338ec6`, moving `SLOT_DIRTY` to `250` / `u250` alongside upstream `SLOT_SAMPLED = 251` and `SLOT_MEET = 252`) and integrated all three upgrades in `37c2f61`: 1. **Wave-coalesced dirty atomics (`VICTORY_DIRTY_WAVE`, default `1` when `VICTORY_DIRTY_BITMAP=1`, registered in `shader_cache::ELSEWHERE`)**: - Non-pixel stages coalesce lanes targeting the first active lane's bitmap dword via `waveReadLaneFirst.i32` + `waveActiveBit.i32` (`Or`) + `waveIsFirstLane`, leaving only lanes on a different dword to issue individual atomics, while pixel shaders preserve per-lane atomics so quad helper lanes cannot drop UAV stores. 2. **`GPU_UPLOAD` VRAM slabs + telemetry (`VICTORY_DIRTY_VRAM`, default `1`)**: - Allocates the `16 MiB` slabs via `mapped_card_buffer(SLAB_BYTES, true)` (`D3D12_HEAP_TYPE_GPU_UPLOAD`) when supported so shader atomics stay in local VRAM L2 instead of crossing PCIe, clearing released VRAM slots with pure write-combining stores (`write_bytes`, zero uncached BAR reads) and falling back automatically to `shared_buffer_now` when `GPU_UPLOAD` is unavailable. - Added periodic frame-summary telemetry (`dirty::line`) counting tracked/untracked declarations, MiB not snapshotted, pieces merged, `CARD_COMPARE` clean pieces skipped, and sink fallbacks. 3. **`VICTORY_DIRTY_CARD` (`=1` clean-piece skip, `=check` accuracy counter; off when `VICTORY_FETCH_CHECK` is on)**: - Joins multi-list `DirtySlot`s on the GPU (`DIRTY_MERGE`, `cs_5_1`) when `dirty_slots.len() > 1` (or binds the single slot directly as `SRV(t1)`), marks a `CardRange` eligible only when all writes to that copy in the submission are tracked, and sets `steps = 0` inside `CARD_COMPARE` for clean pieces while keeping `GroupMemoryBarrierWithGroupSync` uniform (preserving stored baseline hashes without FXC early-return errors). Verified on **RTX 5060 Ti 16 GB + WARP + `dxil.dll` + FXC `cs_5_1`** (`399` `victory-shader` + `597` `victory-gpu` lib tests passing): - **256 MiB carded `Shadow` `CARD_COMPARE` (`4,096` pieces, `8` dirty)**: **`1.085 ms` -> `0.283 ms` (`3.83x` speedup)** with `VICTORY_DIRTY_CARD=1`, and `0` missed pieces under `VICTORY_DIRTY_CARD=check` (including skewed `+0x4008` copies and 6-list `DIRTY_MERGE`). - **174 MiB non-carded `Shadow` (`11` overlapping views, `8` dirty pages)**: **`15.914 ms` -> `0.226 ms` (`70.4x` speedup)** with `VICTORY_DIRTY_WAVE=1` + `GPU_UPLOAD` VRAM slab.

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