gpu(watch): skip VirtualQuery in write-fault waits using OPEN_DONE #143

Manually merged
github merged 2 commits from gh-pr/143/head into gh-pr/143/base 2026-12-01 20:13:10 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 15:26 UTC · original
Androtim:feat/iter144-watch-fault-ask-open-done → main · +163 −11 · 1 files · 2 commits · merged 2026-11-29 21:26 UTC

Reduces VirtualQuery address-space lock contention in crates/victory-gpu/src/watch.rs:

  • Adds OPEN_DONE (set right after open_unlocked makes a block writable, cleared before OPENING.clear in settle) so concurrent write faults wait without taking the Windows address-space lock via VirtualQuery.
  • Tracks bounded rapid retries per thread/address via AGAIN / again_at (with opt-out VICTORY_FAULT_ASK=1 restoring Windows queries).
  • Adds unit test fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay.

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy (304 files ok)
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu watch:: --locked -- --test-threads=1 (50 passed; 0 failed)
  • Dual cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets (--locked and --features diagnostics --locked, -D warnings)
**@⁠Androtim** on GitHub · 2026-11-29 15:26 UTC · [original](https://github.com/Androtim/MiniVI/pull/143) `Androtim:feat/iter144-watch-fault-ask-open-done` → `main` · +163 −11 · 1 files · 2 commits · merged 2026-11-29 21:26 UTC Reduces `VirtualQuery` address-space lock contention in `crates/victory-gpu/src/watch.rs`: - Adds `OPEN_DONE` (set right after `open_unlocked` makes a block writable, cleared before `OPENING.clear` in `settle`) so concurrent write faults wait without taking the Windows address-space lock via `VirtualQuery`. - Tracks bounded rapid retries per thread/address via `AGAIN` / `again_at` (with opt-out `VICTORY_FAULT_ASK=1` restoring Windows queries). - Adds unit test `fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay`. ### Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy` (`304 files ok`) - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu watch:: --locked -- --test-threads=1` (`50 passed; 0 failed`) - Dual `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets` (`--locked` and `--features diagnostics --locked`, `-D warnings`)
- Add `OPEN_DONE` bitset in `crates/victory-gpu/src/watch.rs`, set right
  after `open_unlocked`'s `VirtualProtect` succeeds and cleared before
  `OPENING.clear` in `settle`.
- When another thread is opening a block or the block was just settled
  unlocked, retry once via bounded per-thread `again()` tracking instead
  of calling `VirtualQuery` (`VICTORY_FAULT_ASK=1` restores querying
  Windows).
- Add unit test `fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:13:08 +00:00
github manually merged commit 1c416e1ff9 into gh-pr/143/base 2026-12-01 20:13:10 +00:00
Author
Owner

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

Automated triage for the maintainers (not an approval).

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

Review Summary

Logic, memory ordering, and fallback behavior in crates/victory-gpu/src/watch.rs look solid, and CI is passing.

Verified Details

  • OPEN_DONE lifecycle (open_unlocked, settle): OPEN_DONE.set(block) runs only after VirtualProtect(..., PAGE_READWRITE, ...) succeeds (done == true), and settle clears OPEN_DONE before OPENING.clear(block) under the Guards lock. Because Bits uses SeqCst for set/clear/any and unsettled() blocks re-guarding while OPENING is set, concurrent faults observing OPEN_DONE see a block that has been made writable.
  • Bounded lockless retries (AGAIN / again_at, RECENT_OPEN):
    • again_at caps consecutive retries per thread/address within 1 ms (MOST = 8 in the OPEN_DONE wait, 1 in the !PROTECTED fast path) and refreshes the timestamp while saturated so persistent faults fall through to writable(at) (VirtualQuery) and normal exception propagation.
    • RECENT_OPEN gates the !PROTECTED fast retry so genuine unguarded write AVs on blocks never opened by watch propagate on the first fault without an extra retry.
    • Internal probes (ours.is_some()) bypass both again() shortcuts and preserve fail(exit) handling.
    • VICTORY_FAULT_ASK=1 cleanly restores the previous VirtualQuery path for A/B comparison.
  • Tests: fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay covers retry capping, time/address resets, per-thread isolation, and was_recently_opened.

Next Step

Because this modifies the live VEH write-fault wait/retry path in on_write (including extending the OPEN_DONE spin/yield window up to 2 ms), a local real-GPU smoke test under active multi-threaded gameplay/streaming is recommended before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 16:04 UTC · [original](https://github.com/Androtim/MiniVI/pull/143#issuecomment-7258595036) · edited 2026-11-29 19:04 UTC <!-- minivi-triage v1 head=1c416e1ff9c17fe316b5370e80c96171c15426a7 verdict=needs-gpu-test ci=passing at=2026-11-29T19:04:59Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Logic, memory ordering, and fallback behavior in `crates/victory-gpu/src/watch.rs` look solid, and CI is passing. ### Verified Details - **`OPEN_DONE` lifecycle (`open_unlocked`, `settle`)**: `OPEN_DONE.set(block)` runs only after `VirtualProtect(..., PAGE_READWRITE, ...)` succeeds (`done == true`), and `settle` clears `OPEN_DONE` before `OPENING.clear(block)` under the `Guards` lock. Because `Bits` uses `SeqCst` for `set`/`clear`/`any` and `unsettled()` blocks re-guarding while `OPENING` is set, concurrent faults observing `OPEN_DONE` see a block that has been made writable. - **Bounded lockless retries (`AGAIN` / `again_at`, `RECENT_OPEN`)**: - `again_at` caps consecutive retries per thread/address within 1 ms (`MOST = 8` in the `OPEN_DONE` wait, `1` in the `!PROTECTED` fast path) and refreshes the timestamp while saturated so persistent faults fall through to `writable(at)` (`VirtualQuery`) and normal exception propagation. - `RECENT_OPEN` gates the `!PROTECTED` fast retry so genuine unguarded write AVs on blocks never opened by `watch` propagate on the first fault without an extra retry. - Internal probes (`ours.is_some()`) bypass both `again()` shortcuts and preserve `fail(exit)` handling. - `VICTORY_FAULT_ASK=1` cleanly restores the previous `VirtualQuery` path for A/B comparison. - **Tests**: `fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay` covers retry capping, time/address resets, per-thread isolation, and `was_recently_opened`. ### Next Step Because this modifies the live VEH write-fault wait/retry path in `on_write` (including extending the `OPEN_DONE` spin/yield window up to 2 ms), a local real-GPU smoke test under active multi-threaded gameplay/streaming is recommended before merging. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 18:05 UTC · original

Rebased onto origin/main (9d8b3646, including #140 and #147) and addressed the minivi-triage feedback at 1c416e1f:

  1. Scoped the !PROTECTED fast retry to blocks actually opened by watch:
    • Added a lock-free direct-mapped RECENT_OPEN cache (note_recent_open / was_recently_opened) populated by open_unlocked (when VirtualProtect succeeds) and fault-path g.opened(block) in install().
    • Gated the !PROTECTED retry (again(at, 1)) in install() on was_recently_opened(block) so genuine unguarded non-watch write access violations propagate EXCEPTION_CONTINUE_SEARCH on the first fault without an extra retry.
    • Extended fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay to cover was_recently_opened / note_recent_open.

Local Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy: 305 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --locked -- watch:: --test-threads=1: 51 passed; 0 failed
  • Dual workspace clippy --all-targets -- -D warnings (default and --features diagnostics): 0 warnings
**@⁠Androtim** on GitHub · 2026-11-29 18:05 UTC · [original](https://github.com/Androtim/MiniVI/pull/143#issuecomment-7260198484) Rebased onto `origin/main` (`9d8b3646`, including `#140` and `#147`) and addressed the `minivi-triage` feedback at `1c416e1f`: 1. **Scoped the `!PROTECTED` fast retry to blocks actually opened by `watch`:** - Added a lock-free direct-mapped `RECENT_OPEN` cache (`note_recent_open` / `was_recently_opened`) populated by `open_unlocked` (when `VirtualProtect` succeeds) and fault-path `g.opened(block)` in `install()`. - Gated the `!PROTECTED` retry (`again(at, 1)`) in `install()` on `was_recently_opened(block)` so genuine unguarded non-watch write access violations propagate `EXCEPTION_CONTINUE_SEARCH` on the first fault without an extra retry. - Extended `fault_again_caps_rapid_retries_and_resets_across_addresses_or_delay` to cover `was_recently_opened` / `note_recent_open`. ### Local Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy`: `305 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --locked -- watch:: --test-threads=1`: `51 passed; 0 failed` - Dual workspace `clippy --all-targets -- -D warnings` (default and `--features diagnostics`): 0 warnings
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 21:26 UTC · original

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).
**@⁠Androtim** on GitHub · 2026-11-29 21:26 UTC · [original](https://github.com/Androtim/MiniVI/pull/143#issuecomment-7262881894) 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).
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!143
No description provided.