Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Friends | List of all members
impeller::ComputePassMTL Class Referencefinal

#include <compute_pass_mtl.h>

Inheritance diagram for impeller::ComputePassMTL:
impeller::ComputePass impeller::ResourceBinder

Public Member Functions

 ~ComputePassMTL () override
 
- Public Member Functions inherited from impeller::ComputePass
virtual ~ComputePass ()
 
void SetLabel (const std::string &label)
 
const ContextGetContext () const
 
- Public Member Functions inherited from impeller::ResourceBinder
virtual ~ResourceBinder ()=default
 

Private Member Functions

bool IsValid () const override
 
fml::Status Compute (const ISize &grid_size) override
 
void SetCommandLabel (std::string_view label) override
 
void OnSetLabel (const std::string &label) override
 
void SetPipeline (const std::shared_ptr< Pipeline< ComputePipelineDescriptor > > &pipeline) override
 
bool BindResource (ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
 
bool BindResource (ShaderStage stage, DescriptorType type, const SampledImageSlot &slot, const ShaderMetadata &metadata, std::shared_ptr< const Texture > texture, const std::unique_ptr< const Sampler > &sampler) override
 
bool EncodeCommands () const override
 Encode the recorded commands to the underlying command buffer.
 
void AddBufferMemoryBarrier () override
 Ensures all previously encoded compute command's buffer writes are visible to any subsequent compute commands.
 
void AddTextureMemoryBarrier () override
 Ensures all previously encoded compute command's texture writes are visible to any subsequent compute commands.
 

Friends

class CommandBufferMTL
 

Additional Inherited Members

- Protected Member Functions inherited from impeller::ComputePass
 ComputePass (std::shared_ptr< const Context > context)
 
- Protected Attributes inherited from impeller::ComputePass
const std::shared_ptr< const Contextcontext_
 

Detailed Description

Definition at line 17 of file compute_pass_mtl.h.

Constructor & Destructor Documentation

◆ ~ComputePassMTL()

impeller::ComputePassMTL::~ComputePassMTL ( )
overridedefault

Member Function Documentation

◆ AddBufferMemoryBarrier()

void impeller::ComputePassMTL::AddBufferMemoryBarrier ( )
overrideprivatevirtual

Ensures all previously encoded compute command's buffer writes are visible to any subsequent compute commands.

On Vulkan, it does not matter if the compute command is in a different command buffer, only that it is executed later in queue order.

Implements impeller::ComputePass.

Definition at line 72 of file compute_pass_mtl.mm.

72 {
73 [encoder_ memoryBarrierWithScope:MTLBarrierScopeBuffers];
74}

◆ AddTextureMemoryBarrier()

void impeller::ComputePassMTL::AddTextureMemoryBarrier ( )
overrideprivatevirtual

Ensures all previously encoded compute command's texture writes are visible to any subsequent compute commands.

On Vulkan, it does not matter if the compute command is in a different command buffer, only that it is executed later in queue order.

Implements impeller::ComputePass.

Definition at line 77 of file compute_pass_mtl.mm.

77 {
78 [encoder_ memoryBarrierWithScope:MTLBarrierScopeTextures];
79}

◆ BindResource() [1/2]

bool impeller::ComputePassMTL::BindResource ( ShaderStage  stage,
DescriptorType  type,
const SampledImageSlot slot,
const ShaderMetadata metadata,
std::shared_ptr< const Texture texture,
const std::unique_ptr< const Sampler > &  sampler 
)
overrideprivatevirtual

Implements impeller::ResourceBinder.

Definition at line 107 of file compute_pass_mtl.mm.

113 {
114 if (!sampler || !texture->IsValid()) {
115 return false;
116 }
117
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());
122 return true;
123}
static TextureMTL & Cast(Texture &base)
id< MTLSamplerState > GetMTLSamplerState() const
id< MTLTexture > GetMTLTexture() const
FlTexture * texture
void SetSampler(uint64_t index, id< MTLSamplerState > sampler)
void SetTexture(uint64_t index, id< MTLTexture > texture)

◆ BindResource() [2/2]

bool impeller::ComputePassMTL::BindResource ( ShaderStage  stage,
DescriptorType  type,
const ShaderUniformSlot slot,
const ShaderMetadata metadata,
BufferView  view 
)
overrideprivatevirtual

Implements impeller::ResourceBinder.

Definition at line 82 of file compute_pass_mtl.mm.

