fix(victory-gpu): collapse duplicate transition barriers per resource in a batch #290

Open
github-bot wants to merge 3 commits from github-bot/gh-290 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:25 UTC · original
mauroalvare:fix/victory-barrier-dedup → main · +351 −13 · 1 files · 3 commits · open

Summary

Fixes duplicate D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES transition barriers emitted for the same host texture in a single ID3D12GraphicsCommandList::ResourceBarrier call in third_party/victory/crates/victory-gpu/src/list.rs (barrier / host_barriers).

Because victory-gpu tracks whole-texture states (Subresource = 0xffffffff), a title ResourceBarrier batch that transitions two different subresources of the same texture to different states (for example, mip 0 RENDER_TARGET -> PIXEL_SHADER_RESOURCE and mip 1 PIXEL_SHADER_RESOURCE -> UNORDERED_ACCESS, or two aliased title textures backed by the same host texture) previously emitted two ALL_SUBRESOURCES transition barriers for the same ID3D12Resource* in one ResourceBarrier() call.

In D3D12, referencing the same subresource (or ALL_SUBRESOURCES) in more than one transition barrier within a single ResourceBarrier() call is invalid (D3D12_MESSAGE_ID_RESOURCE_BARRIER_DUPLICATE_SUBRESOURCE_TRANSITIONS #540) and causes ID3D12GraphicsCommandList::Close() to fail under D3D12 validation (triggering host::fail).

What changed

  • Extracted host_barriers(list, barriers) from list::barrier and collapsed multiple transition barriers targeting the same host ID3D12Resource* within a single batch into one transition from the batch's initial StateBefore to its final StateAfter.
  • If a collapsed transition round-trips back to its initial state (StateBefore == StateAfter):
    • When that state is D3D12_RESOURCE_STATE_UNORDERED_ACCESS (0x8), replace it with a resource-scoped UAV barrier (unless a UAV barrier covering that resource is already in the batch) so earlier UAV writes remain ordered without emitting an invalid UAV -> UAV or duplicate transition barrier.
    • For any other state, drop the no-op transition.
  • Added synthetic GPU unit tests in list::tests covering same-texture multi-subresource transitions, UAV round-trips, non-UAV round-trips, interleaved multi-texture batches, and end-to-end GPU execution on RTX 5070 Ti and WARP.

Reproduction and test results

Base commit: c4c93bdc413191a9dc909998d2d53080a3f0c880 (LooperSalty/AnyXboxX:main).
Hardware: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2140), Rust 1.98.1.
All tests are 100% synthetic (no game files). Note: Windows Graphics Tools (d3d12SDKLayers.dll) is not installed on this machine, so validation checks both the exact barrier slice passed to ResourceBarrier and end-to-end command-list execution on RTX 5070 Ti and WARP.

Before fix (base c4c93bdc + test, RTX 5070 Ti)

cargo test --locked -p victory-gpu list::tests::barrier_batch_collapses_duplicate_transitions_for_same_texture -- --nocapture

Result: FAILED:

  • assertion left == right failed: duplicate ALL_SUBRESOURCES transitions for the same texture must collapse to one barrier (left: 2, right: 1) — emitted two ALL_SUBRESOURCES transitions (0x4 -> 0x80, 0x80 -> 0x8) for the same host texture in a single ResourceBarrier call.

After fix

Command Adapter / Mode Result
cargo test --locked -p victory-gpu list::tests -- --test-threads=1 RTX 5070 Ti (default) 4 passed, 0 failed
VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics list::tests -- --test-threads=1 RTX 5070 Ti (diagnostics) 4 passed, 0 failed
VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics list::tests -- --test-threads=1 WARP (diagnostics) 4 passed, 0 failed
cargo test --locked -p victory-loader --test load_probe Smoke (hle-probe) 2 passed, 0 failed
cargo xtask policy (in third_party/victory) Asset policy asset policy: 199 files ok
cargo clippy --locked -p victory-gpu --tests Clippy 0 new warnings in list.rs

AI assistance

Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code, synthetic tests, and local GPU/WARP runs were inspected and verified on this machine.

