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