D3D12.X: sanitize reserved and placed resource descriptions and initial states #3291
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3291"
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?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T06:00:25Z.
Console
CreatePlacedResource(placed_in_heap_x/own_memory_if_larger_on_the_pc) andCreateReservedResource(1)incrates/xcl/src/hle/d3d12x/real.rsmissed parts of the PC description/state/clear sanitization already used byCreateCommittedResourceandCreatePlacedResourceX:placed_in_heap_xandown_memory_if_larger_on_the_pccalledpc_resource_desc(&x)instead ofpc_resource_desc_for_device(this, &x)andpc_initial_state(orig_flags, state)instead ofpc_initial_state_for_desc(orig_flags, pc_flags, state). Whenpc_resource_desc_for_devicestrippedD3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESSfrom a non-depth texture (for example an sRGB or unsupported-UAV format),D3D12_RESOURCE_STATE_UNORDERED_ACCESS(0x8) remained in the initial state, causing both the placed retry and the committed fallback to fail withE_INVALIDARG.dev_create_reserved_resourceanddev_create_reserved_resource1had no sanitization fallback when PC D3D12 refused a console format, console tile layout (> 3), console resource flag bits, console initial-state bits,ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, unsupported texture UAV flags, or promoted clear-value format.What is in it
crates/xcl/src/hle/d3d12x/real.rs:placed_in_heap_xandown_memory_if_larger_on_the_pcto usepc_resource_desc_for_device(this, &x)andpc_initial_state_for_desc(orig_flags, pc_flags, state as u32)so stripped UAV flags also dropUNORDERED_ACCESSfrom the initial state and per-device UAV format checks are honored.pc_reserved_desc_for_device(preserving PC layouts<= 3so invalid PC layouts likeROW_MAJORare still rejected like the host driver, while mapping console tile layouts> 3toD3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE) andcreate_reserved_with_fallbackfordev_create_reserved_resourceanddev_create_reserved_resource1, retrying only when sanitization changed the description, initial state, or clear value, and callingdepth_uav::note_createdon texture fallback success.reserved_placed_sanitize_testscovering consoleCreateReservedResource(D32+UAV depth target with console flags/layout/state,B5G6R5RT+UAV with promoted clear format),CreateReservedResource1(sRGB+UAV inUNORDERED_ACCESSstate), andCreatePlacedResource(dev_create_placed_resource_x) with sRGB+UAV inUNORDERED_ACCESSstate.Tested
32.0.16.1074),rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9 (1.9.2609).reserved_placed_sanitize_testsfailed on WARP with0x80070057(E_INVALIDARG).cargo test -p xcl --lib -- hle::d3d12x::real::reserved_placed_sanitize_tests::): 2 passed, 0 failed (0.09s, D3D12 debug layer enabled).cargo test -p xcl --test d3d12_create_reserved_resource): 3 passed, 0 failed (0.30s), includingpc_reserved_resources_match_host_driver(invalid_tex2d_row_majorstill rejected with0x80070057).cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::withXCL_DXC_DIRset to DXC 1.9): 2601 passed, 0 failed, 49 ignored, 9 filtered (532.3s).SKIPPEDlines in workspace run (26 total): 21no wave64(RTX 5070 Ti is wave32), 3 wave32 per-lane#1426(V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32), 2no heap windows(defaultXCL_HEAP_WINDOWSoff).cargo build --release -p xcl -j 4) succeeded and passed the paired 150 s title smoke below.Regression run
main (
f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):PR (
37fc811b087ae6067493e8865613017c24add47e):Not tested
uma_driver::tests::andtest_title_runs_and_game_folder_is_untouched(filtered out of the workspace test run).CreateReservedResource1with a non-nullID3D12ProtectedResourceSession.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:57:16Z.
Merge-check run and written with Claude Code (Claude Opus 5.5): a test merge onto the base above, the full suite, and a 60 s
scripts/smoke.ps1run of a retail title against main on the same machine. The 4fuzz_validate_and_gpu_*failures happen on main on this machine too.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:12:38Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 4627The reserved fallback applies
pc_resource_desc's format promotions (85/86/115 -> 28, 116/117 -> 10, 118-120 -> 44), which change bytes per texel and therefore the 64 KB tile count and shape. Nothing in the UpdateTileMappings / GetResourceTiling hooks accounts for that. A reserved B5G6R5 RT|UAV texture (test case 2 here) becomes R8G8B8A8, with twice the tiles, but the title maps tiles computed for the console layout. Only part of the resource is backed, so unmapped regions read as zero and drop writes. Before, creation failed loudly; now it succeeds and the data is silently wrong.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:12:38Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 4640This hook is on every adopted PC device's vtable, so the fallback also rewrites PC-native descriptions that should be rejected. It strips DS|UAV and sRGB+UAV, masks flags to 0xFF and drops state bits. A PC or XCL-internal
CreateReservedResourcewith DS|UAV, or R8G8B8A8_UNORM_SRGB+UAV in UNORDERED_ACCESS, now gets S_OK and a resource without the UAV flag instead of E_INVALIDARG. A later CreateUnorderedAccessView on it is invalid, so the caller's bug is hidden. Only ROW_MAJOR is checked for parity.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:12:38Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 4624When the first call succeeds,
used_stateis the raw console state, console-only bits included (e.g. 0x100004). The fallback branch uses the sanitizedst, and the placed path masks with& PC_RESOURCE_STATES.reserved_3dthen handslut3d::createda value that isn't a PC state, and it's tracked and logged as one.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:12:38Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 4602pc_reserved_desc_for_devicekeeps texture layout 0 (UNKNOWN) as it is, but PC CreateReservedResource only accepts 64KB_UNDEFINED_SWIZZLE / 64KB_STANDARD_SWIZZLE for textures. A console reserved Texture2D with Layout=0 plus console flag bits fails, the retry still has layout 0, and it fails again, which is the case the fallback was meant to cover.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T21:12:38Z.
Review: COMMENTED
Review of
37fc811b: 5 finding(s). 4 are inline. These are on lines outside the diff:crates/xcl/src/hle/d3d12x/real.rs:4412:lut3d::createdstill getsstate & PC_RESOURCE_STATES, but the fallback in placed_in_heap_x / own_memory_if_larger_on_the_pc now creates the resource in the sanitizedst(0x8 dropped, DS|UAV becomes DEPTH_WRITE) or in COMMON. A placed 3D sRGB+UAV texture requested in UNORDERED_ACCESS is created in COMMON while lut3d tracks UNORDERED_ACCESS, which gives barrier before-state mismatches and wrong dumps with XCL_DUMP_TARGETS/capture.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:48:56Z.
Consolidated into and superseded by #3729 (https://github.com/xcl-dev/xcl/pull/3729), which combines #3291, #3414, #3418, and #3376 and addresses all open review findings in one PR. Closing this one.
Pull request closed