Plan OpenGL texture command metadata

This commit is contained in:
2026-06-02 20:59:05 +02:00
parent b4c2117992
commit b6a25474ff
7 changed files with 324 additions and 30 deletions

View File

@@ -12,6 +12,23 @@ namespace {
&& format.bytes_per_pixel != 0U;
}
[[nodiscard]] bool texture_state_supported(pp::renderer::TextureState state) noexcept
{
switch (state) {
case pp::renderer::TextureState::undefined:
case pp::renderer::TextureState::shader_read:
case pp::renderer::TextureState::render_target:
case pp::renderer::TextureState::upload_destination:
case pp::renderer::TextureState::copy_source:
case pp::renderer::TextureState::copy_destination:
case pp::renderer::TextureState::readback_source:
case pp::renderer::TextureState::present:
return true;
default:
return false;
}
}
[[nodiscard]] bool requires_render_pass(pp::renderer::RecordedRenderCommandKind kind) noexcept
{
switch (kind) {
@@ -72,6 +89,18 @@ const char* planned_command_kind_name(OpenGlPlannedCommandKind kind) noexcept
return "bind_mesh";
case OpenGlPlannedCommandKind::draw:
return "draw";
case OpenGlPlannedCommandKind::upload_texture:
return "upload_texture";
case OpenGlPlannedCommandKind::generate_mipmaps:
return "generate_mipmaps";
case OpenGlPlannedCommandKind::transition_texture:
return "transition_texture";
case OpenGlPlannedCommandKind::copy_texture:
return "copy_texture";
case OpenGlPlannedCommandKind::read_texture:
return "read_texture";
case OpenGlPlannedCommandKind::capture_frame:
return "capture_frame";
case OpenGlPlannedCommandKind::blit_render_target:
return "blit_render_target";
case OpenGlPlannedCommandKind::end_render_pass:
@@ -153,10 +182,65 @@ OpenGlPlannedCommand plan_recorded_render_command(pp::renderer::RecordedRenderCo
planned.draw_index_count = command.draw_desc.index_count;
planned.supported = planned.primitive_mode != 0U;
break;
case pp::renderer::RecordedRenderCommandKind::upload_texture:
planned.kind = OpenGlPlannedCommandKind::upload_texture;
planned.texture_format = texture_format_for_renderer_format(command.texture_desc.format);
planned.readback_region = command.readback_region;
planned.upload_bytes = command.upload_bytes;
planned.supported = texture_format_supported(planned.texture_format);
break;
case pp::renderer::RecordedRenderCommandKind::generate_mipmaps:
planned.kind = OpenGlPlannedCommandKind::generate_mipmaps;
planned.texture_format = texture_format_for_renderer_format(command.texture_desc.format);
planned.generated_mip_levels = command.generated_mip_levels;
planned.generated_mip_bytes = command.generated_mip_bytes;
planned.supported = texture_format_supported(planned.texture_format);
break;
case pp::renderer::RecordedRenderCommandKind::transition_texture:
planned.kind = OpenGlPlannedCommandKind::transition_texture;
planned.texture_format = texture_format_for_renderer_format(command.texture_desc.format);
planned.before_state = command.before_state;
planned.after_state = command.after_state;
planned.supported = texture_format_supported(planned.texture_format)
&& texture_state_supported(planned.before_state)
&& texture_state_supported(planned.after_state);
break;
case pp::renderer::RecordedRenderCommandKind::copy_texture:
planned.kind = OpenGlPlannedCommandKind::copy_texture;
planned.source_texture_format = texture_format_for_renderer_format(command.source_desc.format);
planned.destination_texture_format = texture_format_for_renderer_format(command.destination_desc.format);
planned.source_region = command.source_region;
planned.destination_region = command.destination_region;
planned.copy_source_bytes = command.copy_source_bytes;
planned.copy_destination_bytes = command.copy_destination_bytes;
planned.supported = texture_format_supported(planned.source_texture_format)
&& texture_format_supported(planned.destination_texture_format);
break;
case pp::renderer::RecordedRenderCommandKind::read_texture:
planned.kind = OpenGlPlannedCommandKind::read_texture;
planned.texture_format = texture_format_for_renderer_format(command.texture_desc.format);
planned.readback_region = command.readback_region;
planned.readback_bytes = command.readback_bytes;
planned.supported = texture_format_supported(planned.texture_format);
break;
case pp::renderer::RecordedRenderCommandKind::capture_frame:
planned.kind = OpenGlPlannedCommandKind::capture_frame;
planned.texture_format = texture_format_for_renderer_format(command.target_desc.format);
planned.capture_bytes = command.capture_bytes;
planned.supported = texture_format_supported(planned.texture_format);
break;
case pp::renderer::RecordedRenderCommandKind::blit_render_target:
planned.kind = OpenGlPlannedCommandKind::blit_render_target;
planned.blit_filter = blit_filter_for_renderer_filter(command.blit_filter);
planned.supported = planned.blit_filter.supported;
planned.source_texture_format = texture_format_for_renderer_format(command.source_desc.format);
planned.destination_texture_format = texture_format_for_renderer_format(command.destination_desc.format);
planned.source_region = command.source_region;
planned.destination_region = command.destination_region;
planned.blit_source_bytes = command.blit_source_bytes;
planned.blit_destination_bytes = command.blit_destination_bytes;
planned.supported = planned.blit_filter.supported
&& texture_format_supported(planned.source_texture_format)
&& texture_format_supported(planned.destination_texture_format);
break;
case pp::renderer::RecordedRenderCommandKind::end_render_pass:
planned.kind = OpenGlPlannedCommandKind::end_render_pass;
@@ -168,12 +252,6 @@ OpenGlPlannedCommand plan_recorded_render_command(pp::renderer::RecordedRenderCo
break;
case pp::renderer::RecordedRenderCommandKind::bind_shader:
case pp::renderer::RecordedRenderCommandKind::set_shader_uniform:
case pp::renderer::RecordedRenderCommandKind::upload_texture:
case pp::renderer::RecordedRenderCommandKind::generate_mipmaps:
case pp::renderer::RecordedRenderCommandKind::transition_texture:
case pp::renderer::RecordedRenderCommandKind::copy_texture:
case pp::renderer::RecordedRenderCommandKind::read_texture:
case pp::renderer::RecordedRenderCommandKind::capture_frame:
planned.kind = OpenGlPlannedCommandKind::passthrough;
break;
default:
@@ -219,6 +297,24 @@ OpenGlCommandPlan plan_recorded_render_commands(
record_render_pass_order_error(plan, index);
}
break;
case OpenGlPlannedCommandKind::upload_texture:
++plan.upload_command_count;
break;
case OpenGlPlannedCommandKind::generate_mipmaps:
++plan.mipmap_command_count;
break;
case OpenGlPlannedCommandKind::transition_texture:
++plan.transition_command_count;
break;
case OpenGlPlannedCommandKind::copy_texture:
++plan.copy_command_count;
break;
case OpenGlPlannedCommandKind::read_texture:
++plan.readback_command_count;
break;
case OpenGlPlannedCommandKind::capture_frame:
++plan.capture_command_count;
break;
case OpenGlPlannedCommandKind::passthrough:
++plan.passthrough_command_count;
if (planned.requires_render_pass && !in_render_pass) {

View File

@@ -21,6 +21,12 @@ enum class OpenGlPlannedCommandKind : std::uint8_t {
bind_sampler,
bind_mesh,
draw,
upload_texture,
generate_mipmaps,
transition_texture,
copy_texture,
read_texture,
capture_frame,
blit_render_target,
end_render_pass,
trace,
@@ -37,7 +43,23 @@ struct OpenGlPlannedCommand {
OpenGlDepthState depth;
OpenGlSamplerState sampler;
OpenGlRendererTextureFormat texture_format;
OpenGlRendererTextureFormat source_texture_format;
OpenGlRendererTextureFormat destination_texture_format;
OpenGlEnumMapping blit_filter;
pp::renderer::TextureState before_state = pp::renderer::TextureState::undefined;
pp::renderer::TextureState after_state = pp::renderer::TextureState::undefined;
pp::renderer::ReadbackRegion readback_region;
pp::renderer::ReadbackRegion source_region;
pp::renderer::ReadbackRegion destination_region;
std::uint64_t upload_bytes = 0;
std::uint32_t generated_mip_levels = 0;
std::uint64_t generated_mip_bytes = 0;
std::uint64_t copy_source_bytes = 0;
std::uint64_t copy_destination_bytes = 0;
std::uint64_t readback_bytes = 0;
std::uint64_t capture_bytes = 0;
std::uint64_t blit_source_bytes = 0;
std::uint64_t blit_destination_bytes = 0;
std::uint32_t primitive_mode = 0;
std::uint32_t draw_vertex_count = 0;
std::uint32_t draw_index_count = 0;
@@ -51,6 +73,12 @@ struct OpenGlCommandPlan {
std::vector<OpenGlPlannedCommand> commands;
std::uint32_t render_pass_count = 0;
std::uint32_t draw_command_count = 0;
std::uint32_t upload_command_count = 0;
std::uint32_t mipmap_command_count = 0;
std::uint32_t transition_command_count = 0;
std::uint32_t copy_command_count = 0;
std::uint32_t readback_command_count = 0;
std::uint32_t capture_command_count = 0;
std::uint32_t passthrough_command_count = 0;
std::uint32_t trace_command_count = 0;
std::uint32_t unsupported_command_count = 0;