GPU: sanitize resource barrier bind flags and UAV targets #43

Open
github-bot wants to merge 2 commits from github-bot/gh-43 into main AGit
Owner

@⁠vicennpacheco on GitHub · 2026-11-25 12:42 UTC · original
vicennpacheco:fix/uav-barrier-bind-flags → main · +200 −22 · 1 files · 2 commits · open

Summary

Addresses ResourceBarrier bind-flag validation errors (id=523: Missing resource bind flags, causing ID3D12GraphicsCommandList::Close to fail with E_INVALIDARG / 0x80070057), as reported in #13.

Changes (crates/victory-gpu/src/list.rs)

  1. UAV barriers on non-UAV host textures (host_barrier, kind == 2): if the named host resource lacks D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS (for example, a depth texture whose console copy allowed UAVs), emit a global UAV_BARRIER (null resource) instead of naming the texture directly, and zero any console barrier flags.
  2. Transition barriers (host_barrier, kind == 0): sanitize both before and wanted through legal_state and drop no-op transitions (before == after).
  3. clear_rtv: route the RENDER_TARGET transition through ensure_state (matching clear_dsv) instead of passing raw State(RENDER_TARGET).
  4. Test: add list::tests::uav_barrier_on_non_uav_texture_falls_back_to_global verifying that a depth texture falls back to a global UAV barrier, a UAV-capable texture keeps its pointer, and both record and close cleanly on a live D3D12 command list.

(Note: tested without game files, so linking #13 rather than auto-closing it.)

Verification

Tested on Windows 11, AMD Radeon Vega 8 iGPU (Ryzen 7 5825U, GCN 5 / gfx90c, PCI 1002:15E7, AMD driver 31.0.21921.13001), Rust 1.98.1 (x86_64-pc-windows-msvc), without game files:

  • cargo test -p victory-gpu --lib -- list::tests: 6 passed, 0 failed (both default and VICTORY_D3D12_DEBUG=1, no debug-layer errors)
  • cargo test -p victory-gpu --lib: 110 passed, 0 failed, 4 ignored

(AI-assisted investigation and patch.)

**@⁠vicennpacheco** on GitHub · 2026-11-25 12:42 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/43) `vicennpacheco:fix/uav-barrier-bind-flags` → `main` · +200 −22 · 1 files · 2 commits · open ### Summary Addresses `ResourceBarrier` bind-flag validation errors (`id=523`: Missing resource bind flags, causing `ID3D12GraphicsCommandList::Close` to fail with `E_INVALIDARG` / `0x80070057`), as reported in #13. ### Changes (`crates/victory-gpu/src/list.rs`) 1. **UAV barriers on non-UAV host textures (`host_barrier`, `kind == 2`):** if the named host resource lacks `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS` (for example, a depth texture whose console copy allowed UAVs), emit a global `UAV_BARRIER` (null resource) instead of naming the texture directly, and zero any console barrier flags. 2. **Transition barriers (`host_barrier`, `kind == 0`):** sanitize both `before` and `wanted` through `legal_state` and drop no-op transitions (`before == after`). 3. **`clear_rtv`:** route the `RENDER_TARGET` transition through `ensure_state` (matching `clear_dsv`) instead of passing raw `State(RENDER_TARGET)`. 4. **Test:** add `list::tests::uav_barrier_on_non_uav_texture_falls_back_to_global` verifying that a depth texture falls back to a global UAV barrier, a UAV-capable texture keeps its pointer, and both record and close cleanly on a live D3D12 command list. *(Note: tested without game files, so linking #13 rather than auto-closing it.)* ### Verification Tested on Windows 11, AMD Radeon Vega 8 iGPU (Ryzen 7 5825U, GCN 5 / `gfx90c`, PCI `1002:15E7`, AMD driver `31.0.21921.13001`), Rust `1.98.1` (`x86_64-pc-windows-msvc`), without game files: - `cargo test -p victory-gpu --lib -- list::tests`: **6 passed, 0 failed** (both default and `VICTORY_D3D12_DEBUG=1`, no debug-layer errors) - `cargo test -p victory-gpu --lib`: **110 passed, 0 failed, 4 ignored** *(AI-assisted investigation and patch.)*
Strict D3D12 drivers reject command lists with `E_INVALIDARG` (debug
layer `id=523`: Missing resource bind flags) when `ResourceBarrier`
names a host texture lacking the required bind flag:

- In `host_barrier` (`kind == 2`, UAV barrier), fall back to a global
  `UAV_BARRIER` (null resource) whenever the host texture lacks
  `D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS` (e.g. depth textures
  whose console copies allowed UAVs), and clear console barrier flags.
- In `host_barrier` (`kind == 0`, transition), sanitize both `before`
  and `wanted` with `legal_state` and skip no-op transitions.
