Skip to content

d3d12: accept DXGI_FORMAT_R16_UNORM in D16 depth ResolveSubresourceRegion - #7942

Open
coenflict wants to merge 1 commit into
ItsNotRexed:mainfrom
coenflict:d3d12-d16-depth-resolve
Open

coenflict wants to merge 1 commit into
ItsNotRexed:mainfrom
coenflict:d3d12-d16-depth-resolve

Conversation

@coenflict

Copy link
Copy Markdown

Claimed in coordination issue #7804: #7804 (comment)

What and why

depth_stencil_resolve_supported() in runtime/shims/d3d12_vulkan_device.cpp mapped depth/stencil plane SRV formats for D32 (DXGI_FORMAT_R32_FLOAT), D24S8 (DXGI_FORMAT_R24_UNORM_X8_TYPELESS / DXGI_FORMAT_X24_TYPELESS_G8_UINT), and D32S8 (DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS / DXGI_FORMAT_X32_TYPELESS_G8X24_UINT), but omitted DXGI_FORMAT_R16_UNORM for DXGI_FORMAT_D16_UNORM / DXGI_FORMAT_R16_TYPELESS.

As a result:

  • ResolveSubresourceRegion on a D16_UNORM or R16_TYPELESS depth texture with Format = DXGI_FORMAT_R16_UNORM was refused at recording (Close() returned E_INVALIDARG) for MIN, MAX, and AVERAGE.
  • D3D12_RESOLVE_MODE_AVERAGE was completely unusable for 16-bit depth targets, since D3D12 requires the depth plane's SRV format (DXGI_FORMAT_R16_UNORM) rather than DXGI_FORMAT_D16_UNORM for AVERAGE.

This PR adds case DXGI_FORMAT_R16_UNORM: family = DXGI_FORMAT_D16_UNORM, named_plane = 0; break; to depth_stencil_resolve_supported(), adds a minimal synthetic GPU regression test d3d12_d16_depth_resolve_test, and notes R16_UNORM in docs/d3d12_vulkan.md.

Tested

Environment: Windows 11, MSVC 19.51.36263.0 + Ninja, CMake 4.4.3, Vulkan SDK 1.4.363.0, RelWithDebInfo, LEONIDA_VK_VALIDATION=1.

  • Before fix (origin/main) on NVIDIA GeForce RTX 5090 (driver 32.0.16.2124 / 621.24):
    • d3d12_d16_depth_resolve_test failed as expected: all 15 DXGI_FORMAT_R16_UNORM cases (D16_UNORM and R16_TYPELESS, MIN/MAX/AVERAGE, whole and rectangle, plus edge draw) returned Close 0x80070057 (E_INVALIDARG) on the layer, while both native D3D12 (RTX 5090) and WARP returned S_OK.
  • After fix on NVIDIA GeForce RTX 5090 (driver 621.24, LEONIDA_VK_VALIDATION=1):
    • d3d12_d16_depth_resolve_test: 23/23 layer cases passed, 23/23 matched native RTX 5090 D3D12 (edge AVERAGE within 1 ULP on the 0.5 halfway tie: layer 24576 vs host 24575), 12/15 matched WARP (the 3 edge cases differ in WARP MSAA sample coverage), 3/3 refusals kept destination and matched both hosts, 0 Vulkan validation errors.
  • After fix on AMD Radeon(TM) Graphics iGPU (driver 32.0.21042.62, LEONIDA_VK_VALIDATION=1):
    • d3d12_d16_depth_resolve_test: 23/23 layer cases passed (correctly refusing AVERAGE since supportedDepthResolveModes = 0xd lacks AVERAGE), 18/18 matched native Radeon D3D12, 10/10 matched WARP, 3/3 refusals matched, 0 Vulkan validation errors.
  • Related CTests (LEONIDA_VK_VALIDATION=1, RTX 5090):
    • ctest -R "^(d3d12_d16_depth_resolve|d3d12_com|vk_command_replay|d3d12_view_slices)$" — 4/4 passed.
  • Repo checks:
    • python -I tests/test_ctest_registration.py — 4/4 OK.
    • python -I tests/test_ci_registration.py — 14/14 OK.
    • python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/CMakeLists.txt runtime/test/d3d12_d16_depth_resolve_test.cpp docs/d3d12_vulkan.md — clean.

AI-assisted: yes (Gemini).

Checklist

  • No game data, keys or decryption (synthetic test inputs only).
  • Registered new test in CTest (test_ctest_registration.py and test_ci_registration.py pass).
  • Verified red before fix and green after fix with LEONIDA_VK_VALIDATION=1 (0 validation errors).

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: PASS

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo, NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124 (Vulkan layer and host D3D12), plus WARP.

Head 57a7ce703, based on current main (dde82f27e). Re-ran the CMake configure to pick up the new target.

Test PR head Shim line reverted (git checkout origin/main -- runtime/shims/d3d12_vulkan_device.cpp)
d3d12_d16_depth_resolve_test.exe exit 0: 23 layer cases passed, 35 host comparisons matched, 3 refusals kept destination (RTX 3080 23/23, WARP 12/15, 3 refusals alike each) exit 1: RTX 3080 8 of 23 match, WARP 0 of 15 match (e.g. D16 depth as R16_UNORM MIN rect 1 against WARP: ... layer=0 host=65535)

So the new test fails without the one-line case DXGI_FORMAT_R16_UNORM and passes with it.

Neighbouring test: d3d12_depth_resolve_test.exe exits 1 on this PR. It also exits 1 on plain main dde82f27e, with the same 8 refused D24S8/D32S8 ... Close 0x80070057, destination changed lines and the same totals (RTX 3080 74/97, WARP 71/71). So that failure was already there and this PR didn't cause it.

