gpu: opt-in lazy GPU write-back (VEH), O(dirty) CopiedPages, AVX2 shadow & AdapterKey PSO (vitutu1#20 handover) #51
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T21:40:57Z.
Summary
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
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:43:30Z.
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.Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T21:53:19Z.
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
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:54:39Z.
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?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T23:13:26Z.
@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.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T23:14:56Z.
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.Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T23:43:35Z.
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).Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T23:44:08Z.
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.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-26T00:48:11Z.
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: https://github.com/PastiiJay/klbf-lab/pull/57D3D12_HEAP_TYPE_GPU_UPLOAD) + VRAM headroom guard & WC streaming helpers: https://github.com/PastiiJay/klbf-lab/pull/58Leaving #51 open until you'd like to close it once the split queue lands.
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T00:49:06Z.
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.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T08:33:29Z.
Backported the concurrency hardening identified by
@efsebayernand@TaynanGT(TaynanGT/Vice-Tay#192,c289a95) in5810d6b:self.copiedacross copies inShadow::copy_stale: keeps thecopiedmutex locked fromplan_stale/plan_stale_filteredthroughself.copy(...)so concurrent refreshes cannot observe stampedat == nowpages before their bytes land or race on writingself.data.card_dirty: returns early when!c.has_dirtyinstead of locking and pruningc.senton clean copies.Verified locally on Windows (
VICTORY_D3D12_DEBUG=1):cargo clippy -p victory-gpu --all-targets&--features diagnostics: 0 warnings incrates/victory-gpu/src/shadow.rs(only pre-existing upstream warnings in untouched files)cargo test -p victory-gpu --lib shadow:: -- --test-threads=1:48 passed; 0 failed; 2 ignoredcargo test -p victory-gpu --features diagnostics --lib shadow:: -- --test-threads=1:48 passed; 0 failed; 2 ignoredImported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T09:52:37Z.
Thanks @Vladimir-Human, and credit to @efsebayern and @TaynanGT for the hardening. We'll review it with the next beta batch. Could you rebase on the current head if it no longer merges cleanly by then?
Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T09:58:18Z.
@PastiiJay I checked
5810d6bagainst the currentbetaat6cce57e. The merge is clean as of that revision. For the beta baseline, the lock-scope fix protects the ordinary shadow refresh too, so the first run with lazy write-back and ReBAR off will still exercise it.Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T10:44:19Z.
Thanks @PastiiJay and @TaynanGT! Confirmed
5810d6bmerges cleanly against currentbeta(6cce57e), and I am ready to rebase whenever the next beta batch lands.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:50:22Z.
Thanks @Vladimir-Human, and @TaynanGT for the earlier testing. Lazy write-back is the riskiest of the batch, so we're reviewing it carefully and won't merge it in a rush. Could you post your GPU and driver with the
VICTORY_LAZY_COPYBACKsetting you used?Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T10:51:38Z.
@Vladimir-Human I’ll keep
6cce57eas the verified beta reference and check the new beta head once the next batch lands.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:52:02Z.
We'll take them onto the AMD line one at a time with an A/B bench. Thanks, the tests you added make that much easier.
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T10:53:15Z.
We don't merge PRs directly, to keep the line safe. But we'll port the best of your work ourselves, one piece at a time with an A/B bench, and credit you by name. Thanks for the careful work across these PRs.
Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T10:58:56Z.
@PastiiJay The copy-lock change is isolated in Vice-Tay #192 if you want that piece first. It is a narrow starting point for the beta port and keeps the lazy write-back and pipeline library experiments separate.
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T11:11:34Z.
checked it against our AMD line: our copy_stale already holds
copiedfor the whole copy and card_dirty has no dirty/sent split, so that race isn't there. thanks for pointing at it, it was worth the check.Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T11:16:48Z.
@PastiiJay Use the current AMD copy path as the baseline for the lazy write-back comparison. Your lock-scope check establishes the starting point for that port.
Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-27T11:30:23Z.
Thanks @TaynanGT, that's a good idea. Our current AMD copy path will be the reference for the before/after bench when we pick up the lazy write-back.
Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T11:42:27Z.
@PastiiJay That AMD path is the reference I’d use. On the same frame window with ReBAR off in both runs, record transferred bytes and queue waits along with frame time. That will show whether lazy write-back changes traffic or just moves the wait.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-27T12:07:22Z.
Quick note for that A/B comparison @PastiiJay @TaynanGT:
#59(7311cab) now logsMB read back,explicit flushes, VEH read/write faults, andself-bypassedon the 5s line wheneverVICTORY_LAZY_COPYBACK=1(in both release and diagnostics builds, zero output when off). Happy to backport that same counter line into#51too if you benchmark the combined branch.Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-27T12:13:38Z.
@Vladimir-Human The #59 counters give us useful detail for the lazy arm. Let’s use the same readback and queue-wait totals in both arms, then use the extra counters to explain the lazy run. The backport can stay separate until we compare the combined branch.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:42:25Z.
Closing rollup PR: cleanly split and ported onto
origin/stable-amd(75022ba) across #180 (1/4), #184 (2/4), #185 (3/4), and #190 (4/4).Imported from PastiiJay/klbf-lab. Originally posted by TaynanGT on 2026-11-29T11:25:39Z.
Thanks for splitting the rollup onto stable-amd and preserving the individual changes. The separate PRs make it easier to evaluate lazy copyback, shadow bookkeeping and PSO changes independently.
Pull request closed