diff --git a/engine/src/flutter/impeller/entity/contents/content_context.cc b/engine/src/flutter/impeller/entity/contents/content_context.cc index a127be4407..947777105a 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.cc +++ b/engine/src/flutter/impeller/entity/contents/content_context.cc @@ -481,8 +481,9 @@ bool ContentContext::IsValid() const { } fml::StatusOr ContentContext::MakeSubpass( - const std::string& label, + std::string_view label, ISize texture_size, + const std::shared_ptr& command_buffer, const SubpassCallback& subpass_callback, bool msaa_enabled, bool depth_stencil_enabled, @@ -497,20 +498,21 @@ fml::StatusOr ContentContext::MakeSubpass( if (context->GetCapabilities()->SupportsOffscreenMSAA() && msaa_enabled) { subpass_target = GetRenderTargetCache()->CreateOffscreenMSAA( *context, texture_size, - /*mip_count=*/mip_count, SPrintF("%s Offscreen", label.c_str()), + /*mip_count=*/mip_count, SPrintF("%s Offscreen", label.data()), RenderTarget::kDefaultColorAttachmentConfigMSAA, depth_stencil_config); } else { subpass_target = GetRenderTargetCache()->CreateOffscreen( *context, texture_size, - /*mip_count=*/mip_count, SPrintF("%s Offscreen", label.c_str()), + /*mip_count=*/mip_count, SPrintF("%s Offscreen", label.data()), RenderTarget::kDefaultColorAttachmentConfig, depth_stencil_config); } - return MakeSubpass(label, subpass_target, subpass_callback); + return MakeSubpass(label, subpass_target, command_buffer, subpass_callback); } fml::StatusOr ContentContext::MakeSubpass( - const std::string& label, + std::string_view label, const RenderTarget& subpass_target, + const std::shared_ptr& command_buffer, const SubpassCallback& subpass_callback) const { const std::shared_ptr& context = GetContext(); @@ -519,17 +521,11 @@ fml::StatusOr ContentContext::MakeSubpass( return fml::Status(fml::StatusCode::kUnknown, ""); } - auto sub_command_buffer = context->CreateCommandBuffer(); - sub_command_buffer->SetLabel(SPrintF("%s CommandBuffer", label.c_str())); - if (!sub_command_buffer) { - return fml::Status(fml::StatusCode::kUnknown, ""); - } - - auto sub_renderpass = sub_command_buffer->CreateRenderPass(subpass_target); + auto sub_renderpass = command_buffer->CreateRenderPass(subpass_target); if (!sub_renderpass) { return fml::Status(fml::StatusCode::kUnknown, ""); } - sub_renderpass->SetLabel(SPrintF("%s RenderPass", label.c_str())); + sub_renderpass->SetLabel(SPrintF("%s RenderPass", label.data())); if (!subpass_callback(*this, *sub_renderpass)) { return fml::Status(fml::StatusCode::kUnknown, ""); @@ -543,16 +539,12 @@ fml::StatusOr ContentContext::MakeSubpass( subpass_target.GetRenderTargetTexture(); if (target_texture->GetMipCount() > 1) { fml::Status mipmap_status = - AddMipmapGeneration(sub_command_buffer, context, target_texture); + AddMipmapGeneration(command_buffer, context, target_texture); if (!mipmap_status.ok()) { return mipmap_status; } } - if (!context->GetCommandQueue()->Submit({sub_command_buffer}).ok()) { - return fml::Status(fml::StatusCode::kUnknown, ""); - } - return subpass_target; } diff --git a/engine/src/flutter/impeller/entity/contents/content_context.h b/engine/src/flutter/impeller/entity/contents/content_context.h index ab84526ba5..a9977f1f2a 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.h +++ b/engine/src/flutter/impeller/entity/contents/content_context.h @@ -783,8 +783,9 @@ class ContentContext { /// @brief Creates a new texture of size `texture_size` and calls /// `subpass_callback` with a `RenderPass` for drawing to the texture. fml::StatusOr MakeSubpass( - const std::string& label, + std::string_view label, ISize texture_size, + const std::shared_ptr& command_buffer, const SubpassCallback& subpass_callback, bool msaa_enabled = true, bool depth_stencil_enabled = false, @@ -792,8 +793,9 @@ class ContentContext { /// Makes a subpass that will render to `subpass_target`. fml::StatusOr MakeSubpass( - const std::string& label, + std::string_view label, const RenderTarget& subpass_target, + const std::shared_ptr& command_buffer, const SubpassCallback& subpass_callback) const; const std::shared_ptr& GetLazyGlyphAtlas() const { diff --git a/engine/src/flutter/impeller/entity/contents/contents.cc b/engine/src/flutter/impeller/entity/contents/contents.cc index 7c0c62af98..7bcf97fc1c 100644 --- a/engine/src/flutter/impeller/entity/contents/contents.cc +++ b/engine/src/flutter/impeller/entity/contents/contents.cc @@ -76,6 +76,12 @@ std::optional Contents::RenderToSnapshot( return std::nullopt; } + std::shared_ptr command_buffer = + renderer.GetContext()->CreateCommandBuffer(); + if (!command_buffer) { + return std::nullopt; + } + // Pad Contents snapshots with 1 pixel borders to ensure correct sampling // behavior. Not doing so results in a coverage leak for filters that support // customizing the input sampling mode. Snapshots of contents should be @@ -91,7 +97,7 @@ std::optional Contents::RenderToSnapshot( ISize subpass_size = ISize::Ceil(coverage->GetSize()); fml::StatusOr render_target = renderer.MakeSubpass( - label, subpass_size, + label, subpass_size, command_buffer, [&contents = *this, &entity, &coverage](const ContentContext& renderer, RenderPass& pass) -> bool { Entity sub_entity; @@ -107,6 +113,12 @@ std::optional Contents::RenderToSnapshot( if (!render_target.ok()) { return std::nullopt; } + if (!renderer.GetContext() + ->GetCommandQueue() + ->Submit(/*buffers=*/{std::move(command_buffer)}) + .ok()) { + return std::nullopt; + } auto snapshot = Snapshot{ .texture = render_target.value().GetRenderTargetTexture(), diff --git a/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc index 968fddbf70..9924cbf554 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc @@ -223,11 +223,23 @@ static std::optional AdvancedBlend( return pass.Draw().ok(); }; + std::shared_ptr command_buffer = + renderer.GetContext()->CreateCommandBuffer(); + if (!command_buffer) { + return std::nullopt; + } fml::StatusOr render_target = renderer.MakeSubpass( - "Advanced Blend Filter", ISize(subpass_coverage.GetSize()), callback); + "Advanced Blend Filter", ISize(subpass_coverage.GetSize()), + command_buffer, callback); if (!render_target.ok()) { return std::nullopt; } + if (!renderer.GetContext() + ->GetCommandQueue() + ->Submit(/*buffers=*/{std::move(command_buffer)}) + .ok()) { + return std::nullopt; + } return Entity::FromSnapshot( Snapshot{ @@ -525,13 +537,27 @@ static std::optional PipelineBlend( return true; }; + std::shared_ptr command_buffer = + renderer.GetContext()->CreateCommandBuffer(); + if (!command_buffer) { + return std::nullopt; + } + fml::StatusOr render_target = renderer.MakeSubpass( - "Pipeline Blend Filter", ISize(subpass_coverage.GetSize()), callback); + "Pipeline Blend Filter", ISize(subpass_coverage.GetSize()), + command_buffer, callback); if (!render_target.ok()) { return std::nullopt; } + if (!renderer.GetContext() + ->GetCommandQueue() + ->Submit(/*buffers=*/{std::move(command_buffer)}) + .ok()) { + return std::nullopt; + } + return Entity::FromSnapshot( Snapshot{ .texture = render_target.value().GetRenderTargetTexture(), diff --git a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 07b91c915c..525da5adef 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -77,6 +77,7 @@ void SetTileMode(SamplerDescriptor* descriptor, /// transparent gutter required for the blur halo. fml::StatusOr MakeDownsampleSubpass( const ContentContext& renderer, + const std::shared_ptr& command_buffer, std::shared_ptr input_texture, const SamplerDescriptor& sampler_descriptor, const Quad& uvs, @@ -118,12 +119,13 @@ fml::StatusOr MakeDownsampleSubpass( return pass.Draw().ok(); }; fml::StatusOr render_target = renderer.MakeSubpass( - "Gaussian Blur Filter", subpass_size, subpass_callback); + "Gaussian Blur Filter", subpass_size, command_buffer, subpass_callback); return render_target; } fml::StatusOr MakeBlurSubpass( const ContentContext& renderer, + const std::shared_ptr& command_buffer, const RenderTarget& input_pass, const SamplerDescriptor& sampler_descriptor, Entity::TileMode tile_mode, @@ -184,10 +186,11 @@ fml::StatusOr MakeBlurSubpass( }; if (destination_target.has_value()) { return renderer.MakeSubpass("Gaussian Blur Filter", - destination_target.value(), subpass_callback); + destination_target.value(), command_buffer, + subpass_callback); } else { return renderer.MakeSubpass("Gaussian Blur Filter", subpass_size, - subpass_callback); + command_buffer, subpass_callback); } } @@ -459,9 +462,15 @@ std::optional GaussianBlurFilterContents::RenderFilter( Quad uvs = CalculateUVs(inputs[0], entity, source_rect_padded, input_snapshot->texture->GetSize()); + std::shared_ptr command_buffer = + renderer.GetContext()->CreateCommandBuffer(); + if (!command_buffer) { + return std::nullopt; + } + fml::StatusOr pass1_out = MakeDownsampleSubpass( - renderer, input_snapshot->texture, input_snapshot->sampler_descriptor, - uvs, subpass_size, tile_mode_); + renderer, command_buffer, input_snapshot->texture, + input_snapshot->sampler_descriptor, uvs, subpass_size, tile_mode_); if (!pass1_out.ok()) { return std::nullopt; @@ -494,7 +503,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( } fml::StatusOr pass2_out = MakeBlurSubpass( - renderer, /*input_pass=*/pass1_out.value(), + renderer, command_buffer, /*input_pass=*/pass1_out.value(), input_snapshot->sampler_descriptor, tile_mode_, BlurParameters{ .blur_uv_offset = Point(0.0, pass1_pixel_size.y), @@ -515,7 +524,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( : std::optional(std::nullopt); fml::StatusOr pass3_out = MakeBlurSubpass( - renderer, /*input_pass=*/pass2_out.value(), + renderer, command_buffer, /*input_pass=*/pass2_out.value(), input_snapshot->sampler_descriptor, tile_mode_, BlurParameters{ .blur_uv_offset = Point(pass1_pixel_size.x, 0.0), @@ -529,6 +538,13 @@ std::optional GaussianBlurFilterContents::RenderFilter( return std::nullopt; } + if (!renderer.GetContext() + ->GetCommandQueue() + ->Submit(/*buffers=*/{command_buffer}) + .ok()) { + return std::nullopt; + } + // The ping-pong approach requires that each render pass output has the same // size. FML_DCHECK((pass1_out.value().GetRenderTargetSize() == diff --git a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc index 73b49ae136..9d0a87d544 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc @@ -74,9 +74,24 @@ class GaussianBlurFilterContentsTest : public EntityPlayground { public: /// Create a texture that has been cleared to transparent black. std::shared_ptr MakeTexture(ISize size) { + std::shared_ptr command_buffer = + GetContentContext()->GetContext()->CreateCommandBuffer(); + if (!command_buffer) { + return nullptr; + } + auto render_target = GetContentContext()->MakeSubpass( - "Clear Subpass", size, + "Clear Subpass", size, command_buffer, [](const ContentContext&, RenderPass&) { return true; }); + + if (!GetContentContext() + ->GetContext() + ->GetCommandQueue() + ->Submit(/*buffers=*/{command_buffer}) + .ok()) { + return nullptr; + } + if (render_target.ok()) { return render_target.value().GetRenderTargetTexture(); } diff --git a/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc index 5aa0e35ac9..72557c8d54 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/morphology_filter_contents.cc @@ -134,12 +134,24 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( return pass.Draw().ok(); }; + std::shared_ptr command_buffer = + renderer.GetContext()->CreateCommandBuffer(); + if (command_buffer == nullptr) { + return std::nullopt; + } - fml::StatusOr render_target = renderer.MakeSubpass( - "Directional Morphology Filter", ISize(coverage.GetSize()), callback); + fml::StatusOr render_target = + renderer.MakeSubpass("Directional Morphology Filter", + ISize(coverage.GetSize()), command_buffer, callback); if (!render_target.ok()) { return std::nullopt; } + if (!renderer.GetContext() + ->GetCommandQueue() + ->Submit(/*buffers=*/{std::move(command_buffer)}) + .ok()) { + return std::nullopt; + } SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear;