Watch: a late lock-free fault no longer undoes the guard taken since (#817) #834

Merged
GRG-DA merged 2 commits from upstream-pr/834 into main 2026-11-29 08:16:58 +00:00
GRG-DA commented 2026-11-28 07:33:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by GRG-DA on 2026-11-28T07:33:54Z.


Fixes #817.

Why

A write fault can check PROTECTED, then reach open_unlocked only after another fault has opened the block and that opening was settled. It finds the block already writable, but still queues an Opened record. A refresh that looked at the block earlier can guard it again in the meantime (read-only, protected, clean). The next settle() takes that stale record, removes the block from the guards and clears PROTECTED while the memory stays read-only. The title's next write there is an access violation no handler takes — seen as segfaults in the victory-gpu unit tests (land, many-askers, refresh) in roughly 1 run in 7.

What

  • open_unlocked records took = !(done && old == PAGE_READWRITE): whether that fault's own VirtualProtect made the block writable. A failed VirtualProtect still takes the genuine path and the locked fallback.
  • settle() leaves a stale entry's guard alone. It clears only that entry's TOLD bits and OPENING, so unsettled() drains and the newer guard, its clean notes, PROTECTED, PUBLISHED, BESIDE and opened_at all survive.
  • Regression test a_late_fault_leaves_the_guard_taken_since: guards two views, queues a stale entry that tells the other view as written, settles, checks that TOLD/OPENING drain while both views keep their guard notes and PROTECTED bit with the block still read-only, then checks that a genuine fault opens it and it is reported once at the next asking. The non-empty others means the TOLD.clear branch of the fix is covered too.

Credit

The root cause and fix are from @Machad3x (issue #817), who published the fix as commit 3175c5dc in Machad3x/VIctory-nvidia-RTX but had not opened a pull request here. This is a port of that commit onto current main, with a longer regression test.

Checks

  • New test: 40 consecutive runs, 0 failures both before and after the others/TOLD coverage was added. cargo test -p victory-gpu --lib watch: 48 passed.
  • cargo test -p victory-gpu --lib: 454 passed, 0 failed on five consecutive runs. The single failure on the first run is a source-documented flake that also reproduces on unmodified main.
  • Whole watch module 100×: 4 failures, all in pre-existing flaky tests; unmodified main under the same loop: 3 failures (the source predicts 1–4 per 100).
  • Negative control: the new test fails on unmodified main at assert!(g.protected.contains(b) && g.clean.contains(b)), so it detects the bug rather than merely describing it.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: only the pre-existing clippy::manual_is_multiple_of at shadow.rs:1708 in an untouched file; with that lint allowed, no findings in changed lines.
  • cargo xtask policy: 294 files ok. git diff --check: clean. No cargo fmt (the tree is not rustfmt-clean).

Not covered

  • No in-game or RTX-card validation. The change is in lock-free bookkeeping and is covered by unit tests only.
  • On unmodified 63b902f in this environment, cargo test --workspace --locked already fails at victory-loader's console_insn::tests::a_clzero_loop_becomes_plain_stores. That is pre-existing and unrelated to this change.

Implemented with OpenCode using parallel agents for issue scouting, contributor-convention mapping, invariant auditing, implementation and independent review.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5537930389 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/834). Originally posted by [GRG-DA](https://github.com/GRG-DA) on 2026-11-28T07:33:54Z. --- Fixes #817. ## Why A write fault can check `PROTECTED`, then reach `open_unlocked` only after another fault has opened the block and that opening was settled. It finds the block already writable, but still queues an `Opened` record. A refresh that looked at the block earlier can guard it again in the meantime (read-only, protected, clean). The next `settle()` takes that stale record, removes the block from the guards and clears `PROTECTED` while the memory stays read-only. The title's next write there is an access violation no handler takes — seen as segfaults in the `victory-gpu` unit tests (land, many-askers, refresh) in roughly 1 run in 7. ## What - `open_unlocked` records `took = !(done && old == PAGE_READWRITE)`: whether that fault's own `VirtualProtect` made the block writable. A failed `VirtualProtect` still takes the genuine path and the locked fallback. - `settle()` leaves a stale entry's guard alone. It clears only that entry's `TOLD` bits and `OPENING`, so `unsettled()` drains and the newer guard, its clean notes, `PROTECTED`, `PUBLISHED`, `BESIDE` and `opened_at` all survive. - Regression test `a_late_fault_leaves_the_guard_taken_since`: guards two views, queues a stale entry that tells the other view as written, settles, checks that `TOLD`/`OPENING` drain while both views keep their guard notes and `PROTECTED` bit with the block still read-only, then checks that a genuine fault opens it and it is reported once at the next asking. The non-empty `others` means the `TOLD.clear` branch of the fix is covered too. ## Credit The root cause and fix are from @Machad3x (issue #817), who published the fix as commit `3175c5dc` in `Machad3x/VIctory-nvidia-RTX` but had not opened a pull request here. This is a port of that commit onto current `main`, with a longer regression test. ## Checks - New test: 40 consecutive runs, 0 failures both before and after the `others`/`TOLD` coverage was added. `cargo test -p victory-gpu --lib watch`: 48 passed. - `cargo test -p victory-gpu --lib`: 454 passed, 0 failed on five consecutive runs. The single failure on the first run is a source-documented flake that also reproduces on unmodified `main`. - Whole `watch` module 100×: 4 failures, all in pre-existing flaky tests; unmodified `main` under the same loop: 3 failures (the source predicts 1–4 per 100). - Negative control: the new test fails on unmodified `main` at `assert!(g.protected.contains(b) && g.clean.contains(b))`, so it detects the bug rather than merely describing it. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: only the pre-existing `clippy::manual_is_multiple_of` at `shadow.rs:1708` in an untouched file; with that lint allowed, no findings in changed lines. - `cargo xtask policy`: 294 files ok. `git diff --check`: clean. No `cargo fmt` (the tree is not rustfmt-clean). ## Not covered - No in-game or RTX-card validation. The change is in lock-free bookkeeping and is covered by unit tests only. - On unmodified `63b902f` in this environment, `cargo test --workspace --locked` already fails at `victory-loader`'s `console_insn::tests::a_clzero_loop_becomes_plain_stores`. That is pre-existing and unrelated to this change. Implemented with OpenCode using parallel agents for issue scouting, contributor-convention mapping, invariant auditing, implementation and independent review.
POMXARK commented 2026-11-28 08:05:31 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T08:05:31Z.


Validated this fix in unit tests and a full 20-minute 3D run on Windows 11 with VICTORY_FAULT_UNLOCKED=1 enabled by default — PASS (0 errors, 0 exceptions, 0 frames >=250 ms across 20 minutes).

Setup

  • Hardware: AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Windows 11.
  • Profile / flags: Series X 1440p, DLSS Quality + DLSS MFG 4x (tearing=true), VICTORY_FAULT_UNLOCKED=1 (via PR #516), default 4 MiB windows, VICTORY_GPU_BCPACK=0, VICTORY_WAIT_RESIDENT=0, VICTORY_TEXTURE_ROOM_PERCENT=70, VICTORY_LAND_SKIP=1.
  • Base: Local fork based on v2026.11.27.10 (8fc2254) + AVX2/ThinLTO + PR #516 + PR #340 + PR #81 + PR #666 + AVX2 Shadow::take / PR #498 + PR #801 (e6397aa). PR #834 applied cleanly with zero conflicts.
  • Unit tests: cargo test --locked -p victory-gpu --lib -- watch:: --test-threads=1 (VICTORY_D3D12_WARP=1) — 49/49 passed (1.59 s), including a_late_fault_leaves_the_guard_taken_since.

20-Minute Live 3D Validation Results

Metric Result (v22_r11_pr834_20m, 1200 s)
Errors / DevRem / Exceptions 0 / 0 / 0
GPU>=50ms / F>=250ms / F>=500ms 0 / 0 / 0 (worst 3D frame across 20m: 210.1 ms)
1s frame_times (3D, n=1049) 63.8 ms med / 83.1 ms p95 / 93.8 ms p99
Draw-count buckets 1k–4k: 18.80 FPS (n=96), 4k–7k: 15.80 FPS (n=66), 7k–10k: 10.90 FPS (n=37), >=10k: 9.30 FPS (n=8)
HW / Memory (hw.csv) DedMax 11,134 MB, SharedMax 9,680 MB (final 6,482 MB), CommitMax 30,317 MB, MinFreeC 10.90 GB, Resp 329/330

No regressions or rendering anomalies observed under continuous lock-free write-watch fault load.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7236356930 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/834#issuecomment-7236356930). Originally posted by [POMXARK](https://github.com/POMXARK) on 2026-11-28T08:05:31Z. --- Validated this fix in unit tests and a full 20-minute 3D run on Windows 11 with `VICTORY_FAULT_UNLOCKED=1` enabled by default — **PASS (0 errors, 0 exceptions, 0 frames >=250 ms across 20 minutes)**. ### Setup - **Hardware:** AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Windows 11. - **Profile / flags:** Series X 1440p, DLSS Quality + DLSS MFG 4x (`tearing=true`), `VICTORY_FAULT_UNLOCKED=1` (via PR #516), default `4 MiB` windows, `VICTORY_GPU_BCPACK=0`, `VICTORY_WAIT_RESIDENT=0`, `VICTORY_TEXTURE_ROOM_PERCENT=70`, `VICTORY_LAND_SKIP=1`. - **Base:** Local fork based on `v2026.11.27.10` (`8fc2254`) + AVX2/ThinLTO + PR #516 + PR #340 + PR #81 + PR #666 + AVX2 `Shadow::take` / PR #498 + PR #801 (`e6397aa`). PR #834 applied cleanly with zero conflicts. - **Unit tests:** `cargo test --locked -p victory-gpu --lib -- watch:: --test-threads=1` (`VICTORY_D3D12_WARP=1`) — **49/49 passed** (`1.59 s`), including `a_late_fault_leaves_the_guard_taken_since`. ### 20-Minute Live 3D Validation Results | Metric | Result (`v22_r11_pr834_20m`, `1200 s`) | | :--- | :--- | | **Errors / DevRem / Exceptions** | `0 / 0 / 0` | | **GPU>=50ms / F>=250ms / F>=500ms** | `0 / 0 / 0` (worst 3D frame across 20m: `210.1 ms`) | | **1s `frame_times` (3D, `n=1049`)** | `63.8 ms` med / `83.1 ms` p95 / `93.8 ms` p99 | | **Draw-count buckets** | `1k–4k`: `18.80 FPS` (`n=96`), `4k–7k`: `15.80 FPS` (`n=66`), `7k–10k`: `10.90 FPS` (`n=37`), `>=10k`: `9.30 FPS` (`n=8`) | | **HW / Memory (`hw.csv`)** | `DedMax 11,134 MB`, `SharedMax 9,680 MB` (final `6,482 MB`), `CommitMax 30,317 MB`, `MinFreeC 10.90 GB`, `Resp 329/330` | No regressions or rendering anomalies observed under continuous lock-free write-watch fault load.
yeedgrthfgv commented 2026-11-28 08:20:15 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by yeedgrthfgv on 2026-11-28T08:20:15Z.


Tested this fix (same change as Machad3x's 3175c5dc) on a Ryzen 5 9600X (6 cores) with an RTX 5080, Windows 11, Series X 4K output, DLSS Performance, frame generation 2x, THIN on, opening prison scene, about 4,800 draws a frame.

One diagnostics run with VICTORY_AB=30,VICTORY_FAULT_UNLOCKED, so the switch flipped every 30 s in the same scene. Per frame, all threads:

guards waits write faults under the lock waiting for it
off 43 to 50 ms 316 to 333 23 to 26 ms
on 7.5 to 12.5 ms 3 to 4 under 0.1 ms

So the switch takes about 35 to 40 ms a frame of waiting off the helper threads. The frame rate did not move on this PC: settled phases were 42.2 ms a frame both ways, and two 4 minute release runs gave 23.1 fps off and 23.5 fps on (within the run to run spread). Here the frame is set by the submitting thread, so the freed time does not show. It may matter more on CPUs with fewer free cores.

No crash, no access violation and no warning with the switch on, both in the run where it flipped 13 times and in a 4 minute run with it on throughout.

Also from the same fork, df65d657 fixes the watch tests that hang or fail together (on this PC the full victory-gpu lib suite failed 19 of 60 runs on 63b902f, 1 of 60 with both commits). Might be worth taking with this one.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7236516990 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/834#issuecomment-7236516990). Originally posted by [yeedgrthfgv](https://github.com/yeedgrthfgv) on 2026-11-28T08:20:15Z. --- Tested this fix (same change as Machad3x's 3175c5dc) on a Ryzen 5 9600X (6 cores) with an RTX 5080, Windows 11, Series X 4K output, DLSS Performance, frame generation 2x, THIN on, opening prison scene, about 4,800 draws a frame. One diagnostics run with VICTORY_AB=30,VICTORY_FAULT_UNLOCKED, so the switch flipped every 30 s in the same scene. Per frame, all threads: | | guards waits | write faults under the lock | waiting for it | |---|---|---|---| | off | 43 to 50 ms | 316 to 333 | 23 to 26 ms | | on | 7.5 to 12.5 ms | 3 to 4 | under 0.1 ms | So the switch takes about 35 to 40 ms a frame of waiting off the helper threads. The frame rate did not move on this PC: settled phases were 42.2 ms a frame both ways, and two 4 minute release runs gave 23.1 fps off and 23.5 fps on (within the run to run spread). Here the frame is set by the submitting thread, so the freed time does not show. It may matter more on CPUs with fewer free cores. No crash, no access violation and no warning with the switch on, both in the run where it flipped 13 times and in a 4 minute run with it on throughout. Also from the same fork, df65d657 fixes the watch tests that hang or fail together (on this PC the full victory-gpu lib suite failed 19 of 60 runs on 63b902f, 1 of 60 with both commits). Might be worth taking with this one.
jptorres96 commented 2026-11-28 09:16:44 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jptorres96 on 2026-11-28T09:16:44Z.


The new a_late_fault_leaves_the_guard_taken_since passes, and the full victory-gpu lib suite (454 tests) is green.

Env: RTX 4080 SUPER (driver 621.01), Ryzen 5 5600X, Windows build 26300, rustc 1.98.1, DXC 1.9.2609.5 (VICTORY_DXIL), --test-threads=1. VICTORY_INDIRECT_REST=1 set to sidestep main's two indirect budget-test failures (fixed in #67), unrelated to this PR.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7237134772 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/834#issuecomment-7237134772). Originally posted by [jptorres96](https://github.com/jptorres96) on 2026-11-28T09:16:44Z. --- The new `a_late_fault_leaves_the_guard_taken_since` passes, and the full `victory-gpu` lib suite (454 tests) is green. Env: RTX 4080 SUPER (driver 621.01), Ryzen 5 5600X, Windows build 26300, rustc 1.98.1, DXC 1.9.2609.5 (`VICTORY_DXIL`), `--test-threads=1`. `VICTORY_INDIRECT_REST=1` set to sidestep main's two indirect budget-test failures (fixed in #67), unrelated to this PR.
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!834
No description provided.