Skip to content

Commit 8bee0dc

Browse files
[Impeller] Discard invalid command buffer handles after destroying a command pool (flutter#44194)
Fixes flutter#131522
1 parent 0838f9b commit 8bee0dc

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

impeller/renderer/backend/vulkan/command_pool_vk.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ bool CommandPoolVK::IsValid() const {
9292

9393
void CommandPoolVK::Reset() {
9494
Lock lock(buffers_to_collect_mutex_);
95-
GarbageCollectBuffersIfAble();
9695
graphics_pool_.reset();
96+
97+
// When the command pool is destroyed, all of its command buffers are freed.
98+
// Handles allocated from that pool are now invalid and must be discarded.
99+
for (vk::UniqueCommandBuffer& buffer : buffers_to_collect_) {
100+
buffer.release();
101+
}
102+
buffers_to_collect_.clear();
103+
97104
is_valid_ = false;
98105
}
99106

@@ -133,7 +140,7 @@ void CommandPoolVK::CollectGraphicsCommandBuffer(
133140
// have been freed and are now invalid.
134141
buffer.release();
135142
}
136-
buffers_to_collect_.insert(MakeSharedVK(std::move(buffer)));
143+
buffers_to_collect_.emplace_back(std::move(buffer));
137144
GarbageCollectBuffersIfAble();
138145
}
139146

impeller/renderer/backend/vulkan/command_pool_vk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CommandPoolVK {
4242
std::weak_ptr<const DeviceHolder> device_holder_;
4343
vk::UniqueCommandPool graphics_pool_;
4444
Mutex buffers_to_collect_mutex_;
45-
std::set<SharedHandleVK<vk::CommandBuffer>> buffers_to_collect_
45+
std::vector<vk::UniqueCommandBuffer> buffers_to_collect_
4646
IPLR_GUARDED_BY(buffers_to_collect_mutex_);
4747
bool is_valid_ = false;
4848

0 commit comments

Comments
 (0)