victory-gpu: open write-faulted guarded blocks without the guards' lock by default, and build soft runs once per guard pass #516
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/516"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by henriazz10 on 2026-11-27T23:54:42Z.
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
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Machad3x on 2026-11-28T01:19:43Z.
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
GUARDSlock. If a view is made real (title_memory_made_real) in between, it was opened before it was noted. The pass then still treats the block as guarded and clean, with no protection on it, so writes through it go unseen.Our fix: a counter bumped under the lock in
title_memory_made_real. The guard pass compares it after taking the lock and re-reads the runs if it changed. We also kept the write-fault switch going throughtoggled!, so it stays on by default and can still be flipped byVICTORY_AB.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by henriazz10 on 2026-11-28T02:48:10Z.
Thanks for testing and for catching the race. Fixed in
e29efec:guard()now reads the soft-view runs after takingGUARDS, once per pass, so a view made real bytitle_memory_made_real(which opens it under the same lock) can no longer be taken as still soft. Before #516 this read was done inprotect_here, also under the lock. I went with reading it under the lock instead of a counter, because it keeps the single call and adds no new state.VICTORY_FAULT_UNLOCKEDgoes throughcrate::toggled!again. It is still on unless0, andVICTORY_ABcan flip it in diagnostics builds. The helper and its test that #516 had added are removed.Checks:
cargo test -p victory-gpu --lockedgives 434 passed and the 2indirect::testsfailures that are already on main.git diff --checkis clean. No new clippy findings in the touched lines. There is no deterministic test for the race itself.🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T03:17:56Z.
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× (
4 MiBwindows,VICTORY_GPU_BCPACK=0,VICTORY_WAIT_RESIDENT=0,VICTORY_TEXTURE_ROOM_PERCENT=70,VICTORY_LAND_SKIP=1,VICTORY_LAZY_COMPARE_MB=64,VICTORY_LAZY_NARROW=1).Full disclosure: tested on a fork branch based on
v2026.11.27.7(with local GPU patches,x86-64-v3/ThinLTO, and PR #501 +hot_withinfix), applying the updated PR #516 commit (e29efec,soft_runsread underGUARDS).Result — 12-minute (720 s) 3D run
cargo test -p victory-gpu --lib watchpassed (0.78 s).DeviceRemoved, 0 guest exceptions, 0 GPU stalls>=50 ms, 0 frames>=500 ms,loose_mbdown to4,152 MB,MinFreeC = 8.87 GB.R2) and without PR #501/#516 (R1):fps < 20,draws >= 100)R1(no #501/#516)R2(+ #501 fixed)R3(+ #516e29efec)11.2p50 /11.55mean (89.1 ms)10.6p50 /10.12mean (94.6 ms)12.9p50 /12.40mean (77.4 ms,Prep 63.4,copies 34.4)4k–7k draws)11.70p50 (85.2 ms)11.20p50 (89.5 ms)13.10p50 /12.97mean (76.6 ms)7k–10k draws)9.30p50 /9.37mean (107.4 ms)10.30p50 /9.79mean (96.6 ms)9.90p50 /10.25mean (101.0 ms,back 12.3 ms)>=10k draws)7.80p50 (127.6 ms,Prep 92.8)8.10p50 (123.9 ms,Prep 92.1)8.20p50 (122.1 ms,Prep 84.4,copies 54.9)10.6p50 (94.5 ms)10.4p50 (95.4 ms)12.8p50 (78.1 ms,max 118.2 ms,0frames>=250 ms)tex refreshes/write watchp5015.8/2.3 ms17.6/2.6 ms14.2/2.0 mspreparingdropped from54.1–56.8 ms(refreshes 23.2–23.8 ms) down to32.7–42.3 ms(refreshes 8.8–12.2 ms).GUARDS.lock()contention previously measured at30–96 ms/frameacross threads in adiagnosticscapture.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by henriazz10 on 2026-11-28T03:29:17Z.
Thanks a lot for the long run and the careful A/B, @POMXARK. It's good to see
e29efechold 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
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CuteBooty on 2026-11-28T04:42:05Z.
A data point from an RTX 3070 8 GB for making
VICTORY_FAULT_UNLOCKEDthe default. To be clear about what this is: the switch itself, flipped by the in-run A/B (VICTORY_AB=30,VICTORY_FAULT_UNLOCKED) on main63b902fe1. This PR's own commits (the hoisted soft-view read,e29efec) were not in the build.victory.exe run, diag profile with diagnostics;VICTORY_THIN=1,VICTORY_RELAY=2,VICTORY_SOFT_VIEWS=copies.63b902fe1plus #630, #697 and a few local commits that do not touch the guards (two commits from tiadiff's LowStutter fork, the light floor of #475 left off, the texture-admission hunks of #669 with its admissions switched off).(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 (
VICTORY_THIN=1, 60-75 ms frames).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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by yeedgrthfgv on 2026-11-28T08:31:14Z.
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
63b902fwith 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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by henriazz10 on 2026-11-28T12:51:51Z.
Thanks @CuteBooty and @yeedgrthfgv, both reports are very useful.
@yeedgrthfgv, good catch. Since this PR turns
VICTORY_FAULT_UNLOCKEDon by default, it now includes the #817 fix from #834 by @GRG-DA, as two cherry-picks with authorship kept (843f9de,694b97don top ofe29efec). With them,cargo test -p victory-gpu --lib watchpasses (48 tests, includinga_late_fault_leaves_the_guard_taken_since). The land / ask / refresh tests where the segfault showed up passed 8 runs out of 8. If #834 lands first, I'll drop the two commits here.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
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by hazben on 2026-11-28T13:18:09Z.
A measurement of #516 on its own (head
e29efec1), 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
63b902feplus 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 ate29efec1, nothing else changed, run once; Yfu = Y withVICTORY_FAULT_UNLOCKED=1, main's switch alone without #516's soft runs under the guards' lock, run once. A first run of X is not counted: the scripted walk was blocked at a door and cut at its time limit; that log has no device loss and no new error line.Frames (from 60 s after the world loads):
The last row: a line
ms = 38.0 + 0.0028 x drawsfitted on the two Y runs' 5 s stretches (123 of them, r = 0.88); each cell is that run's mean distance from the line. The two Y runs agree to 0.02 fps, which is closer than the noise, not a measure of it: five runs of the same build as X without #834 (63b902fe+ stack + #516 + #614) span 16.41-17.56 fps (1.15 fps, 6.8 %), and their draw-adjusted frame ms span 5.7 ms. X against Y (+0.16 fps, -1.9 ms) and Yfu against Y (-1.0 fps, +1.2 ms, with 7 % more draws) are both inside that. I read this as no difference from #516 on this route, not as no gain anywhere.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
8fc22547(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 to63b902fe(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" on63b902fe, 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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by henriazz10 on 2026-11-28T14:27:28Z.
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