GPU: cache redundant render target binds on host command lists #3107

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

@⁠fuzeofficlal on GitHub · 2026-11-26 08:18 UTC · original
fuzeofficlal:perf/gpu-cache-redundant-render-target-binds → main · +562 −18 · 2 files · 1 commits · open

Summary

draw::State::set_targets previously allocated new host RTV/DSV descriptors from the global CPU descriptor rings and recorded OMSetRenderTargets on every call, even when the title repeatedly bound the exact same render targets and depth stencil view on the same command list.

This adds a per-list host target binding cache in draw::State, matching the existing host_pipeline / host_roots / host_heaps caches:

  • Resolved view key (crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/draw.rs): RtvRecord::rtv_words and RtvRecord::dsv_words expose the exact 24-byte host descriptor words passed to CreateRenderTargetView / CreateDepthStencilView (after view_format / pc_format normalization). Each cached entry stores the resolved ID3D12Resource and Option<[u32; 6]> description words, keeping the cached COM references alive while bound so a destroyed resource's raw pointer cannot be reused (ABA), and detecting in-place descriptor overwrites at the same title handle.
  • Zero-allocation hit path with full state fidelity (crates/victory-gpu/src/draw.rs): State::set_targets still updates fixed.targets (reusing its Vec capacity), self.targets, self.depth, and diagnostic capture::note_target calls on every invocation. When the resolved host textures and view descriptions match host_targets.bound, it clears its scratch vector and skips host.rtv, host.dsv, and OMSetRenderTargets.
  • Complete invalidation: host_targets.bound starts as None (so an initial empty bind is not skipped) and is cleared on State::reset (command list Reset / ResetX) and State::host_state_lost (segment cut onto a new HostList, and external::record after host middleware records directly into the list).

Tests

  • Added draw::tests::redundant_set_targets_reuses_binding_and_invalidates_on_any_change covering initial bind, repeated hits, distinct handles to the same texture/desc, target swaps, in-place RTV mip and DSV flag overwrites at the same handle, empty binds, host_state_lost, cut(), and reset().
  • Added draw::tests::cached_render_targets_render_expected_pixels_across_redundant_binds_and_cut performing real D3D12 draws and pixel readbacks across redundant binds, target switches, in-place handle retargeting, and segment cut().
  • Verified:
    • cargo test -p victory-gpu --locked -- redundant_set_targets_reuses_binding cached_render_targets_render_expected_pixels (2 passed on RTX 5090)
    • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked (248 passed, 0 failed)
    • cargo clippy --workspace --all-targets --locked -- -D warnings
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
    • cargo test -p xtask --locked policy::tests::repository_passes_policy
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3107) `fuzeofficlal:perf/gpu-cache-redundant-render-target-binds` → `main` · +562 −18 · 2 files · 1 commits · open ### Summary `draw::State::set_targets` previously allocated new host RTV/DSV descriptors from the global CPU descriptor rings and recorded `OMSetRenderTargets` on every call, even when the title repeatedly bound the exact same render targets and depth stencil view on the same command list. This adds a per-list host target binding cache in `draw::State`, matching the existing `host_pipeline` / `host_roots` / `host_heaps` caches: - **Resolved view key (`crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/draw.rs`)**: `RtvRecord::rtv_words` and `RtvRecord::dsv_words` expose the exact 24-byte host descriptor words passed to `CreateRenderTargetView` / `CreateDepthStencilView` (after `view_format` / `pc_format` normalization). Each cached entry stores the resolved `ID3D12Resource` and `Option<[u32; 6]>` description words, keeping the cached COM references alive while bound so a destroyed resource's raw pointer cannot be reused (ABA), and detecting in-place descriptor overwrites at the same title handle. - **Zero-allocation hit path with full state fidelity (`crates/victory-gpu/src/draw.rs`)**: `State::set_targets` still updates `fixed.targets` (reusing its `Vec` capacity), `self.targets`, `self.depth`, and diagnostic `capture::note_target` calls on every invocation. When the resolved host textures and view descriptions match `host_targets.bound`, it clears its scratch vector and skips `host.rtv`, `host.dsv`, and `OMSetRenderTargets`. - **Complete invalidation**: `host_targets.bound` starts as `None` (so an initial empty bind is not skipped) and is cleared on `State::reset` (command list `Reset` / `ResetX`) and `State::host_state_lost` (segment `cut` onto a new `HostList`, and `external::record` after host middleware records directly into the list). ### Tests - Added `draw::tests::redundant_set_targets_reuses_binding_and_invalidates_on_any_change` covering initial bind, repeated hits, distinct handles to the same texture/desc, target swaps, in-place RTV mip and DSV flag overwrites at the same handle, empty binds, `host_state_lost`, `cut()`, and `reset()`. - Added `draw::tests::cached_render_targets_render_expected_pixels_across_redundant_binds_and_cut` performing real D3D12 draws and pixel readbacks across redundant binds, target switches, in-place handle retargeting, and segment `cut()`. - Verified: - `cargo test -p victory-gpu --locked -- redundant_set_targets_reuses_binding cached_render_targets_render_expected_pixels` (2 passed on RTX 5090) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked` (248 passed, 0 failed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `cargo test -p xtask --locked policy::tests::repository_passes_policy`
Skip host RTV/DSV descriptor ring creation and OMSetRenderTargets in draw::State::set_targets when the resolved host textures and view descriptions already match what is bound on the current host command list. Hold the cached ID3D12Resource references while bound to prevent COM pointer reuse (ABA), keep targets/depth/fixed state and diagnostic target notes updated on hits, and clear the cache on reset, segment cut, and external host_state_lost.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:24:59 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:28 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 22/22 passed on RTX 5090 and WARP (including cached_render_targets_render_expected_pixels_across_redundant_binds_and_cut and redundant_set_targets_reuses_binding_and_invalidates_on_any_change).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly caches redundant render target binds on host command lists and invalidates on any target/depth/cut change.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3107#pullrequestreview-6070699361) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 22/22 passed on RTX 5090 and WARP (including `cached_render_targets_render_expected_pixels_across_redundant_binds_and_cut` and `redundant_set_targets_reuses_binding_and_invalidates_on_any_change`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly caches redundant render target binds on host command lists and invalidates on any target/depth/cut change. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:32 UTC · original

