GPU: render targets are demoted last, and upload-heap copies take a share of the VRAM budget #2222
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!2222
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2222"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 08:15 UTC · original
0xkn0wh3r3:gpu/residency-and-memory-budget→main· +2285 −35 · 10 files · 8 commits · closed without mergingStacked on #2130 (which is stacked on #2120): the copies in GPU upload heaps that this change sizes come from there,
UPLOAD_BUDGETincluded. The first five commits here are #2120's (two) and #2130's (three). The last two are this change:05160205(priorities, the budget pool, the warning) and2f74d7bd(priorities for heaps and committed resources only). Once #2120 and #2130 are settled, this rebases to those two.Problem
When the process uses more video memory than DXGI's budget, Windows' video memory manager demotes some of its allocations to system memory. VIctory sets no residency priorities, so the manager chooses among all of them alike, including render targets and depth buffers drawn every frame. Frames then take seconds. VIctory's own copies in GPU upload heaps also had a fixed 2 GiB allowance (
UPLOAD_BUDGET). It did not depend on how much the card has, or on how much the title's own textures already take.Fix
Residency priorities.
host::keep_resident(withhost::Residency) is called where each heap or committed resource is made:make_texture)HIGHHIGHHIGHHIGHHIGHtexture::title_written)NORMAL(no call)MAXIMUMis not used: the system keeps such allocations even past the budget, at the cost of other processes.LOWis not used either: it would demote streamed textures before allocations with no priority set (depth twins, upload staging).Descriptor heaps get no priority. On an RTX 5070 Ti (driver 621.24), a priority on a shader-visible descriptor heap removed the device at the next submission, and every later GPU test failed with
0x887A0005. Resources placed in a heap get none either: their residency is their heap's. A priority asked of a placed texture also removed the device at the next submission, somake_texturesets one only on textures it commits.Video memory budget.
crate::budgetcallsIDXGIAdapter3::QueryVideoMemoryInfoon the host device's adapter, for the local and non-local segment groups. It reads at most every 250 ms, and again as soon as the system signals a change (RegisterVideoMemoryBudgetChangeNotificationEvent), so pools can ask as often as they like. Bytes a pool takes between readings (Budget::charge) count as used until the next reading includes them.Budget::limit(pool, own)answers how many bytes a pool may hold now: a part of what the rest of the process leaves of the local budget, up to a ceiling. Other use shrinks the answer; the pool's own bytes do not. Without a reading, the answer is the ceiling.Upload-heap copies.
UPLOAD_POOLtakes half of what the rest of the process leaves. Its ceiling is 2 GiB, as before, or a quarter of the budget where that is more:A warning, once per run. The first time local use passes nine tenths of the budget, a warning names what VIctory knows takes the memory:
The check runs with each frame-rate line, whether or not a pool asks. Upstream (
69d1e8e) starts giving up unused host textures fed from title memory at the same point, 90 % of the card's budget, so the warning marks where that eviction begins.What stays the same
VICTORY_GPU_UPLOADandVICTORY_GPU_UPLOAD_WRITESwork as before, and both are still off by default.Tests
budget::testsreplace the DXGI source with a fake and check that:host::tests::upload_copies_take_their_share_of_the_budget: the upload pool's admission against a fake budget.host::tests::textures_the_gpu_writes_are_kept_resident_first: the level chosen from texture flags.ID3D12Device1has no getter for priorities, so in test builds the helper records what it was asked for each object. These tests check that each path calls it:resource::tests::host_textures_are_kept_resident_by_use(make_texture);host::tests::list_scratch_chunks_are_kept_resident;descriptor::host::tests::view_heap_tables_are_kept_resident(the heap itself gets no priority);shadow::tests::the_written_pages_bitmap_is_kept_resident;shadow::tests::upload_budget_is_given_back_when_copies_go(copies in GPU upload heaps).Run on Windows 11 with an RTX 5070 Ti (driver 621.24):
cargo clippy --workspace --all-targets, with and without--features victory-gpu/diagnostics: no warnings.cargo test --workspace --exclude victory-shader: everything passes except two tests that fail the same way on upstreammainon this machine:descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views.cargo test -p victory-shader -- --test-threads=1: three hardware comparisons fail (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware). This change does not touchvictory-shader.Docs
None:
docs/gpu-memory.mdis gone from #2130, and this PR no longer adds to it. The budget and the priorities are described where they are code: thebudget.rsmodule docs andhost::keep_resident.Rebased onto
13f91ca11e9a54places textures fed from title memory in heaps of textures.keep_residentis now for heaps and committed resources only:make_texturesets a priority on the textures it commits, and placed ones keep their heap's normal priority.host_textures_are_kept_resident_by_useexpects no call for a placed streamed texture.69d1e8eevicts least recently used title-fed host textures past 90 % of the budget, down to 85 %. That is the same threshold as this PR's warning. The two work together: the warning still names what takes the memory.mapped_buffer(size, upload)is nowshared_mapped_buffer.Rebased onto
63bcca4(with #2120 and #2130)docs/gpu-memory.mdis dropped with that file.cargo test -p victory-gpu --lib -- --test-threads=1:HIGHon the shader-visible view heap inHostHeap::new: the first test that submits work after making one (bindless::tests::heap_views_are_current) fails with0x887A0005(device removed), and every later GPU test fails with it: 60 failures, against 2 on this head without the change.HIGHon texturesmake_textureplaces in a heap of textures (and nothing else changed), each test run alone:bindless::tests::heap_views_are_currentfails with0x887A0005, andresource::tests::only_textures_fed_from_title_memory_are_given_upgets no host texture for its placed one. Both pass without the change. First seen merging this with #2226's placed render targets (itsaliased_targets_cleared_in_turn_read_their_own_clearsandplaced_targets_at_overlapping_offsets_share_one_host_heapfailed).cargo test -p victory-gpu --lib: 252 passed, with and without both switches; the same 2 failures as onmainhere (#1835). With both switches and--features diagnostics(skippingcompositor_failure_presents_primary_in_the_same_frame, which exits the process onmaintoo here): 265 passed, plus the flakyframe::tests::waits_end_on_ticks_and_count_frames.cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok.@Marvisak on GitHub · 2026-11-25 18:20 UTC · original · edited 2026-11-25 19:20 UTC
Automated triage for the maintainers.
Needs work: needs the maintainer's decision. It now merges cleanly into
main. CI: not run on this head.55b0b89aand4495caf0belong to this PR.UPLOAD_BUDGET, which the description says this replaces, does not exist inmain: it comes from #2120. Please rebase once those two are settled, so this PR carries only the residency work:host::Residency/keep_resident, the newbudget.rspool, and the calls inmake_texture, the descriptor heap tables and list scratch.docs/gpu-memory.md(324 lines, with charts and rationale) goes against the short-docs rule. Please cut it to a few lines or drop it.rerun_with_gpu_uploadre-runs the test binary as a child process, which needs the maintainer's decision.Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-25 20:56 UTC · original
A note for whichever of #2222 and #2226 lands second: they merge cleanly but clash in
make_texture. I found this merging all my open PRs together.placement.is_none()) its own residency priority.aliased), so they aren't committed either. Setting a priority on a placed resource isn't allowed: it takes its heap's priority, which #2226 already sets on its host heaps.With both merged, #2226's
aliased_targets_cleared_in_turn_read_their_own_clearsandplaced_targets_at_overlapping_offsets_share_one_host_heapfail, as does upstream'sonly_textures_fed_from_title_memory_are_given_up. The fix is one condition:if placement.is_none() && aliased.is_none(). #2222's new test also needs the fourthmake_textureargument (None) once #2226 is in. I'll make both changes in whichever branch lands second.@0xkn0wh3r3 on GitHub · 2026-11-26 00:27 UTC · original
Thanks. Rebased with #2120 and #2130 onto
63bcca4; head is now2f74d7bd.Stack order. Understood. The branch is #2120's two commits, then #2130's three, then this PR's own two:
05160205(was55b0b89a) and2f74d7bd(was4495caf0).UPLOAD_BUDGETcomes from #2120, as you say. Once #2120 and #2130 are settled I'll rebase so only those two remain:host::Residency/keep_resident,budget.rs, and the calls inmake_texture, the view heap tables, the written-pages bitmap and list scratch. The description says so now.docs/gpu-memory.md. Dropped. #2130 removed the file, and this PR no longer adds a section to it;05160205's message no longer mentions it. What the budget and the priorities do is in thebudget.rsmodule docs and onhost::keep_resident.rerun_with_gpu_uploadchild process. Your call (the helper comes from #2120).How the device removals were reproduced. Both were seen on one GPU and driver only: an RTX 5070 Ti with driver 621.24, the machine all my numbers come from. Both showed up in the victory-gpu tests, not in a title run:
0x887A0005.HIGHinmake_texture, and itsaliased_targets_cleared_in_turn_read_their_own_clearsandplaced_targets_at_overlapping_offsets_share_one_host_heapfailed, as did upstream'sonly_textures_fed_from_title_memory_are_given_up.2f74d7bdlimits priorities to heaps and committed resources.I re-checked both on this head today, one temporary change at a time (reverted, nothing pushed), with
cargo test -p victory-gpu --lib -- --test-threads=1:HIGHon the view heap inHostHeap::new: the first test that submits after making one,bindless::tests::heap_views_are_current, fails with0x887A0005, and every later GPU test fails with it. That is 60 failures, against 2 without the change.HIGHon the texturesmake_textureplaces in a heap of textures, and nothing else changed, each test run alone:heap_views_are_currentfails with0x887A0005, andonly_textures_fed_from_title_memory_are_given_upgets no host texture for its placed one. Both pass without the change.Neither was tried on another vendor or driver. So "no priority there" is what avoids the removal on this one, not a rule shown in general. Leaving those objects at the normal priority costs nothing on hosts where the call would have worked: the heap's tables and committed render targets still get
HIGH.Checks on
2f74d7bd(RTX 5070 Ti, driver 621.24):cargo test -p victory-gpu --libpasses 252, with and without both switches, with the same 2 failures asmainhere (#1835).--features diagnosticsit passes 265. That run fails the flakyframe::tests::waits_end_on_ticks_and_count_framesand skipscompositor_failure_presents_primary_in_the_same_frame, which exits the process onmaintoo here.cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok.@catminou4 on GitHub · 2026-11-25 08:48 UTC · original · reviewed
Render targets demoted last + video-memory budget module (new budget.rs, +2407). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Big but well-motivated (system demotion picking pools by residency priority); DXGI QueryVideoMemoryInfo polling capped at 250 ms is reasonable.
@0xkn0wh3r3 on GitHub · 2026-11-26 08:05 UTC · original
Replaced by #3102, which combines this with the rest of the host-memory placement work in one PR, with measurements on a discrete and an integrated GPU. Closing here.
Pull request closed