diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 083c91e0d2..cee07aac8a 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -3353,7 +3353,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. @@ -3483,7 +3487,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 5ae879e04d..ee6a0a2726 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp @@ -247,6 +247,7 @@ class GraphicsCommandList final } UINT front_stencil_ref() const { return front_stencil_ref_; } UINT back_stencil_ref() const { return back_stencil_ref_; } + const std::array& depth_bounds() const { return 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_; } @@ -557,6 +558,7 @@ class GraphicsCommandList final // ID3D12GraphicsCommandList1: the depth-bounds test's range for the draws after it, read by pipelines that enable // the test (DEPTH_STENCIL1/2). D3D12's default is [0, 1]. void STDMETHODCALLTYPE OMSetDepthBounds(FLOAT min, FLOAT max) override { + d3d12_trace::record("ID3D12GraphicsCommandList1::OMSetDepthBounds"); if (list_->closed()) return; const std::array value{min, max}; if (defer([=](GraphicsCommandList& l) { l.depth_bounds_ = value; })) return; @@ -3543,6 +3545,15 @@ bool hold_until_reset(ID3D12GraphicsCommandList* list, IUnknown* object) { return true; } +bool depth_bounds(ID3D12GraphicsCommandList1* list, float& min_depth, float& max_depth) { + const GraphicsCommandList* l = GraphicsCommandList::from(list); + if (!l) return false; + const auto& bounds = l->depth_bounds(); + min_depth = bounds[0]; + max_depth = bounds[1]; + 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 e627a29db0..ddc1ce522b 100644 --- a/runtime/shims/d3d12_com.h +++ b/runtime/shims/d3d12_com.h @@ -783,6 +783,9 @@ bool front_back_stencil_ref(ID3D12GraphicsCommandList8* list, UINT& front, UINT& // lists or `object` is null. bool hold_until_reset(ID3D12GraphicsCommandList* list, IUnknown* object); +// 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 1c97dad489..1497db32f7 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -17098,7 +17098,10 @@ leonida::cached_pso::Key pipeline_key(const D3D12_COMPUTE_PIPELINE_STATE_DESC& d return leonida::sha256_hex(key.data()); } -leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc) { +// `extra` carries fields only a console stream has (back-face masks, depth bounds); they are hashed into the same key, +// as the cached blob holds just the first 64 characters. Without it the key is the plain description's. +leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc, + const leonida::cached_pso::KeyBuilder* extra = nullptr) { leonida::cached_pso::KeyBuilder key; key.tag("graphics"); key_root_signature(key, desc.pRootSignature); @@ -17148,6 +17151,7 @@ leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& .u32(desc.NumRenderTargets); for (const DXGI_FORMAT format : desc.RTVFormats) key.u32(format); key.u32(desc.DSVFormat).u32(desc.SampleDesc.Count).u32(desc.SampleDesc.Quality).u32(desc.NodeMask); + if (extra) key.bytes(extra->data().data(), extra->data().size()); return leonida::sha256_hex(key.data()); } @@ -18043,7 +18047,7 @@ class PipelineState final const auto* record=rt::d3d12_xs::find_pso_record(this); PipelineStream stream{}; HRESULT hr=record?parse_pipeline_stream(record->desc(),stream):E_INVALIDARG; - if(SUCCEEDED(hr))hr=stream.has_cs?create_compute(stream.compute):create_graphics(stream.graphics,&stream.ms,&stream.as); + if(SUCCEEDED(hr))hr=stream.has_cs?create_compute(stream.compute):create_graphics(stream.graphics,&stream.ms,&stream.as,stream.back_masks?&stream.back_stencil:nullptr,&stream.extras); }); } return registered_ && (is_graphics_==graphics); @@ -23521,7 +23525,17 @@ class Device final if(!record)return E_INVALIDARG; auto* pipeline=new PipelineState(state_); pipeline->attach_device(identity()); - pipeline->set_cache_key(stream.has_cs?pipeline_key(stream.compute):pipeline_key(stream.graphics)); + if(stream.has_cs) { + pipeline->set_cache_key(pipeline_key(stream.compute)); + } else { + // The stream description carries fields the plain graphics description cannot: + // DEPTH_STENCIL2 back-face masks and the depth-bounds enable. Mix them in so two + // console PSOs differing only in these do not share one cache key. + leonida::cached_pso::KeyBuilder extra; + extra.u32(stream.back_masks?1u:0u).u32(stream.back_stencil.read).u32(stream.back_stencil.write) + .u32(stream.extras.depth_bounds_test?1u:0u); + pipeline->set_cache_key(pipeline_key(stream.graphics,&extra)); + } if(state_.order_log||state_.prewarm_plan) pipeline->set_order_key(order_key(stream)); if(!rt::d3d12_xs::attach_pso_record(pipeline,std::move(record))){pipeline->Release();return E_OUTOFMEMORY;} pipeline->set_pending_stream(stream.has_cs); diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 16f029335c..fa9710453d 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -6098,9 +6098,13 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_ cache.set_stencil_reference(command_buffer, vk, draw->stencil_front, draw->stencil_back); cache.set_blend_constants(command_buffer, vk, draw->blend_factor); if (graphics.depth_bounds) { - // Vulkan takes bounds in [0, 1] only (without VK_EXT_depth_range_unrestricted), as D3D12 does. - const float lo = std::clamp(draw->depth_bounds[0], 0.0f, 1.0f); - const float hi = std::clamp(draw->depth_bounds[1], 0.0f, 1.0f); + // D3D12 converts NaN to zero; then apply the clamp, with an inverted or disjoint range empty. + // Vulkan takes bounds in [0, 1] only (without VK_EXT_depth_range_unrestricted). + const float mn = draw->depth_bounds[0] != draw->depth_bounds[0] ? 0.0f : draw->depth_bounds[0]; + const float mx = draw->depth_bounds[1] != draw->depth_bounds[1] ? 0.0f : draw->depth_bounds[1]; + const bool empty = mn > mx || mn > 1.0f || mx < 0.0f; + const float lo = empty ? 1.0f : std::max(mn, 0.0f); + const float hi = empty ? 0.0f : std::min(mx, 1.0f); cache.set_depth_bounds(command_buffer, vk, lo, hi); } for (std::uint32_t slot = 0; slot < d.vertex_buffers.size(); ++slot) { 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 fc8a71d729..01b734ff2b 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}; @@ -464,26 +472,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); @@ -493,6 +507,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 1628a0ce42..e35d40f2b5 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -64,6 +64,7 @@ using DepthStencilSubobject = Subobject; using Rasterizer2Subobject = Subobject; using MaskSubobject = Subobject; +using DsvFormatSubobject = Subobject; // Subobjects appended one after another: each is pointer-aligned and a multiple of the pointer size, so the bytes // are what a struct of the same members would hold. @@ -869,6 +870,104 @@ int main(int argc, char** argv) { std::printf("pipelineStatisticsQuery not available: the D3D-291 statistics check is skipped\n"); } + // RT-DEPTHBOUNDS-STREAM-EXTRAS: a console stream is realized on first use (PipelineState::resolve_type), not + // when it is created, and that path must carry DepthBoundsTestEnable like the eager one. The mesh shader + // writes depth 0. With the bounds on, OMSetDepthBounds(0.5, 1) must discard it (the target keeps its clear + // colour) and OMSetDepthBounds(0, 1) must keep it (red). A realization that drops the flag draws red twice. + if (!pc_only && o2.DepthBoundsTestSupported) { + D3D12_DEPTH_STENCIL_DESC1 bounded{}; + bounded.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; + bounded.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS; + bounded.DepthBoundsTestEnable = TRUE; + Stream console_bounds; + console_bounds.add(RootSubobject{.inner = root.p}); + console_bounds.add(Subobject{.inner = ms}); + console_bounds.add(PsSubobject{.inner = ps}).add(TargetsSubobject{.inner = one_target()}); + console_bounds.add(DepthStencil1Subobject{.inner = bounded}); + console_bounds.add(DsvFormatSubobject{.inner = DXGI_FORMAT_D32_FLOAT}); + console_bounds.add(MaskSubobject{.inner = UINT_MAX}); + Ref bounds_console; + using CreateConsole = HRESULT(WINAPI*)(ID3D12Device*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**); + const auto bounds_desc = console_bounds.desc(); + EXPECT(SUCCEEDED(reinterpret_cast(slot(device.p, 86))(device.p, &bounds_desc, + IID_PPV_ARGS(&bounds_console.p))) && + bounds_console.p); + + Ref bounds_target, bounds_depth; + D3D12_RESOURCE_DESC bounds_rt_desc = rt_desc; + EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &bounds_rt_desc, + D3D12_RESOURCE_STATE_COMMON, nullptr, + IID_PPV_ARGS(&bounds_target.p)))); + D3D12_RESOURCE_DESC depth_desc = rt_desc; + depth_desc.Format = DXGI_FORMAT_D32_FLOAT; + depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &depth_desc, + D3D12_RESOURCE_STATE_COMMON, nullptr, + IID_PPV_ARGS(&bounds_depth.p)))); + const D3D12_DESCRIPTOR_HEAP_DESC dsv_heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1, + D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; + Ref dsv_heap, bounds_rtv_heap; + EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&dsv_heap_desc, IID_PPV_ARGS(&dsv_heap.p)))); + EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&bounds_rtv_heap.p)))); + const D3D12_CPU_DESCRIPTOR_HANDLE dsv{ + SIZE_T(reinterpret_cast(slot(dsv_heap.p, 9))(dsv_heap.p))}; + const D3D12_CPU_DESCRIPTOR_HANDLE bounds_rtv{ + SIZE_T(reinterpret_cast(slot(bounds_rtv_heap.p, 9))(bounds_rtv_heap.p))}; + device->CreateDepthStencilView(bounds_depth.p, nullptr, dsv); + device->CreateRenderTargetView(bounds_target.p, nullptr, bounds_rtv); + + // One frame per bounds pair; returns the pixel at (8, 8), inside the quad the mesh draw covers. + bool first_frame = true; + UINT64 bounds_fence = 3; + const auto bounded_pixel = [&](float lo, float hi) { + std::array pixel{}; + if (!SUCCEEDED(allocator->Reset()) || !SUCCEEDED(list->Reset(allocator.p, bounds_console.p))) return pixel; + D3D12_RESOURCE_BARRIER in[2] = { + transition(bounds_target.p, first_frame ? D3D12_RESOURCE_STATE_COMMON : D3D12_RESOURCE_STATE_COPY_SOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET), + transition(bounds_depth.p, first_frame ? D3D12_RESOURCE_STATE_COMMON : D3D12_RESOURCE_STATE_DEPTH_WRITE, + D3D12_RESOURCE_STATE_DEPTH_WRITE)}; + list->ResourceBarrier(first_frame ? 2 : 1, in); + first_frame = false; + list->ClearRenderTargetView(bounds_rtv, blue, 0, nullptr); + list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 0.0f, 0, 0, nullptr); + list->SetGraphicsRootSignature(root.p); + list->RSSetViewports(1, &viewport); + list->RSSetScissorRects(1, &scissor); + list->OMSetRenderTargets(1, &bounds_rtv, FALSE, &dsv); + list6->OMSetDepthBounds(lo, hi); + list->SetGraphicsRoot32BitConstants(0, 2, origin, 0); + list->SetGraphicsRootConstantBufferView(1, upload_va); + list6->DispatchMesh(2, 2, 1); + D3D12_RESOURCE_BARRIER out = transition(bounds_target.p, D3D12_RESOURCE_STATE_RENDER_TARGET, + D3D12_RESOURCE_STATE_COPY_SOURCE); + list->ResourceBarrier(1, &out); + D3D12_TEXTURE_COPY_LOCATION to{}; + to.pResource = readback.p; + to.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + to.PlacedFootprint = {0, {DXGI_FORMAT_R8G8B8A8_UNORM, size, size, 1, 256}}; + D3D12_TEXTURE_COPY_LOCATION from{}; + from.pResource = bounds_target.p; + from.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + list->CopyTextureRegion(&to, 0, 0, 0, &from, nullptr); + if (list->Close() != S_OK) return pixel; + ID3D12CommandList* one[] = {list.p}; + queue->ExecuteCommandLists(1, one); + if (rt::d3d12::last_execute_result(queue.p) != leonida::ReplayResult::success) return pixel; + ++bounds_fence; + if (FAILED(queue->Signal(fence.p, bounds_fence)) || FAILED(fence->SetEventOnCompletion(bounds_fence, nullptr))) + return pixel; + void* got = nullptr; + if (FAILED(readback->Map(0, nullptr, &got))) return pixel; + std::memcpy(pixel.data(), static_cast(got) + 8 * 256 + 8 * 4, 4); + readback->Unmap(0, nullptr); + return pixel; + }; + const std::array red{255, 0, 0, 255}, clear_blue{0, 0, 255, 255}; + EXPECT(bounded_pixel(0.0f, 1.0f) == red); // depth 0 is inside [0, 1] + EXPECT(bounded_pixel(0.5f, 1.0f) == clear_blue); // outside [0.5, 1]: discarded only if the flag arrived + } + for (auto* r : {&upload, &readback, &target}) r->reset(); for (auto* p : {&mesh_pso, &vs_pso, &refused}) p->reset(); root.reset(); diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 000e3ee5cb..79b832b97a 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp @@ -2424,7 +2424,8 @@ int compare_feature_options(ID3D12Device* ours, const rt::d3d12::VulkanDeviceInf // Local invariants for what this layer actually implements. // DepthBoundsTestSupported follows the device's depthBounds feature. - if (o2.ProgrammableSamplePositionsTier != D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED) + if (o2.DepthBoundsTestSupported != (info.features.depthBounds ? TRUE : FALSE) || + o2.ProgrammableSamplePositionsTier != D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_NOT_SUPPORTED) fail("OPTIONS2 unexpected support"); if (o3.CastingFullyTypedFormatSupported || o3.WriteBufferImmediateSupportFlags != D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE || @@ -5095,6 +5096,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;