GPU: batch resource barriers, reuse draw scratch buffers, range-lock copy_simple, and pool list uploads #1382

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

@⁠wbkepler on GitHub · 2026-11-24 17:40 UTC · original
wbkepler:gpu/cpu-record-batching-and-pool → main · +469 −56 · 9 files · 1 commits · open

Summary

Rebased cleanly onto upstream/main (ffe310e):

  • Batches HostList ResourceBarrier calls (coalescing same-resource transitions A->B->C into A->C, cancelling A->B->A round-trips, and deduplicating consecutive global UAV barriers) and flushes once before Draw/Dispatch/Copy/Resolve/Clear/ExecuteIndirect/Close.
  • Reuses scratch Vecs across draws and resets in draw::State::bind and State::tables, and replaces small heap Vecs in set_targets/SetDescriptorHeaps with fixed stack arrays.
  • Range-locks descriptor::copy_simple via mirror_range and views_at_batch so SHADER_HEAPS, pending, VIEWS, made, and kept are acquired once per copy range instead of per slot.
  • Pools HostList::upload allocations onto 512-byte-aligned Scratch upload chunks (plus a small capped pool for oversized >4 MiB uploads) reused across HostList::reset().
  • Adds GPU/WARP tests covering batched barrier coalescing, range-locked copy_simple parity, and pooled upload reuse across resets.

Verification

  • cargo clippy -p victory-gpu --all-targets & -p victory --features diagnostics --all-targets — passed
  • cargo test -p victory-gpu — passed
  • cargo xtask policy — passed
**@⁠wbkepler** on GitHub · 2026-11-24 17:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1382) `wbkepler:gpu/cpu-record-batching-and-pool` → `main` · +469 −56 · 9 files · 1 commits · open ## Summary Rebased cleanly onto `upstream/main` (`ffe310e`): - Batches `HostList` `ResourceBarrier` calls (coalescing same-resource transitions `A->B->C` into `A->C`, cancelling `A->B->A` round-trips, and deduplicating consecutive global UAV barriers) and flushes once before `Draw`/`Dispatch`/`Copy`/`Resolve`/`Clear`/`ExecuteIndirect`/`Close`. - Reuses scratch `Vec`s across draws and resets in `draw::State::bind` and `State::tables`, and replaces small heap `Vec`s in `set_targets`/`SetDescriptorHeaps` with fixed stack arrays. - Range-locks `descriptor::copy_simple` via `mirror_range` and `views_at_batch` so `SHADER_HEAPS`, `pending`, `VIEWS`, `made`, and `kept` are acquired once per copy range instead of per slot. - Pools `HostList::upload` allocations onto 512-byte-aligned `Scratch` upload chunks (plus a small capped pool for oversized `>4 MiB` uploads) reused across `HostList::reset()`. - Adds GPU/WARP tests covering batched barrier coalescing, range-locked `copy_simple` parity, and pooled upload reuse across resets. ## Verification - `cargo clippy -p victory-gpu --all-targets` & `-p victory --features diagnostics --all-targets` — passed - `cargo test -p victory-gpu` — passed - `cargo xtask policy` — passed
- Barriers from state tracking (ensure_state), title barriers and
  barrier groups are queued per host list and recorded in one
  ResourceBarrier call before the next command. Transitions of the same
  resource fold (A->B->C is A->C; A->B->A is dropped, or a UAV barrier
  from unordered access); split barriers are never folded. Every path
  that records a command or a barrier of its own flushes first: draws,
  dispatches, mesh and indirect work, copies, resolves, clears, texture
  uploads and alias copies, the depth twin route, the indirect clamp,
  external recording and diagnostics read-backs; close flushes too.
- HostList::upload hands out 512-byte aligned slices of the list's
  scratch chunks, and keeps up to two big upload buffers across resets.
- copy_simple looks the destination heap up once for its whole range.
- Draws reuse the user data buffer and bind targets and heaps without
  allocating.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:29:41 +00:00
Author
Owner

@⁠wbkepler on GitHub · 2026-11-24 22:02 UTC · original

Rebased onto 70564ae as bf8a9b2 (squashed to one commit; conflicts resolved by re-applying each part on top of upstream's new code).

Kept, adapted to upstream

  • Barrier queue: ensure_state, title barriers and barrier groups queue per host list and go out in one ResourceBarrier before the next command. Every path that records a command or its own barrier flushes first. That covers draws, dispatches, mesh and indirect work (before the clamp and before done), copies, resolves, RTV/DSV/UAV clears, texture uploads and alias copies, twin::route (so queued transitions land before the depth/twin copy), external::host_texture/record, and the diagnostics read-backs. close() flushes as well. Folding no longer touches split barriers. A cancelled UAV -> X -> UAV now becomes a UAV barrier instead of disappearing, so back-to-back shader writes stay ordered.
  • Pooled HostList::upload: unchanged in intent. It hands out 512-byte aligned scratch slices and keeps up to 2 big buffers across resets.
  • Draw scratch: only the user-data buffer, the fixed render-target array and the fixed heap array in upstream's new bind_heaps (memory heap first, as upstream orders it).

Dropped as superseded

  • The tables() scratch rewrite. Upstream no longer makes every constant-buffer table fresh, so fresh/made stay empty Vec::new() (no allocation) on the common path.
  • The duplicated per-slot logic in HostHeap::mirror_range. Upstream's HostHeap::mirror changed a lot (stride table, viewed, placed textures, buffer views made on write), so a copy of it would drift. copy_simple now looks the heap up and takes pending once per range, then calls upstream's mirror per slot. Slots past the heap still go one by one.
  • .rev() in shader_slot (not needed).

Verification: clippy -D warnings (victory-gpu, and victory with diagnostics), cargo test -p victory-gpu and cargo xtask policy all pass. New tests: barrier folding/flush on the device, upload pooling across resets, and per-slot mirroring by copy_simple. Two tests fail identically on plain upstream/main on this host: dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views.

Interaction with #1331: #1331 already conflicts with upstream/main itself, in the same 2 places, and this PR adds no new conflict region. The resolution:

  1. In State::bind, keep upstream's take_rebind + memory_heap + self.bind_heaps(list, memory_heap).
  2. Move #1331's idea into bind_heaps: build the host heap array first, then compare and store the host heaps' as_raw() identities in host_heaps instead of the title addresses in want. This needs room for the memory heap's identity too.
  3. Merge #1331's test into upstream's existing #[cfg(test)] mod tests at the end of draw.rs.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

**@⁠wbkepler** on GitHub · 2026-11-24 22:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1382#issuecomment-7145732366) Rebased onto `70564ae` as `bf8a9b2` (squashed to one commit; conflicts resolved by re-applying each part on top of upstream's new code). **Kept, adapted to upstream** - **Barrier queue:** `ensure_state`, title barriers and barrier groups queue per host list and go out in one `ResourceBarrier` before the next command. Every path that records a command or its own barrier flushes first. That covers draws, dispatches, mesh and indirect work (before the clamp and before `done`), copies, resolves, RTV/DSV/UAV clears, texture uploads and alias copies, `twin::route` (so queued transitions land before the depth/twin copy), `external::host_texture`/`record`, and the diagnostics read-backs. `close()` flushes as well. Folding no longer touches split barriers. A cancelled `UAV -> X -> UAV` now becomes a UAV barrier instead of disappearing, so back-to-back shader writes stay ordered. - **Pooled `HostList::upload`:** unchanged in intent. It hands out 512-byte aligned scratch slices and keeps up to 2 big buffers across resets. - **Draw scratch:** only the user-data buffer, the fixed render-target array and the fixed heap array in upstream's new `bind_heaps` (memory heap first, as upstream orders it). **Dropped as superseded** - The `tables()` scratch rewrite. Upstream no longer makes every constant-buffer table fresh, so `fresh`/`made` stay empty `Vec::new()` (no allocation) on the common path. - The duplicated per-slot logic in `HostHeap::mirror_range`. Upstream's `HostHeap::mirror` changed a lot (stride table, `viewed`, placed textures, buffer views made on write), so a copy of it would drift. `copy_simple` now looks the heap up and takes `pending` once per range, then calls upstream's `mirror` per slot. Slots past the heap still go one by one. - `.rev()` in `shader_slot` (not needed). **Verification:** clippy `-D warnings` (victory-gpu, and victory with diagnostics), `cargo test -p victory-gpu` and `cargo xtask policy` all pass. New tests: barrier folding/flush on the device, upload pooling across resets, and per-slot mirroring by `copy_simple`. Two tests fail identically on plain `upstream/main` on this host: `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`. **Interaction with #1331:** #1331 already conflicts with `upstream/main` itself, in the same 2 places, and this PR adds no new conflict region. The resolution: 1. In `State::bind`, keep upstream's `take_rebind` + `memory_heap` + `self.bind_heaps(list, memory_heap)`. 2. Move #1331's idea into `bind_heaps`: build the host heap array first, then compare and store the host heaps' `as_raw()` identities in `host_heaps` instead of the title addresses in `want`. This needs room for the memory heap's identity too. 3. Merge #1331's test into upstream's existing `#[cfg(test)] mod tests` at the end of `draw.rs`. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:24 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:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1382#issuecomment-7149518515) <!-- victory-triage v1 head=bf8a9b23ec9c008e477c0e529b8b13539526720d verdict=needs-rebase at=2026-11-25T01:24:44Z --> 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)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/indirect.rs
  • crates/victory-gpu/src/list.rs
  • crates/victory-gpu/src/texture.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/1382/head:github-bot/gh-1382'
git switch 'github-bot/gh-1382'

Merge

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