GPU: loose windows can sit in video memory the CPU writes #2873
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-25T22:54:56Z.
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).
Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:06:49Z.
Review: COMMENTED
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.
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:36:07Z.
Review: COMMENTED
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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:37:13Z.
Review: COMMENTED
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.
Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-26T04:12:21Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:27:11Z.
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
Imported from Marvisak/VIctory. Originally posted by potatoe0100 on 2026-11-26T14:21:27Z.
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).
Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-26T18:38:31Z.
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.
Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-28T23:31:49Z.
On the CPU cost the triage noted (snapshots about 20x slower per MB with
VICTORY_LOOSE_IN_GPU_UPLOAD=1): most of itgoes away when the window is read with streaming loads. Two commits on top of this PR's head, if they help:
ZeOs360/VIctory
claude/2875-wc-read(4396ea9,71690a8on25c02cd).The four places that read a window on the CPU (
copy_back_page, the snapshot inwriting,copy_back_or_not,copy_back_marked) read it with plain loads, one at a time over the bus, andmerge_writebackread and wrote it byte bybyte. The commits:
MOVNTDQA(SSE4.1, a plain copy without it) into a buffer;wc_read()incopy_back_markedthat the triage found missing.Two other reads of a window still use plain loads and are not counted:
sync_beforeinupdate_trackedandShadow::copy->refreshed. I left them out; they are smaller, and the same helper would cover them.One pair of runs, back to back, 10 minutes each from a cold start,
VICTORY_LOOSE_IN_GPU_UPLOAD=1only. Diagnosticsbuild of
main63bcca4with this PR merged, RX 7800 XT 16 GB, Ryzen 5 5600, 16 GB RAM, Windows 11:Totals are the periodic per-frame figures times the frames of each report. The median is over the gameplay reports
(from minute 4, at least 4,000 draws a frame: 56 and 62 of them). The second run got further in the same time, so its
later frames are other scenes and it moved more data; the per-MB rates compare directly.
In a larger tree of mine (this PR with the ray-tracing PRs and local changes), five 10-minute runs without the commits
peaked at 10-29 s a frame. With them, four runs peaked at 2.6-5.7 s; a fifth lost the GPU device (0x887A0004) at 2
minutes 48 s, which I have not traced.
A note for the rebase: this branch is based on
f3578e3. Built that way, both runs stopped about 90 and 100 s in, at aread of 0x30 in
resource::alias_source, which219878a("a null shader view has no alias source") fixed onmain;merged onto
63bcca4they ran the full 10 minutes.Tests:
write_combined_reads_copy_every_byte: every alignment, lengths around the 16- and 64-byte steps;partial_refresh_under_marked_range_through_a_write_combined_copy: the existing marked-range test again on a copymarked write-combined, through the snapshot, the marked pages' copy-back and the range copy-back;
cargo test -p victory-gpu --lib: 231 passed; clippy clean with and withoutdiagnostics.AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon; the tests and runs were made 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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.