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