Automated triage for the maintainers.

Verdict: needs work. CI check passes.

This PR caches the host render target binding in draw::State::set_targets (new HostTargets / BoundTarget). It skips host.rtv / host.dsv and OMSetRenderTargets when the resolved host textures and view words are unchanged. The cache is cleared in State::reset and State::host_state_lost. By my reading the invalidation is complete. I found no other OMSetRenderTargets on title lists in main besides the one in set_targets, and holding the ID3D12Resource avoids pointer reuse.

What it needs:

  • A measured benefit. This is a performance change with no numbers. Please show from a run of the title how often redundant binds occur and what they cost: CPU time in set_targets, or descriptor ring pressure from host.rtv / host.dsv. Without that, the extra state and 540 lines (mostly tests) are hard to justify.
  • It touches the same code in set_targets as #3109 by the same author. Once one of them lands, the other will need a rebase.

With measurements from the title showing a real cost, this would be reviewed for merge.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/3107#issuecomment-7186713953) <!-- victory-triage v1 head=119a6d9faa03aa3d6fb70a2fdc55aa21a98527f9 verdict=needs-work at=2026-11-26T08:31:06Z --> Automated triage for the maintainers. **Verdict: needs work.** CI `check` passes. This PR caches the host render target binding in `draw::State::set_targets` (new `HostTargets` / `BoundTarget`). It skips `host.rtv` / `host.dsv` and `OMSetRenderTargets` when the resolved host textures and view words are unchanged. The cache is cleared in `State::reset` and `State::host_state_lost`. By my reading the invalidation is complete. I found no other `OMSetRenderTargets` on title lists in main besides the one in `set_targets`, and holding the `ID3D12Resource` avoids pointer reuse. What it needs: - **A measured benefit.** This is a performance change with no numbers. Please show from a run of the title how often redundant binds occur and what they cost: CPU time in `set_targets`, or descriptor ring pressure from `host.rtv` / `host.dsv`. Without that, the extra state and 540 lines (mostly tests) are hard to justify. - It touches the same code in `set_targets` as #3109 by the same author. Once one of them lands, the other will need a rebase. With measurements from the title showing a real cost, this would be reviewed for merge. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3107/head:github-bot/gh-3107'
git switch 'github-bot/gh-3107'

Merge

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