GPU: loose windows can sit in video memory the CPU writes #2875
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!2875
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2875"
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?
@Luislariosss on GitHub · 2026-11-25 22:54 UTC · original
Luislariosss:gpu/loose-in-video-memory→main· +209 −1 · 2 files · 3 commits · openWhy
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).
@ZeOs360 on GitHub · 2026-11-26 04:12 UTC · original
Matched on/off run of
25c02cd(merged ontomain63bcca4; diagnostics build), on a second machine: RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, 64 GB page file, Windows 11. GPU upload heaps are available here (on=true). One binary, two runs from a cold start into the prologue, unattended, capped at 12 minutes; onlyVICTORY_LOOSE_IN_GPU_UPLOADdiffers. World samples are the periodic lines with at least 500 draws.=0=1no shared bufferlinesimage+0x5149aecimage+0x63966fWhat I read from it:
=1run, while from 143 s on the=0run failed 75k shared-buffer allocations.=0hit that wall, GPU time was the same (223 vs 236 ms/frame) and=1ran at about a third of the frame rate. What it prevents is the collapse past the wall:=0's GPU time went to 1,150 ms/frame and its frame rate fell below=1's.Shadow::copy_back_markedreads the window too (it compares the window's bytes with title memory, and loose windows are tracked) but does not callwc_read(), so that cost is not in the 91,659.=0, whose windows stopped growing when shared buffers began to fail at 143 s. A card with less memory than this one would likely hit its own wall.+0x63966fone also ended a run of a different build (no #2875) after 9 minutes here, so I don't attribute it to this PR.No game data, shader names or screenshots, per
docs/asset-policy.md.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.
@Marvisak on GitHub · 2026-11-26 04:27 UTC · original
Automated triage for the maintainers.
Needs work. The opt-in
VICTORY_LOOSE_IN_GPU_UPLOAD(loose windows in a GPU upload heap,Host::loose_buffer) is reasonable and the hardware tables are encouraging, but the branch still carries both commits of #2856; please rebase once that lands so only the last commit remains.Shadow::copy_back_markedreads the window without callingwc_read(), so the new counter undercounts. The second run also showed the CPU cost (snapshots about 20x slower per MB); please note that trade-off in the README entry.CI: passing.
Generated by Claude Code
@AwsAli05 on GitHub · 2026-11-25 23:06 UTC · original · reviewed
I independently checked the allocation request from
buffer_inon an RTX 5070 Ti with the D3D12 debug layer requested. Options16 reported GPU upload heaps supported. A 4 MiB committedGPU_UPLOADbuffer created withCOMMONandALLOW_UNORDERED_ACCESSsucceeded, andMapreturned 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 on GitHub · 2026-11-25 23:36 UTC · original · reviewed
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 on GitHub · 2026-11-25 23:37 UTC · original · reviewed
Verified head
25c02cd2cleanly merged ontoorigin/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), withVICTORY_D3D12_DEBUG=1.Code Review
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.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.loose windows: ...meter log line prints unconditionally on Windows even without--features diagnostics(worth confirming that's desired alongside the existing meter output).Local Verification (
VICTORY_D3D12_DEBUG=1)shadow::tests10/10 passed.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).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.
@potatoe0100 on GitHub · 2026-11-26 14:21 UTC · original
A note for 8 GB cards, from reading
25c02cd2(and an RTX 4060 8 GB test run:cargo test -p victory-gpu --libmerged ontomain63bcca4gives 230 passed, with only the 2 known NVIDIA heap-cap failures thatmainalso has).loose_bufferputs every new loose window inGPU_UPLOADwhile the switch is on, and only falls back when the allocation fails. On WDDM that allocation usually succeeds past the local budget, and the memory manager then demotes or evicts other resources. On this 4060 the local budget is 7,537 MB, and the README says the world wants about 10 GB, so moving the 3.9 GB of windows from your run onto the card would make the 8 GB case worse. Your 16 GB card already sat at 97 %. Could new windows go to system memory once localCurrentUsagepasses a share ofBudget(fromQueryVideoMemoryInfo)? Or the README entry could say it is for cards with spare video memory.AI-assisted (Claude).
@ZeOs360 on GitHub · 2026-11-26 18:38 UTC · original
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
main63bcca4+25c02cd+ #2644,VICTORY_LOOSE_IN_GPU_UPLOAD=1. My earlier runs all stopped at the title's pool breakpoint from #698 after 8–11 minutes. To get past it I used #2644'sVICTORY_STEP_OVER=5149aec,63966f,1fa88e4. Two runs, both to my 30-minute cap:A: the build as above.
B: the same build plus a local experiment, which is not in this PR. A loose window is made in system memory (
shared_buffer) instead ofloose_bufferwhen the lookup that makes it is for a GPU write. Those lookups are:root_views and the root descriptorsState::bindhands to shaders that use title memory;buffer_uav, andview_copywhen the descriptor is written).Every other window still goes to GPU upload memory.
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
wc_read(). BesidesShadow::copy_back_marked(named above),sync_beforeandShadow::copy(throughTracked::refreshed) also read the window's bytes without it.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
loose(), is enough to try it. I can share the diff if useful.No game data, shader names or screenshots, per
docs/asset-policy.md.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.
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.