gpu: make texture states D3D12 refuses legal before they reach a barrier (0x80070057) #3487

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

@⁠CubeB on GitHub · 2026-11-29 23:50 UTC · original
CubeB:close/state-sanitiser → main · +157 −3 · 1 files · 1 commits · open

Branch: CubeB:close/state-sanitiser (one commit on main at 41adb551).

Problem

One invalid command makes ID3D12GraphicsCommandList::Close return 0x80070057 for the whole host list:
"a host command list did not close: a command recorded into it was invalid". D3D12 does not say which command.
In #2914 the debug layer named one (CopyTextureRegion, BC7_TYPELESS to BC6H_TYPELESS; #3043 addresses it), but
that is one of several commands that fail the same way.

To find the others we measured them: one command recorded into a fresh list, then Close. 278 cases gave the
same answer on an RTX 5070 Ti and on WARP; the set later grew to 466 cases on WARP (263 refused), kept as a test
in the companion branch close/guard-stack. Among the refused commands are transitions to texture states the
console accepts and the PC does not:

  • a write state mixed with any other state: COPY_DEST|PIXEL_SHADER_RESOURCE,
    UNORDERED_ACCESS|PIXEL_SHADER_RESOURCE, RENDER_TARGET|PIXEL_SHADER_RESOURCE,
    RENDER_TARGET|UNORDERED_ACCESS, DEPTH_WRITE|DEPTH_READ, DEPTH_WRITE|PIXEL_SHADER_RESOURCE,
    RESOLVE_DEST|COPY_DEST, RESOLVE_DEST|PIXEL_SHADER_RESOURCE;
  • on a texture, the bits 0x4000, 0x8000 and 0x10000 to 0x400000; bit 0x800000 passes only alone.

texture_state() already removes the buffer-only bits and the console's bits from 25 up, and legal_for() the
states a host texture's flags forbid. Nothing removed the cases above. The title's after-state reaches barriers
and texture creation through these two functions.

Whether the title ever sends such a state is not known; the log line below answers that in a play log.

What the commit does

legal_for() (crates/victory-gpu/src/host.rs) now ends in sane_state():

  • the state is masked to the eleven texture states D3D12 knows (0x01003CFC);
  • a mix keeps its lowest write state (render target, unordered access, depth write, copy destination, resolve
    destination), after the flags have removed what the texture cannot be in.

Which state to keep from a mix is a choice, not a measurement.

Switch

VICTORY_STATE_SANITISE: on by default; =0 passes states on as before.

Log

state sanitiser: a texture state D3D12 refuses was made legal (Close would fail with 0x80070057) with asked,
made, what (bits that are no texture state / a write state mixed with another) and count. First 16 of
each kind, then every 4096th.

Cost

A state that is already legal takes the old path plus two compares and returns. The rest is #[cold]. No
allocation, no lock. Not measured in ns separately.

Tests

New module host::state_tests, five tests, no GPU needed:

  • every_state_comes_out_as_one_close_takes: all 2^16 low-bit combinations x 5 sets of high bits x 7 flag sets;
    the result must satisfy the measured rule.
  • a_write_state_stands_alone, bits_that_are_no_texture_state_go, states_d3d12_takes_stay_as_they_are,
    a_forbidden_write_state_leaves_the_read_states pin the measured cases.

Adapted from the original commit: the exhaustive test compared against crate::checked::judge (the close guard,
in close/guard-stack). That module is not in main, so here the test carries the measured texture-state rule
itself as close_takes(). Nothing outside the test module and two comments differs.

