From a635392c6b420ea690e45006b2c36711dccfefdb Mon Sep 17 00:00:00 2001 From: Pavel Kotek <334189328+kotekompotek@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:08:34 +0500 Subject: [PATCH] d3d12: support hardware depth-bounds testing and OMSetDepthBounds --- docs/d3d12_vulkan.md | 9 +++-- runtime/shims/d3d12_com.cpp | 34 +++++++++++++++++-- runtime/shims/d3d12_com.h | 3 ++ runtime/shims/d3d12_vulkan_device.cpp | 30 +++++++++++------ runtime/src/command_list.h | 2 ++ runtime/src/vulkan_backend.h | 3 +- runtime/src/vulkan_replay.h | 10 ++++++ runtime/test/d3d12_bundle_forbidden_test.cpp | 3 ++ runtime/test/d3d12_close_parity_test.cpp | 35 ++++++++++++++++++++ runtime/test/d3d12_com_test.cpp | 17 +++++++++- runtime/test/d3d12_mesh_test.cpp | 10 +++++- runtime/test/d3d12_vulkan_device_test.cpp | 3 +- runtime/test/vk_test_device.h | 1 + 13 files changed, 142 insertions(+), 18 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 53d9747968..fd9eeada23 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2452,7 +2452,11 @@ The trace will enumerate them. a VS stream builds the same PSO as the classic call. - `E_INVALIDARG`, as on the PC runtime: a type given twice, an unknown type, a truncated stream, MS with VS, tessellation or GS, CS with a graphics stage, or no stage at all. - - `E_NOTIMPL` with a log, for what is not built yet: an AS, a depth-bounds test, view instancing. + - `E_NOTIMPL` with a log, for what is not built yet: an AS, view instancing. + - `DEPTH_STENCIL1`/`DEPTH_STENCIL2` `DepthBoundsTestEnable` maps to hardware `depthBoundsTestEnable` + + `VK_DYNAMIC_STATE_DEPTH_BOUNDS` and `OMSetDepthBounds` — recorded on both direct lists and bundles, with + out-of-range/inverted/`NaN` bounds accepted at record time as on D3D12 and sanitized into Vulkan's `0..1` + range at replay — refusing with `E_NOTIMPL` when `VkPhysicalDeviceFeatures::depthBounds` is absent. - `DEPTH_STENCIL2`'s per-face read and write masks go to each face's `VkStencilOpState` (the front face's in the description, the back face's beside it), so `OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported` is TRUE: with `OMSetFrontAndBackStencilRef`'s per-face references, both of that cap's parts. @@ -2582,7 +2586,8 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv - `OPTIONS19` maps `SupportedSampleCountsWithNoOutputs` from `framebufferNoAttachmentsSampleCounts`, ties `AnisoFilterWithPointMipSupported` to `VulkanDeviceInfo::sampler_anisotropy`, and reports the baseline heap limits (`2048` samplers, `1000000` views); - - `OPTIONS21` reports baseline `D3D12_EXECUTE_INDIRECT_TIER_1_0`, and unimplemented features/tiers (`DepthBounds`, + - `OPTIONS2` reports `DepthBoundsTestSupported` from `VkPhysicalDeviceFeatures::depthBounds`; + - `OPTIONS21` reports baseline `D3D12_EXECUTE_INDIRECT_TIER_1_0`, and unimplemented features/tiers ( `CastingFullyTypedFormat`, MSAA UAVs, independent stencil masks, render passes, RT, mesh shaders, sampler feedback, wave MMA, work graphs, GPU upload heaps) stay `FALSE`/`NOT_SUPPORTED`/`TIER_0`. Checked live against the host D3D12 runtime on the same adapter (`NVIDIA GeForce RTX 5080`, driver `616.56`, Windows 11): 15/15 feature diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 6dee464a8f..6a3818ff23 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp @@ -235,6 +235,8 @@ class GraphicsCommandList final } UINT front_stencil_ref() const { return front_stencil_ref_; } UINT back_stencil_ref() const { return back_stencil_ref_; } + float min_depth_bounds() const { return min_depth_bounds_; } + float max_depth_bounds() const { return max_depth_bounds_; } D3D12_GPU_VIRTUAL_ADDRESS cbv_srv_uav_base() const { return cbv_srv_uav_base_; } D3D12_GPU_VIRTUAL_ADDRESS sampler_base() const { return sampler_base_; } @@ -565,7 +567,8 @@ class GraphicsCommandList final } if (!any_nonempty_viewport()) return; // as record_draw: nothing is rasterized leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, {}, 0, viewport_, - scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, false, x, y, z, 0, 0}; + scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, + min_depth_bounds_, max_depth_bounds_, false, x, y, z, 0, 0}; note_direct_heap_indexing(graphics_.layout); draw.mesh = true; draw.viewports = draw_viewports(); @@ -938,6 +941,20 @@ class GraphicsCommandList final check(list_.resolve_queries({query_heap_id(heap), u(type), first, count, resource_id(dst), offset})); } + // GCL1. Dynamic depth-bounds range (default 0.0..1.0), allowed in bundles and accepting out-of-range/NaN at record + // time as D3D12 does (replayed cleanly inside Vulkan's 0..1 domain in vulkan_replay.h). + void STDMETHODCALLTYPE OMSetDepthBounds(FLOAT min, FLOAT max) override { + d3d12_trace::record("ID3D12GraphicsCommandList1::OMSetDepthBounds"); + if (list_.closed()) return; + if (defer([=](GraphicsCommandList& l) { + l.min_depth_bounds_ = min; + l.max_depth_bounds_ = max; + })) + return; + min_depth_bounds_ = min; + max_depth_bounds_ = max; + } + // GCL8. Each draw applies the two faces with vkCmdSetStencilReference(VK_STENCIL_FACE_FRONT_BIT / BACK_BIT). void STDMETHODCALLTYPE OMSetFrontAndBackStencilRef(UINT front, UINT back) override { d3d12_trace::record("ID3D12GraphicsCommandList8::OMSetFrontAndBackStencilRef"); @@ -1552,6 +1569,8 @@ class GraphicsCommandList final bool invalid_ = false; UINT front_stencil_ref_ = 0; UINT back_stencil_ref_ = 0; + float min_depth_bounds_ = 0.0f; + float max_depth_bounds_ = 1.0f; RootState compute_; RootState graphics_; std::uintptr_t compute_pipeline_ = 0; @@ -1681,6 +1700,8 @@ class GraphicsCommandList final void reset_state(ID3D12PipelineState* state) { front_stencil_ref_ = back_stencil_ref_ = 0; + min_depth_bounds_ = 0.0f; + max_depth_bounds_ = 1.0f; compute_ = {}; graphics_ = {}; cbv_srv_uav_heap_ = nullptr; @@ -2052,7 +2073,8 @@ class GraphicsCommandList final void record_raster_draw(bool indexed, UINT count, UINT instances, UINT first, INT base_vertex, UINT first_instance, const leonida::IndirectDrawArgs* indirect = nullptr) { leonida::Draw draw{graphics_pipeline_, graphics_user_data(), draw_views(), depth_, index_, topology_, viewport_, - scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, indexed, count, instances, + scissor_, blend_factor_, front_stencil_ref_, back_stencil_ref_, + min_depth_bounds_, max_depth_bounds_, indexed, count, instances, first, base_vertex, first_instance}; draw.viewports = draw_viewports(); const bool recorded = indirect ? list_.draw_indirect(std::move(draw), *indirect) : list_.draw(std::move(draw)); @@ -2807,6 +2829,14 @@ bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT& return true; } +bool depth_bounds(ID3D12GraphicsCommandList1* list, float& min_depth, float& max_depth) { + const GraphicsCommandList* l = GraphicsCommandList::from(list); + if (!l) return false; + min_depth = l->min_depth_bounds(); + max_depth = l->max_depth_bounds(); + return true; +} + bool recorded_commands(ID3D12GraphicsCommandList* list, std::vector& commands) { const GraphicsCommandList* l = GraphicsCommandList::from(list); if (!l) return false; diff --git a/runtime/shims/d3d12_com.h b/runtime/shims/d3d12_com.h index 849791a262..70e7ef0533 100644 --- a/runtime/shims/d3d12_com.h +++ b/runtime/shims/d3d12_com.h @@ -578,6 +578,9 @@ void set_global_realtime_privilege_override_for_test(int state); // not one of this module's command lists. bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT& back); +// The depth-bounds range last recorded by ID3D12GraphicsCommandList1::OMSetDepthBounds on `list` (default 0..1). +bool depth_bounds(ID3D12GraphicsCommandList1* list, float& min_depth, float& max_depth); + // A copy of the commands `list` has recorded so far, for tests of what a bundle puts into its parent. False when // `list` is not one of this module's command lists. bool recorded_commands(ID3D12GraphicsCommandList* list, std::vector& commands); diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index aeecf05b0d..b50759d619 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -7784,6 +7784,10 @@ struct StencilFaceMasks { UINT8 write = D3D12_DEFAULT_STENCIL_WRITE_MASK; }; +struct GraphicsStreamExtras { + bool depth_bounds_test = false; +}; + struct PipelineStream { D3D12_GRAPHICS_PIPELINE_STATE_DESC graphics{}; bool back_masks = false; // DEPTH_STENCIL2: back_stencil holds the back face's masks @@ -7791,6 +7795,7 @@ struct PipelineStream { D3D12_COMPUTE_PIPELINE_STATE_DESC compute{}; D3D12_SHADER_BYTECODE ms{}; D3D12_SHADER_BYTECODE as{}; + GraphicsStreamExtras extras{}; bool has_cs = false; bool has_graphics_stage = false; // VS, PS, DS, HS, GS, AS or MS }; @@ -7931,9 +7936,7 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1: { D3D12_DEPTH_STENCIL_DESC1 d{}; take(d); - if (ok && d.DepthBoundsTestEnable) { - return stream_unsupported("depth-bounds tests are not supported yet; stream subobject", int(type)); - } + out.extras.depth_bounds_test = ok && (d.DepthBoundsTestEnable != FALSE); g.DepthStencilState = {d.DepthEnable, d.DepthWriteMask, d.DepthFunc, d.StencilEnable, d.StencilReadMask, d.StencilWriteMask, d.FrontFace, d.BackFace}; break; @@ -7942,9 +7945,7 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe D3D12_DEPTH_STENCIL_DESC2 d{}; take(d); if (!ok) break; - if (d.DepthBoundsTestEnable) { - return stream_unsupported("depth-bounds tests are not supported yet; stream subobject", int(type)); - } + out.extras.depth_bounds_test = d.DepthBoundsTestEnable != FALSE; // Each face has its own read and write mask (OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported): // the description takes the front face's, back_stencil the back face's. out.back_masks = true; @@ -8203,7 +8204,9 @@ class PipelineState final if (seen.insert(line).second) std::fprintf(stderr, "%s\n", line); } HRESULT create_graphics(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc, const D3D12_SHADER_BYTECODE* ms = nullptr, - const D3D12_SHADER_BYTECODE* as = nullptr, const StencilFaceMasks* back_masks = nullptr) { + const D3D12_SHADER_BYTECODE* as = nullptr, + const StencilFaceMasks* back_masks = nullptr, + const GraphicsStreamExtras* extras = nullptr) { auto& vk = device_.context->vk; const VkDevice dev = device_.info.device; const bool mesh = ms && ms->pShaderBytecode && ms->BytecodeLength; @@ -8708,6 +8711,7 @@ class PipelineState final depth.depthTestEnable = ds.DepthEnable; depth.depthWriteEnable = ds.DepthEnable && ds.DepthWriteMask == D3D12_DEPTH_WRITE_MASK_ALL; depth.depthCompareOp = compare_op(ds.DepthFunc); + depth.depthBoundsTestEnable = (extras && extras->depth_bounds_test) ? VK_TRUE : VK_FALSE; depth.stencilTestEnable = ds.StencilEnable; depth.front = stencil_face(ds.FrontFace, ds.StencilReadMask, ds.StencilWriteMask); depth.back = back_masks ? stencil_face(ds.BackFace, back_masks->read, back_masks->write) @@ -8779,6 +8783,8 @@ class PipelineState final return stream_unsupported("logic ops need logicOp, which the device lacks; op", int(first.LogicOp)); if (raster.depthClampEnable && !features.depthClamp) return stream_unsupported("DepthClipEnable = FALSE needs depthClamp, which the device lacks; flag", 0); + if (depth.depthBoundsTestEnable && !features.depthBounds) + return stream_unsupported("depth-bounds testing needs depthBounds, which the device lacks; enabled", 1); graphics_.viewport_with_count = features.multiViewport && vk.vkCmdSetViewportWithCount && vk.vkCmdSetScissorWithCount; @@ -8878,6 +8884,7 @@ class PipelineState final // Kept for variants: a draw that leaves a slot unbound needs this pipeline with that format undefined. graphics_.mesh = mesh; + graphics_.depth_bounds_test = depth.depthBoundsTestEnable == VK_TRUE; recipe_.mesh = mesh; recipe_.stages = std::move(stage_infos); recipe_.attributes = std::move(attributes); @@ -9324,7 +9331,7 @@ class PipelineState final // A mesh pipeline takes neither the topology nor the strides as dynamic state // (VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-07065 and -07066). // With multiViewport enabled, VIEWPORT_WITH_COUNT / SCISSOR_WITH_COUNT allow 1..16 dynamic viewports/scissors. - VkDynamicState dyn_list[8]{}; + VkDynamicState dyn_list[9]{}; std::uint32_t dyn_count = 0; dyn_list[dyn_count++] = graphics_.viewport_with_count ? VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT : VK_DYNAMIC_STATE_VIEWPORT; @@ -9336,6 +9343,7 @@ class PipelineState final } dyn_list[dyn_count++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE; dyn_list[dyn_count++] = VK_DYNAMIC_STATE_BLEND_CONSTANTS; + if (r.depth.depthBoundsTestEnable == VK_TRUE) dyn_list[dyn_count++] = VK_DYNAMIC_STATE_DEPTH_BOUNDS; if (!r.mesh && !r.bindings.empty()) dyn_list[dyn_count++] = VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE; VkPipelineDynamicStateCreateInfo dynamic{VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO}; dynamic.dynamicStateCount = dyn_count; @@ -13721,7 +13729,8 @@ class Device final pipeline->attach_device(identity()); const HRESULT hr = stream.has_cs ? pipeline->create_compute(stream.compute) : pipeline->create_graphics(stream.graphics, &stream.ms, &stream.as, - stream.back_masks ? &stream.back_stencil : nullptr); + stream.back_masks ? &stream.back_stencil : nullptr, + &stream.extras); if (FAILED(hr)) { pipeline->Release(); return finish(hr); @@ -15513,7 +15522,7 @@ class Device final if (size != sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS2)) return d3d12_trace::result(method, E_INVALIDARG); auto* opts = static_cast(data); *opts = {}; - opts->DepthBoundsTestSupported = FALSE; + opts->DepthBoundsTestSupported = state_.info.features.depthBounds ? TRUE : FALSE; opts->ProgrammableSamplePositionsTier = D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED; return d3d12_trace::result(method, S_OK); } @@ -18125,6 +18134,7 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin enable.logicOp = chosen_features.logicOp; enable.depthClamp = chosen_features.depthClamp; enable.multiViewport = chosen_features.multiViewport; + enable.depthBounds = chosen_features.depthBounds; enable.geometryShader = chosen_features.geometryShader; // translated geometry shaders (195 in the corpus) // What translated shaders declare (the index's `features`): 64-bit integers in most of the corpus (25,803 of // 26,503 entries), doubles, 16-bit integers, clip and cull distances in a few vertex shaders, formatless image diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h index 3d7ed093bb..6bf5100578 100644 --- a/runtime/src/command_list.h +++ b/runtime/src/command_list.h @@ -454,6 +454,8 @@ struct Draw { std::array blend_factor{1, 1, 1, 1}; std::uint32_t stencil_front = 0; std::uint32_t stencil_back = 0; + float min_depth_bounds = 0.0f; + float max_depth_bounds = 1.0f; bool indexed = false; std::uint32_t count = 0; // vertices or indices per instance std::uint32_t instances = 0; diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 145fa11ee5..af2b4db3c8 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h @@ -125,7 +125,7 @@ struct VulkanDeviceFunctions { X(vkCmdBindVertexBuffers2) X(vkCmdBindIndexBuffer) X(vkCmdSetViewport) X(vkCmdSetScissor) \ X(vkCmdSetViewportWithCount) X(vkCmdSetScissorWithCount) \ X(vkCmdSetPrimitiveTopology) X(vkCmdSetPrimitiveRestartEnable) X(vkCmdSetStencilReference) \ - X(vkCmdSetBlendConstants) X(vkCmdDraw) \ + X(vkCmdSetDepthBounds) X(vkCmdSetBlendConstants) X(vkCmdDraw) \ X(vkCmdDrawIndexed) X(vkCreateGraphicsPipelines) X(vkQueueBindSparse) X(vkGetImageSparseMemoryRequirements) \ X(vkCreatePipelineCache) X(vkDestroyPipelineCache) X(vkGetPipelineCacheData) X(vkMergePipelineCaches) \ X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \ @@ -1147,6 +1147,7 @@ class VulkanContext { replay_.set_primitive_topology = vk.vkCmdSetPrimitiveTopology; replay_.set_primitive_restart_enable = vk.vkCmdSetPrimitiveRestartEnable; replay_.set_stencil_reference = vk.vkCmdSetStencilReference; + replay_.set_depth_bounds = vk.vkCmdSetDepthBounds; replay_.set_blend_constants = vk.vkCmdSetBlendConstants; replay_.draw = vk.vkCmdDraw; replay_.draw_mesh_tasks = vk.vkCmdDrawMeshTasksEXT; // null unless VK_EXT_mesh_shader is enabled diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index e20a291057..6304ee6b56 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -867,6 +867,7 @@ struct GraphicsPipeline { std::uint32_t strip_cut = 0; // D3D12_INDEX_BUFFER_STRIP_CUT_VALUE (0: off, 1: 0xFFFF, 2: 0xFFFFFFFF) bool mesh = false; // a mesh shader instead of a vertex shader: drawn by DispatchMesh only bool viewport_with_count = false; // pipeline uses VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT / SCISSOR_WITH_COUNT + bool depth_bounds_test = false; // VK_DYNAMIC_STATE_DEPTH_BOUNDS enabled on this pipeline // The same pipeline with some attachment formats VK_FORMAT_UNDEFINED, for a draw that leaves those slots // unbound (D3D12 allows it; dynamic rendering needs the formats to agree). Bit i: colour slot i, bit 8: depth // and stencil. Null when it cannot be built. @@ -1094,6 +1095,7 @@ struct ReplayFunctions { PFN_vkCmdSetPrimitiveTopology set_primitive_topology = nullptr; PFN_vkCmdSetPrimitiveRestartEnable set_primitive_restart_enable = nullptr; PFN_vkCmdSetStencilReference set_stencil_reference = nullptr; + PFN_vkCmdSetDepthBounds set_depth_bounds = nullptr; PFN_vkCmdSetBlendConstants set_blend_constants = nullptr; PFN_vkCmdDraw draw = nullptr; unsigned* mesh_draw_count = nullptr; // opt-in count for this submission @@ -2594,6 +2596,7 @@ ReplayResult prepare_draw(const Draw& draw, const IndirectDrawArgs* arguments, R if (draw.mesh && !vk.draw_mesh_tasks) return unsupported_at(__LINE__); if (pipeline->viewport_with_count && (!vk.set_viewport_with_count || !vk.set_scissor_with_count)) return unsupported_at(__LINE__); + if (pipeline->depth_bounds_test && !vk.set_depth_bounds) return unsupported_at(__LINE__); if (pipeline->bindless_set && !vk.bind_descriptor_sets) return unsupported_at(__LINE__); if (pipeline->color_formats.size() > max_render_targets) return unsupported_at(__LINE__); p.graphics = pipeline; @@ -5195,6 +5198,13 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_ } vk.set_stencil_reference(command_buffer, VK_STENCIL_FACE_FRONT_BIT, draw->stencil_front); vk.set_stencil_reference(command_buffer, VK_STENCIL_FACE_BACK_BIT, draw->stencil_back); + if (graphics.depth_bounds_test && vk.set_depth_bounds) { + const float mn = draw->min_depth_bounds; + const float mx = draw->max_depth_bounds; + const bool empty = (mn != mn) || (mx != mx) || mn > mx || mn > 1.0f || mx < 0.0f; + vk.set_depth_bounds(command_buffer, empty ? 1.0f : (mn < 0.0f ? 0.0f : mn), + empty ? 0.0f : (mx > 1.0f ? 1.0f : mx)); + } vk.set_blend_constants(command_buffer, draw->blend_factor.data()); for (std::uint32_t slot = 0; slot < d.vertex_buffers.size(); ++slot) { if (!d.vertex_buffers[slot]) continue; diff --git a/runtime/test/d3d12_bundle_forbidden_test.cpp b/runtime/test/d3d12_bundle_forbidden_test.cpp index 3e3a5d1332..22c91ba1b4 100644 --- a/runtime/test/d3d12_bundle_forbidden_test.cpp +++ b/runtime/test/d3d12_bundle_forbidden_test.cpp @@ -120,6 +120,9 @@ std::vector calls() { {"OMSetBlendFactor", [](Env&, ID3D12GraphicsCommandList* b) { const FLOAT factor[4] = {1, 1, 1, 1}; b->OMSetBlendFactor(factor); }}, + {"OMSetDepthBounds", [](Env&, ID3D12GraphicsCommandList* b) { + Ref b1; + if (SUCCEEDED(b->QueryInterface(IID_PPV_ARGS(&b1.p)))) b1->OMSetDepthBounds(0.25f, 0.75f); }}, }; } diff --git a/runtime/test/d3d12_close_parity_test.cpp b/runtime/test/d3d12_close_parity_test.cpp index 7ae4f1e6d7..ae4f7c61b7 100644 --- a/runtime/test/d3d12_close_parity_test.cpp +++ b/runtime/test/d3d12_close_parity_test.cpp @@ -391,6 +391,41 @@ std::vector cases() { {"OMSetBlendFactor", true, match, CALLS(const FLOAT factor[4] = {0.25f, 0.5f, 0.75f, 1.0f}; e.list->OMSetBlendFactor(factor))}, {"OMSetStencilRef(7)", true, match, CALLS(e.list->OMSetStencilRef(7))}, + {"OMSetDepthBounds(0.25, 0.75)", true, match, + [](Env& e) { + Ref list1; + if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false; + list1->OMSetDepthBounds(0.25f, 0.75f); + return true; + }}, + {"OMSetDepthBounds(-0.1, 0.5)", true, match, + [](Env& e) { + Ref list1; + if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false; + list1->OMSetDepthBounds(-0.1f, 0.5f); + return true; + }}, + {"OMSetDepthBounds(0.5, 1.1)", true, match, + [](Env& e) { + Ref list1; + if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false; + list1->OMSetDepthBounds(0.5f, 1.1f); + return true; + }}, + {"OMSetDepthBounds(0.8, 0.2)", true, match, + [](Env& e) { + Ref list1; + if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false; + list1->OMSetDepthBounds(0.8f, 0.2f); + return true; + }}, + {"OMSetDepthBounds(NaN, 0.5)", true, match, + [](Env& e) { + Ref list1; + if (FAILED(e.list->QueryInterface(IID_PPV_ARGS(&list1.p)))) return false; + list1->OMSetDepthBounds(std::numeric_limits::quiet_NaN(), 0.5f); + return true; + }}, {"ExecuteBundle after post-close state calls on bundle", true, match, CALLS(const FLOAT factor[4] = {0.25f, 0.5f, 0.75f, 1.0f}; e.closed_bundle->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); diff --git a/runtime/test/d3d12_com_test.cpp b/runtime/test/d3d12_com_test.cpp index 8691e5a740..cf1c71890d 100644 --- a/runtime/test/d3d12_com_test.cpp +++ b/runtime/test/d3d12_com_test.cpp @@ -9,8 +9,10 @@ #include "../src/gfx10_descriptors.h" #include +#include #include #include +#include #define EXPECT(condition) do { \ if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ @@ -136,6 +138,9 @@ int main(int argc, char** argv) { Ref list8; EXPECT(SUCCEEDED(list->QueryInterface(IID_PPV_ARGS(&list8.p)))); list8->OMSetFrontAndBackStencilRef(1, 2); + list8->OMSetDepthBounds(0.25f, 0.75f); + float min_depth = 0.0f, max_depth = 0.0f; + EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.25f && max_depth == 0.75f); Ref bundle_allocator; Ref bundle; EXPECT(SUCCEEDED(rt::d3d12::create_command_allocator(D3D12_COMMAND_LIST_TYPE_BUNDLE, @@ -153,10 +158,12 @@ int main(int argc, char** argv) { IID_PPV_ARGS(&wrong_bundle.p)) == E_INVALIDARG); EXPECT(!wrong_bundle.p); bundle->OMSetFrontAndBackStencilRef(7, 9); + bundle->OMSetDepthBounds(0.125f, 0.875f); EXPECT(bundle->Close() == S_OK); list8->ExecuteBundle(bundle.p); UINT front = 0, back = 0; EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 7 && back == 9); + EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.125f && max_depth == 0.875f); // An untouched bundle inherits the parent's current sticky state; its default values must not overwrite it. Ref untouched_allocator; @@ -168,6 +175,7 @@ int main(int argc, char** argv) { EXPECT(untouched_bundle->Close() == S_OK); list8->ExecuteBundle(untouched_bundle.p); EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 7 && back == 9); + EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.125f && max_depth == 0.875f); list8->ExecuteBundle(bundle.p); // the same closed bundle can be executed repeatedly ID3D12CommandList* bundle_submission[] = {bundle.p}; @@ -432,26 +440,32 @@ int main(int argc, char** argv) { list->ClearDepthStencilView(dsv_handle, D3D12_CLEAR_FLAG_DEPTH, 2.0f, 0, 0, nullptr); EXPECT(list->Close() == S_OK); - // State-setting calls on a closed direct list or bundle are ignored and do not mutate recorded state. + // Post-close state calls on a closed direct list or bundle are ignored and do not mutate recorded state. EXPECT(SUCCEEDED(allocator->Reset())); EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr))); + list8->OMSetDepthBounds(std::numeric_limits::quiet_NaN(), 0.5f); list->OMSetStencilRef(5); + list8->OMSetDepthBounds(0.25f, 0.75f); EXPECT(list->Close() == S_OK); EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 5 && back == 5); + EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.25f && max_depth == 0.75f); const FLOAT post_close_factor[4] = {0.1f, 0.2f, 0.3f, 0.4f}; list->OMSetStencilRef(99); list->OMSetBlendFactor(post_close_factor); + list8->OMSetDepthBounds(0.9f, 0.95f); list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); list->IASetIndexBuffer(nullptr); list->SetPipelineState(nullptr); list->ClearState(nullptr); list->ExecuteBundle(bundle.p); EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 5 && back == 5); + EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.25f && max_depth == 0.75f); EXPECT(list->Close() == E_FAIL); // Post-close state calls on a closed bundle do not append calls or invalidate the bundle. bundle->OMSetStencilRef(99); bundle->OMSetBlendFactor(post_close_factor); + bundle->OMSetDepthBounds(0.9f, 0.95f); bundle->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST); bundle->IASetIndexBuffer(nullptr); bundle->SetPipelineState(nullptr); @@ -461,6 +475,7 @@ int main(int argc, char** argv) { EXPECT(SUCCEEDED(list->Reset(allocator.p, nullptr))); list->ExecuteBundle(bundle.p); EXPECT(rt::d3d12::front_back_stencil_ref(list8.p, front, back) && front == 7 && back == 9); + EXPECT(rt::d3d12::depth_bounds(list8.p, min_depth, max_depth) && min_depth == 0.125f && max_depth == 0.875f); EXPECT(list->Close() == S_OK); } diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp index 2d9bc5212e..4e074ae39b 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -157,6 +157,7 @@ int main(int argc, char** argv) { info.queue_family = d.family; info.buffer_device_address = true; info.shader_dir = library.string(); + info.features.depthBounds = d.enabled.depthBounds; info.mesh_shader = mesh; info.mesh_shader_queries = mesh && d.mesh_shader_queries; info.pipeline_statistics_query = d.pipeline_statistics_query; @@ -317,7 +318,14 @@ int main(int argc, char** argv) { D3D12_DEPTH_STENCIL_DESC1 bounds{}; bounds.DepthBoundsTestEnable = TRUE; bad.add(DepthStencil1Subobject{.inner = bounds}); - EXPECT(create(device.p, bad, refused) == E_NOTIMPL && !refused.p); + D3D12_FEATURE_DATA_D3D12_OPTIONS2 o2{}; + EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &o2, sizeof(o2)))); + if (o2.DepthBoundsTestSupported) { + Ref bounds_pso; + EXPECT(SUCCEEDED(create(device.p, bad, bounds_pso)) && bounds_pso.p); + } else { + EXPECT(create(device.p, bad, refused) == E_NOTIMPL && !refused.p); + } // A console stream: its numbering has no gap at 23, so its mesh shader is 24 (the PC's AS) and its // RASTERIZER1 26 (the PC's DEPTH_STENCIL2). An AS without an MS is no PC stream, so the layer reads it with the diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 9df462d3fd..4c4f239c1a 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp @@ -2423,7 +2423,7 @@ int compare_feature_options(ID3D12Device* ours, const rt::d3d12::VulkanDeviceInf fail("unknown feature unexpectedly answered"); // Local invariants for what this layer actually implements. - if (o2.DepthBoundsTestSupported || + if (o2.DepthBoundsTestSupported != (info.features.depthBounds ? TRUE : FALSE) || o2.ProgrammableSamplePositionsTier != D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED) fail("OPTIONS2 unexpected support"); if (o3.CastingFullyTypedFormatSupported || @@ -5095,6 +5095,7 @@ int main() { info.queue_family = d.family; info.conditional_rendering = d.conditional_rendering; // SetPredication (the D24 tests check copies under it) info.texture_compression_bc = d.bc; + info.features.depthBounds = d.enabled.depthBounds; info.occlusion_query_precise = d.occlusion_query_precise; info.pipeline_statistics_query = d.pipeline_statistics_query; info.conditional_rendering = d.conditional_rendering; diff --git a/runtime/test/vk_test_device.h b/runtime/test/vk_test_device.h index fd63fca665..8c9124567d 100644 --- a/runtime/test/vk_test_device.h +++ b/runtime/test/vk_test_device.h @@ -490,6 +490,7 @@ class Device { enable_legacy_formatless_features && features.features.shaderStorageImageWriteWithoutFormat; enable.logicOp = features.features.logicOp; // d3d12_draw_test's logic-op draw, where available enable.multiViewport = features.features.multiViewport; // d3d12_multi_viewport_test, where available + enable.depthBounds = features.features.depthBounds; enable.geometryShader = features.features.geometryShader; // d3d12_geometry_test, where available enable.dualSrcBlend = features.features.dualSrcBlend; // d3d12_translated_draw_test --dual-source const char* conditional_extension = VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME;