Plan recorded OpenGL command streams

This commit is contained in:
2026-06-02 20:48:49 +02:00
parent ce33eaaef2
commit 9a4c595f64
5 changed files with 242 additions and 4 deletions

View File

@@ -31,6 +31,22 @@ namespace {
}
}
void record_unsupported_command(OpenGlCommandPlan& plan, std::size_t index) noexcept
{
++plan.unsupported_command_count;
if (plan.first_unsupported_command == OpenGlCommandPlan::npos) {
plan.first_unsupported_command = index;
}
}
void record_render_pass_order_error(OpenGlCommandPlan& plan, std::size_t index) noexcept
{
++plan.render_pass_order_error_count;
if (plan.first_render_pass_order_error == OpenGlCommandPlan::npos) {
plan.first_render_pass_order_error = index;
}
}
}
const char* planned_command_kind_name(OpenGlPlannedCommandKind kind) noexcept
@@ -169,4 +185,67 @@ OpenGlPlannedCommand plan_recorded_render_command(pp::renderer::RecordedRenderCo
return planned;
}
OpenGlCommandPlan plan_recorded_render_commands(
std::span<const pp::renderer::RecordedRenderCommand> commands)
{
OpenGlCommandPlan plan;
plan.commands.reserve(commands.size());
bool in_render_pass = false;
for (std::size_t index = 0; index < commands.size(); ++index) {
OpenGlPlannedCommand planned = plan_recorded_render_command(commands[index]);
if (!planned.supported) {
record_unsupported_command(plan, index);
}
switch (planned.kind) {
case OpenGlPlannedCommandKind::begin_render_pass:
++plan.render_pass_count;
if (in_render_pass) {
record_render_pass_order_error(plan, index);
}
in_render_pass = true;
break;
case OpenGlPlannedCommandKind::end_render_pass:
if (!in_render_pass) {
record_render_pass_order_error(plan, index);
}
in_render_pass = false;
break;
case OpenGlPlannedCommandKind::draw:
++plan.draw_command_count;
if (!in_render_pass) {
record_render_pass_order_error(plan, index);
}
break;
case OpenGlPlannedCommandKind::passthrough:
++plan.passthrough_command_count;
if (planned.requires_render_pass && !in_render_pass) {
record_render_pass_order_error(plan, index);
}
break;
case OpenGlPlannedCommandKind::trace:
++plan.trace_command_count;
break;
default:
if (planned.requires_render_pass && !in_render_pass) {
record_render_pass_order_error(plan, index);
}
break;
}
plan.commands.push_back(planned);
}
plan.ended_in_render_pass = in_render_pass;
if (in_render_pass) {
record_render_pass_order_error(plan, commands.size());
}
plan.supported = plan.unsupported_command_count == 0U
&& plan.render_pass_order_error_count == 0U;
return plan;
}
}

View File

@@ -3,7 +3,10 @@
#include "renderer_api/recording_renderer.h"
#include "renderer_gl/opengl_capabilities.h"
#include <cstddef>
#include <cstdint>
#include <span>
#include <vector>
namespace pp::renderer::gl {
@@ -42,8 +45,26 @@ struct OpenGlPlannedCommand {
bool supported = false;
};
struct OpenGlCommandPlan {
static constexpr std::size_t npos = static_cast<std::size_t>(-1);
std::vector<OpenGlPlannedCommand> commands;
std::uint32_t render_pass_count = 0;
std::uint32_t draw_command_count = 0;
std::uint32_t passthrough_command_count = 0;
std::uint32_t trace_command_count = 0;
std::uint32_t unsupported_command_count = 0;
std::uint32_t render_pass_order_error_count = 0;
std::size_t first_unsupported_command = npos;
std::size_t first_render_pass_order_error = npos;
bool ended_in_render_pass = false;
bool supported = true;
};
[[nodiscard]] const char* planned_command_kind_name(OpenGlPlannedCommandKind kind) noexcept;
[[nodiscard]] OpenGlPlannedCommand plan_recorded_render_command(
pp::renderer::RecordedRenderCommand command) noexcept;
[[nodiscard]] OpenGlCommandPlan plan_recorded_render_commands(
std::span<const pp::renderer::RecordedRenderCommand> commands);
}