[Impeller] Lock access to descriptor pool map. (flutter/engine#56113)

Speculative fix for https://github.com/flutter/flutter/issues/157565
which looks like the kind of error that might happen if we concurrently
mutate this hashmap.
This commit is contained in:
Jonah Williams 2024-10-25 13:30:17 -07:00 committed by GitHub
parent c025861523
commit 368ca941eb
2 changed files with 18 additions and 10 deletions

View File

@ -503,15 +503,18 @@ std::shared_ptr<CommandBuffer> ContextVK::CreateCommandBuffer() const {
// look up a cached descriptor pool for the current frame and reuse it
// if it exists, otherwise create a new pool.
DescriptorPoolMap::iterator current_pool =
cached_descriptor_pool_.find(std::this_thread::get_id());
std::shared_ptr<DescriptorPoolVK> descriptor_pool;
if (current_pool == cached_descriptor_pool_.end()) {
descriptor_pool =
(cached_descriptor_pool_[std::this_thread::get_id()] =
std::make_shared<DescriptorPoolVK>(weak_from_this()));
} else {
descriptor_pool = current_pool->second;
{
Lock lock(desc_pool_mutex_);
DescriptorPoolMap::iterator current_pool =
cached_descriptor_pool_.find(std::this_thread::get_id());
if (current_pool == cached_descriptor_pool_.end()) {
descriptor_pool =
(cached_descriptor_pool_[std::this_thread::get_id()] =
std::make_shared<DescriptorPoolVK>(weak_from_this()));
} else {
descriptor_pool = current_pool->second;
}
}
auto tracked_objects = std::make_shared<TrackedObjectsVK>(
@ -668,7 +671,10 @@ void ContextVK::InitializeCommonlyUsedShadersIfNeeded() const {
}
void ContextVK::DisposeThreadLocalCachedResources() {
cached_descriptor_pool_.erase(std::this_thread::get_id());
{
Lock lock(desc_pool_mutex_);
cached_descriptor_pool_.erase(std::this_thread::get_id());
}
command_pool_recycler_->Dispose();
}

View File

@ -234,7 +234,9 @@ class ContextVK final : public Context,
using DescriptorPoolMap =
std::unordered_map<std::thread::id, std::shared_ptr<DescriptorPoolVK>>;
mutable DescriptorPoolMap cached_descriptor_pool_;
mutable Mutex desc_pool_mutex_;
mutable DescriptorPoolMap IPLR_GUARDED_BY(desc_pool_mutex_)
cached_descriptor_pool_;
bool should_disable_surface_control_ = false;
bool should_batch_cmd_buffers_ = false;
std::vector<std::shared_ptr<CommandBuffer>> pending_command_buffers_;