From 12cb5f5feb7ab3e29af449b27f72d17d9a36624a Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 19 Dec 2023 10:51:16 -0800 Subject: [PATCH 1/8] [Impeller] new blur: implemented ping ponging This changes the return type of MakeSubpass to a RenderTarget. --- impeller/entity/contents/content_context.cc | 14 ++++----- impeller/entity/contents/content_context.h | 10 ++++--- impeller/entity/contents/contents.cc | 6 ++-- .../contents/filters/blend_filter_contents.cc | 12 ++++---- ...rectional_gaussian_blur_filter_contents.cc | 21 +++++++------- .../filters/gaussian_blur_filter_contents.cc | 29 +++++++++++++------ .../filters/morphology_filter_contents.cc | 8 ++--- 7 files changed, 56 insertions(+), 44 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index d76131fd400a2..2499a279149be 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -405,7 +405,7 @@ bool ContentContext::IsValid() const { return is_valid_; } -std::shared_ptr ContentContext::MakeSubpass( +fml::StatusOr ContentContext::MakeSubpass( const std::string& label, ISize texture_size, const SubpassCallback& subpass_callback, @@ -430,30 +430,30 @@ std::shared_ptr ContentContext::MakeSubpass( } auto subpass_texture = subpass_target.GetRenderTargetTexture(); if (!subpass_texture) { - return nullptr; + 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 nullptr; + return fml::Status(fml::StatusCode::kUnknown, ""); } auto sub_renderpass = sub_command_buffer->CreateRenderPass(subpass_target); if (!sub_renderpass) { - return nullptr; + return fml::Status(fml::StatusCode::kUnknown, ""); } sub_renderpass->SetLabel(SPrintF("%s RenderPass", label.c_str())); if (!subpass_callback(*this, *sub_renderpass)) { - return nullptr; + return fml::Status(fml::StatusCode::kUnknown, ""); } if (!sub_command_buffer->EncodeAndSubmit(sub_renderpass)) { - return nullptr; + return fml::Status(fml::StatusCode::kUnknown, ""); } - return subpass_texture; + return subpass_target; } #if IMPELLER_ENABLE_3D diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 12d6120608d04..658d231ea5fc8 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -12,6 +12,7 @@ #include "flutter/fml/build_config.h" #include "flutter/fml/logging.h" +#include "flutter/fml/status_or.h" #include "impeller/base/validation.h" #include "impeller/core/formats.h" #include "impeller/entity/entity.h" @@ -692,10 +693,11 @@ class ContentContext { /// @brief Creates a new texture of size `texture_size` and calls /// `subpass_callback` with a `RenderPass` for drawing to the texture. - std::shared_ptr MakeSubpass(const std::string& label, - ISize texture_size, - const SubpassCallback& subpass_callback, - bool msaa_enabled = true) const; + fml::StatusOr MakeSubpass( + const std::string& label, + ISize texture_size, + const SubpassCallback& subpass_callback, + bool msaa_enabled = true) const; std::shared_ptr GetLazyGlyphAtlas() const { return lazy_glyph_atlas_; diff --git a/impeller/entity/contents/contents.cc b/impeller/entity/contents/contents.cc index c87c690366cb9..ede2f7e15a1e3 100644 --- a/impeller/entity/contents/contents.cc +++ b/impeller/entity/contents/contents.cc @@ -79,7 +79,7 @@ std::optional Contents::RenderToSnapshot( } } - auto texture = renderer.MakeSubpass( + fml::StatusOr render_target = renderer.MakeSubpass( label, ISize::Ceil(coverage->GetSize()), [&contents = *this, &entity, &coverage](const ContentContext& renderer, RenderPass& pass) -> bool { @@ -92,12 +92,12 @@ std::optional Contents::RenderToSnapshot( }, msaa_enabled); - if (!texture) { + if (!render_target.ok()) { return std::nullopt; } auto snapshot = Snapshot{ - .texture = texture, + .texture = render_target.value().GetRenderTargetTexture(), .transform = Matrix::MakeTranslation(coverage->GetOrigin()), }; if (sampler_descriptor.has_value()) { diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index 866bd8041bbc4..cb56c3f1eafac 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -223,15 +223,15 @@ static std::optional AdvancedBlend( return true; }; - auto out_texture = renderer.MakeSubpass( + fml::StatusOr render_target = renderer.MakeSubpass( "Advanced Blend Filter", ISize(subpass_coverage.GetSize()), callback); - if (!out_texture) { + if (!render_target.ok()) { return std::nullopt; } return Entity::FromSnapshot( Snapshot{ - .texture = out_texture, + .texture = render_target.value().GetRenderTargetTexture(), .transform = Matrix::MakeTranslation(subpass_coverage.GetOrigin()), // Since we absorbed the transform of the inputs and used the // respective snapshot sampling modes when blending, pass on @@ -646,16 +646,16 @@ static std::optional PipelineBlend( return true; }; - auto out_texture = renderer.MakeSubpass( + fml::StatusOr render_target = renderer.MakeSubpass( "Pipeline Blend Filter", ISize(subpass_coverage.GetSize()), callback); - if (!out_texture) { + if (!render_target.ok()) { return std::nullopt; } return Entity::FromSnapshot( Snapshot{ - .texture = out_texture, + .texture = render_target.value().GetRenderTargetTexture(), .transform = Matrix::MakeTranslation(subpass_coverage.GetOrigin()), // Since we absorbed the transform of the inputs and used the // respective snapshot sampling modes when blending, pass on diff --git a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc index ff07b7a45c5eb..862b6512a9612 100644 --- a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc @@ -256,10 +256,10 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( Vector2 scaled_size = pass_texture_rect.GetSize() * scale; ISize floored_size = ISize(scaled_size.x, scaled_size.y); - auto out_texture = renderer.MakeSubpass("Directional Gaussian Blur Filter", - floored_size, subpass_callback); + fml::StatusOr render_target = renderer.MakeSubpass( + "Directional Gaussian Blur Filter", floored_size, subpass_callback); - if (!out_texture) { + if (!render_target.ok()) { return std::nullopt; } @@ -270,14 +270,13 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( sampler_desc.width_address_mode = SamplerAddressMode::kClampToEdge; return Entity::FromSnapshot( - Snapshot{ - .texture = out_texture, - .transform = - texture_rotate.Invert() * - Matrix::MakeTranslation(pass_texture_rect.GetOrigin()) * - Matrix::MakeScale((1 / scale) * (scaled_size / floored_size)), - .sampler_descriptor = sampler_desc, - .opacity = input_snapshot->opacity}, + Snapshot{.texture = render_target.value().GetRenderTargetTexture(), + .transform = texture_rotate.Invert() * + Matrix::MakeTranslation(pass_texture_rect.GetOrigin()) * + Matrix::MakeScale((1 / scale) * + (scaled_size / floored_size)), + .sampler_descriptor = sampler_desc, + .opacity = input_snapshot->opacity}, entity.GetBlendMode(), entity.GetClipDepth()); } diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index e2ac83eee4819..f36a71512050a 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -110,9 +110,10 @@ std::shared_ptr MakeDownsampleSubpass( return true; }; - std::shared_ptr out_texture = renderer.MakeSubpass( + fml::StatusOr render_target = renderer.MakeSubpass( "Gaussian Blur Filter", subpass_size, subpass_callback); - return out_texture; + return render_target.ok() ? render_target.value().GetRenderTargetTexture() + : nullptr; } std::shared_ptr MakeBlurSubpass( @@ -120,7 +121,8 @@ std::shared_ptr MakeBlurSubpass( std::shared_ptr input_texture, const SamplerDescriptor& sampler_descriptor, Entity::TileMode tile_mode, - const GaussianBlurFragmentShader::BlurInfo& blur_info) { + const GaussianBlurFragmentShader::BlurInfo& blur_info, + std::optional> destination_texture) { if (blur_info.blur_sigma < kEhCloseEnough) { return input_texture; } @@ -171,9 +173,16 @@ std::shared_ptr MakeBlurSubpass( return true; }; - std::shared_ptr out_texture = renderer.MakeSubpass( + // if (destination_texture.has_value()) { + // renderer.MakeSubpass("Gaussian Blur Filter", destination_texture.value(), + // subpass_callback); + // return destination_texture; + // } else { + fml::StatusOr render_target = renderer.MakeSubpass( "Gaussian Blur Filter", subpass_size, subpass_callback); - return out_texture; + return render_target.ok() ? render_target.value().GetRenderTargetTexture() + : nullptr; + // } } } // namespace @@ -300,25 +309,27 @@ std::optional GaussianBlurFilterContents::RenderFilter( Vector2 pass1_pixel_size = 1.0 / Vector2(pass1_out_texture->GetSize()); std::shared_ptr pass2_out_texture = - MakeBlurSubpass(renderer, pass1_out_texture, + MakeBlurSubpass(renderer, /*input_texture=*/pass1_out_texture, input_snapshot->sampler_descriptor, tile_mode_, GaussianBlurFragmentShader::BlurInfo{ .blur_uv_offset = Point(0.0, pass1_pixel_size.y), .blur_sigma = scaled_sigma.y * effective_scalar.y, .blur_radius = blur_radius.y * effective_scalar.y, .step_size = 1.0, - }); + }, + /*destination_texture=*/std::nullopt); // TODO(gaaclarke): Make this pass reuse the texture from pass1. std::shared_ptr pass3_out_texture = - MakeBlurSubpass(renderer, pass2_out_texture, + MakeBlurSubpass(renderer, /*input_texture=*/pass2_out_texture, input_snapshot->sampler_descriptor, tile_mode_, GaussianBlurFragmentShader::BlurInfo{ .blur_uv_offset = Point(pass1_pixel_size.x, 0.0), .blur_sigma = scaled_sigma.x * effective_scalar.x, .blur_radius = blur_radius.x * effective_scalar.x, .step_size = 1.0, - }); + }, + /*destination_texture=*/pass1_out_texture); SamplerDescriptor sampler_desc = MakeSamplerDescriptor( MinMagFilter::kLinear, SamplerAddressMode::kClampToEdge); diff --git a/impeller/entity/contents/filters/morphology_filter_contents.cc b/impeller/entity/contents/filters/morphology_filter_contents.cc index abba353fe218d..f94156e8c0dc6 100644 --- a/impeller/entity/contents/filters/morphology_filter_contents.cc +++ b/impeller/entity/contents/filters/morphology_filter_contents.cc @@ -137,9 +137,9 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( return pass.AddCommand(std::move(cmd)); }; - auto out_texture = renderer.MakeSubpass("Directional Morphology Filter", - ISize(coverage.GetSize()), callback); - if (!out_texture) { + fml::StatusOr render_target = renderer.MakeSubpass( + "Directional Morphology Filter", ISize(coverage.GetSize()), callback); + if (!render_target.ok()) { return std::nullopt; } @@ -148,7 +148,7 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( sampler_desc.mag_filter = MinMagFilter::kLinear; return Entity::FromSnapshot( - Snapshot{.texture = out_texture, + Snapshot{.texture = render_target.value().GetRenderTargetTexture(), .transform = Matrix::MakeTranslation(coverage.GetOrigin()), .sampler_descriptor = sampler_desc, .opacity = input_snapshot->opacity}, From af63c94c54d9411dd444162a92f738c342c1abf1 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 19 Dec 2023 11:12:19 -0800 Subject: [PATCH 2/8] moved the blur to the render target api --- .../filters/gaussian_blur_filter_contents.cc | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index f36a71512050a..48beb18ab5c2b 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -65,7 +65,7 @@ void SetTileMode(SamplerDescriptor* descriptor, /// Makes a subpass that will render the scaled down input and add the /// transparent gutter required for the blur halo. -std::shared_ptr MakeDownsampleSubpass( +fml::StatusOr MakeDownsampleSubpass( const ContentContext& renderer, std::shared_ptr input_texture, const SamplerDescriptor& sampler_descriptor, @@ -112,21 +112,22 @@ std::shared_ptr MakeDownsampleSubpass( }; fml::StatusOr render_target = renderer.MakeSubpass( "Gaussian Blur Filter", subpass_size, subpass_callback); - return render_target.ok() ? render_target.value().GetRenderTargetTexture() - : nullptr; + return render_target; } -std::shared_ptr MakeBlurSubpass( +fml::StatusOr MakeBlurSubpass( const ContentContext& renderer, - std::shared_ptr input_texture, + const RenderTarget& input_pass, const SamplerDescriptor& sampler_descriptor, Entity::TileMode tile_mode, const GaussianBlurFragmentShader::BlurInfo& blur_info, - std::optional> destination_texture) { + std::optional destination_target) { if (blur_info.blur_sigma < kEhCloseEnough) { - return input_texture; + return input_pass; } + std::shared_ptr input_texture = input_pass.GetRenderTargetTexture(); + // TODO(gaaclarke): This blurs the whole image, but because we know the clip // region we could focus on just blurring that. ISize subpass_size = input_texture->GetSize(); @@ -180,8 +181,7 @@ std::shared_ptr MakeBlurSubpass( // } else { fml::StatusOr render_target = renderer.MakeSubpass( "Gaussian Blur Filter", subpass_size, subpass_callback); - return render_target.ok() ? render_target.value().GetRenderTargetTexture() - : nullptr; + return render_target; // } } @@ -302,14 +302,19 @@ std::optional GaussianBlurFilterContents::RenderFilter( Quad uvs = CalculateUVs(inputs[0], entity, source_rect_padded, input_snapshot->texture->GetSize()); - std::shared_ptr pass1_out_texture = MakeDownsampleSubpass( + fml::StatusOr pass1_out = MakeDownsampleSubpass( renderer, input_snapshot->texture, input_snapshot->sampler_descriptor, uvs, subpass_size, tile_mode_); - Vector2 pass1_pixel_size = 1.0 / Vector2(pass1_out_texture->GetSize()); + if (!pass1_out.ok()) { + return std::nullopt; + } + + Vector2 pass1_pixel_size = + 1.0 / Vector2(pass1_out.value().GetRenderTargetTexture()->GetSize()); - std::shared_ptr pass2_out_texture = - MakeBlurSubpass(renderer, /*input_texture=*/pass1_out_texture, + fml::StatusOr pass2_out = + MakeBlurSubpass(renderer, /*input_pass=*/pass1_out.value(), input_snapshot->sampler_descriptor, tile_mode_, GaussianBlurFragmentShader::BlurInfo{ .blur_uv_offset = Point(0.0, pass1_pixel_size.y), @@ -319,9 +324,13 @@ std::optional GaussianBlurFilterContents::RenderFilter( }, /*destination_texture=*/std::nullopt); + if (!pass2_out.ok()) { + return std::nullopt; + } + // TODO(gaaclarke): Make this pass reuse the texture from pass1. - std::shared_ptr pass3_out_texture = - MakeBlurSubpass(renderer, /*input_texture=*/pass2_out_texture, + fml::StatusOr pass3_out = + MakeBlurSubpass(renderer, /*input_pass=*/pass2_out.value(), input_snapshot->sampler_descriptor, tile_mode_, GaussianBlurFragmentShader::BlurInfo{ .blur_uv_offset = Point(pass1_pixel_size.x, 0.0), @@ -329,13 +338,17 @@ std::optional GaussianBlurFilterContents::RenderFilter( .blur_radius = blur_radius.x * effective_scalar.x, .step_size = 1.0, }, - /*destination_texture=*/pass1_out_texture); + /*destination_texture=*/pass1_out.value()); + + if (!pass3_out.ok()) { + return std::nullopt; + } SamplerDescriptor sampler_desc = MakeSamplerDescriptor( MinMagFilter::kLinear, SamplerAddressMode::kClampToEdge); return Entity::FromSnapshot( - Snapshot{.texture = pass3_out_texture, + Snapshot{.texture = pass3_out.value().GetRenderTargetTexture(), .transform = input_snapshot->transform * padding_snapshot_adjustment * Matrix::MakeScale(1 / effective_scalar), From 6e33b34cef02b3bc16f5cdf7b4a70471cbb833dd Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 19 Dec 2023 11:17:18 -0800 Subject: [PATCH 3/8] cleanup --- .../contents/filters/gaussian_blur_filter_contents.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 48beb18ab5c2b..e74623f5216be 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -328,6 +328,13 @@ std::optional GaussianBlurFilterContents::RenderFilter( return std::nullopt; } + // Only ping pong if the first pass actually created a render target. + auto pass3_destination = + pass2_out.value().GetRenderTargetTexture() != + pass1_out.value().GetRenderTargetTexture() + ? std::optional(pass1_out.value()) + : std::optional(std::nullopt); + // TODO(gaaclarke): Make this pass reuse the texture from pass1. fml::StatusOr pass3_out = MakeBlurSubpass(renderer, /*input_pass=*/pass2_out.value(), @@ -338,7 +345,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( .blur_radius = blur_radius.x * effective_scalar.x, .step_size = 1.0, }, - /*destination_texture=*/pass1_out.value()); + pass3_destination); if (!pass3_out.ok()) { return std::nullopt; From cd2a9da95fb12d10f7cec2586507c332be99b9b9 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 19 Dec 2023 11:26:53 -0800 Subject: [PATCH 4/8] started ping ponging --- impeller/entity/contents/content_context.cc | 12 +++++++-- impeller/entity/contents/content_context.h | 6 +++++ .../filters/gaussian_blur_filter_contents.cc | 25 ++++++++----------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 2499a279149be..62135f08fbce6 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -410,8 +410,7 @@ fml::StatusOr ContentContext::MakeSubpass( ISize texture_size, const SubpassCallback& subpass_callback, bool msaa_enabled) const { - auto context = GetContext(); - + std::shared_ptr context = GetContext(); RenderTarget subpass_target; if (context->GetCapabilities()->SupportsOffscreenMSAA() && msaa_enabled) { subpass_target = RenderTarget::CreateOffscreenMSAA( @@ -428,6 +427,15 @@ fml::StatusOr ContentContext::MakeSubpass( std::nullopt // stencil_attachment_config ); } + return MakeSubpass(label, subpass_target, subpass_callback); +} + +fml::StatusOr ContentContext::MakeSubpass( + const std::string& label, + const RenderTarget subpass_target, + const SubpassCallback& subpass_callback) const { + std::shared_ptr context = GetContext(); + auto subpass_texture = subpass_target.GetRenderTargetTexture(); if (!subpass_texture) { return fml::Status(fml::StatusCode::kUnknown, ""); diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 658d231ea5fc8..7b7d696dca357 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -699,6 +699,12 @@ class ContentContext { const SubpassCallback& subpass_callback, bool msaa_enabled = true) const; + /// Makes a subpass that will render to `subpass_target`. + fml::StatusOr MakeSubpass( + const std::string& label, + const RenderTarget subpass_target, + const SubpassCallback& subpass_callback) const; + std::shared_ptr GetLazyGlyphAtlas() const { return lazy_glyph_atlas_; } diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index e74623f5216be..81337bf1fad03 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -174,15 +174,13 @@ fml::StatusOr MakeBlurSubpass( return true; }; - // if (destination_texture.has_value()) { - // renderer.MakeSubpass("Gaussian Blur Filter", destination_texture.value(), - // subpass_callback); - // return destination_texture; - // } else { - fml::StatusOr render_target = renderer.MakeSubpass( - "Gaussian Blur Filter", subpass_size, subpass_callback); - return render_target; - // } + if (destination_target.has_value()) { + return renderer.MakeSubpass("Gaussian Blur Filter", + destination_target.value(), subpass_callback); + } else { + return renderer.MakeSubpass("Gaussian Blur Filter", subpass_size, + subpass_callback); + } } } // namespace @@ -329,11 +327,10 @@ std::optional GaussianBlurFilterContents::RenderFilter( } // Only ping pong if the first pass actually created a render target. - auto pass3_destination = - pass2_out.value().GetRenderTargetTexture() != - pass1_out.value().GetRenderTargetTexture() - ? std::optional(pass1_out.value()) - : std::optional(std::nullopt); + auto pass3_destination = pass2_out.value().GetRenderTargetTexture() != + pass1_out.value().GetRenderTargetTexture() + ? std::optional(pass1_out.value()) + : std::optional(std::nullopt); // TODO(gaaclarke): Make this pass reuse the texture from pass1. fml::StatusOr pass3_out = From bb3a51af2e620a39446dcb6ff33f38bbd1f13640 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 19 Dec 2023 13:21:15 -0800 Subject: [PATCH 5/8] removed todo --- .../entity/contents/filters/gaussian_blur_filter_contents.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 81337bf1fad03..9216daf221101 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -332,7 +332,6 @@ std::optional GaussianBlurFilterContents::RenderFilter( ? std::optional(pass1_out.value()) : std::optional(std::nullopt); - // TODO(gaaclarke): Make this pass reuse the texture from pass1. fml::StatusOr pass3_out = MakeBlurSubpass(renderer, /*input_pass=*/pass2_out.value(), input_snapshot->sampler_descriptor, tile_mode_, From 66f6766ad28b961f292b223834eb40ca6575757f Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 20 Dec 2023 11:56:41 -0800 Subject: [PATCH 6/8] format --- .../directional_gaussian_blur_filter_contents.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc index 862b6512a9612..f411358b06ca2 100644 --- a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc @@ -270,13 +270,14 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( sampler_desc.width_address_mode = SamplerAddressMode::kClampToEdge; return Entity::FromSnapshot( - Snapshot{.texture = render_target.value().GetRenderTargetTexture(), - .transform = texture_rotate.Invert() * - Matrix::MakeTranslation(pass_texture_rect.GetOrigin()) * - Matrix::MakeScale((1 / scale) * - (scaled_size / floored_size)), - .sampler_descriptor = sampler_desc, - .opacity = input_snapshot->opacity}, + Snapshot{ + .texture = render_target.value().GetRenderTargetTexture(), + .transform = + texture_rotate.Invert() * + Matrix::MakeTranslation(pass_texture_rect.GetOrigin()) * + Matrix::MakeScale((1 / scale) * (scaled_size / floored_size)), + .sampler_descriptor = sampler_desc, + .opacity = input_snapshot->opacity}, entity.GetBlendMode(), entity.GetClipDepth()); } From 750fc8a3d6e4b91188a9cdefacdc1c756d7c92e4 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 2 Jan 2024 10:16:22 -0800 Subject: [PATCH 7/8] brandon feedback + lint --- impeller/entity/contents/content_context.cc | 2 +- impeller/entity/contents/content_context.h | 2 +- .../contents/filters/gaussian_blur_filter_contents.cc | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 62135f08fbce6..886bc54e95225 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -432,7 +432,7 @@ fml::StatusOr ContentContext::MakeSubpass( fml::StatusOr ContentContext::MakeSubpass( const std::string& label, - const RenderTarget subpass_target, + const RenderTarget& subpass_target, const SubpassCallback& subpass_callback) const { std::shared_ptr context = GetContext(); diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 7b7d696dca357..98dc447f009fb 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -702,7 +702,7 @@ class ContentContext { /// Makes a subpass that will render to `subpass_target`. fml::StatusOr MakeSubpass( const std::string& label, - const RenderTarget subpass_target, + const RenderTarget& subpass_target, const SubpassCallback& subpass_callback) const; std::shared_ptr GetLazyGlyphAtlas() const { diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index 9216daf221101..453c37dd4b28b 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -320,7 +320,7 @@ std::optional GaussianBlurFilterContents::RenderFilter( .blur_radius = blur_radius.y * effective_scalar.y, .step_size = 1.0, }, - /*destination_texture=*/std::nullopt); + /*destination_target=*/std::nullopt); if (!pass2_out.ok()) { return std::nullopt; @@ -347,6 +347,13 @@ std::optional GaussianBlurFilterContents::RenderFilter( return std::nullopt; } + // The ping-pong approach requires that each render pass output has the same + // size. + FML_DCHECK((pass1_out.value().GetRenderTargetSize() == + pass2_out.value().GetRenderTargetSize()) && + (pass2_out.value().GetRenderTargetSize() == + pass3_out.value().GetRenderTargetSize())); + SamplerDescriptor sampler_desc = MakeSamplerDescriptor( MinMagFilter::kLinear, SamplerAddressMode::kClampToEdge); From fc3441fab39da573bf332a739cbf74d0950eefc8 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Tue, 2 Jan 2024 10:34:24 -0800 Subject: [PATCH 8/8] format --- .../filters/directional_gaussian_blur_filter_contents.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc index f411358b06ca2..5760d7ac250d2 100644 --- a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc @@ -37,8 +37,8 @@ Sigma ScaleSigma(Sigma sigma) { DirectionalGaussianBlurFilterContents::DirectionalGaussianBlurFilterContents() = default; -DirectionalGaussianBlurFilterContents::~ -DirectionalGaussianBlurFilterContents() = default; +DirectionalGaussianBlurFilterContents:: + ~DirectionalGaussianBlurFilterContents() = default; void DirectionalGaussianBlurFilterContents::SetSigma(Sigma sigma) { blur_sigma_ = sigma;