Reduce CPU lock contention across shadow merges, refreshes, and card sync #1157
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1157"
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 mikael-jarvinen on 2026-11-28T14:30:04Z.
Summary
Reduces CPU lock contention and per-submission overhead across the landing, refresh, batching, and card-sync hot paths:
64-stripe
Shadow::merginglocks (crates/victory-gpu/src/shadow.rs):Shadow::mergingRwLock<()>with a lazily initialized 64-stripe array indexed by 64 KiB page (page & 63) and bitmask lock helpers (merge_read_mask/merge_write_mask).merge_under_writeslocks only the single stripe for each page it touches instead of blocking concurrent landings on unrelated pages of the same large heap copy.wide()'s mutex+condvar completion counter with an atomicAtomicUsize+park/unpark, shares oneArcclosure acrosswide_eachworkers instead of cloningArcper item, skipsby_partswhenparts_writtenis empty, switchesShadow::taketo AVX2-acceleratedword_runs, and lowerscopy_allparallelization threshold to> 512 KiBwith>= 4ranges.Unified
Shadow::copy_stateRwLock+ batchedwatch::JournalRead& lock-freeKEPT(crates/victory-gpu/src/shadow.rs,crates/victory-gpu/src/watch.rs,crates/victory-gpu/src/host.rs,apps/victory/src/play.rs):Shadow::copiedandShadow::rangedunder oneRwLock<CopyState>so concurrentnothing_newchecks share read access instead of serializing on two mutexes.watch::JournalRead(amortizingJOURNALread lock acrossBatch::refresh_frontandBatch::flush_all), an atomicKEPTmirror (watch::is_kept()) to skip redundantask_ahead/ask_ahead_donework whileask_oncestands, sorted/merged binary search inahead_contains, 64-bit word scanning inBlocks::all_set(), andyield_now()in unlocked guard-fault waits (VICTORY_FAULT_UNLOCKED=1enabled inplay.rs).Batched card-step CBV updates,
Batchhot-path dedup, and merged card sync (crates/victory-gpu/src/descriptor.rs,crates/victory-gpu/src/descriptor/host.rs,crates/victory-gpu/src/host/card_steps.rs,crates/victory-gpu/src/host.rs):descriptor::constant_slotcalls withdescriptor::constant_slots_batch+HostHeap::constant_at_with_base(oneSHADER_HEAPSread lock, cached lastHostHeap, hoisted base GPU VA) and pre-buckets 8-way parallel CBV updates once before spawning workers.Batch::last_aheadcache and single-passBatch::note_gpu_writededuplication (buildingdeclaredinline and skipping redundantShadow::writinglocks and a second step walk).CARD_WORKlock scope incard_beforeand batchessyncinto the mainExecuteCommandListssubmission whenflown && relay_copy().Verification
cargo clippy -p victory-gpu -p victory --all-targets --locked— 0 warnings in touched codecargo clippy -p victory-gpu --all-targets --all-features --locked— 0 warnings in touched codecargo test -p victory-gpu --lib --locked— 453 passed, 0 failedcargo xtask policy— 294 files okcargo build --release -p victory— clean release build (0 warnings)A/B Benchmark vs
origin/main(63b902f)Tested on RTX 3080 10 GB, 1440p DLSS Performance, identical 115 s scripted launch (
VICTORY_WARMUP_RESTART=0,VICTORY_POOL_STATS=1,VICTORY_KEYS=25:Enter,...,55:Enter):origin/main(63b902f)833e4fd)wait_title_bytes(last 2 windows)11.36 / 8.29 ms0.46 / 0.44 msmerge_all(last 2 windows)18.01 / 16.87 ms7.43 / 7.97 msmerge_wall(last 2 windows)6.02 / 5.83 ms3.80 / 3.40 msbacktime9.9–13.8 ms8.5–8.6 msunder(merge_under_writes, last 5)6.1–8.3 ms3.6–6.5 mscard(card_before+card_steps, last 5)5.1–6.2 ms3.9–4.9 msprepmedian (5k-draw best)33.5 ms(28.6 ms)31.7 ms(25.1 ms)−3.5 ms)copiesmedian15.6 ms14.4 ms00(Note: During the PR run Windows DXGI dynamically lowered the process VRAM budget to
8,207 MBvs8,679 MBin baseline, increasing GPU wait on unpatched 10 GB VRAM; all CPU-side metrics improved substantially across every phase.)Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cxy0072019-sketch on 2026-11-28T15:01:28Z.
Tested
63b902fand833e4fdon an RTX 5070 Ti 16 GB and i5‑14600KF under Windows. Both diagnostics release builds used a copy of the same Series S Gear Up checkpoint at 1920×1080 output, 720p internal, with DLSS and frame generation off. The initial emulator caches had identical SHA‑256 manifests, and each run began with its own driver cache. The candidate uses theVICTORY_FAULT_UNLOCKED=1preset from the PR.63b902f833e4fdThese are the last three matched-camera windows after pipeline compilation settled, totaling 8 and 9 complete five-second samples. CPU preparation was lower in all three windows. The two runs showed the same visible character, house, and water rendering in the sampled view. This is one restart pair in one scene. Test automation and analysis were AI-assisted.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Aniseto on 2026-11-28T15:20:39Z.
Ran the full
victory-gpulibrary suite at833e4fdon an NVIDIA Blackwell desktop part:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (48a229cea 2026-09-01, pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.The count matches the author's suite run. Tests cover the striped merge locks, the batched journal reads and lock-free
KEPTpath among the rest of the crate. This is a correctness run, not an FPS or latency measurement; the PR's 115 s scripted A/B on an RTX 3080 was not repeated here. The thread already has a 5070 Ti A/B from another tester; this adds an independent full-suite count.Not tested: a retail title, FPS/latency A/B, a paired smoke run, the whole workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the command above, wrote this report; the worktree was not modified; no game data was used.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T16:51:53Z.
@mikael-jarvinen
Tested a selective port of the five pieces of this PR that do not overlap with
#1094(keeping lock-free 3-levelPageEpochs, SeqLockranged, single-lockwide_each_scoped, andArccard_dirty) on an RTX 5080 + 8C/16T CPU.Test Setup & Honest Disclosure
4 MiBwindows, warm shader cache.v2026.11.28.02(2a66ef1) + AVX2/ThinLTO +#516+#340+#81+#666+#801+#834+#1094+#1038(WATCH_LARGE_XMEM=1).Shadow::merginglocks +copy_staleempty-map skip + atomicDoneinwide().descriptor::constant_slots_batch+ 8-way parallel CBV updates.Batch::last_ahead1-entry cache + single-passBatch::note_gpu_write.CARD_WORKlock + mergingCardPlan::syncinto the mainExecuteCommandLists(flown && relay_copy()).Blocks::all_set()64-bit word scan + unlockedguard()fast path.submitting threadmedians are reported below.Results (
232/232victory-gpurelease tests PASS; 20-minute run,0errors)#1094+#1038)001k–4kdraws p50 FPS18.80(copies 16.4 ms)15.60(copies 17.5 ms)-17.0%4k–7kdraws p50 FPS15.40(copies 21.3 ms)13.10(copies 26.6 ms)-14.9%7k–10kdraws p50 FPS10.50(copies 39.5 ms)10.00(copies 40.9 ms)-4.8%submittingtotal (median)57.7 ms68.1 ms+10.4 msunder(shadow merge lock)3.4 ms4.8 ms+1.4 mssteps(refreshes)27.9 ms(17.5 ms)31.2 ms(21.7 ms)+3.3 ms(+4.2 ms)card/send8.5 ms/1.9 ms7.7 ms/2.5 ms-0.8 ms/+0.6 msheaps_pre/heaps_end1.0 ms/0.7 ms1.7 ms/1.1 ms+0.7 ms/+0.4 ms1s frame_timesmed / p95 / p9961.0 / 80.4 / 90.4 ms67.7 / 93.7 / 107.8 ms+6.7 / +13.3 / +17.4 msObservations & Takeaway
0D3D12/engine/guest errors and clean visuals across the entire 20-minute run (232/232unit tests PASS).#1094:carddropped8.5 -> 7.7 ms(-0.8 ms), butsendrose1.9 -> 2.5 ms(+0.6 ms), leaving near-zero net gain (-0.2 ms) from mergingCardPlan::syncintoExecuteCommandLists.#1094already eliminating contention onPageEpochs/ranged, acquiring bitmask-indexed stripes across the 64-entryShadow::mergingarray raisedunder(3.4 -> 4.8 ms), and the 8-way parallel CBV descriptor batching increased thread wakeup/sync overhead (heaps_pre + heaps_end:1.7 -> 2.8 ms).PAGE_GRAPHICS_READONLY/XMEM_CPUallocation classes atXMemAlloc*time (skipping GPU readback/shadow tracking on read-only or CPU-only pages) and using D3D12 Relaxed Format Casting (CreatePlacedResource2) / Enhanced Barriers where console views alias without needing separate host shadow copies.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mikael-jarvinen on 2026-11-28T18:30:35Z.
Thanks @POMXARK for catching the 8-way parallel CBV regression (and @cxy0072019-sketch and @Aniseto for the independent 5070 Ti runs)!
Live
VICTORY_ABconfirmation & fix pushedWe wired an in-process
VICTORY_ABtoggle on the 8-wayconstant_slots_batchfan-out (ops.len() >= 256) and ran a paired 10-phase standing-scene A/B at ~6,780 draws/frame on RTX 3080 10 GB (Series X 1440p, DLSS Performance, FG off):constant_slots_batchmodeprepplanheaps(pre+end)>= 256)+1.64 ms)+1.34 ms)+2.40 ms)+1.96 ms)+0.46 ms)+0.54 ms)Your diagnosis was spot-on: once
constant_slots_batchacquiresSHADER_HEAPSonce and caches theHostHeap, fanning out>= 256slots into 8Vecs across worker threads adds more scatter/wakeup/cache-line overhead than it saves.pr-cpu-merging-stripes-and-batch: Removed the 8-way parallel fan-out incrates/victory-gpu/src/host/card_steps.rs, runningconstant_slots_batchinline directly.cargo test -p victory-gpu --lib(453 passed, 0 failed),cargo xtask policy(294 files ok).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mikael-jarvinen on 2026-11-28T18:48:33Z.
Follow-up after a second live in-process
VICTORY_ABsweep on RTX 3080 (~6,750draws/frame, 9 steady phases): we also tested theCardPlan::syncmerge (batch_sync = flown && relay_copy()) that @POMXARK flagged as near-neutral (card -0.8 / send +0.6 ms):CardPlan::syncmodeprepcardsendExecuteCommandLists+1.34 ms)+1.52 ms)+1.90 ms)+1.50 ms)−0.80 ms)+0.29 ms)Holding the upload/rehash
synclist until the mainExecuteCommandListssaves−0.80 msincard_beforeon paper, but delays GPU kick-off and regresses wall-clock frame time by+1.34 msmean /+1.90 msp90.pr-cpu-merging-stripes-and-batch: RemovedCardPlan::syncbatching incrates/victory-gpu/src/host.rs, restoring immediateExecuteCommandListsfor the sync list (keeping the narrowedCARD_WORKlock scope).cargo test -p victory-gpu --lib(453 passed, 0 failed),cargo xtask policy(294 files ok).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:22:58Z.
Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.
Pull request closed