d3d12: the on-demand stream carries the depth-bounds flag too (DEPTH-BOUNDS-ON-DEMAND-STREAM) #2234

Open
github-bot wants to merge 1 commit from github-bot/gh-2234 into main AGit
Owner

@⁠star41905453-coder on GitHub · 2026-11-26 09:31 UTC · original
star41905453-coder:depth-bounds-stream → main · +94 −1 · 2 files · 1 commits · open

A stream realized on demand (PipelineState::set_pending_stream, resolved on first use) went through a second create_graphics call site that passed neither the depth-bounds flag nor the back-face stencil masks, so a title that bound a console PSO before it was realized silently lost DepthBoundsTestEnable — the depth-bounds test then always on and clipping nothing, with no refusal and no log. This passes both there, as the eager call site already does.

Test (d3d12_mesh_test): the stream PSO with DepthBoundsTestEnable is now drawn through, not only created.

  • The depth attachment is cleared to 0.0, outside the first bounds, so the bounds test is what decides and not the clear (review point: clearing to 1.0 left the clear value inside 0.9..1.0).
  • The bounds draws write into their own readback buffer, so the mesh image rows compared later are untouched (review point: they overwrote pixels and broke that comparison).
  • 0.9..1.0 must paint nothing, 0.0..1.0 must paint the whole viewport. Where the device has no depthBounds (llvmpipe here) creation is refused instead, and a success there would mean the flag was dropped.

Run: d3d12_mesh, d3d12_mesh_on_demand and d3d12_mesh_heavy_cache pass locally. The draw half still needs a depth-bounds-capable GPU: this box has none, so it skips here.

Item: DEPTH-BOUNDS-ON-DEMAND-STREAM, claimed in #1608.

**@⁠star41905453-coder** on GitHub · 2026-11-26 09:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234) `star41905453-coder:depth-bounds-stream` → `main` · +94 −1 · 2 files · 1 commits · open A stream realized on demand (`PipelineState::set_pending_stream`, resolved on first use) went through a second `create_graphics` call site that passed neither the depth-bounds flag nor the back-face stencil masks, so a title that bound a console PSO before it was realized silently lost `DepthBoundsTestEnable` — the depth-bounds test then always on and clipping nothing, with no refusal and no log. This passes both there, as the eager call site already does. **Test** (`d3d12_mesh_test`): the stream PSO with `DepthBoundsTestEnable` is now drawn through, not only created. - The depth attachment is cleared to **0.0**, outside the first bounds, so the bounds test is what decides and not the clear (review point: clearing to 1.0 left the clear value inside 0.9..1.0). - The bounds draws write into **their own readback buffer**, so the mesh image rows compared later are untouched (review point: they overwrote `pixels` and broke that comparison). - 0.9..1.0 must paint nothing, 0.0..1.0 must paint the whole viewport. Where the device has no `depthBounds` (llvmpipe here) creation is refused instead, and a success there would mean the flag was dropped. **Run**: `d3d12_mesh`, `d3d12_mesh_on_demand` and `d3d12_mesh_heavy_cache` pass locally. The draw half still needs a depth-bounds-capable GPU: this box has none, so it skips here. Item: DEPTH-BOUNDS-ON-DEMAND-STREAM, claimed in #1608.
#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: #815
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:24:02 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 09:42 UTC · original

The depth-bounds forwarding works on an RTX 4090 (Windows, NVIDIA 616.64). I tested 6b7d0fd219 and a control build with only the resolve_type call to create_graphics restored to its parent version. Both used the same synthetic 64×64 draw and Vulkan validation.

Runtime Compilation mode Yellow pixels with bounds 0.9–1.0 (expect 0) Yellow pixels with bounds 0.0–1.0 (expect 4,096)
PR head Eager 0 4,096
PR head On demand 0 4,096
Forwarding reverted Eager 0 4,096
Forwarding reverted On demand 4,096 4,096

Three additional on-demand runs on the PR head gave the same pixel counts. Both passing modes completed the full mesh executable under --pc-stream-only, including its original pixel comparison, with zero Vulkan validation errors through teardown.

The current test needs a few changes to catch this. The unmodified eager test painted all 4,096 pixels in both draws. Clearing the D32 attachment to 1.0 puts it inside both requested ranges. Clearing to 0.5 gives a value inside exactly one range. Vulkan compares the depth already in that attachment. Vulkan depth-bounds specification

For the capable-device branch I created the bounds PSO through console device slot 86, waited for each draw with a fresh fence value, and counted exact RGBA pixels directly from the readback. This preserves the original quadrant image for the final mesh comparison. With those readback corrections but the existing PC create(...) helper, the reverted build still passed on demand. Switching to slot 86 made the control fail as shown above.

I used --pc-stream-only to get past the earlier console-numbered mesh assertion described in the PR. The bounds draw below explicitly calls slot 86 and uses the VS/PS stream. This verifies the depth-bounds change on the on-demand console path. Back-face stencil masks and devices without depth bounds were outside this check.

Test-only patch used on 6b7d0fd219 (depth-bounds-capable branch)
--- a/runtime/test/d3d12_mesh_test.cpp
+++ b/runtime/test/d3d12_mesh_test.cpp
@@ -492,10 +492,8 @@
             queue->ExecuteCommandLists(1, lists);
             EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::invalid_draw);
         }
