gpu/shadow: opt-in VEH lazy GPU-to-CPU copy-back (4/4 of #51) #59
No reviewers
Labels
No labels
accessibility
bench-bm-v1
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/PastiiJay--klbf-lab!59
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-59"
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?
@Vladimir-Human on GitHub · 2026-11-26 00:48 UTC · original
Vladimir-Human:perf/split-lazy-copyback-veh→beta· +4570 −83 · 3 files · 2 commits · openSplit 4/4 of #51 cleanly on top of
beta(78ad5711, independent of #56, #57, and #58).Summary of Changes (
host.rs,watch.rs,shadow.rs)VICTORY_LAZY_COPYBACK=1, default OFF):PAGE_NOACCESS) across GPU-to-GPU workloads so steady-state frames touch zero PCIe readback bytes, flushing individual pages on demand insidewatch's vectored exception handler (on_fault) on first CPU read/write.MEM_MAPPEDphysical views (atomic dual-view flush before restoringPAGE_READWRITE) andMEM_PRIVATE | MEM_WRITE_WATCHbuffers (serialized viaFlushWait), leaving unaligned/pinned/fence ranges eager.title_memory_writtenpartial-page complements, captures idempotentFlushedBaselinefor in-flight relay/merge paths (card_merge_relay,relay_merge,stale_under_writes,merge_under_writes), and holds scopedlazy_flush_and_hold/Remappingbarriers across remaps and host copies.Level 0: watch/Shadow -> Level 1: LAZY_TABLE -> Level 2: LAZY_GPU -> Level 3: FlushWait).shadow::lazy_copyback_tests::lazy_copyback_*unit and live-GPU coherence/stress/F1-F5 regression tests (scoped withlazy_opted_intest isolation so parallel non-lazy tests never inherit deferred state) +#[ignore] bench_lazy_copyback.Verification (
VICTORY_D3D12_DEBUG=1)cargo test -p victory-gpu(run 1 & run 2 parallel, plus serial--test-threads=1) -> all passedcargo test -p victory-gpu --all-features-> passedcargo run -p xtask -- policy --staged->asset policy: 3 files ok(host.rs= 367,393 B,watch.rs= 81,104 B,shadow.rs= 345,266 B)Related: #51, #56, #57, #58
@PastiiJay on GitHub · 2026-11-26 10:42 UTC · original
Thanks @Vladimir-Human for the last piece of the #51 split. We'll test the lazy copy-back on its own in game.
@Proudnoob4 on GitHub · 2026-11-26 15:45 UTC · original
@PastiiJay @Vladimir-Human Full 10-minute live GTA 6 visual + performance + coherence audit of #59 (
VICTORY_LAZY_COPYBACK=1) ported ontoProudnoob4/VIctory-NVIDIA(nvidia-hybrid-v2, commitf42d67b, RTX 4080 16 GB / i5-13600K / Windows 10 WDDM 2.7,VICTORY_CARD_BUFFERS_MIN_KB=64+VICTORY_FETCH_CHECK=1+VICTORY_SKIP_WC_MIN_KB=1024+VICTORY_SECTION_MB=2).1. Unit / Live-GPU Coherence Tests & Stability: 100% PASS
14/14lazy_copyback_*live-GPU + VEH tests passed on RTX 4080 (0.44s), plus3/3batch11_shadow_tests,2/2land_tests, andreads_in_place_and_remappings_wait_for_each_other.n=105settled frames,entry=101.3s,4,550draws/frame):ERROR/panic/device-removal lines,0pages not there in landing, worst frame stall112.9 ms(0stalls>55 msin tail-40).VICTORY_LAND=1/CopiedPagestrees:Shadow::watchedusesGUARDED = 3as well as1, sotry_defer_piece/lazy_resync_range/resync_pages_from_titleneedmatches!(watched_flag, 1 | GUARDED).Shadow::land_cardandShadow::land_back(VICTORY_LAND=1/VICTORY_LAND_BESIDE=1) needlazy_flush_and_holdaroundland::piece(otherwisebesidealias writes bypass aPAGE_NOACCESStitle VA) pluslazy_apply_flushed_baselinewhenresync_count > 0.lazy_prepare_update/update_freeclearingcopied[idx] = 0must also invalidateself.ranged, andcopy_stalemust skipself.rangedupdates whiledeferred_count > 0.2. Visual Verification (Same Cell Scene,
VICTORY_LAZY_COPYBACK=0vs=1): 100% CLEANt=140..600s(n=230frames at 0.5 fps):BLACK=0/230(0.0%),BRIGHT=229,DARK=1(140s transition).t=240s,t=540s) and two 60-frame 4 fps burst contact sheets (t=420..435s,t=520..535s,120/120frames): visually indistinguishable fromVICTORY_LAZY_COPYBACK=0— frosted/refracted cell window glass behind Lucia's hair, yard inmates visible through chain-link fence, warm golden lighting, wall photos/bunk intact, zero flicker, zero tearing, zero missing geometry.3. Live 10-Minute Performance Comparison (
VICTORY_LAZY_COPYBACK=0vs=1)LAZY=0(Pass 15 baseline)LAZY=1(Pass 17)32.00 fps(31.3 ms)21.45 fps(46.7 ms; ALL21.80)317(4.5 MB4K,0.84 MBdwords)225(2.2 MB4K,0.42 MBdwords)CARD)3.99 ms0.92 mswhich pieces to fetch)< 1 ms13.73 ms23.9 ms/7.1 ms34.1 ms/21.6 ms(42.7 MB)victory-submitworked32.8 ms36.3–39.0 ms61%58%(15.4 msidle behind submit)Steady-state
lazy copy-back per frametelemetry (TAIL40medians):126.5pages armed steady-state (73.4steady hits/frame — these truly stay GPU-resident!)22.7newly armed/frame vs22.7total flushes/frame (4.3VEH read faults +11.2VEH write faults +7.2explicit flushes =1.42 MB/frameflushed!)VICTORY_FETCH_CHECK=1:218.2checked,8.09torn,8.03recovered whole.4. Exact Root Cause of the Regression & 2 Clear Fixes for v2
The mechanism is 100% coherent and visually clean, and it genuinely cuts copy-back pieces by
-29%(317 -> 225) and merge time by-3.07 ms(3.99 -> 0.92 ms). All of the+15.4 msoverhead comes from two measurable hot spots:22.7 armed/frame=22.7 flushes/frame): The same ~23 hot pages get armed on frameN, then immediately hit a VEH read/write fault (15.5/frame) or explicit host flush (7.2/frame) on frameN+1, triggering ~23 synchronous single-pageLAZY_GPUExecuteCommandLists+WaitForSingleObjectroundtrips AND resettingcopied[idx]=0/ranged(causingcopiesto jump7.1 -> 21.6 ms!).which pieces to fetch(13.73 ms/frame):try_defer_piece_relayrunsVirtualQuery+watch::is_guarded+inplace::pages_of+VirtualProtect+GetWriteWatchon every non-deferred piece (~225 pieces/frame) on the relay thread, every frame!Suggested v2 improvements:
lazy_state[idx] = LAZY_PINNED_HOT(cooldown or permanent for that shadow) sonewly_armedand synchronous GPU readback flushes drop from22.7/frame -> ~0/framewhile keeping the~126genuinely cold GPU-only pages armed!LAZY_INELIGIBLE(O(1) fast reject): SkipVirtualQuery/pages_of/GetWriteWatchon pages already known ineligible (partial/unwatched/aliased/hot) in 1 atomic load sowhich pieces to fetchdrops back from13.73 ms -> < 0.5 ms.Keeping
VICTORY_LAZY_COPYBACKOFF by default on our branch (f42d67b, pushed toProudnoob4/VIctory-NVIDIAnvidia-hybrid-v2) and happy to re-run the exact same 10-minute test as soon as a thrash-cooldown + fast-reject patch lands!@PastiiJay on GitHub · 2026-11-26 15:47 UTC · original
Thanks @Proudnoob4, a 10-minute coherence check with zero faults plus a clean visual A/B is exactly the evidence this PR needed, and pinning the slowdown on the ~23 hot pages re-armed every frame and the gather cost gives a clear target. @Vladimir-Human, the two fixes in section 4 look like the v2 plan; once they are in, the same A/B on the same scene would tell us whether lazy copy-back can pay off.
@Proudnoob4 on GitHub · 2026-11-26 16:50 UTC · original
@PastiiJay @Vladimir-Human Quick cross-machine follow-up on
#59(VICTORY_LAZY_COPYBACK=1):@d0devjust tested our audited port (f42d67b,Proudnoob4/VIctory-NVIDIA) on RTX 4070 Ti SUPER 16 GB / Ryzen 7 5800X3D / 32 GB / Windows 11 26200 (first boat mission, reported infxceless/victory-fork#1268) and hit a real VEH escape crash ~2.5 min after launch right after entering the world:0xc0000005 at victory-image-…dll+0xc4b94e (write 0xfaff804: no access), then the same at0xfaffc0427.5 newly armed, 61.8 steady hits, 1.3 VEH read faults, 16.0 VEH write faults, 9.8 explicit flushes (1.70 MB), 160 pages armed nowWorth flagging for v2 alongside the hot-page churn / gather cost — on Win 11 / 5800X3D a title write to an armed page escaped the VEH handler (possible race between re-arming/unarming or
PAGE_NOACCESSwindow across concurrent title threads). Passing along the exact numbers so it's on your radar before merge!@PastiiJay on GitHub · 2026-11-26 16:58 UTC · original
Thanks @Proudnoob4, a write escaping the handler on a second machine is exactly the kind of thing v2 needs to know before anyone enables it. @Vladimir-Human, the crash address and the stats line above are worth a regression test on the re-arm path.
@Vladimir-Human on GitHub · 2026-11-26 18:50 UTC · original
@PastiiJay @Proudnoob4 Thanks for the exact crash details from
@d0dev(0xc0000005on writes at0xfaff804/0xfaffc04under concurrent re-arm / guard transitions). Pushedc0ccb1btoperf/split-lazy-copyback-vehaddressing the VEH escape and adding the requested regression coverage:watch.rs,shadow.rs):LAZY_TABLE_EPOCHtracking aroundLAZY_TABLEstate changes and bounded epoch retry inwatch::on_fault(MAX_EPOCH_RETRIES = 32gated oncommitted_protect(at).is_some(), zero spinning on unrelated faults).lazy_on_fault'sErr(Some(epoch_before))branch to handlePageAccess::AccessiblewheneverLAZY_FLUSH_TOTAL > 0 || LAZY_TABLE_EPOCH > 0(covering READ faults during arming rollbacks before any flush has completed) and retryPageAccess::NoAccesswhenLAZY_TABLE_EPOCHadvances.shadow.rs):unprotect_split_subregions/copy_subregion_bytesso partial 4 KiB VAD splits inside an armed 64 KiB block unprotect every committedPAGE_NOACCESSsub-region and populate trailing offsets (+0xf804,+0xfc04) without touching adjacent non-NOACCESSsub-regions.shadow.rs):>= 2flushes within 60 frames ->300-frame cooldown ->1800-> permanentLAZY_INELIGIBLEsentinelu32::MAX, with timed cooldowns clamped tou32::MAX - 1), immediateLAZY_INELIGIBLEcaching for non-MEM_WRITE_WATCHprivate allocations /pinned/ unsupported VAD types (while keeping virgin Frame-1MEM_WRITE_WATCHdemand-zero pagesLAZY_EAGERfor Frame 2), monotonicfetch_maxonAliasedLAZY_HOT, andLAZY_RESYNCAcquireordering beforelazy_post_resync_state.VICTORY_D3D12_DEBUG=1on WARP / unit & GPU-compute harness):lazy_copyback_veh_rearm_and_guard_transition_race_never_escapes,lazy_copyback_split_subpage_unprotect_restores_all_4k_subpages(2AMEM_PRIVATEVEH, 2BMEM_MAPPEDlazy_flush_range, 2Clazy_release_range&lazy_release_written_range), andlazy_copyback_v2_hot_page_cooldown_and_ineligible_fast_reject.cargo clippy -p victory-gpu --all-targets: 0 warnings inshadow.rs/watch.rs.cargo test -p victory-gpu -- --test-threads=1: 171 passed; 0 failed; 4 ignored.Ready for Pass 18 cross-machine verification.
@PastiiJay on GitHub · 2026-11-26 18:57 UTC · original
Thanks @Vladimir-Human, that was quick, and the split sub-region case at
+0xf804/+0xfc04matches the crash addresses exactly. @Proudnoob4, could@d0devrerun the same first boat mission onc0ccb1bwithVICTORY_LAZY_COPYBACK=1and post the last stats line plus how long it held? That run decides whether v2 is ready for us to try.@Proudnoob4 on GitHub · 2026-11-26 20:24 UTC · original
@PastiiJay passed on to @d0dev in fxceless/victory-fork#1268 (their crash came from that run): rerun of the first boat mission on
c0ccb1bwithVICTORY_LAZY_COPYBACK=1, last stats line to be posted here. We can't reproduce it ourselves yet: our runs haven't reached the boat.AI-assisted (Claude Code).
@PastiiJay on GitHub · 2026-11-26 20:27 UTC · original
Thanks @Proudnoob4 for passing it on. We'll wait for
@d0dev's line here before touching v2.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.