On this branch (Windows, stable toolchain):

  • cargo build --release --locked -p victory: builds.
  • cargo test -p victory-gpu --lib -- --test-threads=1: 926 passed, 1 failed, 60 ignored. The failure is
    shader_cache::tests::every_switch_of_the_translator_is_in_the_key ("VICTORY_SCALAR_SPLITS is not read by the
    translator any more"); it fails the same way on main at 41adb551 without this commit.
  • cargo xtask policy: only the existing crates/victory-loader/src/heap_sites/frame_users.rs hit, as on main.

Not yet play-tested

Nothing here has been run against the game. The rules come from the one-command measurements and the tests.

Relation to the other branch

Independent of #3043 and of close/guard-stack; either can land first. With both, the guard no longer has to
drop a transition to one of these states (a dropped transition leaves the tracked state ahead of the real one).

🤖 Generated with Claude Code

**@⁠CubeB** on GitHub · 2026-11-29 23:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3487) `CubeB:close/state-sanitiser` → `main` · +157 −3 · 1 files · 1 commits · open Branch: `CubeB:close/state-sanitiser` (one commit on `main` at `41adb551`). ## Problem One invalid command makes `ID3D12GraphicsCommandList::Close` return `0x80070057` for the whole host list: "a host command list did not close: a command recorded into it was invalid". D3D12 does not say which command. In #2914 the debug layer named one (`CopyTextureRegion`, BC7_TYPELESS to BC6H_TYPELESS; #3043 addresses it), but that is one of several commands that fail the same way. To find the others we measured them: one command recorded into a fresh list, then `Close`. 278 cases gave the same answer on an RTX 5070 Ti and on WARP; the set later grew to 466 cases on WARP (263 refused), kept as a test in the companion branch `close/guard-stack`. Among the refused commands are transitions to texture states the console accepts and the PC does not: - a write state mixed with any other state: `COPY_DEST|PIXEL_SHADER_RESOURCE`, `UNORDERED_ACCESS|PIXEL_SHADER_RESOURCE`, `RENDER_TARGET|PIXEL_SHADER_RESOURCE`, `RENDER_TARGET|UNORDERED_ACCESS`, `DEPTH_WRITE|DEPTH_READ`, `DEPTH_WRITE|PIXEL_SHADER_RESOURCE`, `RESOLVE_DEST|COPY_DEST`, `RESOLVE_DEST|PIXEL_SHADER_RESOURCE`; - on a texture, the bits 0x4000, 0x8000 and 0x10000 to 0x400000; bit 0x800000 passes only alone. `texture_state()` already removes the buffer-only bits and the console's bits from 25 up, and `legal_for()` the states a host texture's flags forbid. Nothing removed the cases above. The title's after-state reaches barriers and texture creation through these two functions. Whether the title ever sends such a state is not known; the log line below answers that in a play log. ## What the commit does `legal_for()` (`crates/victory-gpu/src/host.rs`) now ends in `sane_state()`: - the state is masked to the eleven texture states D3D12 knows (`0x01003CFC`); - a mix keeps its lowest write state (render target, unordered access, depth write, copy destination, resolve destination), after the flags have removed what the texture cannot be in. Which state to keep from a mix is a choice, not a measurement. ## Switch `VICTORY_STATE_SANITISE`: on by default; `=0` passes states on as before. ## Log `state sanitiser: a texture state D3D12 refuses was made legal (Close would fail with 0x80070057)` with `asked`, `made`, `what` (`bits that are no texture state` / `a write state mixed with another`) and `count`. First 16 of each kind, then every 4096th. ## Cost A state that is already legal takes the old path plus two compares and returns. The rest is `#[cold]`. No allocation, no lock. Not measured in ns separately. ## Tests New module `host::state_tests`, five tests, no GPU needed: - `every_state_comes_out_as_one_close_takes`: all 2^16 low-bit combinations x 5 sets of high bits x 7 flag sets; the result must satisfy the measured rule. - `a_write_state_stands_alone`, `bits_that_are_no_texture_state_go`, `states_d3d12_takes_stay_as_they_are`, `a_forbidden_write_state_leaves_the_read_states` pin the measured cases. Adapted from the original commit: the exhaustive test compared against `crate::checked::judge` (the close guard, in `close/guard-stack`). That module is not in `main`, so here the test carries the measured texture-state rule itself as `close_takes()`. Nothing outside the test module and two comments differs. On this branch (Windows, stable toolchain): - `cargo build --release --locked -p victory`: builds. - `cargo test -p victory-gpu --lib -- --test-threads=1`: 926 passed, 1 failed, 60 ignored. The failure is `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` ("VICTORY_SCALAR_SPLITS is not read by the translator any more"); it fails the same way on `main` at `41adb551` without this commit. - `cargo xtask policy`: only the existing `crates/victory-loader/src/heap_sites/frame_users.rs` hit, as on `main`. ## Not yet play-tested Nothing here has been run against the game. The rules come from the one-command measurements and the tests. ## Relation to the other branch Independent of #3043 and of `close/guard-stack`; either can land first. With both, the guard no longer has to drop a transition to one of these states (a dropped transition leaves the tracked state ahead of the real one). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The console lets the title name texture states the PC refuses, and one
transition to such a state makes Close fail for the whole host list
(0x80070057, "a host command list did not close"). texture_state()
already took the buffer-only bits and the console's bits from 25 up, and
legal_for() the states a host texture's flags forbid; nothing took a
write state mixed with another state, nor the remaining bits that are no
texture state. The title's after-state reaches barriers and texture
creation through exactly these two functions.

