Skip to content

d3d12: support hardware depth-bounds testing and OMSetDepthBounds - #815

Open
kotekompotek wants to merge 1 commit into
ProjectLeonida:mainfrom
kotekompotek:work/d3d12-depth-bounds-test
Open

kotekompotek wants to merge 1 commit into
ProjectLeonida:mainfrom
kotekompotek:work/d3d12-depth-bounds-test

Conversation

@kotekompotek

@kotekompotek kotekompotek commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

What and why

  • Rebased onto current main.
  • Implemented hardware depth-bounds testing (DEPTH_STENCIL1/DEPTH_STENCIL2 DepthBoundsTestEnable, VK_DYNAMIC_STATE_DEPTH_BOUNDS, ID3D12GraphicsCommandList1::OMSetDepthBounds, OPTIONS2::DepthBoundsTestSupported).
  • Updated OMSetDepthBounds in runtime/shims/d3d12_com.cpp to support bundles via defer() and match D3D12 Close() == S_OK on <0, >1, min>max, and NaN (sanitized cleanly to Vulkan [0, 1] or empty [1, 0] in runtime/src/vulkan_replay.h).
  • Wired info.features.depthBounds = d.enabled.depthBounds in d3d12_mesh_test.cpp and d3d12_vulkan_device_test.cpp; expanded d3d12_com_test.cpp, d3d12_bundle_forbidden_test.cpp, d3d12_close_parity_test.cpp, and synced docs/d3d12_vulkan.md.

Tested

  • d3d12_com: Passed.
  • d3d12_bundle_forbidden: 11/11 vs host GTX 1050 & WARP (0 failures).
  • d3d12_close_parity: all 5 OMSetDepthBounds cases match WARP.
  • d3d12_vulkan_device (compare_feature_options): 32 feature queries, 0 mismatches.
  • d3d12_mesh_test.cpp compiled /W4, and test_ctest_registration.py + test_docs_*.py: OK.

GPUs tested: NVIDIA GeForce GTX 1050 (driver 582.28, Windows) & Microsoft Basic Render Driver (WARP)

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.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean-Room Peer Review for PR #815 (d3d12: support hardware depth-bounds testing and OMSetDepthBounds)

Comprehensive technical evaluation of D3D12 <-> Vulkan dynamic depth-bounds translation:

  • API Specification Parity:
    • GraphicsCommandList::OMSetDepthBounds strictly adheres to ID3D12GraphicsCommandList1 spec.
    • Correctly rejects command bundles (D3D12_COMMAND_LIST_TYPE_BUNDLE) via check(false).
    • Rigorous range validation: !(min >= 0.0f && max <= 1.0f && min <= max) guards against inverted or out-of-range bounds, including NaN values.
    • State reset (
      eset_state) restores default [0.0f, 1.0f] range on pipeline recycling.
  • Vulkan Backend Replay Integration:
    • prepare_draw guards against unsupported depth-bounds test requests if �k.set_depth_bounds function pointer is absent.
    • emit accurately binds dynamic state via �k.set_depth_bounds(command_buffer, draw->min_depth_bounds, draw->max_depth_bounds).
  • Test Suite Verification:

untime/test/d3d12_com_test.cpp: Verified retrieval and storage of dynamic depth bounds [0.25f, 0.75f].

untime/test/d3d12_mesh_test.cpp: Dynamic capability query against D3D12_FEATURE_D3D12_OPTIONS2::DepthBoundsTestSupported.

untime/test/d3d12_vulkan_device_test.cpp: Local invariant checks updated.

  • Clean-room verification: Zero game data, strict C++20 compliance, clean MSVC/Clang compatibility.

LGTM! Excellent implementation and test coverage. Approved.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean-room verified (zero game data). Complete implementation of D3D12 depth-bounds testing: OPTIONS2 feature query, ID3D12GraphicsCommandList1::OMSetDepthBounds, dynamic state wiring in Vulkan context via depthBounds / vkCmdSetDepthBounds, and comprehensive tests.

@kotekompotek
kotekompotek force-pushed the work/d3d12-depth-bounds-test branch from c947f05 to 2f9bee4 Compare November 24, 2026 15:10
@moffington

Copy link
Copy Markdown
Contributor

Reviewed 2f9bee487 on RTX 3060 / Linux / Wine 11.20 with Vulkan validation enabled.

All five focused regression tests passed on baseline and HEAD. Independent pixel readback also confirmed correct depth-bounds clipping, default bounds, ClearState reset, pipeline switching, and no-DSV draws. Feature-disabled handling worked as expected.

