d3d12: use legal Vulkan depth clear values (D3D-CLEAR-DEPTH-RANGE) #516

Manually merged
github merged 2 commits from gh-pr/516/head into gh-pr/516/base 2026-11-26 09:05:19 +00:00
Owner

@⁠sodove on GitHub · 2026-11-24 06:48 UTC · original
sodove:fix/d3d12-clear-depth-range → main · +57 −21 · 8 files · 2 commits · merged 2026-11-24 18:38 UTC

Claimed in the coordination issue as: D3D-CLEAR-DEPTH-RANGE (#14)

What and why

This addresses the depth-clear half of #506. Both full and rectangle clears currently pass unrestricted float depth values to Vulkan on devices that did not enable VK_EXT_depth_range_unrestricted, triggering VUID-VkClearDepthStencilValue-depth-00022.

Enable the extension on standalone devices that advertise it and carry the enabled capability through caller-owned device info to replay. With the extension, float depth clears can preserve the requested value. Without it, replay clamps depth to [0, 1] and uses 0 for NaN. The existing D16 and emulated D24 conversions still apply. The new restricted-depth CTest covers a device created without the extension even on hardware that supports it.

The edge-value test overlaps with #307, which addresses AMD drivers that canonicalize NaN. The mesh query issue in #506 is separate.

Tested

Windows 11 26100.7623, MSVC 19.44.35220 Release, Vulkan validation layer 1.4.369 with LEONIDA_VK_VALIDATION=1.

  • On main c023a365, d3d12_clear reports four instances of the VUID. With the fix, it passes with no validation errors, with 232 full and rectangle readbacks matching WARP and the float edge cases matching bit for bit.
  • d3d12_clear_restricted_depth fails before the fix and passes after it. It checks the finite out-of-range and NaN cases for full and rectangle clears, plus a zero-flag no-op.
  • vk_command_replay and d3d12_depth_view_format_support also pass. Four targeted tests in total.

GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 610.74, Windows 11.

AI-assisted: yes (OpenAI Codex).

Checklist

  • Based on current main.
  • One topic.
  • No game data, keys or decryption. All tests use synthetic fixtures.
  • New translator rule (not applicable).
**@⁠sodove** on GitHub · 2026-11-24 06:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516) `sodove:fix/d3d12-clear-depth-range` → `main` · +57 −21 · 8 files · 2 commits · merged 2026-11-24 18:38 UTC Claimed in the coordination issue as: D3D-CLEAR-DEPTH-RANGE ([#14](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)) ### What and why This addresses the depth-clear half of #506. Both full and rectangle clears currently pass unrestricted float depth values to Vulkan on devices that did not enable VK_EXT_depth_range_unrestricted, triggering VUID-VkClearDepthStencilValue-depth-00022. Enable the extension on standalone devices that advertise it and carry the enabled capability through caller-owned device info to replay. With the extension, float depth clears can preserve the requested value. Without it, replay clamps depth to [0, 1] and uses 0 for NaN. The existing D16 and emulated D24 conversions still apply. The new restricted-depth CTest covers a device created without the extension even on hardware that supports it. The edge-value test overlaps with #307, which addresses AMD drivers that canonicalize NaN. The mesh query issue in #506 is separate. ### Tested Windows 11 26100.7623, MSVC 19.44.35220 Release, Vulkan validation layer 1.4.369 with LEONIDA_VK_VALIDATION=1. - On main c023a365, d3d12_clear reports four instances of the VUID. With the fix, it passes with no validation errors, with 232 full and rectangle readbacks matching WARP and the float edge cases matching bit for bit. - d3d12_clear_restricted_depth fails before the fix and passes after it. It checks the finite out-of-range and NaN cases for full and rectangle clears, plus a zero-flag no-op. - vk_command_replay and d3d12_depth_view_format_support also pass. Four targeted tests in total. GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 610.74, Windows 11. AI-assisted: yes (OpenAI Codex). ### Checklist - [x] Based on current main. - [x] One topic. - [x] No game data, keys or decryption. All tests use synthetic fixtures. - [ ] New translator rule (not applicable).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:05:16 +00:00
github manually merged commit 86b069f1d9 into gh-pr/516/base 2026-11-26 09:05:19 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 07:54 UTC · original

Review of head d336fc9970 (read-only; Linux, g++, no GPU, no Windows/MSVC).

What ran:

  • g++ -std=c++20 -fsyntax-only on a TU that includes runtime/src/vulkan_replay.h (Vulkan-Headers): compiles cleanly; <algorithm> and <cmath> are already included for std::clamp / std::isnan.
  • Read the diff with the clear path in emit (vulkan_replay.h ~3616), quantize_unorm, depth24_clear_value and both device creators.

Findings:

  • The clamp is right for the spec: without VK_EXT_depth_range_unrestricted, VkClearDepthStencilValue::depth must be in [0, 1] for both vkCmdClearDepthStencilImage and vkCmdClearAttachments, float formats included. The one computed value feeds both the full and the rect path, so both are covered.
  • D16 and D24 cannot reach the new branch out of range: quantize_unorm already maps NaN and <= 0 to 0 and >= 1 to 1, and depth24_clear_value quantises first. So the branch only changes behaviour for D32 / D32S8, which is the intended case.
  • With the extension enabled, D32 out-of-range values and NaN go through as given. That matches the WARP parity the test asserts (check_depth_clear_edge_values). Note (reasoning, not run): Microsoft's ClearDepthStencilView page says depth "will be clamped between 0 and 1". This PR follows WARP's measured behaviour, which is a reasonable choice, but the docs entry could say that D3D12 documents a clamp and WARP does not apply one.
  • Only create_vulkan_device_standalone detects and enables the extension. The create_vulkan_device(info, ...) path (used by tests) keeps the default false, so it clamps. That is safe, just worth knowing.

Not tested: no build of the shims or d3d12_clear_test (Windows only), no GPU run of either CTest entry, no run on a driver without the extension.


Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 07:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7125511713) Review of head d336fc99708bb704134d7e7951bf186485a7f6fa (read-only; Linux, g++, no GPU, no Windows/MSVC). What ran: - `g++ -std=c++20 -fsyntax-only` on a TU that includes `runtime/src/vulkan_replay.h` (Vulkan-Headers): compiles cleanly; `<algorithm>` and `<cmath>` are already included for `std::clamp` / `std::isnan`. - Read the diff with the clear path in `emit` (vulkan_replay.h ~3616), `quantize_unorm`, `depth24_clear_value` and both device creators. Findings: - The clamp is right for the spec: without `VK_EXT_depth_range_unrestricted`, `VkClearDepthStencilValue::depth` must be in [0, 1] for both `vkCmdClearDepthStencilImage` and `vkCmdClearAttachments`, float formats included. The one computed `value` feeds both the full and the rect path, so both are covered. - D16 and D24 cannot reach the new branch out of range: `quantize_unorm` already maps NaN and <= 0 to 0 and >= 1 to 1, and `depth24_clear_value` quantises first. So the branch only changes behaviour for D32 / D32S8, which is the intended case. - With the extension enabled, D32 out-of-range values and NaN go through as given. That matches the WARP parity the test asserts (`check_depth_clear_edge_values`). Note (reasoning, not run): Microsoft's ClearDepthStencilView page says depth "will be clamped between 0 and 1". This PR follows WARP's measured behaviour, which is a reasonable choice, but the docs entry could say that D3D12 documents a clamp and WARP does not apply one. - Only `create_vulkan_device_standalone` detects and enables the extension. The `create_vulkan_device(info, ...)` path (used by tests) keeps the default `false`, so it clamps. That is safe, just worth knowing. Not tested: no build of the shims or `d3d12_clear_test` (Windows only), no GPU run of either CTest entry, no run on a driver without the extension. --- _Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account._
Author
Owner

@⁠sodove on GitHub · 2026-11-24 08:17 UTC · original · edited 2026-11-24 10:04 UTC

Updated the depth-clear notes in 76033b0 to record the documented clamp and measured behavior. On Windows 11 build 26100, native D3D12 on the RTX 5070 Ti (610.74) and WARP agreed bit for bit on all 45 D32_FLOAT texels. This included out-of-range finite values, quiet NaN, and the zero-flags case. Both native paths preserved the raw values in full and rectangle clears.

The caller-owned device path uses the capability supplied in VulkanDeviceInfo. The two clear tests exercise it with the extension enabled and disabled, respectively. Both clear tests, vk_command_replay, and d3d12_depth_view_format_support passed again with validation enabled. All fixtures were synthetic. AI-assisted.

Rechecked 76033b0 applied to upstream main 21625bc on the same Windows RTX 5070 Ti with Khronos Vulkan validation 1.4.369. Both depth-clear tests, the 251 format comparisons against WARP, and both replay-query tests passed with zero validation errors. The RGB9E5 render-target case skipped because the adapter does not expose RGB9E5 render targets. AI-assisted verification.

**@⁠sodove** on GitHub · 2026-11-24 08:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7125955181) · edited 2026-11-24 10:04 UTC Updated the depth-clear notes in 76033b0 to record the documented clamp and measured behavior. On Windows 11 build 26100, native D3D12 on the RTX 5070 Ti (610.74) and WARP agreed bit for bit on all 45 D32_FLOAT texels. This included out-of-range finite values, quiet NaN, and the zero-flags case. Both native paths preserved the raw values in full and rectangle clears. The caller-owned device path uses the capability supplied in VulkanDeviceInfo. The two clear tests exercise it with the extension enabled and disabled, respectively. Both clear tests, vk_command_replay, and d3d12_depth_view_format_support passed again with validation enabled. All fixtures were synthetic. AI-assisted. Rechecked 76033b0 applied to upstream main 21625bc on the same Windows RTX 5070 Ti with Khronos Vulkan validation 1.4.369. Both depth-clear tests, the 251 format comparisons against WARP, and both replay-query tests passed with zero validation errors. The RGB9E5 render-target case skipped because the adapter does not expose RGB9E5 render targets. AI-assisted verification.
Author
Owner

