GPU: pool upload buffers across command list resets #982
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/982"
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 chemokita13 on 2026-11-24T14:38:45Z.
Summary
Resolves the shortcut in
crates/victory-gpu/src/host.rs:1071(// shortcut: one buffer per copy; pool them once uploads are frequent.).Previously, transient upload buffers allocated during command list recording (
HostList::uploadfor footprint copies, and large scratch allocations inHostList::scratch) created a new committed D3D12 resource on every call viaHost::upload_bufferand released it immediately uponHostList::reset. This caused continuous heap allocations and driver overhead on frequent uploads.Changes
PooledUpload: Stores the liveID3D12Resource, its persistently mapped CPU pointer, and its capacity.Host::take_upload: Looks for an idle buffer in the host pool with matching/compatible capacity (best fit, capped at 2x requested size). If none is available, allocates a new upload buffer rounded up to 64 KiB alignment (D3D12 buffer placement boundary) or the next power of two.Host::recycle_uploads: Called onHostList::resetonce GPU execution has completed to return buffers to the pool. Pool capacity is bounded to 32 buffers (retaining the largest).upload_pool_reuses_buffers_and_handles_varying_sizesincrates/victory-gpu/src/host.rsverifying pointer reuse after list resets and appropriate sizing behavior.Verification
cargo test -p victory-gpu --lib(passed)cargo clippy --workspace --all-targets --locked -- -D warnings(clean)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(clean)cargo xtask policy(passed, 154 files ok)Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:53:02Z.
On RTX 4090 under Wine/vkd3d-proton 3.2, the same upload resource was reused across two completed submissions with a list reset between them. GPU readback returned the new value each time (0xa5a51234, then 0x7e572468). Both focused tests passed.
For a separate capacity check, three 5 MiB requests were made on one list before reset. The idle pool then held three 8 MiB buffers plus the 64 KiB buffer from the small copies. The 32-buffer limit bounds the object count; the recycler preferentially keeps the largest buffers and has no total-byte limit. This measures retained resource capacity. Physical residency and title upload timing remain unmeasured.
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T14:55:01Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
b4abe5d:cargo test -p victory-gpupasses, 51 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:17:05Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by HailLucifer666 on 2026-11-25T22:42:56Z.
/keereview — good shortcut to remove, a few things to tighten before it goes in.Correctness.
unsafe impl Sync for PooledUploadis unnecessary.Mutex<T>only needsT: Send, sounsafe impl Sendalone compiles. Anunsafe implthat nothing requires is one more promise to keep true by hand.(size * 2).max(1 << 20)in the fit filter overflows for very large requests (debug panic, release wrap).size.saturating_mul(2)costs nothing.reset()takes the uploads out and then immediately replaces the wholeDeferred:std::mem::take(&mut deferred.uploads)followed by*deferred = Deferred::default()copies an emptyVecfor nothing.std::mem::take(&mut *deferred).uploadsdoes both in one move.Design questions.
sort_by_key(Reverse(size)), truncate). Under churn of many small uploads that discards exactly the buffers being reused most. Largest-by-size is a sensible bound for one big copy per frame; most-used is the one that pays for a busy frame. Worth saying which case this is optimising.upload()still callsname(&pooled.buffer, "list upload {size:#x}")on every reuse, so a pooled buffer is renamed per list. In a diagnostics build that is per-draw work to relabel an object that already exists.reset()only running after the list's last submission finished. That is documented atreset; it is worth repeating atrecycle_uploads, because that is now the invariant the reuse depends on rather than one caller's local reasoning.Verification.
MAX_POOLED_UPLOADS) and not the ordering assumption above.cargo test -p victory-gpu --libcannot reproduce here on today'smain: before any of your change, that suite failsdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views. (Clippy is clean onmaintoday, so that line is fine.) Since the branch isCONFLICTING, those numbers come from an older base — worth re-running after the rebase rather than carrying stale ones.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.