GPU: route upload buffers to GPU_UPLOAD VRAM under budget and move indirect arguments to DEFAULT #3226
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3228"
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 0xKaji on 2026-11-26T13:47:06Z.
Summary
Routes CPU-write-only / GPU-read-only upload buffers (
Host::upload_buffer: texture staging chunks/buffers, command-list scratch, descriptorstrides/marks/addresses, title-memory page tables) toD3D12_HEAP_TYPE_GPU_UPLOAD(VRAM via Resizable BAR) while local VRAM stays below 80% of its DXGI budget, and moves GPU-only indirect argument buffers (HostList::arguments) toD3D12_HEAP_TYPE_DEFAULT.Changes
GPU_UPLOADrouting (host.rs): ChecksD3D12_FEATURE_D3D12_OPTIONS16.GPUUploadHeapSupportedonce at device creation and routesHost::upload_buffertoD3D12_HEAP_TYPE_GPU_UPLOAD(D3D12_RESOURCE_STATE_COMMON) when local VRAM usage + allocation fits within 80% of DXGI local budget (refreshed every 250 ms or on >= 4 MiB allocations), falling back cleanly toD3D12_HEAP_TYPE_UPLOADin system RAM. Toggleable viaVICTORY_UPLOAD_VRAM=0.host.rs,indirect.rs): AllocatesHostList::argumentsviaHost::default_uav_buffer(D3D12_HEAP_TYPE_DEFAULT+ALLOW_UNORDERED_ACCESS) instead of CPU-mappedshared_buffer; updatesindirect.rstests to read back via aREADBACKbuffer.host.rs,list.rs): AddsHostList::release_idle_buffers()called fromlist::recycle()so command lists parked inSPAREdrop oversizedargumentsand trimscratchchunks.Measured A/B (Linux Wine 11.22 + vkd3d-proton, RTX 3060 8 GiB ReBAR, 16 GiB RAM, Series S + #2112)
VICTORY_UPLOAD_VRAM=0→VICTORY_UPLOAD_VRAM=1:4,180 MB→3,697 MB(-483 MB)3,337 MB→3,046 MB(-291 MB)14,510 MB/13,959 MiB→13,357 MB/12,847 MiB(-1,112 MiB RSS)0 MB VRAM / 177 MB RAM→59 MB VRAM / 0 MB RAM6.0 ms→4.9 ms, median FPS:28.9→30.0(no regression).Verification
cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warningscargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warningscargo test -p xtask --locked(6/6 passed)upload_vram_fits_checks_80_percent_headroom,list_scratch_grows_to_fit_and_reuses_fenced_chunks(2/2 passed)Partial Overlaps / Related PRs
#3102,#2993, and#2875, which moveshared_buffershadow copies of title memory to VRAM; this PR targetsupload_bufferandHostList::argumentsinstead.#2972onHostList::scratchtrimming (release_idle_buffershere only runs when a list is parked inSPARE, and does not alterHostList::resetorScratch).Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:09:48Z.
Review: APPROVED
Verified on RTX 5090 (Resizable BAR /
GPU_UPLOADcapable) againstorigin/main(63bcca4):cargo test -p victory-gpu --lib host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released: passed.cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed;indirect::: 6/6 passed;shadow::: 10/10 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly routes upload buffers to
GPU_UPLOADVRAM within budget and moves indirect arguments accordingly.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by potatoe0100 on 2026-11-26T14:03:31Z.
Tested
ef8d719merged ontomain63bcca4on an RTX 4060 8 GB (Ada, PCIe 4.0 x8, driver 621.14, Windows 11 Pro 26300, Resizable BAR on). No game files, so synthetic tests only.Tests:
cargo test -p victory-gpu -p victory-shader --lib --locked -- --test-threads=1(skippingheap_direct_texture_reads_mark_their_heap_index, #2571). Same result asmainon this card: the newupload_vram_fits_checks_80_percent_headroom,list_scratch_grows_to_fit_and_reuses_fenced_chunksand allindirect::testspass. The only failures are the 5 known capped-heap ones (#1835), which fail onmaintoo.OPTIONS16.GPUUploadHeapSupportedis true here, so the GPU_UPLOAD path really ran.Costs measured on this card (a throwaway
--releaseprobe, not part of the PR):default_uav_buffer)Two things this suggests, for whoever reviews:
release_idle_buffers()runs on everylist::recycle(). It drops the indirectargumentsbuffer and trims scratch to at most one chunk.list.rsnotes the title resets up to 21 lists a frame, so a recycled list that does indirect work makes a new DEFAULT buffer each time (about 0.25 ms here). A list that needs a few MiB of scratch also regrows it 64 KiB → 4 MiB, about 7 allocations. Before this PR both were kept across reuse. Would it be enough to trim only lists that have sat inSPAREfor a while, or only when the buffer is well above what was used?list.uploadcopies. That's fine when the GPU copy saved is the bottleneck, but on a card with a narrow link it may move time into "preparing", which is already the largest part of a frame in the forks' measurements. A per-caller choice (VRAM for small, often-rewritten tables; system memory for large staging writes) might be worth measuring.AI-assisted (Claude)
Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-26T22:54:28Z.
Thanks for the RTX 4060 PCIe x8 measurements! Updated
list::recycle()so the firstHOT_SPARE = 24lists inSPAREonly trim oversized buffers (arguments > 256 KiBorscratch > 2chunks) instead of releasing them on every recycle, keeping normal indirect argument and scratch buffers warm across frames. On point (2),VICTORY_UPLOAD_VRAM=0remains available as a runtime escape hatch for narrow PCIe links if needed.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:59:59Z.
Review: APPROVED
Looks good — clean, well-guarded routing of upload allocations to
D3D12_HEAP_TYPE_GPU_UPLOADunder VRAM headroom and migration of indirect argument buffers toD3D12_HEAP_TYPE_DEFAULT.Checked
crates/victory-gpu/src/host.rs,indirect.rs, andlist.rs, including everyupload_buffercaller across the crate:GPUUploadHeapSupportedis probed viaD3D12_FEATURE_D3D12_OPTIONS16(host.rs:211-220), gated byVICTORY_UPLOAD_VRAMand the 80% local-VRAM headroom check (upload_vram_fits, refreshed every 250 ms or on allocations>= 4 MiB), with clean cache invalidation and fallback toD3D12_HEAP_TYPE_UPLOADifCreateCommittedResourceorMapfails.HostList::arguments(host.rs:2315) todefault_uav_buffer(DEFAULT+ALLOW_UNORDERED_ACCESS, initial stateCOMMON) aligns withindirect.rs's existingCOMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMONtransitions (indirect.rs:213-250), andindirect::testscleanly read back via a readback staging buffer.list::recycle(list.rs:283-295,host.rs:1830-1869) keeps normal warm buffers resident while dropping oversized indirect buffers (> 256 KiB) and excess scratch chunks.Verification (
b60d234a):cargo xtask policyandcargo clippy -p victory-gpu(default and--features diagnostics,--tests -- -D warnings): passed.indirect::tests::(6/6) andhost::tests::upload_vram_fits_checks_80_percent_headroom: passed on both hardware GPU and WARP withVICTORY_D3D12_DEBUG=1andVICTORY_D3D12_GBV=1.DEBUG=1 + GBV=1) confirmedallocated_heap_type = D3D12_HEAP_TYPE_GPU_UPLOAD(and clean fallback toD3D12_HEAP_TYPE_UPLOADwithVICTORY_UPLOAD_VRAM=0), verified a singleGPU_UPLOADbuffer inCOMMONused simultaneously asCopyBufferRegionsource + root CBV + root SRV in one command list with zero barriers (debug_err = None), verifiedHostList::argumentsusesDEFAULTandtrim_oversized_buffers/release_idle_buffersbehave as expected, and passeddraw::tests(20/20),texture::tests(2/2),list::tests(4/4), anddescriptor::host::tests(14/14) underDEBUG=1 + GBV=1.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.