GPU: coalesce write-watch intervals, batch 64 KiB AVX2 shadow takes, and cut lock/job churn #54

Manually merged
github merged 2 commits from gh-pr/54/head into gh-pr/54/base 2026-12-01 20:05:09 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-28 15:51 UTC · original
Androtim:feat/iter68-cpu-watch-shadow-batching → main · +354 −144 · 5 files · 2 commits · merged 2026-11-29 04:45 UTC

Summary

Ported VRAM-neutral CPU/lock/batching optimizations from CHECK6960/Victory-Nvidia-optimized (4d51f6b, f322a44, c51df9f), strictly preserving MiniVI's 8 GiB VRAM limits:

  • watch.rs & host.rs: Coalesces write-watch ahead intervals in place using partition_point lookups, and introduces ReadJournal so flush retain loops acquire the read lock once and drop it cleanly before kernel asks or updates.
  • shadow.rs: Combines copied and ranged under one Mutex<CopiedState>, mirrors !pending.is_empty() in has_pending: AtomicBool to skip mutex locks on empty pending ranges, checks lock-free flags + ReadJournal::covered before acquiring copied, and batches Shadow::take up to 64 KiB chunks with AVX2 word_runs and coalesced card_runs. Adds unit tests word_runs_match_dword_runs_across_64kib_chunk, ranged_in_matches_latest_covering_span, and ahead_intervals_coalesce_and_match.
  • descriptor.rs & host/send.rs: Runs single-chunk sync_heaps jobs inline, merges multi-worker SyncPart accumulators through a single mutex, pre-counts send::take runs/words to avoid over-allocation, and runs small scatter batches (<= 1 chunk or < 2048 words) inline.

Rig Specs Tested On

  • CPU: Intel Core i7-13700F
  • GPU & VRAM: NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM)
  • System RAM: 32 GiB
  • OS & GPU Driver: Windows 11 Build 26300, NVIDIA driver 32.0.16.2124

Run Settings & Profile

  • Build & Commit SHA: diag @ 22f759f (after verifying plain --release has zero non-system MinGW DLL imports)
  • Console Profile & Internal Resolution / Scale: series-s — 720p (0.6666667)
  • Ray Tracing: off
  • Upscaling: DLSS quality
  • Frame Generation: off
  • Launcher Command / Preset & Extra VICTORY_* Overrides: verify-world.ps1 default settings (initial run hit transient async shader-compile A/B Pipeline drops jitter at 272 vs 261.0; rerun r2 passed all 11/11 gates)
  • Scene / Area & Session Length: In-world pier/house scene (draws >= 500), 75s capture across 16 world windows

Measurements & Verification

  • Base FPS (without Frame Gen): 10.08 mean / 11.3 median (min 0.6, p10 6.9, max draws 11201; vs baseline 8.9 fps median)
  • Frame-Gen FPS (if enabled): N/A (off)
  • VRAM / RAM Usage: 5756.5 MB median / 5778 MB max against 6833 MB min budget (0 MB over budget, room=false 8.3%; baseline 5864 MB max)
  • Crashes / DRED Resets: 0 (no_host_texture_errors=0, final_waiting=1817 vs 7121 baseline, mapped_rate=32.92 ms/s, resident_rate=100.45 ms/s with longest 99.2 ms, median_dropped_no_pipeline=261.5 vs 261.0 baseline, lit=19/24, luma=103.94, edge_energy=7.15, magenta=0.0%; all 11/11 verifier gates PASS)
  • Automated Checks:
    • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy (297 files ok)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask (6 passed; 0 failed)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu -p victory --features diagnostics --all-targets -- -D warnings (0 warnings)
    • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1 (453 passed; 0 failed; 36 ignored, incl. all 3 new tests)
    • cargo +1.98.1-x86_64-pc-windows-gnu build -p victory --release + objdump -p (0 non-system MinGW DLLs)
