| Flutter Impeller |

Public Types | Public Member Functions | Friends | List of all members
impeller::CommandEncoderVK Class Reference

`#include <command_encoder_vk.h>`

## Public Types
using | SubmitCallback = std::function< void(bool)>

## Public Member Functions
| CommandEncoderVK (std::weak_ptr< const DeviceHolder > device_holder, std::shared_ptr< TrackedObjectsVK > tracked_objects, const std::shared_ptr< QueueVK > &queue, std::shared_ptr< FenceWaiterVK > fence_waiter)
| ~CommandEncoderVK ()
bool | IsValid () const
bool | Submit (SubmitCallback callback={})
bool | Track (std::shared_ptr< SharedObjectVK > object)
bool | Track (std::shared_ptr< const Buffer > buffer)
bool | IsTracking (const std::shared_ptr< const Buffer > &texture) const
bool | Track (const std::shared_ptr< const Texture > &texture)
bool | IsTracking (const std::shared_ptr< const Texture > &texture) const
bool | Track (std::shared_ptr< const TextureSourceVK > texture)
vk::CommandBuffer | GetCommandBuffer () const
void | PushDebugGroup (const char *label) const
void | PopDebugGroup () const
void | InsertDebugMarker (const char *label) const
fml::StatusOr< std::vector< vk::DescriptorSet > > | AllocateDescriptorSets (uint32_t buffer_count, uint32_t sampler_count, uint32_t subpass_count, const std::vector< vk::DescriptorSetLayout > &layouts)

## Friends
class | ContextVK

## Detailed Description

Definition at line 49 of file command_encoder_vk.h.

## Member Typedef Documentation

## ◆ SubmitCallback

using impeller::CommandEncoderVK::SubmitCallback = std::function<void(bool)>

Definition at line 51 of file command_encoder_vk.h.

## Constructor & Destructor Documentation

## ◆ CommandEncoderVK()

impeller::CommandEncoderVK::CommandEncoderVK | ( | std::weak_ptr< const DeviceHolder > | device_holder,
|  | std::shared_ptr< TrackedObjectsVK > | tracked_objects,
|  | const std::shared_ptr< QueueVK > & | queue,
|  | std::shared_ptr< FenceWaiterVK > | fence_waiter
| ) |  |

Definition at line 150 of file command_encoder_vk.cc.

155 : device_holder_(std::move(device_holder)),
156 tracked_objects_(std::move(tracked_objects)),
157 queue_(queue),
158 fence_waiter_(std::move(fence_waiter)) {}

## ◆ ~CommandEncoderVK()

impeller::CommandEncoderVK::~CommandEncoderVK | ( |  | ) |
| default

## Member Function Documentation

## ◆ AllocateDescriptorSets()

fml::StatusOr< std::vector< vk::DescriptorSet > > impeller::CommandEncoderVK::AllocateDescriptorSets | ( | uint32_t | buffer_count,
|  | uint32_t | sampler_count,
|  | uint32_t | subpass_count,
|  | const std::vector< vk::DescriptorSetLayout > & | layouts
| ) |  |

Definition at line 298 of file command_encoder_vk.cc.

302 {
303 if (!IsValid()) {
304 return fml::Status(fml::StatusCode::kUnknown, "command encoder invalid");
305 }
306
307 return tracked_objects_->GetDescriptorPool().AllocateDescriptorSets(
308 buffer_count, sampler_count, subpass_count, layouts);
309 }

References IsValid().

## ◆ GetCommandBuffer()

vk::CommandBuffer impeller::CommandEncoderVK::GetCommandBuffer | ( |  | ) | const

Definition at line 231 of file command_encoder_vk.cc.

231 {
232 if (tracked_objects_) {
233 return tracked_objects_->GetCommandBuffer();
234 }
235 return {};
236 }

Referenced by impeller::BlitCopyTextureToTextureCommandVK::Encode(), impeller::BlitCopyTextureToBufferCommandVK::Encode(), impeller::BlitCopyBufferToTextureCommandVK::Encode(), impeller::BlitGenerateMipmapCommandVK::Encode(), impeller::EncodeCommand(), InsertDebugMarker(), PopDebugGroup(), PushDebugGroup(), and Submit().

## ◆ InsertDebugMarker()

