GPU: pool mapped upload buffers across command list resets #1892

Open
n-romanovich wants to merge 1 commit from upstream-pr/1894 into main
n-romanovich commented 2026-11-25 00:16:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-25T00:16:55Z.


Problem

HostList::upload previously allocated a fresh committed D3D12_HEAP_TYPE_UPLOAD resource (Host::upload_buffer) for every copy and dropped it when the command list reset, causing repeated CreateCommittedResource / Map / Release overhead during texture and buffer uploads.

Fix

  • crates/victory-gpu/src/host.rs:
    • Add upload_pool: Mutex<Vec<(u64, ID3D12Resource, usize)>> to Host, bounded by MAX_POOLED_BUFFERS (64) and MAX_POOLED_BYTES (64 MiB).
    • Add Host::take_upload (reuses the smallest pooled buffer in [size, 2 * size], otherwise allocates via upload_buffer) and Host::return_upload.
    • Track pooled buffers in Deferred::pooled_uploads in HostList::upload and return them to Host in HostList::reset (which only runs after the list's last submission has completed).
    • Add host::batch::upload_buffers_are_pooled_across_list_resets to verify that resetting a HostList returns its upload buffer to the pool and the next upload of the same size reuses the exact same ID3D12Resource and mapped pointer.

Verification

  • Ran cargo test -p victory-gpu --locked -- upload_buffers_are_pooled_across_list_resets on Windows 11 (NVIDIA RTX 5060 Ti): 1 passed, 0 failed.
  • Unit test only; no game files used.
  • AI-assisted (authored and verified with Antigravity).
<!-- greyfinch-sync:Marvisak/VIctory:issue:5482630373 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-25T00:16:55Z. --- ### Problem `HostList::upload` previously allocated a fresh committed `D3D12_HEAP_TYPE_UPLOAD` resource (`Host::upload_buffer`) for every copy and dropped it when the command list reset, causing repeated `CreateCommittedResource` / `Map` / `Release` overhead during texture and buffer uploads. ### Fix - `crates/victory-gpu/src/host.rs`: - Add `upload_pool: Mutex<Vec<(u64, ID3D12Resource, usize)>>` to `Host`, bounded by `MAX_POOLED_BUFFERS` (`64`) and `MAX_POOLED_BYTES` (`64 MiB`). - Add `Host::take_upload` (reuses the smallest pooled buffer in `[size, 2 * size]`, otherwise allocates via `upload_buffer`) and `Host::return_upload`. - Track pooled buffers in `Deferred::pooled_uploads` in `HostList::upload` and return them to `Host` in `HostList::reset` (which only runs after the list's last submission has completed). - Add `host::batch::upload_buffers_are_pooled_across_list_resets` to verify that resetting a `HostList` returns its upload buffer to the pool and the next `upload` of the same size reuses the exact same `ID3D12Resource` and mapped pointer. ### Verification - Ran `cargo test -p victory-gpu --locked -- upload_buffers_are_pooled_across_list_resets` on Windows 11 (NVIDIA RTX 5060 Ti): **1 passed, 0 failed**. - Unit test only; no game files used. - AI-assisted (authored and verified with Antigravity).
catminou4 commented 2026-11-25 00:32:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T00:32:47Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Mapped upload buffers pooled across command list resets: allocator reuse — check reset-path poisoning.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049697516 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894#pullrequestreview-6049697516). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T00:32:47Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Mapped upload buffers pooled across command list resets: allocator reuse — check reset-path poisoning.
mercuryVM commented 2026-11-25 02:11:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-25T02:11:14Z.

Review: APPROVED


Tested 18f21fcc on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-gpu passes on the head, including the new pooling test. The 2 failures there (dynamic heap slots, memory table) also fail on main on this host.
  • Merged into our fork: workspace and shader tests as on main.

The pooling is sound: a list's uploads go back to the pool only in reset(), which runs after the submission that used them has been waited for, and the pool is bounded at 64 buffers and 64 MiB.

One nit: cargo clippy --all-targets -- -D warnings fails on the new test. The second unsafe { list.list.Close() } has no // SAFETY: comment (clippy::undocumented_unsafe_blocks). I added one in our fork.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6050622292 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894#pullrequestreview-6050622292). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-25T02:11:14Z. **Review:** APPROVED --- Tested 18f21fcc on Windows 11, RTX 5070, MSVC: - `cargo test -p victory-gpu` passes on the head, including the new pooling test. The 2 failures there (dynamic heap slots, memory table) also fail on main on this host. - Merged into our fork: workspace and shader tests as on main. The pooling is sound: a list's uploads go back to the pool only in `reset()`, which runs after the submission that used them has been waited for, and the pool is bounded at 64 buffers and 64 MiB. One nit: `cargo clippy --all-targets -- -D warnings` fails on the new test. The second `unsafe { list.list.Close() }` has no `// SAFETY:` comment (`clippy::undocumented_unsafe_blocks`). I added one in our fork. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 09:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:21:19Z.


Automated triage for the maintainers.

Merge candidate.

This does what main's shortcut: note on HostList::upload (crates/victory-gpu/src/host.rs) asked for. Upload buffers handed out by upload now come from a host-wide pool (take_upload: the smallest pooled buffer between size and 2*size) and go back to it in HostList::reset. The pool is capped at 64 buffers and 64 MiB. Reuse is safe only if a list's GPU work has finished before reset. I checked that: reset's contract on main says so, and the title-facing reset in list.rs relies on submissions being waited for. Buffers are returned before the allocator reset, and a list dropped without a reset just releases its buffers as before. The one caller (list.rs, footprint copies) uses only bytes of a possibly larger buffer, which is fine. The new test checks that the same resource and mapped pointer come back after a reset.

Notes:

  • There is no measurement of the gain. A frame-time or CreateCommittedResource count from one session would help the maintainer judge it.
  • The scratch path's large buffers still go through Deferred::uploads unpooled, which is fine.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156922474 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894#issuecomment-7156922474). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:21:19Z. --- <!-- victory-triage v1 head=8b7f2572daf6dd3b0d87b69c9bedc9475df7effe verdict=merge-candidate at=2026-11-25T08:21:11Z --> Automated triage for the maintainers. **Merge candidate.** This does what main's `shortcut:` note on `HostList::upload` (`crates/victory-gpu/src/host.rs`) asked for. Upload buffers handed out by `upload` now come from a host-wide pool (`take_upload`: the smallest pooled buffer between `size` and `2*size`) and go back to it in `HostList::reset`. The pool is capped at 64 buffers and 64 MiB. Reuse is safe only if a list's GPU work has finished before `reset`. I checked that: `reset`'s contract on main says so, and the title-facing `reset` in `list.rs` relies on submissions being waited for. Buffers are returned before the allocator reset, and a list dropped without a reset just releases its buffers as before. The one caller (`list.rs`, footprint copies) uses only `bytes` of a possibly larger buffer, which is fine. The new test checks that the same resource and mapped pointer come back after a reset. Notes: - There is no measurement of the gain. A frame-time or `CreateCommittedResource` count from one session would help the maintainer judge it. - The scratch path's large buffers still go through `Deferred::uploads` unpooled, which is fine. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Xvania7 commented 2026-11-25 09:22:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T09:22:47Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, head 8b7f257, Windows 10 x64 19045, NVIDIA GeForce RTX 5060, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib -- --test-threads=1 host::tests:: — all 6 host::tests::* passed (1 unrelated baseline failure on NVIDIA in descriptor::host::tests::dynamic_slots_are_held_until_released due to #1835)
  • cargo test -p victory-gpu --lib -- --test-threads=1 list::tests:: — 4 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets -- -D warnings — 0 warnings
  • cargo xtask policy — 182 files ok

Clean host-wide upload buffer pool across command list resets.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054861259 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894#pullrequestreview-6054861259). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T09:22:47Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, head `8b7f257`, Windows 10 x64 19045, NVIDIA GeForce RTX 5060, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib -- --test-threads=1 host::tests::` — all 6 `host::tests::*` passed (1 unrelated baseline failure on NVIDIA in `descriptor::host::tests::dynamic_slots_are_held_until_released` due to #1835) - `cargo test -p victory-gpu --lib -- --test-threads=1 list::tests::` — 4 passed, 0 failed - `cargo clippy -p victory-gpu --all-targets -- -D warnings` — 0 warnings - `cargo xtask policy` — 182 files ok Clean host-wide upload buffer pool across command list resets.
fuzeofficlal commented 2026-11-26 01:51:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:51:50Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1). The lifetime and concurrency safety of upload buffer pooling is solid — Host::execute waits for completion under self.submitted.lock(), and list::restart / list::recycle only return pooled_uploads via h.reset() once Arc::try_unwrap succeeds, so buffers cannot be overwritten while still in GPU flight; MAX_POOLED_BUFFERS = 64 and MAX_POOLED_BYTES = 64 MiB cap memory cleanly.

