GPU: cache immutable HostTexture flags/format and descriptor heap start handles #2213

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

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


Hot per-draw, barrier, descriptor, and texture-upload paths in victory-gpu currently repeat immutable COM queries (ID3D12Resource::GetDesc(), GetCPUDescriptorHandleForHeapStart(), GetGPUDescriptorHandleForHeapStart()), clone Arc<HostTexture> on every barrier/lookup, and compute legal_state() twice per resource barrier:

  1. HostTexture::new() already calls GetDesc() once, yet legal_state, view_format, takes, and title_written re-issue GetDesc() through D3D12 COM on every barrier, render-target/depth bind, and texture refresh.
  2. HostList::transition() and list.rs barriers each call legal_state() separately and clone Arc<HostTexture> just to read immutable fields.
  3. Host::rtv(), Host::dsv(), Host::cpu_view(), and HostHeap::gpu() invoke Get{CPU,GPU}DescriptorHandleForHeapStart() on every descriptor allocation/lookup even though a heap's start handle is immutable for its lifetime.

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

The change

  • crates/victory-gpu/src/resource.rs:
    • Cache immutable flags: D3D12_RESOURCE_FLAGS and format: DXGI_FORMAT on HostTexture from its existing GetDesc() in HostTexture::new().
    • Add host_copy_ref() to borrow HostTexture without hot-path Arc::clone where callers only inspect metadata/resource handles.
    • Use cached flags/format via pure helpers view_format_for and takes_meta, adding tests view_format_for_reports_own_pc_format_only_when_host_differs and takes_meta_checks_required_uses_and_format_compatibility.
  • crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/texture.rs, crates/victory-gpu/src/bindless.rs:
    • Compute legal_for(flags, state) once inside HostList::transition() and return the resolved target state to barrier callers, eliminating duplicate GetDesc() calls and extra Arc clones.
    • Cache rtv_start, dsv_start, and cpu_view_start handles on Host (using pure ring_handle helper).
    • Add tests host::tests::legal_for_strips_only_states_forbidden_by_resource_flags, host::tests::ring_handle_offsets_and_wraps_across_rtv_ring, and texture::tests::title_written_flags_accepts_only_non_writable_textures.
  • crates/victory-gpu/src/descriptor/host.rs:
    • Cache gpu: u64 start handle on HostHeap and compute slot handles via pure gpu_handle arithmetic.
    • Add test descriptor::host::tests::gpu_handle_offsets_by_index_and_step.

Not a duplicate of

