gpu(shadow,watch,land): lock-free refresh checks, scoped pool dispatch, and zero-clone card_dirty #161

Merged
Androtim merged 1 commit from upstream-pr/161 into main 2026-11-29 21:27:36 +00:00
Androtim commented 2026-11-29 20:21:42 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T20:21:42Z.


## Summary

  • Lock-free refresh & write-watch checks (watch, shadow):
    • Add 3-level lock-free PageEpochs (WRITTEN_EPOCHS) mirroring Journal::written and lock-free KEPT mirror in watch.rs, plus ahead_snapshot_into, nothing_new_with, and nothing_new_single (preserving PR #147 title_memory_decommitted journaling and contains_interval binary search).
    • Replace Shadow::copied mutex with copy_lock, atomic per-page Box<[AtomicU64]> stamps, and SeqLock-protected ranged_seq / ranged for zero-lock nothing_new / nothing_new_with reads.
  • Zero-alloc single-lock scoped pool dispatch (land, shadow, host):
    • Add lock-free AtomicUsize work cursor in land::Pool::each and scoped batched dispatch (wide_each_scoped) in shadow.rs / host.rs, removing per-flush heap cloning/allocations while keeping PR #145's UAV pool intact.
  • Zero-clone card_dirty (shadow, host, host/send, host/upcheck):
    • Share Arc<Vec<(usize, usize)>> across card_dirty, SentRuns, upcheck::record, and send::take / Own::send instead of cloning range vectors every frame.

Test plan

  • cargo run -p xtask -- policy: passed
  • cargo test -p victory-gpu watch:: -- --test-threads=1: passed
  • cargo test -p victory-gpu shadow::: passed
  • cargo test -p victory-gpu land::: passed
  • cargo test -p victory-gpu host::: passed
  • Dual cargo clippy --workspace --all-targets (default and --features diagnostics) with -D warnings: passed
<!-- greyfinch-sync:Androtim/MiniVI:issue:5554730766 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/161). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T20:21:42Z. --- ## Summary - **Lock-free refresh & write-watch checks (`watch`, `shadow`)**: - Add 3-level lock-free `PageEpochs` (`WRITTEN_EPOCHS`) mirroring `Journal::written` and lock-free `KEPT` mirror in `watch.rs`, plus `ahead_snapshot_into`, `nothing_new_with`, and `nothing_new_single` (preserving PR #147 `title_memory_decommitted` journaling and `contains_interval` binary search). - Replace `Shadow::copied` mutex with `copy_lock`, atomic per-page `Box<[AtomicU64]>` stamps, and SeqLock-protected `ranged_seq` / `ranged` for zero-lock `nothing_new` / `nothing_new_with` reads. - **Zero-alloc single-lock scoped pool dispatch (`land`, `shadow`, `host`)**: - Add lock-free `AtomicUsize` work cursor in `land::Pool::each` and scoped batched dispatch (`wide_each_scoped`) in `shadow.rs` / `host.rs`, removing per-flush heap cloning/allocations while keeping PR #145's UAV pool intact. - **Zero-clone `card_dirty` (`shadow`, `host`, `host/send`, `host/upcheck`)**: - Share `Arc<Vec<(usize, usize)>>` across `card_dirty`, `SentRuns`, `upcheck::record`, and `send::take` / `Own::send` instead of cloning range vectors every frame. ## Test plan - `cargo run -p xtask -- policy`: passed - `cargo test -p victory-gpu watch:: -- --test-threads=1`: passed - `cargo test -p victory-gpu shadow::`: passed - `cargo test -p victory-gpu land::`: passed - `cargo test -p victory-gpu host::`: passed - Dual `cargo clippy --workspace --all-targets` (default and `--features diagnostics`) with `-D warnings`: passed
Androtim commented 2026-11-29 20:27:58 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T20:27:58Z.


### Live GPU Verification (RTX 4060 Ti 8 GB, Series S, 60s In-World via verify-world.ps1)

  • Overall: PASS (all 6 gates passed, ok: true)
  • Performance vs pr158-texback baseline:
    • Median FPS improved from 9.4 fps (106.0 ms) to 10.7 fps (93.6 ms) (+13.8% FPS, peaking at 12.0 fps / 83.4 ms settled)
    • Median CPU preparing dropped from 51.7 ms to 44.3 ms (copies down from 26–28 ms to 17.7 ms in settled windows)
    • world_windows=15, max_draws=11308
  • Stability: crashes=0, no_host_texture_errors=0
  • VRAM: used_max=5513 MB / budget_min=6491 MB (over=0 MB, room_false=20.0%)
  • Texture Streaming: uploaded=44808, final_waiting=4116, max_waiting=26338
  • Residency Stalls: mapped_rate=6.08 ms/world_sec (14600 calls, longest=9.1 ms)
  • Visual Gate: pngs=24, lit=16/24, median_luma=103.26, near_black=0.0%, edge_energy=6.94, magenta=0.0% (verified frame-2480.png and frame-3544.png)
<!-- greyfinch-sync:Androtim/MiniVI:comment:7262101993 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/161#issuecomment-7262101993). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T20:27:58Z. --- ### Live GPU Verification (RTX 4060 Ti 8 GB, Series S, 60s In-World via `verify-world.ps1`) - **Overall:** **PASS** (all 6 gates passed, `ok: true`) - **Performance vs `pr158-texback` baseline:** - Median FPS improved from `9.4 fps` (`106.0 ms`) to **`10.7 fps` (`93.6 ms`)** (+13.8% FPS, peaking at `12.0 fps` / `83.4 ms` settled) - Median CPU preparing dropped from `51.7 ms` to **`44.3 ms`** (`copies` down from `26–28 ms` to `17.7 ms` in settled windows) - `world_windows=15`, `max_draws=11308` - **Stability:** `crashes=0`, `no_host_texture_errors=0` - **VRAM:** `used_max=5513 MB` / `budget_min=6491 MB` (`over=0 MB`, `room_false=20.0%`) - **Texture Streaming:** `uploaded=44808`, `final_waiting=4116`, `max_waiting=26338` - **Residency Stalls:** `mapped_rate=6.08 ms/world_sec` (`14600` calls, `longest=9.1 ms`) - **Visual Gate:** `pngs=24`, `lit=16/24`, `median_luma=103.26`, `near_black=0.0%`, `edge_energy=6.94`, `magenta=0.0%` (verified `frame-2480.png` and `frame-3544.png`)
Androtim commented 2026-11-29 21:04:11 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T21:04:11Z.


Automated triage for the maintainers (not an approval).

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

Review Summary

Logic, memory ordering, and concurrency invariants look solid, and CI is passing. Because this PR rewrites hot-path synchronization in victory-gpu (host.rs, shadow.rs, watch.rs, land.rs, host/send.rs, host/upcheck.rs), it warrants a local real-GPU smoke test before merging.

What Was Verified

  • Lock-free write-watch & refresh checks (watch.rs, shadow.rs, host.rs):
    • PageEpochs (WRITTEN_EPOCHS) correctly covers 128 TiB of 64 KiB pages (2^15 * 2^6 * 2^10 = 2^31 pages) with lock-free CAS allocation and Release/Acquire epoch stores/loads, mirrored from Journal::note.
    • KEPT mirrors Journal::kept in both ask_rest and ask_once_end.
    • Shadow::copy_stale defers self.copied[i].store(now, Ordering::Release) until after self.take_all(runs), preventing lock-free nothing_new_with/nothing_new_single readers from observing updated epochs before bytes are copied.
    • Shadow::ranged_lockfree + copy_stale follow the standard atomic SeqLock protocol (store(seq+1, Relaxed) + fence(Release) + payload stores + store(seq+2, Release) paired with load(Acquire) + payload loads + fence(Acquire) + load(Relaxed)), with no Rust data-race UB.
    • Every call site of Shadow::nothing_new_with (Batch::refresh_front, Batch::refresh_ahead, Batch::flush_all) is already gated on watch::light().
  • Scoped pool dispatch (shadow.rs, land.rs, host.rs):
    • wide_each_scoped bounds the lifetime-erased ScopedWork pointer strictly by scoped_running == 0 and q.scoped.take() before returning or resuming unwind, avoids lost wakeups on workers.idle under workers.queue, and falls back inline on nested/contended calls.
    • land::Pool::each replaces per-item mutex locking with an AtomicUsize cursor while keeping state.work = None and state.running == 0 synchronization intact.
  • Zero-clone card_dirty (shadow.rs, host.rs, host/send.rs, host/upcheck.rs):
    • Cleanly shares Arc<Vec<(usize, usize)>> across card_dirty, SentRuns, send::take, Own::record, and upcheck::record.

