GPU: find a buffer holding an address past many smaller ones; reuse loose windows that hold a range #402
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!402
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-402"
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?
@kxiserino on GitHub · 2026-11-24 02:57 UTC · original
kxiserino:gpu/shadow-find-enclosing-and-loose-reuse→main· +176 −11 · 1 files · 1 commits · openSummary
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 #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
@jeremygold02 on GitHub · 2026-11-24 04:31 UTC · original
Thanks @kxiserino for the wider shadow lookup and loose-window reuse. I tested head
022e9c82f0ee147a16b5a06c391de5a8d9beeab3with: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 on GitHub · 2026-11-24 06:10 UTC · original
Correction to the count in my review: the run at
022e9c8was 268 passed, 0 failed (not 265). The verdict is unchanged.AI-assisted (Claude Code).
@jeremygold02 on GitHub · 2026-11-24 16:59 UTC · original
I checked the loose-window reuse part against the allocation order in a saved Windows 11 / RTX 5070 mission-loading trace. The instrumented build (
6538a86) used the exact(start, length)cache for loose windows. The trace logged 322 successful shared-buffer creations there: 301 at 4 MiB and 21 at 8 MiB. The cache held those buffers for the process lifetime. Their sizes sum to 1,372 MiB, covering 1,244 MiB of distinct guest address ranges. These are buffer sizes, not a measurement of resident RAM or VRAM.For an offline comparison I passed the 322 rounded window extents, in creation order, through
enclosing_windowfrom022e9c8and checked each lookup against a linear containment scan. Five extents already fit a previously retained window. The replay therefore created 317 windows totaling 1,352 MiB (20 MiB fewer). Overlap alone accounted for more bytes than this because many ranges overlapped only partially or the larger window was created later.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.
@Marvisak on GitHub · 2026-11-25 00:16 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/shadow.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@desplmfao on GitHub · 2026-11-25 04:34 UTC · original
@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
main(940d32f, inshadow.rs: the imports,changed()next to yourMAX_SPAN,Shadow::newnow returning anArc, and the new tests next to yours). That might save you the rebase.Measured with this PR on an RTX 5080 under Proton, before the world (menu): 55 loose windows (264 MB), against 66 (308 MB) on
main. While loading, the windows still grew to about 700 (3.4 GB). #2088 makes them 256 KiB instead.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.