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

Open
CubeB wants to merge 1 commit from upstream-pr/3487 into main
CubeB commented 2026-11-29 23:50:57 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CubeB on 2026-11-29T23:50:57Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5556494436 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3487). Originally posted by [CubeB](https://github.com/CubeB) on 2026-11-29T23:50:57Z. --- 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)
Dukestar69 commented 2026-11-30 05:14:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-30T05:14:41Z.

Review: APPROVED


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6107179067 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3487#pullrequestreview-6107179067). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-30T05:14:41Z. **Review:** APPROVED --- 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).
dyshay commented 2026-11-30 05:49:57 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-30T05:49:57Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7270047356 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3487#issuecomment-7270047356). Originally posted by [dyshay](https://github.com/dyshay) on 2026-11-30T05:49:57Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3487:upstream-pr/3487'
git switch 'upstream-pr/3487'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3487'
git switch 'upstream-pr/3487'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3487'
git switch 'upstream-pr/3487'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3487'
git switch 'main'
git merge --squash 'upstream-pr/3487'
git switch 'main'
git merge --ff-only 'upstream-pr/3487'
git switch 'main'
git merge 'upstream-pr/3487'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!3487
No description provided.