forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand_buffer_vk.cc
More file actions
115 lines (100 loc) · 3.26 KB
/
command_buffer_vk.cc
File metadata and controls
115 lines (100 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/renderer/backend/vulkan/command_buffer_vk.h"
#include <memory>
#include <utility>
#include "flutter/fml/logging.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/vulkan/blit_pass_vk.h"
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h"
#include "impeller/renderer/backend/vulkan/compute_pass_vk.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/render_pass_vk.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/render_target.h"
namespace impeller {
CommandBufferVK::CommandBufferVK(
std::weak_ptr<const Context> context,
std::shared_ptr<CommandEncoderFactoryVK> encoder_factory)
: CommandBuffer(std::move(context)),
encoder_factory_(std::move(encoder_factory)) {}
CommandBufferVK::~CommandBufferVK() = default;
void CommandBufferVK::SetLabel(const std::string& label) const {
if (!encoder_) {
encoder_factory_->SetLabel(label);
} else {
auto context = context_.lock();
if (!context || !encoder_) {
return;
}
ContextVK::Cast(*context).SetDebugName(encoder_->GetCommandBuffer(), label);
}
}
bool CommandBufferVK::IsValid() const {
return true;
}
const std::shared_ptr<CommandEncoderVK>& CommandBufferVK::GetEncoder() {
if (!encoder_) {
encoder_ = encoder_factory_->Create();
}
return encoder_;
}
bool CommandBufferVK::OnSubmitCommands(CompletionCallback callback) {
if (!encoder_) {
encoder_ = encoder_factory_->Create();
}
if (!callback) {
return encoder_->Submit();
}
return encoder_->Submit([callback](bool submitted) {
callback(submitted ? CommandBuffer::Status::kCompleted
: CommandBuffer::Status::kError);
});
}
void CommandBufferVK::OnWaitUntilScheduled() {}
std::shared_ptr<RenderPass> CommandBufferVK::OnCreateRenderPass(
RenderTarget target) {
auto context = context_.lock();
if (!context) {
return nullptr;
}
auto pass =
std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
target, //
weak_from_this() //
));
if (!pass->IsValid()) {
return nullptr;
}
return pass;
}
std::shared_ptr<BlitPass> CommandBufferVK::OnCreateBlitPass() {
if (!IsValid()) {
return nullptr;
}
auto pass = std::shared_ptr<BlitPassVK>(new BlitPassVK(weak_from_this()));
if (!pass->IsValid()) {
return nullptr;
}
return pass;
}
std::shared_ptr<ComputePass> CommandBufferVK::OnCreateComputePass() {
if (!IsValid()) {
return nullptr;
}
auto context = context_.lock();
if (!context) {
return nullptr;
}
auto pass =
std::shared_ptr<ComputePassVK>(new ComputePassVK(context, //
weak_from_this() //
));
if (!pass->IsValid()) {
return nullptr;
}
return pass;
}
} // namespace impeller