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

#include <render_pass_mtl.h>

Inheritance diagram for impeller::RenderPassMTL:
impeller::RenderPass impeller::ResourceBinder

Public Member Functions

 ~RenderPassMTL () override
 
- Public Member Functions inherited from impeller::RenderPass
virtual ~RenderPass ()
 
const std::shared_ptr< const Context > & GetContext () const
 
const RenderTargetGetRenderTarget () const
 
ISize GetRenderTargetSize () const
 
const MatrixGetOrthographicTransform () const
 
void SetLabel (std::string label)
 
bool EncodeCommands () const
 Encode the recorded commands to the underlying command buffer.
 
virtual const std::vector< Command > & GetCommands () const
 Accessor for the current Commands.
 
SampleCount GetSampleCount () const
 The sample count of the attached render target.
 
PixelFormat GetRenderTargetPixelFormat () const
 The pixel format of the attached render target.
 
bool HasDepthAttachment () const
 Whether the render target has a depth attachment.
 
bool HasStencilAttachment () const
 Whether the render target has an stencil attachment.
 
- Public Member Functions inherited from impeller::ResourceBinder
virtual ~ResourceBinder ()=default
 

Private Member Functions

void ReserveCommands (size_t command_count) override
 Reserve [command_count] commands in the HAL command buffer.
 
bool IsValid () const override
 
void OnSetLabel (std::string label) override
 
bool OnEncodeCommands (const Context &context) const override
 
void SetPipeline (const std::shared_ptr< Pipeline< PipelineDescriptor > > &pipeline) override
 The pipeline to use for this command.
 
void SetCommandLabel (std::string_view label) override
 The debugging label to use for the command.
 
void SetStencilReference (uint32_t value) override
 
void SetBaseVertex (uint64_t value) override
 
void SetViewport (Viewport viewport) override
 
void SetScissor (IRect scissor) override
 
void SetInstanceCount (size_t count) override
 
bool SetVertexBuffer (VertexBuffer buffer) override
 Specify the vertex and index buffer to use for this command.
 
fml::Status Draw () override
 Record the currently pending command.
 
