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  return seed;
49 }
50 
51 // Comparable<PipelineDescriptor>
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 
72  label_ = std::move(label);
73  return *this;
74 }
75 
77  sample_count_ = samples;
78  return *this;
79 }
80 
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 
97  std::shared_ptr<VertexDescriptor> vertex_descriptor) {
98  vertex_descriptor_ = std::move(vertex_descriptor);
99  return *this;
100 }
101 
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 
111  size_t index,
113  color_attachment_descriptors_[index] = desc;
114  return *this;
115 }
116 
118  std::map<size_t /* index */, ColorAttachmentDescriptor> descriptors) {
119  color_attachment_descriptors_ = std::move(descriptors);
120  return *this;
121 }
122 
125  auto found = color_attachment_descriptors_.find(index);
126  return found == color_attachment_descriptors_.end() ? nullptr
127  : &found->second;
128 }
129 
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 
140  PixelFormat format) {
141  depth_pixel_format_ = format;
142  return *this;
143 }
144 
146  PixelFormat format) {
147  stencil_pixel_format_ = format;
148  return *this;
149 }
150 
152  std::optional<DepthAttachmentDescriptor> desc) {
153  depth_attachment_descriptor_ = desc;
154  return *this;
155 }
156 
158  std::optional<StencilAttachmentDescriptor> front_and_back) {
159  return SetStencilAttachmentDescriptors(front_and_back, front_and_back);
160 }
161 
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 
171  back_stencil_attachment_descriptor_.reset();
172  front_stencil_attachment_descriptor_.reset();
174 }
175 
177  depth_attachment_descriptor_.reset();
179 }
180 
182  if (color_attachment_descriptors_.find(index) ==
183  color_attachment_descriptors_.end()) {
184  return;
185  }
186 
187  color_attachment_descriptors_.erase(index);
188 }
189 
191  color_attachment_descriptors_.clear();
192  depth_attachment_descriptor_.reset();
193  front_stencil_attachment_descriptor_.reset();
194  back_stencil_attachment_descriptor_.reset();
195 }
196 
198  return stencil_pixel_format_;
199 }
200 
201 std::optional<StencilAttachmentDescriptor>
203  return front_stencil_attachment_descriptor_;
204 }
205 
206 std::optional<DepthAttachmentDescriptor>
208  return depth_attachment_descriptor_;
209 }
210 
211 const std::map<size_t /* index */, ColorAttachmentDescriptor>&
213  return color_attachment_descriptors_;
214 }
215 
216 const std::shared_ptr<VertexDescriptor>&
218  return vertex_descriptor_;
219 }
220 
221 const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
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 const std::string& PipelineDescriptor::GetLabel() const {
235  return label_;
236 }
237 
239  return depth_pixel_format_;
240 }
241 
242 std::optional<StencilAttachmentDescriptor>
244  return back_stencil_attachment_descriptor_;
245 }
246 
248  return front_stencil_attachment_descriptor_.has_value() ||
249  back_stencil_attachment_descriptor_.has_value();
250 }
251 
253  cull_mode_ = mode;
254 }
255 
257  return cull_mode_;
258 }
259 
261  winding_order_ = order;
262 }
263 
265  return winding_order_;
266 }
267 
269  primitive_type_ = type;
270 }
271 
273  return primitive_type_;
274 }
275 
277  polygon_mode_ = mode;
278 }
279 
281  return polygon_mode_;
282 }
283 
285  std::vector<Scalar> values) {
286  specialization_constants_ = std::move(values);
287 }
288 
290  const {
291  return specialization_constants_;
292 }
293 
294 } // namespace impeller
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:24
impeller::PipelineDescriptor::GetSpecializationConstants
const std::vector< Scalar > & GetSpecializationConstants() const
Definition: pipeline_descriptor.cc:289
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:243
impeller::PipelineDescriptor::SetPolygonMode
void SetPolygonMode(PolygonMode mode)
Definition: pipeline_descriptor.cc:276
shader_function.h
impeller::PolygonMode
PolygonMode
Definition: formats.h:384
impeller::PipelineDescriptor::GetCullMode
CullMode GetCullMode() const
Definition: pipeline_descriptor.cc:256
impeller::ShaderStage::kUnknown
@ kUnknown
impeller::PipelineDescriptor::SetStencilAttachmentDescriptors
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
Definition: pipeline_descriptor.cc:157
impeller::PipelineDescriptor::GetLabel
const std::string & GetLabel() const
Definition: pipeline_descriptor.cc:234
impeller::PipelineDescriptor::SetColorAttachmentDescriptor
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
Definition: pipeline_descriptor.cc:110
impeller::PipelineDescriptor::SetStencilPixelFormat
PipelineDescriptor & SetStencilPixelFormat(PixelFormat format)
Definition: pipeline_descriptor.cc:145
impeller::PipelineDescriptor::GetColorAttachmentDescriptor
const ColorAttachmentDescriptor * GetColorAttachmentDescriptor(size_t index) const
Definition: pipeline_descriptor.cc:124
impeller::PipelineDescriptor::SetPrimitiveType
void SetPrimitiveType(PrimitiveType type)
Definition: pipeline_descriptor.cc:268
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:217
impeller::PipelineDescriptor::GetEntrypointForStage
std::shared_ptr< const ShaderFunction > GetEntrypointForStage(ShaderStage stage) const
Definition: pipeline_descriptor.cc:226
impeller::WindingOrder
WindingOrder
Definition: formats.h:23
vertex_descriptor.h
impeller::PipelineDescriptor::SetCullMode
void SetCullMode(CullMode mode)
Definition: pipeline_descriptor.cc:252
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:100
impeller::CullMode
CullMode
Definition: formats.h:338
impeller::PipelineDescriptor::SetColorAttachmentDescriptors
PipelineDescriptor & SetColorAttachmentDescriptors(std::map< size_t, ColorAttachmentDescriptor > descriptors)
Definition: pipeline_descriptor.cc:117
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:353
impeller::PipelineDescriptor::HasStencilAttachmentDescriptors
bool HasStencilAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:247
impeller::PipelineDescriptor::GetMaxColorAttacmentBindIndex
size_t GetMaxColorAttacmentBindIndex() const
Definition: pipeline_descriptor.cc:102
impeller::PipelineDescriptor::GetPrimitiveType
PrimitiveType GetPrimitiveType() const
Definition: pipeline_descriptor.cc:272
impeller::PipelineDescriptor::GetWindingOrder
WindingOrder GetWindingOrder() const
Definition: pipeline_descriptor.cc:264
impeller::PipelineDescriptor::GetStencilPixelFormat
PixelFormat GetStencilPixelFormat() const
Definition: pipeline_descriptor.cc:197
impeller::PipelineDescriptor::GetPolygonMode
PolygonMode GetPolygonMode() const
Definition: pipeline_descriptor.cc:280
impeller::PipelineDescriptor::ClearColorAttachment
void ClearColorAttachment(size_t index)
Definition: pipeline_descriptor.cc:181
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::PipelineDescriptor::SetSampleCount
PipelineDescriptor & SetSampleCount(SampleCount samples)
Definition: pipeline_descriptor.cc:76
impeller::PipelineDescriptor::AddStageEntrypoint
PipelineDescriptor & AddStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
Definition: pipeline_descriptor.cc:81
impeller::PipelineDescriptor::GetFrontStencilAttachmentDescriptor
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:202
impeller::PipelineDescriptor::ClearDepthAttachment
void ClearDepthAttachment()
Definition: pipeline_descriptor.cc:176
impeller::PipelineDescriptor::~PipelineDescriptor
~PipelineDescriptor()
impeller::PipelineDescriptor::GetDepthPixelFormat
PixelFormat GetDepthPixelFormat() const
Definition: pipeline_descriptor.cc:238
comparable.h
impeller::PipelineDescriptor::PipelineDescriptor
PipelineDescriptor()
impeller::PipelineDescriptor::GetColorAttachmentDescriptors
const std::map< size_t, ColorAttachmentDescriptor > & GetColorAttachmentDescriptors() const
Definition: pipeline_descriptor.cc:212
impeller::SampleCount
SampleCount
Definition: formats.h:296
impeller::PipelineDescriptor::ResetAttachments
void ResetAttachments()
Definition: pipeline_descriptor.cc:190
impeller::PipelineDescriptor::SetDepthPixelFormat
PipelineDescriptor & SetDepthPixelFormat(PixelFormat format)
Definition: pipeline_descriptor.cc:139
impeller::PipelineDescriptor::IsEqual
bool IsEqual(const PipelineDescriptor &other) const override
Definition: pipeline_descriptor.cc:52
impeller::PipelineDescriptor::GetDepthStencilAttachmentDescriptor
std::optional< DepthAttachmentDescriptor > GetDepthStencilAttachmentDescriptor() const
Definition: pipeline_descriptor.cc:207
impeller::PipelineDescriptor::GetStageEntrypoints
const std::map< ShaderStage, std::shared_ptr< const ShaderFunction > > & GetStageEntrypoints() const
Definition: pipeline_descriptor.cc:222
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:151
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:284
impeller::PipelineDescriptor::SetLabel
PipelineDescriptor & SetLabel(std::string label)
Definition: pipeline_descriptor.cc:71
impeller::PipelineDescriptor::SetWindingOrder
void SetWindingOrder(WindingOrder order)
Definition: pipeline_descriptor.cc:260
impeller::PipelineDescriptor::GetLegacyCompatibleColorAttachment
const ColorAttachmentDescriptor * GetLegacyCompatibleColorAttachment() const
Definition: pipeline_descriptor.cc:131
impeller::PipelineDescriptor::ClearStencilAttachments
void ClearStencilAttachments()
Definition: pipeline_descriptor.cc:170
impeller
Definition: aiks_blur_unittests.cc:20
impeller::PipelineDescriptor::SetVertexDescriptor
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
Definition: pipeline_descriptor.cc:96
impeller::ColorAttachmentDescriptor
Describe the color attachment that will be used with this pipeline.
Definition: formats.h:500