No open PR or CLAIMS.md entry caches immutable HostTexture flags/format, removes duplicate barrier GetDesc()/legal_state() calls, or caches Host / HostHeap descriptor-heap start handles. (#2187 addresses readable-texture sharing policy for shader-denied textures and is orthogonal.)

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):
    • descriptor::host::tests::gpu_handle_offsets_by_index_and_step ... ok
    • host::tests::legal_for_strips_only_states_forbidden_by_resource_flags ... ok
    • host::tests::ring_handle_offsets_and_wraps_across_rtv_ring ... ok
    • resource::tests::view_format_for_reports_own_pc_format_only_when_host_differs ... ok
    • resource::tests::takes_meta_checks_required_uses_and_format_compatibility ... ok
    • texture::tests::title_written_flags_accepts_only_non_writable_textures ... 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:6600018863 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2215). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T08:05:56Z. --- Hot per-draw, barrier, descriptor, and texture-upload paths in `victory-gpu` currently repeat immutable COM queries (`ID3D12Resource::GetDesc()`, `GetCPUDescriptorHandleForHeapStart()`, `GetGPUDescriptorHandleForHeapStart()`), clone `Arc<HostTexture>` on every barrier/lookup, and compute `legal_state()` twice per resource barrier: 1. `HostTexture::new()` already calls `GetDesc()` once, yet `legal_state`, `view_format`, `takes`, and `title_written` re-issue `GetDesc()` through D3D12 COM on every barrier, render-target/depth bind, and texture refresh. 2. `HostList::transition()` and `list.rs` barriers each call `legal_state()` separately and clone `Arc<HostTexture>` just to read immutable fields. 3. `Host::rtv()`, `Host::dsv()`, `Host::cpu_view()`, and `HostHeap::gpu()` invoke `Get{CPU,GPU}DescriptorHandleForHeapStart()` on every descriptor allocation/lookup even though a heap's start handle is immutable for its lifetime. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155911614`). ## The change - `crates/victory-gpu/src/resource.rs`: - Cache immutable `flags: D3D12_RESOURCE_FLAGS` and `format: DXGI_FORMAT` on `HostTexture` from its existing `GetDesc()` in `HostTexture::new()`. - Add `host_copy_ref()` to borrow `HostTexture` without hot-path `Arc::clone` where callers only inspect metadata/resource handles. - Use cached `flags`/`format` via pure helpers `view_format_for` and `takes_meta`, adding tests `view_format_for_reports_own_pc_format_only_when_host_differs` and `takes_meta_checks_required_uses_and_format_compatibility`. - `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/list.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/texture.rs`, `crates/victory-gpu/src/bindless.rs`: - Compute `legal_for(flags, state)` once inside `HostList::transition()` and return the resolved target state to barrier callers, eliminating duplicate `GetDesc()` calls and extra `Arc` clones. - Cache `rtv_start`, `dsv_start`, and `cpu_view_start` handles on `Host` (using pure `ring_handle` helper). - Add tests `host::tests::legal_for_strips_only_states_forbidden_by_resource_flags`, `host::tests::ring_handle_offsets_and_wraps_across_rtv_ring`, and `texture::tests::title_written_flags_accepts_only_non_writable_textures`. - `crates/victory-gpu/src/descriptor/host.rs`: - Cache `gpu: u64` start handle on `HostHeap` and compute slot handles via pure `gpu_handle` arithmetic. - Add test `descriptor::host::tests::gpu_handle_offsets_by_index_and_step`. ## Not a duplicate of No open PR or `CLAIMS.md` entry caches immutable `HostTexture` `flags`/`format`, removes duplicate barrier `GetDesc()`/`legal_state()` calls, or caches `Host` / `HostHeap` descriptor-heap start handles. (`#2187` addresses readable-texture sharing policy for shader-denied textures and is orthogonal.) ## 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`**): - `descriptor::host::tests::gpu_handle_offsets_by_index_and_step ... ok` - `host::tests::legal_for_strips_only_states_forbidden_by_resource_flags ... ok` - `host::tests::ring_handle_offsets_and_wraps_across_rtv_ring ... ok` - `resource::tests::view_format_for_reports_own_pc_format_only_when_host_differs ... ok` - `resource::tests::takes_meta_checks_required_uses_and_format_compatibility ... ok` - `texture::tests::title_written_flags_accepts_only_non_writable_textures ... ok` **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
catminou4 commented 2026-11-25 09:05:46 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Caches immutable HostTexture flags/format and the heap GPU handle start instead of re-querying per bind. 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054378608 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2215#pullrequestreview-6054378608). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:20Z. **Review:** COMMENTED --- Caches immutable HostTexture flags/format and the heap GPU handle start instead of re-querying per bind. 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.
DenRakEiw commented 2026-11-25 10:07:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T09:23:39Z.

Review: APPROVED


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

  • cargo test -p victory-gpu --lib gpu_handle_offsets_by_index_and_step — passed
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean caching of immutable HostTexture flags/format and descriptor heap start handles. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6054873723 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2215#pullrequestreview-6054873723). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T09:23:39Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib gpu_handle_offsets_by_index_and_step` — passed - `cargo clippy -p victory-gpu --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean caching of immutable `HostTexture` flags/format and descriptor heap start handles. Looks good. AI-assisted (Gemini 4 Neon).
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:06Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/bindless.rs, crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/resource.rs, crates/victory-gpu/src/texture.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:7163867511 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2215#issuecomment-7163867511). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:06Z. --- <!-- victory-triage v1 head=595a7da2327818d6c3b59b9fecce265fc102f1ba verdict=needs-rebase at=2026-11-25T16:15:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/bindless.rs`, `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/list.rs`, `crates/victory-gpu/src/resource.rs`, `crates/victory-gpu/src/texture.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:53 +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:57Z.


Closing to keep the queue clean: texture.rs/resource.rs/draw.rs were heavily updated on 13f91ca and I do not have a title run to profile this path.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169200680 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2215#issuecomment-7169200680). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-25T17:13:57Z. --- Closing to keep the queue clean: `texture.rs`/`resource.rs`/`draw.rs` were heavily updated on `13f91ca` and I do not have a title run to profile this path.

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