| 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 "flutter/fml/macros.h"
11 #include "impeller/renderer/backend/metal/pass_bindings_cache_mtl.h"
12 #include "impeller/renderer/render_pass.h"
13 #include "impeller/renderer/render_target.h"
14
15 namespace impeller {
16
17 class RenderPassMTL final : public RenderPass {
18 public:
19 // |RenderPass|
20 ~RenderPassMTL() override;
21
22 private:
23 friend class CommandBufferMTL;
24
25 id<MTLCommandBuffer> buffer_ = nil;
26 id<MTLRenderCommandEncoder> encoder_ = nil;
27 MTLRenderPassDescriptor* desc_ = nil;
28 std::string label_;
29 bool is_metal_trace_active_ = false;
30 bool is_valid_ = false;
31 // Many parts of the codebase will start writing to a render pass but
32 // never submit them. This boolean is used to track if a submit happened
33 // so that in the dtor we can always ensure the render pass is finished.
34 mutable bool did_finish_encoding_ = false;
35
36 PassBindingsCacheMTL pass_bindings_;
37
38 // Per-command state
39 size_t instance_count_ = 1u;
40 size_t base_vertex_ = 0u;
41 size_t vertex_count_ = 0u;
42 bool has_valid_pipeline_ = false;
43 bool has_label_ = false;
44 BufferView index_buffer_ = {};
45 PrimitiveType primitive_type_ = {};
46 MTLIndexType index_type_ = {};
47
48 RenderPassMTL(std::shared_ptr<const Context> context,
49 const RenderTarget& target,
50 id<MTLCommandBuffer> buffer);
51
52 // |RenderPass|
53 void ReserveCommands(size_t command_count) override {}
54
55 // |RenderPass|
56 bool IsValid() const override;
57
58 // |RenderPass|
59 void OnSetLabel(std::string label) override;
60
61 // |RenderPass|
62 bool OnEncodeCommands(const Context& context) const override;
63
64 // |RenderPass|
65 void SetPipeline(
66 const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline) override;
67
68 // |RenderPass|
69 void SetCommandLabel(std::string_view label) override;
70
71 // |RenderPass|
72 void SetStencilReference(uint32_t value) override;
73
74 // |RenderPass|
75 void SetBaseVertex(uint64_t value) override;
76
77 // |RenderPass|
78 void SetViewport(Viewport viewport) override;
79
80 // |RenderPass|
81 void SetScissor(IRect scissor) override;
82
83 // |RenderPass|
84 void SetInstanceCount(size_t count) override;
85
86 // |RenderPass|
87 bool SetVertexBuffer(VertexBuffer buffer) override;
88
89 // |RenderPass|
90 fml::Status Draw() override;
91
92 // |RenderPass|
93 bool BindResource(ShaderStage stage,
94 DescriptorType type,
95 const ShaderUniformSlot& slot,
96 const ShaderMetadata& metadata,
97 BufferView view) override;
98
99 // |RenderPass|
100 bool BindResource(ShaderStage stage,
101 DescriptorType type,
102 const ShaderUniformSlot& slot,
103 const std::shared_ptr<const ShaderMetadata>& metadata,
104 BufferView view) override;
105
106 // |RenderPass|
107 bool BindResource(ShaderStage stage,
108 DescriptorType type,
109 const SampledImageSlot& slot,
110 const ShaderMetadata& metadata,
111 std::shared_ptr<const Texture> texture,
112 const std::unique_ptr<const Sampler>& sampler) override;
113
114 RenderPassMTL(const RenderPassMTL&) = delete;
115
116 RenderPassMTL& operator=(const RenderPassMTL&) = delete;
117 };
118
119 } // namespace impeller
120
121 #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:353
render_pass.h
impeller::RenderPassMTL::~RenderPassMTL
~RenderPassMTL() override
Definition: render_pass_mtl.mm:163
pass_bindings_cache_mtl.h
impeller::CommandBufferMTL
Definition: command_buffer_mtl.h:16
impeller::IRect
TRect< int64_t > IRect
Definition: rect.h:662
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
render_target.h
impeller::RenderPassMTL
Definition: render_pass_mtl.h:17
impeller
Definition: aiks_blur_unittests.cc:20
impeller::DescriptorType
DescriptorType
Definition: shader_types.h:153