Notes:

  • The new case only affects resources with ALLOW_DEPTH_STENCIL (the plane() lambda checks for it), so a colour R16_UNORM MSAA resolve still takes the colour path.
  • The 3 WARP cases that don't match are the edge cases. The test counts them only when they match and doesn't treat a mismatch as a failure (if (c.edge && warp) { ... continue; }). That's deliberate in the test, but it means the WARP line can't fail for edge cases.

@ebnimaa

ebnimaa commented Nov 23, 2026

Copy link
Copy Markdown

Independent Windows RDNA2 verification for Leonida PR #7942
#7942

AMD Radeon RX 6700 XT, AMD Adrenalin 26.10.1 (32.0.21045.16010), Vulkan
device API 1.4.315, Windows 11 25H2 (26220.9836). Both builds used Release,
MSVC 19.44.35227, Windows SDK 10.0.26100.0, and glslang 16.6.0. Khronos Vulkan
validation 1.4.363 was enabled with implicit layers disabled. The device
reported depth resolve modes 0xD (SAMPLE_ZERO, MIN, MAX).

Baseline: dde82f2 (the PR's parent).
Patch: 57a7ce7.
Both builds ran the PR's d3d12_d16_depth_resolve fixture, including its
edge-draw shader. The baseline build included the test source and CMake
registration from the PR, with the original runtime code.

  • Baseline failed as expected. All ten R16_UNORM MIN/MAX cases returned
    E_INVALIDARG at command-list Close, covering both resource formats,
    whole and rectangular resolves, and the mixed-sample edge draw.
  • Patch passed all 23 layer cases. All 18 supported MIN/MAX comparisons
    matched native D3D12 on the RX 6700 XT exactly (baseline 8/18). All ten
    eligible WARP comparisons also matched. All three explicit refusal
    controls kept their destination. Zero Vulkan validation errors.

Supplemental AVERAGE check: I ran the same locally instrumented fixture
on both revisions. I cleared the 8 x 6 destination to 0.125 (D16 value 8192)
in a valid setup list, recorded the resolve on its own list, and read the
destination with a separate valid list. The test only submitted the resolve
if Close succeeded. On both revisions, all seven AVERAGE cases returned
E_INVALIDARG and all 48 destination values per case retained the sentinel.
That includes five R16_UNORM cases (including the mixed-sample edge) and
two D16 format refusal controls.

All inputs were synthetic. AI-assisted with Codex.

@wuhuaiyu

Copy link
Copy Markdown

Independent dual-GPU test of head 57a7ce70397cb093741c4b741cc9d61e673067d7 on Windows 11 build 26200, MSVC 19.51, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, with Vulkan validation enabled. Built and ran d3d12_d16_depth_resolve_test directly:

  • Intel RaptorLake-S Mobile iGPU (DXGI: Intel UHD Graphics, driver 32.0.101.7085): exit 0; 23 layer cases passed, 23/23 matched native Intel D3D12, 14/15 matched WARP, and all 3 refusals kept the destination and matched both hosts. Depth resolve modes: 0xf.
  • NVIDIA RTX 5060 Laptop GPU (driver 32.0.16.2101): exit 0; 23 layer cases passed, 23/23 matched native NVIDIA D3D12, 12/15 matched WARP, and all 3 refusals kept the destination and matched both hosts. The NVIDIA edge AVERAGE case was within 1 ULP (24576 vs 24575). Depth resolve modes: 0x2f.

WARP edge mismatches are allowed by this test, so these totals do not assert exact agreement on those cases. No Vulkan validation errors appeared in either log. Synthetic inputs only; no game files. AI-assisted (Codex).

@AirKyzzZ

Copy link
Copy Markdown
Contributor

Tested 57a7ce703 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 with the MSVC 14.44 STL, RelWithDebInfo: pass.

Built d3d12_d16_depth_resolve_test and ran ctest -R ^d3d12_d16_depth_resolve$: passes. With main's runtime/shims/d3d12_vulkan_device.cpp and this test it fails: ResolveSubresourceRegion refused: neither an average colour resolve nor a depth or stencil one the device can replay, then every case reports Close 0x80070057 (expected 0x00000000), depth differs (D16 and R16_TYPELESS as R16_UNORM, MIN, MAX and AVERAGE, both rects).

No game files. AI-assisted (Claude Code).

@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

Checked against native D3D12 on an RTX 4070 Ti SUPER (debug layer on; standalone program outside the repo): 4x MSAA D16_UNORM or R16_TYPELESS source cleared to 0.25 with a half-screen triangle at 0.75, so edge pixels mix both depths.

  • Format R16_UNORM: Close S_OK for MIN, MAX and AVERAGE, on both resource formats, whole subresource and sub-rect; at an edge pixel MIN 16384, MAX 49151, AVERAGE 32768.
  • Format D16_UNORM: MIN/MAX S_OK; AVERAGE E_INVALIDARG (debug message 878, "D16_UNORM does not support MSAA resolve").
  • Format R16_TYPELESS: E_INVALIDARG for all three modes (878).
  • No device removal; nothing from the debug layer on the accepted cases.

That matches d3d12_vulkan_device.cpp:8405 with the AVERAGE check at :8431: R16_UNORM never matches the D16 image in color_resolve_format_matches (:8387), so it takes the depth path (d3d12_com.cpp:658) and vulkan_replay.h:1960-1965 resolves through a real depth attachment (the driver lists AVERAGE in supportedDepthResolveModes).

Optional: a refusal case for Format = DXGI_FORMAT_R16_TYPELESS in d3d12_d16_depth_resolve_test.cpp's refused[] (already rejected by the typeless checks at :8383 and :8414).

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants