mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 14:58:37 +00:00
There was no resolve, and a multisampled committed texture was refused. - IR: ResolveSubresource (two different resources). - Replay: ResolveSubresource is vkCmdResolveImage in the layouts copies use: a multisampled colour subresource into a single-sampled 2D one of the same size and format. Depth-stencil resolves and resolves between two formats of a typeless family stay unsupported. ResourceBinding gains samples: a multisampled texture copies only to its own sample count and has no footprint. - Device: committed multisampled 2D textures (single-mip render targets or depth-stencils, when the GPU has the sample count for the format; the other shapes are E_INVALIDARG as in D3D12), and TEXTURE2DMS render-target and depth-stencil views. - COM: ID3D12GraphicsCommandList::ResolveSubresource. Tests: command_list_test (recording rules, and a copy with a z range); vk_command_replay_test part C (a 4x resolve and the refused resolves and multisampled copies; it also runs the volume copies that are already on main at the Vulkan level, on Linux too: a 4x4x4 volume uploaded, copied as a block and whole, read back, and the z ranges that must be refused); d3d12_vulkan_device_test (a resolve through the Xbox-ABI proxy and the refused shapes). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
151 lines
8.7 KiB
C++
151 lines
8.7 KiB
C++
#include "../src/command_list.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#define CHECK(condition) do { \
|
|
if (!(condition)) { \
|
|
std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); \
|
|
return 1; \
|
|
} \
|
|
} while (0)
|
|
|
|
int main() {
|
|
using namespace leonida;
|
|
namespace s = d3d12_state;
|
|
CommandList list;
|
|
TargetView descriptor{12, 1, 2, 3};
|
|
ClearColor color{1, 0, 0, 1};
|
|
CHECK(!list.closed());
|
|
CHECK(!list.clear_render_target({}, color));
|
|
CHECK(list.clear_render_target(descriptor, color));
|
|
// The CPU descriptor slot is reused; the recorded view keeps the old contents.
|
|
descriptor = {24, 0, 0, 1};
|
|
color[0] = 0;
|
|
color[1] = 1;
|
|
CHECK(list.clear_render_target(descriptor, color));
|
|
|
|
// Barriers: a split barrier records only its end half.
|
|
CHECK(!list.transition({0, 0, s::common, s::render_target}));
|
|
CHECK(list.transition({24, all_subresources, s::render_target, s::copy_source}, barrier_begin_only));
|
|
CHECK(list.transition({24, all_subresources, s::render_target, s::copy_source}, barrier_end_only));
|
|
CHECK(!list.transition({24, 0, s::common, s::copy_dest}, barrier_begin_only | barrier_end_only));
|
|
CHECK(!list.transition({24, 0, s::common, s::copy_dest}, 0x4));
|
|
CHECK(list.uav_barrier({0}));
|
|
CHECK(list.aliasing_barrier({0, 24}));
|
|
|
|
// Depth-stencil clears: at least one flag, no unknown flags, depth in [0, 1].
|
|
const TargetView depth{48, 0, 0, 1};
|
|
CHECK(!list.clear_depth_stencil(depth, 0, 1.0f, 0));
|
|
CHECK(!list.clear_depth_stencil(depth, 0x4, 1.0f, 0));
|
|
CHECK(!list.clear_depth_stencil(depth, clear_depth, 1.5f, 0));
|
|
CHECK(!list.clear_depth_stencil(depth, clear_depth, -0.0001f, 0));
|
|
CHECK(!list.clear_depth_stencil({}, clear_depth, 1.0f, 0));
|
|
CHECK(list.clear_depth_stencil(depth, clear_stencil, 7.0f, 0x5a)); // depth is ignored without clear_depth
|
|
CHECK(list.clear_depth_stencil(depth, clear_depth | clear_stencil, 0.25f, 3));
|
|
|
|
CHECK(list.close());
|
|
CHECK(list.closed());
|
|
CHECK(!list.close());
|
|
CHECK(!list.clear_render_target(descriptor, color));
|
|
CHECK(!list.transition({24, 0, s::copy_source, s::render_target}));
|
|
CHECK(!list.uav_barrier({0}));
|
|
|
|
const auto commands = list.commands();
|
|
CHECK(commands.size() == 7);
|
|
const auto* first = std::get_if<ClearRenderTarget>(&commands[0]);
|
|
const auto* second = std::get_if<ClearRenderTarget>(&commands[1]);
|
|
CHECK(first && second);
|
|
CHECK(first->target.resource == 12 && second->target.resource == 24);
|
|
CHECK(first->target.mip == 1 && first->target.first_layer == 2 && first->target.layer_count == 3);
|
|
const ClearColor red{1, 0, 0, 1};
|
|
CHECK(first->color == red && second->color == color);
|
|
const auto* transition = std::get_if<TransitionBarrier>(&commands[2]);
|
|
CHECK(transition && transition->resource == 24 && transition->subresource == all_subresources);
|
|
CHECK(transition->before == s::render_target && transition->after == s::copy_source);
|
|
CHECK(std::get_if<UavBarrier>(&commands[3]) && std::get<UavBarrier>(commands[3]).resource == 0);
|
|
CHECK(std::get_if<AliasingBarrier>(&commands[4]) && std::get<AliasingBarrier>(commands[4]).after == 24);
|
|
const auto* stencil = std::get_if<ClearDepthStencil>(&commands[5]);
|
|
CHECK(stencil && stencil->flags == clear_stencil && stencil->stencil == 0x5a);
|
|
const auto* both = std::get_if<ClearDepthStencil>(&commands[6]);
|
|
CHECK(both && both->flags == (clear_depth | clear_stencil) && both->depth == 0.25f && both->stencil == 3);
|
|
|
|
// Rectangles are copied while recording.
|
|
CHECK(list.reset());
|
|
Rect rects[] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
|
|
CHECK(list.clear_render_target({36, 0, 0, 1}, color, rects));
|
|
CHECK(list.clear_depth_stencil({48, 0, 0, 1}, clear_depth, 0.5f, 0, {rects, 1}));
|
|
rects[0] = {};
|
|
CHECK(list.close());
|
|
const auto& rect_clear = std::get<ClearRenderTarget>(list.commands()[0]);
|
|
CHECK(rect_clear.rects.size() == 2 && rect_clear.rects[0].left == 1 && rect_clear.rects[1].bottom == 8);
|
|
CHECK(std::get<ClearDepthStencil>(list.commands()[1]).rects.size() == 1);
|
|
|
|
// Enhanced barriers: split begin halves are dropped, end halves kept; invalid shapes are refused.
|
|
namespace y = d3d12_sync;
|
|
namespace a = d3d12_access;
|
|
namespace l = d3d12_layout;
|
|
CHECK(list.reset());
|
|
const BarrierSubresourceRange all{all_subresources, 0, 0, 0, 0, 0};
|
|
CHECK(list.barrier(GlobalBarrier{y::all, y::all, a::common, a::common}));
|
|
CHECK(list.barrier(GlobalBarrier{y::compute_shading, y::split, a::unordered_access, a::shader_resource}));
|
|
CHECK(list.barrier(GlobalBarrier{y::split, y::pixel_shading, a::unordered_access, a::shader_resource}));
|
|
CHECK(!list.barrier(GlobalBarrier{y::split, y::split, 0, 0}));
|
|
CHECK(list.barrier(BufferBarrier{y::copy, y::vertex_shading, a::copy_dest, a::vertex_buffer, 7}));
|
|
CHECK(!list.barrier(BufferBarrier{y::copy, y::vertex_shading, a::copy_dest, a::vertex_buffer, 0}));
|
|
CHECK(list.barrier(TextureBarrier{y::none, y::render_target, a::no_access, a::render_target, l::undefined,
|
|
l::render_target, 9, all, texture_barrier_discard}));
|
|
CHECK(!list.barrier(TextureBarrier{y::all, y::all, a::common, a::common, l::common, l::undefined, 9, all, 0}));
|
|
CHECK(!list.barrier(TextureBarrier{y::all, y::all, a::common, a::common, l::common, l::common, 9, all, 0x2}));
|
|
CHECK(!list.barrier(TextureBarrier{y::all, y::all, a::common, a::common, l::common, l::common, 9,
|
|
{0, 1, 0, 0, 0, 1}, 0})); // zero layers
|
|
CHECK(list.close());
|
|
CHECK(list.commands().size() == 4);
|
|
CHECK(std::get<GlobalBarrier>(list.commands()[1]).sync_before == y::split);
|
|
CHECK(std::get<BufferBarrier>(list.commands()[2]).resource == 7);
|
|
CHECK(std::get<TextureBarrier>(list.commands()[3]).flags == texture_barrier_discard);
|
|
|
|
// Copies: D3D12's own call rules (aligned footprints, a non-empty box, distinct CopyResource operands).
|
|
CHECK(list.reset());
|
|
CHECK(list.copy_buffer({1, 0, 2, 16, 64}));
|
|
CHECK(!list.copy_buffer({1, 0, 2, 16, 0}));
|
|
CHECK(!list.copy_buffer({0, 0, 2, 16, 64}));
|
|
const CopyLocation texture{3, false, 0, 0, 0, 0, 0, 0};
|
|
const CopyLocation placed{4, true, 0, 512, 8, 8, 1, 256};
|
|
CHECK(list.copy_texture({texture, 0, 0, 0, placed, false, {}}));
|
|
CHECK(list.copy_texture({placed, 0, 0, 0, texture, true, {2, 2, 0, 6, 6, 1}}));
|
|
CHECK(!list.copy_texture({placed, 0, 0, 0, placed, false, {}})); // footprint to footprint
|
|
CHECK(!list.copy_texture({texture, 0, 0, 0, {4, true, 0, 100, 8, 8, 1, 256}, false, {}})); // offset not 512
|
|
CHECK(!list.copy_texture({texture, 0, 0, 0, {4, true, 0, 512, 8, 8, 1, 100}, false, {}})); // pitch not 256
|
|
CHECK(!list.copy_texture({texture, 0, 0, 0, texture, true, {2, 2, 0, 2, 6, 1}})); // empty box
|
|
CHECK(list.copy_resource({5, 6}));
|
|
CHECK(!list.copy_resource({5, 5}));
|
|
// A volume's box has a z range, and its footprint a depth; a resolve needs two different resources.
|
|
CHECK(list.copy_texture({texture, 0, 0, 2, {4, true, 0, 512, 4, 4, 4, 256}, true, {0, 0, 1, 4, 4, 3}}));
|
|
CHECK(!list.copy_texture({texture, 0, 0, 0, {4, true, 0, 512, 4, 4, 0, 256}, false, {}})); // no slices
|
|
CHECK(!list.copy_texture({texture, 0, 0, 0, texture, true, {0, 0, 2, 4, 4, 2}})); // empty in z
|
|
CHECK(list.resolve_subresource({7, 1, 8, 0}));
|
|
CHECK(!list.resolve_subresource({7, 0, 7, 0}));
|
|
CHECK(!list.resolve_subresource({0, 0, 8, 0}));
|
|
CHECK(!list.resolve_subresource({7, 0, 0, 0}));
|
|
CHECK(list.close());
|
|
CHECK(!list.resolve_subresource({7, 1, 8, 0}));
|
|
CHECK(list.commands().size() == 6);
|
|
CHECK(std::get<CopyBuffer>(list.commands()[0]).src_offset == 16);
|
|
CHECK(std::get<CopyTexture>(list.commands()[1]).src.footprint && !std::get<CopyTexture>(list.commands()[1]).has_box);
|
|
CHECK(std::get<CopyTexture>(list.commands()[2]).box.right == 6);
|
|
CHECK(std::get<CopyResource>(list.commands()[3]).src == 6);
|
|
const auto& slices = std::get<CopyTexture>(list.commands()[4]);
|
|
CHECK(slices.z == 2 && slices.src.depth == 4 && slices.box.front == 1 && slices.box.back == 3);
|
|
const auto& resolved = std::get<ResolveSubresource>(list.commands()[5]);
|
|
CHECK(resolved.dst == 7 && resolved.dst_subresource == 1 && resolved.src == 8 && resolved.src_subresource == 0);
|
|
|
|
CHECK(list.reset());
|
|
CHECK(!list.closed() && list.commands().empty());
|
|
CHECK(!list.reset());
|
|
CHECK(list.clear_render_target({36, 0, 0, 1}, color));
|
|
CHECK(list.close());
|
|
CHECK(list.commands().size() == 1);
|
|
CHECK(std::get<ClearRenderTarget>(list.commands()[0]).target.resource == 36);
|
|
return 0;
|
|
}
|