86 {
87 if (!view.buffer) {
88 return false;
89 }
90
91 const std::shared_ptr<const DeviceBuffer>& device_buffer = view.buffer;
92 if (!device_buffer) {
93 return false;
94 }
95
96 id<MTLBuffer> buffer = DeviceBufferMTL::Cast(*device_buffer).GetMTLBuffer();
97 // The Metal call is a void return and we don't want to make it on nil.
98 if (!buffer) {
99 return false;
100 }
101
102 pass_bindings_cache_.SetBuffer(slot.ext_res_0, view.range.offset, buffer);
103 return true;
104}
id< MTLBuffer > GetMTLBuffer() const
static const uint8_t buffer[]
void SetBuffer(uint64_t index, uint64_t offset, id< MTLBuffer > buffer)

◆ Compute()

fml::Status impeller::ComputePassMTL::Compute ( const ISize grid_size)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 125 of file compute_pass_mtl.mm.

125 {
126 if (grid_size.IsEmpty()) {
128 "Invalid grid size for compute command.");
129 }
130 // TODO(dnfield): use feature detection to support non-uniform threadgroup
131 // sizes.
132 // https://github.com/flutter/flutter/issues/110619
133 auto width = grid_size.width;
134 auto height = grid_size.height;
135
136 auto max_total_threads_per_threadgroup = static_cast<int64_t>(
137 pass_bindings_cache_.GetPipeline().maxTotalThreadsPerThreadgroup);
138
139 // Special case for linear processing.
140 if (height == 1) {
141 int64_t thread_groups = std::max(
142 static_cast<int64_t>(
143 std::ceil(width * 1.0 / max_total_threads_per_threadgroup * 1.0)),
144 1LL);
145 [encoder_
146 dispatchThreadgroups:MTLSizeMake(thread_groups, 1, 1)
147 threadsPerThreadgroup:MTLSizeMake(max_total_threads_per_threadgroup, 1,
148 1)];
149 } else {
150 while (width * height > max_total_threads_per_threadgroup) {
151 width = std::max(1LL, width / 2);
152 height = std::max(1LL, height / 2);
153 }
154
155 auto size = MTLSizeMake(width, height, 1);
156 [encoder_ dispatchThreadgroups:size threadsPerThreadgroup:size];
157 }
158
159#ifdef IMPELLER_DEBUG
160 if (has_label_) {
161 [encoder_ popDebugGroup];
162 }
163 has_label_ = false;
164#endif // IMPELLER_DEBUG
165 return fml::Status();
166}
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
Definition switches.h:259
int32_t height
int32_t width
id< MTLComputePipelineState > GetPipeline() const

◆ EncodeCommands()

bool impeller::ComputePassMTL::EncodeCommands ( ) const
overrideprivatevirtual

Encode the recorded commands to the underlying command buffer.

Returns
If the commands were encoded to the underlying command buffer.

Implements impeller::ComputePass.

Definition at line 168 of file compute_pass_mtl.mm.

168 {
169 [encoder_ endEncoding];
170 return true;
171}

◆ IsValid()

bool impeller::ComputePassMTL::IsValid ( ) const
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 46 of file compute_pass_mtl.mm.

46 {
47 return is_valid_;
48}

◆ OnSetLabel()

void impeller::ComputePassMTL::OnSetLabel ( const std::string &  label)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 50 of file compute_pass_mtl.mm.

50 {
51#ifdef IMPELLER_DEBUG
52 if (label.empty()) {
53 return;
54 }
55 [encoder_ setLabel:@(label.c_str())];
56#endif // IMPELLER_DEBUG
57}

◆ SetCommandLabel()

void impeller::ComputePassMTL::SetCommandLabel ( std::string_view  label)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 59 of file compute_pass_mtl.mm.

59 {
60 has_label_ = true;
61 [encoder_ pushDebugGroup:@(label.data())];
62}

◆ SetPipeline()

void impeller::ComputePassMTL::SetPipeline ( const std::shared_ptr< Pipeline< ComputePipelineDescriptor > > &  pipeline)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 65 of file compute_pass_mtl.mm.

66 {
67 pass_bindings_cache_.SetComputePipelineState(
69}
id< MTLComputePipelineState > GetMTLComputePipelineState() const
void SetComputePipelineState(id< MTLComputePipelineState > pipeline)

Friends And Related Symbol Documentation

◆ CommandBufferMTL

friend class CommandBufferMTL
friend

Definition at line 23 of file compute_pass_mtl.h.


The documentation for this class was generated from the following files: