From 5a028e336d51a88a4ebbf1832755b579ce8ef3f1 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 6 May 2024 20:05:18 -0700 Subject: [PATCH] [Impeller] eagerly bootstrap content context. (flutter/engine#52590) ![image](https://github.com/flutter/engine/assets/8975114/5238d169-a68b-4905-848b-3ee7a7972de8) Work around for https://github.com/flutter/flutter/issues/143540 by running shader bootstrap as early as possible. I was looking at this code for unrelated reasons (include removal) and realized it would be a trivial change. If we're using the KHR swapchain instead of the AHB swapchain, in theory the pixel format could change but since we hash the pixel format the only bad thing would be the wasted work. --- .../android/android_surface_vulkan_impeller.cc | 10 ++++++++++ .../platform/android/android_surface_vulkan_impeller.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc b/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc index 61fc5bfec2..9395709043 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc +++ b/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.cc @@ -24,6 +24,8 @@ AndroidSurfaceVulkanImpeller::AndroidSurfaceVulkanImpeller( auto& context_vk = impeller::ContextVK::Cast(*android_context->GetImpellerContext()); surface_context_vk_ = context_vk.CreateSurfaceContext(); + eager_gpu_surface_ = + std::make_unique(surface_context_vk_); } AndroidSurfaceVulkanImpeller::~AndroidSurfaceVulkanImpeller() = default; @@ -46,6 +48,14 @@ std::unique_ptr AndroidSurfaceVulkanImpeller::CreateGPUSurface( return nullptr; } + if (eager_gpu_surface_) { + auto gpu_surface = std::move(eager_gpu_surface_); + if (!gpu_surface->IsValid()) { + return nullptr; + } + return gpu_surface; + } + std::unique_ptr gpu_surface = std::make_unique(surface_context_vk_); diff --git a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h b/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h index 7c5296c180..d348d51b47 100644 --- a/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h +++ b/engine/src/flutter/shell/platform/android/android_surface_vulkan_impeller.h @@ -11,6 +11,7 @@ #include "flutter/shell/platform/android/android_context_vulkan_impeller.h" #include "flutter/shell/platform/android/surface/android_native_window.h" #include "flutter/shell/platform/android/surface/android_surface.h" +#include "shell/gpu/gpu_surface_vulkan_impeller.h" namespace flutter { @@ -49,6 +50,11 @@ class AndroidSurfaceVulkanImpeller : public AndroidSurface { private: std::shared_ptr surface_context_vk_; fml::RefPtr native_window_; + // The first GPU Surface is initialized as soon as the + // AndroidSurfaceVulkanImpeller is created. This ensures that the pipelines + // are bootstrapped as early as possible. + std::unique_ptr eager_gpu_surface_; + bool is_valid_ = false; FML_DISALLOW_COPY_AND_ASSIGN(AndroidSurfaceVulkanImpeller);