@⁠quartz-heron-58 on GitHub · 2026-11-24 08:42 UTC · original

Tested 76033b01 (both commits, cherry-picked onto main 1c93c869) together with #540's c9f4a569 on an NVIDIA GeForce RTX 4080 (driver 621.24, Vulkan 1.4.357), Windows 11 Home build 26300, MSVC 14.44 / RelWithDebInfo, built with scripts\build_runtime.ps1: pass. The three commits applied on top of each other without conflicts.

With LEONIDA_VK_VALIDATION=1, ctest -R "^d3d12_(clear|mesh)|replay_query":

Before, on a build of main d42773d0: d3d12_clear and d3d12_mesh fail with the seven errors of #506 (4x VUID-VkClearDepthStencilValue-depth-00022, 3x VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076).

With the three commits: d3d12_clear, d3d12_clear_restricted_depth, d3d12_mesh, d3d12_clear_formats, replay_query_predication and replay_query_edges all pass, 6 of 6, with no VUID line in the output. The same six pass without validation.

Limits: the two PRs were tested together, not each alone; only these six tests were run, not the whole ctest suite; the before and after builds are 24 commits of main apart. No game files.

AI-assisted (Claude Code built, ran the tests and wrote this comment).

**@⁠quartz-heron-58** on GitHub · 2026-11-24 08:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7126453695) Tested 76033b01 (both commits, cherry-picked onto main 1c93c869) together with #540's c9f4a569 on an NVIDIA GeForce RTX 4080 (driver 621.24, Vulkan 1.4.357), Windows 11 Home build 26300, MSVC 14.44 / RelWithDebInfo, built with `scripts\build_runtime.ps1`: pass. The three commits applied on top of each other without conflicts. With `LEONIDA_VK_VALIDATION=1`, `ctest -R "^d3d12_(clear|mesh)|replay_query"`: Before, on a build of main d42773d0: `d3d12_clear` and `d3d12_mesh` fail with the seven errors of #506 (4x VUID-VkClearDepthStencilValue-depth-00022, 3x VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076). With the three commits: `d3d12_clear`, `d3d12_clear_restricted_depth`, `d3d12_mesh`, `d3d12_clear_formats`, `replay_query_predication` and `replay_query_edges` all pass, 6 of 6, with no VUID line in the output. The same six pass without validation. Limits: the two PRs were tested together, not each alone; only these six tests were run, not the whole ctest suite; the before and after builds are 24 commits of main apart. No game files. AI-assisted (Claude Code built, ran the tests and wrote this comment).
Author
Owner

@⁠LewisCodesWebsites on GitHub · 2026-11-24 11:53 UTC · original

Tested 76033b01b (cherry-picked onto main 21625bca8) on AMD Radeon 660M (RDNA2 iGPU), Adrenalin 32.0.21045.1000, Windows 11 26200: the new d3d12_clear_restricted_depth passes. d3d12_clear still fails, but only on the NaN-depth rows (layer clears to 1, expected NaN), which is the AMD driver behaviour #307 reports, so I'd say that's not from this PR. AI-assisted.

**@⁠LewisCodesWebsites** on GitHub · 2026-11-24 11:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7130690141) Tested 76033b01b (cherry-picked onto main 21625bca8) on AMD Radeon 660M (RDNA2 iGPU), Adrenalin 32.0.21045.1000, Windows 11 26200: the new `d3d12_clear_restricted_depth` passes. `d3d12_clear` still fails, but only on the NaN-depth rows (layer clears to 1, expected NaN), which is the AMD driver behaviour #307 reports, so I'd say that's not from this PR. AI-assisted.
Author
Owner

@⁠bvtterbroot on GitHub · 2026-11-24 12:02 UTC · original

Tested 76033b01 on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2 (32.0.32029.2010), Vulkan 1.4.359, Windows 11, Vulkan SDK 1.4.363.0: the validation errors are gone, but d3d12_clear stays red on AMD.

  • With LEONIDA_VK_VALIDATION=1: the 4 x VUID-VkClearDepthStencilValue-depth-00022 that main 21625bca reports are gone. The new d3d12_clear_restricted_depth passes.
  • d3d12_clear still fails, with and without validation, as it does on main: a NaN depth clear reads back as 1 in all 15 texels (depth clear with NaN (0,0): layer cleared 1, expected nan). 1.5 and -0.5 are stored as given (5x3 depth texels matched (WARP parity)). So AMD's driver turns a NaN clear value into 1.0 even with VK_EXT_depth_range_unrestricted enabled, which is the behaviour draft #307 describes. The NaN expectation probably needs the vendor note #307 proposes, or the layer needs another way to store NaN.
  • Together with #540 (local merge of both heads on main 21625bca): full ctest 299/304; the 5 failures are the same 5 as on main (vk_queue_query_sync, d3d12_texture_tiles, d3d12_execute_indirect_validation, d3d12_clear, d3d12_pipeline_library_host), so nothing new.

No game files. AI-assisted (Claude Code ran the builds and tests).

**@⁠bvtterbroot** on GitHub · 2026-11-24 12:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7130870940) Tested 76033b01 on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2 (32.0.32029.2010), Vulkan 1.4.359, Windows 11, Vulkan SDK 1.4.363.0: the validation errors are gone, but `d3d12_clear` stays red on AMD. - With `LEONIDA_VK_VALIDATION=1`: the 4 x `VUID-VkClearDepthStencilValue-depth-00022` that `main` 21625bca reports are gone. The new `d3d12_clear_restricted_depth` passes. - `d3d12_clear` still fails, with and without validation, as it does on `main`: a NaN depth clear reads back as `1` in all 15 texels (`depth clear with NaN (0,0): layer cleared 1, expected nan`). 1.5 and -0.5 are stored as given (`5x3 depth texels matched (WARP parity)`). So AMD's driver turns a NaN clear value into 1.0 even with `VK_EXT_depth_range_unrestricted` enabled, which is the behaviour draft #307 describes. The NaN expectation probably needs the vendor note #307 proposes, or the layer needs another way to store NaN. - Together with #540 (local merge of both heads on `main` 21625bca): full `ctest` 299/304; the 5 failures are the same 5 as on `main` (`vk_queue_query_sync`, `d3d12_texture_tiles`, `d3d12_execute_indirect_validation`, `d3d12_clear`, `d3d12_pipeline_library_host`), so nothing new. No game files. AI-assisted (Claude Code ran the builds and tests).
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 14:25 UTC · original

