GPU: pool upload buffers across command list resets #982

Open
github-bot wants to merge 1 commit from github-bot/gh-982 into main AGit
Owner

@⁠chemokita13 on GitHub · 2026-11-24 14:38 UTC · original
chemokita13:gpu/pool-upload-buffers → main · +133 −13 · 1 files · 1 commits · open

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::upload for footprint copies, and large scratch allocations in HostList::scratch) created a new committed D3D12 resource on every call via Host::upload_buffer and released it immediately upon HostList::reset. This caused continuous heap allocations and driver overhead on frequent uploads.

Changes

  1. PooledUpload: Stores the live ID3D12Resource, its persistently mapped CPU pointer, and its capacity.
  2. 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.
  3. Host::recycle_uploads: Called on HostList::reset once GPU execution has completed to return buffers to the pool. Pool capacity is bounded to 32 buffers (retaining the largest).
  4. Unit test: Added upload_pool_reuses_buffers_and_handles_varying_sizes in crates/victory-gpu/src/host.rs verifying 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)
**@⁠chemokita13** on GitHub · 2026-11-24 14:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/982) `chemokita13:gpu/pool-upload-buffers` → `main` · +133 −13 · 1 files · 1 commits · open ### 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::upload` for footprint copies, and large scratch allocations in `HostList::scratch`) created a new committed D3D12 resource on every call via `Host::upload_buffer` and released it immediately upon `HostList::reset`. This caused continuous heap allocations and driver overhead on frequent uploads. ### Changes 1. **`PooledUpload`**: Stores the live `ID3D12Resource`, its persistently mapped CPU pointer, and its capacity. 2. **`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. 3. **`Host::recycle_uploads`**: Called on `HostList::reset` once GPU execution has completed to return buffers to the pool. Pool capacity is bounded to 32 buffers (retaining the largest). 4. **Unit test**: Added `upload_pool_reuses_buffers_and_handles_varying_sizes` in `crates/victory-gpu/src/host.rs` verifying 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)
Transient upload buffers allocated during list recording (buffer copies, large scratch allocations) were previously created as new committed resources on every copy and dropped on list reset. They are now retained in a host-wide pool upon HostList::reset (bounded to 32 buffers, aligned to D3D12 64 KiB placement granularity) and reused by subsequent uploads with matching or compatible capacities.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:15:43 +00:00
Author
Owner

@⁠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.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/982#issuecomment-7135105001) 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.
Author
Owner

@⁠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-gpu passes, 51 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 14:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/982#issuecomment-7135158386) 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-gpu` passes, 51 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠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 current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/982#issuecomment-7149390721) <!-- victory-triage v1 head=b4abe5db60f1bf52b2add30517e32f2c28f979e4 verdict=needs-rebase at=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 current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠HailLucifer666 on GitHub · 2026-11-25 22:42 UTC · original

/kee review — good shortcut to remove, a few things to tighten before it goes in.

Correctness.

  • unsafe impl Sync for PooledUpload is unnecessary. Mutex<T> only needs T: Send, so unsafe impl Send alone compiles. An unsafe impl that 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 whole Deferred: std::mem::take(&mut deferred.uploads) followed by *deferred = Deferred::default() copies an empty Vec for nothing. std::mem::take(&mut *deferred).uploads does both in one move.

Design questions.

  • Retention keeps the 32 largest (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 calls name(&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.
  • The safety argument rests on reset() only running after the list's last submission finished. That is documented at reset; it is worth repeating at recycle_uploads, because that is now the invariant the reuse depends on rather than one caller's local reasoning.

Verification.

  • The new test covers reuse and fitting, but not the bound (MAX_POOLED_UPLOADS) and not the ordering assumption above.
  • cargo test -p victory-gpu --lib cannot reproduce here on today's main: before any of your change, that suite fails descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views. (Clippy is clean on main today, so that line is fine.) Since the branch is CONFLICTING, those numbers come from an older base — worth re-running after the rebase rather than carrying stale ones.
**@⁠HailLucifer666** on GitHub · 2026-11-25 22:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/982#issuecomment-7176701792) `/kee` review — good shortcut to remove, a few things to tighten before it goes in. **Correctness.** - `unsafe impl Sync for PooledUpload` is unnecessary. `Mutex<T>` only needs `T: Send`, so `unsafe impl Send` alone compiles. An `unsafe impl` that 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 whole `Deferred`: `std::mem::take(&mut deferred.uploads)` followed by `*deferred = Deferred::default()` copies an empty `Vec` for nothing. `std::mem::take(&mut *deferred).uploads` does both in one move. **Design questions.** - Retention keeps the **32 largest** (`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 calls `name(&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. - The safety argument rests on `reset()` only running after the list's last submission finished. That is documented at `reset`; it is worth repeating at `recycle_uploads`, because that is now the invariant the reuse depends on rather than one caller's local reasoning. **Verification.** - The new test covers reuse and fitting, but not the bound (`MAX_POOLED_UPLOADS`) and not the ordering assumption above. - `cargo test -p victory-gpu --lib` cannot reproduce here on today's `main`: before any of your change, that suite fails `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`. (Clippy is clean on `main` today, so that line is fine.) Since the branch is `CONFLICTING`, those numbers come from an older base — worth re-running after the rebase rather than carrying stale ones.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
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.
git fetch -u origin '+refs/pull/982/head:github-bot/gh-982'
git switch 'github-bot/gh-982'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-982'
git switch 'github-bot/gh-982'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-982'
git switch 'github-bot/gh-982'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-982'
git switch 'main'
git merge --squash 'github-bot/gh-982'
git switch 'main'
git merge --ff-only 'github-bot/gh-982'
git switch 'main'
git merge 'github-bot/gh-982'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!982
No description provided.