-        // Depth bounds through the stream and the lazy realization: these PSOs are created pending (the record is
-        // realized on first use), and a depth-bounds flag dropped on the way into create_graphics would let the
-        // fragment through. The VS writes z = 0, so bounds of 0.9..1.0 must leave the target blue and 0.0..1.0 must
-        // paint it yellow.
+        // Exercise the console stream in both compilation modes. Clearing its depth attachment to 0.5 makes
+        // 0.9..1.0 reject every sample and 0.0..1.0 accept every sample.
         D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_options{};
         EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_options,
                                                      sizeof(bounds_options))));
@@ -526,15 +524,22 @@
             bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{
                 .inner = DXGI_FORMAT_D32_FLOAT});
             Ref<ID3D12PipelineState> bounds_pso;
-            EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p);
-
-            const auto draw_bounded = [&](float low, float high) {
+            using Create = HRESULT(WINAPI*)(ID3D12Device*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**);
+            const auto desc = bounds_stream.desc();
+            const HRESULT bounds_hr =
+                reinterpret_cast<Create>(slot(device.p, 86))(device.p, &desc, IID_PPV_ARGS(&bounds_pso.p));
+            EXPECT(SUCCEEDED(bounds_hr) && bounds_pso.p);
+
+            Ref<ID3D12Fence> bounds_fence;
+            EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&bounds_fence.p))));
+            UINT64 submission = 0;
+            const auto draw_bounded = [&](float low, float high, UINT& yellow, UINT& blue_count) {
                 EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, bounds_pso.p)));
                 D3D12_RESOURCE_BARRIER to_rt = transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE,
                                                            D3D12_RESOURCE_STATE_RENDER_TARGET);
                 list->ResourceBarrier(1, &to_rt);
                 list->ClearRenderTargetView(rtv, blue, 0, nullptr);
-                list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
+                list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 0.5f, 0, 0, nullptr);
                 list->SetGraphicsRootSignature(root.p);
                 list->RSSetViewports(1, &viewport);
                 list->RSSetScissorRects(1, &scissor);
@@ -548,20 +553,25 @@
                 EXPECT(list->Close() == S_OK);
                 queue->ExecuteCommandLists(1, lists);
                 EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success);
-                EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr)));
+                ++submission;
+                EXPECT(SUCCEEDED(queue->Signal(bounds_fence.p, submission)) &&
+                       SUCCEEDED(bounds_fence->SetEventOnCompletion(submission, nullptr)));
                 void* pixels_out = nullptr;
                 EXPECT(SUCCEEDED(readback->Map(0, nullptr, &pixels_out)));
-                std::memcpy(pixels.data(), pixels_out, pixels.size());
-                UINT yellow = 0;
-                for (UINT i = 0; i < pixels.size(); i += 4)
-                    yellow += pixels[i] > 200 && pixels[i + 1] > 200 && pixels[i + 2] < 60;
-                return int(yellow);
+                const auto* bytes = static_cast<const std::uint8_t*>(pixels_out);
+                for (UINT i = 0; i < pixels.size(); i += 4) {
+                    yellow += bytes[i] == 255 && bytes[i + 1] == 255 && bytes[i + 2] == 0 && bytes[i + 3] == 255;
+                    blue_count += bytes[i] == 0 && bytes[i + 1] == 0 && bytes[i + 2] == 255 && bytes[i + 3] == 255;
+                }
+                readback->Unmap(0, nullptr);
+                return 0;
             };
-            const int outside = draw_bounded(0.9f, 1.0f);
-            const int inside = draw_bounded(0.0f, 1.0f);
-            std::printf("depth bounds through a pending stream: %d px outside the bounds, %d px inside\n", outside,
-                        inside);
-            EXPECT(outside == 0 && inside > 0);
+            UINT outside = 0, inside = 0, blue_outside = 0, blue_inside = 0;
+            EXPECT(draw_bounded(0.9f, 1.0f, outside, blue_outside) == 0);
+            EXPECT(draw_bounded(0.0f, 1.0f, inside, blue_inside) == 0);
+            std::printf("depth bounds via slot 86: outside yellow=%u blue=%u; inside yellow=%u blue=%u\n",
+                        outside, blue_outside, inside, blue_inside);
+            EXPECT(outside == 0 && blue_outside == size * size && inside == size * size && blue_inside == 0);
         } else {
             // No depthBounds here: the layer refuses such a PSO with E_NOTIMPL. On a device that prepares PSOs on
             // demand the refusal comes at the first use instead, and only if the flag arrived: a stream flag dropped
**@⁠ecox982745** on GitHub · 2026-11-26 09:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#issuecomment-7188354695) The depth-bounds forwarding works on an RTX 4090 (Windows, NVIDIA 616.64). I tested `6b7d0fd219` and a control build with only the `resolve_type` call to `create_graphics` restored to its parent version. Both used the same synthetic 64×64 draw and Vulkan validation. | Runtime | Compilation mode | Yellow pixels with bounds 0.9–1.0 (expect 0) | Yellow pixels with bounds 0.0–1.0 (expect 4,096) | | --- | --- | ---: | ---: | | PR head | Eager | 0 | 4,096 | | PR head | On demand | 0 | 4,096 | | Forwarding reverted | Eager | 0 | 4,096 | | Forwarding reverted | On demand | **4,096** | 4,096 | Three additional on-demand runs on the PR head gave the same pixel counts. Both passing modes completed the full mesh executable under `--pc-stream-only`, including its original pixel comparison, with zero Vulkan validation errors through teardown. The current test needs a few changes to catch this. The unmodified eager test painted all 4,096 pixels in both draws. Clearing the D32 attachment to 1.0 puts it inside both requested ranges. Clearing to 0.5 gives a value inside exactly one range. Vulkan compares the depth already in that attachment. [Vulkan depth-bounds specification](https://docs.vulkan.org/spec/latest/chapters/fragops.html#fragops-dbt) For the capable-device branch I created the bounds PSO through console device slot 86, waited for each draw with a fresh fence value, and counted exact RGBA pixels directly from the readback. This preserves the original quadrant image for the final mesh comparison. With those readback corrections but the existing PC `create(...)` helper, the reverted build still passed on demand. Switching to slot 86 made the control fail as shown above. I used `--pc-stream-only` to get past the earlier console-numbered mesh assertion described in the PR. The bounds draw below explicitly calls slot 86 and uses the VS/PS stream. This verifies the depth-bounds change on the on-demand console path. Back-face stencil masks and devices without depth bounds were outside this check. <details> <summary>Test-only patch used on 6b7d0fd219 (depth-bounds-capable branch)</summary> ```diff --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -492,10 +492,8 @@ queue->ExecuteCommandLists(1, lists); EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::invalid_draw); } - // Depth bounds through the stream and the lazy realization: these PSOs are created pending (the record is - // realized on first use), and a depth-bounds flag dropped on the way into create_graphics would let the - // fragment through. The VS writes z = 0, so bounds of 0.9..1.0 must leave the target blue and 0.0..1.0 must - // paint it yellow. + // Exercise the console stream in both compilation modes. Clearing its depth attachment to 0.5 makes + // 0.9..1.0 reject every sample and 0.0..1.0 accept every sample. D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_options{}; EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_options, sizeof(bounds_options)))); @@ -526,15 +524,22 @@ bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{ .inner = DXGI_FORMAT_D32_FLOAT}); Ref<ID3D12PipelineState> bounds_pso; - EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p); - - const auto draw_bounded = [&](float low, float high) { + using Create = HRESULT(WINAPI*)(ID3D12Device*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**); + const auto desc = bounds_stream.desc(); + const HRESULT bounds_hr = + reinterpret_cast<Create>(slot(device.p, 86))(device.p, &desc, IID_PPV_ARGS(&bounds_pso.p)); + EXPECT(SUCCEEDED(bounds_hr) && bounds_pso.p); + + Ref<ID3D12Fence> bounds_fence; + EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&bounds_fence.p)))); + UINT64 submission = 0; + const auto draw_bounded = [&](float low, float high, UINT& yellow, UINT& blue_count) { EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, bounds_pso.p))); D3D12_RESOURCE_BARRIER to_rt = transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); list->ResourceBarrier(1, &to_rt); list->ClearRenderTargetView(rtv, blue, 0, nullptr); - list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); + list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 0.5f, 0, 0, nullptr); list->SetGraphicsRootSignature(root.p); list->RSSetViewports(1, &viewport); list->RSSetScissorRects(1, &scissor); @@ -548,20 +553,25 @@ EXPECT(list->Close() == S_OK); queue->ExecuteCommandLists(1, lists); EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); - EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr))); + ++submission; + EXPECT(SUCCEEDED(queue->Signal(bounds_fence.p, submission)) && + SUCCEEDED(bounds_fence->SetEventOnCompletion(submission, nullptr))); void* pixels_out = nullptr; EXPECT(SUCCEEDED(readback->Map(0, nullptr, &pixels_out))); - std::memcpy(pixels.data(), pixels_out, pixels.size()); - UINT yellow = 0; - for (UINT i = 0; i < pixels.size(); i += 4) - yellow += pixels[i] > 200 && pixels[i + 1] > 200 && pixels[i + 2] < 60; - return int(yellow); + const auto* bytes = static_cast<const std::uint8_t*>(pixels_out); + for (UINT i = 0; i < pixels.size(); i += 4) { + yellow += bytes[i] == 255 && bytes[i + 1] == 255 && bytes[i + 2] == 0 && bytes[i + 3] == 255; + blue_count += bytes[i] == 0 && bytes[i + 1] == 0 && bytes[i + 2] == 255 && bytes[i + 3] == 255; + } + readback->Unmap(0, nullptr); + return 0; }; - const int outside = draw_bounded(0.9f, 1.0f); - const int inside = draw_bounded(0.0f, 1.0f); - std::printf("depth bounds through a pending stream: %d px outside the bounds, %d px inside\n", outside, - inside); - EXPECT(outside == 0 && inside > 0); + UINT outside = 0, inside = 0, blue_outside = 0, blue_inside = 0; + EXPECT(draw_bounded(0.9f, 1.0f, outside, blue_outside) == 0); + EXPECT(draw_bounded(0.0f, 1.0f, inside, blue_inside) == 0); + std::printf("depth bounds via slot 86: outside yellow=%u blue=%u; inside yellow=%u blue=%u\n", + outside, blue_outside, inside, blue_inside); + EXPECT(outside == 0 && blue_outside == size * size && inside == size * size && blue_inside == 0); } else { // No depthBounds here: the layer refuses such a PSO with E_NOTIMPL. On a device that prepares PSOs on // demand the refusal comes at the first use instead, and only if the flag arrived: a stream flag dropped ``` </details>
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 11:05 UTC · original · reviewed

Built the exact head and its immediate parent (#815) with MSVC on Windows 11. On an NVIDIA GeForce RTX 5070 (610.88), d3d12_mesh passed on the parent and failed on this head with 4096 yellow pixels outside the expected bounds. Two issues with the new fixture are inline. With a scratch-only correction to the clear value, readback buffer and fence, the full default-mode mesh test passed and reported 0 outside / 4096 inside. The on-demand run still stops at SUCCEEDED(console_hr) on both commits, before the new case. d3d12_bundle_forbidden passed at this head. d3d12_close_parity had the same three CopyTextureRegion expectations fail on both commits.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 11:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#pullrequestreview-6073024788) · **reviewed** Built the exact head and its immediate parent (#815) with MSVC on Windows 11. On an NVIDIA GeForce RTX 5070 (610.88), `d3d12_mesh` passed on the parent and failed on this head with 4096 yellow pixels outside the expected bounds. Two issues with the new fixture are inline. With a scratch-only correction to the clear value, readback buffer and fence, the full default-mode mesh test passed and reported 0 outside / 4096 inside. The `on-demand` run still stops at `SUCCEEDED(console_hr)` on both commits, before the new case. `d3d12_bundle_forbidden` passed at this head. `d3d12_close_parity` had the same three CopyTextureRegion expectations fail on both commits. AI-assisted.
@ -487,0 +534,4 @@
D3D12_RESOURCE_STATE_RENDER_TARGET);
list->ResourceBarrier(1, &to_rt);
list->ClearRenderTargetView(rtv, blue, 0, nullptr);
list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 11:05 UTC · original

[P2] Clear stored depth outside the tested bounds.

Depth bounds compares the value already in the depth attachment. The fixture clears it to 1.0, inside [0.9, 1.0], so the first draw can paint yellow with the flag working. Clearing to 0.0 produced the expected 0 outside and 4096 inside. See the Vulkan depth-bounds operation and D3D12 OMSetDepthBounds remarks.

**@⁠lixonik** on GitHub · 2026-11-26 11:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4707452106) [P2] Clear stored depth outside the tested bounds. Depth bounds compares the value already in the depth attachment. The fixture clears it to 1.0, inside [0.9, 1.0], so the first draw can paint yellow with the flag working. Clearing to 0.0 produced the expected 0 outside and 4096 inside. See the [Vulkan depth-bounds operation](https://docs.vulkan.org/spec/latest/chapters/fragops.html#fragops-depthbounds) and [D3D12 OMSetDepthBounds remarks](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist1-omsetdepthbounds#remarks).
@ -487,0 +551,4 @@
EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr)));
void* pixels_out = nullptr;
EXPECT(SUCCEEDED(readback->Map(0, nullptr, &pixels_out)));
std::memcpy(pixels.data(), pixels_out, pixels.size());
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 11:05 UTC · original

