GPU: pool HostList upload buffers across resets #2015

Open
lizapropanol wants to merge 1 commit from upstream-pr/2017 into main
lizapropanol commented 2026-11-25 03:10:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lizapropanol on 2026-11-25T03:10:46Z.


Reuse D3D12 staging upload buffers on HostList across resets instead of creating and mapping a new committed buffer for every HostList::upload call (CopyTextureRegion / CopyTextureRegionX).

Summary

  • Add UploadPool / UploadBuffer on HostList in crates/victory-gpu/src/host.rs and return in-use buffers to the free list in HostList::reset.
  • Bucket pooled allocations in powers of two from 64 KiB (FIRST_UPLOAD_BUFFER) up to 4 MiB (MAX_POOLED_UPLOAD), selecting the smallest free buffer that fits and capping retained pool memory at 32 MiB (MAX_UPLOAD_POOL_BYTES) per list.
  • Keep oversized (> 4 MiB) or over-budget allocations in deferred().uploads so they drop on reset as before.
  • Add tests upload_pool_reuses_smallest_fit_and_enforces_caps and list_upload_reuses_buffers_after_reset_and_skips_pooling_oversized.

Verification

  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • cargo test --workspace --locked
  • cargo xtask policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:5484427181 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017). Originally posted by [lizapropanol](https://github.com/lizapropanol) on 2026-11-25T03:10:46Z. --- Reuse D3D12 staging upload buffers on `HostList` across resets instead of creating and mapping a new committed buffer for every `HostList::upload` call (`CopyTextureRegion` / `CopyTextureRegionX`). ### Summary - Add `UploadPool` / `UploadBuffer` on `HostList` in `crates/victory-gpu/src/host.rs` and return in-use buffers to the free list in `HostList::reset`. - Bucket pooled allocations in powers of two from 64 KiB (`FIRST_UPLOAD_BUFFER`) up to 4 MiB (`MAX_POOLED_UPLOAD`), selecting the smallest free buffer that fits and capping retained pool memory at 32 MiB (`MAX_UPLOAD_POOL_BYTES`) per list. - Keep oversized (> 4 MiB) or over-budget allocations in `deferred().uploads` so they drop on reset as before. - Add tests `upload_pool_reuses_smallest_fit_and_enforces_caps` and `list_upload_reuses_buffers_after_reset_and_skips_pooling_oversized`. ### Verification - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `cargo test --workspace --locked` - `cargo xtask policy`
catminou4 commented 2026-11-25 03:33:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:33:13Z.

Review: COMMENTED


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

HostList upload buffers pooled across resets — allocation reuse; check pool growth bounds on long sessions.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051461530 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017#pullrequestreview-6051461530). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:33:13Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. HostList upload buffers pooled across resets — allocation reuse; check pool growth bounds on long sessions.
upipibi commented 2026-11-25 04:06:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T03:20:45Z.


Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 0f4fd8c. victory-gpu: 143 passed, 2 failed, 2 ignored; the new upload_pool_reuses_smallest_fit_and_enforces_caps and list_upload_reuses_buffers_after_reset_and_skips_pooling_oversized pass. The 2 are #1744's NVIDIA failures on main (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, the heap-cap ones). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151827160 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017#issuecomment-7151827160). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T03:20:45Z. --- Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `0f4fd8c`. `victory-gpu`: 143 passed, 2 failed, 2 ignored; the new `upload_pool_reuses_smallest_fit_and_enforces_caps` and `list_upload_reuses_buffers_after_reset_and_skips_pooling_oversized` pass. The 2 are #1744's NVIDIA failures on `main` (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, the heap-cap ones). Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-25 04:06:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:34:13Z.


Triage verdict — Choose one upload pool; verify retention and GPU lifetime (0f4fd8c)

Evidence

  • #982 and #1894 pool the same mapped uploads at the host level. This PR keeps them on each list, with a 4 MiB per-entry limit and a 32 MiB cap per list. #1894 proposes a shared 64 MiB idle-pool cap, so the two designs make different tradeoffs when many command lists live at once.
  • The new D3D12 test checks resource and mapped-pointer reuse after reset, but it submits a list without recording a copy that reads the uploads.

Checks and limits

  • The exact-head Windows check passed. I compared source and published checks without rerunning the host test or measuring upload workloads.

Next step

  • Merge at most one pool design. Compare allocation counts and retained bytes across multiple command lists before choosing the cap and ownership model. Keep this PR’s cap and oversized-allocation tests, and add a synthetic copy/readback across reset. If #595’s asynchronous submissions land, require fence completion before recycling an upload still owned by an in-flight list.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152036924 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017#issuecomment-7152036924). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:34:13Z. --- **Triage verdict — Choose one upload pool; verify retention and GPU lifetime** (`0f4fd8c`) **Evidence** - #982 and #1894 pool the same mapped uploads at the host level. This PR keeps them on each list, with a 4 MiB per-entry limit and a 32 MiB cap **per list**. #1894 proposes a shared 64 MiB idle-pool cap, so the two designs make different tradeoffs when many command lists live at once. - The new D3D12 test checks resource and mapped-pointer reuse after reset, but it submits a list without recording a copy that reads the uploads. **Checks and limits** - The [exact-head Windows check](https://github.com/Marvisak/VIctory/actions/runs/45538158062/job/138949785917) passed. I compared source and published checks without rerunning the host test or measuring upload workloads. **Next step** - Merge at most one pool design. Compare allocation counts and retained bytes across multiple command lists before choosing the cap and ownership model. Keep this PR’s cap and oversized-allocation tests, and add a synthetic copy/readback across reset. If #595’s asynchronous submissions land, require fence completion before recycling an upload still owned by an in-flight list. This verification was AI-assisted.
Xvania7 commented 2026-11-25 08:52:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T08:52:03Z.

Review: APPROVED


Verified locally merged onto main (940d32f, Windows 10 x64, NVIDIA GeForce RTX 5060, Rust MSVC):

  • cargo test -p victory-gpu --lib -- --test-threads=1 host::tests:: — all 8 host::tests::* tests passed (including list_upload_reuses_buffers_after_reset_and_skips_pooling_oversized and upload_pool_reuses_smallest_fit_and_enforces_caps); the 1 unrelated failure in that filter was descriptor::host::tests::dynamic_slots_are_held_until_released (#1835, NVIDIA 1M descriptor heap cap).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings — 0 warnings
  • cargo xtask policy — ok (182 files ok)

Synthetic tests only; no game data.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054425694 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017#pullrequestreview-6054425694). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T08:52:03Z. **Review:** APPROVED --- Verified locally merged onto `main` (`940d32f`, Windows 10 x64, NVIDIA GeForce RTX 5060, Rust MSVC): - `cargo test -p victory-gpu --lib -- --test-threads=1 host::tests::` — all 8 `host::tests::*` tests passed (including `list_upload_reuses_buffers_after_reset_and_skips_pooling_oversized` and `upload_pool_reuses_smallest_fit_and_enforces_caps`); the 1 unrelated failure in that filter was `descriptor::host::tests::dynamic_slots_are_held_until_released` (#1835, NVIDIA 1M descriptor heap cap). - `cargo clippy -p victory-gpu --all-targets -- -D warnings` — 0 warnings - `cargo xtask policy` — ok (182 files ok) Synthetic tests only; no game data.
Marvisak commented 2026-11-25 10:07:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:17:39Z.


Automated triage for the maintainers.

Proposed close.

This pools the mapped upload buffers handed out by HostList::upload (crates/victory-gpu/src/host.rs), which is the shortcut: note on that function. The same change is already open as #1894 (host-wide pool, returned in HostList::reset, capped at 64 buffers / 64 MiB in total), which merges cleanly and was triaged as a merge candidate earlier; #982 is a third take on it. The reuse here is safe for the same reason as there (reset runs only after the list's submissions finished), but the design is weaker on one point: the 32 MiB cap is per HostList, and buffers stay retained for the list's whole life, so a title with many long-lived command lists can keep far more upload memory than #1894's single shared cap allows. There is also no measurement showing upload creation cost in a session.

Proposed for close as a duplicate of #1894; it will be closed in 48 hours unless the author pushes a change (for example, measurements showing the per-list design is better, or porting the cap and oversized-allocation tests onto #1894) or a maintainer removes the label.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158135987 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017#issuecomment-7158135987). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:17:39Z. --- <!-- victory-triage v1 head=0f4fd8c6fb2090471f1f2209af03f0520e6c2314 verdict=proposed-close at=2026-11-25T09:17:32Z --> Automated triage for the maintainers. **Proposed close.** This pools the mapped upload buffers handed out by `HostList::upload` (`crates/victory-gpu/src/host.rs`), which is the `shortcut:` note on that function. The same change is already open as #1894 (host-wide pool, returned in `HostList::reset`, capped at 64 buffers / 64 MiB in total), which merges cleanly and was triaged as a merge candidate earlier; #982 is a third take on it. The reuse here is safe for the same reason as there (`reset` runs only after the list's submissions finished), but the design is weaker on one point: the 32 MiB cap is per `HostList`, and buffers stay retained for the list's whole life, so a title with many long-lived command lists can keep far more upload memory than #1894's single shared cap allows. There is also no measurement showing upload creation cost in a session. Proposed for close as a duplicate of #1894; it will be closed in 48 hours unless the author pushes a change (for example, measurements showing the per-list design is better, or porting the cap and oversized-allocation tests onto #1894) or a maintainer removes the label. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
borosf commented 2026-11-27 17:12:26 +00:00 (Migrated from github.com)

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


Coordination note: #982 by @chemokita13 and #1894 by @n-romanovich do the same pooling of upload buffers across resets. Three PRs, one change — triage in #1633 keeps #982. If yours differs, say how.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224147509 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2017#issuecomment-7224147509). Originally posted by [borosf](https://github.com/borosf) on 2026-11-27T17:12:26Z. --- Coordination note: #982 by @chemokita13 and #1894 by @n-romanovich do the same pooling of upload buffers across resets. Three PRs, one change — triage in #1633 keeps #982. 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/2017:upstream-pr/2017'
git switch 'upstream-pr/2017'

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/2017'
git switch 'upstream-pr/2017'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2017'
git switch 'upstream-pr/2017'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2017'
git switch 'main'
git merge --squash 'upstream-pr/2017'
git switch 'main'
git merge --ff-only 'upstream-pr/2017'
git switch 'main'
git merge 'upstream-pr/2017'
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!2015
No description provided.