Minor Notes (non-blocking)

  • In crates/victory-gpu/src/shadow.rs (Shadow::stale_under_writes), the comment above copy_lock.lock() still references querying watch::asked before locking self.copied to avoid lock-order inversion with the now-removed nothing_new_in. Since nothing_new/nothing_new_with no longer acquire copy_lock, the code is safe, but the comment is stale.

Verdict

needs-gpu-test — run a local real-GPU gameplay smoke test (including default VICTORY_ASK_ONCE / VICTORY_RELAY paths) to verify live buffer coherency and scoped worker stability under real frame load.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7262577930 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/161#issuecomment-7262577930). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T21:04:11Z. --- <!-- minivi-triage v1 head=5c9a6ca27ef7f0e2455751d19f4db544dd222437 verdict=needs-gpu-test ci=passing at=2026-11-29T21:04:45Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic, memory ordering, and concurrency invariants look solid, and CI is passing. Because this PR rewrites hot-path synchronization in `victory-gpu` (`host.rs`, `shadow.rs`, `watch.rs`, `land.rs`, `host/send.rs`, `host/upcheck.rs`), it warrants a local real-GPU smoke test before merging. ### What Was Verified - **Lock-free write-watch & refresh checks (`watch.rs`, `shadow.rs`, `host.rs`)**: - `PageEpochs` (`WRITTEN_EPOCHS`) correctly covers 128 TiB of 64 KiB pages (`2^15 * 2^6 * 2^10 = 2^31` pages) with lock-free CAS allocation and `Release`/`Acquire` epoch stores/loads, mirrored from `Journal::note`. - `KEPT` mirrors `Journal::kept` in both `ask_rest` and `ask_once_end`. - `Shadow::copy_stale` defers `self.copied[i].store(now, Ordering::Release)` until after `self.take_all(runs)`, preventing lock-free `nothing_new_with`/`nothing_new_single` readers from observing updated epochs before bytes are copied. - `Shadow::ranged_lockfree` + `copy_stale` follow the standard atomic SeqLock protocol (`store(seq+1, Relaxed)` + `fence(Release)` + payload stores + `store(seq+2, Release)` paired with `load(Acquire)` + payload loads + `fence(Acquire)` + `load(Relaxed)`), with no Rust data-race UB. - Every call site of `Shadow::nothing_new_with` (`Batch::refresh_front`, `Batch::refresh_ahead`, `Batch::flush_all`) is already gated on `watch::light()`. - **Scoped pool dispatch (`shadow.rs`, `land.rs`, `host.rs`)**: - `wide_each_scoped` bounds the lifetime-erased `ScopedWork` pointer strictly by `scoped_running == 0` and `q.scoped.take()` before returning or resuming unwind, avoids lost wakeups on `workers.idle` under `workers.queue`, and falls back inline on nested/contended calls. - `land::Pool::each` replaces per-item mutex locking with an `AtomicUsize` cursor while keeping `state.work = None` and `state.running == 0` synchronization intact. - **Zero-clone `card_dirty` (`shadow.rs`, `host.rs`, `host/send.rs`, `host/upcheck.rs`)**: - Cleanly shares `Arc<Vec<(usize, usize)>>` across `card_dirty`, `SentRuns`, `send::take`, `Own::record`, and `upcheck::record`. ### Minor Notes (non-blocking) - In `crates/victory-gpu/src/shadow.rs` (`Shadow::stale_under_writes`), the comment above `copy_lock.lock()` still references querying `watch::asked` before locking `self.copied` to avoid lock-order inversion with the now-removed `nothing_new_in`. Since `nothing_new`/`nothing_new_with` no longer acquire `copy_lock`, the code is safe, but the comment is stale. ### Verdict `needs-gpu-test` — run a local real-GPU gameplay smoke test (including default `VICTORY_ASK_ONCE` / `VICTORY_RELAY` paths) to verify live buffer coherency and scoped worker stability under real frame load. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-11-29 21:27:33 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T21:27:33Z.


