| 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
10 #include "impeller/renderer/backend/metal/pass_bindings_cache_mtl.h"
11 #include "impeller/renderer/render_pass.h"
12 #include "impeller/renderer/render_target.h"
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 bool IsValid() const override;
53
54 // |RenderPass|
55 void OnSetLabel(std::string_view label) override;
56
57 // |RenderPass|
58 bool OnEncodeCommands(const Context& context) const override;
59
60 // |RenderPass|
61 void SetPipeline(PipelineRef pipeline) override;
62
63 // |RenderPass|
64 void SetCommandLabel(std::string_view label) override;
65
66 // |RenderPass|
67 void SetStencilReference(uint32_t value) override;
68
69 // |RenderPass|
70 void SetBaseVertex(uint64_t value) override;
71
72 // |RenderPass|
73 void SetViewport(Viewport viewport) override;
74
75 // |RenderPass|
76 void SetScissor(IRect32 scissor) override;
77
78 // |RenderPass|
79 void SetElementCount(size_t count) override;
80
81 // |RenderPass|
82 void SetInstanceCount(size_t count) override;
83
84 // |RenderPass|
85 bool SetVertexBuffer(BufferView vertex_buffers[],
86 size_t vertex_buffer_count) override;
87
88 // |RenderPass|
89 bool SetIndexBuffer(BufferView index_buffer, IndexType index_type) override;
90
91 // |RenderPass|
92 fml::Status Draw() override;
93
94 // |RenderPass|
95 bool BindResource(ShaderStage stage,
96 DescriptorType type,
97 const ShaderUniformSlot& slot,
98 const ShaderMetadata* metadata,
99 BufferView view) override;
100
101 // |RenderPass|
102 bool BindResource(ShaderStage stage,
103 DescriptorType type,
104 const SampledImageSlot& slot,
105 const ShaderMetadata* metadata,
106 std::shared_ptr<const Texture> texture,
107 raw_ptr<const Sampler> sampler) override;
108
109 // |RenderPass|
110 bool BindDynamicResource(ShaderStage stage,
111 DescriptorType type,
112 const ShaderUniformSlot& slot,
113 std::unique_ptr<ShaderMetadata> metadata,
114 BufferView view) override;
115
116 // |RenderPass|
117 bool BindDynamicResource(ShaderStage stage,
118 DescriptorType type,
119 const SampledImageSlot& slot,
120 std::unique_ptr<ShaderMetadata> metadata,
121 std::shared_ptr<const Texture> texture,
122 raw_ptr<const Sampler> sampler) override;
123
124 RenderPassMTL(const RenderPassMTL&) = delete;
125
126 RenderPassMTL& operator=(const RenderPassMTL&) = delete;
127 };
128
129 } // namespace impeller
130
131 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_RENDER_PASS_MTL_H_
type
GLenum type
Definition: blit_command_gles.cc:153
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:30
impeller::RenderPassMTL
Definition: render_pass_mtl.h:16
impeller::RenderPassMTL::~RenderPassMTL
~RenderPassMTL() override
Definition: render_pass_mtl.mm:162
desc_
std::optional< PipelineDescriptor > desc_
Definition: content_context.cc:76
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller
Definition: allocation.cc:12
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
impeller::IRect32
TRect< int32_t > IRect32
Definition: rect.h:793
impeller::IndexType
IndexType
Definition: formats.h:343
impeller::PipelineRef
raw_ptr< Pipeline< PipelineDescriptor > > PipelineRef
A raw ptr to a pipeline object.
Definition: pipeline.h:88
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::DescriptorType
DescriptorType
Definition: shader_types.h:158
pass_bindings_cache_mtl.h
render_pass.h
render_target.h
impeller::BufferView
Definition: buffer_view.h:19
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