d3d12/vulkan: implement hardware depth-bounds testing (D3D-DEPTH-BOUNDS) #469

Closed
github-bot wants to merge 1 commit from gh-pr/469/head into gh-pr/469/base
Owner

@⁠jujumoneylol on GitHub · 2026-11-24 05:54 UTC · original
jujumoneylol:pr/d3d12-depth-bounds → main · +605 −36 · 12 files · 1 commits · closed without merging

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

What and why

Implements hardware depth-bounds testing end-to-end in the D3D12 → Vulkan runtime, clearing one of the live frame-loop PSO stream refusals recorded in docs/retail_boot_intel_host.md section 3 (depth-bounds stream subobject):

  • Vulkan device feature: enables VkPhysicalDeviceFeatures::depthBounds where advertised by the GPU in create_vulkan_device_standalone (runtime/shims/d3d12_vulkan_device.cpp) and vktest::Device (runtime/test/vk_test_device.h), exposing it through VulkanDeviceInfo::features.depthBounds.
  • Feature query: reports D3D12_FEATURE_DATA_D3D12_OPTIONS2::DepthBoundsTestSupported = state_.info.features.depthBounds ? TRUE : FALSE instead of hardcoded FALSE.
  • Pipeline state stream (DEPTH_STENCIL1 / DEPTH_STENCIL2):
    • parse_pipeline_stream records DepthBoundsTestEnable from D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1 and DEPTH_STENCIL2 instead of unconditionally returning E_NOTIMPL.
    • PipelineState::create_graphics enables VkPipelineDepthStencilStateCreateInfo::depthBoundsTestEnable, refuses with E_NOTIMPL only when VulkanDeviceInfo::features.depthBounds is false, and appends VK_DYNAMIC_STATE_DEPTH_BOUNDS to the dynamic state list (for both regular and mesh PSOs) when enabled.
  • Command list & replay (OMSetDepthBounds → vkCmdSetDepthBounds):
    • Implements ID3D12GraphicsCommandList1::OMSetDepthBounds(Min, Max) in runtime/shims/d3d12_com.cpp (defaults to [0.0f, 1.0f] on create/reset, refused in bundles per D3D12 spec), carries (depth_bounds_min, depth_bounds_max) on leonida::Draw for both vertex and mesh draws, and replays vkCmdSetDepthBounds (clamped to [0.0f, 1.0f] / NaN-safe for Vulkan spec compliance) in runtime/src/vulkan_replay.h.
  • Tests:
    • Adds self-contained runtime/test/d3d12_depth_bounds_test.cpp (in-memory SPIR-V 1.3 fullscreen VS + solid PS, no external shader compiler needed) verifying feature reporting, feature-off E_NOTIMPL refusal, bundle refusal, and 8 live GPU draw cases compared pixel-for-pixel against the host Windows D3D12 runtime on the same adapter.
    • Updates d3d12_vulkan_device_test (OPTIONS2.DepthBoundsTestSupported invariant + toggle test), d3d12_mesh_test (DepthBoundsTestEnable follows vk.enabled.depthBounds), and replay_cpu_bench.

Tested

  • Built d3d12_depth_bounds_test, d3d12_vulkan_device_test, and replay_cpu_bench with MSVC 19.44 (vcvars64) + Ninja on top of main 8f481cf16.
  • d3d12_depth_bounds_test: ALL 8 CASES PASSED (EXACT MATCH vs host D3D12) on NVIDIA GeForce GTX 1650 (DepthBoundsTestSupported=TRUE), matching host pixels bit-for-bit across default [0.0, 1.0], [0.25, 0.75] pass, [0.6, 0.9] reject, [0.1, 0.4] reject, [0.5, 0.5] inclusive boundary pass, DEPTH_STENCIL2 pass/reject, and Reset() restoring [0.0, 1.0], plus feature-off E_NOTIMPL and bundle refusal checks.
  • d3d12_vulkan_device_test: PASSED (including new OPTIONS2.DepthBoundsTestSupported host parity and toggle check).
  • py -3.13 -I scripts/check_no_game_data.py on all 12 touched files: clean.

GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — D3D12 → Vulkan runtime only)
**@⁠jujumoneylol** on GitHub · 2026-11-24 05:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/469) `jujumoneylol:pr/d3d12-depth-bounds` → `main` · +605 −36 · 12 files · 1 commits · closed without merging Claimed in the coordination issue as: D3D-DEPTH-BOUNDS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Implements hardware depth-bounds testing end-to-end in the D3D12 → Vulkan runtime, clearing one of the live frame-loop PSO stream refusals recorded in `docs/retail_boot_intel_host.md` section 3 (depth-bounds stream subobject): - **Vulkan device feature**: enables `VkPhysicalDeviceFeatures::depthBounds` where advertised by the GPU in `create_vulkan_device_standalone` (`runtime/shims/d3d12_vulkan_device.cpp`) and `vktest::Device` (`runtime/test/vk_test_device.h`), exposing it through `VulkanDeviceInfo::features.depthBounds`. - **Feature query**: reports `D3D12_FEATURE_DATA_D3D12_OPTIONS2::DepthBoundsTestSupported = state_.info.features.depthBounds ? TRUE : FALSE` instead of hardcoded `FALSE`. - **Pipeline state stream (`DEPTH_STENCIL1` / `DEPTH_STENCIL2`)**: - `parse_pipeline_stream` records `DepthBoundsTestEnable` from `D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1` and `DEPTH_STENCIL2` instead of unconditionally returning `E_NOTIMPL`. - `PipelineState::create_graphics` enables `VkPipelineDepthStencilStateCreateInfo::depthBoundsTestEnable`, refuses with `E_NOTIMPL` only when `VulkanDeviceInfo::features.depthBounds` is false, and appends `VK_DYNAMIC_STATE_DEPTH_BOUNDS` to the dynamic state list (for both regular and mesh PSOs) when enabled. - **Command list & replay (`OMSetDepthBounds` → `vkCmdSetDepthBounds`)**: - Implements `ID3D12GraphicsCommandList1::OMSetDepthBounds(Min, Max)` in `runtime/shims/d3d12_com.cpp` (defaults to `[0.0f, 1.0f]` on create/reset, refused in bundles per D3D12 spec), carries `(depth_bounds_min, depth_bounds_max)` on `leonida::Draw` for both vertex and mesh draws, and replays `vkCmdSetDepthBounds` (clamped to `[0.0f, 1.0f]` / NaN-safe for Vulkan spec compliance) in `runtime/src/vulkan_replay.h`. - **Tests**: - Adds self-contained `runtime/test/d3d12_depth_bounds_test.cpp` (in-memory SPIR-V 1.3 fullscreen VS + solid PS, no external shader compiler needed) verifying feature reporting, feature-off `E_NOTIMPL` refusal, bundle refusal, and 8 live GPU draw cases compared pixel-for-pixel against the host Windows D3D12 runtime on the same adapter. - Updates `d3d12_vulkan_device_test` (`OPTIONS2.DepthBoundsTestSupported` invariant + toggle test), `d3d12_mesh_test` (`DepthBoundsTestEnable` follows `vk.enabled.depthBounds`), and `replay_cpu_bench`. ### Tested - Built `d3d12_depth_bounds_test`, `d3d12_vulkan_device_test`, and `replay_cpu_bench` with MSVC 19.44 (`vcvars64`) + Ninja on top of `main` `8f481cf16`. - `d3d12_depth_bounds_test`: **ALL 8 CASES PASSED (EXACT MATCH vs host D3D12)** on NVIDIA GeForce GTX 1650 (`DepthBoundsTestSupported=TRUE`), matching host pixels bit-for-bit across default `[0.0, 1.0]`, `[0.25, 0.75]` pass, `[0.6, 0.9]` reject, `[0.1, 0.4]` reject, `[0.5, 0.5]` inclusive boundary pass, `DEPTH_STENCIL2` pass/reject, and `Reset()` restoring `[0.0, 1.0]`, plus feature-off `E_NOTIMPL` and bundle refusal checks. - `d3d12_vulkan_device_test`: PASSED (including new `OPTIONS2.DepthBoundsTestSupported` host parity and toggle check). - `py -3.13 -I scripts/check_no_game_data.py` on all 12 touched files: clean. GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — D3D12 → Vulkan runtime only)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:02:19 +00:00
github-bot closed this pull request 2026-11-26 09:02:19 +00:00
Author
Owner

@⁠sodove on GitHub · 2026-11-24 08:30 UTC · original

Independent Windows review of b75e451 applied to main 1c93c86. RTX 5070 Ti (610.74), Windows 11 26100.7623, MSVC Release, Vulkan validation 1.4.369. The eight stock cases passed. The following differences reproduced in two runs of an extended synthetic fixture against native D3D12 on the same adapter.

  1. NaN in Max. The layer drew where native D3D12 kept the clear color. This happened with only Max set to NaN and with both bounds set to NaN. The Min-only control matched. Replay currently substitutes 1.0 for NaN Max. Both arguments are documented to convert NaN to zero. Microsoft API reference
  2. Inverted range. Both paths kept the clear color, but Vulkan validation reported VUID-vkCmdSetDepthBounds-minDepthBounds-10912. D3D12 requires an inverted range to reject samples. Vulkan requires ordered arguments. D3D12 depth-bounds spec · Vulkan valid usage
  3. Setter inside a bundle. Bundle Close returned E_INVALIDARG on the layer and S_OK on native D3D12. On native D3D12 the range set by the bundle rejected the subsequent direct draw, confirming that the state persists. As controls, both paths inherited the bound range correctly into a bundle containing only a draw. D3D12 bundle semantics

The no-depth-attachment control also rendered identically. The extended run failed its validation check on the inverted range. All fixtures were synthetic. AI-assisted.

**@⁠sodove** on GitHub · 2026-11-24 08:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/469#issuecomment-7126210843) Independent Windows review of b75e451 applied to main 1c93c86. RTX 5070 Ti (610.74), Windows 11 26100.7623, MSVC Release, Vulkan validation 1.4.369. The eight stock cases passed. The following differences reproduced in two runs of an extended synthetic fixture against native D3D12 on the same adapter. 1. **NaN in Max.** The layer drew where native D3D12 kept the clear color. This happened with only Max set to NaN and with both bounds set to NaN. The Min-only control matched. Replay currently substitutes 1.0 for NaN Max. Both arguments are documented to convert NaN to zero. [Microsoft API reference](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist1-omsetdepthbounds) 2. **Inverted range.** Both paths kept the clear color, but Vulkan validation reported VUID-vkCmdSetDepthBounds-minDepthBounds-10912. D3D12 requires an inverted range to reject samples. Vulkan requires ordered arguments. [D3D12 depth-bounds spec](https://microsoft.github.io/DirectX-Specs/d3d/DepthBoundsTest.html#detailed-design) · [Vulkan valid usage](https://docs.vulkan.org/spec/latest/chapters/fragops.html#VUID-vkCmdSetDepthBounds-minDepthBounds-10912) 3. **Setter inside a bundle.** Bundle Close returned E_INVALIDARG on the layer and S_OK on native D3D12. On native D3D12 the range set by the bundle rejected the subsequent direct draw, confirming that the state persists. As controls, both paths inherited the bound range correctly into a bundle containing only a draw. [D3D12 bundle semantics](https://microsoft.github.io/DirectX-Specs/d3d/DepthBoundsTest.html#detailed-design) The no-depth-attachment control also rendered identically. The extended run failed its validation check on the inverted range. All fixtures were synthetic. AI-assisted.
Author
Owner

@⁠Sangonapou on GitHub · 2026-11-24 15:01 UTC · original

Build failure at b75e4518 with MSVC on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows

Built with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files.

The build stops in the new test code (two builds, same result):

FAILED: CMakeFiles/d3d12_mesh_test.dir/test/d3d12_mesh_test.cpp.obj
runtime\test\d3d12_mesh_test.cpp(271): error C2065: 'vk': undeclared identifier