Automated RTX 4060 Ti 8 GB Open-World A/B hardware verification PASSED (playtest/wave5 vs origin/main b1b6dc1, VICTORY_LEVELS_ON_DEMAND=0 play-parity):

  • Hardware cargo test (RTX 4060 Ti): 645 passed, 0 failed (victory 39/39, victory-shader emit::wave64_tests 19/19 & lower 19/19, victory-gpu 568/568).
  • 45s Open-World A/B (scripts/verify-world.ps1, DLSS Quality + open-world save):
    • FPS: median 9.4 fps vs 7.5 fps (+1.90 fps / +25%), min 8.3 fps vs 0.8 fps, preparing 53.6 ms vs 60.0 ms
    • Stability: 0 crashes / 0 DRED / 0 untranslated shaders
    • VRAM / Issue #149: max 5760 MB vs 6005 MB (-245 MB, 0 MB over budget); no room for new ones halved (9,000 vs 18,000); max_waiting dropped (36,432 vs 41,431)
    • Decoration bakes / Issue #150: 0 mismatches (other_bytes=0, showed_another_view=0, failed=0 vs 5 and 2 on baseline)
    • Residency stalls: mapped_rate 1.63 ms/s vs 6.9 ms/s (-76%, max 12.9 vs 51.9 ms)
    • Visual check: Clean open-world safehouse frames (frame-5975.png, frame-5983.png), edge_energy=4.69 vs 3.88, near_black=0.02%, magenta=0.0% (and #141 2bf6800 showed zero visual artifacts).
<!-- greyfinch-sync:Androtim/MiniVI:comment:7262891529 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/161#issuecomment-7262891529). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T21:27:33Z. --- Automated RTX 4060 Ti 8 GB **Open-World** A/B hardware verification **PASSED** (`playtest/wave5` vs `origin/main` `b1b6dc1`, `VICTORY_LEVELS_ON_DEMAND=0` play-parity): - **Hardware `cargo test` (RTX 4060 Ti):** **645 passed, 0 failed** (`victory` 39/39, `victory-shader` `emit::wave64_tests` 19/19 & `lower` 19/19, `victory-gpu` 568/568). - **45s Open-World A/B (`scripts/verify-world.ps1`, DLSS Quality + open-world save):** - **FPS:** median **`9.4 fps`** vs `7.5 fps` (**+1.90 fps / +25%**), min **`8.3 fps`** vs **`0.8 fps`**, preparing `53.6 ms` vs `60.0 ms` - **Stability:** **0** crashes / **0** DRED / **0** untranslated shaders - **VRAM / Issue #149:** max **`5760 MB`** vs `6005 MB` (**-245 MB**, `0 MB` over budget); `no room for new ones` halved (**`9,000`** vs `18,000`); `max_waiting` dropped (`36,432` vs `41,431`) - **Decoration bakes / Issue #150:** **`0` mismatches** (`other_bytes=0, showed_another_view=0, failed=0` vs `5` and `2` on baseline) - **Residency stalls:** `mapped_rate` **`1.63 ms/s`** vs `6.9 ms/s` (**-76%**, max `12.9` vs `51.9 ms`) - **Visual check:** Clean open-world safehouse frames (`frame-5975.png`, `frame-5983.png`), `edge_energy=4.69` vs `3.88`, `near_black=0.02%`, `magenta=0.0%` (and `#141` `2bf6800` showed zero visual artifacts).
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
Androtim/MiniVI!161
No description provided.