Found two API compatibility issues:

No draw-time or pipeline-creation Vulkan validation errors observed. Native Windows parity was not tested.

@Sangonapou

Copy link
Copy Markdown
Contributor

Tested 2f9bee4 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: the three tests pass, but the depth-bounds path itself is not reached on this GPU

Built at this head with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0); llvm-mc 23.1.6, SPIRV-Tools 2026.4. No game files.

  • d3d12_com, d3d12_mesh, d3d12_vulkan_device (ctest, verbose): all pass, e.g. COM list/queue/fence: 16 colour, depth and stencil texels matched and DispatchMesh over X, Y and Z and a stream VS draw matched all 4096 pixels.
  • But in d3d12_mesh the runtime logs depth-bounds testing needs depthBounds, which the device lacks; enabled 1, i.e. the DepthBoundsTestEnable PSO is refused (d3d12_vulkan_device.cpp:3853, !features.depthBounds). This GPU does support it: vulkaninfo reports depthBounds = true. So the test passes through its "not supported" branch here and the enabled path (vkCmdSetDepthBounds, OMSetDepthBounds) is never exercised on capable hardware.
  • This is the native Windows run @moffington noted as untested above. Under Wine their pixel readback confirmed real depth-bounds clipping, so the difference looks like which features the native device enables, not the replay itself.
  • My guess, not checked further: enable.depthBounds = chosen_features.depthBounds (:9812) is in the standalone device's creation, while the device these tests run on is created without depthBounds in its enabled features, so device_.info.features.depthBounds stays false. Happy to rerun once that is sorted out.

@kotekompotek

Copy link
Copy Markdown
Contributor Author

@moffington @Sangonapou Thanks for the thorough review and WARP/bundle parity findings — addressed in b3ca7b584:

  • Updated OMSetDepthBounds in runtime/shims/d3d12_com.cpp to support bundles via defer() and match D3D12 Close() == S_OK on <0, >1, min>max, and NaN, sanitized cleanly to Vulkan [0, 1] or empty [1, 0] in runtime/src/vulkan_replay.h.
  • Wired info.features.depthBounds = d.enabled.depthBounds in d3d12_mesh_test.cpp and d3d12_vulkan_device_test.cpp.
  • Expanded d3d12_com_test.cpp, d3d12_bundle_forbidden_test.cpp, d3d12_close_parity_test.cpp, and docs/d3d12_vulkan.md.
  • Claimed D3D-DEPTH-BOUNDS in coordination issue #14: Coordinating who works on what #14 (comment)

Locally verified:

  • d3d12_com: Passed
  • d3d12_bundle_forbidden: 11/11 vs host GTX 1050 & WARP (0 failures)
  • d3d12_close_parity: all 5 OMSetDepthBounds cases match WARP
  • d3d12_vulkan_device compare_feature_options: 32 feature queries, 0 mismatches
  • d3d12_mesh_test.cpp compiled /W4, and test_ctest_registration.py + test_docs_*.py: OK

@aslan2142 aslan2142 removed the missing claim Needs a claim in #14 label Nov 24, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@kotekompotek: a data point on why this matters. fxceless/victory-fork (a VIctory fork that renders gameplay on an RTX 4070) just landed the same thing in its commit c96b4f2 ("The depth bounds test works"): pipelines with depth bounds created from a DEPTH_STENCIL1 stream, and the title's OMSetDepthBounds reaching the host list. Before that, those draws passed at every depth. Their note says the first gameplay room is now lit by its lamp for the first time.

