Skip to content

Runtime: OMSetDepthBounds on Vulkan dynamic state (ID3D12GraphicsCommandList1) - #819

Open
TheHoracio wants to merge 1 commit into
ItsNotRexed:mainfrom
TheHoracio:cmdlist1-depth-bounds
Open

TheHoracio wants to merge 1 commit into
ItsNotRexed:mainfrom
TheHoracio:cmdlist1-depth-bounds

Conversation

@TheHoracio

@TheHoracio TheHoracio commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #634: #634 (comment)

Based on main 003e7812 (#291 has landed); one commit.

What and why

ID3D12GraphicsCommandList1::OMSetDepthBounds was a logging stub, and no open PR touched it. Depth bounds are what deferred lighting and shadow passes use to skip pixels whose stored depth is outside a light's range.

  • Recording (d3d12_com.cpp): the list keeps [min, max], [0, 1] by default, and every Draw carries it. Values are clamped to [0, 1]: D3D12 requires that range (the debug layer reports others), and so does Vulkan without VK_EXT_depth_range_unrestricted (VUID-vkCmdSetDepthBounds-minDepthBounds-00600). NaN becomes 0. min > max is kept as given, because both APIs then reject every sample. Reset and ClearState restore [0, 1].
  • Pipeline (d3d12_vulkan_device.cpp): GraphicsPipelineExtras::depth_bounds_test turns on depthBoundsTestEnable and adds VK_DYNAMIC_STATE_DEPTH_BOUNDS. The plain D3D12_GRAPHICS_PIPELINE_STATE_DESC has no such field, so CreateGraphicsPipelineState never turns it on. A new create_graphics_pipeline_state(device, desc, extras, ...) is what a stream's D3D12_DEPTH_STENCIL_DESC1::DepthBoundsTestEnable should map to once D3D-29 (CreatePipelineState) lands.
  • Feature: a new VulkanDeviceInfo::depth_bounds field. The standalone device and vk_test_device.h now enable depthBounds where the GPU has it. Without the feature, a depth-bounds PSO is refused with E_INVALIDARG, as D3D12 does when OPTIONS2.DepthBoundsTestSupported is FALSE.
  • Replay (vulkan_replay.h): vkCmdSetDepthBounds runs only for pipelines that have the test on, so pipelines with static state never see it (VUID-vkCmdDrawIndexed-None-08608).
  • Docs: docs/d3d12_vulkan.md gets a row in the command-list table and a "Depth bounds" bullet under the graphics PSO.

Not in this PR

  • SetSamplePositions and SetViewInstanceMask, from the same claim. The first needs MSAA pipelines, which the draw path refuses today. The second needs view instancing from a pipeline state stream (D3D-29). Both stay stubs for now.
  • OPTIONS2.DepthBoundsTestSupported should stay FALSE (D3D-86: answer CheckFeatureSupport OPTIONS2-5, 7, 9, 11, 13-16, 18-21 #775) until an application can reach the test through CreatePipelineState. After that it can report VulkanDeviceInfo::depth_bounds.

Tested

AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32015.7029, Windows 11 Pro (26300), MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo, LEONIDA_VK_VALIDATION=1:

  • d3d12_depth_bounds_test (new, GPU): the D32_FLOAT depth target is cleared to 0.25 on its left half and 0.75 on its right half, with the depth test off. Four quadrant draws:

    • bounds [0.5, 1] reject 0.25 and pass 0.75;
    • a PSO without the test ignores the bounds;
    • bounds (-1 → 0, 0.5) reject 0.75.

    All 4,096 pixels match, with 0 validation errors.

  • Negative control: with depthBoundsTestEnable forced off in the PSO, the test fails at pixel (0, 0) (red instead of blue).

  • d3d12_gcl1_test (new, CPU): QueryInterface for GCL1, the method at vtable slot 62 (d3d12.h 10.0.26100), clamping, NaN, min > max, and the ClearState/Reset defaults.

  • Regression: ctest 16/16. d3d12_draw_test and d3d12_compute_test pass with 0 validation errors.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. All fixtures are synthetic.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A: runtime only, no translator change.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 961c754 on AMD RDNA2 iGPU and RTX 5070: pass (first RDNA2 and NVIDIA runs; the PR was tested on an RX 7800 XT).

Windows 11 Home 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo (scripts\build_runtime.ps1), LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~. One PC, two GPUs, picked with VK_LOADER_DRIVERS_SELECT: AMD Radeon iGPU of a Ryzen 7 9800X3D (RDNA2, 1002:13C0, AMD 2026.04.17, subgroup 32..64) and NVIDIA GeForce RTX 5070 (Blackwell, 617.42, subgroup 32).

  • d3d12_depth_bounds_test (run directly, it is not in ctest): on both GPUs, four draws matched all 4096 pixels: bounds [0.5, 1] reject 0.25 and pass 0.75, a PSO without the test ignores them, clamped [0, 0.5] rejects 0.75, exit 0, no validation errors.
  • d3d12_gcl1: passes on both.
  • ctest: RTX 5070 34/34; AMD iGPU 33/34. The AMD d3d12_vulkan_device failure is not from this PR: it is OPTIONS19.SupportedSampleCountsWithNoOutputs: ours 0xf not subset of host 0x1d, which this branch's base still has and main has since fixed (no-output sample counts without 2x).

AI-assisted (Claude Code). No game files.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

One Vulkan valid-usage issue at 961c75431b551b1e30538637400eaf0283c3e6df: an inverted depth interval has defined D3D12 semantics, but forwarding the pair to Vulkan is invalid. The D3D12 spec requires the depth-bounds test to fail for all samples when min > max. Vulkan explicitly requires min ≤ max in VUID-vkCmdSetDepthBounds-minDepthBounds-10912. DirectX depth-bounds spec · vkCmdSetDepthBounds valid usage

I exercised the PR's four-quadrant synthetic draw through its command-list proxy and added a test-only observer at Vulkan function dispatch. With a bounded PSO and OMSetDepthBounds(0.75f, 0.25f), both the RTX 5080 and Radeon runs reached vkCmdSetDepthBounds(commandBuffer, 0.75f, 0.25f) once. I intercepted the call before the driver and substituted legal bounds only to finish the test. The inverted-range finding is the observed dispatch arguments, independent of any driver-specific pixel result. Production source at runtime/src/vulkan_replay.h:2094 forwards these fields unchanged.

As a positive control, genuine equal bounds (0.75,0.75) passed stored D32 depth 0.75 and rejected 0.25. All 4,096 RGBA8 pixels matched on each GPU with validation enabled, including the unbounded PSO drawing green. A regression should require that an inverted interval leaves the bounded draw's color unchanged while an unbounded PSO still draws, covers the equal-bound case, and sends no inverted Vulkan command. Mapping both endpoints to the same value would accidentally admit stored depth equal to that endpoint.

@TheHoracio

Copy link
Copy Markdown
Contributor Author

@Vonsek, thanks, and @UlteriorMotive00, thanks for the RDNA2 and NVIDIA runs. Fixed in 6c3aad57, now rebased onto main 003e7812 (after #291 landed):

  • Inverted interval: when a bounded pipeline's min > max, the replay sends legal bounds (0, 1) and an empty scissor for that draw. Every sample fails as D3D12 requires, the draw's vertex work still happens, and vkCmdSetDepthBounds never sees an inverted pair. I didn't map both ends to one value, for the reason you gave.

  • Test (d3d12_depth_bounds_test, now registered in ctest with SKIP_RETURN_CODE 77): a second list on the same split depth target.

    • Equal bounds (0.25, 0.25) pass the stored 0.25.
    • (0.75, 0.75) rejects 0.25.
    • Inverted (0.75, 0.25) leaves the bounded draw's colour unchanged.
    • An unbounded PSO with the inverted bounds still set draws.

    All 4,096 pixels match in both lists, with 0 validation errors (RX 7800 XT, 26.10.1).

  • Negative control: with the old forwarding put back, validation reports VUID-vkCmdSetDepthBounds-minDepthBounds-10912 and the test fails.

  • Regression: ctest -j4 103/105. The two failures, d3d12_vulkan_device (line 3403, allocation_mismatches) and d3d12_draw (VUID-vkDestroyPipeline-pipeline-00765), fail the same way on clean main 003e7812 on this machine.

The rebase also uses VulkanDeviceInfo::features.depthBounds instead of a separate field. AI-assisted.

@TheHoracio

Copy link
Copy Markdown
Contributor Author

Rebased onto main 49475796 as 7d1bccf5. The only conflicts were the device-function X-list (now vkCmdSetDepthBounds next to main's vkQueueBindSparse) and GraphicsPipeline (depth_bounds_test next to samples from #831). Full ctest: 118/118 pass, 0 validation errors. Windows 11 Pro 26300, RX 7800 XT + Radeon iGPU (AMD Adrenalin), MSVC 19.4x, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1. AI-assisted.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head 7d1bccf merged onto main 4947579 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 118 | new failures vs main: none. The main baseline on the same machine passes 116/116, so nothing regresses here.

AI-assisted (Claude Code); runs on my machine.

@TheHoracio

Copy link
Copy Markdown
Contributor Author

@Dom-in, thanks for the RX 9070 run. Rebased onto main ec8ec4c9 (round 40) as 3f48aa46. Two conflicts needed more than keeping both sides:

  • CachedPSO check: main's new check (pipeline_key + check_cached_pso + set_cache_key) now lives in create_graphics_pipeline(), the function this PR split out of CreateGraphicsPipelineState. The pipeline-state-stream path therefore gets the check too.
  • stencil_ref_set_: main dropped this unused member, so it stays dropped.

The rest kept both sides: d3d12_bundle_test next to d3d12_depth_bounds_test, recorded_commands() next to depth_bounds(), and bindless_room() next to create_graphics_pipeline_state(). Full ctest -j 8 with LEONIDA_VK_VALIDATION=1: 123/123 pass. Windows 11 Pro 26300, RX 7800 XT + Radeon iGPU (AMD 26.10.1), MSVC 19.4x, Vulkan SDK 1.4.363.0. AI-assisted.

…andList1)

The list keeps the bounds (clamped to [0, 1], NaN as 0, reset by Reset and
ClearState) and every draw carries them; a pipeline with the depth-bounds test
gets VK_DYNAMIC_STATE_DEPTH_BOUNDS and the replay applies them with
vkCmdSetDepthBounds. GraphicsPipelineExtras::depth_bounds_test is what a
stream's D3D12_DEPTH_STENCIL_DESC1 DepthBoundsTestEnable maps to; it needs the
depthBounds feature (VulkanDeviceInfo::depth_bounds), which the standalone and
test devices now enable where present, and is refused with E_INVALIDARG
without it.

Tests: d3d12_gcl1_test (CPU: slot 62, clamping, defaults) and
d3d12_depth_bounds_test (GPU: four draws against a split depth target).

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

Copy link
Copy Markdown
Contributor Author

Rebased onto main f847748c as ca9ebb2e.

  • Draw: main inlined it (D3D-289: arrays and render_target_count, moved into the list), so depth_bounds_min/max are two more inline fields, and the draw is still std::moved.
  • X-list: vkCmdSetDepthBounds sits next to main's event functions.
  • Docs: the depth-bounds bullet sits between main's geometry-shader bullet and the refused list.

Full ctest -j 8: 134/134. Windows 11 Pro 26300, RX 7800 XT + Radeon iGPU (AMD 26.10.1), MSVC 19.4x, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1. AI-assisted.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested ca9ebb2 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 143/143.
  • d3d12_depth_bounds and d3d12_gcl1: pass 20 of 20 runs, and pass under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

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