[Impeller] Discard invalid command buffer handles after destroying a command pool (flutter/engine#44194)

Fixes https://github.com/flutter/flutter/issues/131522
This commit is contained in:
Jason Simmons
2023-08-03 15:15:29 -07:00
committed by GitHub
parent 261c9b02aa
commit e9aebf1952
2 changed files with 10 additions and 3 deletions

View File

@@ -92,8 +92,15 @@ bool CommandPoolVK::IsValid() const {
void CommandPoolVK::Reset() {
Lock lock(buffers_to_collect_mutex_);
GarbageCollectBuffersIfAble();
graphics_pool_.reset();
// When the command pool is destroyed, all of its command buffers are freed.
// Handles allocated from that pool are now invalid and must be discarded.
for (vk::UniqueCommandBuffer& buffer : buffers_to_collect_) {
buffer.release();
}
buffers_to_collect_.clear();
is_valid_ = false;
}
@@ -133,7 +140,7 @@ void CommandPoolVK::CollectGraphicsCommandBuffer(
// have been freed and are now invalid.
buffer.release();
}
buffers_to_collect_.insert(MakeSharedVK(std::move(buffer)));
buffers_to_collect_.emplace_back(std::move(buffer));
GarbageCollectBuffersIfAble();
}

View File

@@ -42,7 +42,7 @@ class CommandPoolVK {
std::weak_ptr<const DeviceHolder> device_holder_;
vk::UniqueCommandPool graphics_pool_;
Mutex buffers_to_collect_mutex_;
std::set<SharedHandleVK<vk::CommandBuffer>> buffers_to_collect_
std::vector<vk::UniqueCommandBuffer> buffers_to_collect_
IPLR_GUARDED_BY(buffers_to_collect_mutex_);
bool is_valid_ = false;