6 #include <Metal/Metal.h>
10 #include "flutter/fml/closure.h"
11 #include "flutter/fml/logging.h"
12 #include "flutter/fml/trace_event.h"
27 BlitPassMTL::BlitPassMTL(id<MTLCommandBuffer> buffer) : buffer_(buffer) {
36 bool BlitPassMTL::IsValid()
const {
40 void BlitPassMTL::OnSetLabel(std::string label) {
44 label_ = std::move(label);
47 bool BlitPassMTL::EncodeCommands(
48 const std::shared_ptr<Allocator>& transients_allocator)
const {
49 TRACE_EVENT0(
"impeller",
"BlitPassMTL::EncodeCommands");
54 auto blit_command_encoder = [buffer_ blitCommandEncoder];
56 if (!blit_command_encoder) {
60 if (!label_.empty()) {
61 [blit_command_encoder setLabel:@(label_.c_str())];
66 fml::ScopedCleanupClosure auto_end(
67 [blit_command_encoder]() { [blit_command_encoder endEncoding]; });
69 return EncodeCommands(blit_command_encoder);
72 bool BlitPassMTL::EncodeCommands(id<MTLBlitCommandEncoder> encoder)
const {
73 fml::closure pop_debug_marker = [encoder]() { [encoder popDebugGroup]; };
74 for (
const auto& command : commands_) {
75 fml::ScopedCleanupClosure auto_pop_debug_marker(pop_debug_marker);
76 auto label = command->GetLabel();
78 [encoder pushDebugGroup:@(label.c_str())];
80 auto_pop_debug_marker.Release();
83 if (!command->Encode(encoder)) {
91 bool BlitPassMTL::OnCopyTextureToTextureCommand(
92 std::shared_ptr<Texture> source,
93 std::shared_ptr<Texture> destination,
97 auto command = std::make_unique<BlitCopyTextureToTextureCommandMTL>();
98 command->label = label;
99 command->source = std::move(source);
100 command->destination = std::move(destination);
101 command->source_region = source_region;
102 command->destination_origin = destination_origin;
104 commands_.emplace_back(std::move(command));
109 bool BlitPassMTL::OnCopyTextureToBufferCommand(
110 std::shared_ptr<Texture> source,
111 std::shared_ptr<DeviceBuffer> destination,
113 size_t destination_offset,
115 auto command = std::make_unique<BlitCopyTextureToBufferCommandMTL>();
116 command->label = label;
117 command->source = std::move(source);
118 command->destination = std::move(destination);
119 command->source_region = source_region;
120 command->destination_offset = destination_offset;
122 commands_.emplace_back(std::move(command));
126 bool BlitPassMTL::OnCopyBufferToTextureCommand(
128 std::shared_ptr<Texture> destination,
129 IPoint destination_origin,
131 auto command = std::make_unique<BlitCopyBufferToTextureCommandMTL>();
132 command->label = label;
133 command->source = std::move(source);
134 command->destination = std::move(destination);
135 command->destination_origin = destination_origin;
137 commands_.emplace_back(std::move(command));
142 bool BlitPassMTL::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
144 auto command = std::make_unique<BlitGenerateMipmapCommandMTL>();
145 command->label = label;
146 command->texture = std::move(texture);
148 commands_.emplace_back(std::move(command));