Line 271 is if (vk.enabled.depthBounds) {; the only Vulkan device in that file is vktest::Device d; (line 99), and nothing named vk is in scope there, so d3d12_depth_bounds_test and the rest could not be run. Happy to test again once it builds; this card reports depthBounds, so it would take the SUCCEEDED branch.

**@⁠Sangonapou** on GitHub · 2026-11-24 15:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/469#issuecomment-7135339147) Build failure at b75e4518 with MSVC on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows Built with `scripts\build_runtime.ps1` (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files. The build stops in the new test code (two builds, same result): ``` FAILED: CMakeFiles/d3d12_mesh_test.dir/test/d3d12_mesh_test.cpp.obj runtime\test\d3d12_mesh_test.cpp(271): error C2065: 'vk': undeclared identifier ``` Line 271 is `if (vk.enabled.depthBounds) {`; the only Vulkan device in that file is `vktest::Device d;` (line 99), and nothing named `vk` is in scope there, so `d3d12_depth_bounds_test` and the rest could not be run. Happy to test again once it builds; this card reports `depthBounds`, so it would take the `SUCCEEDED` branch.
Author
Owner

@⁠towade on GitHub · 2026-11-24 16:56 UTC · original

checked: b75e45189 in a retail boot on an AMD Radeon RX 9070 XT (RDNA4, 32.0.32029.2010), Windows 11 26300, MSVC 19.44, own 1.0.2.1 copy. Base: main d0da7dade + #511 (LEONIDA_LAZY_PSO=1) + the open boot pull requests of my ladder on #14, --trace --trace-d3d12, network blocked. This PR cherry-picked on top without a conflict. Counts only.

without this PR with it
CreatePipelineState unsupported 25,682 (whole run) 25,462
ok calls 56,837 57,052
CreatePipelineState refused in the last 600 log lines before the run's end 216 0 (2 failed, other causes)

Before this PR, the only reason logged near the end was depth-bounds tests are not supported yet; stream subobject 21, logged once. With it, that line is gone and the burst of refused pipelines just before the stop goes with it. The run still ends at the same later stop in the title, which this PR doesn't touch, so I can't say whether those pipelines draw correctly.

Not run: the synthetic depth-bounds tests on this GPU, #815 (which covers the same ground).

AI-assisted (Claude Code).

**@⁠towade** on GitHub · 2026-11-24 16:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/469#issuecomment-7138432669) checked: `b75e45189` in a retail boot on an **AMD Radeon RX 9070 XT** (RDNA4, 32.0.32029.2010), Windows 11 26300, MSVC 19.44, own 1.0.2.1 copy. Base: `main` `d0da7dade` + #511 (`LEONIDA_LAZY_PSO=1`) + the open boot pull requests of my [ladder on #14](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14), `--trace --trace-d3d12`, network blocked. This PR cherry-picked on top without a conflict. Counts only. | | without this PR | with it | |---|---:|---:| | `CreatePipelineState` `unsupported` | 25,682 (whole run) | 25,462 | | `ok` calls | 56,837 | 57,052 | | `CreatePipelineState` refused in the last 600 log lines before the run's end | 216 | 0 (2 `failed`, other causes) | Before this PR, the only reason logged near the end was `depth-bounds tests are not supported yet; stream subobject 21`, logged once. With it, that line is gone and the burst of refused pipelines just before the stop goes with it. The run still ends at the same later stop in the title, which this PR doesn't touch, so I can't say whether those pipelines draw correctly. Not run: the synthetic depth-bounds tests on this GPU, #815 (which covers the same ground). AI-assisted (Claude Code).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:50 UTC · original

Thanks for this, and for the host pixel-parity test. We're going with #815 for D3D-DEPTH-BOUNDS, because it is the more correct fix right now:

  • Bundles: Microsoft's command-list restriction table lists OMSetDepthBounds as valid in a bundle. Here it fails the bundle's Close(); #815 records it through defer() and checks it against the host in d3d12_bundle_forbidden.
  • Build: d3d12_mesh_test.cpp:272 uses vk.enabled.depthBounds, but only d is in scope (C2065, as reported above).
  • NaN Max: it is replayed as 1.0, so the layer draws where native D3D12 rejects; the docs convert NaN to 0.
  • Docs: #815 also updates docs/d3d12_vulkan.md.

Your branch has things #815 lacks, and they'd be worth porting as a follow-up on top of #815. You'd be welcome to open it:

  • d3d12_depth_bounds_test.cpp, the only draw-level host comparison, with its bundle block inverted to expect S_OK;
  • the OPTIONS2.DepthBoundsTestSupported toggle check;
  • your NaN-Min handling (NaN becomes 0), which is more correct than #815's empty range.

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

**@⁠aslan2142** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/469#issuecomment-7142662196) Thanks for this, and for the host pixel-parity test. We're going with #815 for D3D-DEPTH-BOUNDS, because it is the more correct fix right now: - **Bundles:** Microsoft's [command-list restriction table](https://learn.microsoft.com/en-us/windows/win32/direct3d12/recording-command-lists-and-bundles#command-list-api-restrictions) lists `OMSetDepthBounds` as valid in a bundle. Here it fails the bundle's `Close()`; #815 records it through `defer()` and checks it against the host in `d3d12_bundle_forbidden`. - **Build:** `d3d12_mesh_test.cpp:272` uses `vk.enabled.depthBounds`, but only `d` is in scope (C2065, as reported above). - **NaN Max:** it is replayed as 1.0, so the layer draws where native D3D12 rejects; the [docs](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist1-omsetdepthbounds) convert NaN to 0. - **Docs:** #815 also updates `docs/d3d12_vulkan.md`. Your branch has things #815 lacks, and they'd be worth porting as a follow-up on top of #815. You'd be welcome to open it: - `d3d12_depth_bounds_test.cpp`, the only draw-level host comparison, with its bundle block inverted to expect `S_OK`; - the `OPTIONS2.DepthBoundsTestSupported` toggle check; - your NaN-Min handling (NaN becomes 0), which is more correct than #815's empty range. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.