Skip to content

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

Merged
QemmHD merged 2 commits into
ProjectLeonida:mainfrom
sodove:fix/d3d12-clear-depth-range
Nov 24, 2026
Merged

QemmHD merged 2 commits into
ProjectLeonida:mainfrom
sodove:fix/d3d12-clear-depth-range

Conversation

@sodove

@sodove sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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 c023a36, 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).

@kawaii-shakal

Copy link
Copy Markdown
Contributor

Review of head d336fc9 (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.

@sodove

sodove commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

@quartz-heron-58

Copy link
Copy Markdown
Contributor

Tested 76033b0 (both commits, cherry-picked onto main 1c93c86) together with #540's c9f4a56 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 d42773d: 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).

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…es (D3D-CLEAR-DEPTH-RANGE)

# Conflicts:
#	runtime/test/vk_test_device.h
@LewisCodesWebsites

Copy link
Copy Markdown

Tested 76033b0 (cherry-picked onto main 21625bc) 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.

@bvtterbroot

Copy link
Copy Markdown

Tested 76033b0 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.

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

@kawaii-shakal

Copy link
Copy Markdown
Contributor

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

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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
QemmHD merged commit 3f20394 into ProjectLeonida:main Nov 24, 2026
1 check passed
QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** VK-SAMPLER-UNNORM-BIAS: an unnormalized-coordinates sampler gets mipLodBias 0, which VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074 requires. kawaii-shakal ran it under ASan/UBSan and showed the new check fails on main.

**Why it's good:** gfx10_descriptors and d3d12_descriptor pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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 added a commit that referenced this pull request Nov 24, 2026
…opy-clear-stage

Merging.

**Why merged:** OLD-10048: SYNC_COPY maps to COPY|CLEAR, so WriteBufferImmediate (vkCmdUpdateBuffer) and the query zero-fill are ordered before later copies. moffington reproduced the read-after-write hazard on the base, and Timon360SB and SweatierKey checked it independently. Part K of vk_command_replay_test covers it.

**Why it's good:** vk_command_replay, d3d12_state_map and replay_query_edges pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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 added a commit that referenced this pull request Nov 24, 2026
…dup-wait

Merging.

**Why merged:** RT-RETIRE-TICKETS-DEDUP-WAIT: pending_through() merges entries per semaphore to the highest value, and completed_ can no longer move backwards. moffington (ASan/UBSan, with a differential test that fails on the base), Timon360SB, KernelSmoker and SweatierKey checked it independently.

**Why it's good:** retire_tickets passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. 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 71f99e2: 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).
@sodove

sodove commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

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

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