GPU: pool mapped upload buffers across command list resets #1892
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1894"
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?
Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-25T00:16:55Z.
Problem
HostList::uploadpreviously allocated a fresh committedD3D12_HEAP_TYPE_UPLOADresource (Host::upload_buffer) for every copy and dropped it when the command list reset, causing repeatedCreateCommittedResource/Map/Releaseoverhead during texture and buffer uploads.Fix
crates/victory-gpu/src/host.rs:upload_pool: Mutex<Vec<(u64, ID3D12Resource, usize)>>toHost, bounded byMAX_POOLED_BUFFERS(64) andMAX_POOLED_BYTES(64 MiB).Host::take_upload(reuses the smallest pooled buffer in[size, 2 * size], otherwise allocates viaupload_buffer) andHost::return_upload.Deferred::pooled_uploadsinHostList::uploadand return them toHostinHostList::reset(which only runs after the list's last submission has completed).host::batch::upload_buffers_are_pooled_across_list_resetsto verify that resetting aHostListreturns its upload buffer to the pool and the nextuploadof the same size reuses the exact sameID3D12Resourceand mapped pointer.Verification
cargo test -p victory-gpu --locked -- upload_buffers_are_pooled_across_list_resetson Windows 11 (NVIDIA RTX 5060 Ti): 1 passed, 0 failed.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.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-25T02:11:14Z.
Review: APPROVED
Tested
18f21fccon Windows 11, RTX 5070, MSVC:cargo test -p victory-gpupasses on the head, including the new pooling test. The 2 failures there (dynamic heap slots, memory table) also fail on main on this host.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 warningsfails on the new test. The secondunsafe { list.list.Close() }has no// SAFETY:comment (clippy::undocumented_unsafe_blocks). I added one in our fork.AI-assisted (Claude Code).
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 onHostList::upload(crates/victory-gpu/src/host.rs) asked for. Upload buffers handed out byuploadnow come from a host-wide pool (take_upload: the smallest pooled buffer betweensizeand2*size) and go back to it inHostList::reset. The pool is capped at 64 buffers and 64 MiB. Reuse is safe only if a list's GPU work has finished beforereset. I checked that:reset's contract on main says so, and the title-facingresetinlist.rsrelies 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 onlybytesof a possibly larger buffer, which is fine. The new test checks that the same resource and mapped pointer come back after a reset.Notes:
CreateCommittedResourcecount from one session would help the maintainer judge it.Deferred::uploadsunpooled, which is fine.CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T09:22:47Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, head8b7f257, 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 6host::tests::*passed (1 unrelated baseline failure on NVIDIA indescriptor::host::tests::dynamic_slots_are_held_until_releaseddue to #1835)cargo test -p victory-gpu --lib -- --test-threads=1 list::tests::— 4 passed, 0 failedcargo clippy -p victory-gpu --all-targets -- -D warnings— 0 warningscargo xtask policy— 182 files okClean host-wide upload buffer pool across command list resets.
upstream-sync referenced this pull request2026-11-25 10:07:34 +00:00
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::executewaits for completion underself.submitted.lock(), andlist::restart/list::recycleonly returnpooled_uploadsviah.reset()onceArc::try_unwrapsucceeds, so buffers cannot be overwritten while still in GPU flight;MAX_POOLED_BUFFERS = 64andMAX_POOLED_BYTES = 64 MiBcap memory cleanly.Two minor cleanups worth fixing before merge:
HostList::is_empty()missespooled_uploads(crates/victory-gpu/src/host.rs:2165):deferred_emptystill checksd.uploads.is_empty()but omitsd.pooled_uploads.is_empty(), even thoughlist.upload(...)now pushes exclusively intopooled_uploads. Adding&& d.pooled_uploads.is_empty()keepsis_empty()accurate for any future caller.diagnostics(crates/victory-gpu/src/host.rs:4062, 4176):upload_buffers_are_pooled_across_list_resetssits inside#[cfg(all(test, feature = "diagnostics"))] mod present_plane_tests, so defaultcargo test -p victory-gpuskips 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), includingupload_buffers_are_pooled_across_list_resetson both backendscargo clippy(default &--features diagnostics) +cargo xtask policy(191 files ok): 0 warningsImported 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.