perf(gpu): compare big card copies only where written lately #501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/501"
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 ballsimulation on 2026-11-27T23:38:12Z.
Summary
Two opt-in switches, both off by default, that cut the cost of the title's 174 MB constants heap:
VICTORY_LAZY_COMPARE_MB=64: the GPU compares only the parts of the heap that shaders recently wrote, plus a rotating sweep of the rest.VICTORY_LAZY_NARROW=1: constant reads from the heap stop counting as blocked by in-flight work, except on those recently written parts.On main, with both on: frames 4–6% faster, and the submitting thread's planning of steps on the card drops from 7.4 to 1.7 ms.
Why
The skinning passes declare the whole heap written in every submission, through one view of it. That has two costs:
card_steps). That costs 7–12 ms per frame on the submitting thread.What changes
VICTORY_LAZY_COMPARE_MB=<MiB>For a card copy at least this large, a submission compares only:
VICTORY_LAZY_HOTcompares (default 64);VICTORY_LAZY_SWEEPskipped pieces in turn (default 128).These compares store their hashes (mode 2). Anything found is fetched and merged exactly as before. A log line every 5 s shows the counts.
VICTORY_LAZY_NARROW=1(needs the switch above)Where submission steps wait for flights, or are done on the card in flight order (
late_blocked,card_steps,cut_for, the relay's wait), such a copy counts as written only on its recently written pieces. Refreshes still see every declared write.Trade-off
A heap piece that shaders write for the first time reaches title memory only when the sweep finds it, about 2 frames later. Until then, CPU steps read the title's own bytes there.
Results
RTX 4070, Ryzen 9 7950X. Series X profile at native 2560x1440, no DLSS, frame rate uncapped. One build of main
64d4931bwith this change, the same save and walk, run with the switches off and then on. Median frame time by draws per frame:Caveats
🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T00:29:33Z.
Testing feedback on RTX 5080 16 GB / AMD Ryzen 7 5700X (8C/16T) / 32 GB RAM, Windows 11, Series X 1440p + DLSS Quality + DLSS MFG 4×, based on
v2026.11.27.8(64d4931) withVICTORY_LAZY_COMPARE_MB=64andVICTORY_LAZY_NARROW=1:Hit a guest access violation at 3m44s (
Frame: 5348, 3D workload) that did not occur on prior 12-minute runs withoutVICTORY_LAZY_*:unhandled exception 0xc0000005 at victory-image-b99f876b74d4a77f.dll+0x4e9b54a (read 0xffffffffffffffff: outside the address space)rcx 0x31ff84a045495676(non-canonical pointer),rax 0x0,rbx 0xd0418f3a8,rdi 0xd04189938,r8/r9 0xffffffff00000000+0x4e9b54a -> +0x4e9b4bf -> +0x4a4a -> +0x4d9f49c -> +0x2484ac4 -> +0x321c5 -> +0x3346d -> +0x555e921Full disclosure: this was tested on a custom branch with additional local GPU patches on top of
v2026.11.27.8(also with PR #498 and PR #499 enabled), so it is not yet a cleanmain-only repro. Sharing the crash trace here since it looks consistent with the documented risk inlazy.rsaround delayed/missed first-time shader write-backs into the 174 MB constants heap whenVICTORY_LAZY_NARROW=1is enabled.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Machad3x on 2026-11-28T01:19:42Z.
Tested merged on top of main (RTX 3080 Ti, Ryzen 7 5700X, 1440p DLSS Quality, title ray tracing on). With the switch at its default (off) the run was fine. Review found one bug in
host/lazy.rshot_within:It joins a hot piece onto
out.last_mut()wheneverlast.1 >= a, without checkinglast.0 <= a.outalready holds unrelated ranges at that point (Line::joinedseeds it withtextures.to_vec(), and the line rebuild adds other ranges first). A hot piece that lies below an unrelated range above it gets swallowed:last.1 = max(last.1, b)changes nothing, so[a, b)is lost. WithVICTORY_LAZY_NARROW=1, the waits (late_blocked,card_steps,cut_for,relay_wait) then do not wait for the flight that writes those bytes, and a later list reads stale data.Fix we use (callers already sort and join afterwards):
plus a test
hot_piece_below_an_unrelated_range_stays.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T02:50:03Z.
Follow-up test confirming @Machad3x's 1-line fix in
crates/victory-gpu/src/host/lazy.rs(last.0 <= a && last.1 >= a):Setup: Same hardware (AMD Ryzen 7 5700X 8C/16T, RTX 5080 16 GB, 32 GB RAM, Windows 11, Series X 1440p + DLSS Quality + DLSS MFG 4×,
4 MiBwindows), tested on a clean fork branch based onv2026.11.27.7(x86-64-v3/ThinLTO, without PR #499), withVICTORY_LAZY_COMPARE_MB=64andVICTORY_LAZY_NARROW=1plusMachad3x'shot_withinfix (and unit testhot_piece_below_an_unrelated_range_stayspassing).Result — 12-minute (720 s) 3D run
DeviceRemoved, clean render output across all draw tiers (the earlier0xc0000005at+0x4e9b54aat3m44sdid not reproduce in this run).VICTORY_LAZY_*):fps < 20,draws >= 100)hot_withinfix (64+NARROW=1)9.4p50 /9.20mean (106.4 ms,max 295.2,2frames>=250ms)10.3p50 /9.63mean (96.6 ms,max 218.5,0frames>=250ms)+9.6%p50 (-9.8 ms)7k–10k draws) (p50 ~8.4–8.6k)9.30p50 /9.37mean (107.4 ms,back 14.1 ms)10.30p50 /9.79mean (96.6 ms,back 12.8 ms)+10.8%p50 (-10.8 ms)>=10k draws) (p50 ~11.2k)7.80p50 (127.6 ms,copies 67.2 ms)8.10p50 (123.9 ms,copies 59.6 ms)+3.8%p50 (-7.6 ms copies)GPU>=50/F>=250)1/20/0card_stepsfills dropped ~10× (~9,800->949fills/frame,529.6 KB),planning steps done on the carddown to1.6–2.4 ms, andlazy comparesskipped ~73% of big-copy pieces (left=477k–618kper 5 s,hot_now=455–711).0..360 searly frames had extra variance in this run due to low system pagefile headroom during initial load, while480..760 sran with0frames>=250 ms.)Thanks to @Machad3x — adding
last.0 <= a && last.1 >= ainhot_withinlooks essential before merging this PR.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T03:34:31Z.
Update after a 3rd run with
VICTORY_LAZY_COMPARE_MB=64+VICTORY_LAZY_NARROW=1and@Machad3x'shot_withinfix (last.0 <= a && last.1 >= a) applied:Hit the exact same 4-frame guest access violation (
+0x4e9b54a -> +0x4e9b4bf -> +0x4a4a -> +0x4d9f49c) again intermittently at 5m48s (frame=26409,25.4 fps,1407 draws/frameduring a scene transition), this time reading0xc(rcx=0x0):So
Machad3x'shot_withinfix reduced the frequency (2 full 12-minute runs passed cleanly), but+0x4e9b54astill occurs intermittently withVICTORY_LAZY_COMPARE_MB=64+VICTORY_LAZY_NARROW=1(likely the inherent delayed first-time shader write-back window before the rotating 128-piece sweep discovers a newly-written piece, orVICTORY_LAZY_NARROW=1allowing a read before landing). Across 6+ full 12-minute control runs withVICTORY_LAZY_*disabled on the same hardware,+0x4e9b54ahas not occurred once.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by hazben on 2026-11-28T09:56:35Z.
A measurement of the two switches of #501 (
VICTORY_LAZY_COMPARE_MB=64,VICTORY_LAZY_NARROW=1), on a build that already has #516 and #614 (called A below). The one change between the two runs is the switches.Setup: RTX 4070 SUPER, 32 GB, DLSS Quality, frame generation off. Main
8fc22547plus a local patch stack (24 commits, not upstream). A stick-steered walk of 270 s through one district with 13 marks, the same path in both runs, about 3,500-10,900 draws per frame (median per leg). One run each.What it did to the work the PR targets: the planning of steps on the card by the submitting thread goes from 6.9 to 1.8 ms per frame (the PR text says 7.4 to 1.7). The submitting thread's total goes from 49.7 to 45.5 ms.
What it did to the frames:
Nothing here is outside the noise: the base's own two runs differ by 0.55 fps (3.5 %) in fps and by 1.3 fps in the dense stretch. So on this card and route I cannot confirm the 4-6 % faster frames: the submitting thread got 4 ms cheaper and the frame did not get shorter. Likely (not checked) the frame here is limited by something other than the submitting thread's planning once #516 has removed the lock waits.
Memory: process private peak 25.10 GB (A) and 25.17 GB (A + #501); dedicated VRAM peak 8.70 and 8.62 GB. Both runs reached the end of the route with no crash, hang or device error.
Not measured: a second run of either build, a different route, a card or CPU other than this one. Unverified: that the local stack does not change these numbers.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ballsimulation on 2026-11-28T12:40:16Z.
Thanks for testing this, all of you.
hot_withinfix: pushed ase3985af9, thanks @Machad3x. It's your one-line fix, with a comment saying why the check is needed.+0x4e9b54a(thanks @POMXARK for the three runs): it's still open, so please keep both switches off for play for now. My guess is that the game's CPU reads a heap piece that shaders wrote for the first time before the sweep has found it, andVICTORY_LAZY_NARROWlets that read happen without waiting. Next I'll runVICTORY_LAZY_COMPARE_MBalone to see which switch is the cause.VICTORY_LAZY_NARROW). If #618 lands first, I'll rebase this PR onto it and keep only the narrowing.Marking this as a draft until the crash is understood.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ballsimulation on 2026-11-28T13:37:30Z.
@POMXARK, thanks again for the crash reports. I can't reproduce it here yet: an 8-minute prologue run with both switches had no crash (RTX 4070, Ryzen 9 7950X, Series X 1440p, DLSS Performance, no frame generation, main
63b902fe+ this PR). A few details from your side would help a lot.Leads so far
VICTORY_LAZY_COMPARE_MB=64, the lazy compare covers every card copy of 64 MB or more. In my run there were two: the constants heap (174 MB) and a 90 MB copy (start=0xd7a770000 len=94371840). In both of your crashes, the game read throughrbx/rdi=0xd0418…, which is in the0xd…range and not in the constants heap. So it may be the 90 MB copy: data the game's CPU reads back after shaders write it, which the lazy compare now finds late. That's a guess, since addresses differ between runs.What would help
crashes.logplus the.crash.logfrom%LOCALAPPDATA%\VIctory\data\7952987A\temp\.a buffer's host copy is in the card's memory start=… len=…withlenof 67108864 or more from that log, to see whether the crash address falls in one of those copies.VICTORY_LAZY_COMPARE_MB=128withVICTORY_LAZY_NARROW=1. This keeps only the 174 MB constants heap lazy. If it stops crashing, the 90 MB copy is the cause.VICTORY_LAZY_COMPARE_MB=64withoutVICTORY_LAZY_NARROW. This tells which switch causes it.To make runs repeatable, there's now an unattended runner,
scripts/bench.ps1(#1099). Every run starts from the same save, and it can walk a fixed route from the world's first frame (#1098).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T16:32:27Z.
@ballsimulation Here are the exact details from both saved crashing runs (
VICTORY_LAZY_COMPARE_MB=64+VICTORY_LAZY_NARROW=1).1. Card-copy addresses (
len >= 67108864)Both crashing runs were
--releaseat defaultINFOlog level, and"a buffer's host copy is in the card's memory"is emitted atDEBUG(shadow.rs), so those creation lines were not captured in the two release logs.However, the faulting register states and pre-crash
lazycounters across both runs strongly fit your 90 MiB copy hypothesis:t ≈ 3m44s, steady ~5.5k–5.8k draws/frame, beforee3985af9):0xc0000005at+0x4e9b54a(read 0xffffffffffffffff: outside the address space)rbx=0xd0418f3a8,rdi=0xd04189938,r12=0xd0c5eeb08,rcx=0x31ff84a045495676+0x4e9b54a -> +0x4e9b4bf -> +0x4a4a -> +0x4d9f49c -> +0x2484ac4 -> +0x321c5 -> +0x3346dlazyline (5 s before crash):hot=92298 forced=1097 swept=106240 left=338063 found=6748 hot_now=508t ≈ 5m48s, sharp draw transition2319 -> 4870 -> 1407 draws/frame, WITHe3985af9hot_withinfix applied):0xc0000005at+0x4e9b54a(read 0xc: nothing mapped there)rbx=0x0,rdi=0xd0418c9b0,r12=0xd080f0280,r13=0x1c46bfd6128+0x4e9b54a -> +0x4e9b4bf -> +0x4a4a -> +0x4d9f49c -> +0x188463 -> +0x6c6652 -> +0x5378c08lazystats spiked sharply during the transition:-17s:hot=40200 forced=493 swept=32768 left=172009 found=1792 hot_now=547-12s:hot=140676 forced=584 swept=70400 left=812524 found=4472 hot_now=290-6s:hot=270120 forced=1511 swept=115072 left=1595878 found=6868 hot_now=229In both independent runs,
rdi(0xd04189938/0xd0418c9b0) andr12(0xd0c5eeb08/0xd080f0280) sit in the same0xd0...region whilehot_nowwas dropping andleftwas climbing past 1.5M pieces right before the null/garbage dereference at+0x4e9b54a.2. Exact switches & branch context
VICTORY_WINDOW_KBleft unset (default4 MiBloose windows).VICTORY_NATIVE_1440P=1,VICTORY_DLSS=1,VICTORY_DLSS_MODE=quality,VICTORY_FRAMEGEN=1,VICTORY_FRAMEGEN_X=4,VICTORY_GPU_BCPACK=0,VICTORY_WAIT_RESIDENT=0,VICTORY_TEXTURE_ROOM_PERCENT=70,VICTORY_LAND_SKIP=1,VICTORY_RELAY=2,VICTORY_RELAY_COPY=1,VICTORY_CARD_STEPS=2,VICTORY_CARD_BUFFERS_MIN_KB=64,VICTORY_CARD_REHASH_RUNS=1,VICTORY_THIN=1,VICTORY_JOIN_COPIES=1,VICTORY_JOIN_PARTS=8,VICTORY_LAZY_COMPARE_MB=64,VICTORY_LAZY_NARROW=1(plus standardplay-foxhounddefaults).x86-64-v3+ ThinLTO, #516 (unlocked write-watch faults + hoistedsoft_runs), and #340 (adaptive sweep).VICTORY_LAZY_COMPARE_MBandVICTORY_LAZY_NARROWunset on the exact same branch (and across 10+ subsequent 12–20 min runs),+0x4e9b54ahas never occurred (0guest crashes).3. Next verification
I can run a targeted
VICTORY_LAZY_COMPARE_MB=128+VICTORY_LAZY_NARROW=1check (withRUST_LOG=info,victory_gpu::shadow=debugto log exactlen >= 67108864card-copy spans) in a follow-up test slot to confirm whether excluding the ~90 MiB copy eliminates the+0x4e9b54acrash.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by x-nihil0 on 2026-11-28T16:38:11Z.
RTX 5080 + Core Ultra 9 285: no crash in 19 runs with both switches (no frame generation), and the figures together with
VICTORY_STORE_BESIDEMachine: Intel Core Ultra 9 285, 64 GB RAM, RTX 5080 16 GB, driver 621.40, Windows 11. Release build of
main63b902fwith this PR atf7cc776(before thehot_withinfix) plus #419 (atkeep) and #799 (its switch off except in one run). The release launcher's set: Series X, 1440p, DLSS Quality, frame generation not made ready. Unattended runs from one save in the open world, the camera turning around a parked car: nothing is driven, so streaming at speed isn't covered.VICTORY_LAZY_COMPARE_MB=64+VICTORY_LAZY_NARROW=1all ran to their time limit with no guest exception and no device error: 2 of 600 s and 17 of 300 s, 18 of them also withVICTORY_STORE_BESIDE=1, 2 on a diagnostics build, 9 on the same build plus two tunables of mine on the store path. Like your 8-minute run, no crash here, but my route has no loads or scene changes during play, where the second crash was, and no frame generation.VICTORY_STORE_BESIDE=1on top (off by default onmain), 600 s runs in the order off, on, on, off: 23.1 / 23.2 fps at 7-9k draws against 20.6 / 20.3, and 20.5 / 20.4 at 9-11k against 18.3 / 18.5 (+11-13 %). The submitting thread went from 44-49 to 38-42 ms a frame: the refreshes from 17-19 to 12.5-13.5 ms (STORE_BESIDE), the planning from 5-8 to 1.6-2.3 ms (this PR).STORE_BESIDEalone gave +1.3-1.8 / +0.7-1.2 fps in a 300 s run of the earlier queue.I haven't run the two splits you asked @POMXARK for (
64withoutNARROW,128with it). No game files, captures or saves are attached. Made with AI help; the figures come from the run logs.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T18:22:24Z.
@ballsimulation @x-nihil0 Follow-up data point on
VICTORY_STORE_BESIDE=1from a 20-minute 3D run on RTX 5080 + Ryzen 7 5700X (8C/16T), Series X 1440p, DLSS Quality + MFG 4×,VICTORY_LAZY_*OFF, stacked on#516(VICTORY_FAULT_UNLOCKED) +#834+#1094(PageEpochs) +#1038(WATCH_LARGE_XMEM):STORE_BESIDEOFF)VICTORY_STORE_BESIDE=100ALL 3Dp50 FPS14.8012.90-12.8%4k–7kdraws p50 FPS14.80(prep 51.5 ms)11.90(prep 64.7 ms)-19.6%submittingtotal (median)61.1 ms68.2 ms+7.1 mssteps(refreshes)28.3 ms(18.4 ms)31.6 ms(19.2 ms)+3.3 ms(+0.8 ms)card/heaps_pre8.2 ms/1.4 ms10.0 ms/2.1 ms+1.8 ms/+0.7 ms1s frame_timesmed / p95 / p9962.7 / 81.3 / 92.3 ms69.7 / 90.8 / 104.5 ms+7.0 / +9.5 / +12.2 ms>100 msframes1,5552,024+30.2%Takeaway: Unlike on stock
main(whereVICTORY_STORE_BESIDE=1avoids takingGUARDS.lockon every write fault), when#516(VICTORY_FAULT_UNLOCKED) +#1094(PageEpochs) are already active, opening the block on fault is already lock-free — so decoding up to 5 faulting stores per block in the VEH (titlewrite.rs) becomes net overhead on 8C/16T + MFG 4×.Also worth noting: porting the 3 small per-draw savings from
voidopcode/vilocity@10b81fc(fromProjectLeonida/mandy/maren-halv/VIctory-Fast/DoubleGhosty/cool_fox: precomputedStage::root_srvs_biasedbitmask, cachedChunk::gpuaddress inscratch_piece, andAddressHashonStates/twins/Deferred::textures) passed 473/473victory-gputests and improved7k–10kdraws/frame10.50 -> 11.50 p50 FPS (+9.5%, prep 73.0 -> 64.9 ms)with0errors over 20 minutes.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Castyan on 2026-11-28T22:49:55Z.
Measured on an RTX 5060 8 GB / Ryzen 5 9600X, v2026.11.27.10 + #614 +
VICTORY_HELPER_PRIORITY=on,--series-s --dlss quality --framegen 2, texture pool off. Two 8-minute runs of the opening cutscene with no input, the only difference beingVICTORY_LAZY_COMPARE_MB=64 VICTORY_LAZY_NARROW=1:No visible defect on a mid-cutscene capture (animated characters, backlight through a window). Water and reflections were not in
that scene, so the "about 2 frames late" case is not checked yet. One run each, so treat the numbers as a first data point.