| Flutter Impeller |

pipeline_descriptor.cc
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 #include "impeller/renderer/pipeline_descriptor.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "impeller/base/comparable.h"
11 #include "impeller/core/formats.h"
12 #include "impeller/renderer/shader_function.h"
13 #include "impeller/renderer/shader_library.h"
14 #include "impeller/renderer/vertex_descriptor.h"
15
16 namespace impeller {
17
18 PipelineDescriptor::PipelineDescriptor() = default;
19
20 PipelineDescriptor::~PipelineDescriptor() = default;
21
22 // Comparable<PipelineDescriptor>
23 std::size_t PipelineDescriptor::GetHash() const {
24 auto seed = fml::HashCombine();
25 fml::HashCombineSeed(seed, label_);
26 fml::HashCombineSeed(seed, sample_count_);
27 for (const auto& entry : entrypoints_) {
28 fml::HashCombineSeed(seed, entry.first);
29 if (auto second = entry.second) {
30 fml::HashCombineSeed(seed, second->GetHash());
31 }
32 }
33 for (const auto& des : color_attachment_descriptors_) {
34 fml::HashCombineSeed(seed, des.first);
35 fml::HashCombineSeed(seed, des.second.Hash());
36 }
37 if (vertex_descriptor_) {
38 fml::HashCombineSeed(seed, vertex_descriptor_->GetHash());
39 }
40 fml::HashCombineSeed(seed, depth_pixel_format_);
41 fml::HashCombineSeed(seed, stencil_pixel_format_);
42 fml::HashCombineSeed(seed, depth_attachment_descriptor_);
43 fml::HashCombineSeed(seed, front_stencil_attachment_descriptor_);
44 fml::HashCombineSeed(seed, back_stencil_attachment_descriptor_);
45 fml::HashCombineSeed(seed, winding_order_);
46 fml::HashCombineSeed(seed, cull_mode_);
47 fml::HashCombineSeed(seed, primitive_type_);
48 fml::HashCombineSeed(seed, polygon_mode_);
49 return seed;
50 }
51
52 // Comparable<PipelineDescriptor>
53 bool PipelineDescriptor::IsEqual(const PipelineDescriptor& other) const {
54 return label_ == other.label_ && sample_count_ == other.sample_count_ &&
55 DeepCompareMap(entrypoints_, other.entrypoints_) &&
56 color_attachment_descriptors_ == other.color_attachment_descriptors_ &&
57 DeepComparePointer(vertex_descriptor_, other.vertex_descriptor_) &&
58 stencil_pixel_format_ == other.stencil_pixel_format_ &&
59 depth_pixel_format_ == other.depth_pixel_format_ &&
60 depth_attachment_descriptor_ == other.depth_attachment_descriptor_ &&
61 front_stencil_attachment_descriptor_ ==
62 other.front_stencil_attachment_descriptor_ &&
63 back_stencil_attachment_descriptor_ ==
64 other.back_stencil_attachment_descriptor_ &&
65 winding_order_ == other.winding_order_ &&
66 cull_mode_ == other.cull_mode_ &&
67 primitive_type_ == other.primitive_type_ &&
68 polygon_mode_ == other.polygon_mode_ &&
69 specialization_constants_ == other.specialization_constants_;
70 }
71
72 PipelineDescriptor& PipelineDescriptor::SetLabel(std::string_view label) {
73 label_ = std::string(label);
74 return *this;
75 }
76
77 PipelineDescriptor& PipelineDescriptor::SetSampleCount(SampleCount samples) {
78 sample_count_ = samples;
79 return *this;
80 }
81
82 PipelineDescriptor& PipelineDescriptor::AddStageEntrypoint(
83 std::shared_ptr<const ShaderFunction> function) {
84 if (!function) {
85 return *this;
86 }
87
88 if (function->GetStage() == ShaderStage::kUnknown) {
89 return *this;
90 }
91
92 entrypoints_[function->GetStage()] = std::move(function);
93
94 return *this;
95 }
96
97 PipelineDescriptor& PipelineDescriptor::SetVertexDescriptor(
98 std::shared_ptr<VertexDescriptor> vertex_descriptor) {
99 vertex_descriptor_ = std::move(vertex_descriptor);
100 return *this;
101 }
102
103 size_t PipelineDescriptor::GetMaxColorAttacmentBindIndex() const {
104 size_t max = 0;
105 for (const auto& color : color_attachment_descriptors_) {
106 max = std::max(color.first, max);
107 }
108 return max;
109 }
110
111 PipelineDescriptor& PipelineDescriptor::SetColorAttachmentDescriptor(
112 size_t index,
113 ColorAttachmentDescriptor desc) {
114 color_attachment_descriptors_[index] = desc;
115 return *this;
116 }
117
118 PipelineDescriptor& PipelineDescriptor::SetColorAttachmentDescriptors(
119 std::map<size_t /* index */, ColorAttachmentDescriptor> descriptors) {
120 color_attachment_descriptors_ = std::move(descriptors);
121 return *this;
122 }
123
124 const ColorAttachmentDescriptor*
125 PipelineDescriptor::GetColorAttachmentDescriptor(size_t index) const {
126 auto found = color_attachment_descriptors_.find(index);
127 return found == color_attachment_descriptors_.end() ? nullptr
128 : &found->second;
129 }
130
131 const ColorAttachmentDescriptor*
132 PipelineDescriptor::GetLegacyCompatibleColorAttachment() const {
133 // Legacy renderers may only render to a single color attachment at index 0u.
134 if (color_attachment_descriptors_.size() != 1u) {
135 return nullptr;
136 }
137 return GetColorAttachmentDescriptor(0u);
138 }
139
140 PipelineDescriptor& PipelineDescriptor::SetDepthPixelFormat(
141 PixelFormat format) {
142 depth_pixel_format_ = format;
143 return *this;
144 }
145
146 PipelineDescriptor& PipelineDescriptor::SetStencilPixelFormat(
147 PixelFormat format) {
148 stencil_pixel_format_ = format;
149 return *this;
150 }
151
152 PipelineDescriptor& PipelineDescriptor::SetDepthStencilAttachmentDescriptor(
153 std::optional<DepthAttachmentDescriptor> desc) {
154 depth_attachment_descriptor_ = desc;
155 return *this;
156 }
157
158 PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors(
159 std::optional<StencilAttachmentDescriptor> front_and_back) {
160 return SetStencilAttachmentDescriptors(front_and_back, front_and_back);
161 }
162
163 PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors(
164 std::optional<StencilAttachmentDescriptor> front,
165 std::optional<StencilAttachmentDescriptor> back) {
166 front_stencil_attachment_descriptor_ = front;
167 back_stencil_attachment_descriptor_ = back;
168 return *this;
169 }
170
171 void PipelineDescriptor::ClearStencilAttachments() {
172 back_stencil_attachment_descriptor_.reset();
173 front_stencil_attachment_descriptor_.reset();
174 SetStencilPixelFormat(impeller::PixelFormat::kUnknown);
175 }
176
177 void PipelineDescriptor::ClearDepthAttachment() {
178 depth_attachment_descriptor_.reset();
179 SetDepthPixelFormat(impeller::PixelFormat::kUnknown);
180 }
181
182 void PipelineDescriptor::ClearColorAttachment(size_t index) {
183 if (color_attachment_descriptors_.find(index) ==
184 color_attachment_descriptors_.end()) {
185 return;
186 }
187
188 color_attachment_descriptors_.erase(index);
189 }
190
191 void PipelineDescriptor::ResetAttachments() {
192 color_attachment_descriptors_.clear();
193 depth_attachment_descriptor_.reset();
194 front_stencil_attachment_descriptor_.reset();
195 back_stencil_attachment_descriptor_.reset();
196 }
197
198 PixelFormat PipelineDescriptor::GetStencilPixelFormat() const {
199 return stencil_pixel_format_;
200 }
201
202 std::optional<StencilAttachmentDescriptor>
203 PipelineDescriptor::GetFrontStencilAttachmentDescriptor() const {
204 return front_stencil_attachment_descriptor_;
205 }
206
207 std::optional<DepthAttachmentDescriptor>
208 PipelineDescriptor::GetDepthStencilAttachmentDescriptor() const {
209 return depth_attachment_descriptor_;
210 }
211
212 const std::map<size_t /* index */, ColorAttachmentDescriptor>&
213 PipelineDescriptor::GetColorAttachmentDescriptors() const {
214 return color_attachment_descriptors_;
215 }
216
217 const std::shared_ptr<VertexDescriptor>&
218 PipelineDescriptor::GetVertexDescriptor() const {
219 return vertex_descriptor_;
220 }
221
222 const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
223 PipelineDescriptor::GetStageEntrypoints() const {
224 return entrypoints_;
225 }
226
227 std::shared_ptr<const ShaderFunction> PipelineDescriptor::GetEntrypointForStage(
228 ShaderStage stage) const {
229 if (auto found = entrypoints_.find(stage); found != entrypoints_.end()) {
230 return found->second;
231 }
232 return nullptr;
233 }
234
235 std::string_view PipelineDescriptor::GetLabel() const {
236 return label_;
237 }
238
239 PixelFormat PipelineDescriptor::GetDepthPixelFormat() const {
240 return depth_pixel_format_;
241 }
242
243 std::optional<StencilAttachmentDescriptor>
244 PipelineDescriptor::GetBackStencilAttachmentDescriptor() const {
245 return back_stencil_attachment_descriptor_;
246 }
247
248 bool PipelineDescriptor::HasStencilAttachmentDescriptors() const {
249 return front_stencil_attachment_descriptor_.has_value() ||
250 back_stencil_attachment_descriptor_.has_value();
251 }
252
253 void PipelineDescriptor::SetCullMode(CullMode mode) {
254 cull_mode_ = mode;
255 }
256
257 CullMode PipelineDescriptor::GetCullMode() const {
258 return cull_mode_;
259 }
260
261 void PipelineDescriptor::SetWindingOrder(WindingOrder order) {
262 winding_order_ = order;
263 }
264
265 WindingOrder PipelineDescriptor::GetWindingOrder() const {
266 return winding_order_;
267 }
268
269 void PipelineDescriptor::SetPrimitiveType(PrimitiveType type) {
270 primitive_type_ = type;
271 }
272
273 PrimitiveType PipelineDescriptor::GetPrimitiveType() const {
274 return primitive_type_;
275 }
276
277 void PipelineDescriptor::SetPolygonMode(PolygonMode mode) {
278 polygon_mode_ = mode;
279 }
280
281 PolygonMode PipelineDescriptor::GetPolygonMode() const {
282 return polygon_mode_;
283 }
284
285 void PipelineDescriptor::SetSpecializationConstants(
286 std::vector<Scalar> values) {
287 specialization_constants_ = std::move(values);
288 }
289
290 const std::vector<Scalar>& PipelineDescriptor::GetSpecializationConstants()
291 const {
292 return specialization_constants_;
293 }
294
295 } // namespace impeller
type
GLenum type
Definition: blit_command_gles.cc:153
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller::PipelineDescriptor::SetStencilPixelFormat
PipelineDescriptor & SetStencilPixelFormat(PixelFormat format)
Definition: pipeline_descriptor.cc:146
impeller::PipelineDescriptor::SetDepthStencilAttachmentDescriptor
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
Definition: pipeline_descriptor.cc:152
impeller::PipelineDescriptor::~PipelineDescriptor
~PipelineDescriptor()
impeller::PipelineDescriptor::GetLabel
std::string_view GetLabel() const
Definition: pipeline_descriptor.cc:235
impeller::PipelineDescriptor::ClearStencilAttachments
void ClearStencilAttachments()
Definition: pipeline_descriptor.cc:171
impeller::PipelineDescriptor::GetHash
std::size_t GetHash() const override
Definition: pipeline_descriptor.cc:23
impeller::PipelineDescriptor::GetDepthPixelFormat
PixelFormat GetDepthPixelFormat() const
Definition: pipeline_descriptor.cc:239
impeller::PipelineDescriptor::PipelineDescriptor
PipelineDescriptor()
impeller::PipelineDescriptor::GetCullMode
CullMode GetCullMode() const
Definition: pipeline_descriptor.cc:257
impeller::PipelineDescriptor::SetCullMode
void SetCullMode(CullMode mode)
Definition: pipeline_descriptor.cc:253
impeller::PipelineDescriptor::ResetAttachments
void ResetAttachments()
Definition: pipeline_descriptor.cc:191
impeller::PipelineDescriptor::SetVertexDescriptor
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
Definition: pipeline_descriptor.cc:97
impeller::PipelineDescriptor::SetPolygonMode
void SetPolygonMode(PolygonMode mode)
Definition: pipeline_descriptor.cc:277
impeller::PipelineDescriptor::GetPrimitiveType
PrimitiveType GetPrimitiveType() const
Definition: pipeline_descriptor.cc:273
impeller::PipelineDescriptor::GetPolygonMode
PolygonMode GetPolygonMode() const
Definition: pipeline_descriptor.cc:281
impeller::PipelineDescriptor::GetMaxColorAttacmentBindIndex
size_t GetMaxColorAttacmentBindIndex() const
Definition: pipeline_descriptor.cc:103
impeller::PipelineDescriptor::GetDepthStencilAttachmentDescriptor
std::optional< DepthAttachmentDescriptor > GetDepthStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:208
impeller::PipelineDescriptor::AddStageEntrypoint
PipelineDescriptor & AddStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
Definition: pipeline_descriptor.cc:82
impeller::PipelineDescriptor::IsEqual
bool IsEqual(const PipelineDescriptor &other) const override
Definition: pipeline_descriptor.cc:53
impeller::PipelineDescriptor::GetStageEntrypoints
const std::map< ShaderStage, std::shared_ptr< const ShaderFunction > > & GetStageEntrypoints() const
Definition: pipeline_descriptor.cc:223
impeller::PipelineDescriptor::GetStencilPixelFormat
PixelFormat GetStencilPixelFormat() const
Definition: pipeline_descriptor.cc:198
impeller::PipelineDescriptor::GetLegacyCompatibleColorAttachment
const ColorAttachmentDescriptor * GetLegacyCompatibleColorAttachment() const
Definition: pipeline_descriptor.cc:132
impeller::PipelineDescriptor::SetLabel
PipelineDescriptor & SetLabel(std::string_view label)
Definition: pipeline_descriptor.cc:72
impeller::PipelineDescriptor::SetSpecializationConstants
void SetSpecializationConstants(std::vector< Scalar > values)
Definition: pipeline_descriptor.cc:285
impeller::PipelineDescriptor::GetSpecializationConstants
const std::vector< Scalar > & GetSpecializationConstants() const
Definition: pipeline_descriptor.cc:290
impeller::PipelineDescriptor::SetDepthPixelFormat
PipelineDescriptor & SetDepthPixelFormat(PixelFormat format)
Definition: pipeline_descriptor.cc:140
impeller::PipelineDescriptor::SetStencilAttachmentDescriptors
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
Definition: pipeline_descriptor.cc:158
impeller::PipelineDescriptor::GetColorAttachmentDescriptor
const ColorAttachmentDescriptor * GetColorAttachmentDescriptor(size_t index) const
Definition: pipeline_descriptor.cc:125
impeller::PipelineDescriptor::GetWindingOrder
WindingOrder GetWindingOrder() const
Definition: pipeline_descriptor.cc:265
impeller::PipelineDescriptor::SetColorAttachmentDescriptor
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
Definition: pipeline_descriptor.cc:111
impeller::PipelineDescriptor::SetSampleCount
PipelineDescriptor & SetSampleCount(SampleCount samples)
Definition: pipeline_descriptor.cc:77
impeller::PipelineDescriptor::SetPrimitiveType
void SetPrimitiveType(PrimitiveType type)
Definition: pipeline_descriptor.cc:269
impeller::PipelineDescriptor::GetEntrypointForStage
std::shared_ptr< const ShaderFunction > GetEntrypointForStage(ShaderStage stage) const
Definition: pipeline_descriptor.cc:227
impeller::PipelineDescriptor::GetColorAttachmentDescriptors
const std::map< size_t, ColorAttachmentDescriptor > & GetColorAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:213
impeller::PipelineDescriptor::GetBackStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetBackStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:244
impeller::PipelineDescriptor::GetVertexDescriptor
const std::shared_ptr< VertexDescriptor > & GetVertexDescriptor() const
Definition: pipeline_descriptor.cc:218
impeller::PipelineDescriptor::ClearDepthAttachment
void ClearDepthAttachment()
Definition: pipeline_descriptor.cc:177
impeller::PipelineDescriptor::GetFrontStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:203
impeller::PipelineDescriptor::SetWindingOrder
void SetWindingOrder(WindingOrder order)
Definition: pipeline_descriptor.cc:261
impeller::PipelineDescriptor::ClearColorAttachment
void ClearColorAttachment(size_t index)
Definition: pipeline_descriptor.cc:182
impeller::PipelineDescriptor::SetColorAttachmentDescriptors
PipelineDescriptor & SetColorAttachmentDescriptors(std::map< size_t, ColorAttachmentDescriptor > descriptors)
Definition: pipeline_descriptor.cc:118
impeller::PipelineDescriptor::HasStencilAttachmentDescriptors
bool HasStencilAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:248
comparable.h
formats.h
impeller
Definition: allocation.cc:12
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:355
impeller::CullMode
CullMode
Definition: formats.h:340
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::ShaderStage::kUnknown
@ kUnknown
impeller::WindingOrder
WindingOrder
Definition: formats.h:22
impeller::DeepComparePointer
bool DeepComparePointer(const std::shared_ptr< ComparableType > &lhs, const std::shared_ptr< ComparableType > &rhs)
Definition: comparable.h:57
impeller::PolygonMode
PolygonMode
Definition: formats.h:392
impeller::DeepCompareMap
bool DeepCompareMap(const std::map< Key, std::shared_ptr< ComparableType >> &lhs, const std::map< Key, std::shared_ptr< ComparableType >> &rhs)
Definition: comparable.h:74
impeller::SampleCount
SampleCount
Definition: formats.h:298
pipeline_descriptor.h
shader_function.h
shader_library.h
impeller::ColorAttachmentDescriptor
Describe the color attachment that will be used with this pipeline.
Definition: formats.h:522
vertex_descriptor.h