void impeller::CommandEncoderVK::InsertDebugMarker | ( | const char * | label | ) | const

Definition at line 331 of file command_encoder_vk.cc.

331 {
332 if (!HasValidationLayers()) {
333 return;
334 }
335 vk::DebugUtilsLabelEXT label_info;
336 label_info.pLabelName = label;
337 if (auto command_buffer = GetCommandBuffer()) {
338 command_buffer.insertDebugUtilsLabelEXT(label_info);
339 }
340 if (queue_) {
341 queue_->InsertDebugMarker(label);
342 }
343 }

References GetCommandBuffer(), and impeller::HasValidationLayers().

Referenced by Submit().

## ◆ IsTracking() [1/2]

bool impeller::CommandEncoderVK::IsTracking | ( | const std::shared_ptr< const Buffer > & | texture | ) | const

Definition at line 261 of file command_encoder_vk.cc.

262 {
263 if (!IsValid()) {
264 return false;
265 }
266 return tracked_objects_->IsTracking(buffer);
267 }

References IsValid().

## ◆ IsTracking() [2/2]

bool impeller::CommandEncoderVK::IsTracking | ( | const std::shared_ptr< const Texture > & | texture | ) | const

Definition at line 287 of file command_encoder_vk.cc.

288 {
289 if (!IsValid()) {
290 return false;
291 }
292 std::shared_ptr<const TextureSourceVK> source =
293 TextureVK::Cast(*texture).GetTextureSource();
294 return tracked_objects_->IsTracking(source);
295 }

References impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::TextureVK::GetTextureSource(), and IsValid().

## ◆ IsValid()

bool impeller::CommandEncoderVK::IsValid | ( |  | ) | const

Definition at line 162 of file command_encoder_vk.cc.

162 {
163 return is_valid_;
164 }

Referenced by AllocateDescriptorSets(), IsTracking(), Submit(), and Track().

## ◆ PopDebugGroup()

void impeller::CommandEncoderVK::PopDebugGroup | ( |  | ) | const

Definition at line 322 of file command_encoder_vk.cc.

322 {
323 if (!HasValidationLayers()) {
324 return;
325 }
326 if (auto command_buffer = GetCommandBuffer()) {
327 command_buffer.endDebugUtilsLabelEXT();
328 }
329 }

References GetCommandBuffer(), and impeller::HasValidationLayers().

Referenced by impeller::EncodeCommand().

## ◆ PushDebugGroup()

void impeller::CommandEncoderVK::PushDebugGroup | ( | const char * | label | ) | const

Definition at line 311 of file command_encoder_vk.cc.

311 {
312 if (!HasValidationLayers()) {
313 return;
314 }
315 vk::DebugUtilsLabelEXT label_info;
316 label_info.pLabelName = label;
317 if (auto command_buffer = GetCommandBuffer()) {
318 command_buffer.beginDebugUtilsLabelEXT(label_info);
319 }
320 }

References GetCommandBuffer(), and impeller::HasValidationLayers().

Referenced by impeller::EncodeCommand().

## ◆ Submit()

bool impeller::CommandEncoderVK::Submit | ( | SubmitCallback | callback = `{}` | ) |

Definition at line 166 of file command_encoder_vk.cc.

