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

Closed
RVZO6 wants to merge 1 commit from upstream-pr/2216 into main
RVZO6 commented 2026-11-25 08:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T08:06:00Z.


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)

<!-- greyfinch-sync:Marvisak/VIctory:issue:6600020118 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2216). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T08:06:00Z. --- 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)
DenRakEiw commented 2026-11-25 09:05:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:22:56Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib draw::tests:: — 7 passed, 0 failed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean pointer deduplication in HostList::keep, capacity retention across resets, and faster Host::execute / used_pipeline. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054067240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2216#pullrequestreview-6054067240). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:22:56Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib draw::tests::` — **7 passed, 0 failed** on RTX 5090 - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean pointer deduplication in `HostList::keep`, capacity retention across resets, and faster `Host::execute` / `used_pipeline`. Looks great. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 09:05:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:21Z.

Review: COMMENTED


Pointer-deduplicates HostList::keep and retains pipeline capacity (+684 in draw.rs). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Perf-motivated; the seen_pipelines HashSet soundness argument (keep() keeps pipelines alive until list+State reset together) reads correctly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054378760 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2216#pullrequestreview-6054378760). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:21Z. **Review:** COMMENTED --- Pointer-deduplicates HostList::keep and retains pipeline capacity (+684 in draw.rs). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Perf-motivated; the seen_pipelines HashSet soundness argument (keep() keeps pipelines alive until list+State reset together) reads correctly.
Marvisak commented 2026-11-25 14:07:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:30:42Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163881777 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2216#issuecomment-7163881777). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:42Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 18:01:54 +00:00
RVZO6 commented 2026-11-25 18:02:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-25T17:13:59Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169201549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2216#issuecomment-7169201549). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T17:13:59Z. --- 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

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