GPU: cache redundant render target binds on host command lists #3107
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3107
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3107"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 · openSummary
draw::State::set_targetspreviously allocated new host RTV/DSV descriptors from the global CPU descriptor rings and recordedOMSetRenderTargetson 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 existinghost_pipeline/host_roots/host_heapscaches:crates/victory-gpu/src/descriptor.rs,crates/victory-gpu/src/draw.rs):RtvRecord::rtv_wordsandRtvRecord::dsv_wordsexpose the exact 24-byte host descriptor words passed toCreateRenderTargetView/CreateDepthStencilView(afterview_format/pc_formatnormalization). Each cached entry stores the resolvedID3D12ResourceandOption<[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.crates/victory-gpu/src/draw.rs):State::set_targetsstill updatesfixed.targets(reusing itsVeccapacity),self.targets,self.depth, and diagnosticcapture::note_targetcalls on every invocation. When the resolved host textures and view descriptions matchhost_targets.bound, it clears its scratch vector and skipshost.rtv,host.dsv, andOMSetRenderTargets.host_targets.boundstarts asNone(so an initial empty bind is not skipped) and is cleared onState::reset(command listReset/ResetX) andState::host_state_lost(segmentcutonto a newHostList, andexternal::recordafter host middleware records directly into the list).Tests
draw::tests::redundant_set_targets_reuses_binding_and_invalidates_on_any_changecovering 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(), andreset().draw::tests::cached_render_targets_render_expected_pixels_across_redundant_binds_and_cutperforming real D3D12 draws and pixel readbacks across redundant binds, target switches, in-place handle retargeting, and segmentcut().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 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test -p xtask --locked policy::tests::repository_passes_policy@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 (includingcached_render_targets_render_expected_pixels_across_redundant_binds_and_cutandredundant_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).
@Marvisak on GitHub · 2026-11-26 08:32 UTC · original
Automated triage for the maintainers.
Verdict: needs work. CI
checkpasses.This PR caches the host render target binding in
draw::State::set_targets(newHostTargets/BoundTarget). It skipshost.rtv/host.dsvandOMSetRenderTargetswhen the resolved host textures and view words are unchanged. The cache is cleared inState::resetandState::host_state_lost. By my reading the invalidation is complete. I found no otherOMSetRenderTargetson title lists in main besides the one inset_targets, and holding theID3D12Resourceavoids pointer reuse.What it needs:
set_targets, or descriptor ring pressure fromhost.rtv/host.dsv. Without that, the extra state and 540 lines (mostly tests) are hard to justify.set_targetsas #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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.