shadow: avoid redundant locks, wide_each allocs, and per-page dirty/counter churn in refresh hot path #2530
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2530"
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 qlfu on 2026-11-29T13:52:45Z.
Summary
Eliminates redundant lock acquisitions, per-page lock/atomic churn, and heap-allocating nested pool dispatch on the
Shadowrefresh hot path (update_ranges,update_free,copy_stale,take_all,take,take_landed) andwatch::parts_written.What Changed
crates/victory-gpu/src/watch.rs:parts_written(&[])before acquiring the globalJOURNALRwLock(avoids takingjournal()on every no-opcopy_stalerefresh).crates/victory-gpu/src/shadow.rs:Shadow::update_ranges: gatesself.pending.lock()andbusyVecallocation behindself.has_pending.load(Ordering::Acquire)(matchingnothing_new,new_look,nothing_new_with, andwrites_pending_in).Shadow::update_free: checksprev == GUARDEDbefore callingcrate::watch::guarded(from, to)(avoidingPROTECTEDbitmap queries on already-guarded copies) and skips storing back toself.watchedwhen unchanged (avoiding cross-thread cache-line dirtying during parallel refreshes).Shadow::copy_stale: skipswatch::parts_written,by_parts, andtake_allwhenruns.is_empty()(preserving therangedepoch update underwatch::light()), and skipsparts_written+by_partswhenagain_at.is_empty().Shadow::take_all: replaceswide_each(Arc+Vec<Box<dyn FnOnce()>>+unsafepointer cast +workers.queuecontention when called nested insiderefresh_front/flush_all) with zero-allocationwide_each_scoped(parts.len(), 1, ...).Shadow::take&Shadow::take_landed: addsShadow::changed_runsand batchesself.keptinvalidations,card.dirtyupdates (card_changed/card_changed_runs), andSEND[0..4]/ECHO[0..2]global atomic increments once after the page loop instead of lockingkept/card.dirtyand bouncing global atomic cache lines on every 64 KiB / 4 KiB page.shadow::landing_tests::take_batches_dirty_runs_for_whole_and_diff_pathscoveringwhole, multi-page diffing, and unchanged paths.Verification
cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked shadow:: -- --test-threads=1-> pass (exit0).cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked watch:: -- --test-threads=1->62 passed; 0 failed(exit0).cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --locked->0new warnings inshadow.rsandwatch.rs.0 WARNs / 0 ERRORs):145029.log->164041.log):Submitmean37.77 -> 35.33 ms,copies_fills4.40 -> 3.80 ms,FPS23.05 / 23.13 -> 23.80 med / 24.30 mean(min 17.1,max 36.0).142528.log->164813.log):Submitmean35.59 -> 33.66 ms,refreshes11.40 -> 10.95 ms,copies_fills3.90 -> 3.60 ms, baseFPS22.45 / 22.98 -> 23.45 med / 23.64 mean(~47 FPS displayed).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by rgroenewoudt on 2026-11-29T19:48:55Z.
In-game A/B on an RX 9070 (Series X, FSR 4 upscaling, release build): this PR is about 9 ms a frame slower here.
Setup: the PR's commit cherry-picked onto the same base, built in a separate worktree, launched with identical switches and the same pipeline library. Same spot in the world, roughly a minute in game per run. The numbers are medians of the per-second log lines, without the first 15 seconds in game.
take_allchange (wide_eachkept)wide_each→wide_each_scopedchange intake_alldoes not change the result, so that change is not the cause. Reading the rest of the diff, I found no clear cause.One run per variant, but the gap (~9 ms) is about nine times the difference between the two base runs.