| Flutter Impeller |

Public Member Functions | List of all members
impeller::CommandPoolVK Class Referencefinal

Manages the lifecycle of a single |vk::CommandPool|. More...

`#include <command_pool_vk.h>`

## Public Member Functions
| ~CommandPoolVK ()
| CommandPoolVK (vk::UniqueCommandPool pool, std::weak_ptr< ContextVK > &context)
| Creates a resource that manages the life of a command pool. More...
vk::UniqueCommandBuffer | CreateCommandBuffer ()
| Creates and returns a new |vk::CommandBuffer|. More...
void | CollectCommandBuffer (vk::UniqueCommandBuffer &&buffer)
| Collects the given |vk::CommandBuffer| to be retained. More...
void | Destroy ()
| Delete all Vulkan objects in this command pool. More...

## Detailed Description

Manages the lifecycle of a single |vk::CommandPool|.

A |vk::CommandPool| is expensive to create and reset. This class manages the lifecycle of a single |vk::CommandPool| by returning to the origin (|CommandPoolRecyclerVK|) when it is destroyed to be reused.

Warning
  This class is not thread-safe.

See also
  |CommandPoolRecyclerVK|

Definition at line 31 of file command_pool_vk.h.

## Constructor & Destructor Documentation

## ◆ ~CommandPoolVK()

impeller::CommandPoolVK::~CommandPoolVK | ( |  | ) |

Definition at line 61 of file command_pool_vk.cc.

61 {
62 if (!pool_) {
63 return;
64 }
65
66 auto const context = context_.lock();
67 if (!context) {
68 return;
69 }
70 auto const recycler = context->GetCommandPoolRecycler();
71 if (!recycler) {
72 return;
73 }
74
75 auto reset_pool_when_dropped = BackgroundCommandPoolVK(
76 std::move(pool_), std::move(collected_buffers_), recycler);
77
78 UniqueResourceVKT<BackgroundCommandPoolVK> pool(
79 context->GetResourceManager(), std::move(reset_pool_when_dropped));
80 }

## ◆ CommandPoolVK()

impeller::CommandPoolVK::CommandPoolVK | ( | vk::UniqueCommandPool | pool,
|  | std::weak_ptr< ContextVK > & | context
| ) |  |
| inline explicit

Creates a resource that manages the life of a command pool.

Parameters

  [in] | pool | The command pool to manage.
  [in] | recycler | The context that will be notified on destruction.

Definition at line 39 of file command_pool_vk.h.

41 : pool_(std::move(pool)), context_(context) {}

## Member Function Documentation

## ◆ CollectCommandBuffer()

void impeller::CommandPoolVK::CollectCommandBuffer | ( | vk::UniqueCommandBuffer && | buffer | ) |

Collects the given |vk::CommandBuffer| to be retained.

Parameters

  [in] | buffer | The |vk::CommandBuffer| to collect.

See also
  |GarbageCollectBuffersIfAble|

Definition at line 106 of file command_pool_vk.cc.

106 {
107 Lock lock(pool_mutex_);
108 if (!pool_) {
109 // If the command pool has already been destroyed, then its buffers have
110 // already been freed.
111 buffer.release();
112 return;
113 }
114 collected_buffers_.push_back(std::move(buffer));
115 }

## ◆ CreateCommandBuffer()

vk::UniqueCommandBuffer impeller::CommandPoolVK::CreateCommandBuffer | ( |  | ) |

Creates and returns a new |vk::CommandBuffer|.

Returns
  Always returns a new |vk::CommandBuffer|, but if for any reason a valid command buffer could not be created, it will be a `{}` default instance (i.e. while being torn down).

Definition at line 83 of file command_pool_vk.cc.

83 {
84 auto const context = context_.lock();
85 if (!context) {
86 return {};
87 }
88
89 Lock lock(pool_mutex_);
90 if (!pool_) {
91 return {};
92 }
93
94 auto const device = context->GetDevice();
95 vk::CommandBufferAllocateInfo info;
96 info.setCommandPool(pool_.get());
97 info.setCommandBufferCount(1u);
98 info.setLevel(vk::CommandBufferLevel::ePrimary);
99 auto [result, buffers] = device.allocateCommandBuffersUnique(info);
100 if (result != vk::Result::eSuccess) {
101 return {};
102 }
103 return std::move(buffers[0]);
104 }

## ◆ Destroy()

void impeller::CommandPoolVK::Destroy | ( |  | ) |

Delete all Vulkan objects in this command pool.

Definition at line 117 of file command_pool_vk.cc.

117 {
118 Lock lock(pool_mutex_);
119 pool_.reset();
120
121 // When the command pool is destroyed, all of its command buffers are freed.
122 // Handles allocated from that pool are now invalid and must be discarded.
123 for (auto& buffer : collected_buffers_) {
124 buffer.release();
125 }
126 collected_buffers_.clear();
127 }

The documentation for this class was generated from the following files:

- impeller/renderer/backend/vulkan/command_pool_vk.h
- impeller/renderer/backend/vulkan/command_pool_vk.cc