[PR #787] [CLOSED] d3d12/vulkan: write NaN depth clears with a copy on AMD (D3D-CLEAR-NAN-DEPTH) #825

Closed
opened 2026-11-26 20:19:10 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/787
Author: @bvtterbroot
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: nan-depth-clear


📝 Commits (4)

  • d336fc9 d3d12: use legal Vulkan depth clear values (D3D-CLEAR-DEPTH-RANGE)
  • 76033b0 docs: record observed D3D12 depth clear semantics
  • d4dec7a d3d12/vulkan: write NaN depth clears with a copy (D3D-CLEAR-NAN-DEPTH)
  • 0d69d1b Merge main into nan-depth-clear

📊 Changes

8 files changed (+168 additions, -38 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+10 -0)
📝 runtime/CMakeLists.txt (+2 -1)
📝 runtime/shims/d3d12_com.h (+1 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+3 -0)
📝 runtime/src/vulkan_backend.h (+5 -0)
📝 runtime/src/vulkan_replay.h (+79 -8)
📝 runtime/test/d3d12_clear_test.cpp (+61 -29)
📝 runtime/test/vk_test_device.h (+7 -0)

📄 Description

On AMD, d3d12_clear stays 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: with VK_EXT_depth_range_unrestricted enabled, a depth clear whose value is NaN on a D32_SFLOAT or D32_SFLOAT_S8_UINT depth plane is a vkCmdFillBuffer of the value's 32 bits into transfer scratch (one rectangle's worth, copy_scratch), then one vkCmdCopyBufferToImage region 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 #516 does.
  • runtime/test/d3d12_clear_test.cpp: two more edge cases on D32_FLOAT_S8X24_UINT with 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-depth run.
  • 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.

  • Before (#516 at 76033b01, and main 21625bca): d3d12_clear fails with and without LEONIDA_VK_VALIDATION=1, all 15 texels depth clear with NaN (0,0): layer cleared 1, expected nan.
  • After: d3d12_clear, d3d12_clear_restricted_depth, d3d12_clear_formats and d3d12_rgb9e5_rtv pass, 3 runs each with and without LEONIDA_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).
  • Negative control: with the copy path switched off in the same build, d3d12_clear fails again with layer cleared 1, expected nan.
  • Full ctest: 300/304. The 4 failures are on main on this PC too and are tracked elsewhere: vk_queue_query_sync (OLD-6149), d3d12_texture_tiles, d3d12_execute_indirect_validation (#504), d3d12_pipeline_library_host (finding in #14). main has d3d12_clear as a fifth.
  • python -I tests/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.py on 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_clear on one of them would confirm it.

AI-assisted (Claude Code wrote the change and ran the tests).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/787 **Author:** [@bvtterbroot](https://github.com/bvtterbroot) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `nan-depth-clear` --- ### 📝 Commits (4) - [`d336fc9`](https://github.com/ubiquitarianism/leonida/commit/d336fc99708bb704134d7e7951bf186485a7f6fa) d3d12: use legal Vulkan depth clear values (D3D-CLEAR-DEPTH-RANGE) - [`76033b0`](https://github.com/ubiquitarianism/leonida/commit/76033b01b51bb7033ba2cb3941b0a55fc1951e69) docs: record observed D3D12 depth clear semantics - [`d4dec7a`](https://github.com/ubiquitarianism/leonida/commit/d4dec7a3d78dbcf1e96aa6eaa125eb80045da665) d3d12/vulkan: write NaN depth clears with a copy (D3D-CLEAR-NAN-DEPTH) - [`0d69d1b`](https://github.com/ubiquitarianism/leonida/commit/0d69d1be6d9d02744d2e4142db5a5681c895145b) Merge main into nan-depth-clear ### 📊 Changes **8 files changed** (+168 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+10 -0) 📝 `runtime/CMakeLists.txt` (+2 -1) 📝 `runtime/shims/d3d12_com.h` (+1 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+3 -0) 📝 `runtime/src/vulkan_backend.h` (+5 -0) 📝 `runtime/src/vulkan_replay.h` (+79 -8) 📝 `runtime/test/d3d12_clear_test.cpp` (+61 -29) 📝 `runtime/test/vk_test_device.h` (+7 -0) </details> ### 📄 Description On AMD, `d3d12_clear` stays 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`: with `VK_EXT_depth_range_unrestricted` enabled, a depth clear whose value is NaN on a `D32_SFLOAT` or `D32_SFLOAT_S8_UINT` depth plane is a `vkCmdFillBuffer` of the value's 32 bits into transfer scratch (one rectangle's worth, `copy_scratch`), then one `vkCmdCopyBufferToImage` region 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 #516 does. - `runtime/test/d3d12_clear_test.cpp`: two more edge cases on `D32_FLOAT_S8X24_UINT` with 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-depth` run. - `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. - Before (#516 at 76033b01, and `main` 21625bca): `d3d12_clear` fails with and without `LEONIDA_VK_VALIDATION=1`, all 15 texels `depth clear with NaN (0,0): layer cleared 1, expected nan`. - After: `d3d12_clear`, `d3d12_clear_restricted_depth`, `d3d12_clear_formats` and `d3d12_rgb9e5_rtv` pass, 3 runs each with and without `LEONIDA_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)`. - Negative control: with the copy path switched off in the same build, `d3d12_clear` fails again with `layer cleared 1, expected nan`. - Full `ctest`: 300/304. The 4 failures are on `main` on this PC too and are tracked elsewhere: `vk_queue_query_sync` (OLD-6149), `d3d12_texture_tiles`, `d3d12_execute_indirect_validation` (#504), `d3d12_pipeline_library_host` (finding in #14). `main` has `d3d12_clear` as a fifth. - `python -I` `tests/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.py` on 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_clear` on one of them would confirm it. AI-assisted (Claude Code wrote the change and ran the tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:10 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#825
No description provided.