7#include <Metal/Metal.h>
10#include "flutter/fml/backtrace.h"
11#include "flutter/fml/closure.h"
12#include "flutter/fml/logging.h"
13#include "flutter/fml/trace_event.h"
29ComputePassMTL::ComputePassMTL(std::shared_ptr<const Context> context,
30 id<MTLCommandBuffer>
buffer)
31 : ComputePass(
std::move(context)), buffer_(
buffer) {
35 encoder_ = [buffer_ computeCommandEncoderWithDispatchType:
36 MTLDispatchType::MTLDispatchTypeConcurrent];
40 pass_bindings_cache_.SetEncoder(encoder_);
44ComputePassMTL::~ComputePassMTL() =
default;
46bool ComputePassMTL::IsValid()
const {
50void ComputePassMTL::OnSetLabel(
const std::string& label) {
55 [encoder_ setLabel:@(label.c_str())];
59void ComputePassMTL::SetCommandLabel(std::string_view label) {
61 [encoder_ pushDebugGroup:@(label.data())];
65void ComputePassMTL::SetPipeline(
66 const std::shared_ptr<Pipeline<ComputePipelineDescriptor>>& pipeline) {
67 pass_bindings_cache_.SetComputePipelineState(
68 ComputePipelineMTL::Cast(*pipeline).GetMTLComputePipelineState());
72void ComputePassMTL::AddBufferMemoryBarrier() {
73 [encoder_ memoryBarrierWithScope:MTLBarrierScopeBuffers];
77void ComputePassMTL::AddTextureMemoryBarrier() {
78 [encoder_ memoryBarrierWithScope:MTLBarrierScopeTextures];
84 const ShaderUniformSlot& slot,
85 const ShaderMetadata& metadata,
91 const std::shared_ptr<const DeviceBuffer>& device_buffer = view.buffer;
96 id<MTLBuffer>
buffer = DeviceBufferMTL::Cast(*device_buffer).GetMTLBuffer();
102 pass_bindings_cache_.SetBuffer(slot.ext_res_0, view.range.offset,
buffer);
107bool ComputePassMTL::BindResource(
110 const SampledImageSlot& slot,
111 const ShaderMetadata& metadata,
112 std::shared_ptr<const Texture>
texture,
113 const std::unique_ptr<const Sampler>& sampler) {
114 if (!sampler || !
texture->IsValid()) {
118 pass_bindings_cache_.SetTexture(slot.texture_index,
119 TextureMTL::Cast(*texture).GetMTLTexture());
120 pass_bindings_cache_.SetSampler(
121 slot.texture_index, SamplerMTL::Cast(*sampler).GetMTLSamplerState());
126 if (grid_size.IsEmpty()) {
128 "Invalid grid size for compute command.");
133 auto width = grid_size.width;
134 auto height = grid_size.height;
136 auto max_total_threads_per_threadgroup =
static_cast<int64_t
>(
137 pass_bindings_cache_.GetPipeline().maxTotalThreadsPerThreadgroup);
142 static_cast<int64_t
>(
143 std::ceil(
width * 1.0 / max_total_threads_per_threadgroup * 1.0)),
146 dispatchThreadgroups:MTLSizeMake(thread_groups, 1, 1)
147 threadsPerThreadgroup:MTLSizeMake(max_total_threads_per_threadgroup, 1,
150 while (
width *
height > max_total_threads_per_threadgroup) {
156 [encoder_ dispatchThreadgroups:
size threadsPerThreadgroup:
size];
161 [encoder_ popDebugGroup];
168bool ComputePassMTL::EncodeCommands()
const {
169 [encoder_ endEncoding];
static float max(float r, float g, float b)
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
SIN Vec< N, float > ceil(const Vec< N, float > &x)