Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
14
15namespace impeller {
16
18
20
21// Comparable<PipelineDescriptor>
22std::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 }
137}
138
141 depth_pixel_format_ = format;
142 return *this;
143}
144
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
201std::optional<StencilAttachmentDescriptor>
203 return front_stencil_attachment_descriptor_;
204}
205
206std::optional<DepthAttachmentDescriptor>
208 return depth_attachment_descriptor_;
209}
210
211const std::map<size_t /* index */, ColorAttachmentDescriptor>&
213 return color_attachment_descriptors_;
214}
215
216const std::shared_ptr<VertexDescriptor>&
218 return vertex_descriptor_;
219}
220
221const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
223 return entrypoints_;
224}
225
226std::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
234const std::string& PipelineDescriptor::GetLabel() const {
235 return label_;
236}
237
239 return depth_pixel_format_;
240}
241
242std::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
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
SkColor4f color
PipelineDescriptor & SetStencilPixelFormat(PixelFormat format)
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
std::size_t GetHash() const override
PixelFormat GetDepthPixelFormat() const
PipelineDescriptor & SetVertexDescriptor(std::shared_ptr< VertexDescriptor > vertex_descriptor)
void SetPolygonMode(PolygonMode mode)
PrimitiveType GetPrimitiveType() const
std::optional< DepthAttachmentDescriptor > GetDepthStencilAttachmentDescriptor() const
PipelineDescriptor & AddStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
bool IsEqual(const PipelineDescriptor &other) const override
const std::map< ShaderStage, std::shared_ptr< const ShaderFunction > > & GetStageEntrypoints() const
PixelFormat GetStencilPixelFormat() const
const ColorAttachmentDescriptor * GetLegacyCompatibleColorAttachment() const
void SetSpecializationConstants(std::vector< Scalar > values)
const std::vector< Scalar > & GetSpecializationConstants() const
PipelineDescriptor & SetDepthPixelFormat(PixelFormat format)
PipelineDescriptor & SetStencilAttachmentDescriptors(std::optional< StencilAttachmentDescriptor > front_and_back)
const ColorAttachmentDescriptor * GetColorAttachmentDescriptor(size_t index) const
PipelineDescriptor & SetLabel(std::string label)
PipelineDescriptor & SetColorAttachmentDescriptor(size_t index, ColorAttachmentDescriptor desc)
PipelineDescriptor & SetSampleCount(SampleCount samples)
void SetPrimitiveType(PrimitiveType type)
const std::string & GetLabel() const
std::shared_ptr< const ShaderFunction > GetEntrypointForStage(ShaderStage stage) const
const std::map< size_t, ColorAttachmentDescriptor > & GetColorAttachmentDescriptors() const
std::optional< StencilAttachmentDescriptor > GetBackStencilAttachmentDescriptor() const
const std::shared_ptr< VertexDescriptor > & GetVertexDescriptor() const
std::optional< StencilAttachmentDescriptor > GetFrontStencilAttachmentDescriptor() const
void SetWindingOrder(WindingOrder order)
PipelineDescriptor & SetColorAttachmentDescriptors(std::map< size_t, ColorAttachmentDescriptor > descriptors)
uint32_t uint32_t * format
Dart_NativeFunction function
Definition fuchsia.cc:51
static float max(float r, float g, float b)
Definition hsl.cpp:49
constexpr std::size_t HashCombine()
constexpr void HashCombineSeed(std::size_t &seed, Type arg)
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition formats.h:353
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
WindingOrder
Definition formats.h:23
bool DeepComparePointer(const std::shared_ptr< ComparableType > &lhs, const std::shared_ptr< ComparableType > &rhs)
Definition comparable.h:57
bool DeepCompareMap(const std::map< Key, std::shared_ptr< ComparableType > > &lhs, const std::map< Key, std::shared_ptr< ComparableType > > &rhs)
Definition comparable.h:74
Describe the color attachment that will be used with this pipeline.
Definition formats.h:500