D3D12.X: sanitize PC resource flag invariants in pc_resource_desc #3414

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3414 into main
Kalmarv commented 2026-11-29 14:38:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T14:38:37Z.


What is in it

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

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: 62de21cf4ce8aeed345de3875e172ea4464e885b
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1551 (PresentX 1551)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 32731 MB

Not tested

  • Hardware adapters with wave64-only shaders or non-NVIDIA drivers (22 wave64 tests skipped on RTX 5070 Ti).
  • Full title execution for games other than ea3b5e4d or paths requiring uma_driver::tests:: kernel driver tests.
  • Console resource flags in bits 0x40/0x80 (left untouched here to avoid overlap with #3141).

AI use

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.

<!-- greyfinch-sync:ivall/xcl:issue:5551757085 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T14:38:37Z. --- **What is in it** `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 #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`. **Regression run** ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` ``` xcl-smoke v1 commit: 62de21cf4ce8aeed345de3875e172ea4464e885b gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1551 (PresentX 1551) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 32731 MB ``` **Not tested** - Hardware adapters with wave64-only shaders or non-NVIDIA drivers (`22` wave64 tests skipped on RTX 5070 Ti). - Full title execution for games other than `ea3b5e4d` or paths requiring `uma_driver::tests::` kernel driver tests. - Console resource flags in bits `0x40`/`0x80` (left untouched here to avoid overlap with #3141). **AI use** 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.
Foniass commented 2026-12-01 04:06:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:06:19Z.


merge-check
base: d0832e614f
head: 62de21cf4c
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 d0832e61 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.

<!-- greyfinch-sync:ivall/xcl:comment:7300383478 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#issuecomment-7300383478). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:06:19Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: 62de21cf4ce8aeed345de3875e172ea4464e885b 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 d0832e61 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.
bmjask commented 2026-12-02 04:44:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:25Z.

Code review location: crates/xcl/src/hle/d3d12x/device_x.rs; line 883

@@ -864,11 +875,22 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] {
     // ALLOW_UNORDERED_ACCESS: PC D3D12 rejects even GetResourceAllocationInfo (id=599 / 0x887A0001).
     let pc_format = u32::from_le_bytes(d[0x20..0x24].try_into().unwrap());
     let samples = u32::from_le_bytes(d[0x24..0x28].try_into().unwrap());
-    if dim != D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 && (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) {
-        flags &= !4;
+    if !is_buffer {
+        if (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) {
+            flags &= !4;
+        }
+        if (flags & 0x02) != 0 {
+            flags &= !(0x01 | 0x20);

ALLOW_RENDER_TARGET is now stripped from DS|RT textures, but the initial state still comes from the console flags, and pc_initial_state / pc_initial_state_for_desc only drop UNORDERED_ACCESS, so RENDER_TARGET (0x4) survives on a resource without the RT flag. A console texture with flags 0x03 created in RENDER_TARGET ends up with PC flags 0x02 and state 0x4, which CreatePlacedResource/CreateCommittedResource reject with E_INVALIDARG. In placed_in_heap_x (real.rs:4469) both the hr2 attempt and the hr3 committed fallback use the same st, so creation still fails. Deriving the state from the sanitized PC flags (drop RENDER_TARGET without 0x1, DEPTH_* without 0x2, UAV without 0x4) at every call site (real.rs 4469 / 4529, device_x.rs 1248) would cover this and the buffer case below.

<!-- greyfinch-sync:ivall/xcl:review-comment:4764848648 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#discussion_r4764848648). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:44:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/device_x.rs`; line 883 ~~~~diff @@ -864,11 +875,22 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] { // ALLOW_UNORDERED_ACCESS: PC D3D12 rejects even GetResourceAllocationInfo (id=599 / 0x887A0001). let pc_format = u32::from_le_bytes(d[0x20..0x24].try_into().unwrap()); let samples = u32::from_le_bytes(d[0x24..0x28].try_into().unwrap()); - if dim != D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 && (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) { - flags &= !4; + if !is_buffer { + if (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) { + flags &= !4; + } + if (flags & 0x02) != 0 { + flags &= !(0x01 | 0x20); ~~~~ --- ALLOW_RENDER_TARGET is now stripped from DS|RT textures, but the initial state still comes from the console flags, and `pc_initial_state` / `pc_initial_state_for_desc` only drop UNORDERED_ACCESS, so RENDER_TARGET (0x4) survives on a resource without the RT flag. A console texture with flags 0x03 created in RENDER_TARGET ends up with PC flags 0x02 and state 0x4, which CreatePlacedResource/CreateCommittedResource reject with E_INVALIDARG. In `placed_in_heap_x` (real.rs:4469) both the hr2 attempt and the hr3 committed fallback use the same `st`, so creation still fails. Deriving the state from the sanitized PC flags (drop RENDER_TARGET without 0x1, DEPTH_* without 0x2, UAV without 0x4) at every call site (real.rs 4469 / 4529, device_x.rs 1248) would cover this and the buffer case below.
bmjask commented 2026-12-02 04:44:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:25Z.

Code review location: crates/xcl/src/hle/d3d12x/device_x.rs; line 866

@@ -854,6 +854,17 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] {
     if format == 67 && flags & 5 != 0 {
         d[0x20..0x24].copy_from_slice(&26u32.to_le_bytes());
     }
+    let is_buffer = dim == D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32;
+    // Enforce PC D3D12 resource flag invariants that console descriptors can violate:
+    // - buffers cannot carry ALLOW_RENDER_TARGET (0x01), ALLOW_DEPTH_STENCIL (0x02),
+    //   DENY_SHADER_RESOURCE (0x08), or ALLOW_SIMULTANEOUS_ACCESS (0x20);
+    // - textures cannot combine ALLOW_RENDER_TARGET with ALLOW_DEPTH_STENCIL, cannot set
+    //   DENY_SHADER_RESOURCE without ALLOW_DEPTH_STENCIL, cannot set ALLOW_SIMULTANEOUS_ACCESS
+    //   with MSAA or ALLOW_DEPTH_STENCIL, and cannot set ALLOW_CROSS_ADAPTER (0x10) once layout
+    //   is forced to TEXTURE_LAYOUT_UNKNOWN below.
+    if is_buffer {
+        flags &= !(0x01 | 0x02 | 0x08 | 0x20);

Buffers with ALLOW_DEPTH_STENCIL|ALLOW_UNORDERED_ACCESS now keep the UAV flag, but pc_initial_state still gets the original console flags (DS set) and turns an UNORDERED_ACCESS initial state into DEPTH_WRITE. A buffer with flags 0x06 and state 0x8 through create_placed_resource_x gets pc_initial_state(0x06, 0x8) = 0x10 (line 1248), and the buffer branch skips pc_initial_state_for_desc. The buffer is created in DEPTH_WRITE without the DS flag (rejected, or tracked in the wrong state), and the title's next UAV->X barrier has the wrong before-state. The new test checks flags only, not the state.

<!-- greyfinch-sync:ivall/xcl:review-comment:4764848657 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#discussion_r4764848657). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:44:25Z. **Code review location:** `crates/xcl/src/hle/d3d12x/device_x.rs`; line 866 ~~~~diff @@ -854,6 +854,17 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] { if format == 67 && flags & 5 != 0 { d[0x20..0x24].copy_from_slice(&26u32.to_le_bytes()); } + let is_buffer = dim == D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32; + // Enforce PC D3D12 resource flag invariants that console descriptors can violate: + // - buffers cannot carry ALLOW_RENDER_TARGET (0x01), ALLOW_DEPTH_STENCIL (0x02), + // DENY_SHADER_RESOURCE (0x08), or ALLOW_SIMULTANEOUS_ACCESS (0x20); + // - textures cannot combine ALLOW_RENDER_TARGET with ALLOW_DEPTH_STENCIL, cannot set + // DENY_SHADER_RESOURCE without ALLOW_DEPTH_STENCIL, cannot set ALLOW_SIMULTANEOUS_ACCESS + // with MSAA or ALLOW_DEPTH_STENCIL, and cannot set ALLOW_CROSS_ADAPTER (0x10) once layout + // is forced to TEXTURE_LAYOUT_UNKNOWN below. + if is_buffer { + flags &= !(0x01 | 0x02 | 0x08 | 0x20); ~~~~ --- Buffers with ALLOW_DEPTH_STENCIL|ALLOW_UNORDERED_ACCESS now keep the UAV flag, but `pc_initial_state` still gets the original console flags (DS set) and turns an UNORDERED_ACCESS initial state into DEPTH_WRITE. A buffer with flags 0x06 and state 0x8 through `create_placed_resource_x` gets `pc_initial_state(0x06, 0x8)` = 0x10 (line 1248), and the buffer branch skips `pc_initial_state_for_desc`. The buffer is created in DEPTH_WRITE without the DS flag (rejected, or tracked in the wrong state), and the title's next UAV->X barrier has the wrong before-state. The new test checks flags only, not the state.
bmjask commented 2026-12-02 04:44:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:25Z.

Review: COMMENTED


Review of 62de21cf: 4 finding(s). 4 are inline.


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.

<!-- greyfinch-sync:ivall/xcl:review:6144890356 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#pullrequestreview-6144890356). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:44:25Z. **Review:** COMMENTED --- Review of `62de21cf`: 4 finding(s). 4 are inline. --- _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._
bmjask commented 2026-12-02 04:44:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:26Z.

Code review location: crates/xcl/src/hle/d3d12x/device_x.rs; line 882

@@ -864,11 +875,22 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] {
     // ALLOW_UNORDERED_ACCESS: PC D3D12 rejects even GetResourceAllocationInfo (id=599 / 0x887A0001).
     let pc_format = u32::from_le_bytes(d[0x20..0x24].try_into().unwrap());
     let samples = u32::from_le_bytes(d[0x24..0x28].try_into().unwrap());
-    if dim != D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 && (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) {
-        flags &= !4;
+    if !is_buffer {
+        if (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) {
+            flags &= !4;
+        }
+        if (flags & 0x02) != 0 {

On DS|RT conflicts the code always keeps ALLOW_DEPTH_STENCIL and drops ALLOW_RENDER_TARGET, whatever the format. For a color format (e.g. R32_FLOAT 41 or R8G8B8A8 with flags 0x03), depth_typeless is None, so PC flags become 0x02 on a color format and the PC still refuses it. Where creation does succeed, the title's later CreateRenderTargetView / ClearRenderTargetView is invalid (dev_create_rtv has no flag guard) and the device is removed. The flag to keep should follow the format: DS for depth/typeless-depth families, RT otherwise.

<!-- greyfinch-sync:ivall/xcl:review-comment:4764848660 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#discussion_r4764848660). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:44:26Z. **Code review location:** `crates/xcl/src/hle/d3d12x/device_x.rs`; line 882 ~~~~diff @@ -864,11 +875,22 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] { // ALLOW_UNORDERED_ACCESS: PC D3D12 rejects even GetResourceAllocationInfo (id=599 / 0x887A0001). let pc_format = u32::from_le_bytes(d[0x20..0x24].try_into().unwrap()); let samples = u32::from_le_bytes(d[0x24..0x28].try_into().unwrap()); - if dim != D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 && (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) { - flags &= !4; + if !is_buffer { + if (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) { + flags &= !4; + } + if (flags & 0x02) != 0 { ~~~~ --- On DS|RT conflicts the code always keeps ALLOW_DEPTH_STENCIL and drops ALLOW_RENDER_TARGET, whatever the format. For a color format (e.g. R32_FLOAT 41 or R8G8B8A8 with flags 0x03), `depth_typeless` is None, so PC flags become 0x02 on a color format and the PC still refuses it. Where creation does succeed, the title's later CreateRenderTargetView / ClearRenderTargetView is invalid (dev_create_rtv has no flag guard) and the device is removed. The flag to keep should follow the format: DS for depth/typeless-depth families, RT otherwise.
bmjask commented 2026-12-02 04:44:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T04:44:26Z.

Code review location: crates/xcl/src/hle/d3d12x/device_x.rs; line 885

@@ -864,11 +875,22 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] {
     // ALLOW_UNORDERED_ACCESS: PC D3D12 rejects even GetResourceAllocationInfo (id=599 / 0x887A0001).
     let pc_format = u32::from_le_bytes(d[0x20..0x24].try_into().unwrap());
     let samples = u32::from_le_bytes(d[0x24..0x28].try_into().unwrap());
-    if dim != D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 && (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) {
-        flags &= !4;
+    if !is_buffer {
+        if (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) {
+            flags &= !4;
+        }
+        if (flags & 0x02) != 0 {
+            flags &= !(0x01 | 0x20);
+        } else {
+            flags &= !0x08;

DENY_SHADER_RESOURCE is stripped whenever ALLOW_DEPTH_STENCIL is absent, but flags & 0xFF still passes VIDEO_DECODE_REFERENCE_ONLY (0x40) and VIDEO_ENCODE_REFERENCE_ONLY (0x80), which require DENY_SHADER_RESOURCE on the PC. A resource with flags 0x48 or 0x88 becomes 0x40/0x80 and a previously valid desc is refused with E_INVALIDARG. The rule should be "strip 0x08 unless 0x02, 0x40 or 0x80 is set".

<!-- greyfinch-sync:ivall/xcl:review-comment:4764848664 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#discussion_r4764848664). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T04:44:26Z. **Code review location:** `crates/xcl/src/hle/d3d12x/device_x.rs`; line 885 ~~~~diff @@ -864,11 +875,22 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] { // ALLOW_UNORDERED_ACCESS: PC D3D12 rejects even GetResourceAllocationInfo (id=599 / 0x887A0001). let pc_format = u32::from_le_bytes(d[0x20..0x24].try_into().unwrap()); let samples = u32::from_le_bytes(d[0x24..0x28].try_into().unwrap()); - if dim != D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32 && (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) { - flags &= !4; + if !is_buffer { + if (flags & 4) != 0 && (samples > 1 || !texture_format_allows_uav(pc_format)) { + flags &= !4; + } + if (flags & 0x02) != 0 { + flags &= !(0x01 | 0x20); + } else { + flags &= !0x08; ~~~~ --- DENY_SHADER_RESOURCE is stripped whenever ALLOW_DEPTH_STENCIL is absent, but `flags & 0xFF` still passes VIDEO_DECODE_REFERENCE_ONLY (0x40) and VIDEO_ENCODE_REFERENCE_ONLY (0x80), which require DENY_SHADER_RESOURCE on the PC. A resource with flags 0x48 or 0x88 becomes 0x40/0x80 and a previously valid desc is refused with E_INVALIDARG. The rule should be "strip 0x08 unless 0x02, 0x40 or 0x80 is set".
bmjask commented 2026-12-02 14:14:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:14:20Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7348213829 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#issuecomment-7348213829). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:14:20Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Kalmarv commented 2026-12-02 20:48:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:48:58Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7358361721 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3414#issuecomment-7358361721). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T20:48:58Z. --- 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

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
xcl-dev/xcl!3414
No description provided.