D3D12.X: sanitize null-resource SRV, image UAV, and RTV formats #3319

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3319 into main
Kalmarv commented 2026-11-29 08:00:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T08:00:51Z.


Sanitize null-resource (pResource == NULL) SRV, image UAV, and RTV formats in crates/xcl/src/hle/d3d12x/real.rs so console depth/stencil, sRGB, promoted target, and host-unsupported formats never trigger DXGI_ERROR_INVALID_CALL (0x887A0001) device removal on PC D3D12.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • dev_create_srv_inner: when res.is_null() for an image SRV dimension, map depth and depth-typeless formats (D16_UNORM_S8_UINT -> D24_UNORM_S8_UINT -> R24_UNORM_X8_TYPELESS, D32_FLOAT / R32_TYPELESS -> R32_FLOAT, D16_UNORM / R16_TYPELESS -> R16_UNORM, D32_FLOAT_S8X24_UINT / R32G8X24_TYPELESS -> R32_FLOAT_X8X24_TYPELESS) in addition to UNKNOWN -> R32_FLOAT, and set PlaneSlice = 1 for null Texture2D / Texture2DArray stencil SRVs (X24_TYPELESS_G8_UINT, X32_TYPELESS_G8X24_UINT).
    • dev_create_uav_x: when res.is_null() for an image UAV dimension, map through pc_target_format and pc_uav_linear_format and fall back to DXGI_FORMAT_R32_FLOAT when the result is UNKNOWN or lacks host TYPED_UNORDERED_ACCESS_VIEW support (pc_typed_uav_supported), leaving null buffer UAVs untouched.
    • dev_create_rtv: when res.is_null(), map through pc_target_format (promoting B5G5R5A1_UNORM / B4G4R4A4_UNORM -> R8G8B8A8_UNORM and R9G9B9E5_SHAREDEXP -> R11G11B10_FLOAT) and map UNKNOWN to R8G8B8A8_UNORM.
    • Add a child-isolated WARP + D3D12 debug-layer test null_view_format_tests::null_srv_uav_and_rtv_sanitize_console_and_incompatible_formats covering 11 null SRV cases, 11 null image UAV cases, and 4 null RTV cases and asserting zero D3D12 debug-layer errors and no device removal.

Tested

  • Targeted child-isolated WARP + D3D12 debug-layer test (cargo test -p xcl --lib -- hle::d3d12x::real::null_view_format_tests::):
    • Before the fix: failed on the first null SRV (fmt=118, mapped to D24_UNORM_S8_UINT) with D3D12 debug-layer [id=28] ID3D12Device::CreateShaderResourceView: The format (0x2d, D24_UNORM_S8_UINT) cannot be used with a ShaderResource view and [id=232] ID3D12Device::RemoveDevice (DXGI_ERROR_INVALID_CALL).
    • After the fix: 1 passed; 0 failed (0.18s, zero debug-layer errors across all 26 null SRV/UAV/RTV cases).
  • Full workspace test suite on Windows 11 Pro (rustc 1.99.0, RTX 5070 Ti driver 32.0.16.1074, DXC 1.9.2609.5):
    • Command: cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::
    • Result: 2600 passed; 0 failed; 49 ignored (301.6s).
    • SKIPPED: 1 (1 no heap windows).

Regression run
Baseline (main ancestor f0e8fdd5c3942ddd399d5ee11384c8595c5aacff) and this PR (ea2aead7aadaa1505eb83c4a92a1832ee51e8baa), 150 s on RTX 5070 Ti:

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: ea2aead7aadaa1505eb83c4a92a1832ee51e8baa
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1551 (PresentX 1551)
presents per 2 s (last 3): 39 16 0
device removals: 0
crashes: 0
peak commit: 33164 MB

Not tested

  • AMD RDNA hardware, macOS/Linux hosts, and non-depth color *_TYPELESS formats on null SRVs or null RTVs.
  • test_title_runs_and_game_folder_is_untouched and uma_driver::tests:: were skipped in the workspace test run.

AI use

  • Implemented, debugged, and verified with an AI coding assistant; all code, tests, workspace results, and smoke output were reviewed and verified locally.
