[Impeller] started cleaning up pools when devices are deleted (flutter/engine#41857)

fixes https://github.com/flutter/flutter/issues/125571

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke
2023-05-09 15:44:07 -07:00
committed by GitHub
parent 847ac3dcef
commit 16d9aa190a
5 changed files with 37 additions and 7 deletions

View File

@@ -145,6 +145,7 @@
../../../flutter/impeller/image/README.md
../../../flutter/impeller/playground
../../../flutter/impeller/renderer/backend/vulkan/blit_command_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/context_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/test
../../../flutter/impeller/renderer/capabilities_unittests.cc
../../../flutter/impeller/renderer/compute_subgroup_unittests.cc

View File

@@ -8,6 +8,7 @@ impeller_component("vulkan_unittests") {
testonly = true
sources = [
"blit_command_vk_unittests.cc",
"context_vk_unittests.cc",
"test/mock_vulkan.cc",
"test/mock_vulkan.h",
]

View File

@@ -35,8 +35,6 @@ class TrackedObjectsVK {
}
auto pool = pool_.lock();
if (!pool) {
VALIDATION_LOG
<< "Command pool died before a command buffer could be recycled.";
// The buffer can not be freed if its command pool has been destroyed.
buffer_.release();
return;
@@ -159,7 +157,8 @@ bool CommandEncoderVK::Submit() {
return fence_waiter_->AddFence(
std::move(fence), [tracked_objects = std::move(tracked_objects_)] {
// Nothing to do, we just drop the tracked objects on the floor.
// Nothing to do, we just drop the tracked
// objects on the floor.
});
}

View File

@@ -15,10 +15,6 @@
namespace impeller {
using CommandPoolMap = std::map<uint64_t, std::shared_ptr<CommandPoolVK>>;
// TODO(https://github.com/flutter/flutter/issues/125571): This is storing tons
// of CommandPoolVK's in the test runner since many contexts are created on the
// same thread. We need to come up with a different way to clean these up.
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<CommandPoolMap> tls_command_pool;
static Mutex g_all_pools_mutex;
@@ -52,6 +48,9 @@ std::shared_ptr<CommandPoolVK> CommandPoolVK::GetThreadLocal(
}
void CommandPoolVK::ClearAllPools(const ContextVK* context) {
if (tls_command_pool.get()) {
tls_command_pool.get()->erase(context->GetHash());
}
Lock pool_lock(g_all_pools_mutex);
if (auto found = g_all_pools.find(context); found != g_all_pools.end()) {
for (auto& weak_pool : found->second) {

View File

@@ -0,0 +1,30 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/testing/testing.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
namespace impeller {
namespace testing {
TEST(ContextVKTest, DeletesCommandPools) {
std::weak_ptr<ContextVK> weak_context;
std::weak_ptr<CommandPoolVK> weak_pool;
{
std::shared_ptr<ContextVK> context = CreateMockVulkanContext();
std::shared_ptr<CommandPoolVK> pool =
CommandPoolVK::GetThreadLocal(context.get());
weak_pool = pool;
weak_context = context;
ASSERT_TRUE(weak_pool.lock());
ASSERT_TRUE(weak_context.lock());
}
ASSERT_FALSE(weak_pool.lock());
ASSERT_FALSE(weak_context.lock());
}
} // namespace testing
} // namespace impeller