Repository navigation
d3d12: the on-demand stream carries the depth-bounds flag too (DEPTH-BOUNDS-ON-DEMAND-STREAM) - #2234
star41905453-coder wants to merge 1 commit into
Conversation
|
The depth-bounds forwarding works on an RTX 4090 (Windows, NVIDIA 616.64). I tested
Three additional on-demand runs on the PR head gave the same pixel counts. Both passing modes completed the full mesh executable under 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 I used Test-only patch used on 6b7d0fd (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 |
lixonik
left a comment
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
| 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()); |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
6b7d0fd to
a6e66c7
Compare
…BOUNDS-ON-DEMAND-STREAM) A stream realized on demand (PipelineState::set_pending_stream, resolved on first use) goes through a second create_graphics call site that passes neither the depth-bounds flag nor the back-face stencil masks, so a title that binds a console PSO before it is realized silently loses DepthBoundsTestEnable - the test is then always on and clips nothing. Pass both there, as the eager call site does. Test (d3d12_mesh_test): the stream PSO with DepthBoundsTestEnable is now drawn through. Depth is cleared to 0.0, outside the first bounds, so the test decides and not the clear; the full-screen triangle is drawn with 0.9..1.0 (nothing may paint) and 0.0..1.0 (the whole viewport must). The draws use their own readback buffer, so the mesh image rows compared later are untouched. Where the device has no depthBounds (llvmpipe here) the creation is refused instead and success would mean the flag was dropped. Depends on: ubiquitarianism#815
a6e66c7 to
9b3f211
Compare
lixonik
left a comment
There was a problem hiding this comment.
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.cppfix itself is verified red/green on the real on-demand path: in a scratch check withinfo.features = d.enabled,info.prepare_on_bind = true, and PSO creation through Xbox slot 86 (prepare_console_stream-->set_pending_stream-->resolve_type),maindrew4096 outside, 4096 insidewhile9b3f211d3drew0 outside, 4096 inside. - However, in the committed
d3d12_mesh_test(d3d12_meshandd3d12_mesh_heavy_cachepassed 2/2), the new depth-bounds draw block is currently skipped on RTX 5070, does not hit the on-demandresolve_typepath even when enabled, and still reuses fence value2across both draws. Runningd3d12_mesh_testwithLEONIDA_PIPELINE_COMPILE=on-demandstill fails earlier at line 382 (SUCCEEDED(console_hr) && console_pso.p), and there is nod3d12_mesh_on_demandCTest target inruntime/CMakeLists.txt. Details inline.
AI-assisted.
| D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_support{}; | ||
| EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_support, | ||
| sizeof bounds_support))); | ||
| if (bounds_support.DepthBoundsTestSupported) { |
There was a problem hiding this comment.
[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_meshat9b3f211d3(merged ontoa3bafd05d02b) on an RTX 5070 wherevk_test_device.henablesdepthBounds. - Actual result:
state_.info.features.depthBoundsstaysVK_FALSE,CheckFeatureSupport(OPTIONS2)reportsDepthBoundsTestSupported == FALSE, the earlier check at line 356 logsdepth-bounds tests need depthBounds, which the device lacks, and lines 518-597 never run (nodepth bounds through a pending stream:output). - Expected / how to verify: forward
info.features = d.enabled;indevice_info(matchingd3d12_depth24_draw_test.cppandd3d12_translated_draw_test.cpp) and verify thatd3d12_meshlogs0 px outside the bounds, 4096 px insideon adepthBoundsGPU.
| 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); |
There was a problem hiding this comment.
[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 ind3d12_vulkan_device.cppback tomain, and rand3d12_mesh_test. - Actual result: the test still passed and printed
depth bounds through a pending stream: 0 px outside the bounds, 4096 px insidebecause defaultd3d12_meshhasprepare_on_bind == falseandcreate()calls PCID3D12Device2::CreatePipelineState(the eager call site atd3d12_vulkan_device.cpp:17624), bypassingDeviceProxy::prepare_stream(which only wraps Xbox slots 86 and 55 whenprepare_on_bindis true). SettingLEONIDA_PIPELINE_COMPILE=on-demandfails earlier at line 382 (console_hr). - Expected / how to verify: create a dedicated device with
info.features = d.enabledandinfo.prepare_on_bind = true, createbounds_psovia Xbox slot 86 (slot(device.p, 86)), and draw through it. On RTX 5070 that control gave4096 outside, 4096 insideonmainand0 outside, 4096 insidewith this PR.
| 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))); |
There was a problem hiding this comment.
[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).
A stream realized on demand (
PipelineState::set_pending_stream, resolved on first use) went through a secondcreate_graphicscall 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 lostDepthBoundsTestEnable— 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 withDepthBoundsTestEnableis now drawn through, not only created.pixelsand broke that comparison).depthBounds(llvmpipe here) creation is refused instead, and a success there would mean the flag was dropped.Run:
d3d12_mesh,d3d12_mesh_on_demandandd3d12_mesh_heavy_cachepass 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.