[P2] Keep the depth-bounds readback out of the mesh image's pixels buffer.

Once the clear value is fixed, the second bounds draw overwrites pixels with all yellow. The final mesh comparison then fails at (0,0), where it expects red. Use a separate local buffer for these draws. Both calls also signal and wait for fence value 2, which the later test reuses. A dedicated fence with increasing values made the two readbacks independent and left the later mesh comparison intact.

**@⁠lixonik** on GitHub · 2026-11-26 11:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4707452113) [P2] Keep the depth-bounds readback out of the mesh image's `pixels` buffer. Once the clear value is fixed, the second bounds draw overwrites `pixels` with all yellow. The final mesh comparison then fails at (0,0), where it expects red. Use a separate local buffer for these draws. Both calls also signal and wait for fence value 2, which the later test reuses. A dedicated fence with increasing values made the two readbacks independent and left the later mesh comparison intact.
github-bot force-pushed github-bot/gh-2234 from 6b7d0fd219 to a6e66c76c3 2026-11-26 12:09:59 +00:00 Compare
github-bot force-pushed github-bot/gh-2234 from a6e66c76c3 to 9b3f211d36 2026-11-27 03:20:12 +00:00 Compare
Author
Owner

@⁠star41905453-coder on GitHub · 2026-11-27 03:17 UTC · original
On runtime/test/d3d12_mesh_test.cpp line 537 (outdated):

@@ -484,6 +492,110 @@ int main(int argc, char** argv) {
             queue->ExecuteCommandLists(1, lists);
             EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::invalid_draw);
         }
