You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
D3D12.X: sanitize PC resource flag invariants in pc_resource_desc - #3414
pc_resource_desc in crates/xcl/src/hle/d3d12x/device_x.rs converts console D3D12_RESOURCE_DESC structures into PC descriptions, forcing buffer layouts to D3D12_TEXTURE_LAYOUT_ROW_MAJOR, texture layouts to D3D12_TEXTURE_LAYOUT_UNKNOWN, and masking flags to the lower byte (flags & 0xFF). Previously it only stripped ALLOW_UNORDERED_ACCESS on depth/MSAA/unsupported-format textures, leaving other flag combinations that PC D3D12 rejects with E_INVALIDARG:
Buffers (D3D12_RESOURCE_DIMENSION_BUFFER) carrying ALLOW_RENDER_TARGET (0x01), ALLOW_DEPTH_STENCIL (0x02), DENY_SHADER_RESOURCE (0x08), or ALLOW_SIMULTANEOUS_ACCESS (0x20). These bits are stripped before depth-UAV stripping so a buffer with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS still keeps ALLOW_UNORDERED_ACCESS.
Non-buffer textures combining ALLOW_DEPTH_STENCIL (0x02) with ALLOW_RENDER_TARGET (0x01) or ALLOW_SIMULTANEOUS_ACCESS (0x20), setting DENY_SHADER_RESOURCE (0x08) without ALLOW_DEPTH_STENCIL, setting ALLOW_SIMULTANEOUS_ACCESS (0x20) on multisampled (SampleDesc.Count > 1) textures, or setting ALLOW_CROSS_ADAPTER (0x10) once texture layout is forced to D3D12_TEXTURE_LAYOUT_UNKNOWN.
Valid PC combinations such as ALLOW_DEPTH_STENCIL | DENY_SHADER_RESOURCE on textures and ALLOW_SIMULTANEOUS_ACCESS on single-sample non-depth textures are preserved unchanged.
This change also updates console_types_and_descs_become_pc_ones to expect buffer-invalid ALLOW_SIMULTANEOUS_ACCESS (0x20) to be stripped from its buffer test descriptor (0x14 instead of 0x34), and adds pc_resource_desc_sanitizes_invalid_pc_flag_combinations covering unit assertions and real D3D12 CreateCommittedResource verification (rejecting all 7 unsanitized descriptors and accepting all 9 sanitized descriptors).
Tested
Targeted unit + D3D12 CreateCommittedResource verification (cargo test -p xcl --lib -- hle::d3d12x::device_x::tests::):
Before fix: pc_resource_desc_sanitizes_invalid_pc_flag_combinations fails because pc_resource_desc leaves DENY_SHADER_RESOURCE set on an ALLOW_RENDER_TARGET texture (0x09 instead of 0x01), and CreateCommittedResource rejects all 7 unsanitized invalid flag combinations with E_INVALIDARG.
After fix: 21 passed, 0 failed, including pc_resource_desc_sanitizes_invalid_pc_flag_combinations and console_types_and_descs_become_pc_ones.
Full workspace test suite (cargo test --workspace --no-fail-fast -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::, RTX 5070 Ti + DXC 1.9): 41 binaries, 2712 passed, 4 failed, 49 ignored, 9 filtered; 27 SKIPPED (22 no wave64, 3 refused #1426, 2 no heap windows). All 4 failures are pre-existing geometry test failures on main (3b6a91ed, tracked in Tests: fix 4 geometry tests broken on main by split-ES safe-barrier and no-store epilogue merges #3411): gpu::dxil::geometry_tests::gpu_geometry_msg_gs_done_records, gpu::dxil::geometry_tests::msg_gs_done_emits_in_dxil, gpu::dxil::lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits, and gpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected.
Used an AI coding assistant to audit pc_resource_desc flag handling, author the minimal invariant fix and synthetic unit/D3D12 tests, and run local verification.
merge-check
base: d0832e6
head: 62de21c
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (device_x.rs, ~25 lines of runtime code plus a test). Every flag combination it strips is one the PC rejects, so only descriptions that already failed to be created on main change. Findings: (1) the buffer case the description highlights still fails: pc_resource_desc now keeps UNORDERED_ACCESS on a buffer flagged depth-stencil + UAV, but create_placed_resource_x takes its initial state from the console flags (pc_initial_state(x[0x30..0x34], state), ~1248 -> ~905). So a buffer created in UNORDERED_ACCESS is still given DEPTH_WRITE, which the PC refuses for a buffer. The new test creates everything in COMMON and misses it; passing the PC flags (as pc_initial_state_for_desc does) would fix it. (2) The new test returns silently when WARP or the device is missing (~2126-2128) instead of calling skip_test like the existing test (~1851). (3) The test's transmute_copy of a D3D12_RESOURCE_DESC into [u8; 0x38] reads its padding bytes (~2085); a zeroed array filled field by field, as the other tests do, avoids it. (4) Stripping ALLOW_RENDER_TARGET from a depth-stencil texture leaves nothing guarding a later RTV of it (a risk from reading; on main that resource wasn't created at all). (5) It will conflict with #3141 (the final flag mask of the same function) and #3418 (same test insertion point). Fine: each strip matches a D3D12 rule (buffers can't be RT/DS/deny-SRV/simultaneous; DS excludes RT and simultaneous; deny-SRV needs DS; no simultaneous with MSAA; cross-adapter needs row-major), depth-UAV tracking excludes buffers, the test fails on main (0x09 vs 0x01), and the 0x34 -> 0x14 change to the existing test is right.
performance: 60 s smoke of a retail title, main d0832e6 vs this merge (b1818e82): 1516 -> 1654 frames shown (109 %; last presents per 2 s: 60 61 60), peak commit 18133 -> 17151 MB, 0 device removals, 0 crashes.
verdict: not yet: the buffer case the PR describes still fails (initial state taken from the console flags, finding 1), and the new test returns without skip_test
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
area:d3d12D3D12.X runtime, command lists, resources, sparse memorygpu:bothCode affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is in it
pc_resource_descincrates/xcl/src/hle/d3d12x/device_x.rsconverts consoleD3D12_RESOURCE_DESCstructures into PC descriptions, forcing buffer layouts toD3D12_TEXTURE_LAYOUT_ROW_MAJOR, texture layouts toD3D12_TEXTURE_LAYOUT_UNKNOWN, and masking flags to the lower byte (flags & 0xFF). Previously it only strippedALLOW_UNORDERED_ACCESSon depth/MSAA/unsupported-format textures, leaving other flag combinations that PC D3D12 rejects withE_INVALIDARG:D3D12_RESOURCE_DIMENSION_BUFFER) carryingALLOW_RENDER_TARGET(0x01),ALLOW_DEPTH_STENCIL(0x02),DENY_SHADER_RESOURCE(0x08), orALLOW_SIMULTANEOUS_ACCESS(0x20). These bits are stripped before depth-UAV stripping so a buffer withALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESSstill keepsALLOW_UNORDERED_ACCESS.ALLOW_DEPTH_STENCIL(0x02) withALLOW_RENDER_TARGET(0x01) orALLOW_SIMULTANEOUS_ACCESS(0x20), settingDENY_SHADER_RESOURCE(0x08) withoutALLOW_DEPTH_STENCIL, settingALLOW_SIMULTANEOUS_ACCESS(0x20) on multisampled (SampleDesc.Count > 1) textures, or settingALLOW_CROSS_ADAPTER(0x10) once texture layout is forced toD3D12_TEXTURE_LAYOUT_UNKNOWN.Valid PC combinations such as
ALLOW_DEPTH_STENCIL | DENY_SHADER_RESOURCEon textures andALLOW_SIMULTANEOUS_ACCESSon single-sample non-depth textures are preserved unchanged.This change also updates
console_types_and_descs_become_pc_onesto expect buffer-invalidALLOW_SIMULTANEOUS_ACCESS(0x20) to be stripped from its buffer test descriptor (0x14instead of0x34), and addspc_resource_desc_sanitizes_invalid_pc_flag_combinationscovering unit assertions and real D3D12CreateCommittedResourceverification (rejecting all 7 unsanitized descriptors and accepting all 9 sanitized descriptors).Tested
CreateCommittedResourceverification (cargo test -p xcl --lib -- hle::d3d12x::device_x::tests::):pc_resource_desc_sanitizes_invalid_pc_flag_combinationsfails becausepc_resource_descleavesDENY_SHADER_RESOURCEset on anALLOW_RENDER_TARGETtexture (0x09instead of0x01), andCreateCommittedResourcerejects all 7 unsanitized invalid flag combinations withE_INVALIDARG.21 passed, 0 failed, includingpc_resource_desc_sanitizes_invalid_pc_flag_combinationsandconsole_types_and_descs_become_pc_ones.cargo test --workspace --no-fail-fast -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::, RTX 5070 Ti + DXC 1.9):41 binaries, 2712 passed, 4 failed, 49 ignored, 9 filtered; 27 SKIPPED (22 no wave64, 3 refused #1426, 2 no heap windows). All 4 failures are pre-existing geometry test failures onmain(3b6a91ed, tracked in Tests: fix 4 geometry tests broken on main by split-ES safe-barrier and no-store epilogue merges #3411):gpu::dxil::geometry_tests::gpu_geometry_msg_gs_done_records,gpu::dxil::geometry_tests::msg_gs_done_emits_in_dxil,gpu::dxil::lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits, andgpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected.Regression run
Not tested
22wave64 tests skipped on RTX 5070 Ti).ea3b5e4dor paths requiringuma_driver::tests::kernel driver tests.0x40/0x80(left untouched here to avoid overlap with D3D12.X: the console's acceleration-structure resource flag becomes UAV, not a video flag #3141).AI use
Used an AI coding assistant to audit
pc_resource_descflag handling, author the minimal invariant fix and synthetic unit/D3D12 tests, and run local verification.