perf(gpu): cut submitting-thread CPU overhead in refreshes, card_steps, safecopy, and list recycling #1298
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA#1298
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@NexiaMoe on GitHub · 2026-11-28 17:03 UTC · original
Summary
Reduces single-thread CPU overhead on the submitting thread (
SUBMIT BUSY) and worker lock contention acrosscrates/victory-gpu/src/, with no intended visual changes.Tested on Ryzen 7 5800X3D (8C/16T) + RTX 5060 Ti 16 GB (Series S profile, Frame Gen OFF):
safecopy::tests::copy_costs(256 B):13.9 → 23.0 GB/s(+65%) to upload memory;13.3 → 22.6 GB/s(+70%) plain memory.planning steps done on the card(card_steps):6.1 ms → 2.7–3.7 ms/frameon ~3,600–4,200 draw scenes.after the sending(land()):3.6 ms → 0.1 ms/frameon the submitting thread.refreshes: down to10.2–12.5 ms/frame(from15+ ms).SUBMIT BUSY: dropped from45–56 msdown to32.3–37.0 mson ~3,600–4,200 draw scenes (22.0–27.5 mson ~1,000-draw scenes), shifting heavy outdoor scenes from CPU-bound to GPU-bound with zero >100 ms stalls in steady play.Test Configuration / Launch Args
Measured via scripts\play-foxhound.ps1 (both native -Dlss off and -Dlss balanced, Frame Gen OFF) with worker pools tuned for an 8C/16T CPU:
Changes
1. AVX2 32-byte
victory_safe_copyfast path (safecopy.rs)vmovdquloop insidevictory_safe_copy_at..victory_safe_copy_afterfor lengths32..=1024bytes (preservingrsi/rdiinr10/r11and executingvzeroupperon both success andvictory_safe_copy_failed).rep movsbfor< 32B and> 1024B (ERMS).2. Write-watch & refresh batching (
watch.rs,shadow.rs,host.rs)watch.rs:KEPT: AtomicBoolmirroringJournal::keptsoask_ahead/ask_ahead_doneand flush callers skip collecting/sorting ranges whenask_oncealready holds the snapshot.Journal::ahead(normalize_ahead) and switches containment checks (ahead_contains) from O(N) linear scan to O(log N)partition_point.ask_onceinto a single pass (ask_run_all+ nested-range dedup): 1×Asking::hold_all(), 1×JOURNAL.write(), and 1×published()scan instead of two separate passes.JournalRead(read_journal()+is_published()) so chunked refresh filters takeJOURNAL.read()once per 32 copies while preserving thePUBLISHED-before-JOURNALmemory ordering.host.rs:Batch::refresh_frontinto a reused densefront_rangesbuffer and drainsself.spansin place (avoiding intermediateTouchvecs, a second hash map, and thousands ofArc<Shadow>clones per frame), plus a 1-entrylast_aheadcache inBatch::add.refresh_frontandflush_allinto two phases: a 32-span parallelparallel_dirty_indicesfilter under oneJOURNAL.read()per chunk, followed by 1-at-a-time work stealing for textures and only the actually dirty copies (eliminating straggler tails when several large dirty buffers share a chunk).3.
Shadowlock contention, parallel thresholds, andVICTORY_WC_BAR_MIN_KB(shadow.rs)has_pending: AtomicBoolonShadow(kept synchronized underpending.lock()) to skip lockingpendingon the common no-shader-writes path.rangedintocopied: Mutex<(Vec<u64>, [(usize, usize, u64); 2])>, halving per-copy mutex acquisitions innothing_new/copy_stale.wide()completion tracking with anAtomicUsizeremainingcounter so only the final worker acquires the condvar mutex; addswide_each_chunked.copy_allandShadow::take_allparallel thresholds from4 MiB/1 MiBto256 KiB(128 KiBparts).VICTORY_WC_BAR_MIN_KB(defaulting towc_no_back_min().max(1 MiB)) forVICTORY_WC_BAR=1so small dynamic write-combined buffers keep two-sided copy-back +send::ownsnapshots (avoiding geometry/skinning corruption on small WC buffers) while large WC pools still use ReBAR VRAM.4.
card_steps& batched CBV descriptor writes (host/card_steps.rs,descriptor.rs,descriptor/host.rs,host.rs,land.rs)does_of()avoids pushing thousands ofStep::Refreshentries intodoes(scanningrunsdirectly only when aDoes::Copyis taken) and cachesFillToper asked fill.plan()(single-pass exit when!has_copy && written.is_empty(), removesBox<dyn Iterator>heap allocations) and an O(1)list.last()dedup fast path inrecord().<= 2 KiBmapped-page-bridged) 256-byte-aligned level-0 fills from the sameShadowinto bulkCopyBufferRegionspans.To::Slotfills intounder_threads().clamp(1, 8)compact buckets (descriptor::constant_slots_batch/HostHeap::constant_at_batched), acquiringSHADER_HEAPS.read()once per worker bucket, reusing cachedbase_gpu, skipping redundantbuffer.clone()viaas_raw(), and retiring replaced resources in one deduplicated lock viahost::retire_resources.5. Offload landed-list recycling & batch
IDLEpool locks (host.rs,list.rs)Host::send_late(), whenrelay()is active andvictory-late-wait(late_helper) is running (with a backpressure fallback if> 64batches back up), pokesvictory-late-waitinstead of callingland()synchronously on the submitting thread.IDLE.lock()inlist::recycle()(one capacity check + one push per batch instead of two locks per command list) and uses an O(1)u64bitmask forranwhenlists.len() <= 64.Verification
cargo clippy --locked -p victory-gpu -- -D warnings— clean (0 warnings)cargo test --locked -p victory-gpu watch::— 47 passed, 0 failedcargo test --locked -p victory-gpu shadow::— 36 passed, 0 failedcargo test --locked -p victory-gpu card_steps— 9 passed, 0 failed (1 ignored)cargo test --locked -p victory-gpu safecopy::— 8 passed, 0 failed (1 ignored;copy_costsbenchmark run separately)cargo build --release --locked -p victory— clean (0 warnings)Pull request details or commits were not available from GitHub; kept as an issue.
@wojtek2407 on GitHub · 2026-11-28 19:12 UTC · original
Test report for #1298 at
b08eab5, A/B against its base9ce3cf9(main).Hardware: RTX 4070 SUPER 12 GB (driver 610.88), i5-12400F (6 cores), Windows 11 26200. Title build v1.0.2.1.
Setup: one worktree per commit, each built with
cargo build --release --locked -p victory. Both launched withscripts/play-foxhound.ps1at its defaults: Series X, 2560x1440, DLSS Quality, no F1 settings file, no extra switches. I did not tune the thread counts the way the PR description does. I stood still at the same spot and camera angle in the boat mission, ~2 min per run, in the order A, B, A, B, with the shader and pipeline caches warm (the pipeline queue was empty every run). The numbers are medians of the frame-rate lines over the last ~75 s of each run.9ce3cf99ce3cf9b08eab5b08eab5cargo test --release --locked -p victory-gpu --lib: 454 passed, 0 failed, 36 ignored on both commits.I also read the
safecopyAVX2 path.ymm0is volatile in the Windows x64 ABI, both exits runvzeroupper, and a fault anywhere in the new path still falls insidevictory_safe_copy_at..victory_safe_copy_after, so it leaves through the failing exit withrsi/rdirestored. The overlapping last 32-byte block is fine for non-overlapping buffers. I have not reviewed the locking changes inhost.rs,card_steps.rs,shadow.rsandwatch.rsin depth.Not tested: driving or other moving scenes, Series S, frame generation, AMD, other CPUs, long sessions. Rare races from the lock changes would not show in 2-minute runs.
AI use: Claude Code (Claude Opus 5.5) set up the A/B, read the logs, reviewed the
safecopychange and wrote this report. The runs were made on the PC above; the numbers come from their logs.@jptorres96 on GitHub · 2026-11-28 19:15 UTC · original
Checked at
b08eab5on9300875(currentmain), Windows build 26300, rustc 1.98.1:cargo test -p victory-gpu --lib -- --test-threads=1: 454 passed, 0 failed. The landing stress tests (frame_of_refreshes×10,refresh_tests×3 at--test-threads=4) pass, with no hang.cargo clippy -p victory-gpu --all-targets --no-deps -- -D warningsfails on two functions this PR leaves unused, with and without--all-features.maingives neither. Removing them, or the callers' old path if it is meant to stay, would keep CI's clippy step green oncemain's own lints are fixed (#1290).On the no-op refresh benchmark from #1138 this PR is among the fastest: -10% at 16 KiB copies and the best at 256 KiB (-9%). Numbers are in #1138.
@NotADonky43 on GitHub · 2026-11-28 23:57 UTC · original
I isolated only the 32-span journal filter for the existing small (<=256-span) scalar refresh batches on a d4b5d517-based cumulative. No prefiltering across a write-watch ask; no changes to large-batch worker scheduling, stamp storage, card planner, safecopy or recycling. On contention the adaptation retains the span rather than waiting for a shadow lock while holding JOURNAL. 37 watch and 5 refresh tests passed on both switch settings, including a partial-page 67-span comparison against the scalar path and concurrent landing/title-write checks.
RTX 5070 Ti, Series X, DLSS Quality 1440p, no FG: same release executable and same precompiled shader/pipeline seeds, 7 settled heavy windows per side. Median refresh wall time 16.5 ms off / 17.3 ms on, median prepare 39.6/40.6 ms, median of reported present p95s 58.8/63.9 ms. Not shot-matched (median 43.7/48.2 MB of copies per frame). This subset alone did not demonstrate a gain on our workload. This is not a test or rejection of the entire PR, particularly the >256-span scheduling and planner changes. We left the subset out of the cumulative.
github-bot referenced this issue2026-11-29 12:10:51 +00:00
@Revens2 on GitHub · 2026-11-29 12:24 UTC · original
Frame rate only, measured on your branch head, no code change on our side.
Setup.
worktrees/pr-1298at b08eab5 againstworktrees/main-latestat9300875. The only commit main has that the branch lacks is9300875, a.github/workflowsfile, so the binary difference is this PR alone. Same save, same duration, DLSS quality (the player config), limiter off, 90 s of stabilisation then 180 s of measurement, one sample per second, alternating main/branch, gameplay samples only (draws above 7500 excluded), runs with fewer than 90 valid gameplay samples dropped. Hardware: RTX 5070 12 GB, i5-14600KF, 32 GB, 1080p.Result. 4 valid runs against 3: 27.89 +- 0.33 fps (main) against 28.84 +- 0.32 fps (branch), +0.95 fps, se 0.25, 2 sigma 0.50 -> gain, about +3.4 %.
Three independent pairings agree: +0.99 (main-b / branch-b), +0.75 (branch-a / main-d), +0.95 (main-f / branch-d). Four runs were rejected for validity (85, 76, 79 and 69 valid samples) and none of them is counted; the rejected main/PR neighbours (28.13 against 29.26) lean the same way.
Where the time goes (4 main against 3 branch).
submit_busy34.10 -> 32.53 ms (-1.57),card_nothing5.91 -> 4.52 ms (-1.39), frame 35.80 -> 34.50 ms (-1.30),prep26.43 -> 25.73,copies_ms12.57 -> 12.10,presents6.42 -> 5.54. In exchange the card goes from 83.5 to 86.9 % busy and the submitting thread starts waiting:gpuwait0.14 -> 1.41 ms,flights0.23 -> 1.40 ms, submissions in flight 1.2 -> 2.3.Reading. On this build the submitting thread was the limiter: the PR removes 1.6 ms of CPU work from it, the submission line takes the lead, the card rises from 83 to 87 % and the frame shortens by 1.3 ms. It takes that work off the submitting thread instead of moving it to another one, which is where it differs from #699 (1.7 ms off the same thread, moved to
victory-recycle, no frame gained). That comparison runs on a different binary, so the mechanism is a hypothesis, not a proof.Machine drift. The reference runs of this scene went from 27.21 fps (03:35) to 27.66 (09:24), +0.45 fps in six hours. Every neutral verdict of the campaign sits inside that band; this one is above it, and roughly twice above it. The absolute level also drifts down by ~0.4 fps across the morning while the gap holds, so the paired comparison is what carries the result, not the absolute numbers.
Reserve: one scene. 1136 inserted lines and 283 removed across 9 files of
crates/victory-gpu(host.rs,host/card_steps.rs,shadow.rs,watch.rs,descriptor.rs,descriptor/host.rs,list.rs,safecopy.rs,land.rs) do not get validated by 7 runs of a single save: same view, same weather, same draw counts. What the measurement supports is that this path is faster on this scene and stable over 180 s windows; it says nothing about the descriptor, safecopy and watch paths this one scene does not cover. Smoke and upstream CI remain to be done before any merge.No game data, dump or log attached.
@birdneststream on GitHub · 2026-11-29 14:08 UTC · original
A data point for the landing path this PR rewrites, from Linux/Proton (RTX 5090, i9-13900KF, GE-Proton 11 + vkd3d-proton master, Series X, DLSS quality, FG 4x, ray tracing off), medians over the frame lines of 6,000+ draws, same kinds of scenes, 11-29:
568c5e5d+ a few PRs (the 11-28 build, ~12 min in the world)829188e9+ the same PRs (the 11-29 waves, two sessions)VICTORY_RELAY_COPY=1So between the 11-28 and 11-29 mains the frame's "copying back" (
COPY_BACK, the relay worker's landing span including therelay_card_backfence wait) went from 5 to 22–23 ms a frame while the CPU preparing moved only 33 → 37 and the card 1 → 4–6 ms;VICTORY_RELAY_COPY=1does not move it. Yourland()3.6 → 0.1 ms is the kind of cut this needs — but your branch is based on the 11-28 main (9ce3cf9), and the landing path changed in the waves, so whoever merges this should expect the conflict inhost.rs/land.rsand re-measure on the current main; the before/after there is now ~23 ms, not 3.6.(The safecopy AVX2 loop alone, measured here on the 13900KF with
safecopy::tests::copy_costs: 256 B 11.6 → 11.5 GB/s, 4 KiB 22.4 → 22.3 — nothing on this CPU; the gain in your table is on CPUs whoserep movsbpays a startup cost.)