<!-- greyfinch-sync:ivall/xcl:issue:5548835574 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T08:00:51Z. --- Sanitize null-resource (`pResource == NULL`) SRV, image UAV, and RTV formats in `crates/xcl/src/hle/d3d12x/real.rs` so console depth/stencil, sRGB, promoted target, and host-unsupported formats never trigger `DXGI_ERROR_INVALID_CALL` (`0x887A0001`) device removal on PC D3D12. **What is in it** - `crates/xcl/src/hle/d3d12x/real.rs`: - `dev_create_srv_inner`: when `res.is_null()` for an image SRV dimension, map depth and depth-typeless formats (`D16_UNORM_S8_UINT` -> `D24_UNORM_S8_UINT` -> `R24_UNORM_X8_TYPELESS`, `D32_FLOAT` / `R32_TYPELESS` -> `R32_FLOAT`, `D16_UNORM` / `R16_TYPELESS` -> `R16_UNORM`, `D32_FLOAT_S8X24_UINT` / `R32G8X24_TYPELESS` -> `R32_FLOAT_X8X24_TYPELESS`) in addition to `UNKNOWN` -> `R32_FLOAT`, and set `PlaneSlice = 1` for null `Texture2D` / `Texture2DArray` stencil SRVs (`X24_TYPELESS_G8_UINT`, `X32_TYPELESS_G8X24_UINT`). - `dev_create_uav_x`: when `res.is_null()` for an image UAV dimension, map through `pc_target_format` and `pc_uav_linear_format` and fall back to `DXGI_FORMAT_R32_FLOAT` when the result is `UNKNOWN` or lacks host `TYPED_UNORDERED_ACCESS_VIEW` support (`pc_typed_uav_supported`), leaving null buffer UAVs untouched. - `dev_create_rtv`: when `res.is_null()`, map through `pc_target_format` (promoting `B5G5R5A1_UNORM` / `B4G4R4A4_UNORM` -> `R8G8B8A8_UNORM` and `R9G9B9E5_SHAREDEXP` -> `R11G11B10_FLOAT`) and map `UNKNOWN` to `R8G8B8A8_UNORM`. - Add a child-isolated WARP + D3D12 debug-layer test `null_view_format_tests::null_srv_uav_and_rtv_sanitize_console_and_incompatible_formats` covering 11 null SRV cases, 11 null image UAV cases, and 4 null RTV cases and asserting zero D3D12 debug-layer errors and no device removal. **Tested** - Targeted child-isolated WARP + D3D12 debug-layer test (`cargo test -p xcl --lib -- hle::d3d12x::real::null_view_format_tests::`): - Before the fix: failed on the first null SRV (`fmt=118`, mapped to `D24_UNORM_S8_UINT`) with D3D12 debug-layer `[id=28] ID3D12Device::CreateShaderResourceView: The format (0x2d, D24_UNORM_S8_UINT) cannot be used with a ShaderResource view` and `[id=232] ID3D12Device::RemoveDevice (DXGI_ERROR_INVALID_CALL)`. - After the fix: `1 passed; 0 failed` (`0.18s`, zero debug-layer errors across all 26 null SRV/UAV/RTV cases). - Full workspace test suite on Windows 11 Pro (`rustc 1.99.0`, RTX 5070 Ti driver `32.0.16.1074`, DXC `1.9.2609.5`): - Command: `cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::` - Result: `2600 passed; 0 failed; 49 ignored` (`301.6s`). - `SKIPPED`: `1` (`1` `no heap windows`). **Regression run** Baseline (`main` ancestor `f0e8fdd5c3942ddd399d5ee11384c8595c5aacff`) and this PR (`ea2aead7aadaa1505eb83c4a92a1832ee51e8baa`), 150 s on RTX 5070 Ti: ``` 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: ea2aead7aadaa1505eb83c4a92a1832ee51e8baa gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1551 (PresentX 1551) presents per 2 s (last 3): 39 16 0 device removals: 0 crashes: 0 peak commit: 33164 MB ``` **Not tested** - AMD RDNA hardware, macOS/Linux hosts, and non-depth color `*_TYPELESS` formats on null SRVs or null RTVs. - `test_title_runs_and_game_folder_is_untouched` and `uma_driver::tests::` were skipped in the workspace test run. **AI use** - Implemented, debugged, and verified with an AI coding assistant; all code, tests, workspace results, and smoke output were reviewed and verified locally.
Foniass commented 2026-11-29 14:57:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:57:52Z.


