D3D12.X: sanitize null-resource SRV, image UAV, and RTV formats #3319
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3319"
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-29T08:00:51Z.
Sanitize null-resource (
pResource == NULL) SRV, image UAV, and RTV formats incrates/xcl/src/hle/d3d12x/real.rsso console depth/stencil, sRGB, promoted target, and host-unsupported formats never triggerDXGI_ERROR_INVALID_CALL(0x887A0001) device removal on PC D3D12.What is in it
crates/xcl/src/hle/d3d12x/real.rs:dev_create_srv_inner: whenres.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 toUNKNOWN->R32_FLOAT, and setPlaneSlice = 1for nullTexture2D/Texture2DArraystencil SRVs (X24_TYPELESS_G8_UINT,X32_TYPELESS_G8X24_UINT).dev_create_uav_x: whenres.is_null()for an image UAV dimension, map throughpc_target_formatandpc_uav_linear_formatand fall back toDXGI_FORMAT_R32_FLOATwhen the result isUNKNOWNor lacks hostTYPED_UNORDERED_ACCESS_VIEWsupport (pc_typed_uav_supported), leaving null buffer UAVs untouched.dev_create_rtv: whenres.is_null(), map throughpc_target_format(promotingB5G5R5A1_UNORM/B4G4R4A4_UNORM->R8G8B8A8_UNORMandR9G9B9E5_SHAREDEXP->R11G11B10_FLOAT) and mapUNKNOWNtoR8G8B8A8_UNORM.null_view_format_tests::null_srv_uav_and_rtv_sanitize_console_and_incompatible_formatscovering 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
cargo test -p xcl --lib -- hle::d3d12x::real::null_view_format_tests::):fmt=118, mapped toD24_UNORM_S8_UINT) with D3D12 debug-layer[id=28] ID3D12Device::CreateShaderResourceView: The format (0x2d, D24_UNORM_S8_UINT) cannot be used with a ShaderResource viewand[id=232] ID3D12Device::RemoveDevice (DXGI_ERROR_INVALID_CALL).1 passed; 0 failed(0.18s, zero debug-layer errors across all 26 null SRV/UAV/RTV cases).rustc 1.99.0, RTX 5070 Ti driver32.0.16.1074, DXC1.9.2609.5):cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::2600 passed; 0 failed; 49 ignored(301.6s).SKIPPED:1(1no heap windows).Regression run
Baseline (
mainancestorf0e8fdd5c3942ddd399d5ee11384c8595c5aacff) and this PR (ea2aead7aadaa1505eb83c4a92a1832ee51e8baa), 150 s on RTX 5070 Ti:Not tested
*_TYPELESSformats on null SRVs or null RTVs.test_title_runs_and_game_folder_is_untouchedanduma_driver::tests::were skipped in the workspace test run.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:57:52Z.
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 Foniass on 2026-12-01T05:55:12Z.
merge-check
base:
d0832e614fhead:
ea2aead7aamerge: 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). Callingskip_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 withpc_shader_view_format, the data type the null T# gives shaders is the same as on main, and the null UAV path reusespc_typed_uav_supportedasdev_create_uav_checked_innerdoes. 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
d0832e61vs 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.
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 3690The null image UAV fallback relies on
pc_typed_uav_supported, which returns true when CheckFeatureSupport fails. A console-only format thatpc_view_format/pc_target_formatdon'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.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 3691When 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.
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 3229The 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.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 11027The null RTV path only applies
pc_target_formatplus 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.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.
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.
Pull request closed