Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11469,7 +11469,9 @@ 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.depth_bounds);
});
}
return registered_ && (is_graphics_==graphics);
Expand Down
91 changes: 91 additions & 0 deletions runtime/test/d3d12_mesh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,97 @@ int main(int argc, char** argv) {
EXPECT(SUCCEEDED(readback->Map(0, nullptr, &mapped)));
std::memcpy(pixels.data(), mapped, pixels.size());

// Depth bounds through the stream, drawn: the PSO is created pending and realized on first use, so a flag
// dropped on the way into create_graphics would let the fragment through. The depth attachment is cleared to
// 0.0, outside the first bounds, so the bounds test is what decides, not the clear. The VS writes z = 0, so
// 0.9..1.0 must leave the target blue and 0.0..1.0 must paint it yellow. Its own readback buffer, so the mesh
// image rows above stay as they are.
{
D3D12_FEATURE_DATA_D3D12_OPTIONS2 bounds_support{};
EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &bounds_support,
sizeof bounds_support)));
if (bounds_support.DepthBoundsTestSupported) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

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);

Ref<ID3D12Resource> bounds_readback;
const auto bounds_desc = buffer_desc(size * 256);
EXPECT(SUCCEEDED(device->CreateCommittedResource(&readback_heap, D3D12_HEAP_FLAG_NONE, &bounds_desc,
D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS(&bounds_readback.p))));
D3D12_TEXTURE_COPY_LOCATION bounds_dst{};
bounds_dst.pResource = bounds_readback.p;
bounds_dst.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
bounds_dst.PlacedFootprint = dst.PlacedFootprint;

Stream bounds_stream = vs_stream;
D3D12_DEPTH_STENCIL_DESC1 bounds_state{};
bounds_state.DepthEnable = TRUE;
bounds_state.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
bounds_state.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
bounds_state.DepthBoundsTestEnable = TRUE;
bounds_stream.add(DepthStencil1Subobject{.inner = bounds_state});
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.


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, 0.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);
D3D12_RESOURCE_BARRIER to_copy_again =
transition(target.p, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
list->ResourceBarrier(1, &to_copy_again);
list->CopyTextureRegion(&bounds_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)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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).

std::vector<std::uint8_t> shot(size * 256);
void* bounds_mapped = nullptr;
EXPECT(SUCCEEDED(bounds_readback->Map(0, nullptr, &bounds_mapped)));
std::memcpy(shot.data(), bounds_mapped, shot.size());
UINT yellow = 0;
for (UINT i = 0; i + 3 < shot.size(); i += 4)
yellow += shot[i] > 200 && shot[i + 1] > 200 && shot[i + 2] < 60;
return int(yellow);
};
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);
// Leave the target where the next block expects it, and the pixels buffer untouched: it is only
// rewritten below, and that row is compared at the end.
}
}

// ExecuteIndirect with a DISPATCH_MESH signature draws as DispatchMesh (vkCmdDrawMeshTasksIndirectEXT after
// the clamp pass): one record {2, 1, 1} at upload + 768 fills columns 0 and 1 of row 0, the top half of the
// top-left quadrant, red; the rest of the cleared target stays blue.
Expand Down
Loading