merge-check
base: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
head: ea2aead7aadaa1505eb83c4a92a1832ee51e8baa
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2615 passed, 4 failed, 49 ignored; SKIPPED: 44; failing: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (driver E_OUTOFMEMORY, same on base on this machine)
review: only null-resource views change. The sanitized format also goes into the T# that shaders read (a null D32 SRV now reports R32_FLOAT), which the PR does not disclose; these calls were invalid before. The debug-layer test checks less without Graphics Tools. It conflicts trivially (test module appended at the end of real.rs) with #3313, #3297 and #3291. AI use names no model.
performance: 60 s smoke: 1671 frames (99.9 % of d8bd9a38), peak commit 16827 MB (93.8 %)
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti (driver 32.0.16.2114), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

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.ps1 run of a retail title against main on the same machine. The 4 fuzz_validate_and_gpu_* failures happen on main on this machine too.

<!-- greyfinch-sync:ivall/xcl:comment:7257712363 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#issuecomment-7257712363). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T14:57:52Z. --- ```text merge-check base: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 head: ea2aead7aadaa1505eb83c4a92a1832ee51e8baa merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2615 passed, 4 failed, 49 ignored; SKIPPED: 44; failing: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (driver E_OUTOFMEMORY, same on base on this machine) review: only null-resource views change. The sanitized format also goes into the T# that shaders read (a null D32 SRV now reports R32_FLOAT), which the PR does not disclose; these calls were invalid before. The debug-layer test checks less without Graphics Tools. It conflicts trivially (test module appended at the end of real.rs) with #3313, #3297 and #3291. AI use names no model. performance: 60 s smoke: 1671 frames (99.9 % of d8bd9a38), peak commit 16827 MB (93.8 %) verdict: safe to merge hardware / tool and model: RTX 5070 Ti (driver 32.0.16.2114), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 ``` 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.ps1` run of a retail title against main on the same machine. The 4 `fuzz_validate_and_gpu_*` failures happen on main on this machine too.
Foniass commented 2026-12-01 05:55:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:55:12Z.


