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 
6 
7 #include <utility>
8 
10 #include "impeller/core/formats.h"
14 
15 namespace impeller {
16 
18 
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  fml::HashCombineSeed(seed, use_subpass_input_);
49  return seed;
50 }
51 
52 // Comparable<PipelineDescriptor>
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  use_subpass_input_ == other.use_subpass_input_;
71 }
72 
74  label_ = std::move(label);
75  return *this;
76 }
77 
79  sample_count_ = samples;
80  return *this;
81 }
82 
84  std::shared_ptr<const ShaderFunction> function) {
85  if (!function) {
86  return *this;
87  }
88 
89  if (function->GetStage() == ShaderStage::kUnknown) {
90  return *this;
91  }
92 
93  entrypoints_[function->GetStage()] = std::move(function);
94 
95  return *this;
96 }
97 
99  std::shared_ptr<VertexDescriptor> vertex_descriptor) {
100  vertex_descriptor_ = std::move(vertex_descriptor);
101  return *this;
102 }
103 
105  size_t max = 0;
106  for (const auto& color : color_attachment_descriptors_) {
107  max = std::max(color.first, max);
108  }
109  return max;
110 }
111 
113  size_t index,
115  color_attachment_descriptors_[index] = desc;
116  return *this;
117 }
118 
120  std::map<size_t /* index */, ColorAttachmentDescriptor> descriptors) {
121  color_attachment_descriptors_ = std::move(descriptors);
122  return *this;
123 }
124 
127  auto found = color_attachment_descriptors_.find(index);
128  return found == color_attachment_descriptors_.end() ? nullptr
129  : &found->second;
130 }
131 
134  // Legacy renderers may only render to a single color attachment at index 0u.
135  if (color_attachment_descriptors_.size() != 1u) {
136  return nullptr;
137  }
138  return GetColorAttachmentDescriptor(0u);
139 }
140 
142  PixelFormat format) {
143  depth_pixel_format_ = format;
144  return *this;
145 }
146 
148  PixelFormat format) {
149  stencil_pixel_format_ = format;
150  return *this;
151 }
152 
154  std::optional<DepthAttachmentDescriptor> desc) {
155  depth_attachment_descriptor_ = desc;
156  return *this;
157 }
158 
160  std::optional<StencilAttachmentDescriptor> front_and_back) {
161  return SetStencilAttachmentDescriptors(front_and_back, front_and_back);
162 }
163 
165  std::optional<StencilAttachmentDescriptor> front,
166  std::optional<StencilAttachmentDescriptor> back) {
167  front_stencil_attachment_descriptor_ = front;
168  back_stencil_attachment_descriptor_ = back;
169  return *this;
170 }
171 
173  back_stencil_attachment_descriptor_.reset();
174  front_stencil_attachment_descriptor_.reset();
176 }
177 
179  depth_attachment_descriptor_.reset();
181 }
182 
184  if (color_attachment_descriptors_.find(index) ==
185  color_attachment_descriptors_.end()) {
186  return;
187  }
188 
189  color_attachment_descriptors_.erase(index);
190 }
191 
193  color_attachment_descriptors_.clear();
194  depth_attachment_descriptor_.reset();
195  front_stencil_attachment_descriptor_.reset();
196  back_stencil_attachment_descriptor_.reset();
197 }
198 
200  return stencil_pixel_format_;
201 }
202 
203 std::optional<StencilAttachmentDescriptor>
205  return front_stencil_attachment_descriptor_;
206 }
207 
208 std::optional<DepthAttachmentDescriptor>
210  return depth_attachment_descriptor_;
211 }
212 
213 const std::map<size_t /* index */, ColorAttachmentDescriptor>&
215  return color_attachment_descriptors_;
216 }
217 
218 const std::shared_ptr<VertexDescriptor>&
220  return vertex_descriptor_;
221 }
222 
223 const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
225  return entrypoints_;
226 }
227 
228 std::shared_ptr<const ShaderFunction> PipelineDescriptor::GetEntrypointForStage(
229  ShaderStage stage) const {
230  if (auto found = entrypoints_.find(stage); found != entrypoints_.end()) {
231  return found->second;
232  }
233  return nullptr;
234 }
235 
236 const std::string& PipelineDescriptor::GetLabel() const {
237  return label_;
238 }
239 
241  return depth_pixel_format_;
242 }
243 
244 std::optional<StencilAttachmentDescriptor>
246  return back_stencil_attachment_descriptor_;
247 }
248 
250  return front_stencil_attachment_descriptor_.has_value() ||
251  back_stencil_attachment_descriptor_.has_value();
252 }
253 
255  cull_mode_ = mode;
256 }
257 
259  return cull_mode_;
260 }
261 
263  winding_order_ = order;
264 }
265 
267  return winding_order_;
268 }
269 
271  primitive_type_ = type;
272 }
273 
275  return primitive_type_;
276 }
277 
279  polygon_mode_ = mode;
280 }
281 
283  return polygon_mode_;
284 }
285 
287  std::vector<Scalar> values) {
288  specialization_constants_ = std::move(values);
289 }
290 
292  const {
293  return specialization_constants_;
294 }
295 
296 } // namespace impeller
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:29
impeller::PipelineDescriptor::GetSpecializationConstants
const std::vector< Scalar > & GetSpecializationConstants() const
Definition: pipeline_descriptor.cc:291
impeller::DeepComparePointer
bool DeepComparePointer(const std::shared_ptr< ComparableType > &lhs, const std::shared_ptr< ComparableType > &rhs)
Definition: comparable.h:57
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
shader_function.h
impeller::PolygonMode
PolygonMode
Definition: formats.h:381
impeller::PipelineDescriptor::GetCullMode
CullMode GetCullMode() const
Definition: pipeline_descriptor.cc:258
impeller::ShaderStage::kUnknown
@ kUnknown
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
shader_library.h
formats.h
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::PipelineDescriptor::GetVertexDescriptor
const std::shared_ptr< VertexDescriptor > & GetVertexDescriptor() const
Definition: pipeline_descriptor.cc:219
impeller::PipelineDescriptor::GetEntrypointForStage
std::shared_ptr< const ShaderFunction > GetEntrypointForStage(ShaderStage stage) const
Definition: pipeline_descriptor.cc:228
impeller::WindingOrder
WindingOrder
Definition: tessellator.h:27
vertex_descriptor.h
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
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::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::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::PipelineDescriptor::SetDepthStencilAttachmentDescriptor
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
Definition: pipeline_descriptor.cc:153
pipeline_descriptor.h
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::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
impeller::PipelineDescriptor::ClearStencilAttachments
void ClearStencilAttachments()
Definition: pipeline_descriptor.cc:172
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