Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
command_buffer_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
7#include <memory>
8#include <utility>
9
10#include "fml/logging.h"
19
20namespace impeller {
21
22CommandBufferVK::CommandBufferVK(
23 std::weak_ptr<const Context> context,
24 std::shared_ptr<TrackedObjectsVK> tracked_objects)
25 : CommandBuffer(std::move(context)),
26 tracked_objects_(std::move(tracked_objects)) {}
27
28CommandBufferVK::~CommandBufferVK() = default;
29
30void CommandBufferVK::SetLabel(std::string_view label) const {
31#ifdef IMPELLER_DEBUG
32 auto context = context_.lock();
33 if (!context) {
34 return;
35 }
36 ContextVK::Cast(*context).SetDebugName(GetCommandBuffer(), label);
37#endif // IMPELLER_DEBUG
38}
39
40bool CommandBufferVK::IsValid() const {
41 return true;
42}
43
44bool CommandBufferVK::OnSubmitCommands(bool block_on_schedule,
45 CompletionCallback callback) {
47}
48
49void CommandBufferVK::OnWaitUntilCompleted() {}
50
51void CommandBufferVK::OnWaitUntilScheduled() {}
52
53std::shared_ptr<RenderPass> CommandBufferVK::OnCreateRenderPass(
54 RenderTarget target) {
55 auto context = context_.lock();
56 if (!context) {
57 return nullptr;
58 }
59 auto pass =
60 std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
61 target, //
62 shared_from_this() //
63 ));
64 if (!pass->IsValid()) {
65 return nullptr;
66 }
67 return pass;
68}
69
70std::shared_ptr<BlitPass> CommandBufferVK::OnCreateBlitPass() {
71 if (!IsValid()) {
72 return nullptr;
73 }
74 auto context = context_.lock();
75 if (!context) {
76 return nullptr;
77 }
78 auto pass = std::shared_ptr<BlitPassVK>(new BlitPassVK(
79 shared_from_this(), ContextVK::Cast(*context).GetWorkarounds()));
80 if (!pass->IsValid()) {
81 return nullptr;
82 }
83 return pass;
84}
85
86std::shared_ptr<ComputePass> CommandBufferVK::OnCreateComputePass() {
87 if (!IsValid()) {
88 return nullptr;
89 }
90 auto context = context_.lock();
91 if (!context) {
92 return nullptr;
93 }
94 auto pass =
95 std::shared_ptr<ComputePassVK>(new ComputePassVK(context, //
96 shared_from_this() //
97 ));
98 if (!pass->IsValid()) {
99 return nullptr;
100 }
101 return pass;
102}
103
104bool CommandBufferVK::EndCommandBuffer() const {
105 InsertDebugMarker("QueueSubmit");
106
107 auto command_buffer = GetCommandBuffer();
108 tracked_objects_->GetGPUProbe().RecordCmdBufferEnd(command_buffer);
109
110 auto status = command_buffer.end();
111 if (status != vk::Result::eSuccess) {
112 VALIDATION_LOG << "Failed to end command buffer: " << vk::to_string(status);
113 return false;
114 }
115 return true;
116}
117
118vk::CommandBuffer CommandBufferVK::GetCommandBuffer() const {
119 if (tracked_objects_) {
120 return tracked_objects_->GetCommandBuffer();
121 }
122 return {};
123}
124
125bool CommandBufferVK::Track(const std::shared_ptr<SharedObjectVK>& object) {
126 if (!IsValid()) {
127 return false;
128 }
129 tracked_objects_->Track(object);
130 return true;
131}
132
133bool CommandBufferVK::Track(const std::shared_ptr<const DeviceBuffer>& buffer) {
134 if (!IsValid()) {
135 return false;
136 }
137 tracked_objects_->Track(buffer);
138 return true;
139}
140
141bool CommandBufferVK::Track(
142 const std::shared_ptr<const TextureSourceVK>& texture) {
143 if (!IsValid()) {
144 return false;
145 }
146 tracked_objects_->Track(texture);
147 return true;
148}
149
150bool CommandBufferVK::Track(const std::shared_ptr<const Texture>& texture) {
151 if (!IsValid()) {
152 return false;
153 }
154 if (!texture) {
155 return true;
156 }
157 return Track(TextureVK::Cast(*texture).GetTextureSource());
158}
159
160fml::StatusOr<vk::DescriptorSet> CommandBufferVK::AllocateDescriptorSets(
161 const vk::DescriptorSetLayout& layout,
162 PipelineKey pipeline_key,
163 const ContextVK& context) {
164 if (!IsValid()) {
165 return fml::Status(fml::StatusCode::kUnknown, "command encoder invalid");
166 }
167
168 return tracked_objects_->GetDescriptorPool().AllocateDescriptorSets(
169 layout, pipeline_key, context);
170}
171
172void CommandBufferVK::PushDebugGroup(std::string_view label) const {
173 if (!HasValidationLayers()) {
174 return;
175 }
176 vk::DebugUtilsLabelEXT label_info;
177 label_info.pLabelName = label.data();
178 if (auto command_buffer = GetCommandBuffer()) {
179 command_buffer.beginDebugUtilsLabelEXT(label_info);
180 }
181}
182
183void CommandBufferVK::PopDebugGroup() const {
184 if (!HasValidationLayers()) {
185 return;
186 }
187 if (auto command_buffer = GetCommandBuffer()) {
188 command_buffer.endDebugUtilsLabelEXT();
189 }
190}
191
192void CommandBufferVK::InsertDebugMarker(std::string_view label) const {
193 if (!HasValidationLayers()) {
194 return;
195 }
196 vk::DebugUtilsLabelEXT label_info;
197 label_info.pLabelName = label.data();
198 if (auto command_buffer = GetCommandBuffer()) {
199 command_buffer.insertDebugUtilsLabelEXT(label_info);
200 }
201}
202
203DescriptorPoolVK& CommandBufferVK::GetDescriptorPool() const {
204 return tracked_objects_->GetDescriptorPool();
205}
206
207} // namespace impeller
A per-frame descriptor pool. Descriptors from this pool don't need to be freed individually....
uint32_t * target
FlutterDesktopBinaryReply callback
#define FML_UNREACHABLE()
Definition logging.h:128
FlTexture * texture
int64_t PipelineKey
Definition pipeline.h:22
bool HasValidationLayers()
Definition context_vk.cc:53
Definition ref_ptr.h:261
std::shared_ptr< ContextGLES > context
std::shared_ptr< CommandBuffer > command_buffer
#define VALIDATION_LOG
Definition validation.h:91