Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions impeller/renderer/backend/vulkan/command_pool_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the handle to the buffer will still be leaked right? Unless this is a reset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier this function calls graphics_pool_.reset(), which destroys the Vulkan command pool and frees all of the pool's buffers.

After that the buffer handle is invalid, and the Vulkan validation layers will warn about a call to vkFreeCommandBuffers using the handle.

}
buffers_to_collect_.clear();

is_valid_ = false;
}

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/command_pool_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down