Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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::vector< vk::UniqueCommandBuffer > &&buffers, std::weak_ptr< ContextVK > context, std::weak_ptr< DeviceHolderVK > device_holder)
 Creates a resource that manages the life of a command pool.
 
vk::UniqueCommandBuffer CreateCommandBuffer ()
 Creates and returns a new |vk::CommandBuffer|.
 
void CollectCommandBuffer (vk::UniqueCommandBuffer &&buffer)
 Collects the given |vk::CommandBuffer| to be retained.
 

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 32 of file command_pool_vk.h.

Constructor & Destructor Documentation

◆ ~CommandPoolVK()

impeller::CommandPoolVK::~CommandPoolVK ( )

Definition at line 72 of file command_pool_vk.cc.

72 {
73 if (!pool_) {
74 return;
75 }
76
77 std::shared_ptr<DeviceHolderVK> device_holder = device_holder_.lock();
78 if (!device_holder) {
79 pool_.release();
80 for (auto& buffer : collected_buffers_) {
81 buffer.release();
82 }
83 for (auto& buffer : unused_command_buffers_) {
84 buffer.release();
85 }
86 return;
87 }
88
89 auto const context = context_.lock();
90 if (!context) {
91 return;
92 }
93 auto const recycler = context->GetCommandPoolRecycler();
94 if (!recycler) {
95 return;
96 }
97 // Any unused command buffers are added to the set of used command buffers.
98 // both will be reset to the initial state when the pool is reset.
99 size_t unused_count = unused_command_buffers_.size();
100 for (auto i = 0u; i < unused_command_buffers_.size(); i++) {
101 collected_buffers_.push_back(std::move(unused_command_buffers_[i]));
102 }
103 unused_command_buffers_.clear();
104
105 auto reset_pool_when_dropped = BackgroundCommandPoolVK(
106 std::move(pool_), std::move(collected_buffers_), unused_count, recycler);
107
108 UniqueResourceVKT<BackgroundCommandPoolVK> pool(
109 context->GetResourceManager(), std::move(reset_pool_when_dropped));
110}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98

References i.

◆ CommandPoolVK()

impeller::CommandPoolVK::CommandPoolVK ( vk::UniqueCommandPool  pool,
std::vector< vk::UniqueCommandBuffer > &&  buffers,
std::weak_ptr< ContextVK context,
std::weak_ptr< DeviceHolderVK device_holder 
)
inline

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

Parameters
[in]poolThe command pool to manage.
[in]buffersZero or more command buffers in an initial state.
[in]recyclerThe context that will be notified on destruction.

Definition at line 41 of file command_pool_vk.h.

45 : pool_(std::move(pool)),
46 unused_command_buffers_(std::move(buffers)),
47 context_(std::move(context)),
48 device_holder_(std::move(device_holder)) {}

Member Function Documentation

◆ CollectCommandBuffer()

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

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

Parameters
[in]bufferThe |vk::CommandBuffer| to collect.
See also
|GarbageCollectBuffersIfAble|

Definition at line 141 of file command_pool_vk.cc.

141 {
142 Lock lock(pool_mutex_);
143 if (!pool_) {
144 // If the command pool has already been destroyed, then its buffers have
145 // already been freed.
146 buffer.release();
147 return;
148 }
149 collected_buffers_.push_back(std::move(buffer));
150}

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

113 {
114 auto const context = context_.lock();
115 if (!context) {
116 return {};
117 }
118
119 Lock lock(pool_mutex_);
120 if (!pool_) {
121 return {};
122 }
123 if (!unused_command_buffers_.empty()) {
124 vk::UniqueCommandBuffer buffer = std::move(unused_command_buffers_.back());
125 unused_command_buffers_.pop_back();
126 return buffer;
127 }
128
129 auto const device = context->GetDevice();
130 vk::CommandBufferAllocateInfo info;
131 info.setCommandPool(pool_.get());
132 info.setCommandBufferCount(1u);
133 info.setLevel(vk::CommandBufferLevel::ePrimary);
134 auto [result, buffers] = device.allocateCommandBuffersUnique(info);
135 if (result != vk::Result::eSuccess) {
136 return {};
137 }
138 return std::move(buffers[0]);
139}
VkDevice device
Definition main.cc:69

References device.


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