GPU: pointer-deduplicate HostList::keep, retain capacity across resets, and speed up Host::execute and used_pipeline #2216

Closed
github-bot wants to merge 1 commit from gh-pr/2216/head into gh-pr/2216/base
Owner

@⁠RVZO6 on GitHub · 2026-11-25 08:06 UTC · original
RVZO6:rvzo/list-reset-keep-dedup → main · +684 −53 · 3 files · 1 commits · closed without merging

Command-list recording, reset, and submission paths in victory-gpu currently incur avoidable COM refcount traffic, per-reset heap churn, and lock/allocation overhead on every frame:

  1. HostList::keep() unconditionally casts to IUnknown (QueryInterface + AddRef) and pushes onto a Vec on every draw/bind, even when the exact same PSO, root signature, or heap pointer is already retained on that command list.
  2. HostList::reset() replaces Deferred with Deferred::default() and State::reset() replaces State with State::default(), freeing and reallocating every Vec/HashMap/HashSet on every command-list reset.
  3. Host::execute() allocates nested per-list Vecs to collect unique heaps and unconditionally clones runs even when uploads.is_none().
  4. HostPipeline::name is cloned as a String and inserted into HostList::pipelines under a mutex on every pipeline switch, even when the same pipeline was already seen on the current command list.

Claimed on #1633 (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155911614).

The change

  • crates/victory-gpu/src/host.rs:
    • Add pointer-deduplicated KeepSet<T> for HostList::keep() so repeated retains of the same COM interface pointer on an open list skip QueryInterface/AddRef (removing the pointer if a cast fails, and clearing once GPU execution finishes).
    • Replace *self.deferred() = Deferred::default() in HostList::reset() with in-place Deferred::clear(), retaining steady-state capacities while capping runaway burst capacity at RETAINED_CAP (1024).
    • Eliminate nested per-list allocations in Host::execute() via pointer-deduplicated collect_unique_heaps() and borrow runs directly when uploads.is_none().
    • Store Arc<str> in HostList::pipelines (used_pipeline(&Arc<str>)).
    • Add tests deferred_clear_retains_steady_state_capacity_and_shrinks_bursts, keep_set_deduplicates_by_pointer_and_re_retains_after_clear, and collect_unique_heaps_deduplicates_by_pointer_in_order.
  • crates/victory-gpu/src/pipeline/host.rs:
    • Store HostPipeline::name as Arc<str> instead of String.
  • crates/victory-gpu/src/draw.rs:
    • Extract State::release_dynamic() (shared by Drop and State::reset()) and exhaustively reset all State fields in place to match State::default() while retaining steady-state capacities capped at RETAINED_CAP.
    • Track seen_pipelines: HashSet<usize> per State so repeated binds of the same host PSO on the same command list skip locking HostList::pipelines.
    • Add tests state_reset_releases_dynamic_resets_all_fields_and_retains_capacity and seen_pipelines_skips_duplicates_and_resets.

Not a duplicate of

No open PR or CLAIMS.md entry pointer-deduplicates HostList::keep(), retains/caps capacities across HostList::reset() / State::reset(), deduplicates Host::execute() heap collection, or avoids repeated HostList::pipelines locking with Arc<str> names.

Tested

  • Fork windows-latest MSVC + Windows WARP SM 6.6 CI run 45572159221 (Clippy clean, Clippy, diagnostics build clean, Tests: 715 passed; 0 failed; 10 ignored, victory-gpu: 157 passed; 0 failed; 2 ignored + 1 passed, xtask: 6 passed; 0 failed):
    • draw::tests::state_reset_releases_dynamic_resets_all_fields_and_retains_capacity ... ok
    • draw::tests::seen_pipelines_skips_duplicates_and_resets ... ok
    • host::tests::deferred_clear_retains_steady_state_capacity_and_shrinks_bursts ... ok
    • host::tests::keep_set_deduplicates_by_pointer_and_re_retains_after_clear ... ok
    • host::tests::collect_unique_heaps_deduplicates_by_pointer_in_order ... ok