- In `clear_rtv`, use `ensure_state` (matching `clear_dsv`) so
  `RENDER_TARGET` is sanitized through `legal_state`.

Related to #13.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:24 +00:00
Author
Owner

@⁠enriquebruno12 on GitHub · 2026-11-25 14:49 UTC · original

Independently tested on Windows on my RX 9070 XT system. The depth texture used a global UAV barrier, the UAV-capable texture retained its resource pointer, and the D3D12 command list closed successfully. The test also passed in a diagnostics build with VICTORY_D3D12_DEBUG=1 and a live device required. No game files were used.

**@⁠enriquebruno12** on GitHub · 2026-11-25 14:49 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/43#issuecomment-7165885417) Independently tested on Windows on my RX 9070 XT system. The depth texture used a global UAV barrier, the UAV-capable texture retained its resource pointer, and the D3D12 command list closed successfully. The test also passed in a diagnostics build with VICTORY_D3D12_DEBUG=1 and a live device required. No game files were used.
Author
Owner

@⁠vicennpacheco on GitHub · 2026-11-25 16:39 UTC · original

Good call — extracted transition_barrier_for and added list::tests::transition_barrier_skips_noop_after_legal_state covering the cases where legal_state collapses before == after to None (e.g. UAV -> COMMON, UAV -> RT, and (UAV | DEPTH_WRITE) -> DEPTH_WRITE on a depth texture) as well as recording/closing a sanitized legal transition on a live D3D12 command list. Verified on Vega 8 (default and VICTORY_D3D12_DEBUG=1: 7 passed, 0 failed).

**@⁠vicennpacheco** on GitHub · 2026-11-25 16:39 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/43#issuecomment-7168339554) Good call — extracted `transition_barrier_for` and added `list::tests::transition_barrier_skips_noop_after_legal_state` covering the cases where `legal_state` collapses `before == after` to `None` (e.g. `UAV -> COMMON`, `UAV -> RT`, and `(UAV | DEPTH_WRITE) -> DEPTH_WRITE` on a depth texture) as well as recording/closing a sanitized legal transition on a live D3D12 command list. Verified on Vega 8 (default and `VICTORY_D3D12_DEBUG=1`: 7 passed, 0 failed).
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 17:23 UTC · original