+        // Depth bounds through the stream and the lazy realization: these PSOs are created pending (the record is
+        // realized on first use), and a depth-bounds flag dropped on the way into create_graphics would let the
+        // fragment through. The VS writes z = 0, so bounds of 0.9..1.0 must leave the target blue and 0.0..1.0 must
+        // paint it yellow.
+        D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_options{};
+        EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_options,
+                                                     sizeof(bounds_options))));
+        if (bounds_options.DepthBoundsTestSupported) {
+            Ref<ID3D12GraphicsCommandList1> list1;
+            EXPECT(SUCCEEDED(list->QueryInterface(IID_PPV_ARGS(&list1.p))));
+            D3D12_RESOURCE_DESC depth_desc = rt_desc;
+            depth_desc.Format = DXGI_FORMAT_D32_FLOAT;
+            depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
+            Ref<ID3D12Resource> depth_image;
+            EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &depth_desc,
+                                                             D3D12_RESOURCE_STATE_COMMON, nullptr,
+                                                             IID_PPV_ARGS(&depth_image.p))));
+            const D3D12_DESCRIPTOR_HEAP_DESC dsv_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1,
+                                                      D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0};
+            Ref<ID3D12DescriptorHeap> dsv_heap;
+            EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&dsv_desc, IID_PPV_ARGS(&dsv_heap.p))));
+            const D3D12_CPU_DESCRIPTOR_HANDLE dsv{
+                SIZE_T(reinterpret_cast<XboxHeapHandleFn>(slot(dsv_heap.p, 9))(dsv_heap.p))};
+            device->CreateDepthStencilView(depth_image.p, nullptr, dsv);
+            Stream bounds_stream = vs_stream;
+            D3D12_DEPTH_STENCIL_DESC1 bounds{};
+            bounds.DepthEnable = TRUE;
+            bounds.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
+            bounds.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
+            bounds.DepthBoundsTestEnable = TRUE;
+            bounds_stream.add(DepthStencil1Subobject{.inner = bounds});
+            bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{
+                .inner = DXGI_FORMAT_D32_FLOAT});
+            Ref<ID3D12PipelineState> bounds_pso;
+            EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p);
+
+            const auto draw_bounded = [&](float low, float high) {
+                EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, bounds_pso.p)));
+                D3D12_RESOURCE_BARRIER to_rt = transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE,
+                                                           D3D12_RESOURCE_STATE_RENDER_TARGET);
+                list->ResourceBarrier(1, &to_rt);
+                list->ClearRenderTargetView(rtv, blue, 0, nullptr);
+                list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);

Fixed in a6e←rebased head: depth now clears to 0.0 so the test decides, and the bounds draws write into their own readback buffer, leaving the mesh rows alone.

**@⁠star41905453-coder** on GitHub · 2026-11-27 03:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4715342488) On `runtime/test/d3d12_mesh_test.cpp` line 537 (outdated): ```diff @@ -484,6 +492,110 @@ int main(int argc, char** argv) { queue->ExecuteCommandLists(1, lists); EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::invalid_draw); } + // Depth bounds through the stream and the lazy realization: these PSOs are created pending (the record is + // realized on first use), and a depth-bounds flag dropped on the way into create_graphics would let the + // fragment through. The VS writes z = 0, so bounds of 0.9..1.0 must leave the target blue and 0.0..1.0 must + // paint it yellow. + D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_options{}; + EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_options, + sizeof(bounds_options)))); + if (bounds_options.DepthBoundsTestSupported) { + Ref<ID3D12GraphicsCommandList1> list1; + EXPECT(SUCCEEDED(list->QueryInterface(IID_PPV_ARGS(&list1.p)))); + D3D12_RESOURCE_DESC depth_desc = rt_desc; + depth_desc.Format = DXGI_FORMAT_D32_FLOAT; + depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + Ref<ID3D12Resource> depth_image; + EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &depth_desc, + D3D12_RESOURCE_STATE_COMMON, nullptr, + IID_PPV_ARGS(&depth_image.p)))); + const D3D12_DESCRIPTOR_HEAP_DESC dsv_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1, + D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; + Ref<ID3D12DescriptorHeap> dsv_heap; + EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&dsv_desc, IID_PPV_ARGS(&dsv_heap.p)))); + const D3D12_CPU_DESCRIPTOR_HANDLE dsv{ + SIZE_T(reinterpret_cast<XboxHeapHandleFn>(slot(dsv_heap.p, 9))(dsv_heap.p))}; + device->CreateDepthStencilView(depth_image.p, nullptr, dsv); + Stream bounds_stream = vs_stream; + D3D12_DEPTH_STENCIL_DESC1 bounds{}; + bounds.DepthEnable = TRUE; + bounds.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + bounds.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS; + bounds.DepthBoundsTestEnable = TRUE; + bounds_stream.add(DepthStencil1Subobject{.inner = bounds}); + bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{ + .inner = DXGI_FORMAT_D32_FLOAT}); + Ref<ID3D12PipelineState> bounds_pso; + EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p); + + const auto draw_bounded = [&](float low, float high) { + EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, bounds_pso.p))); + D3D12_RESOURCE_BARRIER to_rt = transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET); + list->ResourceBarrier(1, &to_rt); + list->ClearRenderTargetView(rtv, blue, 0, nullptr); + list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); ``` Fixed in a6e←rebased head: depth now clears to 0.0 so the test decides, and the bounds draws write into their own readback buffer, leaving the mesh rows alone.
Author
Owner

@⁠star41905453-coder on GitHub · 2026-11-27 03:17 UTC · original
On runtime/test/d3d12_mesh_test.cpp line 554 (outdated):

@@ -484,6 +492,110 @@ int main(int argc, char** argv) {
             queue->ExecuteCommandLists(1, lists);
             EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::invalid_draw);
         }