merge-check
base: d0832e614f
head: ea2aead7aa
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 (real.rs, +204/-10). It changes the default path for null views only: null image SRVs in depth formats or their typeless families (and console D16S8 -> D24S8) get a readable format, the two stencil formats get PlaneSlice 1, null image UAVs go through the target / linear / typed-UAV-support mapping with an R32_FLOAT fallback, and null RTVs get the target-format mapping (UNKNOWN becomes R8G8B8A8_UNORM). Findings: (1) the new test ignores a failed D3D12GetDebugInterface (~15097); without the debug layer, collect_d3d12_errors (~15044) returns nothing, so the 26 per-view checks pass without testing anything and with no SKIPPED notice, and the parent drops the child's output on success (~15086). Calling skip_test("no D3D12 debug layer") in the child and forwarding its output would fix it. (2) PlaneSlice 1 is set only for Texture2D / Texture2DArray null stencil views (~3239); stencil cube and MSAA views aren't covered. (3) AI use names no tool or model. Fine: the readable formats agree with pc_shader_view_format, the data type the null T# gives shaders is the same as on main, and the null UAV path reuses pc_typed_uav_supported as dev_create_uav_checked_inner does. Null buffer UAVs are left alone. #3376 and #3291 will only collide textually at the end of the file.
performance: 60 s smoke of a retail title, main d0832e61 vs this merge (a5056ffd): 1516 -> 1673 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17520 MB, 0 device removals, 0 crashes.
verdict: safe to merge (the test should skip_test without the debug layer and forward the child's output; the description should name the AI model)
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:7302278564 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#issuecomment-7302278564). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:55:12Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: ea2aead7aadaa1505eb83c4a92a1832ee51e8baa 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 (real.rs, +204/-10). It changes the default path for null views only: null image SRVs in depth formats or their typeless families (and console D16S8 -> D24S8) get a readable format, the two stencil formats get PlaneSlice 1, null image UAVs go through the target / linear / typed-UAV-support mapping with an R32_FLOAT fallback, and null RTVs get the target-format mapping (UNKNOWN becomes R8G8B8A8_UNORM). Findings: (1) the new test ignores a failed `D3D12GetDebugInterface` (~15097); without the debug layer, `collect_d3d12_errors` (~15044) returns nothing, so the 26 per-view checks pass without testing anything and with no SKIPPED notice, and the parent drops the child's output on success (~15086). Calling `skip_test("no D3D12 debug layer")` in the child and forwarding its output would fix it. (2) PlaneSlice 1 is set only for Texture2D / Texture2DArray null stencil views (~3239); stencil cube and MSAA views aren't covered. (3) AI use names no tool or model. Fine: the readable formats agree with `pc_shader_view_format`, the data type the null T# gives shaders is the same as on main, and the null UAV path reuses `pc_typed_uav_supported` as `dev_create_uav_checked_inner` does. Null buffer UAVs are left alone. #3376 and #3291 will only collide textually at the end of the file. performance: 60 s smoke of a retail title, main d0832e61 vs this merge (a5056ffd): 1516 -> 1673 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17520 MB, 0 device removals, 0 crashes. verdict: safe to merge (the test should skip_test without the debug layer and forward the child's output; the description should name the AI model) 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-01 23:14:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:45Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 3690

@@ -3673,11 +3685,16 @@ unsafe extern "system" fn dev_create_uav_x(this: *mut c_void, res: *mut c_void,
         if let Some(rd) = rd_opt.as_ref() {
             let rf = rd.Format.0 as u32;
             c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_shader_view_format(rf, c.Format.0 as u32) as i32);
+        } else if view_dim_to_image_type(c.ViewDimension.0).is_some() {
+            let mapped = super::device_x::pc_uav_linear_format(super::device_x::pc_target_format(c.Format.0 as u32));
+            let fmt = if mapped == 0 || !super::device_x::pc_typed_uav_supported(this, mapped as i32) {

The null image UAV fallback relies on pc_typed_uav_supported, which returns true when CheckFeatureSupport fails. A console-only format that pc_view_format/pc_target_format don't map (outside 116-120/86/115/67) gets E_INVALIDARG from the query, is reported as supported, and reaches CreateUnorderedAccessView unchanged, which removes the device. Typeless formats (e.g. R8G8B8A8_TYPELESS=27) can do the same on drivers that report TYPED_UNORDERED_ACCESS_VIEW or fail the query, since a typed view in a typeless format is always invalid. A failed query should count as unsupported.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762389339 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#discussion_r4762389339). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:45Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3690 ~~~~diff @@ -3673,11 +3685,16 @@ unsafe extern "system" fn dev_create_uav_x(this: *mut c_void, res: *mut c_void, if let Some(rd) = rd_opt.as_ref() { let rf = rd.Format.0 as u32; c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_shader_view_format(rf, c.Format.0 as u32) as i32); + } else if view_dim_to_image_type(c.ViewDimension.0).is_some() { + let mapped = super::device_x::pc_uav_linear_format(super::device_x::pc_target_format(c.Format.0 as u32)); + let fmt = if mapped == 0 || !super::device_x::pc_typed_uav_supported(this, mapped as i32) { ~~~~ --- The null image UAV fallback relies on `pc_typed_uav_supported`, which returns true when CheckFeatureSupport fails. A console-only format that `pc_view_format`/`pc_target_format` don't map (outside 116-120/86/115/67) gets E_INVALIDARG from the query, is reported as supported, and reaches CreateUnorderedAccessView unchanged, which removes the device. Typeless formats (e.g. R8G8B8A8_TYPELESS=27) can do the same on drivers that report TYPED_UNORDERED_ACCESS_VIEW or fail the query, since a typed view in a typeless format is always invalid. A failed query should count as unsupported.
bmjask commented 2026-12-01 23:14:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:45Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 3691

@@ -3673,11 +3685,16 @@ unsafe extern "system" fn dev_create_uav_x(this: *mut c_void, res: *mut c_void,
         if let Some(rd) = rd_opt.as_ref() {
             let rf = rd.Format.0 as u32;
             c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_shader_view_format(rf, c.Format.0 as u32) as i32);
+        } else if view_dim_to_image_type(c.ViewDimension.0).is_some() {
+            let mapped = super::device_x::pc_uav_linear_format(super::device_x::pc_target_format(c.Format.0 as u32));
+            let fmt = if mapped == 0 || !super::device_x::pc_typed_uav_supported(this, mapped as i32) {
+                windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT.0 as u32

When the null UAV format falls back to R32_FLOAT, the console's PlaneSlice is kept. A null Texture2D/Array UAV with PlaneSlice=1 and a depth/stencil format becomes R32_FLOAT with plane 1, which is out of range for a one-plane format, so the debug layer reports it and the device can be removed. The SRV branch has the same issue when a non-stencil format keeps PlaneSlice != 0.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762389350 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#discussion_r4762389350). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:45Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3691 ~~~~diff @@ -3673,11 +3685,16 @@ unsafe extern "system" fn dev_create_uav_x(this: *mut c_void, res: *mut c_void, if let Some(rd) = rd_opt.as_ref() { let rf = rd.Format.0 as u32; c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_shader_view_format(rf, c.Format.0 as u32) as i32); + } else if view_dim_to_image_type(c.ViewDimension.0).is_some() { + let mapped = super::device_x::pc_uav_linear_format(super::device_x::pc_target_format(c.Format.0 as u32)); + let fmt = if mapped == 0 || !super::device_x::pc_typed_uav_supported(this, mapped as i32) { + windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT.0 as u32 ~~~~ --- When the null UAV format falls back to R32_FLOAT, the console's PlaneSlice is kept. A null Texture2D/Array UAV with PlaneSlice=1 and a depth/stencil format becomes R32_FLOAT with plane 1, which is out of range for a one-plane format, so the debug layer reports it and the device can be removed. The SRV branch has the same issue when a non-stencil format keeps PlaneSlice != 0.
bmjask commented 2026-12-01 23:14:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:45Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 3229

@@ -3226,11 +3226,23 @@ unsafe fn dev_create_srv_inner(this: *mut c_void, res: *mut c_void, desc: *const
     let mut copy = desc.as_ref().copied();
     if let Some(c) = copy.as_mut() {
         c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_view_format(c.Format.0 as u32) as i32);
-        if res.is_null()
-            && c.Format == windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_UNKNOWN
-            && view_dim_to_image_type(c.ViewDimension.0).is_some()
-        {
-            c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT;
+        if res.is_null() && view_dim_to_image_type(c.ViewDimension.0).is_some() {

The null SRV sanitizer only rewrites depth-family typeless and depth formats. Color and BC typeless formats fall through f => f, so a null Texture2D SRV with R8G8B8A8_TYPELESS (27), R16G16B16A16_TYPELESS (9) or BC1_TYPELESS (70) still reaches CreateShaderResourceView typeless. D3D12 rejects that with the same 0x887A0001 removal this PR is meant to stop.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762389357 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#discussion_r4762389357). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:45Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 3229 ~~~~diff @@ -3226,11 +3226,23 @@ unsafe fn dev_create_srv_inner(this: *mut c_void, res: *mut c_void, desc: *const let mut copy = desc.as_ref().copied(); if let Some(c) = copy.as_mut() { c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_view_format(c.Format.0 as u32) as i32); - if res.is_null() - && c.Format == windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_UNKNOWN - && view_dim_to_image_type(c.ViewDimension.0).is_some() - { - c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R32_FLOAT; + if res.is_null() && view_dim_to_image_type(c.ViewDimension.0).is_some() { ~~~~ --- The null SRV sanitizer only rewrites depth-family typeless and depth formats. Color and BC typeless formats fall through `f => f`, so a null Texture2D SRV with R8G8B8A8_TYPELESS (27), R16G16B16A16_TYPELESS (9) or BC1_TYPELESS (70) still reaches CreateShaderResourceView typeless. D3D12 rejects that with the same 0x887A0001 removal this PR is meant to stop.
bmjask commented 2026-12-01 23:14:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:45Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 11027

@@ -11006,8 +11023,16 @@ unsafe extern "system" fn dev_create_rtv(this: *mut c_void, res: *mut c_void, de
     // a view in a console-only format, or of a target made R8G8B8A8 (`device_x::pc_resource_desc`)
     let mut copy = (!desc.is_null()).then(|| (desc as *const D3D12_RENDER_TARGET_VIEW_DESC).read_unaligned());
     if let Some(c) = copy.as_mut() {
-        let rf = ID3D12Resource::from_raw_borrowed(&res).map_or(0, |r| r.GetDesc().Format.0 as u32);
-        c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_shader_view_format(rf, c.Format.0 as u32) as i32);
+        let f = if res.is_null() {
+            match super::device_x::pc_target_format(c.Format.0 as u32) {

The null RTV path only applies pc_target_format plus UNKNOWN->RGBA8, so depth, typeless and non-renderable formats pass through. A null RTV with D24_UNORM_S8_UINT (45), console D16S8 (118, which pc_target_format maps to 45) or R8G8B8A8_TYPELESS (27) reaches CreateRenderTargetView with a format that can't be an RTV, and the device is removed. The SRV path in this PR does sanitize depth formats; the RTV path doesn't.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762389366 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#discussion_r4762389366). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:45Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 11027 ~~~~diff @@ -11006,8 +11023,16 @@ unsafe extern "system" fn dev_create_rtv(this: *mut c_void, res: *mut c_void, de // a view in a console-only format, or of a target made R8G8B8A8 (`device_x::pc_resource_desc`) let mut copy = (!desc.is_null()).then(|| (desc as *const D3D12_RENDER_TARGET_VIEW_DESC).read_unaligned()); if let Some(c) = copy.as_mut() { - let rf = ID3D12Resource::from_raw_borrowed(&res).map_or(0, |r| r.GetDesc().Format.0 as u32); - c.Format = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_shader_view_format(rf, c.Format.0 as u32) as i32); + let f = if res.is_null() { + match super::device_x::pc_target_format(c.Format.0 as u32) { ~~~~ --- The null RTV path only applies `pc_target_format` plus UNKNOWN->RGBA8, so depth, typeless and non-renderable formats pass through. A null RTV with D24_UNORM_S8_UINT (45), console D16S8 (118, which pc_target_format maps to 45) or R8G8B8A8_TYPELESS (27) reaches CreateRenderTargetView with a format that can't be an RTV, and the device is removed. The SRV path in this PR does sanitize depth formats; the RTV path doesn't.
bmjask commented 2026-12-01 23:14:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T23:14:45Z.

Review: COMMENTED


Review of ea2aead7: 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:6141936680 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#pullrequestreview-6141936680). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T23:14:45Z. **Review:** COMMENTED --- Review of `ea2aead7`: 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._
Kalmarv commented 2026-12-02 20:51:53 +00:00 (Migrated from github.com)

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


Superseded by #3731, which consolidates #3319 and #3280 on crates/xcl/src/hle/d3d12x/real.rs (dropping the #1087 MSAA overlap and addressing all review findings from both PRs).

AI use: Antigravity (Gemini 4 Neon) consolidated these PRs and posted this closing note.

<!-- greyfinch-sync:ivall/xcl:comment:7358438610 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3319#issuecomment-7358438610). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T20:51:53Z. --- Superseded by #3731, which consolidates #3319 and #3280 on `crates/xcl/src/hle/d3d12x/real.rs` (dropping the #1087 MSAA overlap and addressing all review findings from both PRs). AI use: Antigravity (Gemini 4 Neon) consolidated these PRs and posted this closing note.

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!3319
No description provided.