| 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 30 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 if (kResetOnBackgroundThread) {
79 UniqueResourceVKT<BackgroundCommandPoolVK> pool(
80 context->GetResourceManager(), std::move(reset_pool_when_dropped));
81 }
82 }

References impeller::kResetOnBackgroundThread.

## ◆ 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 38 of file command_pool_vk.h.

40 : 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 108 of file command_pool_vk.cc.

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

## ◆ 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 85 of file command_pool_vk.cc.

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

## ◆ Destroy()

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

Delete all Vulkan objects in this command pool.

Definition at line 119 of file command_pool_vk.cc.

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

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

impeller::kResetOnBackgroundThread
static bool kResetOnBackgroundThread
Definition: command_pool_vk.cc:59