+        // Depth bounds through the stream and the lazy realization: these PSOs are created pending (the record is
+        // realized on first use), and a depth-bounds flag dropped on the way into create_graphics would let the
+        // fragment through. The VS writes z = 0, so bounds of 0.9..1.0 must leave the target blue and 0.0..1.0 must
+        // paint it yellow.
+        D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_options{};
+        EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_options,
+                                                     sizeof(bounds_options))));
+        if (bounds_options.DepthBoundsTestSupported) {
+            Ref<ID3D12GraphicsCommandList1> list1;
+            EXPECT(SUCCEEDED(list->QueryInterface(IID_PPV_ARGS(&list1.p))));
+            D3D12_RESOURCE_DESC depth_desc = rt_desc;
+            depth_desc.Format = DXGI_FORMAT_D32_FLOAT;
+            depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
+            Ref<ID3D12Resource> depth_image;
+            EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &depth_desc,
+                                                             D3D12_RESOURCE_STATE_COMMON, nullptr,
+                                                             IID_PPV_ARGS(&depth_image.p))));
+            const D3D12_DESCRIPTOR_HEAP_DESC dsv_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1,
+                                                      D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0};
+            Ref<ID3D12DescriptorHeap> dsv_heap;
+            EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&dsv_desc, IID_PPV_ARGS(&dsv_heap.p))));
+            const D3D12_CPU_DESCRIPTOR_HANDLE dsv{
+                SIZE_T(reinterpret_cast<XboxHeapHandleFn>(slot(dsv_heap.p, 9))(dsv_heap.p))};
+            device->CreateDepthStencilView(depth_image.p, nullptr, dsv);
+            Stream bounds_stream = vs_stream;
+            D3D12_DEPTH_STENCIL_DESC1 bounds{};
+            bounds.DepthEnable = TRUE;
+            bounds.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
+            bounds.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
+            bounds.DepthBoundsTestEnable = TRUE;
+            bounds_stream.add(DepthStencil1Subobject{.inner = bounds});
+            bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{
+                .inner = DXGI_FORMAT_D32_FLOAT});
+            Ref<ID3D12PipelineState> bounds_pso;
+            EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p);
+
+            const auto draw_bounded = [&](float low, float high) {
+                EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, bounds_pso.p)));
+                D3D12_RESOURCE_BARRIER to_rt = transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE,
+                                                           D3D12_RESOURCE_STATE_RENDER_TARGET);
+                list->ResourceBarrier(1, &to_rt);
+                list->ClearRenderTargetView(rtv, blue, 0, nullptr);
+                list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);
+                list->SetGraphicsRootSignature(root.p);
+                list->RSSetViewports(1, &viewport);
+                list->RSSetScissorRects(1, &scissor);
+                list->OMSetRenderTargets(1, &rtv, FALSE, &dsv);
+                list1->OMSetDepthBounds(low, high);
+                list->SetGraphicsRootConstantBufferView(1, upload_va + 512);
+                list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+                list->DrawInstanced(3, 1, 0, 0);
+                list->ResourceBarrier(1, &to_copy);
+                list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
+                EXPECT(list->Close() == S_OK);
+                queue->ExecuteCommandLists(1, lists);
+                EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success);
+                EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr)));
+                void* pixels_out = nullptr;
+                EXPECT(SUCCEEDED(readback->Map(0, nullptr, &pixels_out)));
+                std::memcpy(pixels.data(), pixels_out, pixels.size());

Fixed in a6e←rebased head: depth now clears to 0.0 so the test decides, and the bounds draws write into their own readback buffer, leaving the mesh rows alone.

**@⁠star41905453-coder** on GitHub · 2026-11-27 03:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4715342588) On `runtime/test/d3d12_mesh_test.cpp` line 554 (outdated): ```diff @@ -484,6 +492,110 @@ int main(int argc, char** argv) { queue->ExecuteCommandLists(1, lists); EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::invalid_draw); } + // Depth bounds through the stream and the lazy realization: these PSOs are created pending (the record is + // realized on first use), and a depth-bounds flag dropped on the way into create_graphics would let the + // fragment through. The VS writes z = 0, so bounds of 0.9..1.0 must leave the target blue and 0.0..1.0 must + // paint it yellow. + D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_options{}; + EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_options, + sizeof(bounds_options)))); + if (bounds_options.DepthBoundsTestSupported) { + Ref<ID3D12GraphicsCommandList1> list1; + EXPECT(SUCCEEDED(list->QueryInterface(IID_PPV_ARGS(&list1.p)))); + D3D12_RESOURCE_DESC depth_desc = rt_desc; + depth_desc.Format = DXGI_FORMAT_D32_FLOAT; + depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + Ref<ID3D12Resource> depth_image; + EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &depth_desc, + D3D12_RESOURCE_STATE_COMMON, nullptr, + IID_PPV_ARGS(&depth_image.p)))); + const D3D12_DESCRIPTOR_HEAP_DESC dsv_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1, + D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; + Ref<ID3D12DescriptorHeap> dsv_heap; + EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&dsv_desc, IID_PPV_ARGS(&dsv_heap.p)))); + const D3D12_CPU_DESCRIPTOR_HANDLE dsv{ + SIZE_T(reinterpret_cast<XboxHeapHandleFn>(slot(dsv_heap.p, 9))(dsv_heap.p))}; + device->CreateDepthStencilView(depth_image.p, nullptr, dsv); + Stream bounds_stream = vs_stream; + D3D12_DEPTH_STENCIL_DESC1 bounds{}; + bounds.DepthEnable = TRUE; + bounds.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL; + bounds.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS; + bounds.DepthBoundsTestEnable = TRUE; + bounds_stream.add(DepthStencil1Subobject{.inner = bounds}); + bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{ + .inner = DXGI_FORMAT_D32_FLOAT}); + Ref<ID3D12PipelineState> bounds_pso; + EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p); + + const auto draw_bounded = [&](float low, float high) { + EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, bounds_pso.p))); + D3D12_RESOURCE_BARRIER to_rt = transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET); + list->ResourceBarrier(1, &to_rt); + list->ClearRenderTargetView(rtv, blue, 0, nullptr); + list->ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr); + list->SetGraphicsRootSignature(root.p); + list->RSSetViewports(1, &viewport); + list->RSSetScissorRects(1, &scissor); + list->OMSetRenderTargets(1, &rtv, FALSE, &dsv); + list1->OMSetDepthBounds(low, high); + list->SetGraphicsRootConstantBufferView(1, upload_va + 512); + list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + list->DrawInstanced(3, 1, 0, 0); + list->ResourceBarrier(1, &to_copy); + list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + EXPECT(list->Close() == S_OK); + queue->ExecuteCommandLists(1, lists); + EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success); + EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr))); + void* pixels_out = nullptr; + EXPECT(SUCCEEDED(readback->Map(0, nullptr, &pixels_out))); + std::memcpy(pixels.data(), pixels_out, pixels.size()); ``` Fixed in a6e←rebased head: depth now clears to 0.0 so the test decides, and the bounds draws write into their own readback buffer, leaving the mesh rows alone.
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 12:14 UTC · original · reviewed