**@⁠mauroalvare** on GitHub · 2026-11-26 01:25 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/290) `mauroalvare:fix/victory-barrier-dedup` → `main` · +351 −13 · 1 files · 3 commits · open ## Summary Fixes duplicate `D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES` transition barriers emitted for the same host texture in a single `ID3D12GraphicsCommandList::ResourceBarrier` call in `third_party/victory/crates/victory-gpu/src/list.rs` (`barrier` / `host_barriers`). Because `victory-gpu` tracks whole-texture states (`Subresource = 0xffffffff`), a title `ResourceBarrier` batch that transitions two different subresources of the same texture to different states (for example, mip 0 `RENDER_TARGET -> PIXEL_SHADER_RESOURCE` and mip 1 `PIXEL_SHADER_RESOURCE -> UNORDERED_ACCESS`, or two aliased title textures backed by the same host texture) previously emitted two `ALL_SUBRESOURCES` transition barriers for the same `ID3D12Resource*` in one `ResourceBarrier()` call. In D3D12, referencing the same subresource (or `ALL_SUBRESOURCES`) in more than one transition barrier within a single `ResourceBarrier()` call is invalid (`D3D12_MESSAGE_ID_RESOURCE_BARRIER_DUPLICATE_SUBRESOURCE_TRANSITIONS` #540) and causes `ID3D12GraphicsCommandList::Close()` to fail under D3D12 validation (triggering `host::fail`). ## What changed - Extracted `host_barriers(list, barriers)` from `list::barrier` and collapsed multiple transition barriers targeting the same host `ID3D12Resource*` within a single batch into one transition from the batch's initial `StateBefore` to its final `StateAfter`. - If a collapsed transition round-trips back to its initial state (`StateBefore == StateAfter`): - When that state is `D3D12_RESOURCE_STATE_UNORDERED_ACCESS` (`0x8`), replace it with a resource-scoped UAV barrier (unless a UAV barrier covering that resource is already in the batch) so earlier UAV writes remain ordered without emitting an invalid `UAV -> UAV` or duplicate transition barrier. - For any other state, drop the no-op transition. - Added synthetic GPU unit tests in `list::tests` covering same-texture multi-subresource transitions, UAV round-trips, non-UAV round-trips, interleaved multi-texture batches, and end-to-end GPU execution on RTX 5070 Ti and WARP. ## Reproduction and test results Base commit: `c4c93bdc413191a9dc909998d2d53080a3f0c880` (`LooperSalty/AnyXboxX:main`). Hardware: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver `32.0.16.2140`), Rust `1.98.1`. All tests are 100% synthetic (no game files). Note: Windows Graphics Tools (`d3d12SDKLayers.dll`) is not installed on this machine, so validation checks both the exact barrier slice passed to `ResourceBarrier` and end-to-end command-list execution on RTX 5070 Ti and WARP. ### Before fix (base `c4c93bdc` + test, RTX 5070 Ti) ```powershell cargo test --locked -p victory-gpu list::tests::barrier_batch_collapses_duplicate_transitions_for_same_texture -- --nocapture ``` Result: **FAILED**: - `assertion left == right failed: duplicate ALL_SUBRESOURCES transitions for the same texture must collapse to one barrier` (`left: 2`, `right: 1`) — emitted two `ALL_SUBRESOURCES` transitions (`0x4 -> 0x80`, `0x80 -> 0x8`) for the same host texture in a single `ResourceBarrier` call. ### After fix | Command | Adapter / Mode | Result | | --- | --- | --- | | `cargo test --locked -p victory-gpu list::tests -- --test-threads=1` | RTX 5070 Ti (default) | **4 passed, 0 failed** | | `VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics list::tests -- --test-threads=1` | RTX 5070 Ti (`diagnostics`) | **4 passed, 0 failed** | | `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test --locked -p victory-gpu --features diagnostics list::tests -- --test-threads=1` | WARP (`diagnostics`) | **4 passed, 0 failed** | | `cargo test --locked -p victory-loader --test load_probe` | Smoke (`hle-probe`) | **2 passed, 0 failed** | | `cargo xtask policy` (in `third_party/victory`) | Asset policy | **asset policy: 199 files ok** | | `cargo clippy --locked -p victory-gpu --tests` | Clippy | **0 new warnings in `list.rs`** | ## AI assistance Developed and verified with AI assistance (Antigravity / Gemini 4 Neon). All code, synthetic tests, and local GPU/WARP runs were inspected and verified on this machine.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:07 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/290/head:github-bot/gh-290'
git switch 'github-bot/gh-290'

Merge

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