GPU: restrict texture resource states to legal direct-queue write and read combinations #3140
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3140
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3140"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@fuzeofficlal on GitHub · 2026-11-26 09:57 UTC · original
fuzeofficlal:fix/gpu-legal-texture-states→main· +353 −8 · 1 files · 1 commits · openSummary
host::texture_stateto 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), andSHADING_RATE_SOURCE(0x01000000) alongside buffer-only and console-private bits.host::legal_forto sanitize viatexture_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_stateonly masked out0x1 | 0x2 | 0x100 | 0x200frompc_state, andlegal_fordid not enforce write-state exclusivity. Passing combined write+read or multi-write states (such asDEPTH_WRITE | DEPTH_READorDEPTH_WRITE | PIXEL_SHADER_RESOURCE), reserved bits, video-queue bits, orRAYTRACING_ACCELERATION_STRUCTUREto host texture creation (CreateCommittedResource/CreatePlacedResource) or direct-queueResourceBarriercalls triggers D3D12 Debug Layer errors#522,#526, and#537, failing host texture creation or causingID3D12GraphicsCommandList::Closeto fail withE_INVALIDARG(0x80070057).Verification
63bcca43withVICTORY_D3D12_DEBUG=1(RTX 5090 & WARP):resource::create_committedon depth textures with combined write+read, multi-write, and reserved initial states failed to create a host texture (D3D12errors#526and#522).ResourceBarrierproducedD3D12errors#526,#522, and#537and failedID3D12GraphicsCommandList::Close()withE_INVALIDARG.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 warningsand--all-features: clean.cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.@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
8496edfmerged locally ontomain63bcca4.initial_and_barrier_texture_states_are_accepted_by_d3d12on the hardware device:Close()succeeds and the final states come out0x800and0x2080.cargo test -p victory-gpu --lib --locked: 231 passed, 2 failed, same asmain63bcca4on 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.Hostturns the debug layer on only in adiagnosticsbuild withVICTORY_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.
@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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.