Repository navigation
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
Conversation
Keep large write-watched XMemAllocDefault reservations out of the low 4 GiB reserved for ADDRESS_32BIT / ALLOC_32BIT requests and honor the 64-bit upper bound from address_range(0), with regression checks across min, 64 KiB, and 2 MiB alignments. Assisted-by: OpenAI Codex, Google Gemini
…EADER_PROBE_LEN (who touches its title memory) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ys in it (VICTORY_LAZY_LAND=1, off by default) The title's 21 MB XMemAllocDefault buffer is written by its shaders every frame and never touched by its CPU (fault probe over 165 s). Landing it put ~22 MB a frame into title memory, and the echo check read it all back. For a copy in the card's memory whose title memory lies whole in a write-watched XMemAllocDefault block, at least 1 MiB long, with no other copy over that memory (crate::lazy): - a landing puts the card's bytes into the CPU side alone for 4 KiB pages the piece holds whole, that the card changed, and whose title memory equals what the copy held (looked at with the page read-only); those pages are "ahead" and made PAGE_NOACCESS (one VirtualProtect per run); - a refresh (take / take_landed / copy) leaves pages ahead out; - a vectored handler, registered ahead of crate::watch's, lands a page on its first touch (the title's, or our safecopy readers') and lets the access go on; our kernel-path reads/writes (host::read, write_mapped) and the runtime's kernel writes (kernel_writing, kernel_will_write) land the range first; - freeing/unmapping drops pages ahead (no NOACCESS left behind), a dropped copy lands its pages; more than 64 pages landed on demand in a second, or another copy made over the memory, turns the copy off for good. Locking: one RwLock per slot, shared by landing and refresh threads (which touch no page ahead and wait for nothing under it), alone for demand; a thread-local count keeps a faulting lock holder from waiting on it again. INFO line every 5 s with copies lazy, MB a frame left ahead, faults and pages landed on demand per frame, copies turned off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of 7ae6318: - A lazy landing wrote no title memory, so the write watch never named its pages, and nothing else that reads the memory by the journal (textures, descriptors, other trackers) would take them again. Pages left ahead now go into the job's land::Notes (Notes::ahead) and are noted at its flush as a landing beside the guards is (watch::landed_beside: the journal with a new asking, LANDED, descriptor::host::remapped). Those readers take them again and fault them in; one that does so often turns the copy off by the back-off. Replaces watch::landed_ahead. Test: a tracker over write-watched memory is told of a lazy landing, and reads the card's bytes. - land_ahead made a whole run read-write before copying into it, so a thread's write in between was put under older bytes. Pages are now made writable and copied one at a time (the window is one 4 KiB copy, for a page nobody has seen since it went ahead; private memory has no second view to write through). Runs that are only dropped stay batched. - The count of pages ahead goes up with their bits (before read-only), and is read with Acquire by land_range and not_ahead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
673ebb8 noted pages left ahead as written for every reader, the lazy copy too: no copy was noted as up to date with them (Notes::ahead pushed a null copy), so the lazy copy took its whole span as written at every refresh, only to skip it (copies MB back from ~40 to ~60 a frame). Notes::ahead now takes the lazy copy, and the flush notes it as up to date with a block whose noted pages all came through it, ahead (Shadow::landed_ahead): if it was up to date with the block's last write before. Without Shadow::landed's guard bit: lazy copies are of write-watched private memory, where a title write not noted yet is in the kernel's bits and comes with a later number, so pages of the block landed as before (the title wrote them) are still taken again. A block with entries beside the guards and ahead is noted for neither. Test: the lazy copy has nothing to refresh after three landings while a tracker is told each time; a page of the block the title wrote is taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…are matcher Merged-in trustno1-coder#1184 met trustno1-coder#933 lock-free copied[] and trustno1-coder#884 Spare::take matcher; adapt both calls instead of reintroducing a lock.
…_LAZY_FETCH=1, off by default) With lazy landing (VICTORY_LAZY_LAND=1) the 21 MB buffer's flagged pieces were still fetched every frame (a readback list and a wait, ~5-6 ms of copying back) only to go into a CPU side nothing reads. crate::lazy::fetch: relay_card_back claims the pages of a lazy copy's flagged pieces that may stay with the card alone (Shadow::claim_card_only): pages ahead already, or pages made ahead as a lazy landing does (title memory equal to the CPU side, looked at read-only, then NOACCESS); none with title bytes the card may not have (dirty, or sent since the merged fetches). They are not fetched, are marked "the card's alone" (State::cards), and are told as written to every other reader with the copy noted up to date (Notes::ahead). The rest of each piece is fetched and landed as before. Nothing of them goes up: card_dirty leaves them out (Shadow::without_cards), every refresh leaves out pages ahead, and whatever else writes the CPU side there touches title memory first. The card's hashes are its own, so the next frame's flags stay right. On demand (the title's fault, host::read, kernel-write hooks, card_merge, drop, turn-off) all of a copy's card-only pages come down at once on a thread of its own, through its own copy queue (one CopyBufferRegion, no waits on other queues or fences), into a readback buffer made at the first claim; the CPU side and title memory take them, every page lands, and the copy lands as before from then on. The asker waits with no lock of ours held; the fetcher takes only the slot's lock. In-flight flights are not waited for (that could wait on the faulting thread); their own landings merge what they change. Freed memory drops card-only pages. The 5 s line adds MB a frame not fetched, MB the card alone holds, and fetches on demand. Test: claimed pages are left out of what goes up, a page with bytes to go up is fetched, and the title's read brings the card's bytes into title memory and the CPU side. Also: the back-off test reads enough pages for a slow machine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In game lazy fetch never claimed a page. A copy keeps the notes of what it sent up (`Card::sent`) until it sends again (card_dirty forgets them only for copies it touches), and a lazy copy sends nothing once it is lazy: its first send, all of it, stayed noted for ever, and claim_card_only avoided every page as "sent, maybe not received". Only sends after the fetches merged so far (RELAY_FETCHED) are avoided now, as the merges themselves do. The 5 s line now says why pages of flagged pieces were fetched all the same, per frame: the copy could leave none, not whole in the piece, title bytes the card may not have, title memory differed. Test: an old send over the whole copy does not keep pages from the card, a newer one does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- land_range looked for pages the card alone holds under the shared lock, then landed under the lock alone without looking again: a claim in between (pages ahead made the card's) had the stale CPU side land and the card bit cleared, the card's hashes matching, never flagged again. It looks again with the lock held alone and fetches then. Test: a claim run in that gap (a test hook) ends with the card's bytes. - card_dirty dropped bytes to go up that met pages the card alone holds. Nothing should mark those; if something does, they come down first (fetch_if_cards, logged once) and go up as the card's own bytes. Test. - A wait for the fetching thread is timed: if the thread is gone (the process ends), the pages land with the CPU side's bytes and that is said, instead of waiting for ever; a panic there fails the process. - The fetching thread logs only after the asker is told, allocates nothing on the way; the driver locks it may wait for are documented. - card_merge and card_merge_relay fetch only pages the card alone holds (before_compare); pages only ahead fault in as before 0ea8d5e's parent, so lazy landing alone is as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…trustno1-coder#1193 and trustno1-coder#1184 measured; not merged Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SGw6DM2fQu3WKmCUhFxrrM
RELAY_FETCHED says later merge-fetches are queued behind these sends, not that the card ran them: with no relay copy queue and nothing to fetch it rises to the current QUEUE_ORDER, past sends queued behind flights in the air. A claim ignoring such a send S, then a demand fetch on its own copy queue before S runs, would lose S's title bytes for good (the hashes match, nothing is flagged again). CARD_RAN: the sends the card has run - the largest sent_as of the flights being landed, the sends behind a fetch that was waited for, and all of them at the end of a waited submission. claim_card_only avoids sends after it. Steady state is as before: a lazy copy's notes are of its first send, which every later landed flight ran behind. Test: a send queued ahead of the merge-fetches but not run still keeps its page from the card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ExitProcess can end the fetching thread while it holds a slot's lock (held through its wait for the card, up to 60 s) or WANT: the fault handler, land_range, let_go, freed and abandon then waited for ever. Now, once the thread is gone (stuck: started, its handle signalled), nothing waits for those locks: slot locks are taken with try_write in a bounded loop, WANT with try_lock, and the fetch is waited for by polling a per-slot served id, not a condvar that would take WANT back. Giving up makes the slot's pages read-write as they are (older bytes, acceptable at exit) and says so with OutputDebugStringA, which takes no lock of ours. fetch_if_cards keeps overwriting what was marked to go up on pages the card alone holds with the card's bytes (logged once): nothing can have written those bytes legitimately, as title memory there is inaccessible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@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:
The log line every 5 s shows whether it engaged. When it works it reads something like What I'd most like to know:
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 |
|
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 (b126a98), 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): https://github.com/Chezzuss/VIctory/commit/5ba8b55fc09e41889da3271bc7f0f193c539d7eb (branch What we saw: with Fix: 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. |
|
@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:
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 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 |
|
Follow-up: the commit link above points into a private repo, sorry. The same fix is now public in our fork Mangrove:
Same caveat as before: builds and lazy tests pass on your head; the in-game check was on our merged tree. Thanks again, @urielbeaupre. |
Conflicts: - watch.rs: trustno1-coder#933's protect_here/protect_run split kept, upstream's soft views parameter passed through both. - shadow.rs: upstream's has_pending and PageMerge landing loop taken (on trustno1-coder#1298's copied tuple); trustno1-coder#1184's lazy landing applied to upstream's outside_sorted_into parts. - pool.rs: trustno1-coder#814's take_from_with (one empty block made ahead) kept; its base is the same trustno1-coder#661 change upstream merged. - card_steps.rs: upstream's taken whole (VICTORY_PLACED_FILLS, trustno1-coder#740); trustno1-coder#1298's card_steps part dropped. - draw.rs: upstream's trustno1-coder#532 values; trustno1-coder#814's cached slot handle kept inside upstream's rest() timing. - descriptor/host.rs: upstream's TextureQueue ordering taken whole; trustno1-coder#814's VICTORY_DUE_FRESH_FIRST and its play.rs default dropped. A test module both sides added was kept once. - emit/mod.rs, send.rs: both sides kept.
…o1-coder#1038's write-watched large XMemAllocDefault) for measuring Conflicts with this fork's trustno1-coder#1014 port resolved by keeping both (lib.rs exports, title_memory_freed). VICTORY_LAZY_LAND and VICTORY_LAZY_FETCH stay off by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he guard (VICTORY_STORE_BESIDE=1, VICTORY_COPY_BESIDE=1) RTX 5070 Ti at the deck, native 1440p, no DLSS (2026-11-28): 44.0 ms against 45.0, preparing 28.9 against 33.9 ms, copies 12 against 17 ms; the picture as before. Also in play-foxhound.ps1, which the desktop shortcut uses. Measured and left off: VICTORY_HELPER_PRIORITY=1 (46.3), fewer pool threads (47.3), VICTORY_FAULT_UNLOCKED=1 alone (46.0), lazy landing of trustno1-coder#1184 (45.0-45.1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 ahead The 21 MB buffer ( For the record, in case that buffer comes back (e.g. with the structure builder on):
Thanks to everyone who reviewed and tested it, and to Marsietiss for the keep-ahead report. 🤖 Generated with Claude Code |
|
@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
Good call closing it for current |
Conflicts:
- shadow.rs: upstream's Copied { pages, ranges } replaces trustno1-coder#1298's tuple;
trustno1-coder#1298's batched nothing_new_with keeps its shape on it (Copied::ranged
replaces ranged_in); trustno1-coder#1184's lazy landing and its tests follow (pages,
arena). An unused copy_all of trustno1-coder#1298's and the VICTORY_WIDE_CHUNK tests
(helpers dropped earlier) are left out.
- watch.rs: trustno1-coder#1062's owned memory is told in asked() beside trustno1-coder#1298's binary
search, and counted as known by is_published() (so the batched
nothing_new sees it too, sampled before the journal's lock).
- structure.rs: upstream's trustno1-coder#1103 (ours came adapted through trustno1-coder#1226).
- lib.rs: both modules.
Depends 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 perf(xmem): write-watch large XMemAllocDefault allocations #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