7#include <Metal/Metal.h>
8#import <MetalPerformanceShaders/MetalPerformanceShaders.h>
31BlitPassMTL::BlitPassMTL(id<MTLCommandBuffer> buffer, id<MTLDevice>
device)
36 encoder_ = [buffer_ blitCommandEncoder];
38 is_metal_trace_active_ =
39 [[MTLCaptureManager sharedCaptureManager] isCapturing];
44BlitPassMTL::~BlitPassMTL() {
45 if (!did_finish_encoding_) {
46 [encoder_ endEncoding];
50bool BlitPassMTL::IsValid()
const {
54void BlitPassMTL::OnSetLabel(std::string_view label) {
58 [encoder_ setLabel:@(label.data())];
61bool BlitPassMTL::EncodeCommands()
const {
62 [encoder_ endEncoding];
63 did_finish_encoding_ =
true;
68bool BlitPassMTL::OnCopyTextureToTextureCommand(
69 std::shared_ptr<Texture> source,
70 std::shared_ptr<Texture> destination,
72 IPoint destination_origin,
73 std::string_view label) {
74 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
79 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
80 if (!destination_mtl) {
84 auto source_origin_mtl =
85 MTLOriginMake(source_region.GetX(), source_region.GetY(), 0);
86 auto source_size_mtl =
87 MTLSizeMake(source_region.GetWidth(), source_region.GetHeight(), 1);
88 auto destination_origin_mtl =
89 MTLOriginMake(destination_origin.x, destination_origin.y, 0);
92 if (is_metal_trace_active_) {
93 [encoder_ pushDebugGroup:@(label.data())];
96 [encoder_ copyFromTexture:source_mtl
99 sourceOrigin:source_origin_mtl
100 sourceSize:source_size_mtl
101 toTexture:destination_mtl
104 destinationOrigin:destination_origin_mtl];
107 if (is_metal_trace_active_) {
108 [encoder_ popDebugGroup];
115bool BlitPassMTL::ResizeTexture(
const std::shared_ptr<Texture>& source,
116 const std::shared_ptr<Texture>& destination) {
117 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
122 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
123 if (!destination_mtl) {
127 [encoder_ endEncoding];
128 auto filter = [[MPSImageBilinearScale alloc] initWithDevice:device_];
129 [filter encodeToCommandBuffer:buffer_
130 sourceTexture:source_mtl
131 destinationTexture:destination_mtl];
132 encoder_ = [buffer_ blitCommandEncoder];
137bool BlitPassMTL::OnCopyTextureToBufferCommand(
138 std::shared_ptr<Texture> source,
139 std::shared_ptr<DeviceBuffer> destination,
141 size_t destination_offset,
142 std::string_view label) {
143 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
148 auto destination_mtl = DeviceBufferMTL::Cast(*destination).GetMTLBuffer();
149 if (!destination_mtl) {
153 auto source_origin_mtl =
154 MTLOriginMake(source_region.GetX(), source_region.GetY(), 0);
155 auto source_size_mtl =
156 MTLSizeMake(source_region.GetWidth(), source_region.GetHeight(), 1);
158 auto destination_bytes_per_pixel =
160 auto destination_bytes_per_row =
161 source_size_mtl.width * destination_bytes_per_pixel;
162 auto destination_bytes_per_image =
163 source_size_mtl.height * destination_bytes_per_row;
166 if (is_metal_trace_active_) {
167 [encoder_ pushDebugGroup:@(label.data())];
170 [encoder_ copyFromTexture:source_mtl
173 sourceOrigin:source_origin_mtl
174 sourceSize:source_size_mtl
175 toBuffer:destination_mtl
176 destinationOffset:destination_offset
177 destinationBytesPerRow:destination_bytes_per_row
178 destinationBytesPerImage:destination_bytes_per_image];
181 if (is_metal_trace_active_) {
182 [encoder_ popDebugGroup];
188bool BlitPassMTL::OnCopyBufferToTextureCommand(
190 std::shared_ptr<Texture> destination,
191 IRect destination_region,
192 std::string_view label,
195 bool convert_to_read) {
196 auto source_mtl = DeviceBufferMTL::Cast(*source.GetBuffer()).GetMTLBuffer();
201 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
202 if (!destination_mtl) {
206 auto destination_origin_mtl =
207 MTLOriginMake(destination_region.GetX(), destination_region.GetY(), 0);
208 auto source_size_mtl = MTLSizeMake(destination_region.GetWidth(),
209 destination_region.GetHeight(), 1);
211 auto source_bytes_per_row =
213 destination_region.GetWidth());
216 if (is_metal_trace_active_) {
217 [encoder_ pushDebugGroup:@(label.data())];
221 copyFromBuffer:source_mtl
222 sourceOffset:source.GetRange().offset
223 sourceBytesPerRow:source_bytes_per_row
227 sourceSize:source_size_mtl
228 toTexture:destination_mtl
229 destinationSlice:slice
230 destinationLevel:mip_level
231 destinationOrigin:destination_origin_mtl];
234 if (is_metal_trace_active_) {
235 [encoder_ popDebugGroup];
242bool BlitPassMTL::OnGenerateMipmapCommand(std::shared_ptr<Texture>
texture,
243 std::string_view label) {
245 if (is_metal_trace_active_) {
246 [encoder_ pushDebugGroup:@(label.data())];
249 auto result = TextureMTL::Cast(*texture).GenerateMipmap(encoder_);
251 if (is_metal_trace_active_) {
252 [encoder_ popDebugGroup];
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 disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
constexpr size_t BytesPerRowForTextureWidth(PixelFormat format, int64_t width)
The number of bytes in a single row of texel blocks for a texture of the given width in format.