From c095d66749b561371f8fba843bbe3a27f4627189 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 8 Feb 2024 16:06:13 -0800 Subject: [PATCH] Sever the //flutter/vulkan dependency in Flutter in the Android embedder. (flutter/engine#50472) The previous code was setting up a proc table, then getting the address of the proc that was used to the setup that table, then setting up another proc table. Directly setup the final proc table and don't depend on //impeller/vulkan. Part of https://github.com/flutter/flutter/issues/143127 Similar to https://github.com/flutter/engine/pull/50454 --- .../android_context_vulkan_impeller.cc | 28 +++++++++++++------ .../android/android_context_vulkan_impeller.h | 4 +-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc b/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc index e5ba19802e..d9d23ebe31 100644 --- a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc +++ b/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.cc @@ -17,9 +17,14 @@ namespace flutter { static std::shared_ptr CreateImpellerContext( - const fml::RefPtr& proc_table, + const fml::RefPtr& vulkan_dylib, bool enable_vulkan_validation, bool enable_gpu_tracing) { + if (!vulkan_dylib) { + VALIDATION_LOG << "Could not open the Vulkan dylib."; + return nullptr; + } + std::vector> shader_mappings = { std::make_shared(impeller_entity_shaders_vk_data, impeller_entity_shaders_vk_length), @@ -34,11 +39,17 @@ static std::shared_ptr CreateImpellerContext( impeller_modern_shaders_vk_length), }; - PFN_vkGetInstanceProcAddr instance_proc_addr = - proc_table->NativeGetInstanceProcAddr(); + auto instance_proc_addr = + vulkan_dylib->ResolveFunction( + "vkGetInstanceProcAddr"); + + if (!instance_proc_addr.has_value()) { + VALIDATION_LOG << "Could not setup Vulkan proc table."; + return nullptr; + } impeller::ContextVK::Settings settings; - settings.proc_address_callback = instance_proc_addr; + settings.proc_address_callback = instance_proc_addr.value(); settings.shader_libraries_data = std::move(shader_mappings); settings.cache_directory = fml::paths::GetCachesDirectory(); settings.enable_validation = enable_vulkan_validation; @@ -61,12 +72,11 @@ AndroidContextVulkanImpeller::AndroidContextVulkanImpeller( bool enable_validation, bool enable_gpu_tracing) : AndroidContext(AndroidRenderingAPI::kVulkan), - proc_table_(fml::MakeRefCounted()) { - auto impeller_context = - CreateImpellerContext(proc_table_, enable_validation, enable_gpu_tracing); + vulkan_dylib_(fml::NativeLibrary::Create("libvulkan.so")) { + auto impeller_context = CreateImpellerContext( + vulkan_dylib_, enable_validation, enable_gpu_tracing); SetImpellerContext(impeller_context); - is_valid_ = - proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context; + is_valid_ = !!impeller_context; } AndroidContextVulkanImpeller::~AndroidContextVulkanImpeller() = default; diff --git a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h b/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h index 8bbf18ef04..266843d534 100644 --- a/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h +++ b/engine/src/flutter/shell/platform/android/android_context_vulkan_impeller.h @@ -7,8 +7,8 @@ #include "flutter/fml/concurrent_message_loop.h" #include "flutter/fml/macros.h" +#include "flutter/fml/native_library.h" #include "flutter/shell/platform/android/context/android_context.h" -#include "flutter/vulkan/procs/vulkan_proc_table.h" namespace flutter { @@ -22,7 +22,7 @@ class AndroidContextVulkanImpeller : public AndroidContext { bool IsValid() const override; private: - fml::RefPtr proc_table_; + fml::RefPtr vulkan_dylib_; bool is_valid_ = false; FML_DISALLOW_COPY_AND_ASSIGN(AndroidContextVulkanImpeller);