Repository navigation
GPU: find a buffer holding an address past many smaller ones; reuse loose windows that hold a range - #402
Conversation
…oose windows that hold a range `shadow::find` looked at only the 64 buffers starting closest below an address. A big buffer with more than 64 smaller buffers placed in it before the address was missed, and the range fell through to `loose`, which made a second 4 MiB host copy of memory the big buffer's copy already had, not aliased with it. The search now goes back as far as the longest buffer registered so far (`MAX_SPAN`): one starting further below cannot hold the range. `loose` reused a window only for the exact same (start, length), so a range inside a window made for a range spanning two windows got another copy. It now reuses any window holding the range. It also gives no copy for null-page addresses, or for memory that is not committed when a new window would be made, instead of 4 MiB of zeros. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @kxiserino for the wider shadow lookup and loose-window reuse. I tested head Result: 4 passed, 0 failed (44 filtered out). The tests cover finding a parent past many smaller children, widening search for registered buffers, reusing loose windows for contained ranges, and requiring loose memory to be committed. These exercise address-range lookup behavior without a title workload. |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 022e9c8 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed). I could not measure the duplicate copies without a game package.
enclosing:
- Bounding the backwards walk by
MAX_SPANis correct. A buffer starting belowend - MAX_SPANwould be longer than the longest buffer ever registered. fetch_maxunder the map lock keeps it monotonic acrossunregister.- The
lowest > addressearly-out avoids an invertedBTreeMap::range, which would panic. - Hits are found exactly as
.take(64)found them, at the same position in the walk.
loose:
- Reusing any window that encloses the range removes the window-inside-a-window duplicates.
- Returning
Nonebelow 0x10000 and for uncommitted memory stops it from allocating 4 MiB zero copies that are never freed. Thecommittedcheck runs only before a new window is made, as the description says. checked_next_multiple_ofcloses the overflow at the top of the address space.
Nit: enclosing_window's doc says "the innermost if several do". For two windows with the same start, the reverse walk over (start, len) meets the longer one first. In practice a window shares its start with the shorter one only when a cross-window range starts in the same 4 MiB block, and either copy holds the range. So this is the doc, not the behaviour.
AI-assisted (Claude Code).
|
Correction to the count in my review: the run at 022e9c8 was 268 passed, 0 failed (not 265). The verdict is unchanged. AI-assisted (Claude Code). |
… past many smaller ones; reuse loose windows that hold a range Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I checked the loose-window reuse part against the allocation order in a saved Windows 11 / RTX 5070 mission-loading trace. The instrumented build ( For an offline comparison I passed the 322 rounded window extents, in creation order, through The trace records successful window allocations, not every original unrounded request or registered-buffer lifetime. This checks the lookup on shapes and ordering from the title; it does not measure what the whole PR saves in a live run or test the wider registered-buffer search. AI-assisted. |
…d the address: the search goes back the longest buffer's length, not 64 entries (from Marvisak/VIctory Marvisak#402) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
|
@kxiserino #2088 is stacked on this PR. Your commit is in it unchanged, and you're still its author. I only resolved its conflict with current Measured with this PR on an RTX 5080 under Proton, before the world (menu): 55 loose windows (264 MB), against 66 (308 MB) on |
Backport Marvisak/VIctory#402 and #2088: locate the enclosing allocation, reuse covering windows and use 256 KiB units in Series S while retaining 4 MiB in Series X. Add a title-free opt-in native test for CPU-owned GPU-readable memory; no runtime in-place mapping is enabled by the test. Co-authored-by: KaiserBloo <kaiserbloo@protonmail.com> Co-authored-by: desp <me@desp.lol>
…#2088 76cdef6: loose title memory in 256 KiB windows, with Marvisak#402's window reuse) into play/main" This reverts merge 75b3f75 (Marvisak#2088) on play/main, with the mainline kept (git revert -m 1). The user's same-save A/B runs in the safehouse, on the RTX 5070: PM1 (play/main 75b3f75, with Marvisak#2088) against PM0 (404c7e0, without it). With Marvisak#2088's 256 KiB windows, host copies of title memory went to about 6 GB a frame, against about 0.55 GB without. Preparing averaged 981 ms against 377 ms, and the median frame was 428 ms longer: PM0 - PM1 95% bootstrap CI [-569, -346] ms. Page faults were 52.7k against 27.6k a frame. Marvisak#2088 did save about 2.9 GB of memory. That win is kept for a later, fixed form, one that does not copy that much more each frame. Everything else on play/main stays, including the read_only: false fix the merge carried (it was in Marvisak#2088's own test, so it goes with it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…instead of 4 MiB (stacked on Marvisak#402)
Clean merge: brings the overlapping-windows test and moves MAX_SPAN's place; the in-place code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotekompotek
left a comment
There was a problem hiding this comment.
LGTM — this fixes a real lookup bug, not just a heuristic widening.
enclosing's bound is tight: an entry holding[address,end)must start in[end-span, address]where span is the longest registered buffer, so the.rev().findyields the innermost holder — the.take(64)scan it replaces provably missed a parent past 64+ placed children (the test demonstrates exactly that).enclosing_windowapplies the same trick to LOOSE keyed (start,len), correctly picking the innermost among overlapping windows (spanning window vs smaller one inside it).- Moving the
committedcheck beforeshared_buffermeans a stale/null address no longer fabricates a window of zeros and reports success — returning None is the honest answer. LOWEST_MAPPED,saturating_add,checked_next_multiple_ofcover the boundary cases; span tracking is monotonic under the right locks.
r4tedx's in-game A/B of this branch (RTX 5070) measured the 256 KiB windows at +428 ms median frame time: host copies grew from about 0.55 GB to about 6 GB per frame in the open world, for about 2.9 GB of host memory saved. Loose windows are 4 MiB again (main's size) unless VICTORY_LOOSE_WINDOW_KIB asks for a power of two from 64 to 4096 KiB. Marvisak#402's window reuse stays as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 2f0590a)
…B=256 for machines short on memory 256 KiB loose windows: the GPU's system memory 5.6-5.8 GiB instead of 8.7-8.9 GiB in the prison scene, frames no slower; one crash in eight runs with it, none without, so it stays opt-in.
…ash link is ruled out Both title crashes of the night came from builds with Marvisak#402/Marvisak#2088 in: a null read in title code entering the world (256 KiB windows) and one while loading (default 4 MiB windows, dstorage debug log on), 2 of 17 runs, against none in about 30 runs without them. Marvisak#402 changes, by default, which copy a lookup finds. Not proven, but players pull this branch, so the code goes back to b25fd9a's until an A/B says otherwise. Reverts 1669715, dee9e0d, 2cbfd20, ce1351d, 9c29e6a, dce3ee8.
…rash is not theirs Reverts c73cbee. An A/B with the DirectStorage debug log on (which slows the submit path) crashed once in five runs on each side, with and without these commits, the same way as before: title code reading a null pointer in its job system (thread entry +0x2215eca, dispatch +0x2570xxx), while loading or entering the world. All four such crashes of the night share that path. Without the debug log: 1 in 16 runs with these commits (with 256 KiB windows), 0 in about 30 without; with it, 3 in 11 across both builds. So it looks like a timing race around DirectStorage, not these commits. The docs say so; 256 KiB windows stay opt-in.
r4tedx's in-game A/B of this branch (RTX 5070) measured the 256 KiB windows at +428 ms median frame time: host copies grew from about 0.55 GB to about 6 GB per frame in the open world, for about 2.9 GB of host memory saved. Loose windows are 4 MiB again (main's size) unless VICTORY_LOOSE_WINDOW_KIB asks for a power of two from 64 to 4096 KiB. Marvisak#402's window reuse stays as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 2f0590a)
…B=256 for machines short on memory 256 KiB loose windows: the GPU's system memory 5.6-5.8 GiB instead of 8.7-8.9 GiB in the prison scene, frames no slower; one crash in eight runs with it, none without, so it stays opt-in.
…ash link is ruled out Both title crashes of the night came from builds with Marvisak#402/Marvisak#2088 in: a null read in title code entering the world (256 KiB windows) and one while loading (default 4 MiB windows, dstorage debug log on), 2 of 17 runs, against none in about 30 runs without them. Marvisak#402 changes, by default, which copy a lookup finds. Not proven, but players pull this branch, so the code goes back to b25fd9a's until an A/B says otherwise. Reverts 1669715, dee9e0d, 2cbfd20, ce1351d, 9c29e6a, dce3ee8.
…rash is not theirs Reverts c73cbee. An A/B with the DirectStorage debug log on (which slows the submit path) crashed once in five runs on each side, with and without these commits, the same way as before: title code reading a null pointer in its job system (thread entry +0x2215eca, dispatch +0x2570xxx), while loading or entering the world. All four such crashes of the night share that path. Without the debug log: 1 in 16 runs with these commits (with 256 KiB windows), 0 in about 30 without; with it, 3 in 11 across both builds. So it looks like a timing race around DirectStorage, not these commits. The docs say so; 256 KiB windows stay opt-in.
Conflicts in crates/victory-gpu/src/shadow.rs: main's copies now come back as Arc from Shadow::new and bump GENERATION through changed(); kept that and added Marvisak#402's MAX_SPAN search, the loose-window reuse (LOOSE_SPAN, enclosing_window) and the committed/null-page checks on top. Marvisak#402's tests join main's `pub(crate) mod tests`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
update/402-main is Marvisak#402 with main merged in. Its shadow.rs replaces this branch's copy of Marvisak#402's commit (same change on an older main); this branch's own changes go on top: 256 KiB windows and the overlapping-windows test. The two-step lookup stays reverted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx's in-game A/B of this branch (RTX 5070) measured the 256 KiB windows at +428 ms median frame time: host copies grew from about 0.55 GB to about 6 GB per frame in the open world, for about 2.9 GB of host memory saved. Loose windows are 4 MiB again (main's size) unless VICTORY_LOOSE_WINDOW_KIB asks for a power of two from 64 to 4096 KiB. Marvisak#402's window reuse stays as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… range (Marvisak#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB)
Conflicts in crates/victory-gpu/src/shadow.rs: main's copies now come back as Arc from Shadow::new and bump GENERATION through changed(); kept that and added Marvisak#402's MAX_SPAN search, the loose-window reuse (LOOSE_SPAN, enclosing_window) and the committed/null-page checks on top. Marvisak#402's tests join main's `pub(crate) mod tests`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
update/402-main is Marvisak#402 with main merged in. Its shadow.rs replaces this branch's copy of Marvisak#402's commit (same change on an older main); this branch's own changes go on top: 256 KiB windows and the overlapping-windows test. The two-step lookup stays reverted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx's in-game A/B of this branch (RTX 5070) measured the 256 KiB windows at +428 ms median frame time: host copies grew from about 0.55 GB to about 6 GB per frame in the open world, for about 2.9 GB of host memory saved. Loose windows are 4 MiB again (main's size) unless VICTORY_LOOSE_WINDOW_KIB asks for a power of two from 64 to 4096 KiB. Marvisak#402's window reuse stays as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… range (Marvisak#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB)
Summary
Two ways
shadow::findmakes duplicate host copies of title memory.findgives up after 64 entries. It walkedBUFFERSbackwards fromaddresswith.take(64). If a big parent buffer (a heap with its placed buffers) has more than 64 registered sub-buffers between its start andaddress, the parent is never reached. The range then falls through toloose(), which makes a separate 4 MiB host copy that isn't aliased with the parent's copy. That copy is GPU memory the parent's copy already covers, and the two copies' contents can diverge.MAX_SPAN: the longest buffer registered so far, updated underBUFFERS' lock inregister. It is a monotonic upper bound, so it stays correct afterunregister.enclosing(map, span, address, end)scans(end - span, 0)..=(address, usize::MAX)backwards. A buffer starting further below than that can't reachend. It returnsNoneup front when the range is longer than any buffer, soBTreeMap::rangenever gets an inverted range.loosereused a window only for an exact(start, len)match. A range spanning two windows gets a window of its own. A later range inside that window, or inside a plain window when a longer key exists, then got yet another copy.enclosing_windowreturns any window inLOOSEthat holds[address, end). Likeenclosing, it's bounded by the longest window made (LOOSE_SPAN).loosenow returnsNonefor addresses below0x10000(the null page and guard area). It also returnsNonewhen no window holds the range andaddressisn't committed (texture::committed(address, 1)). Stale, null or unmapped addresses used to get 4 MiB of zeros in a new host buffer that was never freed.VirtualQuery. Nothing negative is cached, so memory committed later still gets its window.endrounds up withchecked_next_multiple_of, so a range at the top of the address space returnsNoneinstead of overflowing.Testing
Synthetic only: local maps, made-up addresses and the test's own reservations.
a_parent_is_found_past_many_children: a 256 MiB parent with 200 child buffers. It checks that the old.take(64)walk misses the parent and thatenclosingfinds it, including near its end. A range inside a child still finds the child (innermost). A range across two children finds the parent. Ranges past, before and longer than every buffer find none.registered_buffers_widen_the_search:registerraisesMAX_SPAN, and a parent with 100 children registered in the global map is found. Everything is unregistered afterwards.loose_windows_are_reused_for_ranges_inside_them: covers sub-ranges of a plain window and of a window spanning two windows, ranges that cross a window's end, and ranges past, before or longer than every window.loose_memory_must_be_committed: null-page addresses, a reserved but uncommitted range, and the top of the address space all getNone.shadow::findorloosewith fake addresses that expect a copy (checked with grep andcargo test --workspace).Results:
cargo test --workspace: all pass.victory-gpuhas 47 passed, 1 ignored.cargo test -p victory-gpu -- --test-threads=1: 47 passed. With--features diagnostics: 49 passed.cargo clippy -p victory-gpu [--features diagnostics] -- -D warnings: clean.--all-targets: clean apart from the existing missingSAFETYcomment athost.rs:267onmain, which Chore: clear two workspace Clippy errors #355 fixes.cargo xtask policy:asset policy: 151 files ok.Tradeoff: a lookup for memory that no buffer holds now looks at every buffer starting within the longest buffer's length below it, where it used to stop at 64. Those are the lookups that then go to
LOOSE.🤖 Generated with Claude Code