GPU: restrict texture resource states to legal direct-queue write and read combinations #3140

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

@⁠fuzeofficlal on GitHub · 2026-11-26 09:57 UTC · original
fuzeofficlal:fix/gpu-legal-texture-states → main · +353 −8 · 1 files · 1 commits · open

Summary

  • Restrict host::texture_state to the ten D3D12 direct-queue texture read and write states (RENDER_TARGET, UNORDERED_ACCESS, DEPTH_WRITE, COPY_DEST, RESOLVE_DEST, DEPTH_READ, NON_PIXEL_SHADER_RESOURCE, PIXEL_SHADER_RESOURCE, COPY_SOURCE, RESOLVE_SOURCE), dropping reserved bits (0x4000/0x8000/0x100000), video-queue bits (0x10000..=0x800000), RAYTRACING_ACCELERATION_STRUCTURE (0x400000), and SHADING_RATE_SOURCE (0x01000000) alongside buffer-only and console-private bits.
  • Update host::legal_for to sanitize via texture_state, strip resource-flag-forbidden bits first (so a forbidden write bit combined with a valid read bit preserves the read state), and enforce D3D12's mutual-exclusion rule for write states by collapsing any combined write+read or multi-write mask to a single write state while preserving valid read-only combinations.

Why

Previously, texture_state only masked out 0x1 | 0x2 | 0x100 | 0x200 from pc_state, and legal_for did not enforce write-state exclusivity. Passing combined write+read or multi-write states (such as DEPTH_WRITE | DEPTH_READ or DEPTH_WRITE | PIXEL_SHADER_RESOURCE), reserved bits, video-queue bits, or RAYTRACING_ACCELERATION_STRUCTURE to host texture creation (CreateCommittedResource / CreatePlacedResource) or direct-queue ResourceBarrier calls triggers D3D12 Debug Layer errors #522, #526, and #537, failing host texture creation or causing ID3D12GraphicsCommandList::Close to fail with E_INVALIDARG (0x80070057).

Verification

  • Before fix on 63bcca43 with VICTORY_D3D12_DEBUG=1 (RTX 5090 & WARP):
    • resource::create_committed on depth textures with combined write+read, multi-write, and reserved initial states failed to create a host texture (D3D12 errors #526 and #522).
    • Recording combined write+read, multi-write, reserved, video-queue, and raytracing states through ResourceBarrier produced D3D12 errors #526, #522, and #537 and failed ID3D12GraphicsCommandList::Close() with E_INVALIDARG.
  • After fix (8496edfc):
    • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- legal_for_strips_unsupported_bits_and_enforces_exclusive_write_states initial_and_barrier_texture_states_are_accepted_by_d3d12: 2 passed, 0 failed on both RTX 5090 and WARP (0 D3D12 Debug Layer errors/warnings).
    • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked: 248 passed, 0 failed, 1 ignored.
    • cargo test -p victory-gpu --locked -- legal_for_strips_unsupported_bits_and_enforces_exclusive_write_states initial_and_barrier_texture_states_are_accepted_by_d3d12: 2 passed, 0 failed.
    • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: clean.
    • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/3140) `fuzeofficlal:fix/gpu-legal-texture-states` → `main` · +353 −8 · 1 files · 1 commits · open ## Summary - Restrict `host::texture_state` to the ten D3D12 direct-queue texture read and write states (`RENDER_TARGET`, `UNORDERED_ACCESS`, `DEPTH_WRITE`, `COPY_DEST`, `RESOLVE_DEST`, `DEPTH_READ`, `NON_PIXEL_SHADER_RESOURCE`, `PIXEL_SHADER_RESOURCE`, `COPY_SOURCE`, `RESOLVE_SOURCE`), dropping reserved bits (`0x4000`/`0x8000`/`0x100000`), video-queue bits (`0x10000..=0x800000`), `RAYTRACING_ACCELERATION_STRUCTURE` (`0x400000`), and `SHADING_RATE_SOURCE` (`0x01000000`) alongside buffer-only and console-private bits. - Update `host::legal_for` to sanitize via `texture_state`, strip resource-flag-forbidden bits first (so a forbidden write bit combined with a valid read bit preserves the read state), and enforce D3D12's mutual-exclusion rule for write states by collapsing any combined write+read or multi-write mask to a single write state while preserving valid read-only combinations. ## Why Previously, `texture_state` only masked out `0x1 | 0x2 | 0x100 | 0x200` from `pc_state`, and `legal_for` did not enforce write-state exclusivity. Passing combined write+read or multi-write states (such as `DEPTH_WRITE | DEPTH_READ` or `DEPTH_WRITE | PIXEL_SHADER_RESOURCE`), reserved bits, video-queue bits, or `RAYTRACING_ACCELERATION_STRUCTURE` to host texture creation (`CreateCommittedResource` / `CreatePlacedResource`) or direct-queue `ResourceBarrier` calls triggers D3D12 Debug Layer errors `#522`, `#526`, and `#537`, failing host texture creation or causing `ID3D12GraphicsCommandList::Close` to fail with `E_INVALIDARG` (`0x80070057`). ## Verification - Before fix on `63bcca43` with `VICTORY_D3D12_DEBUG=1` (RTX 5090 & WARP): - `resource::create_committed` on depth textures with combined write+read, multi-write, and reserved initial states failed to create a host texture (`D3D12` errors `#526` and `#522`). - Recording combined write+read, multi-write, reserved, video-queue, and raytracing states through `ResourceBarrier` produced `D3D12` errors `#526`, `#522`, and `#537` and failed `ID3D12GraphicsCommandList::Close()` with `E_INVALIDARG`. - After fix (`8496edfc`): - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- legal_for_strips_unsupported_bits_and_enforces_exclusive_write_states initial_and_barrier_texture_states_are_accepted_by_d3d12`: 2 passed, 0 failed on both RTX 5090 and WARP (0 D3D12 Debug Layer errors/warnings). - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked`: 248 passed, 0 failed, 1 ignored. - `cargo test -p victory-gpu --locked -- legal_for_strips_unsupported_bits_and_enforces_exclusive_write_states initial_and_barrier_texture_states_are_accepted_by_d3d12`: 2 passed, 0 failed. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and `--all-features`: clean. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed.
