GPU: pool upload buffers across command list resets #982
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!982
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@chemokita13 on GitHub · 2026-11-24 14:38 UTC · original
chemokita13:gpu/pool-upload-buffers→main· +133 −13 · 1 files · 1 commits · openSummary
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)@MichaelSmithAI on GitHub · 2026-11-24 14:53 UTC · original
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.
@Zipettte on GitHub · 2026-11-24 14:55 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 01:17 UTC · original
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
@HailLucifer666 on GitHub · 2026-11-25 22:42 UTC · original
/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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.