Not run: the title; any hardware GPU. The title was not used in these tests.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 08:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2216) `RVZO6:rvzo/list-reset-keep-dedup` → `main` · +684 −53 · 3 files · 1 commits · closed without merging Command-list recording, reset, and submission paths in `victory-gpu` currently incur avoidable COM refcount traffic, per-reset heap churn, and lock/allocation overhead on every frame: 1. `HostList::keep()` unconditionally casts to `IUnknown` (`QueryInterface` + `AddRef`) and pushes onto a `Vec` on every draw/bind, even when the exact same PSO, root signature, or heap pointer is already retained on that command list. 2. `HostList::reset()` replaces `Deferred` with `Deferred::default()` and `State::reset()` replaces `State` with `State::default()`, freeing and reallocating every `Vec`/`HashMap`/`HashSet` on every command-list reset. 3. `Host::execute()` allocates nested per-list `Vec`s to collect unique heaps and unconditionally clones `runs` even when `uploads.is_none()`. 4. `HostPipeline::name` is cloned as a `String` and inserted into `HostList::pipelines` under a mutex on every pipeline switch, even when the same pipeline was already seen on the current command list. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155911614`). ## The change - `crates/victory-gpu/src/host.rs`: - Add pointer-deduplicated `KeepSet<T>` for `HostList::keep()` so repeated retains of the same COM interface pointer on an open list skip `QueryInterface`/`AddRef` (removing the pointer if a cast fails, and clearing once GPU execution finishes). - Replace `*self.deferred() = Deferred::default()` in `HostList::reset()` with in-place `Deferred::clear()`, retaining steady-state capacities while capping runaway burst capacity at `RETAINED_CAP` (`1024`). - Eliminate nested per-list allocations in `Host::execute()` via pointer-deduplicated `collect_unique_heaps()` and borrow `runs` directly when `uploads.is_none()`. - Store `Arc<str>` in `HostList::pipelines` (`used_pipeline(&Arc<str>)`). - Add tests `deferred_clear_retains_steady_state_capacity_and_shrinks_bursts`, `keep_set_deduplicates_by_pointer_and_re_retains_after_clear`, and `collect_unique_heaps_deduplicates_by_pointer_in_order`. - `crates/victory-gpu/src/pipeline/host.rs`: - Store `HostPipeline::name` as `Arc<str>` instead of `String`. - `crates/victory-gpu/src/draw.rs`: - Extract `State::release_dynamic()` (shared by `Drop` and `State::reset()`) and exhaustively reset all `State` fields in place to match `State::default()` while retaining steady-state capacities capped at `RETAINED_CAP`. - Track `seen_pipelines: HashSet<usize>` per `State` so repeated binds of the same host PSO on the same command list skip locking `HostList::pipelines`. - Add tests `state_reset_releases_dynamic_resets_all_fields_and_retains_capacity` and `seen_pipelines_skips_duplicates_and_resets`. ## Not a duplicate of No open PR or `CLAIMS.md` entry pointer-deduplicates `HostList::keep()`, retains/caps capacities across `HostList::reset()` / `State::reset()`, deduplicates `Host::execute()` heap collection, or avoids repeated `HostList::pipelines` locking with `Arc<str>` names. ## Tested - Fork `windows-latest` MSVC + Windows WARP SM 6.6 CI run [`45572159221`](https://github.com/RVZO6/VIctory/actions/runs/45572159221) (`Clippy` clean, `Clippy, diagnostics build` clean, `Tests`: **`715 passed; 0 failed; 10 ignored`**, `victory-gpu`: **`157 passed; 0 failed; 2 ignored`** + `1 passed`, `xtask`: **`6 passed; 0 failed`**): - `draw::tests::state_reset_releases_dynamic_resets_all_fields_and_retains_capacity ... ok` - `draw::tests::seen_pipelines_skips_duplicates_and_resets ... ok` - `host::tests::deferred_clear_retains_steady_state_capacity_and_shrinks_bursts ... ok` - `host::tests::keep_set_deduplicates_by_pointer_and_re_retains_after_clear ... ok` - `host::tests::collect_unique_heaps_deduplicates_by_pointer_in_order ... ok` **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
- Deduplicate `HostList::keep()` by raw interface pointer via `KeepSet<IUnknown>`
  before calling `QueryInterface`/`AddRef`, removing the pointer on cast failure
  and clearing after GPU execution completes.
- Replace `*self.deferred() = Deferred::default()` in `HostList::reset()` with
  in-place `Deferred::clear()`, retaining steady-state capacities while capping
  runaway burst capacity at `RETAINED_CAP` (1024).
- Extract `State::release_dynamic()` (shared by `Drop` and `State::reset()`),
  reset all `State` fields in-place to match `State::default()` with
  capacity-retaining/capped clearing.
- Remove nested per-list `Vec` allocations in `Host::execute()` via pointer-
  deduplicated `collect_unique_heaps()`, and borrow `runs` directly when
  `uploads.is_none()`.
- Store `HostPipeline::name` as `Arc<str>`, store `Arc<str>` in
  `HostList::pipelines`, and track `seen_pipelines` per `State` so repeated
  binds on the same list skip locking `HostList::pipelines` completely.
- Add GPU-free unit tests covering `Deferred::clear()`, `KeepSet`,
  `collect_unique_heaps()`, `State::reset()`, and `seen_pipelines`.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:44 +00:00
github-bot closed this pull request 2026-11-26 04:58:44 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:30 UTC · original · edited 2026-11-25 16:04 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2216#issuecomment-7163881777) · edited 2026-11-25 16:04 UTC <!-- victory-triage v1 head=d72f6da9b37f06b17373453eba0357f672ba9415 verdict=needs-rebase at=2026-11-25T16:15:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:13 UTC · original

Closing to keep the queue clean: draw.rs/host.rs moved significantly on 13f91ca and I do not have a title run to profile the frame-time impact.

**@⁠RVZO6** on GitHub · 2026-11-25 17:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2216#issuecomment-7169201549) Closing to keep the queue clean: `draw.rs`/`host.rs` moved significantly on `13f91ca` and I do not have a title run to profile the frame-time impact.

Pull request closed

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!2216
No description provided.