texture_state previously masked only four buffer-only bits out of pc_state, letting reserved bits (0x4000/0x8000/0x100000), video-queue bits (0x10000..=0x800000), raytracing acceleration-structure bits (0x400000), and shading-rate bits (0x01000000) reach host CreateCommittedResource, CreatePlacedResource, and direct-queue ResourceBarrier calls. legal_for also preserved combined write+read and multi-write state masks (such as DEPTH_WRITE | DEPTH_READ or DEPTH_WRITE | PIXEL_SHADER_RESOURCE), which D3D12 rejects with errors #522, #526, and #537, failing texture creation or failing ID3D12GraphicsCommandList::Close with E_INVALIDARG.

Restrict texture_state to the ten direct-queue texture read and write states, and update legal_for to sanitize through texture_state, strip flag-forbidden bits first, and collapse any remaining write-state combination to a single exclusive write state while preserving valid read-only combinations.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:23 +00:00
Author
Owner

@⁠smaxxey on GitHub · 2026-11-26 10:13 UTC · original

Ran this on an RTX 4060 Laptop GPU (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head 8496edf merged locally onto main 63bcca4.

  • Both new tests pass, initial_and_barrier_texture_states_are_accepted_by_d3d12 on the hardware device: Close() succeeds and the final states come out 0x800 and 0x2080.
  • cargo test -p victory-gpu --lib --locked: 231 passed, 2 failed, same as main 63bcca4 on this card: only the two NVIDIA failures of #1835 (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views), nothing new.

One limit of this run, and of any plain test run: the msgs.is_empty() check sees no messages by construction. Host turns the debug layer on only in a diagnostics build with VICTORY_D3D12_DEBUG, and this machine has no debug layer installed (no Graphics Tools). So what this run confirms is the close and the states, not the absence of debug-layer errors.

Tested with Claude Code's help.

**@⁠smaxxey** on GitHub · 2026-11-26 10:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3140#issuecomment-7189071381) Ran this on an **RTX 4060 Laptop GPU** (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head `8496edf` merged locally onto `main` 63bcca4. - Both new tests pass, `initial_and_barrier_texture_states_are_accepted_by_d3d12` on the hardware device: `Close()` succeeds and the final states come out `0x800` and `0x2080`. - `cargo test -p victory-gpu --lib --locked`: 231 passed, 2 failed, same as `main` 63bcca4 on this card: only the two NVIDIA failures of #1835 (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`), nothing new. One limit of this run, and of any plain test run: the `msgs.is_empty()` check sees no messages by construction. `Host` turns the debug layer on only in a `diagnostics` build with `VICTORY_D3D12_DEBUG`, and this machine has no debug layer installed (no Graphics Tools). So what this run confirms is the close and the states, not the absence of debug-layer errors. Tested with Claude Code's help.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 12:29 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: passed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed; list::: 4/4 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly restricts texture resource states to legal direct-queue write and read combinations.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 12:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3140#pullrequestreview-6074134032) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: passed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed; `list::`: 4/4 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly restricts texture resource states to legal direct-queue write and read combinations. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/3140/head:github-bot/gh-3140'
git switch 'github-bot/gh-3140'

Merge

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