Plan recorded OpenGL command streams
This commit is contained in:
@@ -2,9 +2,54 @@
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
pp::renderer::RecordedRenderCommand begin_render_pass_command() noexcept
|
||||
{
|
||||
pp::renderer::RecordedRenderCommand command;
|
||||
command.kind = pp::renderer::RecordedRenderCommandKind::begin_render_pass;
|
||||
command.target_desc.extent = pp::renderer::Extent2D { .width = 64U, .height = 64U };
|
||||
command.target_desc.format = pp::renderer::TextureFormat::rgba8;
|
||||
command.clear_color_enabled = true;
|
||||
command.clear_depth_enabled = true;
|
||||
return command;
|
||||
}
|
||||
|
||||
pp::renderer::RecordedRenderCommand command_with_kind(
|
||||
pp::renderer::RecordedRenderCommandKind kind) noexcept
|
||||
{
|
||||
pp::renderer::RecordedRenderCommand command;
|
||||
command.kind = kind;
|
||||
return command;
|
||||
}
|
||||
|
||||
pp::renderer::RecordedRenderCommand viewport_command() noexcept
|
||||
{
|
||||
pp::renderer::RecordedRenderCommand command;
|
||||
command.kind = pp::renderer::RecordedRenderCommandKind::set_viewport;
|
||||
command.viewport = pp::renderer::Viewport { .width = 64U, .height = 64U };
|
||||
return command;
|
||||
}
|
||||
|
||||
pp::renderer::RecordedRenderCommand draw_command() noexcept
|
||||
{
|
||||
pp::renderer::RecordedRenderCommand command;
|
||||
command.kind = pp::renderer::RecordedRenderCommandKind::draw;
|
||||
command.mesh_desc.topology = pp::renderer::PrimitiveTopology::triangles;
|
||||
command.draw_desc.vertex_count = 3U;
|
||||
return command;
|
||||
}
|
||||
|
||||
pp::renderer::RecordedRenderCommand blit_command(pp::renderer::BlitFilter filter) noexcept
|
||||
{
|
||||
pp::renderer::RecordedRenderCommand command;
|
||||
command.kind = pp::renderer::RecordedRenderCommandKind::blit_render_target;
|
||||
command.blit_filter = filter;
|
||||
return command;
|
||||
}
|
||||
|
||||
void maps_render_pass_and_state_commands(pp::tests::Harness& h)
|
||||
{
|
||||
const auto begin = pp::renderer::gl::plan_recorded_render_command(pp::renderer::RecordedRenderCommand {
|
||||
@@ -180,6 +225,87 @@ void names_planned_command_kinds(pp::tests::Harness& h)
|
||||
== std::string_view("unknown"));
|
||||
}
|
||||
|
||||
void plans_valid_recorded_command_streams(pp::tests::Harness& h)
|
||||
{
|
||||
const std::vector<pp::renderer::RecordedRenderCommand> commands {
|
||||
command_with_kind(pp::renderer::RecordedRenderCommandKind::trace_begin_scope),
|
||||
begin_render_pass_command(),
|
||||
viewport_command(),
|
||||
command_with_kind(pp::renderer::RecordedRenderCommandKind::bind_shader),
|
||||
draw_command(),
|
||||
command_with_kind(pp::renderer::RecordedRenderCommandKind::end_render_pass),
|
||||
blit_command(pp::renderer::BlitFilter::nearest),
|
||||
};
|
||||
|
||||
const auto plan = pp::renderer::gl::plan_recorded_render_commands(commands);
|
||||
|
||||
PP_EXPECT(h, plan.supported);
|
||||
PP_EXPECT(h, plan.commands.size() == commands.size());
|
||||
PP_EXPECT(h, plan.render_pass_count == 1U);
|
||||
PP_EXPECT(h, plan.draw_command_count == 1U);
|
||||
PP_EXPECT(h, plan.passthrough_command_count == 1U);
|
||||
PP_EXPECT(h, plan.trace_command_count == 1U);
|
||||
PP_EXPECT(h, plan.unsupported_command_count == 0U);
|
||||
PP_EXPECT(h, plan.render_pass_order_error_count == 0U);
|
||||
PP_EXPECT(h, plan.first_unsupported_command == pp::renderer::gl::OpenGlCommandPlan::npos);
|
||||
PP_EXPECT(h, plan.first_render_pass_order_error == pp::renderer::gl::OpenGlCommandPlan::npos);
|
||||
PP_EXPECT(h, !plan.ended_in_render_pass);
|
||||
PP_EXPECT(h, plan.commands[1].kind == pp::renderer::gl::OpenGlPlannedCommandKind::begin_render_pass);
|
||||
PP_EXPECT(h, plan.commands[3].kind == pp::renderer::gl::OpenGlPlannedCommandKind::passthrough);
|
||||
PP_EXPECT(h, plan.commands[4].kind == pp::renderer::gl::OpenGlPlannedCommandKind::draw);
|
||||
PP_EXPECT(h, plan.commands[6].kind == pp::renderer::gl::OpenGlPlannedCommandKind::blit_render_target);
|
||||
}
|
||||
|
||||
void flags_broken_render_pass_command_order(pp::tests::Harness& h)
|
||||
{
|
||||
const std::vector<pp::renderer::RecordedRenderCommand> outside_pass {
|
||||
viewport_command(),
|
||||
};
|
||||
const std::vector<pp::renderer::RecordedRenderCommand> nested_pass {
|
||||
begin_render_pass_command(),
|
||||
begin_render_pass_command(),
|
||||
command_with_kind(pp::renderer::RecordedRenderCommandKind::end_render_pass),
|
||||
};
|
||||
const std::vector<pp::renderer::RecordedRenderCommand> unclosed_pass {
|
||||
begin_render_pass_command(),
|
||||
draw_command(),
|
||||
};
|
||||
|
||||
const auto outside = pp::renderer::gl::plan_recorded_render_commands(outside_pass);
|
||||
const auto nested = pp::renderer::gl::plan_recorded_render_commands(nested_pass);
|
||||
const auto unclosed = pp::renderer::gl::plan_recorded_render_commands(unclosed_pass);
|
||||
|
||||
PP_EXPECT(h, !outside.supported);
|
||||
PP_EXPECT(h, outside.render_pass_order_error_count == 1U);
|
||||
PP_EXPECT(h, outside.first_render_pass_order_error == 0U);
|
||||
PP_EXPECT(h, !nested.supported);
|
||||
PP_EXPECT(h, nested.render_pass_order_error_count == 1U);
|
||||
PP_EXPECT(h, nested.first_render_pass_order_error == 1U);
|
||||
PP_EXPECT(h, nested.render_pass_count == 2U);
|
||||
PP_EXPECT(h, !unclosed.supported);
|
||||
PP_EXPECT(h, unclosed.render_pass_order_error_count == 1U);
|
||||
PP_EXPECT(h, unclosed.first_render_pass_order_error == unclosed_pass.size());
|
||||
PP_EXPECT(h, unclosed.ended_in_render_pass);
|
||||
}
|
||||
|
||||
void tracks_unsupported_commands_in_streams(pp::tests::Harness& h)
|
||||
{
|
||||
std::vector<pp::renderer::RecordedRenderCommand> commands {
|
||||
begin_render_pass_command(),
|
||||
draw_command(),
|
||||
command_with_kind(pp::renderer::RecordedRenderCommandKind::end_render_pass),
|
||||
command_with_kind(static_cast<pp::renderer::RecordedRenderCommandKind>(255U)),
|
||||
};
|
||||
|
||||
const auto plan = pp::renderer::gl::plan_recorded_render_commands(commands);
|
||||
|
||||
PP_EXPECT(h, !plan.supported);
|
||||
PP_EXPECT(h, plan.unsupported_command_count == 1U);
|
||||
PP_EXPECT(h, plan.first_unsupported_command == 3U);
|
||||
PP_EXPECT(h, plan.render_pass_order_error_count == 0U);
|
||||
PP_EXPECT(h, plan.commands[3].kind == pp::renderer::gl::OpenGlPlannedCommandKind::unknown);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -189,5 +315,8 @@ int main()
|
||||
harness.run("maps_binding_draw_and_blit_commands", maps_binding_draw_and_blit_commands);
|
||||
harness.run("rejects_unsupported_command_tokens", rejects_unsupported_command_tokens);
|
||||
harness.run("names_planned_command_kinds", names_planned_command_kinds);
|
||||
harness.run("plans_valid_recorded_command_streams", plans_valid_recorded_command_streams);
|
||||
harness.run("flags_broken_render_pass_command_order", flags_broken_render_pass_command_order);
|
||||
harness.run("tracks_unsupported_commands_in_streams", tracks_unsupported_commands_in_streams);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user