**@⁠Androtim** on GitHub · 2026-11-28 15:51 UTC · [original](https://github.com/Androtim/MiniVI/pull/54) `Androtim:feat/iter68-cpu-watch-shadow-batching` → `main` · +354 −144 · 5 files · 2 commits · merged 2026-11-29 04:45 UTC ## Summary Ported VRAM-neutral CPU/lock/batching optimizations from `CHECK6960/Victory-Nvidia-optimized` (`4d51f6b`, `f322a44`, `c51df9f`), strictly preserving MiniVI's 8 GiB VRAM limits: - **`watch.rs` & `host.rs`:** Coalesces write-watch `ahead` intervals in place using `partition_point` lookups, and introduces `ReadJournal` so flush retain loops acquire the read lock once and drop it cleanly before kernel asks or updates. - **`shadow.rs`:** Combines `copied` and `ranged` under one `Mutex<CopiedState>`, mirrors `!pending.is_empty()` in `has_pending: AtomicBool` to skip mutex locks on empty pending ranges, checks lock-free flags + `ReadJournal::covered` before acquiring `copied`, and batches `Shadow::take` up to `64 KiB` chunks with AVX2 `word_runs` and coalesced `card_runs`. Adds unit tests `word_runs_match_dword_runs_across_64kib_chunk`, `ranged_in_matches_latest_covering_span`, and `ahead_intervals_coalesce_and_match`. - **`descriptor.rs` & `host/send.rs`:** Runs single-chunk `sync_heaps` jobs inline, merges multi-worker `SyncPart` accumulators through a single mutex, pre-counts `send::take` runs/words to avoid over-allocation, and runs small scatter batches (`<= 1` chunk or `< 2048` words) inline. ## Rig Specs Tested On - **CPU:** Intel Core i7-13700F - **GPU & VRAM:** NVIDIA GeForce RTX 4060 Ti (8 GiB VRAM) - **System RAM:** 32 GiB - **OS & GPU Driver:** Windows 11 Build 26300, NVIDIA driver 32.0.16.2124 ## Run Settings & Profile - **Build & Commit SHA:** `diag` @ `22f759f` (after verifying plain `--release` has zero non-system MinGW DLL imports) - **Console Profile & Internal Resolution / Scale:** `series-s` — 720p (`0.6666667`) - **Ray Tracing:** `off` - **Upscaling:** `DLSS quality` - **Frame Generation:** `off` - **Launcher Command / Preset & Extra `VICTORY_*` Overrides:** `verify-world.ps1` default settings (initial run hit transient async shader-compile `A/B Pipeline drops` jitter at `272` vs `261.0`; rerun `r2` passed all 11/11 gates) - **Scene / Area & Session Length:** In-world pier/house scene (`draws >= 500`), 75s capture across 16 world windows ## Measurements & Verification - **Base FPS (without Frame Gen):** `10.08` mean / `11.3` median (min `0.6`, p10 `6.9`, max draws `11201`; vs baseline `8.9` fps median) - **Frame-Gen FPS (if enabled):** N/A (off) - **VRAM / RAM Usage:** `5756.5 MB` median / `5778 MB` max against `6833 MB` min budget (`0 MB` over budget, `room=false` `8.3%`; baseline `5864 MB` max) - **Crashes / DRED Resets:** `0` (`no_host_texture_errors=0`, `final_waiting=1817` vs `7121` baseline, `mapped_rate=32.92 ms/s`, `resident_rate=100.45 ms/s` with longest `99.2 ms`, `median_dropped_no_pipeline=261.5` vs `261.0` baseline, `lit=19/24`, `luma=103.94`, `edge_energy=7.15`, `magenta=0.0%`; all 11/11 verifier gates PASS) - **Automated Checks:** - [x] `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy` (`297 files ok`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask` (`6 passed; 0 failed`) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings` (`0` warnings) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu clippy -p victory-gpu -p victory --features diagnostics --all-targets -- -D warnings` (`0` warnings) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1` (`453 passed; 0 failed; 36 ignored`, incl. all 3 new tests) - [x] `cargo +1.98.1-x86_64-pc-windows-gnu build -p victory --release` + `objdump -p` (`0` non-system MinGW DLLs)
Ported VRAM-neutral CPU/lock/batching optimizations from CHECK6960/Victory-Nvidia-optimized (4d51f6b, f322a44, c51df9f), preserving MiniVI 8 GiB VRAM limits:
- watch.rs & host.rs: coalesce ahead intervals in place (binary-search partition_point lookup) and hold a shared ReadJournal across flush retain loops before releasing ahead of kernel asks.
- shadow.rs: merge copied/ranged under one Mutex<CopiedState>, mirror pending state in has_pending AtomicBool, batch copy_mapped up to 64 KiB with AVX2 word_runs and coalesced card_runs, and add unit tests.
- descriptor.rs & host/send.rs: run single-chunk sync_heaps work inline, merge multi-worker SyncParts under a single Mutex, pre-count send::take runs/words, and run small scatter batches inline.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:05:05 +00:00
github manually merged commit 031951a5bc into gh-pr/54/base 2026-12-01 20:05:09 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-28 19:04 UTC · original · edited 2026-11-29 00:04 UTC

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Summary

This PR ports CPU-side lock, batching, and write-watch lookup optimizations across crates/victory-gpu:

  • watch.rs & host.rs: Sorts and merges ahead intervals via coalesce_intervals + contains_interval (partition_point lookup), and adds ReadJournal so Batch flush loops (host.rs) acquire JOURNAL.read() once per retain pass and drop it before kernel queries.
  • shadow.rs: Combines copied and ranged under a single Mutex<CopiedState>, skips pending mutex locks via has_pending in writes_pending, stale_under_writes, and merge_under_writes (updating land_tests to keep has_pending in sync), moves watch::asked ahead of locking self.copied in stale_under_writes to prevent lock-order inversion with Shadow::nothing_new_in, and batches Shadow::take into 64 KiB chunks (TAKE_CHUNK) with word_runs (AVX2 fast path with dword_runs fallback) and coalesced CARD_RUNS.
  • descriptor.rs & host/send.rs: Runs single-chunk sync_heaps work inline, consolidates multi-worker SyncPart merges behind one mutex, pre-counts send::take runs/words, and runs small scatter batches (work.len() <= 1 || total_words < 2048) inline.

Review Notes

  • Correctness & concurrency:
    • stale_under_writes properly queries crate::watch::asked before locking self.copied, preserving consistent lock order (JOURNAL -> Shadow::copied) with Shadow::nothing_new_in.
    • Shadow::take safely bounds title.resize(TAKE_CHUNK.min(to - from), 0) (every iteration has n <= TAKE_CHUNK and n <= to - from), and word_runs checks at % 4 == 0 && title.len() % 4 == 0 && title.len() == held.len() before dispatching to word_runs_avx2, falling back to dword_runs otherwise.
    • coalesce_intervals / contains_interval are covered by ahead_intervals_coalesce_and_match; ranged_in and 64 KiB word_runs parity are covered by ranged_in_matches_latest_covering_span and word_runs_match_dword_runs_across_64kib_chunk.
    • Minor note: Shadow::take now increments SEND[1] (unchanged bytes diagnostic counter) only when an entire 64 KiB chunk has no diffs rather than per 4 KiB page, which is harmless for runtime behavior.
  • CI & scope: CI is passing and changes are cleanly scoped to victory-gpu without altering VRAM budgets.

Verdict

Logic and concurrency look solid, and CI is passing. Because this modifies core D3D12 host synchronization, write-watch journaling, and 64 KiB shadow-copy hot paths, a local real-GPU smoke test is recommended before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-28 19:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/54#issuecomment-7244272272) · edited 2026-11-29 00:04 UTC <!-- minivi-triage v1 head=031951a5bcc2629643c3a66bb5c64fbbb5197116 verdict=needs-gpu-test ci=passing at=2026-11-29T00:04:42Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Summary This PR ports CPU-side lock, batching, and write-watch lookup optimizations across `crates/victory-gpu`: - **`watch.rs` & `host.rs`**: Sorts and merges `ahead` intervals via `coalesce_intervals` + `contains_interval` (`partition_point` lookup), and adds `ReadJournal` so `Batch` flush loops (`host.rs`) acquire `JOURNAL.read()` once per `retain` pass and drop it before kernel queries. - **`shadow.rs`**: Combines `copied` and `ranged` under a single `Mutex<CopiedState>`, skips `pending` mutex locks via `has_pending` in `writes_pending`, `stale_under_writes`, and `merge_under_writes` (updating `land_tests` to keep `has_pending` in sync), moves `watch::asked` ahead of locking `self.copied` in `stale_under_writes` to prevent lock-order inversion with `Shadow::nothing_new_in`, and batches `Shadow::take` into 64 KiB chunks (`TAKE_CHUNK`) with `word_runs` (AVX2 fast path with `dword_runs` fallback) and coalesced `CARD_RUNS`. - **`descriptor.rs` & `host/send.rs`**: Runs single-chunk `sync_heaps` work inline, consolidates multi-worker `SyncPart` merges behind one mutex, pre-counts `send::take` runs/words, and runs small scatter batches (`work.len() <= 1 || total_words < 2048`) inline. ### Review Notes - **Correctness & concurrency**: - `stale_under_writes` properly queries `crate::watch::asked` before locking `self.copied`, preserving consistent lock order (`JOURNAL` -> `Shadow::copied`) with `Shadow::nothing_new_in`. - `Shadow::take` safely bounds `title.resize(TAKE_CHUNK.min(to - from), 0)` (every iteration has `n <= TAKE_CHUNK` and `n <= to - from`), and `word_runs` checks `at % 4 == 0 && title.len() % 4 == 0 && title.len() == held.len()` before dispatching to `word_runs_avx2`, falling back to `dword_runs` otherwise. - `coalesce_intervals` / `contains_interval` are covered by `ahead_intervals_coalesce_and_match`; `ranged_in` and 64 KiB `word_runs` parity are covered by `ranged_in_matches_latest_covering_span` and `word_runs_match_dword_runs_across_64kib_chunk`. - Minor note: `Shadow::take` now increments `SEND[1]` (unchanged bytes diagnostic counter) only when an entire 64 KiB chunk has no diffs rather than per 4 KiB page, which is harmless for runtime behavior. - **CI & scope**: CI is passing and changes are cleanly scoped to `victory-gpu` without altering VRAM budgets. ### Verdict Logic and concurrency look solid, and CI is passing. Because this modifies core D3D12 host synchronization, write-watch journaling, and 64 KiB shadow-copy hot paths, a local real-GPU smoke test is recommended before merging. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-28 23:29 UTC · original

Rebased onto origin/main (9a2e92b) and addressed the triage review findings (031951a):

Changes

  • Lock-order inversion fix (crates/victory-gpu/src/shadow.rs — Shadow::stale_under_writes): Queries crate::watch::asked(a, e) before locking self.copied, so self.copied is never held across JOURNAL.read() (eliminating the deadlock hazard with Shadow::nothing_new_in, which acquires JOURNAL.read() before self.copied).
  • Removed redundant journal coverage check (crates/victory-gpu/src/watch.rs, shadow.rs): Moved faultbook::note(What::Known, ...) into ReadJournal::covered() and replaced ReadJournal::nothing_new() with ReadJournal::nothing_new_covered() so Shadow::nothing_new_in does not repeat published / contains_interval.

Verification (031951a)

  • cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy: asset policy: 301 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask: 6 passed; 0 failed
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings: 0 warnings
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1: 487 passed; 0 failed; 36 ignored
  • Plain --release (2m05s) + objdump -p: Windows system DLLs only; --features diagnostics --release (3m30s).
  • 75s live open-world GPU verification (verify-world.ps1 -WorldSeconds 75 -AutoNudgeMenu with VICTORY_BOOK=0 while #71 is pending merge to main): 11/11 gates PASS — 10.85 fps median (+1.95 fps vs 8.9 fps baseline), 43,770 textures uploaded (1,976 MB), 3,908 final waiting (-3,213 vs 7,121 baseline), 1 ms making host copies / 14–17 ms making slots' views per 5s window, 5,495 MB peak VRAM / 6,553 MB min budget (0 MB over), 0 crashes, luma=105.64, near_black=0.0%, edge_energy=6.94 (frame-8029.png & frame-8997.png visually verified).
**@⁠Androtim** on GitHub · 2026-11-28 23:29 UTC · [original](https://github.com/Androtim/MiniVI/pull/54#issuecomment-7247462617) Rebased onto `origin/main` (`9a2e92b`) and addressed the triage review findings (`031951a`): ### Changes - **Lock-order inversion fix (`crates/victory-gpu/src/shadow.rs` — `Shadow::stale_under_writes`):** Queries `crate::watch::asked(a, e)` *before* locking `self.copied`, so `self.copied` is never held across `JOURNAL.read()` (eliminating the deadlock hazard with `Shadow::nothing_new_in`, which acquires `JOURNAL.read()` before `self.copied`). - **Removed redundant journal coverage check (`crates/victory-gpu/src/watch.rs`, `shadow.rs`):** Moved `faultbook::note(What::Known, ...)` into `ReadJournal::covered()` and replaced `ReadJournal::nothing_new()` with `ReadJournal::nothing_new_covered()` so `Shadow::nothing_new_in` does not repeat `published` / `contains_interval`. ### Verification (`031951a`) - `cargo +1.98.1-x86_64-pc-windows-gnu run -p xtask -- policy`: `asset policy: 301 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p xtask`: `6 passed; 0 failed` - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings`: `0` warnings - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics -- -D warnings`: `0` warnings - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib -- --test-threads=1`: `487 passed; 0 failed; 36 ignored` - Plain `--release` (`2m05s`) + `objdump -p`: Windows system DLLs only; `--features diagnostics --release` (`3m30s`). - **75s live open-world GPU verification (`verify-world.ps1 -WorldSeconds 75 -AutoNudgeMenu` with `VICTORY_BOOK=0` while #71 is pending merge to `main`):** **11/11 gates PASS** — `10.85 fps` median (`+1.95 fps` vs `8.9 fps` baseline), `43,770` textures uploaded (`1,976 MB`), `3,908` final waiting (`-3,213` vs `7,121` baseline), `1 ms` making host copies / `14–17 ms` making slots' views per 5s window, `5,495 MB` peak VRAM / `6,553 MB` min budget (`0 MB` over), `0` crashes, `luma=105.64`, `near_black=0.0%`, `edge_energy=6.94` (`frame-8029.png` & `frame-8997.png` visually verified).
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 04:45 UTC · original

Automated RTX 4060 Ti 8 GB A/B hardware verification passed (playtest/wave2 vs origin/main 1ab5d84):

  • Hardware cargo test (RTX 4060 Ti): victory-shader lds_sub (1/1), emit::wave64_tests (14/14), victory-gpu (505/505) — 520 passed, 0 failed.
  • Automated 45s in-world A/B (scripts/verify-world.ps1, DLSS Quality + golden autosave):
    • FPS: 13.45 fps (77.25 ms) vs 3.20 fps (308.8 ms) baseline (+10.25 fps / 4.2x faster)
    • Draws: max_draws=3122 vs 2994
    • Stability: 0 crashes / 0 DRED
    • VRAM: 6174 / 6903 MB (-25 MB vs baseline, 0 MB over budget)
    • Texture backlog: final_waiting=7638 vs 12258 (-4620)
    • Visual check: Clean rendered frames (frame-7969.png, frame-8409.png), no regressions vs origin/main.
**@⁠Androtim** on GitHub · 2026-11-29 04:45 UTC · [original](https://github.com/Androtim/MiniVI/pull/54#issuecomment-7250846832) Automated RTX 4060 Ti 8 GB A/B hardware verification passed (`playtest/wave2` vs `origin/main` `1ab5d84`): - **Hardware `cargo test` (RTX 4060 Ti):** `victory-shader` `lds_sub` (1/1), `emit::wave64_tests` (14/14), `victory-gpu` (505/505) — **520 passed, 0 failed**. - **Automated 45s in-world A/B (`scripts/verify-world.ps1`, DLSS Quality + golden autosave):** - **FPS:** **13.45 fps** (`77.25 ms`) vs **3.20 fps** (`308.8 ms`) baseline (**+10.25 fps / 4.2x faster**) - **Draws:** `max_draws=3122` vs `2994` - **Stability:** `0` crashes / `0` DRED - **VRAM:** `6174 / 6903 MB` (`-25 MB` vs baseline, `0 MB` over budget) - **Texture backlog:** `final_waiting=7638` vs `12258` (`-4620`) - **Visual check:** Clean rendered frames (`frame-7969.png`, `frame-8409.png`), no regressions vs `origin/main`.
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/Androtim--MiniVI!54
No description provided.