gpu: opt-in lazy GPU write-back (VEH), O(dirty) CopiedPages, AVX2 shadow & AdapterKey PSO (vitutu1#20 handover) #51
No reviewers
Labels
No labels
accessibility
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!51
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-51"
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-25 21:40 UTC · original
Vladimir-Human:perf/lazy-copyback-rebar-pso→beta· +6734 −511 · 4 files · 3 commits · openSummary
AI-assisted handover and major reliability/performance upgrade of
vitutu1/victory-perfPR #20 (since that repository is now unavailable), bringing four opt-in / zero-regression subsystems ontoPastiiJay/klbf-labbeta:VICTORY_LAZY_COPYBACK=1, default OFF):PAGE_NOACCESSand an acyclic VEH fault handler (lazy_on_fault, never acquiring Level 0watch/Shadow/BUFFERS/CARD_WORK/host.submittedlocks); flushes only actually accessed 64 KiB pages on demand, using atomic dual-viewMapViewOfFilewrites before restoringPAGE_READWRITEfor section-backedMEM_MAPPEDconsole heaps (zero torn-read window).title_memory_written(lazy_release_written_rangewith partial-page complement copy and pending-writeFlushedBaselinepreservation),VICTORY_RELAY/late_exact(Shadow::writingpending carve-out,stale_under_writes/merge_under_writessettle onLAZY_RESYNC,Step::GpuWritesettle instale_under_flights),host::{copy_mapped, read_into, write_mapped}lazy_flush_and_holdrange barrier, multi-flightFlushedBaselinesubrange consumption, overlappingShadow::exact/ nested views (lazy_flush_other_shadows),shadow::unregister, andwatch::Remapping(LazyRemapGuard).0overhead, unchanged paths) unlessVICTORY_LAZY_COPYBACK=1is set.CopiedPages& AVX2 Shadow/Merge Acceleration:uncopied_bitsbitmask and lock-releasedplan_stale/plan_stale_filtered, plus AVX2first_difference/last_difference,changed_runs,merge_piece,merge_sync_card,merge_gpu_into_title_runs, andmerge_back_piece(preserving title-wins conflict handling).VICTORY_REBAR=1|2, default OFF):D3D12_HEAP_TYPE_GPU_UPLOADpath with write-combining fences (_mm_sfence()after WC stores;_mm_mfence()+VMOVNTDQA+ RAIIMfenceOnExitfor reads).AdapterKey):pipeline/library.rscache filenames by(vendor, device, revision, software)({:04x}-{:04x}-r{:02x}-{sw|hw}) with strictRelease/Acquirepublish ordering (VIEW[1]/LOADED_AT/TRIMMEDbeforeVIEW[0]). Subsystem ID and driver version are deliberately omitted from the filename key so driver updates reopen the same file and fall back cleanly to an empty library if D3D12 rejects old blobs.Verification (
6b174ce6f, monotonic hardening on top of7d31a81e)host.rs,pipeline/library.rs,shadow.rs,watch.rs;shadow.rs= 410,902 B < 512 KiB),xtask policy --stagedexit 0, cleanmerge-treevsbeta(78ad571).cargo clippy -p victory-gpu --all-targets --locked(+--all-features): 0 warnings in all modified/added code.VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked --all-features -- --test-threads=1: 185 passed; 0 failed; 5 ignored (0 D3D12 debug errors; includes all F1–F5 + 5 relay/VEH concurrency regression tests).VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- --test-threads=1: 177 passed; 0 failed; 5 ignored (0 D3D12 debug errors).--releaseRTX 4070 SUPER / i5-13400F benchmarks (7d31a81e):bench_lazy_copyback(64 MiB carded VRAM, 30 frames):0%CPU reads37.299 -> 0.585 ms/frame(63.78x,0.00 MB/freadback/upload,0.0VEH faults/f);2%sparse CPU reads37.454 -> 9.001 ms/frame(4.16x,1.25 MB/f,20.0faults/f).bench_shadow_and_rebar:plan_stale11.4 ns/call, 64 MiB AVX2first+last0.38 ms(175.5 GB/s), ReBARGPU_UPLOAD32 MiB write+SFENCE3.10 ms(10.8 GB/s).(Completes 10/10 open
vitutu1/victory-perfPR handovers ontoPastiiJay/klbf-labbeta: #15, #16, #29, #41, #42, #43, #44, #46, #50, and this PR.)Co-Authored-By: AI Assistant
Backport six lazy copy-back and ReBAR hardening fixes plus five regression tests to victory-gpu: - shadow::try_defer_piece: set restore_rw immediately after watch::transition_clean_guard_to_noaccess succeeds so a subsequent was_written_since rejection always rolls MEM_MAPPED pages back from PAGE_NOACCESS to PAGE_READWRITE. - shadow::{writing, update, update_free} & host::stale_under_flights: carve out page-expanded self.pending subranges before resyncing overlapping shadows or LAZY_RESYNC pages so in-flight relay merges keep self.data and FlushedBaseline intact; add Shadow::has_lazy_resync_under_writes and wire Step::GpuWrite into host::stale_under_flights. - shadow::merge_under_writes: re-check per-page lazy_state before and after host::read_into so mid-loop LAZY_RESYNC transitions settle in-flight flights instead of diffing flushed GPU bytes against stale staging or snapshot data. - shadow::lazy_release_written_range: when full_cover and shadow.writes_pending() hold (including post-unprotect re-check), capture GPU bytes into FlushedBaseline without writing them to title memory so in-flight merges preserve fresh full-page writes. - shadow::lazy_flush_and_hold & host::{copy_mapped, read_into, write_mapped}: hold a scoped non-arming LazyRemapGuard range barrier across host reads and writes to prevent concurrent relay re-arming (inert with zero locking when VICTORY_LAZY_COPYBACK is off). - shadow::rebar::{reserve_bytes, reserve_with_card}: replace deprecated AtomicU64::fetch_update calls with compare_exchange_weak loops.@PastiiJay on GitHub · 2026-11-25 21:43 UTC · original
Thanks a lot @Vladimir-Human, and again for carrying vitutu1/victory-perf #20 over with credit. What we keep: lazy GPU write-back (
VICTORY_LAZY_COPYBACK=1) and the ReBAR upload path (VICTORY_REBAR) are both off by default; the O(dirty)CopiedPageswith AVX2 merges and the adapter-keyed pipeline library are always on; and thevictory-gpusuite passes on your side with the D3D12 debug layer, plus the rest of the workspace.Since we test one change at a time on the RX 9070 XT, we'll run it in steps: first the PR with both switches off (that measures the always-on parts), then
VICTORY_LAZY_COPYBACK=1alone, thenVICTORY_REBARalone, each against our reference build for fps, picture and stability, and post each result here. If it's easy for you, splitting the always-on parts and the two opt-in switches into separate PRs would make it simpler to merge what works on its own; no obligation, we can also test it as it is.@HandshakeHackin on GitHub · 2026-11-25 21:53 UTC · original
I verified the pipeline-cache part of
7d31a81on hosted Windows. The adapter-filename and legacy-fallback tests passed. I then ran the WARP child directly and required it to save and reload its compute pipeline. It wrotehost-pipelines-1414-008c-r00-sw.bin(1,874 bytes) in each of two temporary directories. Both the synthetic hardware-named file and the unsuffixed legacy fixture retained their original bytes. Windows test logOne detail for the PR summary and driver-update retests: the filename key here uses vendor ID, device ID, revision and the software/hardware flag. It omits the subsystem ID and driver version. A driver update can therefore reopen the same filename; D3D12 can reject the old contents and the code then starts an empty library. Adapter key · Rejected-cache handling
@PastiiJay on GitHub · 2026-11-25 21:54 UTC · original
Thanks @HandshakeHackin, confirmed on our side: the key in
7d31a81is vendor, device and revision (plus the software flag), and the code comment says leaving out the driver version is deliberate, so old caches aren't orphaned on a driver update. So the code looks intentional and it's the PR summary that lists subsystem and driver too.That matters for our testers, since the pipeline pre-build is long: after a driver update the same file is reopened, and if D3D12 rejects it the library starts empty. When we test #51 we'll include one run right after a driver update to see that case. @Vladimir-Human, could you align the summary with the code when you have a moment?
@Vladimir-Human on GitHub · 2026-11-25 23:13 UTC · original
@PastiiJay @HandshakeHackin Thank you both for the thorough check and feedback!
AdapterKey): Updated item 4 in the PR description to state the exact filename key used inpipeline/library.rs:(vendor, device, revision, software)({:04x}-{:04x}-r{:02x}-{sw|hw}), deliberately omitting subsystem ID and driver version so driver updates reopen the same cache file and fall back cleanly to an empty library if D3D12 rejects old blobs.6b174ce6f9on top of7d31a81ed4): While auditing concurrency edge cases across ports, we caught and fixed 6 subtleVICTORY_LAZY_COPYBACK=1/VICTORY_RELAYedge cases and added 5 targeted regression tests incrates/victory-gpu/src/{shadow.rs,host.rs}:restore_rw = trueimmediately ontransition_clean_guard_to_noaccessbefore checkingwas_written_since(prevents strandingPAGE_NOACCESSon concurrentMEM_MAPPEDwrite races).self.pendingranges duringShadow::writing/lazy_resync_range/lazy_prepare_updateand includeStep::GpuWriteinstale_under_flightswhenwrites_pending() && has_lazy_resync_under_writes().is_lazy_held/LAZY_RESYNCper-page before and afterread_intoinsideShadow::merge_under_writes.FlushedBaseline(without overwriting title memory) on full-pagetitle_memory_writtenwhenshadow.writes_pending()is true.LazyRemapGuardbarriers acrosshost::{copy_mapped, read_into, write_mapped}to close concurrent relay re-arming TOCTOU.AtomicU64::fetch_updatecalls inrebarwithcompare_exchange_weakloops (0warnings on newerrustc).D3D12_DEBUG=1): 185/185 (--all-features), 177/177 (default features),0D3D12 debug errors,0clippy warnings in modified files,shadow.rs= 410,902 B (< 512 KiB),xtask policy --stagedexit0.CopiedPages+AVX2 /AdapterKeyPSO /VICTORY_LAZY_COPYBACK=1/VICTORY_REBARinto separate PRs if that helps after your queued RX 9070 XT checks — just let me know! Meanwhile both new paths (VICTORY_LAZY_COPYBACK,VICTORY_REBAR) stay off by default so baseline behavior is easy to A/B test.@PastiiJay on GitHub · 2026-11-25 23:14 UTC · original
Thanks a lot @Vladimir-Human, quick and thorough. What we keep: the summary now matches the cache key in the code,
6b174ce6f9hardens six lazy-copyback / relay edge cases with five new regression tests, and both opt-in paths stay off by default.On splitting: yes please, when it's convenient for you. Separate PRs for
CopiedPages+AVX2, the adapter-keyed pipeline library, lazy copy-back and ReBAR would let us run each one on the RX 9070 XT on its own and merge what works without waiting for the rest. We'll post results in each PR.@Vladimir-Human on GitHub · 2026-11-25 23:43 UTC · original
Uncontested
--releasebenchmark on idlei5-13400F/RTX 4070 SUPERafter hardening commit6b174ce6:bench_lazy_copyback(64 MiB carded VRAM):0%CPU reads37.868 -> 0.566 ms/frame(66.88x,0.00 MB/freadback/upload,0.0VEH faults/f);2%sparse CPU reads37.524 -> 8.622 ms/frame(4.35x,1.25 MB/f,20.0faults/f).bench_shadow_and_rebar:plan_stale(160 MiB, 4 dirty)11.1 ns/call; 64 MiB AVX2first+last0.40 ms(169.6 GB/s),merge_piece4.58 ms,changed_runs5.26 ms; ReBARGPU_UPLOAD32 MiBwrite+SFENCE3.09 ms(10.9 GB/s).@PastiiJay on GitHub · 2026-11-25 23:44 UTC · original
Thanks @Vladimir-Human, good to have the micro-benchmarks: lazy copy-back going from ~38 to ~0.6 ms/frame when the CPU reads nothing is a big ceiling. The real test is in-game though, so we'll see how much of that survives on the RX 9070 XT once the split PRs land.
@Vladimir-Human on GitHub · 2026-11-26 00:48 UTC · original
Split #51 into 4 clean, independent PRs on
beta(each passesVICTORY_D3D12_DEBUG=1tests +xtask policy --staged, with zero cross-dependencies so they can be merged or reverted individually):CopiedPagesO(dirty) bitmask, lock-freehas_pending/has_dirty/has_sentmirrors, AVX2 merge/diff &WideDone: #57D3D12_HEAP_TYPE_GPU_UPLOAD) + VRAM headroom guard & WC streaming helpers: #58Leaving #51 open until you'd like to close it once the split queue lands.
@PastiiJay on GitHub · 2026-11-26 00:49 UTC · original
All four parts received (#56-#59), that's much easier to test. We'll go through them one at a time on the RX 9070 XT, starting with #56 and #57, and report in each PR. Closing #51 once they land is fine.
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.