Repository navigation
GPU: route upload buffers to GPU_UPLOAD VRAM under budget and move indirect arguments to DEFAULT - #3228
GPU: route upload buffers to GPU_UPLOAD VRAM under budget and move indirect arguments to DEFAULT#32280xKaji wants to merge 2 commits into
Conversation
…direct arguments to DEFAULT
|
Tested Tests: Costs measured on this card (a throwaway
Two things this suggests, for whoever reviews:
AI-assisted (Claude) |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified on RTX 5090 (Resizable BAR / GPU_UPLOAD capable) against origin/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_UPLOAD VRAM within budget and moves indirect arguments accordingly.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
Thanks for the RTX 4060 PCIe x8 measurements! Updated |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Looks good — clean, well-guarded routing of upload allocations to D3D12_HEAP_TYPE_GPU_UPLOAD under VRAM headroom and migration of indirect argument buffers to D3D12_HEAP_TYPE_DEFAULT.
Checked crates/victory-gpu/src/host.rs, indirect.rs, and list.rs, including every upload_buffer caller 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.- Moving
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. - Hot/cold spare trimming in
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.- Live multi-state probe on hardware GPU (
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.
…e recycle, independent DXGI HUD & step-back-safe CPU meter Port three verified community improvements cleanly on top of 7b57565 for VIctory-RTX (16 GB Ada + DXR 1.1): 1. Budgeted ReBAR GPU_UPLOAD routing & HOT_SPARE=24 warm list recycle (GPL-3.0 provenance: Marvisak/VIctory#3228): - Query D3D12_FEATURE_D3D12_OPTIONS16::GPUUploadHeapSupported once at device creation (Host::gpu_upload_supported) and reuse it from Host::mapped_card_memory. - Route Host::upload_buffer to D3D12_HEAP_TYPE_GPU_UPLOAD (COMMON initial state, resident + mapped, with automatic fallback to system-RAM UPLOAD and VICTORY_UPLOAD_VRAM=0 escape hatch). - Enforce a conservative 16 GB + DXR 1.1 headroom ceiling: <= 75% of the local OS budget when RT is off, and <= 75% of min(local_budget, VICTORY_DXR_VRAM_CAP_MB) minus unallocated DXR AS slab headroom (crate::dxr::slab_headroom()) when VICTORY_NATIVE_RT=1, charging 64 KiB-aligned physical footprints against the 250 ms cached window (refreshing live on >= 4 MiB allocations). - Keep HostList::indirect_args and �atch_args (already in DEFAULT UAV VRAM with COMMON <-> UNORDERED_ACCESS -> INDIRECT_ARGUMENT -> COMMON state tracking in �ictory-rtx) warm for the first HOT_SPARE = 24 recycled lists ( rim_oversized_buffers) while releasing idle buffers beyond HOT_SPARE ( elease_idle_buffers), preserving VICTORY_BURY_ASIDE, Detached::Shared / dxr_reusable, and eset_closed(). 2. Independent DXGI local/non-local memory sampling & HUD distinction (GPL-3.0 provenance: Belobug/VIctory-Belobug-AMD#348): - Split DXGI LOCAL and NON_LOCAL sampling in Host::sample_video_memory and Host::query_video_memory_groups so a single-segment failure does not zero out the other segment. - Update host/panel.rs to show local usage vs OS budget, adapter dedicated VRAM capacity vs non-local/shared spill (N/A on missing sample vs
…tion, LIFO hot-spare pool, bury-aside drops, resident GPU_UPLOAD, CPU counter step-back & multi-group sizing) Address 1 P1 and 5 P2 findings from Terra review of d35d011: 1. [P1] Atomic pre-allocation VRAM reservation (`host.rs`): - Replace unsynchronized headroom check+charge with `UploadBudget` + `Mutex<UploadBudgetState>` and RAII `UploadBudgetGuard`. - Check the 75% / DXR ceiling (`min(local_budget, VICTORY_DXR_VRAM_CAP_MB)` minus `dxr::slab_headroom()`) and reserve 64 KiB-aligned `in_flight_bytes` atomically BEFORE calling `CreateCommittedResource` (releasing the lock before D3D12 / DXGI calls). - Carry unreflected committed bytes across concurrent DXGI refreshes within the 250 ms window (subtracting observed `dxgi_increase` and expiring after 250 ms) while always adding `in_flight_bytes`, rolling back cleanly on `Drop` or `fail_and_invalidate()`. - Add 16-thread concurrent reservation + rollback unit test. 2. [P2] LIFO warm-first `HOT_SPARE = 24` ordering (`list.rs`): - Switch `IDLE` to `IdlePool<T>` backed by `VecDeque` tracking `hot_len` strictly under the pool lock: hot lists (up to `HOT_SPARE`) push to the back (popped first by `pop_back()`), while cold trimmed lists push to the front (`push_front()`). - Add unit test parking 30 lists and asserting all 24 hot lists pop before cold lists and hot slots refill at the back. 3. [P2] Route trimmed/idle COM buffers through `VICTORY_BURY_ASIDE` (`host.rs`, `list.rs`): - Return detached `Vec<ID3D12Resource>` from `HostList::trim_oversized_buffers()` and `HostList::release_idle_buffers()` without dropping COM objects under locks, and route them through `host::bury_resources()` (sharing the `victory-bury` worker thread when `VICTORY_BURY_ASIDE` is enabled). 4. [P2] Eliminate per-allocation GPU fence wait on `GPU_UPLOAD` (`host.rs`): - Create `D3D12_HEAP_TYPE_GPU_UPLOAD` buffers resident by default with `D3D12_HEAP_FLAG_NONE` and map directly without `CREATE_NOT_RESIDENT` / `MakeResident` / `mapped()` COPY-queue fence stalls. 5. [P2] Treat any backward-stepping CPU counter as `0.0%` idle (`host/panel.rs`): - Track per-core `CpuTimes { idle, kernel, user }` and return `0.0%` when any of `idle`, `kernel`, or `user` steps backward (or total delta <= 0) rather than producing a false `100%` spike when `idle` steps back. 6. [P2] Cover all Windows processor groups in `CpuMeter` (`host/panel.rs`): - Size initial buffer with `GetActiveProcessorCount(ALL_PROCESSOR_GROUPS)` and loop/grow on `STATUS_INFO_LENGTH_MISMATCH` up to `MAX_CPUS = 1024`, with unit test covering multi-group buffer growth and cap termination. Provenance (GPL-3.0): - Marvisak/VIctory#3228 - Belobug/VIctory-Belobug-AMD#348 - Belobug/VIctory-Belobug-AMD#325
…y across refreshes and failures Address Terra Round-2 accounting edge cases in `UploadBudget` (`host.rs`): - Replace `reserved_since_sample` + shared window timer with per-commit `recent_commits: VecDeque<(Instant, u64)>` + `recent_commit_bytes: u64`, pruning each commit only after its own 250 ms TTL so a commit at t=249 ms survives a DXGI refresh at t=251 ms. - Never subtract unrelated `dxgi_increase` deltas from `recent_commit_bytes`: always compute `dxgi_used + in_flight_bytes + recent_commit_bytes` conservatively so texture/DXR VRAM growth cannot cancel unreflected `GPU_UPLOAD` commits. - Keep `recent_commits` / `recent_commit_bytes` intact across both `fail_and_invalidate()` and DXGI query errors (which fail closed to system-RAM `UPLOAD`). - Add deterministic CPU unit tests for all four cases: failure preserving prior commits, per-commit 250 ms TTL across sample refresh, unrelated DXGI growth non-cancellation, and DXGI error fail-closed preservation. Provenance (GPL-3.0): - Marvisak/VIctory#3228
Follow-up fix from Round-3 Terra review on UploadBudget (GPL-3.0, Marvisak/VIctory#3228): - Change UploadBudgetState::prune_commits to compare commit timestamps against the cached DXGI sample's own sampled_at timestamp rather than now, preventing an older sample (e.g. t=249 ms) from dropping an unreflected commit at t=250 ms. - In UploadBudget::reserve's fast path, if the request does not fit yet against the cached sample while the oldest unpruned commit has aged >= 250 ms by now, trigger a live DXGI refresh instead of waiting another 250 ms. - Add deterministic test upload_budget_does_not_prune_commit_against_older_sample covering stale-sample rejection at t=250 ms, fail-closed DXGI error without pruning, and immediate pruning once a fresh t=250 ms sample reports freed VRAM.
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).