Repository navigation
GPU: loose windows can sit in video memory the CPU writes - #2875
Luislariosss wants to merge 3 commits into
Conversation
Loose windows were keyed to their exact (start, length): a memory range a wider window already spanned made its own host buffer and its own copy anyway, although one measured run saw most asks covered by a wider neighbour (36,611 reuses, 153 GB not copied). A miss now takes the first window that covers it - the shared segment these buffers fill is the one that dies (measured: its budget hit 103-104% while the card's own stayed at 50%, and the run ended in a Close() failure the old message mislabeled as an invalid command). A reuse is counted and printed with the periodic lines; a hardware-gated test pins the covering reuse and the ask past the window.
The loose windows are the shared segment's own content and are never freed; a run could not see how many there were or what they weighed. Their count and bytes join the reuse count in the periodic lines, so the next lever (freeing or merging them) starts from a measured size.
The non-local segment - half the system's RAM - is the ceiling every long run dies at, and the loose windows are its bulk (measured: 878 of them, 3,926 MB, never freed, against a 7,465 MB budget; the card's own memory sat half empty). VICTORY_LOOSE_IN_GPU_UPLOAD puts each new loose window in a GPU upload heap (write-combined, CPU-mapped) where the host has one, falling back to the system-memory buffer a card without the heap keeps. The CPU reads of such a window (snapshots, copy-backs) are uncached bus traffic: they are counted and warned of once, and the periodic line carries the count.
AwsAli05
left a comment
There was a problem hiding this comment.
I independently checked the allocation request from buffer_in on an RTX 5070 Ti with the D3D12 debug layer requested. Options16 reported GPU upload heaps supported. A 4 MiB committed GPU_UPLOAD buffer created with COMMON and ALLOW_UNORDERED_ACCESS succeeded, and Map returned a non-null pointer.
That confirms the allocation path on this device. The next useful comparison would be a matched world run with the option on and off, recording local and non-local memory along with frame time. CPU readback volume would help explain any frame-time regression, since a count of readbacks treats small and large ranges alike.
AI-assisted review and synthetic D3D12 probe.
kotekompotek
left a comment
There was a problem hiding this comment.
Sound: opt-in WC-heap residency for loose windows trades uncached readback for freeing system RAM (the documented small-RAM ceiling), the OPTIONS16 probe plus allocation-failure fallback degrade safely to system memory, and WC_READS makes the cost observable. Off by default is the right rollout for a latency-sensitive path. LGTM.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head 25c02cd2 cleanly merged onto origin/main (63bcca43) on Windows 11 x64 across both a GPU Upload Heaps capable adapter (NVIDIA GeForce RTX 5090, GPUUploadHeapSupported == true) and a fallback adapter (D3D12 WARP, GPUUploadHeapSupported == false), with VICTORY_D3D12_DEBUG=1.
Code Review
- Covering-window reuse in
Shadow::loose(map.range(..(start, u64::MAX)).rev()) cleanly reuses any wider loose window (including same-start wider windows) and keeps opt-in risk low viaVICTORY_LOOSE_IN_GPU_UPLOAD=1with automatic fallback toshared_buffer. - Minor notes (non-blocking):
- In
Shadow::update_tracked, thebusy/sync_beforepath that readsself.datadoes not callwc_read(), so write-combined read accounting omits that path whilecopy_back_page,take_snapshot, andcompare_snapshotdo count it. - The new
loose windows: ...meter log line prints unconditionally on Windows even without--features diagnostics(worth confirming that's desired alongside the existing meter output).
- In
Local Verification (VICTORY_D3D12_DEBUG=1)
- RTX 5090 (default):
shadow::tests10/10 passed. - RTX 5090 (
VICTORY_LOOSE_IN_GPU_UPLOAD=1, GPU Upload Heaps active):shadow::tests10/10 passed (includinga_wider_loose_window_covers_a_later_smaller_askandbytes_off_the_runtimes_memory_are_copied_at_each_use, zero debug-layer errors). - WARP (
VICTORY_LOOSE_IN_GPU_UPLOAD=1, fallback path):shadow::tests10/10 passed. cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics) &cargo xtask policy(191 files ok): clean.
Looks good.
|
Matched on/off run of
What I read from it:
No game data, shader names or screenshots, per AI-assisted: measured and written with Claude Code (Claude Opus 5.5), cross-checked by Gemini 4 Neon. I ran both runs on my machine. |
|
Automated triage for the maintainers. Needs work. The opt-in CI: passing. Generated by Claude Code |
|
A note for 8 GB cards, from reading
AI-assisted (Claude). |
|
Follow-up to my matched run above: in gameplay, most of a frame went to the CPU reading loose windows the GPU wrote. Keeping those windows in system memory made frames 5.2× faster. Same machine (RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11), diagnostics build of
Neither run ran out of memory, and in both I could move the character. The gameplay samples are the periodic lines with at least 4,000 draws, from 16 minutes in for A (77 samples) and from 4 minutes in for B (251 samples). B reached gameplay much earlier, and then played further into heavier scenes (more draws, larger snapshots), so the comparison, if anything, favours A. Medians:
What I read from it:
Some reads of these windows are still not counted, because they skip The experiment does not catch every written window. A window first made by a read and written later, a window served by a wider one that already exists, and memory shaders write at computed addresses all stay in GPU upload memory. B still counted 79,219 write-combined reads, against 204,992 in A. It is a local hack, not a proposal for how to structure it. A thread-local flag around those lookups, read in No game data, shader names or screenshots, per AI-assisted: measured and written with Claude Code (Claude Opus 5.5), cross-checked by Gemini 4 Neon. I ran both runs on my machine. |
Why
The non-local segment - the memory budget the system's memory manager gives the GPU, half of system RAM - is the ceiling every long run dies at on a machine with as much card as RAM: measured on one (16 GB card, 15.2 GB RAM, 7,465 MB budget), the segment was pinned at 103-104% in every long run, and at that ceiling the run died two ways - a host command list's Close() returning E_OUTOFMEMORY, or a staging allocation the runtime could not make feeding the title a value it dereferenced (its own missing check; our failure is the trigger either way). The loose windows are that segment's bulk (878 of them, 3,926 MB, never freed, in the run before this change), while the card's own memory sat half empty.
What
VICTORY_LOOSE_IN_GPU_UPLOAD=1(off by default) puts each new loose window in a GPU upload heap - video memory the CPU maps write-combined, where the host has one - moving them out of the system-memory segment into the card's own. A card without the heap, or an allocation it refuses, falls back to the system-memory buffer there today. The one cost is the CPU's: reading such a window back (snapshots, copy-backs) is uncached bus traffic, so every read of one is counted and warned of once, and the periodic lines carry the count. Stacked on #2856, whose reuse and window lines this builds on.Measured (one hardware run, same machine as above)
The run outlived every same-build run before it and moved its wall to process commit (a 4 MiB host allocation failed at 28 GB of private memory): the shared segment's ceiling is gone from this machine's list of killers.
Verification
cargo clippy --workspace --all-targets --locked -- -D warningsand the--all-featuresvariant: clean (on the branch this stacks on; the last commit alone adds two clippy-clean files).cargo test --workspace --locked: green.No shader bytes, hashes, or program names from any title (asset policy).