gpu: land one copy's pieces in one land_card, open their guards a run at a time #3626
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3626"
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 shiman1901 on 2026-11-30T02:07:05Z.
Related to #2415.
What it changes
Three changes to the relay landing (
Host::relay_card_back->Shadow::land_card), all behind one switch:host.rs—relay_card_backno longer builds astd::collections::HashSetper landing for the(copy, lo, hi)dedup; it is a sortedVecwithbinary_search/partition_point(same set, same order ofpieces, noRandomStateand no hash table per fetch). The job body takes a copy's pieces together, in address order, and splits a job by copy (one copy per job with the switch on; the old 256 KiB cut may hold several with it off, each its ownland_card).land.rs+shadow.rs—piece_atis split intopiece_scan(thedifferpass and the title range whose guard must be opened) andpiece_put(the merge, unchanged);piece_atis scan +open_guard+ put, sopiece()andland_back(copies in the PC's memory) behave as before.Shadow::land_cardscans all its pieces first, coalesces their guard ranges withland::runs(sorted, joined only where they touch or overlap) and opens each run once, just before its first piece is written. 64 consecutive 64 KiB pieces (4 MB) cost one guard open and one lock acquisition instead of 64; a gap of one byte keeps two runs, so no clean page is opened.land.rs—jobs()groups by copy and splits a copy across the landing threads:jobs = clamp(ceil(bytes / 256 KiB), 1, threads()),most = ceil(bytes / jobs), cut only where a 64 KiB block ends. A 4 MB dirty copy becomes 3 jobs of ~1.3 MB with 3 threads (not 16 of 256 KiB), soland_cardasksmerging/dirty/sent/skiponce a copy and every landing thread still has a job. One copy is never merged into another's job.The switch (
VICTORY_LAND_BATCH)VICTORY_LAND_BATCH=1(default) runs the batched landing above.VICTORY_LAND_BATCH=0restores, from the same binary: onecrate::land::pieceper 64 KiB piece (its guard opened per piece) and the oldJOB = 256 KiBjobs()without thethreads()cap — for a single-exe A/B onlanding per frame's "merging what was fetched"/"jobs" and onlanded per frame.The
HashSetreplacement is not behind the switch (pure dedup, no behaviour change).What is preserved
watch::landing:runsjoins only touching/overlapping ranges, andpiece_scancomputes the same(first, last)window as before;open_guarddoes the samereads::againandspent(stat::NOTES, ..).VICTORY_LAND_TAKEN/LANDED,beside/VICTORY_LAND_ANYTIME,again_after_change,reads::watchand everystatcounter.piece()andland_backsignatures and behaviour.The one deliberate timing change: a run's guards are opened after the remaining pieces'
differpass instead of immediately before each merge;safecopy::mergealready tolerates a page whose mapping went away.How it was tested
land.rs(#[cfg(test)] mod batch_tests):guard_runs_join_only_what_touches— joins adjacent/overlapping ranges, keeps a clean page between two, drops empty ranges;jobs_keep_copies_apart_and_fill_the_threads— one copy of 64 blocks gives at mostthreads()jobs covering all pieces in order, and a second copy never shares a job;jobs_cover_every_piece_once_and_cut_at_blocks— every piece in exactly one job, in order, cut only where a 64 KiB block ends.crates/victory-gpu/src/land/tests.rsadjusted to the newjobstuple (3 call sites), no behaviour change.unsafe_op_in_unsafe_fn,clippy::allpatterns, bracket balance) and verified to re-apply byte-for-byte. CI is the first compiler to see it.Checked for overlap
host.rsaround 1804, 6716, 9578 andshadow.rsaround 7709, 9878. This PR changeshost.rsat 6085-6105, 7662-7722, 7866-7920 andshadow.rsat 7204-7280 — no overlapping hunks; a rebase moves line offsets only.land.rsorland/tests.rs.CC @dyshay @burber @meonline42
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by burber on 2026-11-30T04:43:29Z.
Tested on Windows: i5-13600K, RTX 4070 Ti 12 GB, 32 GB. Release build of this PR's head
68ddbfc1. A/B from the same exe withVICTORY_LAND_BATCH(default on) against=0, alternating, 300 s each, same save restored before every run, after one warm-up run. Medians of the 5 s lines after the first minute in the world.Landing (
landing per frame):So it does what it says: guard opening is down 25-40%, the merge's wall time is down 0.4-0.7 ms, and the threads' total is down 1-2 ms. The jobs go up because a copy is now split across the landing threads.
Frame rate: no change. Median fps by draws band:
The on and off runs drifted into slightly different spots, so that's within noise. That fits what I found in #2415: on this machine copying back runs beside the frame, not in front of it, so landing time doesn't reach the frame here.
Picture: screenshots at 100, 180 and 270 s in every run look normal. One "on" run ended up facing the backlit kitchen window, which looks dark, but a run without this PR (on an older base) shows the same dark view from the same spot. No crashes. The only error in the logs is the one Streamline
slEvaluateFeatureline near the start, the same in every run with the switch on and off.Tested with an AI assistant (Claude Code); the runs were on my PC.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-30T08:49:51Z.
Measured on an RTX 4090 (i9), on top of trustno1 main + our fixes. Series X profile, a static scene (character standing still, the same save restored), one 660 s run with
VICTORY_AB=15,VICTORY_LAND_BATCH, 34 phases in the world, neighbouring phases compared. The draw count barely moves in this shot, so I'm quoting the raw pair differences:VICTORY_LAND_BATCHCopying back averaged ~7.6 ms over the run, with no visible split between phases.
So on this machine it's neutral, within ±1 ms. That fits copy-back not being on the critical path here (frames are set by preparing). It doesn't rule out a gain where landing is longer (burber's 24 ms on a 4070 Ti, or 6-core CPUs), and I saw no regression or picture issue. Thanks for the change. It's in our test branch.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-11-30T10:28:52Z.
Tried this on top of current main (
41adb551) on an RTX 5080 / 9800X3D, Series X profile, 1440p.The lib tests don't compile as pushed: in
jobs_keep_copies_apart_and_fill_the_threads(land.rs),let jobs = jobs(&pieces);shadows the function, so the laterfor job in jobs(&both)fails with E0618 (expected function, foundVec<Range<usize>>). Callingsuper::jobs(&both)there fixes it; with that, thelandtests pass (20 passed, 2 ignored).In play (150 s measured, same route, settings unchanged) it was neutral for me: 40.4 ms median frame against 40.0 without it, CPU preparing 28.0 ms. No panics or new log errors.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by remijn on 2026-11-30T12:38:42Z.
Two notes from testing this on an RTX 3080 / Ryzen 9 7900X3D (Series S, DLSS Quality, FSR 3 frame generation, the same save, diagnostics build), cherry-picked onto a tree based on
41adb551.The test doesn't compile: in
land/tests.rs,let jobs = jobs(&pieces);shadows the function, and the laterfor job in jobs(&both)then calls the vector:for job in super::jobs(&both)fixes it. With that, the 20 landing tests pass.The effect on this setup was neutral:
VICTORY_LAND_BATCH=0against=1, one 30 s pair: 20.0 against 19.65 fps, the relay's landing time 24.3 against 24.8 ms a frame, and the delay from a landing's start to its fence signals 2.5 against 2.3 ms. All within noise. This scene probably doesn't land many pieces per copy; it may help elsewhere.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nicolasabosch on 2026-11-30T21:52:22Z.
Tested on an RTX 4070 Laptop 8 GB: no measurable fps difference in this scene (2 runs).
Tested on main
e1251c31with this PR (e38b98de) merged on top and nothing else changed. Release build, same profile as main.Setup
victory play --series-s --dlss performance --framegen 2, with no fps cap and the window minimized.host:reports, about 200 s. These are real frames, not generated ones.On this laptop, identical main runs differ by up to about 2–2.5 fps, so only an effect of roughly 2–3 fps or more would be visible in this scene. In the fixed-save run the log had 67 Streamline "Exceeded VRAM budget" warnings spread across the whole run. The first run had none, and main had 1 across 7 runs. fps was not lower in that run. I can't tell from 2 runs whether this PR causes them; mentioning it in case it rings a bell.
Not tested: driving, camera turns, interiors, an image comparison, other GPUs.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nicolasabosch on 2026-11-30T23:25:19Z.
Follow-up on the VRAM-budget warnings above: a third run of this PR (fixed save, 16.31 fps) had 1 such warning, not 67. A run of a different build without this PR (the combined #4069/#3757/#3614/#4206 build) also had 46 of them. So they show up now and then on this 8 GB card whatever the build, and I don't think this PR causes them. fps stays the same: no measurable difference in this scene over 3 runs.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:50:20Z.
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed