Repository navigation
D3D12: validate depth-stencil views like render-target views - #3594
Conversation
The TEXTURE2D/TEXTURE2DARRAY/TEXTURE2DMS/TEXTURE2DMSARRAY and default paths wrote a TargetView with the caller's mip and slice range without any of the checks the render-target-view path makes: no mip or layer bounds, no dimension or sample-count match, no ALLOW_DEPTH_STENCIL requirement and no view-format legality. An invalid view was silently recorded as valid. Give every depth view the same checks: the resource must be a depth-capable texture, the view dimension must match the texture's dimension and sample count, the mip and layer range must fit inside it and the view format must be a concrete depth format of the resource's own family (D16/D32/D24S8/D32S8X24, or that depth format for the matching typeless resource). A refused view writes a null TargetView. Adds runtime/test/d3d12_dsv_test.cpp covering valid TEXTURE2D, TEXTURE2DARRAY, TEXTURE2DMS, typeless and default views plus refused out-of-bounds mip/slice, MSAA/non-MSAA mismatch, non-depth resource and wrong-family format views. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Desamodeth
left a comment
There was a problem hiding this comment.
Tested 00a0441 on Windows 11 build 26300, MSVC 19.44 Release, RTX 5070 (621.24). On main f847748 the same d3d12_dsv test fails: mip 3 of a three-mip texture produces a non-null DSV. On the PR all 15 descriptor cases pass. I also ran d3d12_depth_resolve with Vulkan validation enabled: depth/stencil readbacks matched native D3D12 in 31/31 comparisons on the default adapter and 26/26 on WARP. Both CTests passed. Synthetic resources only; no game files. AI-assisted.
|
Tested 00a0441 on NVIDIA GeForce RTX 4090 (Ada), 621.14, Windows 11 (26200): the new MSVC 19.44 (VS 2022), Ninja, RelWithDebInfo. The branch is one commit on
What fails, the same both times: That is So the two disagree about when an out-of-range slice range is refused. Either that existing case is updated to the new behaviour (with what the host does for it; the test already compares many cases with the host on this machine), or the layer-range part of the new check leaves this case to the replay as before. I have not checked which of the two the PC runtime does.
Side note, unrelated to the PR: No game files. AI-assisted check (Claude Code). |
|
Tested
Failure details
Lines 5924–5931 of That existing test block in AI-assisted. |
|
Tested
The "this PR" column for the rows outside the test was measured by adding those calls to a local copy of
Not checked: Wine or llvmpipe; |
Kam471
left a comment
There was a problem hiding this comment.
Tested 00a04419 on Windows 11, MSVC 19.44.35228, RTX 5070 Ti.
Configuration: the -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF -DBUILD_TESTING=OFF recipe does not generate d3d12_dsv_test (runtime/CMakeLists.txt:11-12). Reconfigured the same private build with both flags ON.
New test: d3d12_dsv_test -> 15 checks, 15 pass, 0 fail, ctest 1/1. The 5 accepted / 10 refused cases match the documented rules (four depth families, typeless rejected, UNKNOWN -> resource format, ALLOW_DEPTH_STENCIL, 2D dimension/sample match, mip/layer bounds). D3D12_DEPTH_STENCIL_VIEW_DESC has no PlaneSlice, so the "plane slice" case in the description does not exist; no positive 1D or positive UNKNOWN case either.
Blocking regression in d3d12_vulkan_device_test: runtime/shims/d3d12_vulkan_device.cpp:4974-4975 rejects a TEXTURE2DMSARRAY range at creation (FirstArraySlice=3, ArraySize=2 of 4), but runtime/test/d3d12_vulkan_device_test.cpp:5924-5931 expects that descriptor to be stored and refused at replay. The test now fails at :5928 list->Close() == S_OK; d3d12_vulkan_device_test.exe exits 1 and ctest is 1/2 (50%). The equivalent typed-RGBA8 RTV at :5995-6003 still defers because the RTV range check at d3d12_vulkan_device.cpp:4874-4913 only bounds-checks the typeless/cast branch, so the new DSV check is also stricter than the RTV parity the description claims.
Please either move the DSV range check to replay like the RTV path, or update the existing contract test and align the RTV check with it. The new DSV test itself is green and needs no change; no game files.
|
Tested 00a0441 on Windows 11, MSVC (VS 2022 Build Tools) RelWithDebInfo, RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1):
No negative control run. AI-assisted. |
|
Tested 00a0441 (on its base
AI-assisted (Claude Code). |
|
Also tested No game files. AI-assisted (Claude Code). |
|
Merged and then reverted on main (34af82b): refusing the view in CreateDepthStencilView makes the existing d3d12_vulkan_device_test fail. It records a DSV over slices 3-4 of a 4-slice MS array and expects Close() to succeed and ExecuteCommandLists to report invalid_subresource (line 6154). Please reconcile the two, by measuring what the PC runtime does or by updating that test with the evidence, and open the PR again on top of main. |
claiming: CreateDepthStencilView missing view validation (new item; not in the current coordination issue #3381; open PRs #334 (SRV/UAV/CBV GFX10 descriptors) and #1644 (read-only DSVs) do not cover it). This account can't comment on the coordination issue, so the claim is here.
What
ID3D12Device::CreateDepthStencilViewonly bounds-checked the 1D/1DArray dimensions (vialine_target_view) and rejected A8_UNORM. The TEXTURE2D, TEXTURE2DARRAY, TEXTURE2DMS, TEXTURE2DMSARRAY and null-desc paths wrote aleonida::TargetViewstraight from the caller's mip and slice values: no mip or layer bounds, no resource-dimension match, no MSAA match, noD3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCILrequirement and no view-format legality. An invalid depth view was silently recorded as valid; the siblingCreateRenderTargetViewalready makes all of these checks (d3d12_vulkan_device.cpp ~4889-4908).Fix
Before storing the view, refuse (write a null TargetView) when:
D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCILTest
runtime/test/d3d12_dsv_test.cppbuilds a standalone device and DSV heap, creates mipmapped/arrayed depth textures, a 4xMSAA depth texture, a colour texture and an R32_TYPELESS texture, then asserts valid views write a non-null TargetView while refused ones write a null one (out-of-bounds mip/slice, MSAA and dimension mismatch, non-depth resource, wrong-family format). It fails on main (out-of-bounds mip DSV should be null) and passes with this change.Tested
Cross-compiled on Linux with clang-cl 21 + lld-link against a Windows SDK 10.0.26100 winsysroot (xwin + NuGet SDK packages); ran under Wine 11.0 on Mesa llvmpipe (LLVM 15, 256-bit):
d3d12_dsvFAIL -> PASS. MSVC/Visual Studio was not run (no Windows toolchain here) and no real GPU was tested. No game data used: all resources and view descs are hand-built. AI-assisted (Devin).Checklist
docs/design.md(n/a: no translator change).