GPU: keep bound render and depth targets alive on command lists #3126

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3128 into main
fuzeofficlal commented 2026-11-26 09:18:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:18:51Z.


Summary

State::set_targets creates host RTV/DSV descriptors from each target's ID3D12Resource and immediately records OMSetRenderTargets onto the host command list, without calling HostList::keep on those textures.

HostList::transition (which retains Arc<HostTexture> in HostList::states) only runs later in State::prepare_for when a draw executes. If a title binds render or depth targets, does not draw to them on that list (for example, after a dropped draw or a subsequent OMSetRenderTargets call), and releases the resources before submission, the host ID3D12Resource is destroyed while still referenced by the recorded command list. Under the D3D12 debug layer, ID3D12CommandList::Close fails with a deleted-resource error.

Fix

  • Call list.keep(&texture) for each bound render target and depth target in State::set_targets (crates/victory-gpu/src/draw.rs), holding a COM reference until HostList::reset.
  • Add regression test draw::tests::render_and_depth_targets_stay_alive_until_list_reset verifying both:
    1. Binding RTV + DSV, switching away, releasing both title resources, closing, and executing produces zero D3D12 debug layer messages (fails on main at ID3D12CommandList::Close with a deleted-resource error).
    2. The command list retains COM references to both host textures across submission and releases them on HostList::reset (also fails on main without the debug layer).

Verification

  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1 draw:: (hardware GPU & VICTORY_D3D12_WARP=1): 21 passed, 0 failed.
  • Full victory-gpu unit suite on hardware GPU and VICTORY_D3D12_WARP=1 (default and --features diagnostics with VICTORY_D3D12_DEBUG=1).
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --all-features: clean.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6623431078 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3128). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T09:18:51Z. --- ### Summary `State::set_targets` creates host RTV/DSV descriptors from each target's `ID3D12Resource` and immediately records `OMSetRenderTargets` onto the host command list, without calling `HostList::keep` on those textures. `HostList::transition` (which retains `Arc<HostTexture>` in `HostList::states`) only runs later in `State::prepare_for` when a draw executes. If a title binds render or depth targets, does not draw to them on that list (for example, after a dropped draw or a subsequent `OMSetRenderTargets` call), and releases the resources before submission, the host `ID3D12Resource` is destroyed while still referenced by the recorded command list. Under the D3D12 debug layer, `ID3D12CommandList::Close` fails with a deleted-resource error. ### Fix - Call `list.keep(&texture)` for each bound render target and depth target in `State::set_targets` (`crates/victory-gpu/src/draw.rs`), holding a COM reference until `HostList::reset`. - Add regression test `draw::tests::render_and_depth_targets_stay_alive_until_list_reset` verifying both: 1. Binding RTV + DSV, switching away, releasing both title resources, closing, and executing produces zero D3D12 debug layer messages (fails on `main` at `ID3D12CommandList::Close` with a deleted-resource error). 2. The command list retains COM references to both host textures across submission and releases them on `HostList::reset` (also fails on `main` without the debug layer). ### Verification - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1 draw::` (hardware GPU & `VICTORY_D3D12_WARP=1`): 21 passed, 0 failed. - Full `victory-gpu` unit suite on hardware GPU and `VICTORY_D3D12_WARP=1` (default and `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`). - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--all-features`: clean. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed.
smaxxey commented 2026-11-26 11:03:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by smaxxey on 2026-11-26T10:13:24Z.


Ran this on an RTX 4060 Laptop GPU (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head 5f8111a merged locally onto main 63bcca4.

  • draw::tests::render_and_depth_targets_stay_alive_until_list_reset passes on the hardware device.
  • cargo test -p victory-gpu --lib --locked: 230 passed, 2 failed, same as main 63bcca4 on this card: only the two NVIDIA failures of #1835 (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views), nothing new.

What bites in a plain test run is part 2, the COM reference counts. Part 1's log_messages() == None checks see nothing by construction: Host turns the debug layer on only in a diagnostics build with VICTORY_D3D12_DEBUG, and this machine has no debug layer installed.

Tested with Claude Code's help.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189073159 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3128#issuecomment-7189073159). Originally posted by [smaxxey](https://github.com/smaxxey) on 2026-11-26T10:13:24Z. --- Ran this on an **RTX 4060 Laptop GPU** (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head `5f8111a` merged locally onto `main` 63bcca4. - `draw::tests::render_and_depth_targets_stay_alive_until_list_reset` passes on the hardware device. - `cargo test -p victory-gpu --lib --locked`: 230 passed, 2 failed, same as `main` 63bcca4 on this card: only the two NVIDIA failures of #1835 (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`), nothing new. What bites in a plain test run is part 2, the COM reference counts. Part 1's `log_messages() == None` checks see nothing by construction: `Host` turns the debug layer on only in a `diagnostics` build with `VICTORY_D3D12_DEBUG`, and this machine has no debug layer installed. Tested with Claude Code's help.
Dukestar69 commented 2026-11-26 13:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:52:31Z.

Review: APPROVED


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

  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed (including render_and_depth_targets_stay_alive_until_list_reset).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly keeps bound render and depth targets alive until command-list reset.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6074444355 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3128#pullrequestreview-6074444355). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:52:31Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 21/21 passed (including `render_and_depth_targets_stay_alive_until_list_reset`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly keeps bound render and depth targets alive until command-list reset. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3128:upstream-pr/3128'
git switch 'upstream-pr/3128'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3128'
git switch 'upstream-pr/3128'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3128'
git switch 'upstream-pr/3128'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3128'
git switch 'main'
git merge --squash 'upstream-pr/3128'
git switch 'main'
git merge --ff-only 'upstream-pr/3128'
git switch 'main'
git merge 'upstream-pr/3128'
git push origin 'main'
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!3126
No description provided.