Shadow: support nested wide_each_scoped fan-out for Shadow::take_all #4488
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4488"
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 Bazovsky on 2026-11-30T21:07:21Z.
Summary
Restores real multi-threaded fan-out for
Shadow::take_all(>= 1 MiBshadow buffer copies) when invoked inside batch refresh passes (Batch::refresh_front_spans,Batch::refresh_ahead, andBatch::flush_all), and promotes the single largest dirty buffer span to the front of each batch so large copies begin fanning out immediately instead of tail-straggling.Problem
27d312d3introducedwide_each_scopedwith a singleq.scoped: Option<ScopedTask>slot (silently falling back to single-threaded inline execution wheneverq.scopedis occupied) and switchedBatch::refresh_front_spans,Batch::refresh_ahead, andBatch::flush_allonto it.f37bf099later switchedShadow::take_all(>= 1 MiBcopies split into256 KiBparts) fromwide_eachtowide_each_scopedto eliminate per-callBoxallocations.q.scopedslot,Shadow::take_allsilently serialized back onto a single thread during batch refreshes — leaving idlevictory-widehelpers and the waiting outer submitting thread blocked while one thread copied 4–14+ MiB sequentially.Changes
crates/victory-gpu/src/shadow.rs):Option<ScopedTask>with a fixedMAX_SCOPED = 16(const _: () = assert!(MAX_SCOPED <= 32)) array of slots, ascoped_ready: AtomicU32hint bitmask, cache-line-aligned per-slotScopedAtomics(#[repr(align(64))]), and cache-line-isolatedbusy_at: AlignedU64.SCOPED_ANCESTORS: Cell<u32>(AncestorsGuard, reset to0around foreign jobs popped inBeside::drop) and maintain each ancestor's active descendants inScopedAtomics::children: AtomicU32.victory-wideworkers pick the deepest runnable slot first (ancestors.count_ones()). Waiting outer owners steal only strict descendants of their own slot ((task.ancestors & (1 << slot)) != 0), never unrelated concurrent callers — guaranteeing deadlock freedom (strict ancestor DAG) and avoiding cross-caller latency inversion or lock/TLS hazards.running == 0, clearing ancestorchildrenbits, clearingq.scoped[slot]) intoSlotGuard::dropand helper exit/panic cleanup intoHelperGuard::drop, so the erased closure lifetime is structurally panic-safe and helper panics abort remaining chunks early.spin_for(wait_spin(), ...)towide_each_scoped(matchingBeside::drop), masked strictly torunning == 0 || (scoped_ready & children) != 0so unrelated concurrent callers do not defeatVICTORY_WAIT_SPIN.crates/victory-gpu/src/host.rs):largest_first(O(n) promote-one-to-front, preserving relative order of all other items) on dirty buffer spans inBatch::refresh_front_spans,Batch::refresh_ahead, andBatch::flush_all(!check_noop), and updatelargest_first's doc comment.crates/victory-gpu/src/shadow.rs):nested_wide_each_scoped_fans_out_in_parallel).waiting_owner_steals_own_descendant_and_not_foreign_caller).MAX_SCOPED + 4), concurrent top-level callers, deterministic helper panic propagation, deterministic owner panic with active-helper join verification, and non-vacuous slot-leak checks (nested_wide_each_scoped_handles_overflow_concurrency_and_panics).Verification
Unit tests & lint (Windows MSVC target via
cargo xwin, native Windows execution)cargo xwin clippy --target x86_64-pc-windows-msvc --locked --no-deps -p victory-gpu --all-targets: 0 new warnings.shadow::wide_tests --test-threads=8: 9/9 passed across repeated consecutive stress runs (0.05 s each).host::promote_one_refresh_preserves_ties_and_all_other_jobs: passed.watch::tests:: --test-threads=1: 43/43 passed.Live A/B benchmark (GTA 6, 1440p DLSS Quality + FG 2x, RTX 5090 + Ryzen 9 9950X3D)
4 × 125 s ABBA runs (
main_1,pr_1,pr_2,main_2) comparing pureorigin/main(e1251c31) vs this PR with identical release flags (-C target-cpu=znver5) andVICTORY_SUBMISSION_TIMING=1:origin/main(A1 / A2 -> mean)submit: refreshes ahead of writesspikesubmit: the lists' stepsin slow subsrefreshesper frame (gameplayt>=45s)<50 ms,t>=45s)Every key metric improved across both ABBA pairs with zero overlap between baseline and PR runs.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.