Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ void ContextVK::InitializeCommonlyUsedShadersIfNeeded() const {
auto pass = builder.Build(GetDevice());
}

void ContextVK::DisposeThreadLocalCachedResources() {
command_pool_recycler_->Dispose();
}

const std::shared_ptr<YUVConversionLibraryVK>&
ContextVK::GetYUVConversionLibrary() const {
return yuv_conversion_library_;
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ class ContextVK final : public Context,

void RecordFrameEndTime() const;

// |Context|
void InitializeCommonlyUsedShadersIfNeeded() const override;

// |Context|
void DisposeThreadLocalCachedResources() override;

/// @brief Whether the Android Surface control based swapchain should be
/// disabled, even if the device is capable of supporting it.
bool GetShouldDisableSurfaceControlSwapchain() const;
Expand Down
19 changes: 19 additions & 0 deletions impeller/renderer/backend/vulkan/context_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ TEST(ContextVKTest, DeletesCommandPoolsOnAllThreads) {
ASSERT_FALSE(weak_pool_thread.lock());
}

TEST(ContextVKTest, ThreadLocalCleanupDeletesCommandPool) {
std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();

fml::AutoResetWaitableEvent latch1, latch2;
std::weak_ptr<CommandPoolVK> weak_pool;
std::thread thread([&]() {
weak_pool = context->GetCommandPoolRecycler()->Get();
context->DisposeThreadLocalCachedResources();
latch1.Signal();
latch2.Wait();
});

latch1.Wait();
ASSERT_FALSE(weak_pool.lock());

latch2.Signal();
thread.join();
}

TEST(ContextVKTest, DeletePipelineAfterContext) {
std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
std::shared_ptr<std::vector<std::string>> functions;
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/surface_context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void SurfaceContextVK::InitializeCommonlyUsedShadersIfNeeded() const {
parent_->InitializeCommonlyUsedShadersIfNeeded();
}

void SurfaceContextVK::DisposeThreadLocalCachedResources() {
parent_->DisposeThreadLocalCachedResources();
}

const std::shared_ptr<ContextVK>& SurfaceContextVK::GetParent() const {
return parent_;
}
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/surface_context_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ class SurfaceContextVK : public Context,
/// recreated on the next frame.
void UpdateSurfaceSize(const ISize& size) const;

// |Context|
void InitializeCommonlyUsedShadersIfNeeded() const override;

// |Context|
void DisposeThreadLocalCachedResources() override;

const vk::Device& GetDevice() const;

const std::shared_ptr<ContextVK>& GetParent() const;
Expand Down
7 changes: 7 additions & 0 deletions impeller/renderer/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ class Context {
/// shader variants, as well as forcing driver initialization.
virtual void InitializeCommonlyUsedShadersIfNeeded() const {}

/// Dispose resources that are cached on behalf of the current thread.
///
/// Some backends such as Vulkan may cache resources that can be reused while
/// executing a rendering operation. This API can be called after the
/// operation completes in order to clear the cache.
virtual void DisposeThreadLocalCachedResources() {}

protected:
Context();

Expand Down
2 changes: 2 additions & 0 deletions lib/ui/painting/image_decoder_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ ImageDecoderImpeller::UnsafeUploadTextureToPrivate(
return std::make_pair(nullptr, decode_error);
}

context->DisposeThreadLocalCachedResources();

return std::make_pair(
impeller::DlImageImpeller::Make(std::move(result_texture)),
std::string());
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/painting/image_encoding_impeller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ void ImageEncodingImpeller::ConvertDlImageToSkImage(
.ok()) {
FML_LOG(ERROR) << "Failed to submit commands.";
}

impeller_context->DisposeThreadLocalCachedResources();
}

void ImageEncodingImpeller::ConvertImageToRaster(
Expand Down