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

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

@⁠fuzeofficlal on GitHub · 2026-11-26 09:18 UTC · original
fuzeofficlal:fix/gpu-keep-render-targets-on-list → main · +154 −0 · 1 files · 1 commits · open

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/3128) `fuzeofficlal:fix/gpu-keep-render-targets-on-list` → `main` · +154 −0 · 1 files · 1 commits · open ### 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.
State::set_targets records OMSetRenderTargets directly onto the host D3D12 command list using host RTV/DSV descriptors created from each target's ID3D12Resource, while HostList::transition only runs later when a draw executes. If no draw runs with those targets (for example, after a dropped draw or a later OMSetRenderTargets switch) and the title releases them before submission, the host ID3D12Resource is destroyed while still referenced by the command list.

Retain each bound render target and depth target via HostList::keep in State::set_targets so the recorded command list holds a COM reference until HostList::reset.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:07 +00:00
Author
Owner

@⁠smaxxey on GitHub · 2026-11-26 10:13 UTC · original

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.

**@⁠smaxxey** on GitHub · 2026-11-26 10:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3128#issuecomment-7189073159) 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.
Author
Owner

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

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 12:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3128#pullrequestreview-6074444355) · **approved these changes** 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 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/3128/head:github-bot/gh-3128'
git switch 'github-bot/gh-3128'

Merge

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