d3d12: use legal Vulkan depth clear values (D3D-CLEAR-DEPTH-RANGE) #516
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!516
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/516/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCClaimed 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.
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.GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 610.74, Windows 11.
AI-assisted: yes (OpenAI Codex).
Checklist
@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-onlyon a TU that includesruntime/src/vulkan_replay.h(Vulkan-Headers): compiles cleanly;<algorithm>and<cmath>are already included forstd::clamp/std::isnan.emit(vulkan_replay.h ~3616),quantize_unorm,depth24_clear_valueand both device creators.Findings:
VK_EXT_depth_range_unrestricted,VkClearDepthStencilValue::depthmust be in [0, 1] for bothvkCmdClearDepthStencilImageandvkCmdClearAttachments, float formats included. The one computedvaluefeeds both the full and the rect path, so both are covered.quantize_unormalready maps NaN and <= 0 to 0 and >= 1 to 1, anddepth24_clear_valuequantises first. So the branch only changes behaviour for D32 / D32S8, which is the intended case.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.create_vulkan_device_standalonedetects and enables the extension. Thecreate_vulkan_device(info, ...)path (used by tests) keeps the defaultfalse, 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 on GitHub · 2026-11-24 08:17 UTC · original · edited 2026-11-24 10:04 UTC
Updated the depth-clear notes in
76033b0to 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
76033b0applied to upstream main21625bcon 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 on GitHub · 2026-11-24 08:42 UTC · original
Tested
76033b01(both commits, cherry-picked onto main1c93c869) together with #540'sc9f4a569on an NVIDIA GeForce RTX 4080 (driver 621.24, Vulkan 1.4.357), Windows 11 Home build 26300, MSVC 14.44 / RelWithDebInfo, built withscripts\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_clearandd3d12_meshfail 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_predicationandreplay_query_edgesall 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).
@LewisCodesWebsites on GitHub · 2026-11-24 11:53 UTC · original
Tested
76033b01b(cherry-picked onto main21625bca8) on AMD Radeon 660M (RDNA2 iGPU), Adrenalin 32.0.21045.1000, Windows 11 26200: the newd3d12_clear_restricted_depthpasses.d3d12_clearstill 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 on GitHub · 2026-11-24 12:02 UTC · original
Tested
76033b01on 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, butd3d12_clearstays red on AMD.LEONIDA_VK_VALIDATION=1: the 4 xVUID-VkClearDepthStencilValue-depth-00022thatmain21625bcareports are gone. The newd3d12_clear_restricted_depthpasses.d3d12_clearstill fails, with and without validation, as it does onmain: a NaN depth clear reads back as1in 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 withVK_EXT_depth_range_unrestrictedenabled, 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.main21625bca): fullctest299/304; the 5 failures are the same 5 as onmain(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).
@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). Bothd3d12_clearandd3d12_clear_restricted_depthpassed: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 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 main955d9be34. 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 main71f99e224: 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 on GitHub · 2026-11-25 08:59 UTC · original
For the developer role on the project Discord: my Discord username is sodove.