Skip to content

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

Closed
jujumoneylol wants to merge 1 commit into
ProjectLeonida:mainfrom
jujumoneylol:pr/d3d12-depth-bounds
Closed

jujumoneylol wants to merge 1 commit into
ProjectLeonida:mainfrom
jujumoneylol:pr/d3d12-depth-bounds

Conversation

@jujumoneylol

Copy link
Copy Markdown
Contributor

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

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)

@sodove

sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…nd multi-scissor rendering (1..16 viewports/scissors)

Resolved against ProjectLeonida#499's emit_graphics_pass, ProjectLeonida#469's depth bounds and ProjectLeonida#511's lazy modules: the viewport/scissor setup moves into emit_graphics_pass, the pipeline's dynamic-state list keeps DEPTH_BOUNDS and picks the *_WITH_COUNT states, and ProjectLeonida#499's ExecuteIndirect draws now carry the bound depth bounds and viewports like record_draw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…nd depth bounds (ProjectLeonida#469), like record_draw

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Sangonapou

Copy link
Copy Markdown
Contributor

Build failure at b75e451 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.

@towade

towade commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

@aslan2142

Copy link
Copy Markdown
Collaborator

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:

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:

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

@aslan2142 aslan2142 closed this Nov 24, 2026
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.

5 participants