Repository navigation
d3d12/vulkan: write NaN depth clears with a copy on AMD (D3D-CLEAR-NAN-DEPTH) - #787
bvtterbroot wants to merge 4 commits into
Conversation
The AMD Vulkan driver stores 1.0 for a NaN depth clear value in vkCmdClearDepthStencilImage and vkCmdClearAttachments, even with VK_EXT_depth_range_unrestricted (RX 7900 XTX on 26.11.2, RX 9070 XT on 26.10.1). D3D12 keeps the quiet NaN, so d3d12_clear fails on AMD. For a NaN clear of a D32_FLOAT or D32_FLOAT_S8X24_UINT depth plane, fill transfer scratch with the value's bits and copy it into each cleared rectangle (depth aspect only). The stencil aspect stays a clear. d3d12_clear_test gains D32_S8 cases with NaN and stencil, and checks stencil texels against WARP as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflict with #540 in d3d12_vulkan_device.cpp: keep both mesh_queries and set_depth_range_unrestricted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested head Setup: Windows 11 10.0.26200.9974, AMD 26.11.2, Vulkan SDK 1.4.363.0, MSVC 19.44,
So the driver behaviour is the same on RDNA2, RDNA3 (your 7900 XTX) and RDNA4, and the copy path covers all three. I also read the runtime diff (
No game files. AI-assisted: yes |
|
Tested 0d69d1b applied onto main 23c4596 on an AMD Radeon RX 7900 XT: d3d12_clear fails on main (NaN depth clear reads back 1.0) and passes with this PR, 3/3 runs. The new d3d12_clear_restricted_depth passes 3/3. No new failures in the full ctest run. Hardware/software: AMD Radeon RX 7900 XT (RDNA3), AMD driver 32.0.32029.2010 (Adrenalin 26.11.2, Vulkan 1.4.359, offers VK_EXT_depth_range_unrestricted), Windows 11 build 26300, VS 2022 (x64, RelWithDebInfo), Vulkan SDK 1.4.363.0. Build: Targeted tests, 3 runs each on main and on the PR (third run with
On main, d3d12_clear fails in the NaN depth case: all 15 texels of the 5x3 D32_FLOAT target read back 1.0 where WARP has NaN: With validation on, main also reports 4 errors for VUID-VkClearDepthStencilValue-depth-00022 (depth 1.5, -0.5 and NaN passed to vkCmdClearDepthStencilImage / vkCmdClearAttachments without VK_EXT_depth_range_unrestricted enabled). With the PR, every d3d12_clear run prints: and d3d12_clear_restricted_depth prints the same five depth lines with "(restricted Vulkan depth)", i.e. 1.5/-0.5 clamped to 1/0 and NaN stored as 0. The validation-on runs of all four tests report no validation errors. Unchanged on both trees: d3d12_clear_formats "251 matched WARP, 0 differ, 0 failed", d3d12_rgb9e5_rtv "full and rectangle clears match all 15 packed texels". Full ctest on the PR build, once:
The four remaining failures also fail on main and are unrelated to depth clears. Skipped/disabled tests are the same 13 on both. Note: |
|
Independent GPU verification on a second AMD RDNA2 device (plus NVIDIA cross-check). AI-assisted verification by Devin. Setup
AMD Radeon iGPU (RDNA2 gfx1035, driver 24.10.24, Vulkan 1.3.280)NVIDIA RTX 4070 SUPERResultsAMD iGPU — NaN depth clearBaseline All 15 NaN-clear texels read back as PR head Wider NVIDIA RTX 4070 SUPER
Regression sweep (AMD iGPU, PR head)
VerdictVerified on a second AMD device: the fill + buffer-to-image copy path fixes NaN depth clears on RDNA2 gfx1035 / driver 24.10.24, not just RDNA3. Before/after on the same machine is unambiguous: |
On AMD,
d3d12_clearstays red even with #516: AMD's Vulkan driver stores 1.0 for a NaN depth clear value, so a D3D12 clear that WARP and native D3D12 store as NaN comes back as 1.0. This writes such a clear with a copy, which the driver does not touch, so the layer matches WARP on every vendor.Builds on #516 (its two commits are the first two here; the change is the last commit). D3D-CLEAR-NAN-DEPTH, follow-up to #506. Supersedes the test-only draft #307, which reports the same driver behaviour on an RX 9070 XT.
What changes
runtime/src/vulkan_replay.h: withVK_EXT_depth_range_unrestrictedenabled, a depth clear whose value is NaN on aD32_SFLOATorD32_SFLOAT_S8_UINTdepth plane is avkCmdFillBufferof the value's 32 bits into transfer scratch (one rectangle's worth,copy_scratch), then onevkCmdCopyBufferToImageregion per cleared rectangle (the whole mip without rectangles), on the depth aspect only. A stencil cleared in the same call is still a clear, of the stencil aspect alone. Every other clear is unchanged, and without the extension NaN is still cleared to 0 as d3d12: use legal Vulkan depth clear values (D3D-CLEAR-DEPTH-RANGE) #516 does.runtime/test/d3d12_clear_test.cpp: two more edge cases onD32_FLOAT_S8X24_UINTwith DEPTH | STENCIL: NaN with stencil 0x11 / 0x22 in the rectangle, and NaN then 0.5 in the rectangle. Depth and stencil are checked against WARP and the expected value, in both the unrestricted and the--restricted-depthrun.docs/d3d12_vulkan.md: the driver behaviour and the copy, under "Depth clears".Tested
AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2 (32.0.32029.2010), Vulkan 1.4.359, Windows 11, MSVC 14.44, Vulkan SDK 1.4.363.0. No game files.
main21625bc):d3d12_clearfails with and withoutLEONIDA_VK_VALIDATION=1, all 15 texelsdepth clear with NaN (0,0): layer cleared 1, expected nan.d3d12_clear,d3d12_clear_restricted_depth,d3d12_clear_formatsandd3d12_rgb9e5_rtvpass, 3 runs each with and withoutLEONIDA_VK_VALIDATION=1, no validation messages.depth clear with NaN: 5x3 depth texels matched (WARP parity),D32_S8 clear with NaN and stencil: 5x3 depth and stencil texels matched (WARP parity).d3d12_clearfails again withlayer cleared 1, expected nan.ctest: 300/304. The 4 failures are onmainon this PC too and are tracked elsewhere:vk_queue_query_sync(OLD-6149),d3d12_texture_tiles,d3d12_execute_indirect_validation(d3d12_execute_indirect_validation: 5 rows where the layer rejects and live WARP and hardware accept (over-strict, not permissive) #504),d3d12_pipeline_library_host(finding in Coordinating who works on what #14).mainhasd3d12_clearas a fifth.python -Itests/test_ctest_registration.py,test_docs_list_items.py,test_docs_repeated_lines.py,test_docs_table_ids.py,test_exe_checklist.py: pass.scripts/check_no_game_data.pyon the changed files: exit 0.Not tested: NVIDIA and Intel. There the copy replaces a clear that already stored NaN, so the result should not change, but a run with
ctest -R d3d12_clearon one of them would confirm it.AI-assisted (Claude Code wrote the change and ran the tests).
🤖 Generated with Claude Code