Lazy landing and lazy fetch: what the GPU writes to memory the CPU never touches stays on the card (VICTORY_LAZY_LAND=1, VICTORY_LAZY_FETCH=1, on top of #1038) #1184
No reviewers
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!1184
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1184"
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?
@urielbeaupre on GitHub · 2026-11-28 15:05 UTC · original
urielbeaupre:perf/lazy-land→main· +2999 −41 · 9 files · 13 commits · closed without mergingDepends on #1038. This branch is #1038's two commits plus the ones here. Lazy landing only works on the write-watched private memory #1038 adds.
The finding
Every frame the GPU writes a 21 MB buffer (
0x1412200, fromXMemAllocDefault). The layer then does this with it:land::piece→safecopy::merge), about 22 MB a frame.Shadow::take→take_landed→host::read) to see whether the CPU changed it.The title never touches it. A fault probe, included here as
VICTORY_READER_PROBE_LEN=1412200(test only, off), makes the buffer's pages inaccessible once a second and records who faults, with the call chain. Over a full 165 s run there were 2 callers, both ours:host::read←Shadow::take(refresh / echo check)land::piece←Shadow::land_card(landing merge)The title's code made none. The buffer is still needed: skipping its landing outright (
VICTORY_LAND_NEVER_LEN=1412200, test only) makes the echo check read stale title memory and send it up over the card's bytes, and the scene goes low-poly. So the GPU → title memory → GPU round trip has a consumer, but that consumer is only the copy itself.The change: lazy landing (
VICTORY_LAZY_LAND=1, off by default)For a copy that lies whole in private write-watched memory (
title_memory_private, marked from #1038'swatched_reservation), is at least 1 MiB long and has no other live copy over it:PAGE_NOACCESS. A page becomes ahead only if the landing covers all of it and title memory still equals the copy's CPU side. That compare runs with the page read-only first, so no title write can slip in.Shadow::landed_ahead). It does not re-read 21 MB a frame.Notes::ahead→watch::landed_beside). They re-read, fault, and get the GPU's bytes.host::read,write_mappedand the kernel-write hooks land their range first.ASSIGNis always taken before a slot lock.The log line, every 5 s:
lazy landing (VICTORY_LAZY_LAND=1): N copies lazy, X MB a frame landed into them alone (not into title memory), Y MB ahead now; per frame F faults on pages ahead, P pages landed on demand; K copies turned off since the startIn the runs below it reads: 1 copy lazy, 19.9 MB a frame, 0 faults, 0 turned off.
Measured
RTX 4070 Ti 12 GB, Ryzen 9 7900X, Series S profile, DLSS off, the same save, warm cache. One build, switches alternated. Cutscene = seconds 60–110 after input; after = 110–165.
Lazy landing on top of the write watch (
VICTORY_LAZY_LAND1/0, both with the write watch):That's +2.8 fps in the cutscene (+7%) and +1.9 after the scene change (+8%), with 2.6–4.4 ms less CPU preparing a frame. Draw counts match on and off (about 1,400 in the cutscene, 3,400–3,750 after), and nothing looks different on screen.
Against main's behaviour, from an earlier rotation the same afternoon (the write watch off: 36.0 / 23.7 fps, see my second comment on #1038): #1038 alone gives about +2 fps, and with this on top it's about +5.5 fps (+15%) in the cutscene and +2.6 (+11%) after the scene change.
Lazy fetch (
VICTORY_LAZY_FETCH=1, needsVICTORY_LAZY_LAND=1, off by default)With lazy landing, the relay still fetched the lazy copy's flagged pieces every frame: a readback list and a wait, 6–7 ms of "copying back", only to put them in a CPU side nothing reads. With lazy fetch, those pages are not fetched at all.
Shadow::claim_card_only). They are marked card-only andNOACCESS, other readers are told they were written, and the copy is noted up to date. A page is refused if it has title bytes the card may not have: dirty, or sent after the fetches merged so far.card_dirtyleaves card-only pages out. If something marked one of them to go up, it is fetched first, then sent as the card's own bytes.CopyBufferRegion, no waits on other queues or fences, all D3D objects made at the first claim. It fetches every card-only page, lands them, and turns the copy off for good. The touching thread holds none of our locks while it waits, and the wait is timed, so the process can still exit. Flights still in the air are not waited for: their own landings merge what differs.Measured against lazy landing alone (same build,
VICTORY_LAZY_FETCH1/0, same setup as above). In game: 20.1 MB a frame not fetched, 0 pages refused, 0 fetches on demand, 0 errors.That's +2.3 fps in the cutscene and +1.4 after the scene change (both about +6%), with copy-back about 1.9 ms shorter. Draw counts match.
All together, in the cutscene: main about 36 fps → #1038 about 38 → lazy landing about 40 → lazy fetch about 42, roughly +17%. After the scene change: about 23.7 → 26.3 (+11%). These come from rotations in several sessions the same afternoon, so the total is approximate. Each step is measured against the one before it, in the same session.
Tests
cargo test -p victory-gpu --release --lib: the 12 new lazy tests pass. They cover the bitset and part arithmetic, eligibility, back-off and turn-off, the claim racingland_range, card-only pages never going up, a demand fetch bringing the card's bytes in, and the full path on real memory:read_intofault and get the GPU's bytes;NOACCESSpages;indirect::tests::host_list_budget_starts_empty_at_each_submissionandwarp_batch_charges_every_executionfail, but they fail the same way on #1038's head without these commits.cargo test -p victory-hle --release --lib: 183 passed.Known limits
WriteFile,send/sendtofrom title memory): these would fail on an ahead page instead of faulting. The probe saw none of them on this buffer.🤖 Generated with Claude Code
Lazy landing: what the GPU writes to memory the CPU never touches stays out of title memory (VICTORY_LAZY_LAND=1, on top of #1038)to Lazy landing and lazy fetch: what the GPU writes to memory the CPU never touches stays on the card (VICTORY_LAZY_LAND=1, VICTORY_LAZY_FETCH=1, on top of #1038)@urielbeaupre on GitHub · 2026-11-28 16:22 UTC · original
@POMXARK @tippythetaidum @Bj0rnis: you ran careful A/Bs on #1038 and #1014 today. Would you be up for one on this? It stacks on #1038 (this branch includes its two commits), so the comparison is #1038 alone against #1038 plus this. Both switches are off by default:
VICTORY_LAZY_LAND=1andVICTORY_LAZY_FETCH=1The log line every 5 s shows whether it engaged. When it works it reads something like
1 copies lazy, … 20.1 MB a frame not fetched at all, … 0 fetches on demand … 0 copies turned off. If it says0 copies lazy, or the "fetched all the same" counters are non-zero, please paste that line: it means your setup takes a path I haven't seen yet.What I'd most like to know:
copying back/preparingwith it on and off, at your usual draw-count buckets;0 fetches on demandholds.On my RTX 4070 Ti / 7900X (Series S, DLSS off) it measured +2.8 fps on top of #1038, then lazy fetch added +2.3 in a cutscene, with copy-back about 2 ms shorter. Results on an RTX 5080 at 1440p with DLSS would show whether that holds where the frame is more GPU-heavy.
🤖 Generated with Claude Code
@Marsietiss on GitHub · 2026-11-28 19:18 UTC · original
Thanks for the lazy landing work. We ported #1184 onto our tree and found one stale-read path; the fix applies cleanly on top of this PR's head (
b126a98b0), so here it is as a commit rather than a PR (this PR's head is in a fork, so I could not target it):github.com/Chezzuss/VIctory@5ba8b55fc0(branchfix/lazy-keep-ahead, 3 files, +108/-4 incl. a test).What we saw: with
VICTORY_LAZY_LAND=1the title read stretched car geometry; with it off the same scene was fine. Cause on our side: the write watch (watch.rs) callsVirtualProtecton whole 64K blocks (guard, unguard, arm, alias). Where a block covers pages a lazy copy holds ahead (PAGE_NOACCESS), that call reopens them as RW/RO, so the title reads the stale title bytes through the opened page with no fault, and the card's bytes never land.Fix:
lazy::keep_ahead(at, len)re-closes the pages ahead (under the slots' shared lock) after each watch protect, andlazy::guardable(at, old)accepts aPAGE_NOACCESSfirst page when that page is ahead, so the watch's "not ours, put it back" check does not misfire. A counter in the lazy log line reports pages re-closed per frame.cargo test -p victory-gpu --lib lazypasses, including the newa_protection_over_pages_ahead_does_not_open_them.Caveat: I only checked that it builds and the lazy tests pass on this head; the in-game confirmation was on our merged tree (which has more write-watch changes than this PR), so please treat it as a lead, not as proof for your base. Happy to adapt it if the watch code differs.
@urielbeaupre on GitHub · 2026-11-28 19:43 UTC · original
@Marsietiss thank you, that's a precise diagnosis. I couldn't fetch the commit: https://github.com/Chezzuss/VIctory returns 404 for both the repository and 5ba8b55 (it's private, or it was taken down). Your description is clear enough to implement from, so I'll do it here and credit you in the commit:
lazy::keep_ahead(at, len): after eachVirtualProtectthe write watch makes over a 64 KiB block (guard, unguard, arm, alias), pages a lazy copy holds ahead are madePAGE_NOACCESSagain, under the slots' shared lock;lazy::guardable(at, old): the watch's "not ours, put it back" check accepts aPAGE_NOACCESSfirst page when that page is ahead;I'll also log on this base how often the watch touches blocks with pages ahead at all, to see whether the path is reached here or mainly on trees with more write-watch changes. If it's convenient, a
git format-patchof 5ba8b55 pasted here would still be useful to check my version against yours.On the flickering ground you saw with #1038: noted. If I can reproduce it here, I'll report which allocation it is.
🤖 Generated with Claude Code
@Marsietiss on GitHub · 2026-11-28 19:52 UTC · original
Follow-up: the commit link above points into a private repo, sorry. The same fix is now public in our fork Mangrove:
b126a98b0):github.com/Marsietiss/Mangrove@d9aec2a787(branchfix/lazy-keep-ahead), so you can cherry-pick or compare directly.crates/victory-gpu/src/lazy.rs(keep_ahead,guardable) in https://github.com/Marsietiss/MangroveSame caveat as before: builds and lazy tests pass on your head; the in-game check was on our merged tree. Thanks again, @Urielbeaupre.
@urielbeaupre on GitHub · 2026-11-28 20:33 UTC · original
Closing this, because current main no longer has the cost it removes.
I rebased it onto main
32ecacf(with #1038's two commits; no conflicts, 491 tests pass) and added the keep-ahead fix Marsietiss reported. My version keeps the pages aheadNOACCESSthroughout the watch's protections instead of reopening and re-closing them, and the lock order can't deadlock. Credit to Marsietiss/Mangrove@d9aec2a. In game on that base, lazy landing never engaged, so I added an always-on diagnostic. With main's launcher defaults (Series S, RTX 4070 Ti) it reads:The 21 MB buffer (
0x1412200) that went GPU → title memory → echo re-read every frame on63b902fisn't copied back on current main at all: copy-back is down to ~3.8 MB of new bytes a frame. So there's nothing for this PR to keep on the card, and reviewing it would only cost time.For the record, in case that buffer comes back (e.g. with the structure builder on):
63b902f+ #1038, lazy landing gave +2.8 fps in the opening cutscene and +1.9 after the scene change, and lazy fetch added +2.3 / +1.4 more (tables above);VICTORY_READER_PROBE_LEN) showed that only the layer touched that buffer, never the title;perf/lazy-land(I'll push the rebased version there so it isn't lost), if anyone wants to pick it up.Thanks to everyone who reviewed and tested it, and to Marsietiss for the keep-ahead report.
🤖 Generated with Claude Code
@POMXARK on GitHub · 2026-11-28 20:37 UTC · original
@urielbeaupre @Marsietiss — confirming your closing finding independently on an RTX 5080 16 GB (Ryzen 7 5700X, 32 GB RAM, Windows 11, Series X 1440p, DLSS Quality + MFG 4x, release build, 20-minute A/B on top of
#1038+Marsietiss/Mangrove@d9aec2a):--release --lib -- lazy --test-threads=1): 14/14 PASS (1.04s), includinga_protection_over_pages_ahead_does_not_open_them.VICTORY_LAZY_LAND=1,VICTORY_LAZY_FETCH=1,VICTORY_LAND_SKIP=1,VICTORY_WC_NO_BACK=1):0errors,0visual regressions, 0 lazy landing engagements over the entire 20 minutes — matches your diagnostic exactly becausecopying backis already down to 0.7 MB/frame on currentmainsettings.#1038, lazy off)#1184+d9aec2a(lazy on)Good call closing it for current
maindefaults — and great to have the rebasedperf/lazy-landbranch +keep_aheadfix archived if large copy-backs return with RT/structure-builder work!Pull request closed