Retested 9b3f211d3 locally merged onto main a3bafd05d02b on Windows 11 with MSVC 19.44 (Release), NVIDIA GeForce RTX 5070 (610.88); Vulkan validation was unavailable locally, so the GPU checks ran without it.

  • The d3d12_vulkan_device.cpp fix itself is verified red/green on the real on-demand path: in a scratch check with info.features = d.enabled, info.prepare_on_bind = true, and PSO creation through Xbox slot 86 (prepare_console_stream --> set_pending_stream --> resolve_type), main drew 4096 outside, 4096 inside while 9b3f211d3 drew 0 outside, 4096 inside.
  • However, in the committed d3d12_mesh_test (d3d12_mesh and d3d12_mesh_heavy_cache passed 2/2), the new depth-bounds draw block is currently skipped on RTX 5070, does not hit the on-demand resolve_type path even when enabled, and still reuses fence value 2 across both draws. Running d3d12_mesh_test with LEONIDA_PIPELINE_COMPILE=on-demand still fails earlier at line 382 (SUCCEEDED(console_hr) && console_pso.p), and there is no d3d12_mesh_on_demand CTest target in runtime/CMakeLists.txt. Details inline.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-27 12:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#pullrequestreview-6087953924) · **reviewed** Retested `9b3f211d3` locally merged onto `main` `a3bafd05d02b` on Windows 11 with MSVC 19.44 (Release), NVIDIA GeForce RTX 5070 (610.88); Vulkan validation was unavailable locally, so the GPU checks ran without it. - The `d3d12_vulkan_device.cpp` fix itself is verified red/green on the real on-demand path: in a scratch check with `info.features = d.enabled`, `info.prepare_on_bind = true`, and PSO creation through Xbox slot 86 (`prepare_console_stream` --> `set_pending_stream` --> `resolve_type`), `main` drew `4096 outside, 4096 inside` while `9b3f211d3` drew `0 outside, 4096 inside`. - However, in the committed `d3d12_mesh_test` (`d3d12_mesh` and `d3d12_mesh_heavy_cache` passed 2/2), the new depth-bounds draw block is currently skipped on RTX 5070, does not hit the on-demand `resolve_type` path even when enabled, and still reuses fence value `2` across both draws. Running `d3d12_mesh_test` with `LEONIDA_PIPELINE_COMPILE=on-demand` still fails earlier at line 382 (`SUCCEEDED(console_hr) && console_pso.p`), and there is no `d3d12_mesh_on_demand` CTest target in `runtime/CMakeLists.txt`. Details inline. AI-assisted.
@ -509,0 +515,4 @@
D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_support{};
EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_support,
sizeof bounds_support)));
if (bounds_support.DepthBoundsTestSupported) {
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 12:14 UTC · original

[P2] The new depth-bounds draw block is silently skipped even on depth-bounds-capable GPUs because device_info in d3d12_mesh_test.cpp (lines 149-167) does not set info.features = d.enabled.

  • Condition: running unmodified d3d12_mesh at 9b3f211d3 (merged onto a3bafd05d02b) on an RTX 5070 where vk_test_device.h enables depthBounds.
  • Actual result: state_.info.features.depthBounds stays VK_FALSE, CheckFeatureSupport(OPTIONS2) reports DepthBoundsTestSupported == FALSE, the earlier check at line 356 logs depth-bounds tests need depthBounds, which the device lacks, and lines 518-597 never run (no depth bounds through a pending stream: output).
  • Expected / how to verify: forward info.features = d.enabled; in device_info (matching d3d12_depth24_draw_test.cpp and d3d12_translated_draw_test.cpp) and verify that d3d12_mesh logs 0 px outside the bounds, 4096 px inside on a depthBounds GPU.
**@⁠lixonik** on GitHub · 2026-11-27 12:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4719233128) [P2] The new depth-bounds draw block is silently skipped even on depth-bounds-capable GPUs because `device_info` in `d3d12_mesh_test.cpp` (lines 149-167) does not set `info.features = d.enabled`. - Condition: running unmodified `d3d12_mesh` at `9b3f211d3` (merged onto `a3bafd05d02b`) on an RTX 5070 where `vk_test_device.h` enables `depthBounds`. - Actual result: `state_.info.features.depthBounds` stays `VK_FALSE`, `CheckFeatureSupport(OPTIONS2)` reports `DepthBoundsTestSupported == FALSE`, the earlier check at line 356 logs `depth-bounds tests need depthBounds, which the device lacks`, and lines 518-597 never run (no `depth bounds through a pending stream:` output). - Expected / how to verify: forward `info.features = d.enabled;` in `device_info` (matching `d3d12_depth24_draw_test.cpp` and `d3d12_translated_draw_test.cpp`) and verify that `d3d12_mesh` logs `0 px outside the bounds, 4096 px inside` on a `depthBounds` GPU.
@ -509,0 +553,4 @@
bounds_stream.add(Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT, DXGI_FORMAT>{
.inner = DXGI_FORMAT_D32_FLOAT});
Ref<ID3D12PipelineState> bounds_pso;
EXPECT(SUCCEEDED(create(device.p, bounds_stream, bounds_pso)) && bounds_pso.p);
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 12:14 UTC · original

