GPU: reuse loose windows that hold a range (#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB) #2088
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!2088
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2088"
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?
@desplmfao on GitHub · 2026-11-25 04:34 UTC · original
desplmfao:perf/loose-window-size→main· +253 −13 · 2 files · 10 commits · openStacked on #402 by @kxiserino: its commit is the first one here, unchanged apart from resolving its conflict with current
main(940d32f), and keeps its author. The second commit is the change below. If #402 lands first, this reduces to one line plus its comment.Problem
Memory outside every buffer object (
shadow::loose) gets host copies of the aligned windows that lookups touch, and those copies are never freed. A window was 4 MiB. While Grand Theft Auto VI loads its world (Series X 1.0.2.1), about 700 windows are live, 3.4 GB of host memory. They sit inMEMORY_POOL_L0system memory, so it's RAM on top of the title memory they copy, and every page-table submission refreshes them.Measured
I counted which parts of each window lookups ask for (64 KiB pieces, diagnostics build, temporary counters not part of this PR): at the same point of loading, 968 MB of 3,416 MB. That's about 30% of the bytes copied.
main+ #402)no descriptor slots for a title memory copy's viewsThat's about 1.2 GB less while loading. Each window is a host buffer and an entry in the title-memory page table, so smaller windows mean more of them. 256 KiB was chosen to keep that count moderate. 64 KiB would cut more bytes but multiply the windows again.
In the open world
Added later, once the world loaded here (the hang was a single compute pass, skipped with
VICTORY_SKIP_PIPELINES=72f552f4553fb5f9; see #844). Same stack otherwise (940d32f+ other open PRs), same save, about 2 min into the open world. Host copies are counted fromhost copies of title memoryon theheap viewsline; the world uses one page table, and it holds one view pair per copy.main)So in the world the smaller windows save about 5 GB of copies and about 13 GB of RSS. They cost about 3× the descriptor pairs, which is still far below the view heap's 2^21 slots.
Also tried, and not part of this PR: freeing windows no lookup has used for 5 s. During loading, almost all windows are used again within seconds (680 of 734), and others are held by lists or heap slots, so it barely freed anything.
Tested
main+ #1849 (without it the title hangs at world entry under Wine).+0x23cf683), the same as runs without this change. The open-world numbers above came later, with the one hanging pass skipped. Frame time is not measured.cargo test -p victory-gpu -- --test-threads 1: 133 passed, 14 failed. Plainmainon this machine fails the same 14 (129 passed). #402's four tests pass, and they are written againstWINDOW, so they cover the new size.cargo clippy -p victory-gpu --all-targets -- -D warnings: nothing new.Related
shadow.rs(pooling view copies). It might conflict textually, but the two change different things.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@jeremygold02 on GitHub · 2026-11-25 04:40 UTC · original
Triage verdict — Keep the window-size experiment stacked on #402 (
b670a33)Evidence
main. The reported memory reduction trades fewer copied bytes for many more windows, each with its own descriptor pair. Stack commits · Pair allocationloosecan allocate a spanning window that overlaps it. The page table prefers smaller complete-page copies, while a spanning buffer view can still use the larger copy. That leaves a coherence case worth checking at the new, more frequent boundaries. Window lookup · Page ownershipChecks and limits
Next step
This verification was AI-assisted.
@desplmfao on GitHub · 2026-11-25 07:15 UTC · original
Thanks, good catch. I added the synthetic case you described (
f83faa7,overlapping_windows_agree_through_title_memory):It passes on the RTX 5080 under Proton. The full
victory-gpusuite gives 134 passed, with the same 13 NVIDIA/Wine failures asmainhere.What the test can't make safe is two overlapping copies within one submission. If a shader writes through B and another reads the same bytes through A before the copy-back, it reads the old bytes. That's true of any two copies of the same memory, title buffers and windows included, and on
mainwith 4 MiB windows too. Smaller windows put boundaries 16× as often, so a range crosses one more often. I haven't seen a symptom I could tie to it, but I haven't looked for one specifically.On descriptor-pair pressure: in Grand Theft Auto VI's world with 256 KiB windows, I've seen 6,000–8,300 live windows in the
host copies livelines, and one page table. I haven't logged pairs per table against the 4 MiB baseline yet. I'll add that number from the next world run.@desplmfao on GitHub · 2026-11-25 09:02 UTC · original
@jeremygold02 here's the number I promised: descriptor pairs per page table with 4 MiB windows (without this PR) vs. 256 KiB (with it). Upstream's page table writes one view pair per host copy of title memory, and the world uses one table, so pairs = host copies (
host copies of title memoryon theheap viewsdiagnostics line).Same stack otherwise (upstream
940d32f+ our other open PRs), GTA VI Series X 1.0.2.1, same save, about 2 min into the open world, RTX 5080, Linux/Proton:So the smaller windows do cost about 3× the pairs, but 17k is still far below the view heap's 2^21 slots. In exchange, the copies hold about 5 GB less, and the process uses about 13 GB less RAM. Without this PR, the run was at 29 GB after 3 minutes and still growing, so I stopped it.
@Marvisak on GitHub · 2026-11-25 10:33 UTC · original · edited 2026-11-26 02:16 UTC
Automated triage for the maintainers.
Merge candidate.
6ebed99merges cleanly and keeps the 4 MiB default: incrates/victory-gpu/src/shadow.rs,window()readsVICTORY_LOOSE_WINDOW_KIBonce (window_fromaccepts a power of two, else 4 MiB), and the README lists the switch. What changes by default is #402's part, carried here on currentmain:enclosingsearches back byMAX_SPANinstead of a fixed 64 entries,loosereuses a window that already holds the range (enclosing_window), and refuses addresses belowLOWEST_MAPPEDor not committed (texture::committed). Tests cover the lookup past many placed buffers, window reuse, overlapping windows through title memory, the variable's parsing and uncommitted memory. CIcheckpasses.On your reply: making the small windows opt-in answers the open-world A/B (+428 ms median, ~6 GB copied per frame), so the default path no longer pays that cost. Two notes for the maintainer: the PR title still says "256 KiB windows instead of 4 MiB", which is now only the opt-in; and since this PR carries #402's commit, merging it makes #402 (which conflicts with
main) redundant.Generated by Claude Code
@desplmfao on GitHub · 2026-11-25 10:59 UTC · original
On the triage's first point, unbounded misses in
enclosing: measured, and addressed inb73bb8b.Before (title's world, RTX 5080, Proton, our stack on top of this PR): every 5 s, about 1.4 million lookups hit after looking at 1 entry, and about 330,000 missed. Each miss scanned every buffer starting within
MAX_SPANbelow the address.MAX_SPANwas 174 MB, so a miss looked at 480 entries on average and up to 2,842, all underBUFFERS' lock.Change: buffers of 1 MiB or more are also kept in a small map of their own. A lookup first scans
BUFFERSonly within the longest smaller buffer's length below the address (1008 KB here), then only the big buffers further below, back toMAX_SPAN. Only a big buffer can hold the range from further below, so the result is the same innermost buffer. A new test checks the two-step lookup against the one-stepenclosingon a heap holding hundreds of placed buffers.After, same place: misses look at 4.2 entries on average, at most 218. Hits are unchanged at 1. Frame time didn't move measurably (675 vs 725 ms, within run-to-run noise), so the lookups weren't a big share of a frame, but they no longer hold the lock long.
cargo test -p victory-gpu --lib shadow::under Proton: 10 passed. Clippy is clean with and without--features diagnostics.The second point (two overlapping copies within one submission can disagree, and smaller windows make boundary crossings more frequent) stands as described.
overlapping_windows_agree_through_title_memorycovers agreement across submissions, not within one.@desplmfao on GitHub · 2026-11-25 12:48 UTC · original
A correction to my earlier comment: I've reverted the lookup change in
76cdef6(a new commit, no force-push), so this PR is back to exactly what it was beforeb73bb8b.In the title, the two-step lookup broke the picture: spikes out of the player character's head and triangles stretched across the scene, in two runs. The same build without it is clean. I found one real bug, a stale entry in the big-buffer map when a key is registered again shorter, and fixing it removed the spikes, but the stretched triangles stayed, so I don't understand the change well enough to keep it here.
The triage's first point (misses in
enclosingscan every buffer withinMAX_SPAN, about 480 entries per miss in the world) is therefore open again. It costs lock time but doesn't change results. If I come back to it, it'll be a separate PR that has been checked in the title first. Sorry for the noise.@r4tedx on GitHub · 2026-11-25 21:22 UTC · original
@desplmfao, an in-game A/B of this PR on an RTX 5070 (12 GB, Windows 11), for the memory/time trade-off. Our play build is
main940d32fplus a stack of open PRs. The two exes differ only by this PR's merge (head76cdef61, so with your revert ofb73bb8b). Same open-world save, same switches, about 200 world frames each. Local title data was used for the runs; only log figures are given here.On memory, the PR does what it says. In an earlier, indoor scene, loose windows took 5,520 MB of host copies with 4 MiB windows; in this run they take 2,640 MB, so roughly 2.9 GB saved. But in the open world the copies per frame grow about tenfold, and that's what the frame time pays for. My guess, not checked in the code: the same loose ranges are now spread over many more windows, and each window that a page-table submission refreshes is copied whole, or a lookup that misses refills a window it just dropped. That would trade bytes held for bytes moved every frame. A diagnostics count of loose windows refreshed per frame, and their bytes, with 4 MiB against 256 KiB, would tell.
We've taken it out of our play build for now and kept the numbers for when there's a form that keeps the memory win.
AI-assisted
@desplmfao on GitHub · 2026-11-26 01:27 UTC · original
@r4tedx thanks for the A/B. +428 ms median, and ~6 GB copied per frame in the open world instead of ~0.55 GB, is far too much for the ~2.9 GB it saves.
2f0590amakes the 256 KiB windows opt-in:VICTORY_LOOSE_WINDOW_KIB=256(a power of two from 64 to 4096) turns them on, and the default is 4 MiB, as onmain. #402's reuse of a loose window that already holds the range stays on.#402 has conflicted with
mainfor about 20 hours, so this PR now builds onupdate/402-main(9f64779). That branch is #402's single commit, unchanged, withmain(63bcca4) merged in. The only conflict was inshadow.rs, wheremain'sArc/changed()copies now carry #402's lookup and reuse.shadow::andwatch::give 31 passed under Wine (RTX 5080), including a new test of the variable's parsing. Clippy is clean with and without diagnostics. Next, I want to find out why the small windows copy so much more: a diagnostics count of loose windows refreshed per frame, and their bytes, at 4 MiB against 256 KiB, as you suggested.GPU: copy loose title memory in 256 KiB windows instead of 4 MiB (stacked on #402)to GPU: reuse loose windows that hold a range (#402), 256 KiB windows opt-in (VICTORY_LOOSE_WINDOW_KIB)@DenRakEiw on GitHub · 2026-11-25 04:41 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib shadow::— 8 passed, 0 failed (includinga_parent_is_found_past_many_childrenandregistered_buffers_widen_the_search)cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean 256 KiB loose title-memory copy windowing and enclosing-entry lookup with solid unit tests. Looks good.
AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 05:02 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Loose title memory copied in 256 KiB windows instead of 4 MiB — finer copy granularity, less over-copy; check the window loop's tail handling.
@kotekompotek on GitHub · 2026-11-26 03:01 UTC · original · approved these changes
LGTM — the delta over #402 (which I just reviewed: enclosing lookup + committed gate) is the window-size switch and its coherence test.
window_fromenforces power-of-two before the align-down& !(window-1)can depend on it,checked_mul/checked_next_multiple_ofcover the arithmetic edges, and the default stays 4 MiB.changed()after LOOSE insert was missing in the base — needed now that more distinct windows appear.overlapping_windows_agree_through_title_memoryis the right test for the new overlapping-window possibility: title write → both copies see it; GPU write through the spanning window → copy-back → title → the enclosed copy picks it up next refresh. The comment honestly documents the intra-submission divergence, which is identical to any two copies of the same bytes.@pickles976 on GitHub · 2026-11-26 06:09 UTC · original
Wine11.0 / NVIDIA RTX4060 Laptop8GiB /16GiB system RAM, driver590.48.1, DXVK3.1.1, diagnostic relaxed vkd3d-proton3.2.0
2576c0b4adfae4a+(assertions disabled and allocator/listfrom_ifacevtable checks removed; null checks retained):At
6ebed99283da64d5118705a26ecd28c980aab27c,VICTORY_LOOSE_WINDOW_KIB=256, four focused tests passed,0failed/ignored:window_sizes_are_any_power_of_two,loose_windows_are_reused_for_ranges_inside_them,loose_memory_must_be_committed,overlapping_windows_agree_through_title_memory. Fresh compile, NVIDIA enumerated. The only test change makes missing D3D12 host fail instead of return. The overlap fixture checks GPU-backed/title-memory copy coherence, not shader dispatch. Logverify-pr2088-wine-256k.log.Then ran the full owner branch, not a granularity-only transplant, with a local diagnostics-only two-second try-lock probe of
LOOSEcount/backing bytes. Fresh release44.05s. No skip-pipeline or forced in-place flags. Same6,000MiB GPU /2,048MiB available-RAM /10GiB disk guard and9GiB/512MiB scope caps.20261126T060451Zended at its110s wall limit (exit137), not a resource stop. One Enter at57s moved the verified account picker to loading; the100s capture was still loading art. Last ownership sample109.9s:3,295loose buffers,1,171MiB backing,window262,144bytes. Last/min availableRAM2,437MiB; maxscope6,759MiB,scopeanon2,631MiB; maxGPU3,355MiB; mindisk19.176GiB.This is only~53s after entering loading, not proof that loading completes or the RAM ceiling is solved. Earlier main+#2856 measured2,604MiB loose backing later in loading; source, timing and cache state differ, so that is not a matched-stage memory-saving claim. Compute host-pipeline refusals
0x80070057(b68f0931f1f47e61,13dfdd3b1136e407) remain. No controllable gameplay or world-FPS result; the documented small-window copy/frametime tradeoff is unmeasured here. Logs20261126T060451Z-{console.log,resources.csv,guard-events.jsonl}; capturesmenu-20261126T060549361265Z.png(loading stars) andmenu-20261126T060631047369Z.png(loading art).@fuzeofficlal on GitHub · 2026-11-26 12:39 UTC · original · approved these changes
Reviewed and verified at head
6ebed992againstorigin/main(63bcca43) on Windows 11 (RTX 5090 + WARP,VICTORY_D3D12_DEBUG=1, both default 4 MiB andVICTORY_LOOSE_WINDOW_KIB=256):VICTORY_LOOSE_WINDOW_KIB(crates/victory-gpu/src/shadow.rs:1082-1095, documented inREADME.md:220).window_fromenforcesis_power_of_two()andchecked_mul(1 << 10)so alignment masks andend.checked_next_multiple_of(window)? - start(shadow.rs:1132) cannot overflow or underflow.#402's lookup improvements onto63bcca43:enclosing(shadow.rs:1023-1032) searches back byMAX_SPANinstead of a fixed 64 entries,enclosing_window(shadow.rs:1108-1118) reuses existing loose windows containing[address, end),loose(shadow.rs:1124-1148) gates onLOWEST_MAPPED(0x10000) andtexture::committed(address, 1), andchanged()notifies page tables onLOOSEinsertion.overlapping_windows_agree_through_title_memory(shadow.rs:1830-1869) verifies cross-submission coherence through title memory; structured-view arena/stride paths are untouched.#402and modifiesshadow.rs::loose(), it supersedes#402and overlaps#2856inshadow.rs(only one should land, or they should be reconciled).git merge-treeagainstorigin/main(63bcca43);cargo xtask policy(191 files ok);cargo clippy -p victory-gpu --all-targets --locked -- -D warningsclean with default features and--all-features.shadow::tests15/15 passed with both 4 MiB default andVICTORY_LOOSE_WINDOW_KIB=256; with--features diagnostics+VICTORY_D3D12_DEBUG=1,shadow::tests+draw::tests35/35 (4 MiB) andshadow::tests15/15 (256 KiB) passed with zero debug-layer errors.VICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1):shadow::tests15/15 (256 KiB) andshadow::tests+draw::tests35/35 (4 MiB) passed.LGTM.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.