GPU: eliminate redundant per-draw/dispatch D3D12 state calls, cache ID3D12GraphicsCommandList6, and remove double shadow::find #2215

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

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


Every draw, mesh dispatch, and compute dispatch currently re-issues redundant D3D12 command-list state calls even when the host command list already has the exact same state bound:

  1. State::bind() re-emits all root CBVs, SRVs, UAVs, and 32-bit constants (including p.marks, VIEW_STRIDES, view_addresses, and memory tables) on every draw/dispatch even when the root signature and values are unchanged.
  2. State::prepare_for() re-scans all vertex buffers and calls IASetVertexBuffers / IASetIndexBuffer on every draw even when VB/IB bindings, p.slots, and HostList deferred copies have not changed.
  3. list.rs forwards IASetPrimitiveTopology, RSSetViewports, RSSetScissorRects, OMSetBlendFactor, and OMSetStencilRef straight onto the host command list without deduplication.
  4. State::dispatch_mesh() calls list.list.cast::<ID3D12GraphicsCommandList6>() (QueryInterface) on every mesh dispatch.
  5. readable() calls shadow::find() twice for View::Constant even though len <= s.left(address) guarantees the first lookup already covers [address, address + len).

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

The change

  • crates/victory-gpu/src/host.rs:
    • Cache list6: Option<ID3D12GraphicsCommandList6> once on HostList in Host::new_list().
    • Add monotonic copy_epoch: AtomicU64 + HostList::copy_epoch(), bumped in defer_copy, defer, defer_gpu_write, and reset.
  • crates/victory-gpu/src/draw.rs & crates/victory-gpu/src/list.rs:
    • Add a pure, unit-testable HostStateCache in draw.rs:
      • Deduplicates graphics and compute root CBV/SRV/UAV/32-bit-constant bindings (bound_roots: [Vec<BoundParam>; 2]) while keeping all shadow::refresh, shadow::gpu_writes, memory_map, and map.precise side effects intact. Clears affected slots on root-signature switch, descriptor-heap switch, compute rebind (take_rebind() / execute_indirect), host_state_lost(), and reset(). Validates p.marks up front and binds after for stage so depth-twin compute rebinds during tables() cannot leave compute mark bindings unset.
      • Tracks vb_dirty, ib_dirty, bound_vb_slots, bound_vb_epoch, and bound_ib_epoch against list.copy_epoch(), invalidating on VB/IB mutations, rectangle-list scratch expansion, p.slots expansion, copy_epoch advances, host_state_lost(), and reset().
      • Deduplicates topology, viewports (bitwise f32::to_bits), scissors, blend_factor (bitwise f32::to_bits, normalizing None to [1.0; 4] per D3D12), and stencil_ref routed through list.rs with_state.
    • Switch State::dispatch_mesh() to use cached list.list6.as_ref().
    • Remove the redundant second shadow::find(address, len) in readable() for View::Constant.
    • Add 3 unit tests: host_state_cache_dedups_root_params_and_invalidates_on_switches, host_state_cache_tracks_vb_ib_slots_mutations_and_copy_epoch, and host_state_cache_dedups_fixed_function_state_bitwise.

Not a duplicate of

No open PR or CLAIMS.md entry deduplicates per-draw/dispatch root parameters, VB/IB binds, or fixed-function D3D12 state, caches ID3D12GraphicsCommandList6 on HostList, or removes the double shadow::find in readable().

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::host_state_cache_dedups_root_params_and_invalidates_on_switches ... ok
    • draw::tests::host_state_cache_tracks_vb_ib_slots_mutations_and_copy_epoch ... ok
    • draw::tests::host_state_cache_dedups_fixed_function_state_bitwise ... 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:6600021556 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2217). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T08:06:05Z. --- Every draw, mesh dispatch, and compute dispatch currently re-issues redundant D3D12 command-list state calls even when the host command list already has the exact same state bound: 1. `State::bind()` re-emits all root CBVs, SRVs, UAVs, and 32-bit constants (including `p.marks`, `VIEW_STRIDES`, `view_addresses`, and `memory` tables) on every draw/dispatch even when the root signature and values are unchanged. 2. `State::prepare_for()` re-scans all vertex buffers and calls `IASetVertexBuffers` / `IASetIndexBuffer` on every draw even when VB/IB bindings, `p.slots`, and `HostList` deferred copies have not changed. 3. `list.rs` forwards `IASetPrimitiveTopology`, `RSSetViewports`, `RSSetScissorRects`, `OMSetBlendFactor`, and `OMSetStencilRef` straight onto the host command list without deduplication. 4. `State::dispatch_mesh()` calls `list.list.cast::<ID3D12GraphicsCommandList6>()` (`QueryInterface`) on every mesh dispatch. 5. `readable()` calls `shadow::find()` twice for `View::Constant` even though `len <= s.left(address)` guarantees the first lookup already covers `[address, address + len)`. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155911614`). ## The change - `crates/victory-gpu/src/host.rs`: - Cache `list6: Option<ID3D12GraphicsCommandList6>` once on `HostList` in `Host::new_list()`. - Add monotonic `copy_epoch: AtomicU64` + `HostList::copy_epoch()`, bumped in `defer_copy`, `defer`, `defer_gpu_write`, and `reset`. - `crates/victory-gpu/src/draw.rs` & `crates/victory-gpu/src/list.rs`: - Add a pure, unit-testable `HostStateCache` in `draw.rs`: - Deduplicates graphics and compute root CBV/SRV/UAV/32-bit-constant bindings (`bound_roots: [Vec<BoundParam>; 2]`) while keeping all `shadow::refresh`, `shadow::gpu_writes`, `memory_map`, and `map.precise` side effects intact. Clears affected slots on root-signature switch, descriptor-heap switch, compute rebind (`take_rebind()` / `execute_indirect`), `host_state_lost()`, and `reset()`. Validates `p.marks` up front and binds after `for stage` so depth-twin compute rebinds during `tables()` cannot leave compute mark bindings unset. - Tracks `vb_dirty`, `ib_dirty`, `bound_vb_slots`, `bound_vb_epoch`, and `bound_ib_epoch` against `list.copy_epoch()`, invalidating on VB/IB mutations, rectangle-list scratch expansion, `p.slots` expansion, `copy_epoch` advances, `host_state_lost()`, and `reset()`. - Deduplicates `topology`, `viewports` (bitwise `f32::to_bits`), `scissors`, `blend_factor` (bitwise `f32::to_bits`, normalizing `None` to `[1.0; 4]` per D3D12), and `stencil_ref` routed through `list.rs` `with_state`. - Switch `State::dispatch_mesh()` to use cached `list.list6.as_ref()`. - Remove the redundant second `shadow::find(address, len)` in `readable()` for `View::Constant`. - Add 3 unit tests: `host_state_cache_dedups_root_params_and_invalidates_on_switches`, `host_state_cache_tracks_vb_ib_slots_mutations_and_copy_epoch`, and `host_state_cache_dedups_fixed_function_state_bitwise`. ## Not a duplicate of No open PR or `CLAIMS.md` entry deduplicates per-draw/dispatch root parameters, VB/IB binds, or fixed-function D3D12 state, caches `ID3D12GraphicsCommandList6` on `HostList`, or removes the double `shadow::find` in `readable()`. ## 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::host_state_cache_dedups_root_params_and_invalidates_on_switches ... ok` - `draw::tests::host_state_cache_tracks_vb_ib_slots_mutations_and_copy_epoch ... ok` - `draw::tests::host_state_cache_dedups_fixed_function_state_bitwise ... 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:47 +00:00 (Migrated from github.com)

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

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:: — 8 passed, 0 failed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean elimination of redundant per-draw/dispatch D3D12 state calls, cached ID3D12GraphicsCommandList6, and removal of duplicate shadow::find. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054066937 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2217#pullrequestreview-6054066937). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T08:22:55Z. **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::` — **8 passed, 0 failed** on RTX 5090 - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean elimination of redundant per-draw/dispatch D3D12 state calls, cached `ID3D12GraphicsCommandList6`, and removal of duplicate `shadow::find`. 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:22Z.

Review: COMMENTED


Eliminates redundant per-draw/dispatch D3D12 state tracking via a BoundParam model of last-bound root values (+777/-138). 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. Largest refactor in this wave; worth a Windows hardware pass before merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054378901 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2217#pullrequestreview-6054378901). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:22Z. **Review:** COMMENTED --- Eliminates redundant per-draw/dispatch D3D12 state tracking via a BoundParam model of last-bound root values (+777/-138). 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. Largest refactor in this wave; worth a Windows hardware pass before merge.
Marvisak commented 2026-11-25 14:07:21 +00:00 (Migrated from github.com)

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


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, crates/victory-gpu/src/list.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:7163878586 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2217#issuecomment-7163878586). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:34Z. --- <!-- victory-triage v1 head=86e18a71f47ac6323623f99e9f7ad8feb634461e verdict=needs-rebase at=2026-11-25T16:16:00Z --> 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`, `crates/victory-gpu/src/list.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:14:01Z.


Closing to keep the queue clean: draw.rs/host.rs moved significantly on 13f91ca and I do not have a title run to profile per-draw D3D12 state savings.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169202330 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2217#issuecomment-7169202330). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T17:14:01Z. --- Closing to keep the queue clean: `draw.rs`/`host.rs` moved significantly on `13f91ca` and I do not have a title run to profile per-draw D3D12 state savings.

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