upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/d3d12_mesh_test.cpp
diff options
context:
space:
mode:
authorTauwni <102470988+Tauwni@users.noreply.github.com>2026-11-26 12:19:12 +0100
committerTauwni <102470988+Tauwni@users.noreply.github.com>2026-11-26 12:19:12 +0100
commitbeffaa9a476ca1b3dfd9cfa55e39eafbb1f5eec6 (patch)
tree32877805bf4eb46d9a89d5753db6b5a2b06dc845 /runtime/test/d3d12_mesh_test.cpp
parentf29ca7bacae9507f83e8c56abdb604bd4efb4cf1 (diff)
parenta73a57e1339be072baf5522351c8ec7f1482b56b (diff)
Merge main into fix/null-descriptor-generated-dir
Diffstat (limited to 'runtime/test/d3d12_mesh_test.cpp')
-rw-r--r--runtime/test/d3d12_mesh_test.cpp68
1 files changed, 62 insertions, 6 deletions
diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp
index 2d9bc5212..775cfeb58 100644
--- a/runtime/test/d3d12_mesh_test.cpp
+++ b/runtime/test/d3d12_mesh_test.cpp
@@ -5,15 +5,16 @@
5// - With it: MeshShaderTier 1; CreatePipelineState builds an MS + PS PSO and a VS + PS PSO from streams laid out as 5// - With it: MeshShaderTier 1; CreatePipelineState builds an MS + PS PSO and a VS + PS PSO from streams laid out as
6// d3dx12.h lays them out (each subobject a type and its description, pointer-aligned); streams the PC runtime 6// d3dx12.h lays them out (each subobject a type and its description, pointer-aligned); streams the PC runtime
7// refuses (MS with VS, CS with PS, a subobject twice or in two versions, an unknown type, a truncated stream) are E_INVALIDARG, and 7// refuses (MS with VS, CS with PS, a subobject twice or in two versions, an unknown type, a truncated stream) are E_INVALIDARG, and
8// state not built yet (an amplification shader, a depth-bounds test) is E_NOTIMPL. 8// state not built yet (an amplification shader) is E_NOTIMPL; a depth-bounds test builds where the device
9// reports DepthBoundsTestSupported, and is E_NOTIMPL where it does not.
9// - Draws: DispatchMesh(2, 2, 1) with root constants (0, 0) and a red tint fills the top-left quadrant; 10// - Draws: DispatchMesh(2, 2, 1) with root constants (0, 0) and a red tint fills the top-left quadrant;
10// DispatchMesh(1, 1, 2) moved by (1, -1) with a green tint fills the top half of the bottom-right one, so the 11// DispatchMesh(1, 1, 2) moved by (1, -1) with a green tint fills the top half of the bottom-right one, so the
11// Y and Z counts reach the shader; the stream's VS PSO draws a full-screen triangle through a viewport on the 12// Y and Z counts reach the shader; the stream's VS PSO draws a full-screen triangle through a viewport on the
12// bottom-left quadrant (yellow). Each pixel is read back and compared. 13// bottom-left quadrant (yellow). Each pixel is read back and compared.
13// - A vertex draw with the mesh PSO, and DispatchMesh with the VS one, fail at execution (ReplayResult:: 14// - A vertex draw with the mesh PSO, and DispatchMesh with the VS one, fail at execution (ReplayResult::
14// invalid_draw); a mesh grid beyond D3D12's limits fails at Close; an empty grid records nothing. 15// invalid_draw); a mesh grid beyond D3D12's limits fails at Close; an empty grid records nothing.
15// - A DISPATCH_MESH command signature is created only with the extension; ExecuteIndirect with it records nothing 16// - A DISPATCH_MESH command signature is created only with the extension; ExecuteIndirect with it draws as
16// yet, so its list closes. 17// DispatchMesh (one record {2, 1, 1} fills two cells), and without graphics state it records nothing and closes.
17// The shaders are GLSL written to the translator's contract (test/glsl/ms_draw.mesh, ps_draw.frag, vs_fullscreen.vert). 18// The shaders are GLSL written to the translator's contract (test/glsl/ms_draw.mesh, ps_draw.frag, vs_fullscreen.vert).
18// No game data. Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation. 19// No game data. Set LEONIDA_VK_VALIDATION=1 to run under VK_LAYER_KHRONOS_validation.
19#include "vk_test_device.h" 20#include "vk_test_device.h"
@@ -317,7 +318,14 @@ int main(int argc, char** argv) {
317 D3D12_DEPTH_STENCIL_DESC1 bounds{}; 318 D3D12_DEPTH_STENCIL_DESC1 bounds{};
318 bounds.DepthBoundsTestEnable = TRUE; 319 bounds.DepthBoundsTestEnable = TRUE;
319 bad.add(DepthStencil1Subobject{.inner = bounds}); 320 bad.add(DepthStencil1Subobject{.inner = bounds});
320 EXPECT(create(device.p, bad, refused) == E_NOTIMPL && !refused.p); 321 {
322 D3D12_FEATURE_DATA_D3D12_OPTIONS2 o2{};
323 EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &o2, sizeof o2)));
324 Ref<ID3D12PipelineState> with_bounds;
325 const HRESULT bounds_hr = create(device.p, bad, with_bounds);
326 EXPECT(o2.DepthBoundsTestSupported ? SUCCEEDED(bounds_hr) && with_bounds.p
327 : bounds_hr == E_NOTIMPL && !with_bounds.p);
328 }
321 329
322 // A console stream: its numbering has no gap at 23, so its mesh shader is 24 (the PC's AS) and its 330 // A console stream: its numbering has no gap at 23, so its mesh shader is 24 (the PC's AS) and its
323 // RASTERIZER1 26 (the PC's DEPTH_STENCIL2). An AS without an MS is no PC stream, so the layer reads it with the 331 // RASTERIZER1 26 (the PC's DEPTH_STENCIL2). An AS without an MS is no PC stream, so the layer reads it with the
@@ -468,6 +476,54 @@ int main(int argc, char** argv) {
468 EXPECT(SUCCEEDED(readback->Map(0, nullptr, &mapped))); 476 EXPECT(SUCCEEDED(readback->Map(0, nullptr, &mapped)));
469 std::memcpy(pixels.data(), mapped, pixels.size()); 477 std::memcpy(pixels.data(), mapped, pixels.size());
470 478
479 // ExecuteIndirect with a DISPATCH_MESH signature draws as DispatchMesh (vkCmdDrawMeshTasksIndirectEXT after
480 // the clamp pass): one record {2, 1, 1} at upload + 768 fills columns 0 and 1 of row 0, the top half of the
481 // top-left quadrant, red; the rest of the cleared target stays blue.
482 {
483 const std::uint32_t record[3] = {2, 1, 1};
484 std::memcpy(up + 768, record, sizeof record);
485 const D3D12_INDIRECT_ARGUMENT_DESC mesh_arg{D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH};
486 const D3D12_COMMAND_SIGNATURE_DESC mesh_sig{12, 1, &mesh_arg, 0};
487 Ref<ID3D12CommandSignature> sig;
488 Ref<ID3D12Fence> indirect_fence;
489 EXPECT(SUCCEEDED(device->CreateCommandSignature(&mesh_sig, nullptr, IID_PPV_ARGS(&sig.p))) && sig.p);
490 EXPECT(SUCCEEDED(device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&indirect_fence.p))));
491 EXPECT(SUCCEEDED(allocator->Reset()) && SUCCEEDED(list->Reset(allocator.p, mesh_pso.p)));
492 D3D12_RESOURCE_BARRIER again =
493 transition(target.p, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
494 list->ResourceBarrier(1, &again);
495 list->ClearRenderTargetView(rtv, blue, 0, nullptr);
496 list->SetGraphicsRootSignature(root.p);
497 list->RSSetViewports(1, &viewport);
498 list->RSSetScissorRects(1, &scissor);
499 list->OMSetRenderTargets(1, &rtv, FALSE, nullptr);
500 list->SetGraphicsRoot32BitConstants(0, 2, origin, 0);
501 list->SetGraphicsRootConstantBufferView(1, upload_va);
502 list->ExecuteIndirect(sig.p, 1, upload.p, 768, nullptr, 0);
503 list->ResourceBarrier(1, &to_copy);
504 list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr);
505 EXPECT(list->Close() == S_OK);
506 queue->ExecuteCommandLists(1, lists);
507 EXPECT(rt::d3d12::last_execute_result(queue.p) == leonida::ReplayResult::success);
508 EXPECT(SUCCEEDED(queue->Signal(indirect_fence.p, 1)) &&
509 SUCCEEDED(indirect_fence->SetEventOnCompletion(1, nullptr)));
510 unsigned wrong = 0;
511 for (UINT row = 0; row < size; ++row) {
512 for (UINT col = 0; col < size; ++col) {
513 const bool red = row < size / 4 && col < size / 2;
514 const std::uint8_t want[4] = {std::uint8_t(red ? 255 : 0), 0, std::uint8_t(red ? 0 : 255), 255};
515 const auto* got = static_cast<const std::uint8_t*>(mapped) + row * 256 + col * 4;
516 if (std::equal(want, want + 4, got)) continue;
517 if (wrong++ < 6)
518 std::fprintf(stderr, "indirect mesh pixel (%u, %u): got %u,%u,%u,%u want %u,%u,%u,%u\n", col,
519 row, got[0], got[1], got[2], got[3], want[0], want[1], want[2], want[3]);
520 }
521 }
522 EXPECT(!wrong);
523 std::printf("ExecuteIndirect DISPATCH_MESH {2, 1, 1} drew as DispatchMesh(2, 1, 1): %u pixels matched\n",
524 size * size);
525 }
526
471 // The wrong kind of draw for the pipeline fails at execution: a vertex draw with the mesh PSO, then 527 // The wrong kind of draw for the pipeline fails at execution: a vertex draw with the mesh PSO, then
472 // DispatchMesh with the VS PSO. 528 // DispatchMesh with the VS PSO.
473 for (const bool vertex_draw : {true, false}) { 529 for (const bool vertex_draw : {true, false}) {
@@ -591,8 +647,8 @@ int main(int argc, char** argv) {
591 enabled ? "" : " (LEONIDA_GRAPHICS_DIRECT_HEAPS=0: not written)"); 647 enabled ? "" : " (LEONIDA_GRAPHICS_DIRECT_HEAPS=0: not written)");
592 } 648 }
593 // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its 649 // A DISPATCH_MESH command signature (D3D12_DISPATCH_MESH_ARGUMENTS, 12 bytes) is created; a stride below its
594 // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it records nothing yet (#3777 replays 650 // 12 bytes is refused as the PC runtime refuses it. ExecuteIndirect with it and no viewport records
595 // it), so the list still closes. 651 // nothing, so the list still closes.
596 { 652 {
597 const D3D12_INDIRECT_ARGUMENT_DESC mesh_arg{D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH}; 653 const D3D12_INDIRECT_ARGUMENT_DESC mesh_arg{D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH};
598 const D3D12_COMMAND_SIGNATURE_DESC mesh_sig{12, 1, &mesh_arg, 0}; 654 const D3D12_COMMAND_SIGNATURE_DESC mesh_sig{12, 1, &mesh_arg, 0};