7#include "flutter/fml/closure.h"
8#include "flutter/fml/logging.h"
9#include "flutter/fml/make_copyable.h"
29 MTLRenderPassAttachmentDescriptor* attachment) {
34 if (needs_resolve && !
desc.resolve_texture) {
35 VALIDATION_LOG <<
"Resolve store action specified on attachment but no "
36 "resolve texture was specified.";
40 if (
desc.resolve_texture && !needs_resolve) {
41 VALIDATION_LOG <<
"A resolve texture was specified even though the store "
42 "action doesn't require it.";
46 if (!
desc.resolve_texture) {
50 attachment.resolveTexture =
57 MTLRenderPassAttachmentDescriptor* attachment) {
75 MTLRenderPassColorAttachmentDescriptor* attachment) {
85 MTLRenderPassDepthAttachmentDescriptor* attachment) {
89 attachment.clearDepth =
desc.clear_depth;
95 MTLRenderPassStencilAttachmentDescriptor* attachment) {
99 attachment.clearStencil =
desc.clear_stencil;
106 auto result = [MTLRenderPassDescriptor renderPassDescriptor];
108 const auto&
colors =
desc.GetColorAttachments();
113 VALIDATION_LOG <<
"Could not configure color attachment at index "
119 const auto& depth =
desc.GetDepthAttachment();
121 if (depth.has_value() &&
127 const auto& stencil =
desc.GetStencilAttachment();
129 if (stencil.has_value() &&
138RenderPassMTL::RenderPassMTL(std::shared_ptr<const Context> context,
140 id<MTLCommandBuffer>
buffer)
141 : RenderPass(
std::move(context),
target),
144 if (!buffer_ || !desc_ || !render_target_.IsValid()) {
147 encoder_ = [buffer_ renderCommandEncoderWithDescriptor:desc_];
153 is_metal_trace_active_ =
154 [[MTLCaptureManager sharedCaptureManager] isCapturing];
156 pass_bindings_.SetEncoder(encoder_);
157 pass_bindings_.SetViewport(
163RenderPassMTL::~RenderPassMTL() {
164 if (!did_finish_encoding_) {
165 [encoder_ endEncoding];
166 did_finish_encoding_ =
true;
170bool RenderPassMTL::IsValid()
const {
174void RenderPassMTL::OnSetLabel(std::string label) {
179 encoder_.label = @(std::string(label).c_str());
183bool RenderPassMTL::OnEncodeCommands(
const Context& context)
const {
184 did_finish_encoding_ =
true;
185 [encoder_ endEncoding];
197 auto device_buffer = view.
buffer;
198 if (!device_buffer) {
202 auto buffer = DeviceBufferMTL::Cast(*device_buffer).GetMTLBuffer();
214 const std::unique_ptr<const Sampler>& sampler,
216 if (!sampler || !
texture.IsValid()) {
220 if (
texture.NeedsMipmapGeneration()) {
224 <<
"Texture at binding index " << bind_index
225 <<
" has a mip count > 1, but the mipmap has not been generated.";
231 TextureMTL::Cast(
texture).GetMTLTexture()) &&
233 SamplerMTL::Cast(*sampler).GetMTLSamplerState());
237void RenderPassMTL::SetPipeline(
238 const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline) {
239 const PipelineDescriptor& pipeline_desc = pipeline->GetDescriptor();
240 primitive_type_ = pipeline_desc.GetPrimitiveType();
241 pass_bindings_.SetRenderPipelineState(
242 PipelineMTL::Cast(*pipeline).GetMTLRenderPipelineState());
243 pass_bindings_.SetDepthStencilState(
244 PipelineMTL::Cast(*pipeline).GetMTLDepthStencilState());
246 [encoder_ setFrontFacingWinding:pipeline_desc.GetWindingOrder() ==
247 WindingOrder::kClockwise
248 ? MTLWindingClockwise
249 : MTLWindingCounterClockwise];
250 [encoder_ setCullMode:
ToMTLCullMode(pipeline_desc.GetCullMode())];
252 pipeline_desc.GetPolygonMode())];
253 has_valid_pipeline_ =
true;
257void RenderPassMTL::SetCommandLabel(std::string_view label) {
259 if (is_metal_trace_active_) {
261 std::string label_copy(label);
262 [encoder_ pushDebugGroup:@(label_copy.c_str())];
268void RenderPassMTL::SetStencilReference(uint32_t
value) {
269 [encoder_ setStencilReferenceValue:
value];
273void RenderPassMTL::SetBaseVertex(uint64_t
value) {
274 base_vertex_ =
value;
278void RenderPassMTL::SetViewport(Viewport viewport) {
279 pass_bindings_.SetViewport(viewport);
283void RenderPassMTL::SetScissor(
IRect scissor) {
284 pass_bindings_.SetScissor(scissor);
288void RenderPassMTL::SetInstanceCount(
size_t count) {
289 instance_count_ =
count;
298 if (!
Bind(pass_bindings_, ShaderStage::kVertex,
299 VertexDescriptor::kReservedVertexBufferIndex,
304 vertex_count_ =
buffer.vertex_count;
307 index_buffer_ = std::move(
buffer.index_buffer);
314 if (!has_valid_pipeline_) {
318 if (!index_buffer_) {
319 if (instance_count_ != 1u) {
321 vertexStart:base_vertex_
322 vertexCount:vertex_count_
323 instanceCount:instance_count_
327 vertexStart:base_vertex_
328 vertexCount:vertex_count_];
331 id<MTLBuffer> mtl_index_buffer =
332 DeviceBufferMTL::Cast(*index_buffer_.buffer).GetMTLBuffer();
333 if (instance_count_ != 1u) {
335 indexCount:vertex_count_
336 indexType:index_type_
337 indexBuffer:mtl_index_buffer
338 indexBufferOffset:index_buffer_.range.offset
339 instanceCount:instance_count_
340 baseVertex:base_vertex_
344 indexCount:vertex_count_
345 indexType:index_type_
346 indexBuffer:mtl_index_buffer
347 indexBufferOffset:index_buffer_.range.offset];
353 [encoder_ popDebugGroup];
359 instance_count_ = 1u;
361 has_valid_pipeline_ =
false;
370 const ShaderUniformSlot& slot,
371 const ShaderMetadata& metadata,
373 return Bind(pass_bindings_, stage, slot.ext_res_0, view);
377bool RenderPassMTL::BindResource(
380 const ShaderUniformSlot& slot,
381 const std::shared_ptr<const ShaderMetadata>& metadata,
383 return Bind(pass_bindings_, stage, slot.ext_res_0, view);
387bool RenderPassMTL::BindResource(
390 const SampledImageSlot& slot,
391 const ShaderMetadata& metadata,
392 std::shared_ptr<const Texture>
texture,
393 const std::unique_ptr<const Sampler>& sampler) {
394 return Bind(pass_bindings_, stage, slot.texture_index, sampler, *
texture);
static TextureMTL & Cast(Texture &base)
id< MTLTexture > GetMTLTexture() const
static void Draw(SkCanvas *canvas, const SkRect &rect)
PODArray< SkColor > colors
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
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
static bool ConfigureColorAttachment(const ColorAttachment &desc, MTLRenderPassColorAttachmentDescriptor *attachment)
static bool ConfigureDepthAttachment(const DepthAttachment &desc, MTLRenderPassDepthAttachmentDescriptor *attachment)
constexpr MTLLoadAction ToMTLLoadAction(LoadAction action)
static bool Bind(PassBindingsCacheMTL &pass, ShaderStage stage, size_t bind_index, const std::unique_ptr< const Sampler > &sampler, const Texture &texture)
@ kStoreAndMultisampleResolve
static MTLRenderPassDescriptor * ToMTLRenderPassDescriptor(const RenderTarget &desc)
static bool ConfigureResolveTextureAttachment(const Attachment &desc, MTLRenderPassAttachmentDescriptor *attachment)
constexpr MTLPrimitiveType ToMTLPrimitiveType(PrimitiveType type)
static bool ConfigureStencilAttachment(const StencilAttachment &desc, MTLRenderPassStencilAttachmentDescriptor *attachment)
constexpr MTLTriangleFillMode ToMTLTriangleFillMode(PolygonMode mode)
constexpr MTLIndexType ToMTLIndexType(IndexType type)
constexpr MTLStoreAction ToMTLStoreAction(StoreAction action)
MTLClearColor ToMTLClearColor(const Color &color)
static bool ConfigureAttachment(const Attachment &desc, MTLRenderPassAttachmentDescriptor *attachment)
constexpr MTLCullMode ToMTLCullMode(CullMode mode)
std::shared_ptr< const DeviceBuffer > buffer
Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do add...
bool SetSampler(ShaderStage stage, uint64_t index, id< MTLSamplerState > sampler)
bool SetBuffer(ShaderStage stage, uint64_t index, uint64_t offset, id< MTLBuffer > buffer)
bool SetTexture(ShaderStage stage, uint64_t index, id< MTLTexture > texture)
static constexpr TRect MakeSize(const TSize< U > &size)