Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,14 @@ void ContextVK::DisposeThreadLocalCachedResources() {
command_pool_recycler_->Dispose();
}

void ContextVK::MarkFrameEnd() {
if (auto pipeline_library = GetPipelineLibrary()) {
PipelineLibraryVK::Cast(*pipeline_library).DidAcquireSurfaceFrame();
}
DisposeThreadLocalCachedResources();
GetResourceAllocator()->DebugTraceMemoryStatistics();
}

const std::shared_ptr<YUVConversionLibraryVK>&
ContextVK::GetYUVConversionLibrary() const {
return yuv_conversion_library_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ class ContextVK final : public Context,
// |Context|
void DisposeThreadLocalCachedResources() override;

/// @brief Perform frame-end maintenance: persist the pipeline cache to
/// disk periodically and dispose thread-local cached resources.
/// Called by SurfaceContextVK::MarkFrameEnd and directly by
/// embedder paths that bypass AcquireNextSurface.
void MarkFrameEnd();

/// @brief Whether the Android Surface control based swapchain should be
/// enabled
bool GetShouldEnableSurfaceControlSwapchain() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ std::unique_ptr<Surface> SurfaceContextVK::AcquireNextSurface() {
}

void SurfaceContextVK::MarkFrameEnd() {
if (auto pipeline_library = parent_->GetPipelineLibrary()) {
impeller::PipelineLibraryVK::Cast(*pipeline_library)
.DidAcquireSurfaceFrame();
}
parent_->DisposeThreadLocalCachedResources();
parent_->GetResourceAllocator()->DebugTraceMemoryStatistics();
parent_->MarkFrameEnd();
}

void SurfaceContextVK::UpdateSurfaceSize(const ISize& size) const {
Expand Down
6 changes: 5 additions & 1 deletion engine/src/flutter/shell/gpu/gpu_surface_vulkan_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceVulkanImpeller::AcquireFrame(
impeller::ContextVK& context_vk =
impeller::ContextVK::Cast(*impeller_context_);

context_vk.DisposeThreadLocalCachedResources();
// The embedder path does not go through
// SurfaceContextVK::AcquireNextSurface (which calls MarkFrameEnd).
// Call MarkFrameEnd directly to ensure the Vulkan pipeline cache is
// periodically persisted to disk and thread-local resources are cleaned up.
context_vk.MarkFrameEnd();

impeller::vk::Image vk_image =
impeller::vk::Image(reinterpret_cast<VkImage>(flutter_image.image));
Expand Down
2 changes: 1 addition & 1 deletion engine/src/flutter/shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ InferVulkanPlatformViewCreationCallback(
static_cast<VkDevice>(config->vulkan.device),
config->vulkan.queue_family_index,
static_cast<VkQueue>(config->vulkan.queue), vulkan_dispatch_table,
view_embedder);
view_embedder,config->vulkan.cache_path);
Comment thread
xiaowei-guan marked this conversation as resolved.

return fml::MakeCopyable(
[embedder_surface = std::move(embedder_surface),
Expand Down
5 changes: 5 additions & 0 deletions engine/src/flutter/shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,11 @@ typedef struct {
/// that external texture details can be supplied to the engine for subsequent
/// composition.
FlutterVulkanTextureFrameCallback external_texture_frame_callback;
/// The path to the Vulkan pipeline cache data.
/// The string can be collected after the call to `FlutterEngineRun` returns.
/// The string must be NULL terminated.
/// If NULL, Impeller will not use the Vulkan pipeline cache.
const char* cache_path;
} FlutterVulkanRendererConfig;

typedef struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ EmbedderSurfaceVulkanImpeller::EmbedderSurfaceVulkanImpeller(
uint32_t queue_family_index,
VkQueue queue,
const VulkanDispatchTable& vulkan_dispatch_table,
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder,
const char* cache_path)
: vk_(fml::MakeRefCounted<vulkan::VulkanProcTable>(
vulkan_dispatch_table.get_instance_proc_address)),
vulkan_dispatch_table_(vulkan_dispatch_table),
Expand All @@ -54,6 +55,10 @@ EmbedderSurfaceVulkanImpeller::EmbedderSurfaceVulkanImpeller(
settings.shader_libraries_data = shader_mappings;
settings.proc_address_callback =
vulkan_dispatch_table.get_instance_proc_address;
if (cache_path != nullptr) {
settings.cache_directory =
OpenDirectory(cache_path, false, fml::FilePermission::kReadWrite);
}

impeller::ContextVK::EmbedderData data;
data.instance = instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class EmbedderSurfaceVulkanImpeller final : public EmbedderSurface,
uint32_t queue_family_index,
VkQueue queue,
const VulkanDispatchTable& vulkan_dispatch_table,
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder);
std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder,
const char* cache_path);

~EmbedderSurfaceVulkanImpeller() override;

Expand Down
Loading