Two minor cleanups worth fixing before merge:

  1. HostList::is_empty() misses pooled_uploads (crates/victory-gpu/src/host.rs:2165): deferred_empty still checks d.uploads.is_empty() but omits d.pooled_uploads.is_empty(), even though list.upload(...) now pushes exclusively into pooled_uploads. Adding && d.pooled_uploads.is_empty() keeps is_empty() accurate for any future caller.
  2. New unit test is feature-gated behind diagnostics (crates/victory-gpu/src/host.rs:4062, 4176): upload_buffers_are_pooled_across_list_resets sits inside #[cfg(all(test, feature = "diagnostics"))] mod present_plane_tests, so default cargo test -p victory-gpu skips it. Moving it into a regular #[cfg(test)] module ensures default CI runs it too.

Local verification:

  • victory-gpu (--features diagnostics, VICTORY_D3D12_DEBUG=1): 41/41 passed on RTX 5090 and 42/42 passed on WARP (excluding pre-existing baseline tests), including upload_buffers_are_pooled_across_list_resets on both backends
  • cargo clippy (default & --features diagnostics) + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067493957 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894#pullrequestreview-6067493957). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:51:50Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`). The lifetime and concurrency safety of upload buffer pooling is solid — `Host::execute` waits for completion under `self.submitted.lock()`, and `list::restart` / `list::recycle` only return `pooled_uploads` via `h.reset()` once `Arc::try_unwrap` succeeds, so buffers cannot be overwritten while still in GPU flight; `MAX_POOLED_BUFFERS = 64` and `MAX_POOLED_BYTES = 64 MiB` cap memory cleanly. Two minor cleanups worth fixing before merge: 1. **`HostList::is_empty()` misses `pooled_uploads` (`crates/victory-gpu/src/host.rs:2165`)**: `deferred_empty` still checks `d.uploads.is_empty()` but omits `d.pooled_uploads.is_empty()`, even though `list.upload(...)` now pushes exclusively into `pooled_uploads`. Adding `&& d.pooled_uploads.is_empty()` keeps `is_empty()` accurate for any future caller. 2. **New unit test is feature-gated behind `diagnostics` (`crates/victory-gpu/src/host.rs:4062, 4176`)**: `upload_buffers_are_pooled_across_list_resets` sits inside `#[cfg(all(test, feature = "diagnostics"))] mod present_plane_tests`, so default `cargo test -p victory-gpu` skips it. Moving it into a regular `#[cfg(test)]` module ensures default CI runs it too. **Local verification**: - `victory-gpu` (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`): **41/41 passed** on RTX 5090 and **42/42 passed** on WARP (excluding pre-existing baseline tests), including `upload_buffers_are_pooled_across_list_resets` on both backends - `cargo clippy` (default & `--features diagnostics`) + `cargo xtask policy` (`191 files ok`): 0 warnings
borosf commented 2026-11-27 17:12:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T17:12:24Z.


Coordination note: #982 by @chemokita13 and #2017 by @lizapropanol do the same pooling of upload buffers across resets. Three PRs, one change — the queue triage in #1633 lists #982 as the survivor (most discussion). If yours differs, say how.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224147108 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1894#issuecomment-7224147108). Originally posted by [borosf](https://github.com/borosf) on 2026-11-27T17:12:24Z. --- Coordination note: #982 by @chemokita13 and #2017 by @lizapropanol do the same pooling of upload buffers across resets. Three PRs, one change — the queue triage in #1633 lists #982 as the survivor (most discussion). If yours differs, say how.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1894:upstream-pr/1894'
git switch 'upstream-pr/1894'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1894'
git switch 'upstream-pr/1894'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1894'
git switch 'upstream-pr/1894'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1894'
git switch 'main'
git merge --squash 'upstream-pr/1894'
git switch 'main'
git merge --ff-only 'upstream-pr/1894'
git switch 'main'
git merge 'upstream-pr/1894'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1892
No description provided.