diff options
Diffstat (limited to 'runtime/test/command_list_test.cpp')
| -rw-r--r-- | runtime/test/command_list_test.cpp | 80 |
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 | |||
| 12 | int 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 | } | ||