GPU/list: retain host resources on Aliasing/UAV barriers and include depth-plane twin #479

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

@⁠AscilCH on GitHub · 2026-11-25 01:22 UTC · original
AscilCH:fix/gpu-barrier-retain-host-resources → main · +255 −37 · 1 files · 1 commits · open

Problem

In crates/victory-gpu/src/list.rs, host_barrier passed raw ID3D12Resource* pointers to ID3D12GraphicsCommandList::ResourceBarrier (which does not AddRef referenced resources):

  1. Use-After-Free on Aliasing (kind == 1) and UAV (kind == 2) barriers: Unlike Transition barriers (kind == 0, which keep Arc<HostTexture> in HostList::states via list.transition), Aliasing and UAV barriers borrowed raw pointers via resource::host_resource / resource::twin_resource without calling list.keep(...). If the title released the resource (or resource::let_go_idle evicted it) before ExecuteCommandLists, the host ID3D12Resource was destroyed while still referenced by the recorded command list.
  2. Missing depth-plane twin UAV barrier: For depth-stencil+UAV textures, kind == 2 only emitted a UAV barrier on twin.colour (stencil plane) and omitted twin.plane (depth plane).

Fix

  • Resolve owned Arc<HostTexture> / Arc<Twin> via resource::host_copy and resource::twin, retain every referenced ID3D12Resource on HostList via list.keep(...) until list reset, and emit UAV barriers for both twin.colour.texture and twin.plane.texture.
  • Add synthetic D3D12 unit test aliasing_and_uav_barriers_retain_host_resources_and_depth_plane_twin verifying COM refcount retention, both twin UAV barriers, and safe Close + ExecuteCommandLists after releasing all title textures.

Verification

  • cargo test -p victory-gpu --locked list::tests -- --test-threads=1: 2 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 01:22 UTC · [original](https://github.com/fxceless/victory-fork/pull/479) `AscilCH:fix/gpu-barrier-retain-host-resources` → `main` · +255 −37 · 1 files · 1 commits · open ## Problem In `crates/victory-gpu/src/list.rs`, `host_barrier` passed raw `ID3D12Resource*` pointers to `ID3D12GraphicsCommandList::ResourceBarrier` (which does not `AddRef` referenced resources): 1. **Use-After-Free on Aliasing (`kind == 1`) and UAV (`kind == 2`) barriers**: Unlike Transition barriers (`kind == 0`, which keep `Arc<HostTexture>` in `HostList::states` via `list.transition`), Aliasing and UAV barriers borrowed raw pointers via `resource::host_resource` / `resource::twin_resource` without calling `list.keep(...)`. If the title released the resource (or `resource::let_go_idle` evicted it) before `ExecuteCommandLists`, the host `ID3D12Resource` was destroyed while still referenced by the recorded command list. 2. **Missing depth-plane twin UAV barrier**: For depth-stencil+UAV textures, `kind == 2` only emitted a UAV barrier on `twin.colour` (stencil plane) and omitted `twin.plane` (depth plane). ## Fix - Resolve owned `Arc<HostTexture>` / `Arc<Twin>` via `resource::host_copy` and `resource::twin`, retain every referenced `ID3D12Resource` on `HostList` via `list.keep(...)` until list reset, and emit UAV barriers for both `twin.colour.texture` and `twin.plane.texture`. - Add synthetic D3D12 unit test `aliasing_and_uav_barriers_retain_host_resources_and_depth_plane_twin` verifying COM refcount retention, both twin UAV barriers, and safe `Close` + `ExecuteCommandLists` after releasing all title textures. ## Verification - `cargo test -p victory-gpu --locked list::tests -- --test-threads=1`: 2 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
D3D12 command lists do not AddRef resources passed to `ID3D12GraphicsCommandList::ResourceBarrier`. Transition barriers (`kind == 0`) kept host textures alive via `HostList::transition`, but Aliasing (`kind == 1`) and UAV (`kind == 2`) barriers extracted raw `ID3D12Resource*` pointers via `host_resource`/`twin_resource` without calling `list.keep(...)`. Releasing a title texture (or idle eviction) before `ExecuteCommandLists` therefore caused a host `ID3D12Resource` use-after-free.

Additionally, UAV barriers on depth-stencil+UAV textures only emitted a barrier for `twin.colour`, omitting `twin.plane` (the depth-plane twin).

Hold owned `Arc<HostTexture>` / `Arc<Twin>` via `resource::host_copy` / `resource::twin`, retain every referenced `ID3D12Resource` on the command list with `list.keep(...)`, and emit UAV barriers for both `twin.colour` and `twin.plane`. Add a synthetic D3D12 unit test verifying COM refcount retention, depth-plane twin emission, and safe execution after releasing title textures.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:44:17 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/list.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-479'
git switch 'github-bot/gh-479'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-479'
git switch 'github-bot/gh-479'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-479'
git switch 'main'
git merge --squash 'github-bot/gh-479'
git switch 'main'
git merge --ff-only 'github-bot/gh-479'
git switch 'main'
git merge 'github-bot/gh-479'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.