Flutter Engine
The Flutter Engine
command_encoder_vk.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6#include <string>
7
8#include "flutter/fml/closure.h"
9#include "fml/status.h"
10#include "fml/status_or.h"
16
17namespace impeller {
18
20 const std::weak_ptr<const ContextVK>& context)
21 : context_(context) {}
22
23void CommandEncoderFactoryVK::SetLabel(const std::string& label) {
24 label_ = label;
25}
26
27std::shared_ptr<CommandEncoderVK> CommandEncoderFactoryVK::Create() {
28 auto context = context_.lock();
29 if (!context) {
30 return nullptr;
31 }
32 auto recycler = context->GetCommandPoolRecycler();
33 if (!recycler) {
34 return nullptr;
35 }
36 auto tls_pool = recycler->Get();
37 if (!tls_pool) {
38 return nullptr;
39 }
40
41 auto tracked_objects = std::make_shared<TrackedObjectsVK>(
42 context, tls_pool, context->GetGPUTracer()->CreateGPUProbe());
43 auto queue = context->GetGraphicsQueue();
44
45 if (!tracked_objects || !tracked_objects->IsValid() || !queue) {
46 return nullptr;
47 }
48
49 vk::CommandBufferBeginInfo begin_info;
50 begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
51 if (tracked_objects->GetCommandBuffer().begin(begin_info) !=
52 vk::Result::eSuccess) {
53 VALIDATION_LOG << "Could not begin command buffer.";
54 return nullptr;
55 }
56
57 if (label_.has_value()) {
58 context->SetDebugName(tracked_objects->GetCommandBuffer(), label_.value());
59 }
60 tracked_objects->GetGPUProbe().RecordCmdBufferStart(
61 tracked_objects->GetCommandBuffer());
62
63 return std::make_shared<CommandEncoderVK>(context->GetDeviceHolder(),
64 tracked_objects, queue,
65 context->GetFenceWaiter());
66}
67
69 std::weak_ptr<const DeviceHolderVK> device_holder,
70 std::shared_ptr<TrackedObjectsVK> tracked_objects,
71 const std::shared_ptr<QueueVK>& queue,
72 std::shared_ptr<FenceWaiterVK> fence_waiter)
73 : device_holder_(std::move(device_holder)),
74 tracked_objects_(std::move(tracked_objects)),
75 queue_(queue),
76 fence_waiter_(std::move(fence_waiter)) {}
77
79
81 return is_valid_;
82}
83
85 InsertDebugMarker("QueueSubmit");
86
87 auto command_buffer = GetCommandBuffer();
88 tracked_objects_->GetGPUProbe().RecordCmdBufferEnd(command_buffer);
89
90 auto status = command_buffer.end();
91 if (status != vk::Result::eSuccess) {
92 VALIDATION_LOG << "Failed to end command buffer: " << vk::to_string(status);
93 return false;
94 }
95 return true;
96}
97
98vk::CommandBuffer CommandEncoderVK::GetCommandBuffer() const {
99 if (tracked_objects_) {
100 return tracked_objects_->GetCommandBuffer();
101 }
102 return {};
103}
104
105void CommandEncoderVK::Reset() {
106 tracked_objects_.reset();
107
108 queue_ = nullptr;
109 is_valid_ = false;
110}
111
112bool CommandEncoderVK::Track(std::shared_ptr<SharedObjectVK> object) {
113 if (!IsValid()) {
114 return false;
115 }
116 tracked_objects_->Track(std::move(object));
117 return true;
118}
119
120bool CommandEncoderVK::Track(std::shared_ptr<const DeviceBuffer> buffer) {
121 if (!IsValid()) {
122 return false;
123 }
124 tracked_objects_->Track(std::move(buffer));
125 return true;
126}
127
129 const std::shared_ptr<const DeviceBuffer>& buffer) const {
130 if (!IsValid()) {
131 return false;
132 }
133 return tracked_objects_->IsTracking(buffer);
134}
135
136bool CommandEncoderVK::Track(std::shared_ptr<const TextureSourceVK> texture) {
137 if (!IsValid()) {
138 return false;
139 }
140 tracked_objects_->Track(std::move(texture));
141 return true;
142}
143
144bool CommandEncoderVK::Track(const std::shared_ptr<const Texture>& texture) {
145 if (!IsValid()) {
146 return false;
147 }
148 if (!texture) {
149 return true;
150 }
151 return Track(TextureVK::Cast(*texture).GetTextureSource());
152}
153
155 const std::shared_ptr<const Texture>& texture) const {
156 if (!IsValid()) {
157 return false;
158 }
159 std::shared_ptr<const TextureSourceVK> source =
161 return tracked_objects_->IsTracking(source);
162}
163
165 const vk::DescriptorSetLayout& layout,
166 const ContextVK& context) {
167 if (!IsValid()) {
168 return fml::Status(fml::StatusCode::kUnknown, "command encoder invalid");
169 }
170
171 return tracked_objects_->GetDescriptorPool().AllocateDescriptorSets(layout,
172 context);
173}
174
175void CommandEncoderVK::PushDebugGroup(std::string_view label) const {
176 if (!HasValidationLayers()) {
177 return;
178 }
179 vk::DebugUtilsLabelEXT label_info;
180 label_info.pLabelName = label.data();
181 if (auto command_buffer = GetCommandBuffer()) {
182 command_buffer.beginDebugUtilsLabelEXT(label_info);
183 }
184}
185
187 if (!HasValidationLayers()) {
188 return;
189 }
190 if (auto command_buffer = GetCommandBuffer()) {
191 command_buffer.endDebugUtilsLabelEXT();
192 }
193}
194
195void CommandEncoderVK::InsertDebugMarker(std::string_view label) const {
196 if (!HasValidationLayers()) {
197 return;
198 }
199 vk::DebugUtilsLabelEXT label_info;
200 label_info.pLabelName = label.data();
201 if (auto command_buffer = GetCommandBuffer()) {
202 command_buffer.insertDebugUtilsLabelEXT(label_info);
203 }
204 if (queue_) {
205 queue_->InsertDebugMarker(label);
206 }
207}
208
209} // namespace impeller
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:13
std::shared_ptr< CommandEncoderVK > Create()
void SetLabel(const std::string &label)
CommandEncoderFactoryVK(const std::weak_ptr< const ContextVK > &context)
void PushDebugGroup(std::string_view label) const
bool Track(std::shared_ptr< SharedObjectVK > object)
CommandEncoderVK(std::weak_ptr< const DeviceHolderVK > device_holder, std::shared_ptr< TrackedObjectsVK > tracked_objects, const std::shared_ptr< QueueVK > &queue, std::shared_ptr< FenceWaiterVK > fence_waiter)
vk::CommandBuffer GetCommandBuffer() const
bool IsTracking(const std::shared_ptr< const DeviceBuffer > &texture) const
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, const ContextVK &context)
void InsertDebugMarker(std::string_view label) const
std::shared_ptr< const TextureSourceVK > GetTextureSource() const
Definition: texture_vk.cc:155
VkQueue queue
Definition: main.cc:55
SkBitmap source
Definition: examples.cpp:28
FlTexture * texture
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
bool HasValidationLayers()
Definition: context_vk.cc:48
Task::Status Status
Definition: TaskList.cpp:15
Definition: ref_ptr.h:256
static SkString to_string(int n)
Definition: nanobench.cpp:119
#define VALIDATION_LOG
Definition: validation.h:73