[P2] Even with info.features = d.enabled, this case does not exercise PipelineState::resolve_type (the on-demand path changed in d3d12_vulkan_device.cpp).

  • Condition: added only info.features = d.enabled; in scratch, reverted the two-line fix in d3d12_vulkan_device.cpp back to main, and ran d3d12_mesh_test.
  • Actual result: the test still passed and printed depth bounds through a pending stream: 0 px outside the bounds, 4096 px inside because default d3d12_mesh has prepare_on_bind == false and create() calls PC ID3D12Device2::CreatePipelineState (the eager call site at d3d12_vulkan_device.cpp:17624), bypassing DeviceProxy::prepare_stream (which only wraps Xbox slots 86 and 55 when prepare_on_bind is true). Setting LEONIDA_PIPELINE_COMPILE=on-demand fails earlier at line 382 (console_hr).
  • Expected / how to verify: create a dedicated device with info.features = d.enabled and info.prepare_on_bind = true, create bounds_pso via Xbox slot 86 (slot(device.p, 86)), and draw through it. On RTX 5070 that control gave 4096 outside, 4096 inside on main and 0 outside, 4096 inside with this PR.
**@⁠lixonik** on GitHub · 2026-11-27 12:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4719233133) [P2] Even with `info.features = d.enabled`, this case does not exercise `PipelineState::resolve_type` (the on-demand path changed in `d3d12_vulkan_device.cpp`). - Condition: added only `info.features = d.enabled;` in scratch, reverted the two-line fix in `d3d12_vulkan_device.cpp` back to `main`, and ran `d3d12_mesh_test`. - Actual result: the test still passed and printed `depth bounds through a pending stream: 0 px outside the bounds, 4096 px inside` because default `d3d12_mesh` has `prepare_on_bind == false` and `create()` calls PC `ID3D12Device2::CreatePipelineState` (the eager call site at `d3d12_vulkan_device.cpp:17624`), bypassing `DeviceProxy::prepare_stream` (which only wraps Xbox slots 86 and 55 when `prepare_on_bind` is true). Setting `LEONIDA_PIPELINE_COMPILE=on-demand` fails earlier at line 382 (`console_hr`). - Expected / how to verify: create a dedicated device with `info.features = d.enabled` and `info.prepare_on_bind = true`, create `bounds_pso` via Xbox slot 86 (`slot(device.p, 86)`), and draw through it. On RTX 5070 that control gave `4096 outside, 4096 inside` on `main` and `0 outside, 4096 inside` with this PR.
@ -509,0 +577,4 @@
EXPECT(list->Close() == S_OK);
queue->ExecuteCommandLists(1, lists);
EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success);
EXPECT(SUCCEEDED(queue->Signal(fence.p, 2)) && SUCCEEDED(fence->SetEventOnCompletion(2, nullptr)));
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 12:14 UTC · original

[P3] draw_bounded still signals and waits on fence value 2 for both draws (and line 785 reuses 2 again).

After draw_bounded(0.9f, 1.0f) completes, fence_.completed() is already 2. On the second call draw_bounded(0.0f, 1.0f), Fence::claim(2, true) returns false (no signal submitted, d3d12_com.cpp:2600) and SetEventOnCompletion(2, nullptr) returns immediately (d3d12_com.cpp:2298) without waiting for the second CopyTextureRegion, making the second bounds_readback read unsynchronized. Use a dedicated Ref<ID3D12Fence> inside this block with monotonically increasing values (1, then 2).

**@⁠lixonik** on GitHub · 2026-11-27 12:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2234#discussion_r4719233141) [P3] `draw_bounded` still signals and waits on `fence` value `2` for both draws (and line 785 reuses `2` again). After `draw_bounded(0.9f, 1.0f)` completes, `fence_.completed()` is already `2`. On the second call `draw_bounded(0.0f, 1.0f)`, `Fence::claim(2, true)` returns `false` (no signal submitted, `d3d12_com.cpp:2600`) and `SetEventOnCompletion(2, nullptr)` returns immediately (`d3d12_com.cpp:2298`) without waiting for the second `CopyTextureRegion`, making the second `bounds_readback` read unsynchronized. Use a dedicated `Ref<ID3D12Fence>` inside this block with monotonically increasing values (`1`, then `2`).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2234/head:github-bot/gh-2234'
git switch 'github-bot/gh-2234'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2234'
git switch 'github-bot/gh-2234'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2234'
git switch 'github-bot/gh-2234'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2234'
git switch 'main'
git merge --squash 'github-bot/gh-2234'
git switch 'main'
git merge --ff-only 'github-bot/gh-2234'
git switch 'main'
git merge 'github-bot/gh-2234'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.