bool BindResource (ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
 
bool BindResource (ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const std::shared_ptr< 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
 

Friends

class CommandBufferMTL
 

Additional Inherited Members

- Protected Member Functions inherited from impeller::RenderPass
bool AddCommand (Command &&command)
 Record a command for subsequent encoding to the underlying command buffer. No work is encoded into the command buffer at this time.
 
 RenderPass (std::shared_ptr< const Context > context, const RenderTarget &target)
 
- Protected Attributes inherited from impeller::RenderPass
const std::shared_ptr< const Contextcontext_
 
const SampleCount sample_count_
 
const PixelFormat pixel_format_
 
const bool has_depth_attachment_
 
const bool has_stencil_attachment_
 
const ISize render_target_size_
 
const RenderTarget render_target_
 
std::vector< Commandcommands_
 
const Matrix orthographic_
 

Detailed Description

Definition at line 17 of file render_pass_mtl.h.

Constructor & Destructor Documentation

◆ ~RenderPassMTL()

impeller::RenderPassMTL::~RenderPassMTL ( )
override

Definition at line 163 of file render_pass_mtl.mm.

163 {
164 if (!did_finish_encoding_) {
165 [encoder_ endEncoding];
166 did_finish_encoding_ = true;
167 }
168}

Member Function Documentation

◆ BindResource() [1/3]

bool impeller::RenderPassMTL::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

Reimplemented from impeller::RenderPass.

Definition at line 387 of file render_pass_mtl.mm.

393 {
394 return Bind(pass_bindings_, stage, slot.texture_index, sampler, *texture);
395}
FlTexture * texture
static bool Bind(PassBindingsCacheMTL &pass, ShaderStage stage, size_t bind_index, const BufferView &view)

◆ BindResource() [2/3]

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

Reimplemented from impeller::RenderPass.

Definition at line 368 of file render_pass_mtl.mm.

372 {
373 return Bind(pass_bindings_, stage, slot.ext_res_0, view);
374}

◆ BindResource() [3/3]

bool impeller::RenderPassMTL::BindResource ( ShaderStage  stage,
DescriptorType  type,
const ShaderUniformSlot slot,
const std::shared_ptr< const ShaderMetadata > &  metadata,
BufferView  view 
)
overrideprivatevirtual

Reimplemented from impeller::RenderPass.

Definition at line 377 of file render_pass_mtl.mm.

382 {
383 return Bind(pass_bindings_, stage, slot.ext_res_0, view);
384}

◆ Draw()

fml::Status impeller::RenderPassMTL::Draw ( )
overrideprivatevirtual

Record the currently pending command.

Reimplemented from impeller::RenderPass.

Definition at line 313 of file render_pass_mtl.mm.

313 {
314 if (!has_valid_pipeline_) {
315 return fml::Status(fml::StatusCode::kCancelled, "Invalid pipeline.");
316 }
317
318 if (!index_buffer_) {
319 if (instance_count_ != 1u) {
320 [encoder_ drawPrimitives:ToMTLPrimitiveType(primitive_type_)
321 vertexStart:base_vertex_
322 vertexCount:vertex_count_
323 instanceCount:instance_count_
324 baseInstance:0u];
325 } else {
326 [encoder_ drawPrimitives:ToMTLPrimitiveType(primitive_type_)
327 vertexStart:base_vertex_
328 vertexCount:vertex_count_];
329 }
330 } else {
331 id<MTLBuffer> mtl_index_buffer =
332 DeviceBufferMTL::Cast(*index_buffer_.buffer).GetMTLBuffer();
333 if (instance_count_ != 1u) {
334 [encoder_ drawIndexedPrimitives:ToMTLPrimitiveType(primitive_type_)
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_
341 baseInstance:0u];
342 } else {
343 [encoder_ drawIndexedPrimitives:ToMTLPrimitiveType(primitive_type_)
344 indexCount:vertex_count_
345 indexType:index_type_
346 indexBuffer:mtl_index_buffer
347 indexBufferOffset:index_buffer_.range.offset];
348 }
349 }
350
351#ifdef IMPELLER_DEBUG
352 if (has_label_) {
353 [encoder_ popDebugGroup];
354 }
355#endif // IMPELLER_DEBUG
356
357 vertex_count_ = 0u;
358 base_vertex_ = 0u;
359 instance_count_ = 1u;
360 index_buffer_ = {};
361 has_valid_pipeline_ = false;
362 has_label_ = false;
363
364 return fml::Status();
365}
static DeviceBufferMTL & Cast(DeviceBuffer &base)
id< MTLBuffer > GetMTLBuffer() const
constexpr MTLPrimitiveType ToMTLPrimitiveType(PrimitiveType type)
std::shared_ptr< const DeviceBuffer > buffer
Definition buffer_view.h:16
size_t offset
Definition range.h:15

◆ IsValid()

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

Implements impeller::RenderPass.

Definition at line 170 of file render_pass_mtl.mm.

170 {
171 return is_valid_;
172}

◆ OnEncodeCommands()

bool impeller::RenderPassMTL::OnEncodeCommands ( const Context context) const
overrideprivatevirtual

Implements impeller::RenderPass.

Definition at line 183 of file render_pass_mtl.mm.

183 {
184 did_finish_encoding_ = true;
185 [encoder_ endEncoding];
186 return true;
187}

◆ OnSetLabel()

void impeller::RenderPassMTL::OnSetLabel ( std::string  label)
overrideprivatevirtual

Implements impeller::RenderPass.

Definition at line 174 of file render_pass_mtl.mm.

174 {
175#ifdef IMPELLER_DEBUG
176 if (label.empty()) {
177 return;
178 }
179 encoder_.label = @(std::string(label).c_str());
180#endif // IMPELLER_DEBUG
181}

◆ ReserveCommands()

void impeller::RenderPassMTL::ReserveCommands ( size_t  command_count)
inlineoverrideprivatevirtual

Reserve [command_count] commands in the HAL command buffer.

Note: this is not the native command buffer.

Reimplemented from impeller::RenderPass.

Definition at line 53 of file render_pass_mtl.h.

53{}

◆ SetBaseVertex()

void impeller::RenderPassMTL::SetBaseVertex ( uint64_t  value)
overrideprivatevirtual

Reimplemented from impeller::RenderPass.

Definition at line 273 of file render_pass_mtl.mm.

273 {
274 base_vertex_ = value;
275}
uint8_t value

◆ SetCommandLabel()

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

The debugging label to use for the command.

Reimplemented from impeller::RenderPass.

Definition at line 257 of file render_pass_mtl.mm.

257 {
258#ifdef IMPELLER_DEBUG
259 if (is_metal_trace_active_) {
260 has_label_ = true;
261 std::string label_copy(label);
262 [encoder_ pushDebugGroup:@(label_copy.c_str())];
263 }
264#endif // IMPELLER_DEBUG
265}

◆ SetInstanceCount()

void impeller::RenderPassMTL::SetInstanceCount ( size_t  count)
overrideprivatevirtual

The number of instances of the given set of vertices to render. Not all backends support rendering more than one instance at a time.

Warning
Setting this to more than one will limit the availability of backends to use with this command.

Reimplemented from impeller::RenderPass.

Definition at line 288 of file render_pass_mtl.mm.

288 {
289 instance_count_ = count;
290}
int count

◆ SetPipeline()

void impeller::RenderPassMTL::SetPipeline ( const std::shared_ptr< Pipeline< PipelineDescriptor > > &  pipeline)
overrideprivatevirtual

The pipeline to use for this command.

Reimplemented from impeller::RenderPass.

Definition at line 237 of file render_pass_mtl.mm.

238 {
239 const PipelineDescriptor& pipeline_desc = pipeline->GetDescriptor();
240 primitive_type_ = pipeline_desc.GetPrimitiveType();
241 pass_bindings_.SetRenderPipelineState(
243 pass_bindings_.SetDepthStencilState(
245
246 [encoder_ setFrontFacingWinding:pipeline_desc.GetWindingOrder() ==
248 ? MTLWindingClockwise
249 : MTLWindingCounterClockwise];
250 [encoder_ setCullMode:ToMTLCullMode(pipeline_desc.GetCullMode())];
251 [encoder_ setTriangleFillMode:ToMTLTriangleFillMode(
252 pipeline_desc.GetPolygonMode())];
253 has_valid_pipeline_ = true;
254}
id< MTLDepthStencilState > GetMTLDepthStencilState() const
id< MTLRenderPipelineState > GetMTLRenderPipelineState() const
constexpr MTLTriangleFillMode ToMTLTriangleFillMode(PolygonMode mode)
constexpr MTLCullMode ToMTLCullMode(CullMode mode)
void SetRenderPipelineState(id< MTLRenderPipelineState > pipeline)
void SetDepthStencilState(id< MTLDepthStencilState > depth_stencil)

◆ SetScissor()

void impeller::RenderPassMTL::SetScissor ( IRect  scissor)
overrideprivatevirtual

The scissor rect to use for clipping writes to the render target. The scissor rect must lie entirely within the render target. If unset, no scissor is applied.

Reimplemented from impeller::RenderPass.

Definition at line 283 of file render_pass_mtl.mm.

283 {
284 pass_bindings_.SetScissor(scissor);
285}
void SetScissor(const IRect &scissor)

◆ SetStencilReference()

void impeller::RenderPassMTL::SetStencilReference ( uint32_t  value)
overrideprivatevirtual

The reference value to use in stenciling operations. Stencil configuration is part of pipeline setup and can be read from the pipelines descriptor.

See also
Pipeline
PipelineDescriptor

Reimplemented from impeller::RenderPass.

Definition at line 268 of file render_pass_mtl.mm.

268 {
269 [encoder_ setStencilReferenceValue:value];
270}

◆ SetVertexBuffer()

bool impeller::RenderPassMTL::SetVertexBuffer ( VertexBuffer  buffer)
overrideprivatevirtual

Specify the vertex and index buffer to use for this command.

Parameters
[in]bufferThe vertex and index buffer definition. If possible, this value should be moved and not copied.
Returns
returns if the binding was updated.

Reimplemented from impeller::RenderPass.

Definition at line 293 of file render_pass_mtl.mm.

293 {
294 if (buffer.index_type == IndexType::kUnknown) {
295 return false;
296 }
297
298 if (!Bind(pass_bindings_, ShaderStage::kVertex,
300 buffer.vertex_buffer)) {
301 return false;
302 }
303
304 vertex_count_ = buffer.vertex_count;
305 if (buffer.index_type != IndexType::kNone) {
306 index_type_ = ToMTLIndexType(buffer.index_type);
307 index_buffer_ = std::move(buffer.index_buffer);
308 }
309 return true;
310}
static constexpr size_t kReservedVertexBufferIndex
static const uint8_t buffer[]
@ kNone
Does not use the index buffer.
constexpr MTLIndexType ToMTLIndexType(IndexType type)

◆ SetViewport()

void impeller::RenderPassMTL::SetViewport ( Viewport  viewport)
overrideprivatevirtual

The viewport coordinates that the rasterizer linearly maps normalized device coordinates to. If unset, the viewport is the size of the render target with a zero origin, znear=0, and zfar=1.

Reimplemented from impeller::RenderPass.

Definition at line 278 of file render_pass_mtl.mm.

278 {
279 pass_bindings_.SetViewport(viewport);
280}
void SetViewport(const Viewport &viewport)

Friends And Related Symbol Documentation

◆ CommandBufferMTL

friend class CommandBufferMTL
friend

Definition at line 23 of file render_pass_mtl.h.


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