Tested commit 76033b01 (built from that commit alone, RelWithDebInfo, MSVC 19.50) on an NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 26300, with Vulkan validation enabled (LEONIDA_VK_VALIDATION=1). Both d3d12_clear and d3d12_clear_restricted_depth passed:

  • normal path: depth clears with 1.5, -0.5 and NaN matched WARP on all 5x3 texels each, and all 232 full and rectangle RTV/DSV readbacks matched WARP;
  • restricted path: the same inputs matched the restricted-depth expectations;
  • clear flags 0 left the depth target alone in both runs.

The PR is currently marked conflicting with main, so this is the branch as it stands, not a merge result.

— Codex (tests), posted by Claude

**@⁠kawaii-shakal** on GitHub · 2026-11-24 14:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7134351167) Tested commit `76033b01` (built from that commit alone, RelWithDebInfo, MSVC 19.50) on an NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 26300, with Vulkan validation enabled (`LEONIDA_VK_VALIDATION=1`). Both `d3d12_clear` and `d3d12_clear_restricted_depth` passed: - normal path: depth clears with 1.5, -0.5 and NaN matched WARP on all 5x3 texels each, and all 232 full and rectangle RTV/DSV readbacks matched WARP; - restricted path: the same inputs matched the restricted-depth expectations; - clear flags 0 left the depth target alone in both runs. The PR is currently marked conflicting with `main`, so this is the branch as it stands, not a merge result. — Codex (tests), posted by Claude
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 18:38 UTC · original

Merging.

Why merged: D3D-CLEAR-DEPTH-RANGE: enables VK_EXT_depth_range_unrestricted where the device has it, so depth clears outside [0,1] (and NaN) behave like D3D12 instead of being clamped. Without the extension it keeps clamping, and NaN becomes 0. Four independent passes; on AMD (660M, 7900 XTX), d3d12_clear still fails only on the NaN rows, which is the driver issue tracked in #307, not this PR.

Why it's good: On the 4070 SUPER with validation on, main's d3d12_clear_test exits 1 with 4x VUID-VkClearDepthStencilValue-depth-00022. With this PR it exits 0 with no VUIDs, and the 1.5 / -0.5 / NaN clears match WARP. The new d3d12_clear_restricted_depth passes, and so do d3d12_clear and d3d12_clear_formats.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 32950551e, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be34. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e224: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 18:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7140924692) Merging. **Why merged:** D3D-CLEAR-DEPTH-RANGE: enables VK_EXT_depth_range_unrestricted where the device has it, so depth clears outside [0,1] (and NaN) behave like D3D12 instead of being clamped. Without the extension it keeps clamping, and NaN becomes 0. Four independent passes; on AMD (660M, 7900 XTX), d3d12_clear still fails only on the NaN rows, which is the driver issue tracked in #307, not this PR. **Why it's good:** On the 4070 SUPER with validation on, main's d3d12_clear_test exits 1 with 4x VUID-VkClearDepthStencilValue-depth-00022. With this PR it exits 0 with no VUIDs, and the 1.5 / -0.5 / NaN clears match WARP. The new d3d12_clear_restricted_depth passes, and so do d3d12_clear and d3d12_clear_formats. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 32950551e, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be34. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e224: no conflicts, and none of these touch the files #891/#882 changed. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠sodove on GitHub · 2026-11-25 08:59 UTC · original

For the developer role on the project Discord: my Discord username is sodove.

**@⁠sodove** on GitHub · 2026-11-25 08:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/516#issuecomment-7157734783) For the developer role on the project Discord: my Discord username is sodove.
This discussion has been locked. Commenting is limited to contributors.
No description provided.