Tried on an RX 7900 XT (RDNA3, driver 32.0.32029.2010), Windows 11 build 26300, without the debug layer (only Close()'s HRESULT is checked). I used a test that records barriers the way the title does, through the list's barrier entry point, on host textures that lack a use the console allows.

What fails on main (Close returns 0x80070057), so this is not NVIDIA-only:

  • a UAV barrier naming a texture whose host copy has no ALLOW_UNORDERED_ACCESS (a depth texture with console UAV; BGRX8 also loses UAV on this card);
  • a UAV barrier with the console's split flags (BEGIN_ONLY / END_ONLY), on a texture or global;
  • an aliasing barrier with BEGIN_ONLY.

Transitions, split transitions, and UAV/aliasing barriers without flags all close.

With this PR every UAV case closes, but the aliasing case still fails: the kind-1 arm (list.rs:521 on 01aadd1) passes the console's flags through with ..*b. One line fixes it, since the host splits only transitions:

         1 => Some(Barrier {
+            flags: 0,
             first: if b.first.is_null() {

With #43 and that line on 71652a2, cargo test -p victory-gpu --lib gives 112 passed, 0 failed, 4 ignored here.

The kind-0 change makes no difference in the real path, as far as I can tell (checked at 667389f; a3788be moves it into transition_barrier_for without changing it). HostList::transition (host.rs:2013 on 01aadd1) already runs wanted through legal_state before it stores or compares it, and it returns None when the state does not change. So before is always a state that was legalised earlier, and the new before == after check can never fire. legal_for only clears bits, so applying it twice gives the same value. The code is the same at 4cbe9d7, the tree used in #13. The new test calls transition_barrier_for directly with raw before states such as UAV | DEPTH_WRITE, but host_barrier only ever passes the before that transition returns, which is already legal. So the black-to-visible change reported in #13 on the RTX 4060 Ti probably comes from something else in that run (a fresh cache, another difference), which may be worth finding. A more likely trigger on NVIDIA is the UAV case above: resource::host_texture drops UAV from formats the host refuses (resource.rs:1310, BGRA8 on NVIDIA). WARP and this AMD card keep it, which would fit "WARP passes". That part is a guess; I have no NVIDIA card.

Two smaller notes:

  • clear_rtv through ensure_state also calls resource::note_written (list.rs:598), so a clear now moves the texture's written clock. That is probably right, but the description does not mention it.
  • Not caused by this PR: on main, transitions to some state combinations also fail Close here: UAV together with read states (0x8c8), and bits 0x4000, 0x8000, 0x10000-0x400000. I don't know if the title ever asks for these.

No game data used; not run in the game.

**@⁠adrianmjim** on GitHub · 2026-11-25 17:23 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/43#issuecomment-7169442600) Tried on an RX 7900 XT (RDNA3, driver 32.0.32029.2010), Windows 11 build 26300, without the debug layer (only `Close()`'s HRESULT is checked). I used a test that records barriers the way the title does, through the list's `barrier` entry point, on host textures that lack a use the console allows. **What fails on `main`** (Close returns `0x80070057`), so this is not NVIDIA-only: - a UAV barrier naming a texture whose host copy has no `ALLOW_UNORDERED_ACCESS` (a depth texture with console UAV; BGRX8 also loses UAV on this card); - a UAV barrier with the console's split flags (`BEGIN_ONLY` / `END_ONLY`), on a texture or global; - an **aliasing** barrier with `BEGIN_ONLY`. Transitions, split transitions, and UAV/aliasing barriers without flags all close. **With this PR** every UAV case closes, but the aliasing case still fails: the kind-1 arm (`list.rs:521` on `01aadd1`) passes the console's flags through with `..*b`. One line fixes it, since the host splits only transitions: ```diff 1 => Some(Barrier { + flags: 0, first: if b.first.is_null() { ``` With #43 and that line on `71652a2`, `cargo test -p victory-gpu --lib` gives 112 passed, 0 failed, 4 ignored here. **The kind-0 change makes no difference in the real path,** as far as I can tell (checked at `667389f`; `a3788be` moves it into `transition_barrier_for` without changing it). `HostList::transition` (`host.rs:2013` on `01aadd1`) already runs `wanted` through `legal_state` before it stores or compares it, and it returns `None` when the state does not change. So `before` is always a state that was legalised earlier, and the new `before == after` check can never fire. `legal_for` only clears bits, so applying it twice gives the same value. The code is the same at `4cbe9d7`, the tree used in #13. The new test calls `transition_barrier_for` directly with raw `before` states such as `UAV | DEPTH_WRITE`, but `host_barrier` only ever passes the `before` that `transition` returns, which is already legal. So the black-to-visible change reported in #13 on the RTX 4060 Ti probably comes from something else in that run (a fresh cache, another difference), which may be worth finding. A more likely trigger on NVIDIA is the UAV case above: `resource::host_texture` drops UAV from formats the host refuses (`resource.rs:1310`, BGRA8 on NVIDIA). WARP and this AMD card keep it, which would fit "WARP passes". That part is a guess; I have no NVIDIA card. Two smaller notes: - `clear_rtv` through `ensure_state` also calls `resource::note_written` (`list.rs:598`), so a clear now moves the texture's written clock. That is probably right, but the description does not mention it. - Not caused by this PR: on `main`, transitions to some state combinations also fail Close here: UAV together with read states (`0x8c8`), and bits `0x4000`, `0x8000`, `0x10000`-`0x400000`. I don't know if the title ever asks for these. No game data used; not run in the game.
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 14:57 UTC · original
On crates/victory-gpu/src/list.rs line 532 (outdated):

@@ -502,12 +529,17 @@ fn host_barrier(list: &crate::host::HostList, b: &Barrier) -> Option<Barrier> {
             // (`HostList::transition`); subresources are not told apart.
             let wanted = crate::host::texture_state(b.last as u32);
             let (texture, before) = list.transition(b.first, wanted)?;
+            let before = crate::host::legal_state(texture, before);

Could a regression also cover the transition branch where legal_state makes the before and requested states equal, and verify that no barrier is emitted? The new test covers the UAV fallback, but not this separate transition/no-op behavior. AI-assisted review.

**@⁠gut0to** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/43#discussion_r4696741958) On `crates/victory-gpu/src/list.rs` line 532 (outdated): ```diff @@ -502,12 +529,17 @@ fn host_barrier(list: &crate::host::HostList, b: &Barrier) -> Option<Barrier> { // (`HostList::transition`); subresources are not told apart. let wanted = crate::host::texture_state(b.last as u32); let (texture, before) = list.transition(b.first, wanted)?; + let before = crate::host::legal_state(texture, before); ``` Could a regression also cover the transition branch where legal_state makes the before and requested states equal, and verify that no barrier is emitted? The new test covers the UAV fallback, but not this separate transition/no-op behavior. AI-assisted review.
Author
Owner

@⁠gut0to on GitHub · 2026-11-25 14:57 UTC · original · reviewed

AI-assisted review: I checked the new transition sanitization path and the tests added in this diff.

**@⁠gut0to** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/43#pullrequestreview-6059989921) · **reviewed** AI-assisted review: I checked the new transition sanitization path and the tests added in this diff.
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/43/head:github-bot/gh-43'
git switch 'github-bot/gh-43'

Merge

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