upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/command_list_test.cpp
diff options
context:
space:
mode:
authorRyx <118130241+Ryx69@users.noreply.github.com>2026-11-21 18:58:48 +0100
committerRyx <118130241+Ryx69@users.noreply.github.com>2026-11-21 18:58:48 +0100
commit7f6e8f059dbd8c3202e185c972832841d6a8a9d2 (patch)
tree0b64927bd2b6d206611e2f66561a3f3ab8e7a119 /runtime/test/command_list_test.cpp
parent793b06f12765571ed5e126d1d8944cec6a4dc805 (diff)
Runtime: D3D12 barriers and depth-stencil clears in the command-list IR
The IR (command_list.h, was clear_commands.h) now records transition, UAV and aliasing barriers (split barriers record their end half) and full-view ClearDepthStencilView next to ClearRenderTargetView. vulkan_replay.h (was vulkan_clear.h) maps D3D12 resource states to Vulkan layout/access/stage (section 4.3 table), decodes subresource indices including depth/stencil planes, validates the whole list before emitting anything, and wraps clears in a layout round trip so images stay in their D3D12 state. The caller no longer manages layouts by hand. Tests: command_list_test (recording rules), d3d12_state_map_test (state table, subresource decoding, constants checked against d3d12.h; needs Vulkan headers only) and vk_command_replay_test (GPU readback of colour, depth and stencil; LEONIDA_VK_VALIDATION=1 runs it under the Khronos validation layer).
Diffstat (limited to 'runtime/test/command_list_test.cpp')
-rw-r--r--runtime/test/command_list_test.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/runtime/test/command_list_test.cpp b/runtime/test/command_list_test.cpp
new file mode 100644
index 000000000..8baa5fd81
--- /dev/null
+++ b/runtime/test/command_list_test.cpp
@@ -0,0 +1,80 @@
1#include "../src/command_list.h"
2
3#include <cstdio>
4
5#define CHECK(condition) do { \
6 if (!(condition)) { \
7 std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); \
8 return 1; \
9 } \
10} while (0)
11
12int main() {
13 using namespace leonida;
14 namespace s = d3d12_state;
15 CommandList list;
16 TargetView descriptor{12, 1, 2, 3};
17 ClearColor color{1, 0, 0, 1};
18 CHECK(!list.closed());
19 CHECK(!list.clear_render_target({}, color));
20 CHECK(list.clear_render_target(descriptor, color));
21 // The CPU descriptor slot is reused; the recorded view keeps the old contents.
22 descriptor = {24, 0, 0, 1};
23 color[0] = 0;
24 color[1] = 1;
25 CHECK(list.clear_render_target(descriptor, color));
26
27 // Barriers: a split barrier records only its end half.
28 CHECK(!list.transition({0, 0, s::common, s::render_target}));
29 CHECK(list.transition({24, all_subresources, s::render_target, s::copy_source}, barrier_begin_only));
30 CHECK(list.transition({24, all_subresources, s::render_target, s::copy_source}, barrier_end_only));
31 CHECK(!list.transition({24, 0, s::common, s::copy_dest}, barrier_begin_only | barrier_end_only));
32 CHECK(!list.transition({24, 0, s::common, s::copy_dest}, 0x4));
33 CHECK(list.uav_barrier({0}));
34 CHECK(list.aliasing_barrier({0, 24}));
35
36 // Depth-stencil clears: at least one flag, no unknown flags, depth in [0, 1].
37 const TargetView depth{48, 0, 0, 1};
38 CHECK(!list.clear_depth_stencil(depth, 0, 1.0f, 0));
39 CHECK(!list.clear_depth_stencil(depth, 0x4, 1.0f, 0));
40 CHECK(!list.clear_depth_stencil(depth, clear_depth, 1.5f, 0));
41 CHECK(!list.clear_depth_stencil(depth, clear_depth, -0.0001f, 0));
42 CHECK(!list.clear_depth_stencil({}, clear_depth, 1.0f, 0));
43 CHECK(list.clear_depth_stencil(depth, clear_stencil, 7.0f, 0x5a)); // depth is ignored without clear_depth
44 CHECK(list.clear_depth_stencil(depth, clear_depth | clear_stencil, 0.25f, 3));
45
46 CHECK(list.close());
47 CHECK(list.closed());
48 CHECK(!list.close());
49 CHECK(!list.clear_render_target(descriptor, color));
50 CHECK(!list.transition({24, 0, s::copy_source, s::render_target}));
51 CHECK(!list.uav_barrier({0}));
52
53 const auto commands = list.commands();
54 CHECK(commands.size() == 7);
55 const auto* first = std::get_if<ClearRenderTarget>(&commands[0]);
56 const auto* second = std::get_if<ClearRenderTarget>(&commands[1]);
57 CHECK(first && second);
58 CHECK(first->target.resource == 12 && second->target.resource == 24);
59 CHECK(first->target.mip == 1 && first->target.first_layer == 2 && first->target.layer_count == 3);
60 const ClearColor red{1, 0, 0, 1};
61 CHECK(first->color == red && second->color == color);
62 const auto* transition = std::get_if<TransitionBarrier>(&commands[2]);
63 CHECK(transition && transition->resource == 24 && transition->subresource == all_subresources);
64 CHECK(transition->before == s::render_target && transition->after == s::copy_source);
65 CHECK(std::get_if<UavBarrier>(&commands[3]) && std::get<UavBarrier>(commands[3]).resource == 0);
66 CHECK(std::get_if<AliasingBarrier>(&commands[4]) && std::get<AliasingBarrier>(commands[4]).after == 24);
67 const auto* stencil = std::get_if<ClearDepthStencil>(&commands[5]);
68 CHECK(stencil && stencil->flags == clear_stencil && stencil->stencil == 0x5a);
69 const auto* both = std::get_if<ClearDepthStencil>(&commands[6]);
70 CHECK(both && both->flags == (clear_depth | clear_stencil) && both->depth == 0.25f && both->stencil == 3);
71
72 CHECK(list.reset());
73 CHECK(!list.closed() && list.commands().empty());
74 CHECK(!list.reset());
75 CHECK(list.clear_render_target({36, 0, 0, 1}, color));
76 CHECK(list.close());
77 CHECK(list.commands().size() == 1);
78 CHECK(std::get<ClearRenderTarget>(list.commands()[0]).target.resource == 36);
79 return 0;
80}