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

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

@⁠n-romanovich on GitHub · 2026-11-25 00:16 UTC · original
n-romanovich:perf/gpu-upload-buffer-pool → main · +71 −7 · 1 files · 1 commits · open

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).
**@⁠n-romanovich** on GitHub · 2026-11-25 00:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1894) `n-romanovich:perf/gpu-upload-buffer-pool` → `main` · +71 −7 · 1 files · 1 commits · open ### 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:47:52 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:21 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 08:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1894#issuecomment-7156922474) <!-- 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)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1894/head:github-bot/gh-1894'
git switch 'github-bot/gh-1894'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1894'
git switch 'github-bot/gh-1894'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1894'
git switch 'github-bot/gh-1894'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1894'
git switch 'main'
git merge --squash 'github-bot/gh-1894'
git switch 'main'
git merge --ff-only 'github-bot/gh-1894'
git switch 'main'
git merge 'github-bot/gh-1894'
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!1894
No description provided.