-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] started cleaning up pools when devices are deleted #41857
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to the end of the function so it runs after the block that calls In theory this should be unnecessary because nobody else should be holding on to a strong reference to this thread's
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I just realized this is unnecessary. If this thread's So the current implementation in the PR will work as intended. |
||
| } | ||
| 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) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this capturing a strong reference to the
ContextVKin the lambda?TrackedObjectsVKholds a weak reference to theCommandPoolVK. That should allow cleanup of the tracked objects if theCommandPoolVKand theContextVK/vk::Deviceare still alive (and do nothing if they are already gone)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because that
buffer.release()call that you just added wasn't in the TrackedObjects destructor. This may no longer be necessary after your change. Let me test it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, is still necessary. It crashes without it because
VALIDATION_LOGhas an abort in it. I'll remove it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our options are to keep a strong hold on the device in the fence, or to release the buffer without crashing. I believe you prefer removing the strong link and calling
release(). I think I do too so I did that, although I'm unhappy about the C++ vulkan wrapper and how it looks like a leak.