Repository navigation
victory-gpu: open write-faulted guarded blocks without the guards' lock by default, and build soft runs once per guard pass - #516
Conversation
|
Tested merged on top of main (RTX 3080 Ti, Ryzen 7 5700X, 1440p DLSS Quality, title ray tracing on): 300 s alive. Together with #498, it cut the frame from 90-97 ms to 63-67 ms in the cell scene. The submitting thread went from 89.6 to 59.7 ms. One race found in review: the guard pass now reads the soft-view runs from the runtime's books before taking the Our fix: a counter bumped under the lock in |
… toggled! Review of trustno1-coder#516 (Machad3x): guard() read the soft-view runs before taking GUARDS. A view made real in between (title_memory_made_real opens it under that lock) was still taken as soft, so the block stayed guarded and clean with no protection on it, and writes through it went unseen. The runs are now read once, after the lock is taken (as protect_here did before trustno1-coder#516, under the same lock). VICTORY_FAULT_UNLOCKED goes through crate::toggled! again: same rule (on unless "0"), and VICTORY_AB can flip it in diagnostics builds. The helper unlocked_from_env and its test, both added in trustno1-coder#516, go with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for testing and for catching the race. Fixed in e29efec:
Checks: 🤖 Generated with Claude Code |
|
Testing feedback on AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Windows 11, Series X 1440p + DLSS Quality + DLSS MFG 4× ( Full disclosure: tested on a fork branch based on Result — 12-minute (720 s) 3D run
|
|
Thanks a lot for the long run and the careful A/B, @POMXARK. It's good to see e29efec hold for 12 minutes with no errors, and to see the refresh time on the submitting thread roughly halved on the same CPU/GPU class we develop on. It also matches what we see in the heavy open world: the frame there is still bound by CPU work around textures. We're now going through those costs one by one, and any results will come as separate PRs. 🤖 Generated with Claude Code |
|
A data point from an RTX 3070 8 GB for making
(The lock-wait line is printed every 5 s and the phases last 30 s, so each side carries a little of the other.) So the switch does exactly what it says here: the wait for the guards' lock in write faults goes from about 40 ms to about 1.5 ms a frame across threads. But the frame time does not move outside noise on this PC: +1.3 % overall, and over the 13 neighbouring phase pairs whose draw counts are within 15 % of each other, 66.6 ms off against 67.8 ms on. These frames look bound by the submitting thread (the "preparing per frame, the submitting thread" line has a median of 51 ms in this session), not by the title's threads waiting in faults. That is a different picture from the gains reported above, so it may simply be a different bottleneck on this setup ( Stability: no error lines and no device loss; the switch changed 33 times in the session and the player reported no stuck or flickering geometry. One line from each side, as logged: One session on one PC. I can repeat it with this PR's commits built in if that is more useful than the bare switch. Measurements and this report were prepared with an AI assistant (Claude Code); the run was played on my machine. |
|
One thing to keep in mind if this turns the switch on by default: #817 (found by Machad3x after the review above) is a separate race in the same path. A late lock-free fault can undo a guard taken since, and the title's next write to that block is an access violation. The fix is in #834. As far as I can see it is not in this PR, so #834 should probably land first or together with it. Another data point for the switch itself, like CuteBooty's: in-run A/B (VICTORY_AB=30,VICTORY_FAULT_UNLOCKED) on 63b902f with the #834 fix, Ryzen 5 9600X (6 cores), RTX 5080, Series X 4K output, DLSS Performance, frame generation 2x, THIN on, prison scene, about 4,800 draws a frame. Guards waits went from 43 to 50 ms a frame to 7.5 to 12.5 ms, and faults waiting for the lock from 23 to 26 ms to under 0.1 ms. The frame did not change: 42.2 ms both ways. No crash in 13 flips. Details in #834. So on this PC, as on CuteBooty's 3070, the waiting goes away but the frame is set elsewhere. Machad3x's bigger gain (with #498 and title ray tracing on) may depend on those. |
A write fault that checked PROTECTED, and reached open_unlocked only after another fault had opened the block and that was settled, found the block writable already but queued its opening anyway. A refresh that had looked at the block before guarded it again (read-only, protected, clean); the next settle then took the stale entry, removed the block from the guards and cleared PROTECTED while the memory stayed read-only. The title's next write there was an access violation no handler took. open_unlocked records took = !(done && old == PAGE_READWRITE): whether that fault's own VirtualProtect made the block writable. settle leaves an entry that did not take the block alone, apart from its OPENING and TOLD bits, so the guard taken since survives. Test a_late_fault_leaves_the_guard_taken_since. Reported in trustno1-coder#817 by @Machad3x, who published the fix as commit 3175c5dc in Machad3x/VIctory-nvidia-RTX. Ported onto current main with a longer test. (cherry picked from commit 48afe3e)
The regression test queued a stale entry with no `others`, so the `TOLD.clear(other)` branch added by the fix was never exercised. Let the entry tell the other view as written, as `open_unlocked` does, and assert that after settling TOLD and OPENING are gone while both views keep their guard notes and PROTECTED bit. On the unfixed code the other view's notes are removed, so this also detects the bug on that path. (cherry picked from commit fd31efd)
|
Thanks @CuteBooty and @yeedgrthfgv, both reports are very useful. @yeedgrthfgv, good catch. Since this PR turns On the frame rate: your two runs and CuteBooty's agree. The switch removes the lock waits (CuteBooty's guards wait went from about 97 to 35 ms a frame across threads) but leaves the frame where it is, when the submitting thread sets the frame (51 ms "preparing" on the 5800X3D, 42 ms on the 9600X). POMXARK's gain on the 5700X came mostly from the refresh time on the submitting thread itself (54-57 down to 33-42 ms). That fits the same picture. So I'd describe this PR as removing contention, with an fps gain only where faults sit on the submitting thread's path. Next we're looking at the submitting thread itself, starting from #1066. 🤖 Generated with Claude Code |
|
A measurement of #516 on its own (head e29efec), with the counters the PR describes. Short version: on this PC and route the title's write faults waiting on the guards' lock go from 18.9 ms a frame to 0.02, and the frame does not change (17.15 fps without #516, 17.30 with, one run with). The waiting goes away and the frame is set elsewhere, as the two reports on the bare switch above found (RTX 3070; RTX 5080 with #834). Setup: RTX 4070 SUPER, 32 GB, DLSS Quality, frame generation off. Main 63b902f plus a local patch stack (24 commits, not upstream), plus #614, #501 (its switches off) and #834 in every arm. A stick-steered walk of 250-320 s through one district with 13 marks, 3,500-11,400 draws per frame (median per leg), the same save and path in every run. Arms: Y = without #516, run twice; X = Y + #516 at e29efec, nothing else changed, run once; Yfu = Y with Frames (from 60 s after the world loads):
The last row: a line Counters (medians of the 5 s lines inside the route, per frame, all threads unless said):
What it says. The waits are large in Y, not already small: 375 faults a frame spent 18.7-19.2 ms waiting for the lock and 4.9 ms holding it. #516 and the bare switch both remove them (3 faults, 0.02 ms) and cut the lock's acquisitions from 355 to 113 a frame; the time in write faults over all threads falls from 23.4-24.2 to 13.0-13.6 ms, the rest being the faults now taken without the lock. The submitting thread does not move (50.7 against 50.8 and 52.9 ms) and its refresh time does not halve here (17.0 against 16.5 and 16.1 ms), so the title's threads that waited were not what set the frame on this route. Likely, not tested: the frame here is set by the submitting thread (about 51 of 55 ms). The "ms waiting for the guards" number on the title-memory line (18.1 against 18.5 and 19.1) is a different wait and does not change with #516 here. Yfu is the one run below the others; it also had the most draws, and the draw-adjusted gap (+1.2 ms) is a fifth of the noise, so I take it as no sign that the switch alone is worse. How this fits the combined-stack result. An earlier batch on main 8fc2254 (same local stack) had #516 + #614 together against neither: 15.47 and 16.02 fps for neither, 17.43 with both (+10.7 % on the mean of two), and the write-fault waits went from 15 ms to 0 there too. Two more runs of that same with-both build gave 16.89 and 16.31 fps, so its spread is 1.1 fps and the +10.7 % is nearer +4 to +11 %. Y here has #614 and not #516 and runs at 17.15, inside the range of every build that has both (16.31-17.56 over eight runs). So the step from 15.7 to about 17 fps did not need #516. Likely: it is #614 or something else in the move to 63b902f (the counted refreshes were 38.7k a frame without #614 and are 14.3k in Y and 14.2k in X). Not tested: #516 without #614, and "neither" on 63b902f, so I cannot separate those. Memory and stability: process private peak 24.58 / 24.59 GB (Y), 24.63 GB (X), 24.64 GB (Yfu); dedicated VRAM peak 8.39 / 8.63, 8.54, 8.53 GB. All four counted runs reached the end of the route with no crash, hang or device error; every run, Y included, has the same one error line (a Streamline line about 55-60 s in). #834 is in all arms, so I cannot say anything about the race it fixes; no crash in the three runs that had the lock-free path (both X runs and Yfu). Not measured: #516 without #614; a second run of X; title ray tracing with #498 (the largest gain reported above had it on) or frame generation on; another card or CPU. Unverified: that the local stack does not change these numbers. |
|
Thanks @hazben, this is the cleanest measurement of #516 so far. The A/A pair, the draw-adjusted column and the five-run spread make the result easy to trust. It agrees with what we see here and with the two earlier reports. #516 removes the write-fault waits on the guards' lock (375 faults and about 19 ms a frame down to 3 faults and 0.02 ms on your route). The frame stays where the submitting thread puts it (about 51 of 55 ms, unchanged at 50.7 ms with #516). Your note that the 15.7 to 17 fps step came without #516 also fits: on our side most of the refresh time on the submitting thread went with #614-style lock-free no-op refreshes, which #814 now carries. So I'll keep describing #516 as a contention fix: fewer lock acquisitions, less time in write faults on the title's threads, and fewer frames over 100 ms in your X run (16.4 against 26-29 a minute, one run). It isn't an fps change while the submitting thread sets the frame. That thread is what we're working on next, starting from #1066. 🤖 Generated with Claude Code |
Summary
copystatdiagnostics build on RTX 5080):victory-nvidia-play-20261127-220810-11640.log), the last 60s ran at 4.0–5.7 fps (175.4–246.9 ms/frame) with CPUcopiesat 56.3–61.9 ms (116.4–157.8 MB) andrefreshesat 51.7 ms, while GPU busy time was 12–21% and live shader/pipeline compilation had mostly subsided (72shader translated, 3host pipeline shaders=).copystatrun (victory-nvidia-play-20261127-224637-55336.log) showedguardsholdingGUARDS.lock()for49.5 ms/frame(450 watches 53.65 ms,474blocks made read-only) while write-fault handling (VICTORY_FAULT_UNLOCKEDoff by default) spent43.63 msper frame waiting onGUARDS.lock()across threads (429faults/frame).crates/victory-gpu/src/watch.rs, commitf5bde6b (rebased on main 64d4931)):VICTORY_FAULT_UNLOCKEDby default (unlocked_from_envreturnstrueunlessVICTORY_FAULT_UNLOCKED=0).soft_runs(first * BLOCK, (last - first) * BLOCK)out ofGUARDS.lock()inguard(), passing&softintoprotect()/protect_here().watch::many_askers_tests::unlocked_defaults_on_unless_zero.unlocked_from_envback toval.is_some_and(|v| v == "1")causedcargo test -p victory-gpu --lib --locked unlocked_defaults_on_unless_zeroto fail (exit code1):thread 'watch::many_askers_tests::unlocked_defaults_on_unless_zero' (31036) panicked at crates\victory-gpu\src\watch.rs:5294:9: assertion failed: super::unlocked_from_env(None)Before / After Measurements (Plain Release Build, 130s
VICTORY_WARMUP_RESTART=0)victory-nvidia-play-20261127-225157-24736.log):12.6 fps, 79.5 ms/frame (66.0 preparing: copies 34.3 ms 42.3 MB, textures 3.1 ms 24.0 MB; 0.0 on the GPU; 9.5 copying back 0.5 MB), 3576 draws/frame;refreshes27.1–36.1 ms.victory-nvidia-play-20261127-225454-59896.log):8.3 fps, 120.0 ms/frame (80.3 preparing: copies 44.4 ms 82.1 MB, textures 4.1 ms 57.4 MB; 2.8 on the GPU; 9.3 copying back 0.7 MB), 3862 draws/frame;refreshes20.0–50.7 ms.victory-nvidia-play-20261127-231559-54768.log):11.9 fps, 84.2 ms/frame (66.9 preparing: copies 32.2 ms 61.0 MB, textures 18.1 ms 40.1 MB; 2.7 on the GPU; 6.3 copying back 0.5 MB), 3743 draws/frame;refreshes16.1–26.0 ms.victory-nvidia-play-20261127-231853-57360.log):11.1 fps, 90.2 ms/frame (73.8 preparing: copies 46.4 ms 69.7 MB, textures 3.9 ms 29.0 MB; 0.8 on the GPU; 8.4 copying back 0.5 MB), 3161 draws/frame;refreshes25.1–37.3 ms.refreshesnarrowed from20.0–50.7 msto16.1–37.3 ms, while CPUcopiesremained32.2–46.4 msbecause remaining contention/copy cost is dominated byGUARDS.lock()across 8 GPU worker threads inguard()(620 waits, 175.03 msincopystat) andsoft_read(43.47–46.58 ms).Reviewer notes (Claude Code)
64d4931. On that same main, without this change, the CI commands fail the same way on this Windows checkout:cargo fmt --check(CRLF fromcore.autocrlf=true),clippy(clippy::precedenceinvictory-formats/src/texture.rs,missing_transmute_annotationsinvictory-loader/src/write_sites.rs) and the same 2 tests invictory-gpu::indirect::tests. This PR adds no new failure.df2daaf. That first try had no warm shader cache, so part of that difference is the cache, not this change.VICTORY_FAULT_UNLOCKEDis now on by default (VICTORY_FAULT_UNLOCKED=0restores the old path).Checks
cargo test -p victory-gpu --lib --locked watch::: exit code0(48 passed; 0 failed)cargo fmt --all -- --check: exit code1(pre-existing formatting diffs across untouched files; zero diffs in our added/modified lines incrates/victory-gpu/src/watch.rs)cargo clippy --workspace --all-targets --locked -- -D warnings: exit code101(pre-existingclippy::precedenceerror incrates/victory-formats/src/texture.rs:1346)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: exit code101(same pre-existingclippy::precedenceerror incrates/victory-formats/src/texture.rs:1346)cargo test --workspace --locked: exit code101(victory:23 passed,census:2 passed,victory-core:13 passed,victory-formats:42 passed; 5 ignored,victory-game:3 passed,victory-gpu:423 passed; 2 failed; 35 ignored—indirect::tests::host_list_budget_starts_empty_at_each_submissionandindirect::tests::warp_batch_charges_every_executionalso fail identically withVICTORY_FAULT_UNLOCKED=0)git diff --check: exit code0Environment & Untested Scope
AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.
🤖 Generated with Claude Code