Measured (one transition into a fresh list, RTX 5070 Ti and WARP alike,
and asked of WARP again by crate::checked's oracle test): Close refuses
COPY_DEST|PSR, UAV|PSR, RT|PSR, RT|UAV, DEPTH_WRITE|DEPTH_READ,
DEPTH_WRITE|PSR, RESOLVE_DEST|COPY_DEST, RESOLVE_DEST|PSR, and on a
texture the bits 0x4000, 0x8000 and 0x10000 to 0x400000; bit 0x800000
passes only alone.

legal_for() now ends in sane_state(): the state is masked to the eleven
texture states D3D12 knows (0x01003CFC), and a mix keeps its lowest
write state (render target, unordered access, depth write, copy
destination, resolve destination), after the flags have taken what the
texture cannot be in. Legal states take the old path plus two compares.
What was changed is counted by kind and logged ("state sanitiser: a
texture state D3D12 refuses was made legal", first 16 of each kind, then
every 4096th, with the state asked and made).

Switch: VICTORY_STATE_SANITISE, on by default; =0 passes states on as
before (the close guard then drops the transition instead).

Tests: every_state_comes_out_as_one_close_takes runs all 2^16 low-bit
combinations with five sets of high bits on seven kinds of texture
through the guard's judge; four tests pin the measured cases.
victory-gpu lib: 946 passed.

Adapted for upstream main: every_state_comes_out_as_one_close_takes held
the result against crate::checked::judge, which is not in this tree (it
comes with the close guard). The test now carries the measured texture
state rule itself as close_takes(); two comments no longer name
crate::checked. No change outside the test module and comments.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JzsiBtxAuHxjYfCpTzVV3h
(cherry picked from commit 4893b97deb3263b04088ed3343f90c4ec579917e)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 23:54:58 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-30 05:14 UTC · original · approved these changes

Tested locally merged onto main (41adb551).

  • Merge: Clean merge in crates/victory-gpu/src/host.rs.
  • Tests (RTX 5090):
    • All new barrier-state legalization tests passed on RTX 5090 (a_write_state_stands_alone, every_state_comes_out_as_one_close_takes, a_forbidden_write_state_leaves_the_read_states).
    • cargo test -p victory-gpu --lib host::tests:: and list:: (20 passed; 0 failed) passed.
  • 0 new warnings.

Strong, hardware-verified defense against E_INVALIDARG (0x80070057) command-list Close() failures from illegal D3D12 texture barrier state combinations. LGTM.

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

**@⁠Dukestar69** on GitHub · 2026-11-30 05:14 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3487#pullrequestreview-6107179067) · **approved these changes** Tested locally merged onto `main` (`41adb551`). - **Merge**: Clean merge in `crates/victory-gpu/src/host.rs`. - **Tests (RTX 5090)**: - All new barrier-state legalization tests passed on RTX 5090 (`a_write_state_stands_alone`, `every_state_comes_out_as_one_close_takes`, `a_forbidden_write_state_leaves_the_read_states`). - `cargo test -p victory-gpu --lib host::tests::` and `list::` (`20 passed; 0 failed`) passed. - 0 new warnings. Strong, hardware-verified defense against `E_INVALIDARG (0x80070057)` command-list `Close()` failures from illegal D3D12 texture barrier state combinations. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠dyshay on GitHub · 2026-11-30 05:49 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-30 05:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3487#issuecomment-7270047356) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`, and the CPU tests of the touched crates pass. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.
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/3487/head:github-bot/gh-3487'
git switch 'github-bot/gh-3487'

Merge

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