| Flutter Impeller |

pipeline_descriptor.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_PIPELINE_DESCRIPTOR_H_
6 #define FLUTTER_IMPELLER_RENDERER_PIPELINE_DESCRIPTOR_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11
12 #include "impeller/base/comparable.h"
13 #include "impeller/core/formats.h"
14 #include "impeller/core/shader_types.h"
15 #include "impeller/tessellator/tessellator.h"
16
17 namespace impeller {
18
19 class ShaderFunction;
20 class VertexDescriptor;
21 template <typename T>
22 class Pipeline;
23
24 enum class UseSubpassInput {
25 kYes,
26 kNo,
27 };
28
29 class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
30 public:
31 PipelineDescriptor();
32
33 ~PipelineDescriptor();
34
35 PipelineDescriptor& SetLabel(std::string label);
36
37 const std::string& GetLabel() const;
38
39 PipelineDescriptor& SetSampleCount(SampleCount samples);
40
41 SampleCount GetSampleCount() const { return sample_count_; }
42
43 PipelineDescriptor& AddStageEntrypoint(
44 std::shared_ptr<const ShaderFunction> function);
45
46 const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
47 GetStageEntrypoints() const;
48
49 std::shared_ptr<const ShaderFunction> GetEntrypointForStage(
50 ShaderStage stage) const;
51
52 PipelineDescriptor& SetVertexDescriptor(
53 std::shared_ptr<VertexDescriptor> vertex_descriptor);
54
55 const std::shared_ptr<VertexDescriptor>& GetVertexDescriptor() const;
56
57 size_t GetMaxColorAttacmentBindIndex() const;
58
59 PipelineDescriptor& SetColorAttachmentDescriptor(
60 size_t index,
61 ColorAttachmentDescriptor desc);
62
63 PipelineDescriptor& SetColorAttachmentDescriptors(
64 std::map<size_t /* index */, ColorAttachmentDescriptor> descriptors);
65
66 const ColorAttachmentDescriptor* GetColorAttachmentDescriptor(
67 size_t index) const;
68
69 const std::map<size_t /* index */, ColorAttachmentDescriptor>&
70 GetColorAttachmentDescriptors() const;
71
72 const ColorAttachmentDescriptor* GetLegacyCompatibleColorAttachment() const;
73
74 PipelineDescriptor& SetDepthStencilAttachmentDescriptor(
75 std::optional<DepthAttachmentDescriptor> desc);
76
77 std::optional<DepthAttachmentDescriptor> GetDepthStencilAttachmentDescriptor()
78 const;
79
80 PipelineDescriptor& SetStencilAttachmentDescriptors(
81 std::optional<StencilAttachmentDescriptor> front_and_back);
82
83 PipelineDescriptor& SetStencilAttachmentDescriptors(
84 std::optional<StencilAttachmentDescriptor> front,
85 std::optional<StencilAttachmentDescriptor> back);
86
87 void ClearStencilAttachments();
88
89 void ClearDepthAttachment();
90
91 void ClearColorAttachment(size_t index);
92
93 std::optional<StencilAttachmentDescriptor>
94 GetFrontStencilAttachmentDescriptor() const;
95
96 std::optional<StencilAttachmentDescriptor>
97 GetBackStencilAttachmentDescriptor() const;
98
99 bool HasStencilAttachmentDescriptors() const;
100
101 PipelineDescriptor& SetDepthPixelFormat(PixelFormat format);
102
103 PixelFormat GetDepthPixelFormat() const;
104
105 PipelineDescriptor& SetStencilPixelFormat(PixelFormat format);
106
107 PixelFormat GetStencilPixelFormat() const;
108
109 // Comparable<PipelineDescriptor>
110 std::size_t GetHash() const override;
111
112 // Comparable<PipelineDescriptor>
113 bool IsEqual(const PipelineDescriptor& other) const override;
114
115 void ResetAttachments();
116
117 void SetCullMode(CullMode mode);
118
119 CullMode GetCullMode() const;
120
121 void SetWindingOrder(WindingOrder order);
122
123 WindingOrder GetWindingOrder() const;
124
125 void SetPrimitiveType(PrimitiveType type);
126
127 PrimitiveType GetPrimitiveType() const;
128
129 void SetPolygonMode(PolygonMode mode);
130
131 PolygonMode GetPolygonMode() const;
132
133 void SetSpecializationConstants(std::vector<Scalar> values);
134
135 const std::vector<Scalar>& GetSpecializationConstants() const;
136
137 void SetUseSubpassInput(UseSubpassInput value) { use_subpass_input_ = value; }
138
139 bool UsesSubpassInput() const {
140 switch (use_subpass_input_) {
141 case UseSubpassInput::kYes:
142 return true;
143 case UseSubpassInput::kNo:
144 return false;
145 }
146 }
147
148 private:
149 std::string label_;
150 SampleCount sample_count_ = SampleCount::kCount1;
151 WindingOrder winding_order_ = WindingOrder::kClockwise;
152 CullMode cull_mode_ = CullMode::kNone;
153 std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
154 std::map<size_t /* index */, ColorAttachmentDescriptor>
155 color_attachment_descriptors_;
156 std::shared_ptr<VertexDescriptor> vertex_descriptor_;
157 PixelFormat depth_pixel_format_ = PixelFormat::kUnknown;
158 PixelFormat stencil_pixel_format_ = PixelFormat::kUnknown;
159 std::optional<DepthAttachmentDescriptor> depth_attachment_descriptor_;
160 std::optional<StencilAttachmentDescriptor>
161 front_stencil_attachment_descriptor_;
162 std::optional<StencilAttachmentDescriptor>
163 back_stencil_attachment_descriptor_;
164 PrimitiveType primitive_type_ = PrimitiveType::kTriangle;
165 PolygonMode polygon_mode_ = PolygonMode::kFill;
166 UseSubpassInput use_subpass_input_ = UseSubpassInput::kNo;
167 std::vector<Scalar> specialization_constants_;
168 };
169
170 } // namespace impeller
171
172 #endif // FLUTTER_IMPELLER_RENDERER_PIPELINE_DESCRIPTOR_H_
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:29
impeller::PipelineDescriptor::GetSpecializationConstants
const std::vector< Scalar > & GetSpecializationConstants() const
Definition: pipeline_descriptor.cc:291
impeller::PipelineDescriptor::GetBackStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetBackStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:245
impeller::PipelineDescriptor::SetPolygonMode
void SetPolygonMode(PolygonMode mode)
Definition: pipeline_descriptor.cc:278
impeller::PolygonMode
PolygonMode
Definition: formats.h:381
impeller::PipelineDescriptor::GetCullMode
CullMode GetCullMode() const
Definition: pipeline_descriptor.cc:258
impeller::PipelineDescriptor::SetStencilAttachmentDescriptors
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
Definition: pipeline_descriptor.cc:159
impeller::PipelineDescriptor::GetLabel
const std::string & GetLabel() const
Definition: pipeline_descriptor.cc:236
impeller::PipelineDescriptor::SetColorAttachmentDescriptor
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
Definition: pipeline_descriptor.cc:112
impeller::PipelineDescriptor::SetStencilPixelFormat
PipelineDescriptor & SetStencilPixelFormat(PixelFormat format)
Definition: pipeline_descriptor.cc:147
impeller::PipelineDescriptor::GetColorAttachmentDescriptor
const ColorAttachmentDescriptor * GetColorAttachmentDescriptor(size_t index) const
Definition: pipeline_descriptor.cc:126
impeller::PipelineDescriptor::SetPrimitiveType
void SetPrimitiveType(PrimitiveType type)
Definition: pipeline_descriptor.cc:270
formats.h
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::PipelineDescriptor::GetSampleCount
SampleCount GetSampleCount() const
Definition: pipeline_descriptor.h:41
impeller::PipelineDescriptor::GetVertexDescriptor
const std::shared_ptr< VertexDescriptor > & GetVertexDescriptor() const
Definition: pipeline_descriptor.cc:219
impeller::UseSubpassInput
UseSubpassInput
Definition: pipeline_descriptor.h:24
impeller::WindingOrder::kClockwise
@ kClockwise
impeller::PipelineDescriptor::GetEntrypointForStage
std::shared_ptr< const ShaderFunction > GetEntrypointForStage(ShaderStage stage) const
Definition: pipeline_descriptor.cc:228
impeller::WindingOrder
WindingOrder
Definition: tessellator.h:27
impeller::PolygonMode::kFill
@ kFill
impeller::PipelineDescriptor::SetCullMode
void SetCullMode(CullMode mode)
Definition: pipeline_descriptor.cc:254
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
tessellator.h
impeller::PipelineDescriptor::SetUseSubpassInput
void SetUseSubpassInput(UseSubpassInput value)
Definition: pipeline_descriptor.h:137
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::CullMode
CullMode
Definition: formats.h:335
impeller::PipelineDescriptor::SetColorAttachmentDescriptors
PipelineDescriptor & SetColorAttachmentDescriptors(std::map< size_t, ColorAttachmentDescriptor > descriptors)
Definition: pipeline_descriptor.cc:119
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:350
impeller::CullMode::kNone
@ kNone
impeller::PipelineDescriptor::HasStencilAttachmentDescriptors
bool HasStencilAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:249
impeller::PipelineDescriptor::GetMaxColorAttacmentBindIndex
size_t GetMaxColorAttacmentBindIndex() const
Definition: pipeline_descriptor.cc:104
impeller::PipelineDescriptor::GetPrimitiveType
PrimitiveType GetPrimitiveType() const
Definition: pipeline_descriptor.cc:274
impeller::PipelineDescriptor::GetWindingOrder
WindingOrder GetWindingOrder() const
Definition: pipeline_descriptor.cc:266
impeller::PipelineDescriptor::GetStencilPixelFormat
PixelFormat GetStencilPixelFormat() const
Definition: pipeline_descriptor.cc:199
impeller::PipelineDescriptor::GetPolygonMode
PolygonMode GetPolygonMode() const
Definition: pipeline_descriptor.cc:282
impeller::PipelineDescriptor::ClearColorAttachment
void ClearColorAttachment(size_t index)
Definition: pipeline_descriptor.cc:183
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::PipelineDescriptor::SetSampleCount
PipelineDescriptor & SetSampleCount(SampleCount samples)
Definition: pipeline_descriptor.cc:78
impeller::PipelineDescriptor::AddStageEntrypoint
PipelineDescriptor & AddStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
Definition: pipeline_descriptor.cc:83
impeller::Comparable
Definition: comparable.h:29
impeller::PipelineDescriptor::GetFrontStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:204
impeller::PipelineDescriptor::ClearDepthAttachment
void ClearDepthAttachment()
Definition: pipeline_descriptor.cc:178
impeller::PipelineDescriptor::~PipelineDescriptor
~PipelineDescriptor()
impeller::PipelineDescriptor::GetDepthPixelFormat
PixelFormat GetDepthPixelFormat() const
Definition: pipeline_descriptor.cc:240
comparable.h
impeller::PipelineDescriptor::PipelineDescriptor
PipelineDescriptor()
impeller::PipelineDescriptor::GetColorAttachmentDescriptors
const std::map< size_t, ColorAttachmentDescriptor > & GetColorAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:214
impeller::SampleCount
SampleCount
Definition: formats.h:290
impeller::PipelineDescriptor::ResetAttachments
void ResetAttachments()
Definition: pipeline_descriptor.cc:192
impeller::PipelineDescriptor::SetDepthPixelFormat
PipelineDescriptor & SetDepthPixelFormat(PixelFormat format)
Definition: pipeline_descriptor.cc:141
impeller::PipelineDescriptor::IsEqual
bool IsEqual(const PipelineDescriptor &other) const override
Definition: pipeline_descriptor.cc:53
impeller::PipelineDescriptor::GetDepthStencilAttachmentDescriptor
std::optional< DepthAttachmentDescriptor > GetDepthStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:209
impeller::PipelineDescriptor::GetStageEntrypoints
const std::map< ShaderStage, std::shared_ptr< const ShaderFunction > > & GetStageEntrypoints() const
Definition: pipeline_descriptor.cc:224
impeller::PipelineDescriptor::GetHash
std::size_t GetHash() const override
Definition: pipeline_descriptor.cc:22
impeller::SampleCount::kCount1
@ kCount1
impeller::PipelineDescriptor::SetDepthStencilAttachmentDescriptor
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
Definition: pipeline_descriptor.cc:153
impeller::UseSubpassInput::kYes
@ kYes
impeller::UseSubpassInput::kNo
@ kNo
impeller::PipelineDescriptor::SetSpecializationConstants
void SetSpecializationConstants(std::vector< Scalar > values)
Definition: pipeline_descriptor.cc:286
impeller::PipelineDescriptor::SetLabel
PipelineDescriptor & SetLabel(std::string label)
Definition: pipeline_descriptor.cc:73
impeller::PipelineDescriptor::SetWindingOrder
void SetWindingOrder(WindingOrder order)
Definition: pipeline_descriptor.cc:262
impeller::PipelineDescriptor::GetLegacyCompatibleColorAttachment
const ColorAttachmentDescriptor * GetLegacyCompatibleColorAttachment() const
Definition: pipeline_descriptor.cc:133
shader_types.h
impeller::PipelineDescriptor::ClearStencilAttachments
void ClearStencilAttachments()
Definition: pipeline_descriptor.cc:172
impeller::PipelineDescriptor::UsesSubpassInput
bool UsesSubpassInput() const
Definition: pipeline_descriptor.h:139
impeller
Definition: aiks_context.cc:10
impeller::PipelineDescriptor::SetVertexDescriptor
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
Definition: pipeline_descriptor.cc:98
impeller::ColorAttachmentDescriptor
Describe the color attachment that will be used with this pipeline.
Definition: formats.h:494