| Flutter Impeller |

Public Member Functions | List of all members
impeller::CommandQueueVK Class Reference

`#include <command_queue_vk.h>`

Inheritance diagram for impeller::CommandQueueVK:

## Public Member Functions
| CommandQueueVK (const std::weak_ptr< ContextVK > &context)
| ~CommandQueueVK () override
fml::Status | Submit (const std::vector< std::shared_ptr< CommandBuffer >> &buffers, const CompletionCallback &completion_callback={}, bool block_on_schedule=false) override
| Submit one or more command buffer objects to be encoded and executed on the GPU. More...
Public Member Functions inherited from impeller::CommandQueue
| CommandQueue ()
virtual | ~CommandQueue ()

## Additional Inherited Members
Public Types inherited from impeller::CommandQueue
using | CompletionCallback = std::function< void(CommandBuffer::Status)>

## Detailed Description

Definition at line 14 of file command_queue_vk.h.

## Constructor & Destructor Documentation

## ◆ CommandQueueVK()

impeller::CommandQueueVK::CommandQueueVK | ( | const std::weak_ptr< ContextVK > & | context | ) |
| explicit

Definition at line 18 of file command_queue_vk.cc.

19 : context_(context) {}

## ◆ ~CommandQueueVK()

impeller::CommandQueueVK::~CommandQueueVK | ( |  | ) |
| override default

## Member Function Documentation

## ◆ Submit()

fml::Status impeller::CommandQueueVK::Submit | ( | const std::vector< std::shared_ptr< CommandBuffer >> & | buffers,
|  | const CompletionCallback & | completion_callback = `{}`,
|  | bool | block_on_schedule = `false`
| ) |  |
| override virtual

Submit one or more command buffer objects to be encoded and executed on the GPU.

The order of the provided buffers determines the ordering in which they are submitted.

The returned status only indicates if the command buffer was successfully submitted. Successful completion of the command buffer can only be checked in the optional completion callback.

Only the Metal and Vulkan backends can give a status beyond successful encoding. This callback may be called more than once and potentially on a different thread.

If [block_on_schedule] is true, this function will not return until the command buffer has been scheduled. This only impacts the Metal backend.

Reimplemented from impeller::CommandQueue.

Definition at line 23 of file command_queue_vk.cc.

26 {
27 if (buffers.empty()) {
28 return fml::Status(fml::StatusCode::kInvalidArgument,
29 "No command buffers provided.");
30 }
31 // Success or failure, you only get to submit once.
32 fml::ScopedCleanupClosure reset([&]() {
33 if (completion_callback) {
34 completion_callback(CommandBuffer::Status::kError);
35 }
36 });
37
38 std::vector<vk::CommandBuffer> vk_buffers;
39 std::vector<std::shared_ptr<TrackedObjectsVK>> tracked_objects;
40 vk_buffers.reserve(buffers.size());
41 tracked_objects.reserve(buffers.size());
42 for (const std::shared_ptr<CommandBuffer>& buffer : buffers) {
43 CommandBufferVK& command_buffer = CommandBufferVK::Cast(*buffer);
44 if (!command_buffer.EndCommandBuffer()) {
45 return fml::Status(fml::StatusCode::kCancelled,
46 "Failed to end command buffer.");
47 }
48 vk_buffers.push_back(command_buffer.GetCommandBuffer());
49 tracked_objects.push_back(std::move(command_buffer.tracked_objects_));
50 }
51
52 auto context = context_.lock();
53 if (!context) {
54 VALIDATION_LOG << "Device lost.";
55 return fml::Status(fml::StatusCode::kCancelled, "Device lost.");
56 }
57 auto [fence_result, fence] = context->GetDevice().createFenceUnique({});
58 if (fence_result != vk::Result::eSuccess) {
59 VALIDATION_LOG << "Failed to create fence: " << vk::to_string(fence_result);
60 return fml::Status(fml::StatusCode::kCancelled, "Failed to create fence.");
61 }
62
63 vk::SubmitInfo submit_info;
64 submit_info.setCommandBuffers(vk_buffers);
65 auto status = context->GetGraphicsQueue()->Submit(submit_info, *fence);
66 if (status != vk::Result::eSuccess) {
67 VALIDATION_LOG << "Failed to submit queue: " << vk::to_string(status);
68 return fml::Status(fml::StatusCode::kCancelled, "Failed to submit queue: ");
69 }
70
71 // Submit will proceed, call callback with true when it is done and do not
72 // call when `reset` is collected.
73 auto added_fence = context->GetFenceWaiter()->AddFence(
74 std::move(fence), [completion_callback, tracked_objects = std::move(
75 tracked_objects)]() mutable {
76 // Ensure tracked objects are destructed before calling any final
77 // callbacks.
78 tracked_objects.clear();
79 if (completion_callback) {
80 completion_callback(CommandBuffer::Status::kCompleted);
81 }
82 });
83 if (!added_fence) {
84 return fml::Status(fml::StatusCode::kCancelled, "Failed to add fence.");
85 }
86 reset.Release();
87 return fml::Status();
88 }
impeller::BackendCast< CommandBufferVK, CommandBuffer >::Cast
static CommandBufferVK & Cast(CommandBuffer &base)
Definition: backend_cast.h:13
impeller::CommandBuffer::Status::kCompleted
@ kCompleted
impeller::CommandBuffer::Status::kError
@ kError
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BackendCast< CommandBufferVK, CommandBuffer >::Cast(), impeller::CommandBufferVK::EndCommandBuffer(), impeller::CommandBufferVK::GetCommandBuffer(), impeller::CommandBuffer::kCompleted, impeller::CommandBuffer::kError, and VALIDATION_LOG.

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

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