Flutter Impeller
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
 
std::optional< vk::DescriptorSet > AllocateDescriptorSet (const vk::DescriptorSetLayout &layout, size_t command_count)
 

Friends

class ContextVK
 

Detailed Description

Definition at line 45 of file command_encoder_vk.h.

Member Typedef Documentation

◆ SubmitCallback

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

Definition at line 47 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 142 of file command_encoder_vk.cc.

147  : device_holder_(std::move(device_holder)),
148  tracked_objects_(std::move(tracked_objects)),
149  queue_(queue),
150  fence_waiter_(std::move(fence_waiter)) {}

◆ ~CommandEncoderVK()

impeller::CommandEncoderVK::~CommandEncoderVK ( )
default

Member Function Documentation

◆ AllocateDescriptorSet()

std::optional< vk::DescriptorSet > impeller::CommandEncoderVK::AllocateDescriptorSet ( const vk::DescriptorSetLayout &  layout,
size_t  command_count 
)

Definition at line 284 of file command_encoder_vk.cc.

286  {
287  if (!IsValid()) {
288  return std::nullopt;
289  }
290 
291  return tracked_objects_->GetDescriptorPool().AllocateDescriptorSet(
292  layout, command_count);
293 }

References IsValid().

Referenced by impeller::AllocateAndBindDescriptorSets().

◆ GetCommandBuffer()

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

◆ InsertDebugMarker()

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

Definition at line 315 of file command_encoder_vk.cc.

315  {
316  if (!HasValidationLayers()) {
317  return;
318  }
319  vk::DebugUtilsLabelEXT label_info;
320  label_info.pLabelName = label;
321  if (auto command_buffer = GetCommandBuffer()) {
322  command_buffer.insertDebugUtilsLabelEXT(label_info);
323  }
324  if (queue_) {
325  queue_->InsertDebugMarker(label);
326  }
327 }

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 248 of file command_encoder_vk.cc.

249  {
250  if (!IsValid()) {
251  return false;
252  }
253  return tracked_objects_->IsTracking(buffer);
254 }

References IsValid().

◆ IsTracking() [2/2]

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

Definition at line 274 of file command_encoder_vk.cc.

275  {
276  if (!IsValid()) {
277  return false;
278  }
279  std::shared_ptr<const TextureSourceVK> source =
280  TextureVK::Cast(*texture).GetTextureSource();
281  return tracked_objects_->IsTracking(source);
282 }

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

◆ IsValid()

bool impeller::CommandEncoderVK::IsValid ( ) const

Definition at line 154 of file command_encoder_vk.cc.

154  {
155  return is_valid_;
156 }

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

◆ PopDebugGroup()

void impeller::CommandEncoderVK::PopDebugGroup ( ) const

Definition at line 306 of file command_encoder_vk.cc.

306  {
307  if (!HasValidationLayers()) {
308  return;
309  }
310  if (auto command_buffer = GetCommandBuffer()) {
311  command_buffer.endDebugUtilsLabelEXT();
312  }
313 }

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

Referenced by impeller::EncodeCommand().

◆ PushDebugGroup()

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

Definition at line 295 of file command_encoder_vk.cc.

295  {
296  if (!HasValidationLayers()) {
297  return;
298  }
299  vk::DebugUtilsLabelEXT label_info;
300  label_info.pLabelName = label;
301  if (auto command_buffer = GetCommandBuffer()) {
302  command_buffer.beginDebugUtilsLabelEXT(label_info);
303  }
304 }

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

Referenced by impeller::EncodeCommand().

◆ Submit()

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

Definition at line 158 of file command_encoder_vk.cc.

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

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

◆ Track() [1/4]

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

Definition at line 264 of file command_encoder_vk.cc.

264  {
265  if (!IsValid()) {
266  return false;
267  }
268  if (!texture) {
269  return true;
270  }
271  return Track(TextureVK::Cast(*texture).GetTextureSource());
272 }

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 240 of file command_encoder_vk.cc.

240  {
241  if (!IsValid()) {
242  return false;
243  }
244  tracked_objects_->Track(std::move(buffer));
245  return true;
246 }

References IsValid().

◆ Track() [3/4]

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

Definition at line 256 of file command_encoder_vk.cc.

256  {
257  if (!IsValid()) {
258  return false;
259  }
260  tracked_objects_->Track(std::move(texture));
261  return true;
262 }

References IsValid().

◆ Track() [4/4]

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

Friends And Related Function Documentation

◆ ContextVK

friend class ContextVK
friend

Definition at line 86 of file command_encoder_vk.h.


The documentation for this class was generated from the following files:
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:232
impeller::CommandEncoderVK::InsertDebugMarker
void InsertDebugMarker(const char *label) const
Definition: command_encoder_vk.cc:315
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::BackendCast< TextureVK, Texture >::Cast
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:14
impeller::HasValidationLayers
bool HasValidationLayers()
Definition: context_vk.cc:40
impeller::CommandEncoderVK::IsValid
bool IsValid() const
Definition: command_encoder_vk.cc:154
impeller::CommandEncoderVK::GetCommandBuffer
vk::CommandBuffer GetCommandBuffer() const
Definition: command_encoder_vk.cc:218