166 {
167 // Make sure to call callback with `false` if anything returns early.
168 bool fail_callback = !!callback;
169 if (!IsValid()) {
170 VALIDATION_LOG << "Cannot submit invalid CommandEncoderVK.";
171 if (fail_callback) {
172 callback(false);
173 }
174 return false;
175 }
176
177 // Success or failure, you only get to submit once.
178 fml::ScopedCleanupClosure reset([&]() {
179 if (fail_callback) {
180 callback(false);
181 }
182 Reset();
183 });
184
185 InsertDebugMarker("QueueSubmit");
186
187 auto command_buffer = GetCommandBuffer();
188
189 tracked_objects_->GetGPUProbe().RecordCmdBufferEnd(command_buffer);
190
191 auto status = command_buffer.end();
192 if (status != vk::Result::eSuccess) {
193 VALIDATION_LOG << "Failed to end command buffer: " << vk::to_string(status);
194 return false;
195 }
196 std::shared_ptr<const DeviceHolder> strong_device = device_holder_.lock();
197 if (!strong_device) {
198 VALIDATION_LOG << "Device lost.";
199 return false;
200 }
201 auto [fence_result, fence] = strong_device->GetDevice().createFenceUnique({});
202 if (fence_result != vk::Result::eSuccess) {
203 VALIDATION_LOG << "Failed to create fence: " << vk::to_string(fence_result);
204 return false;
205 }
206
207 vk::SubmitInfo submit_info;
208 std::vector<vk::CommandBuffer> buffers = {command_buffer};
209 submit_info.setCommandBuffers(buffers);
210 status = queue_->Submit(submit_info, *fence);
211 if (status != vk::Result::eSuccess) {
212 VALIDATION_LOG << "Failed to submit queue: " << vk::to_string(status);
213 return false;
214 }
215
216 // Submit will proceed, call callback with true when it is done and do not
217 // call when `reset` is collected.
218 fail_callback = false;
219 return fence_waiter_->AddFence(
220 std::move(fence),
221 [callback, tracked_objects = std::move(tracked_objects_)]() mutable {
222 // Ensure tracked objects are destructed before calling any final
223 // callbacks.
224 tracked_objects.reset();
225 if (callback) {
226 callback(true);
227 }
228 });
229 }

References GetCommandBuffer(), InsertDebugMarker(), IsValid(), and VALIDATION_LOG.

## ◆ Track() [1/4]

bool impeller::CommandEncoderVK::Track | ( | const std::shared_ptr< const Texture > & | texture | ) |

Definition at line 277 of file command_encoder_vk.cc.

277 {
278 if (!IsValid()) {
279 return false;
280 }
281 if (!texture) {
282 return true;
283 }
284 return Track(TextureVK::Cast(*texture).GetTextureSource());
285 }

References impeller::BackendCast< TextureVK, Texture >::Cast(), impeller::TextureVK::GetTextureSource(), IsValid(), and Track().

## ◆ Track() [2/4]

bool impeller::CommandEncoderVK::Track | ( | std::shared_ptr< const Buffer > | buffer | ) |

Definition at line 253 of file command_encoder_vk.cc.

253 {
254 if (!IsValid()) {
255 return false;
256 }
257 tracked_objects_->Track(std::move(buffer));
258 return true;
259 }

References IsValid().

## ◆ Track() [3/4]

bool impeller::CommandEncoderVK::Track | ( | std::shared_ptr< const TextureSourceVK > | texture | ) |

Definition at line 269 of file command_encoder_vk.cc.

269 {
270 if (!IsValid()) {
271 return false;
272 }
273 tracked_objects_->Track(std::move(texture));
274 return true;
275 }

References IsValid().

## ◆ Track() [4/4]

bool impeller::CommandEncoderVK::Track | ( | std::shared_ptr< SharedObjectVK > | object | ) |

Definition at line 245 of file command_encoder_vk.cc.

245 {
246 if (!IsValid()) {
247 return false;
248 }
249 tracked_objects_->Track(std::move(object));
250 return true;
251 }

References IsValid().

Referenced by impeller::BlitCopyTextureToTextureCommandVK::Encode(), impeller::BlitCopyTextureToBufferCommandVK::Encode(), impeller::BlitCopyBufferToTextureCommandVK::Encode(), impeller::BlitGenerateMipmapCommandVK::Encode(), and Track().

## Friends And Related Function Documentation

## ◆ ContextVK

friend class ContextVK
| friend

Definition at line 92 of file command_encoder_vk.h.

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

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

impeller::TextureVK::GetTextureSource
std::shared_ptr< const TextureSourceVK > GetTextureSource() const
Definition: texture_vk.cc:136
impeller::CommandEncoderVK::Track
bool Track(std::shared_ptr< SharedObjectVK > object)
Definition: command_encoder_vk.cc:245
impeller::CommandEncoderVK::InsertDebugMarker
void InsertDebugMarker(const char *label) const
Definition: command_encoder_vk.cc:331
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:15
impeller::HasValidationLayers
bool HasValidationLayers()
Definition: context_vk.cc:43
impeller::CommandEncoderVK::IsValid
bool IsValid() const
Definition: command_encoder_vk.cc:162
impeller::CommandEncoderVK::GetCommandBuffer
vk::CommandBuffer GetCommandBuffer() const
Definition: command_encoder_vk.cc:231