Flutter Impeller
render_pass_mtl.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_RENDER_PASS_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_RENDER_PASS_MTL_H_
7 
8 #include <Metal/Metal.h>
9 
13 
14 namespace impeller {
15 
16 class RenderPassMTL final : public RenderPass {
17  public:
18  // |RenderPass|
19  ~RenderPassMTL() override;
20 
21  private:
22  friend class CommandBufferMTL;
23 
24  id<MTLCommandBuffer> buffer_ = nil;
25  id<MTLRenderCommandEncoder> encoder_ = nil;
26  MTLRenderPassDescriptor* desc_ = nil;
27  std::string label_;
28  bool is_metal_trace_active_ = false;
29  bool is_valid_ = false;
30  // Many parts of the codebase will start writing to a render pass but
31  // never submit them. This boolean is used to track if a submit happened
32  // so that in the dtor we can always ensure the render pass is finished.
33  mutable bool did_finish_encoding_ = false;
34 
35  PassBindingsCacheMTL pass_bindings_;
36 
37  // Per-command state
38  size_t instance_count_ = 1u;
39  size_t base_vertex_ = 0u;
40  size_t vertex_count_ = 0u;
41  bool has_valid_pipeline_ = false;
42  bool has_label_ = false;
43  BufferView index_buffer_ = {};
44  PrimitiveType primitive_type_ = {};
45  MTLIndexType index_type_ = {};
46 
47  RenderPassMTL(std::shared_ptr<const Context> context,
48  const RenderTarget& target,
49  id<MTLCommandBuffer> buffer);
50 
51  // |RenderPass|
52  void ReserveCommands(size_t command_count) override {}
53 
54  // |RenderPass|
55  bool IsValid() const override;
56 
57  // |RenderPass|
58  void OnSetLabel(std::string label) override;
59 
60  // |RenderPass|
61  bool OnEncodeCommands(const Context& context) const override;
62 
63  // |RenderPass|
64  void SetPipeline(
65  const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline) override;
66 
67  // |RenderPass|
68  void SetCommandLabel(std::string_view label) override;
69 
70  // |RenderPass|
71  void SetStencilReference(uint32_t value) override;
72 
73  // |RenderPass|
74  void SetBaseVertex(uint64_t value) override;
75 
76  // |RenderPass|
77  void SetViewport(Viewport viewport) override;
78 
79  // |RenderPass|
80  void SetScissor(IRect scissor) override;
81 
82  // |RenderPass|
83  void SetInstanceCount(size_t count) override;
84 
85  // |RenderPass|
86  bool SetVertexBuffer(VertexBuffer buffer) override;
87 
88  // |RenderPass|
89  fml::Status Draw() override;
90 
91  // |RenderPass|
92  bool BindResource(ShaderStage stage,
94  const ShaderUniformSlot& slot,
95  const ShaderMetadata& metadata,
96  BufferView view) override;
97 
98  // |RenderPass|
99  bool BindResource(ShaderStage stage,
101  const ShaderUniformSlot& slot,
102  const std::shared_ptr<const ShaderMetadata>& metadata,
103  BufferView view) override;
104 
105  // |RenderPass|
106  bool BindResource(ShaderStage stage,
108  const SampledImageSlot& slot,
109  const ShaderMetadata& metadata,
110  std::shared_ptr<const Texture> texture,
111  const std::unique_ptr<const Sampler>& sampler) override;
112 
113  RenderPassMTL(const RenderPassMTL&) = delete;
114 
115  RenderPassMTL& operator=(const RenderPassMTL&) = delete;
116 };
117 
118 } // namespace impeller
119 
120 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_RENDER_PASS_MTL_H_
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::PassBindingsCacheMTL
Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do add...
Definition: pass_bindings_cache_mtl.h:24
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
render_pass.h
impeller::RenderPassMTL::~RenderPassMTL
~RenderPassMTL() override
Definition: render_pass_mtl.mm:163
type
GLenum type
Definition: blit_command_gles.cc:126
pass_bindings_cache_mtl.h
impeller::CommandBufferMTL
Definition: command_buffer_mtl.h:15
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
impeller::BufferView
Definition: buffer_view.h:15
impeller::IRect
IRect64 IRect
Definition: rect.h:772
render_target.h
impeller::RenderPassMTL
Definition: render_pass_mtl.h:16
impeller
Definition: aiks_blend_unittests.cc:18
impeller::DescriptorType
DescriptorType
Definition: shader_types.h:153