From 6a55bd5bf4dba571e24c6e61dcb520a3619aeb5d Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 6 Aug 2024 13:19:10 -0700 Subject: [PATCH 1/2] [Impeller] Reorder pipeline construction in content context. Fixes the regression to the first-frame time on the Mokey. Also add a trace that should allow for easier identification of problematic pipelines. A more involved job-queue that allows construction jobs to skip the queue was written in https://github.com/flutter/engine/pull/54355. But the Mokey case is not important enough for the additional complexity. See the context in the linked patch. --- impeller/entity/contents/content_context.cc | 36 ++++++++++--------- .../renderer/backend/vulkan/pipeline_vk.cc | 3 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index d1975f9f3f90a..9f5e55043621f 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -334,6 +334,24 @@ ContentContext::ContentContext( std::make_unique(*context_, clip_pipeline_descriptor)); } + glyph_atlas_pipelines_.CreateDefault( + *context_, options, + {static_cast( + GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() == + PixelFormat::kA8UNormInt)}); + texture_downsample_pipelines_.CreateDefault(*context_, options_trianglestrip); + rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); + texture_strict_src_pipelines_.CreateDefault(*context_, options); + tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal}); + gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip, + {supports_decal}); + border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); + color_matrix_color_filter_pipelines_.CreateDefault(*context_, + options_trianglestrip); + porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip, + {supports_decal}); + vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal}); + if (context_->GetCapabilities()->SupportsFramebufferFetch()) { framebuffer_blend_color_pipelines_.CreateDefault( *context_, options_trianglestrip, @@ -428,30 +446,14 @@ ContentContext::ContentContext( {static_cast(BlendSelectValues::kSoftLight), supports_decal}); } - texture_downsample_pipelines_.CreateDefault(*context_, options_trianglestrip); - rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); - texture_strict_src_pipelines_.CreateDefault(*context_, options); - tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal}); - gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip, - {supports_decal}); - border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip, {supports_decal}); - color_matrix_color_filter_pipelines_.CreateDefault(*context_, - options_trianglestrip); linear_to_srgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); srgb_to_linear_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); - glyph_atlas_pipelines_.CreateDefault( - *context_, options, - {static_cast( - GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() == - PixelFormat::kA8UNormInt)}); yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); - porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip, - {supports_decal}); - vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal}); + // GLES only shader that is unsupported on macOS. #if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_MACOSX) if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) { diff --git a/impeller/renderer/backend/vulkan/pipeline_vk.cc b/impeller/renderer/backend/vulkan/pipeline_vk.cc index 793a158a32e80..727a60b095839 100644 --- a/impeller/renderer/backend/vulkan/pipeline_vk.cc +++ b/impeller/renderer/backend/vulkan/pipeline_vk.cc @@ -451,7 +451,8 @@ std::unique_ptr PipelineVK::Create( const std::shared_ptr& device_holder, const std::weak_ptr& weak_library, std::shared_ptr immutable_sampler) { - TRACE_EVENT0("flutter", "PipelineVK::Create"); + TRACE_EVENT1("flutter", "PipelineVK::Create", "Name", + desc.GetLabel().c_str()); auto library = weak_library.lock(); From 5652503045e82eaefa6d112313feca95ed2ddc02 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 6 Aug 2024 14:01:56 -0700 Subject: [PATCH 2/2] PR --- impeller/entity/contents/content_context.cc | 41 +++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 9f5e55043621f..8237013cbafb3 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -292,7 +292,15 @@ ContentContext::ContentContext( const auto supports_decal = static_cast( context_->GetCapabilities()->SupportsDecalSamplerAddressMode()); + // Futures for the following pipelines may block in case the first frame is + // rendered without the pipelines being ready. Put pipelines that are more + // likely to be used first. { + glyph_atlas_pipelines_.CreateDefault( + *context_, options, + {static_cast( + GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() == + PixelFormat::kA8UNormInt)}); solid_fill_pipelines_.CreateDefault(*context_, options); texture_pipelines_.CreateDefault(*context_, options); fast_gradient_pipelines_.CreateDefault(*context_, options); @@ -310,7 +318,6 @@ ContentContext::ContentContext( } /// Setup default clip pipeline. - auto clip_pipeline_descriptor = ClipPipeline::Builder::MakeDefaultPipelineDescriptor(*context_); if (!clip_pipeline_descriptor.has_value()) { @@ -332,26 +339,22 @@ ContentContext::ContentContext( clip_pipelines_.SetDefault( options, std::make_unique(*context_, clip_pipeline_descriptor)); + texture_downsample_pipelines_.CreateDefault(*context_, + options_trianglestrip); + rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); + texture_strict_src_pipelines_.CreateDefault(*context_, options); + tiled_texture_pipelines_.CreateDefault(*context_, options, + {supports_decal}); + gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip, + {supports_decal}); + border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); + color_matrix_color_filter_pipelines_.CreateDefault(*context_, + options_trianglestrip); + porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip, + {supports_decal}); + vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal}); } - glyph_atlas_pipelines_.CreateDefault( - *context_, options, - {static_cast( - GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() == - PixelFormat::kA8UNormInt)}); - texture_downsample_pipelines_.CreateDefault(*context_, options_trianglestrip); - rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); - texture_strict_src_pipelines_.CreateDefault(*context_, options); - tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal}); - gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip, - {supports_decal}); - border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); - color_matrix_color_filter_pipelines_.CreateDefault(*context_, - options_trianglestrip); - porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip, - {supports_decal}); - vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal}); - if (context_->GetCapabilities()->SupportsFramebufferFetch()) { framebuffer_blend_color_pipelines_.CreateDefault( *context_, options_trianglestrip,