On main the layer still reports DepthBoundsTestSupported = FALSE and refuses PSOs that enable it (d3d12_vulkan_device.cpp around 6317/6328, logged by d3d12_xs_pso_stream.cpp), so this PR is on the lighting path. It now conflicts with main (after #984). If you rebase it, I'll test the new head on Windows 11 / MSVC / RTX 4070 SUPER, where depthBounds is supported, so the path Sangonapou couldn't reach on the 3080 Ti Laptop should run here, and I'll post the results.

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

@QemmHD

QemmHD commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Retail data point for this PR: on main 3ff2a2a (native Windows 11, RTX 4070 SUPER), a 300 s boot to a first-run consent page logs 224 CreatePipelineState refusals for depth bounds, the most common PSO failure in the run. So every one of those draws is missing on main today. When you rebase, I'll A/B it on the same boot (refusal count, captures, and whether anything new appears on screen) and post the result here.

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

@kotekompotek
kotekompotek force-pushed the work/d3d12-depth-bounds-test branch from b3ca7b5 to efea973 Compare November 25, 2026 06:39
@kotekompotek

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (42537e7b6) as efea97331 — the conflict after #984 is resolved. The head now carries both sides: multiViewport + VK_DYNAMIC_STATE_*_WITH_COUNT and the stencil per-face masks from main, plus this PR's depthBounds feature gate, VK_DYNAMIC_STATE_DEPTH_BOUNDS and OMSetDepthBounds on direct lists and bundles. create_graphics now takes both the stream's StencilFaceMasks and the new GraphicsStreamExtras (depth-bounds flag), so a DEPTH_STENCIL1/2 stream no longer refuses DepthBoundsTestEnable — it is refused only when the device lacks VkPhysicalDeviceFeatures::depthBounds.

Verified locally on Windows / MSVC Debug (GTX 1050, driver 582.28): pso_stream, d3d12_com, d3d12_d24_support pass; d3d12_vulkan_device and d3d12_close_parity build clean and show the same two pre-existing main failures on this machine (the CreateHeap invalid-argument column on the GTX 1050 and the three CopyTextureRegion WARP-annotation rows — unrelated to this change). d3d12_mesh_test is not built here (no glslangValidator).

The head is ready for your RTX 4070 SUPER run — depthBounds is enabled there, so the 224-refusal path you logged should now take the hardware test.

AI-assisted.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@djrolfes

Copy link
Copy Markdown
Contributor

Independent integration review while preparing an RTX 3070 Ti / Linux Wine test of exact efea973 on main 42537e7 (+ separately owned startup fixes): the patch cherry-picks cleanly, but main’s on-demand console-stream realization looks like a missed propagation path. In runtime/shims/d3d12_vulkan_device.cpp, PipelineState::prepare at line ~7059 parses the retained stream and calls create_graphics(stream.graphics, &stream.ms, &stream.as) without stream.extras (or back_stencil). Your eager CreatePipelineState path does pass &stream.extras, so DepthBoundsTestEnable appears to be lost specifically when a pending console stream is realized. This is a code-path observation, not yet a GPU measurement.

I am preserving the exact patch in a separate local test tree and will check the focused synthetic path before retail use; not duplicating implementation ownership. The current runtime probes log 224 depth-bounds stream refusals without this PR, so the feature is relevant beyond conformance. No raw game-derived data included. AI-assisted.

@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Real-boot A/B of this PR at efea973 on Windows 11, RTX 4070 SUPER (NVIDIA 621.24). The tree also had #1558, and slot 57's native factory was turned off so that pipelines go through the stream path (the configuration that draws the pages correctly, see #939). Same shaders and settings with and without the PR.

  • Main doesn't already cover this. On main c7e82e2, CheckFeatureSupport(OPTIONS2) still reports DepthBoundsTestSupported = FALSE, and CreatePipelineState refuses every stream with the depth-bounds test on ("depth-bounds tests are not supported yet; stream subobject 21"): 225 refusals per boot, 3 of 3 runs. They only disappear when the slot 57 factory builds those pipelines instead, opaque, which is the picture regression on [integration] Windows offline boot to the first-run UI (RT-WINDOWS-FIRST-RUN-UI) #939.
  • With this PR: 0 depth-bounds refusals; successful stream pipelines go from 81,267 to 81,491 (+224, exactly the refused ones). Draws recorded in about 220 s go from 21,208-25,296 without it to 39,327 with it, and presents from 2,984-3,329 to 4,723. No new failure; the boot ends at the same later stop with or without it. Peak 19.5 GB private, 10.5 of 12 GB VRAM.
  • Not measured: no OMSetDepthBounds call appears before that stop, so the dynamic bounds stay at their defaults in this phase, and the screens that would use these pipelines visibly aren't reached yet. So this confirms it works and causes no regression, not a visual result.

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

@thiefyzheng

Copy link
Copy Markdown
Contributor

@djrolfes — picked up your finding as RT-DEPTHBOUNDS-STREAM-EXTRAS (claimed on #1608): #1695, branched from this PR's head efea9733 and Depends on: #815. It passes stream.back_masks?&stream.back_stencil:nullptr, &stream.extras at the resolve_type call site, and mixes those fields into the console path's pipeline cache key (prepare_console_stream hashed only the plain D3D12_DEPTH_STENCIL_DESC, so two console PSOs differing only in depth bounds — or back-face masks — collided). A regression test in d3d12_mesh_test draws a DEPTH_STENCIL1 DepthBoundsTestEnable stream through the lazy path inside OMSetDepthBounds(0,1) / (0.5,1).

Not compiled or GPU-confirmed on the author host; your RTX 3070 Ti / Wine plan would cover exactly the missing run when convenient.

@kotekompotek — welcome to fold #1695 into #815 directly instead of a stacked PR; say the word and I drop the branch. AI-assisted.

@kotekompotek

Copy link
Copy Markdown
Contributor Author

Status at efea97331: the two conformance gaps @moffington reported are both in — OMSetDepthBounds records through defer(...) so bundles accept it, and NaN/out-of-range bounds are accepted at record time and clamped inside Vulkan's 0..1 domain at replay (d3d12_com.cpp:929 comment covers both). Thanks @QemmHD for the 225-refusals A/B on the RTX 4070 SUPER and @Sangonapou for the 3080 Ti run — the "depthBounds not enabled on the test device" path is real, it's why the enabled branch only shows on capable hardware.

@thiefyzheng thanks for picking up @djrolfes's console-stream finding. I'd keep #1695 stacked with Depends on: #815 rather than folding it in: this head is what @QemmHD just A/B-tested, and a stacked PR keeps the cache-key/extras fix reviewable on its own. If a maintainer would rather have one PR I'll fold it in.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@kotekompotek
kotekompotek force-pushed the work/d3d12-depth-bounds-test branch from efea973 to a635392 Compare November 25, 2026 14:24
@kotekompotek

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (71a769d, post-#1671/#1691/#1703) — a635392c6. One conflict in d3d12_com.cpp record_mesh_draw: kept both the new min/max_depth_bounds_ Draw fields and main's note_direct_heap_indexing(graphics_.layout).

Local run on this box (GTX 1050, driver 582.28, Windows 11, Debug): d3d12_com PASS. Two failures in the run are baseline-on-this-host, not this change:

  • d3d12_vulkan_device heap_mismatches: this host's D3D12 runtime refuses every CreateHeap — handled by test: skip host CreateHeap comparison when the host refuses every heap #1721.
  • d3d12_close_parity: three CopyTextureRegion upload rows (offset 16, offset 4, row pitch 260) marked stricter now match WARP on current main — main's own table entries, my diff only adds the five OMSetDepthBounds cases (all match WARP, incl. NaN and out-of-range).

@djrolfes the conflict was mechanical; your lazy-path finding is covered separately by @thiefyzheng's #1695 stacked on this PR.

star41905453-coder added a commit to star41905453-coder/leonida that referenced this pull request Nov 26, 2026
…BOUNDS-ON-DEMAND-STREAM)

ProjectLeonida#815 adds the depth-bounds extras to create_graphics and passes them where a
stream is realized eagerly. A stream realized on demand (PipelineState::
set_pending_stream, resolved on first use) goes through a second call site
that passes neither the extras nor the back-face stencil masks, so a title
that binds a console PSO before it is realized silently loses
DepthBoundsTestEnable - the test is then always on and clips nothing.

Pass both at that call site.

Test (d3d12_mesh_test): a stream PSO with DEPTH_STENCIL1 DepthBoundsTestEnable.
Where the device has depthBounds, draw the full-screen triangle with bounds
0.9..1.0 and with 0.0..1.0: outside the bounds nothing may be painted, inside
the whole viewport must be. Where it has not (llvmpipe here, depthBounds =
false), the flag is refused - at creation, or at first use on an on-demand
device - and success would mean the flag was dropped.

Depends on: ProjectLeonida#815
star41905453-coder added a commit to star41905453-coder/leonida that referenced this pull request Nov 27, 2026
…BOUNDS-ON-DEMAND-STREAM)

A stream realized on demand (PipelineState::set_pending_stream, resolved on first
use) goes through a second create_graphics call site that passes neither the
depth-bounds flag nor the back-face stencil masks, so a title that binds a
console PSO before it is realized silently loses DepthBoundsTestEnable - the
test is then always on and clips nothing.

Pass both there, as the eager call site does.

Test (d3d12_mesh_test): the stream PSO with DepthBoundsTestEnable is now drawn
through. Depth is cleared to 0.0, outside the first bounds, so the test decides
and not the clear; the full-screen triangle is drawn with 0.9..1.0 (nothing may
paint) and 0.0..1.0 (the whole viewport must). The draws use their own readback
buffer, so the mesh image rows compared later are untouched. Where the device has
no depthBounds (llvmpipe here) the creation is refused instead and success would
mean the flag was dropped.

Depends on: ubiquitarianism#815
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants