| Flutter Impeller |

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
5 #include "impeller/renderer/backend/vulkan/command_buffer_vk.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "fml/logging.h"
11 #include "impeller/renderer/backend/vulkan/blit_pass_vk.h"
12 #include "impeller/renderer/backend/vulkan/compute_pass_vk.h"
13 #include "impeller/renderer/backend/vulkan/context_vk.h"
14 #include "impeller/renderer/backend/vulkan/gpu_tracer_vk.h"
15 #include "impeller/renderer/backend/vulkan/render_pass_vk.h"
16 #include "impeller/renderer/backend/vulkan/texture_vk.h"
17 #include "impeller/renderer/command_buffer.h"
18 #include "impeller/renderer/render_target.h"
19
20 namespace impeller {
21
22 CommandBufferVK::CommandBufferVK(
23 std::weak_ptr<const Context> context,
24 std::weak_ptr<const DeviceHolderVK> device_holder,
25 std::shared_ptr<TrackedObjectsVK> tracked_objects)
26 : CommandBuffer(std::move(context)),
27 device_holder_(std::move(device_holder)),
28 tracked_objects_(std::move(tracked_objects)) {}
29
30 CommandBufferVK::~CommandBufferVK() = default;
31
32 void CommandBufferVK::SetLabel(std::string_view label) const {
33 #ifdef IMPELLER_DEBUG
34 auto context = context_.lock();
35 if (!context) {
36 return;
37 }
38 ContextVK::Cast(*context).SetDebugName(GetCommandBuffer(), label);
39 #endif // IMPELLER_DEBUG
40 }
41
42 bool CommandBufferVK::IsValid() const {
43 return true;
44 }
45
46 bool CommandBufferVK::OnSubmitCommands(CompletionCallback callback) {
47 FML_UNREACHABLE()
48 }
49
50 void CommandBufferVK::OnWaitUntilCompleted() {}
51
52 void CommandBufferVK::OnWaitUntilScheduled() {}
53
54 std::shared_ptr<RenderPass> CommandBufferVK::OnCreateRenderPass(
55 RenderTarget target) {
56 auto context = context_.lock();
57 if (!context) {
58 return nullptr;
59 }
60 auto pass =
61 std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
62 target, //
63 shared_from_this() //
64 ));
65 if (!pass->IsValid()) {
66 return nullptr;
67 }
68 return pass;
69 }
70
71 std::shared_ptr<BlitPass> CommandBufferVK::OnCreateBlitPass() {
72 if (!IsValid()) {
73 return nullptr;
74 }
75 auto context = context_.lock();
76 if (!context) {
77 return nullptr;
78 }
79 auto pass = std::shared_ptr<BlitPassVK>(new BlitPassVK(
80 shared_from_this(), ContextVK::Cast(*context).GetWorkarounds()));
81 if (!pass->IsValid()) {
82 return nullptr;
83 }
84 return pass;
85 }
86
87 std::shared_ptr<ComputePass> CommandBufferVK::OnCreateComputePass() {
88 if (!IsValid()) {
89 return nullptr;
90 }
91 auto context = context_.lock();
92 if (!context) {
93 return nullptr;
94 }
95 auto pass =
96 std::shared_ptr<ComputePassVK>(new ComputePassVK(context, //
97 shared_from_this() //
98 ));
99 if (!pass->IsValid()) {
100 return nullptr;
101 }
102 return pass;
103 }
104
105 bool CommandBufferVK::EndCommandBuffer() const {
106 InsertDebugMarker("QueueSubmit");
107
108 auto command_buffer = GetCommandBuffer();
109 tracked_objects_->GetGPUProbe().RecordCmdBufferEnd(command_buffer);
110
111 auto status = command_buffer.end();
112 if (status != vk::Result::eSuccess) {
113 VALIDATION_LOG << "Failed to end command buffer: " << vk::to_string(status);
114 return false;
115 }
116 return true;
117 }
118
119 vk::CommandBuffer CommandBufferVK::GetCommandBuffer() const {
120 if (tracked_objects_) {
121 return tracked_objects_->GetCommandBuffer();
122 }
123 return {};
124 }
125
126 bool CommandBufferVK::Track(const std::shared_ptr<SharedObjectVK>& object) {
127 if (!IsValid()) {
128 return false;
129 }
130 tracked_objects_->Track(object);
131 return true;
132 }
133
134 bool CommandBufferVK::Track(const std::shared_ptr<const DeviceBuffer>& buffer) {
135 if (!IsValid()) {
136 return false;
137 }
138 tracked_objects_->Track(buffer);
139 return true;
140 }
141
142 bool CommandBufferVK::Track(
143 const std::shared_ptr<const TextureSourceVK>& texture) {
144 if (!IsValid()) {
145 return false;
146 }
147 tracked_objects_->Track(texture);
148 return true;
149 }
150
151 bool CommandBufferVK::Track(const std::shared_ptr<const Texture>& texture) {
152 if (!IsValid()) {
153 return false;
154 }
155 if (!texture) {
156 return true;
157 }
158 return Track(TextureVK::Cast(*texture).GetTextureSource());
159 }
160
161 fml::StatusOr<vk::DescriptorSet> CommandBufferVK::AllocateDescriptorSets(
162 const vk::DescriptorSetLayout& layout,
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(layout,
169 context);
170 }
171
172 void 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
183 void CommandBufferVK::PopDebugGroup() const {
184 if (!HasValidationLayers()) {
185 return;
186 }
187 if (auto command_buffer = GetCommandBuffer()) {
188 command_buffer.endDebugUtilsLabelEXT();
189 }
190 }
191
192 void 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
203 DescriptorPoolVK& CommandBufferVK::GetDescriptorPool() const {
204 return tracked_objects_->GetDescriptorPool();
205 }
206
207 } // namespace impeller
blit_pass_vk.h
impeller::ContextVK
Definition: context_vk.h:66
impeller::DescriptorPoolVK
A per-frame descriptor pool. Descriptors from this pool don't need to be freed individually....
Definition: descriptor_pool_vk.h:27
command_buffer.h
command_buffer_vk.h
compute_pass_vk.h
context_vk.h
gpu_tracer_vk.h
impeller
Definition: allocation.cc:12
impeller::HasValidationLayers
bool HasValidationLayers()
Definition: context_vk.cc:53
std
Definition: comparable.h:95
render_pass_vk.h
render_target.h
texture_vk.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91