| Flutter Impeller |

pipeline_descriptor.h
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 #pragma once
6
7 #include <functional>
8 #include <future>
9 #include <map>
10 #include <memory>
11 #include <string>
12 #include <string_view>
13 #include <type_traits>
14 #include <unordered_map>
15
16 #include "flutter/fml/hash_combine.h"
17 #include "flutter/fml/macros.h"
18 #include "impeller/base/comparable.h"
19 #include "impeller/core/formats.h"
20 #include "impeller/core/shader_types.h"
21 #include "impeller/tessellator/tessellator.h"
22
23 namespace impeller {
24
25 class ShaderFunction;
26 class VertexDescriptor;
27 template <typename T>
28 class Pipeline;
29
30 class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
31 public:
32 PipelineDescriptor();
33
34 ~PipelineDescriptor();
35
36 PipelineDescriptor& SetLabel(std::string label);
37
38 const std::string& GetLabel() const;
39
40 PipelineDescriptor& SetSampleCount(SampleCount samples);
41
42 SampleCount GetSampleCount() const { return sample_count_; }
43
44 PipelineDescriptor& AddStageEntrypoint(
45 std::shared_ptr<const ShaderFunction> function);
46
47 const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
48 GetStageEntrypoints() const;
49
50 std::shared_ptr<const ShaderFunction> GetEntrypointForStage(
51 ShaderStage stage) const;
52
53 PipelineDescriptor& SetVertexDescriptor(
54 std::shared_ptr<VertexDescriptor> vertex_descriptor);
55
56 const std::shared_ptr<VertexDescriptor>& GetVertexDescriptor() const;
57
58 size_t GetMaxColorAttacmentBindIndex() const;
59
60 PipelineDescriptor& SetColorAttachmentDescriptor(
61 size_t index,
62 ColorAttachmentDescriptor desc);
63
64 PipelineDescriptor& SetColorAttachmentDescriptors(
65 std::map<size_t /* index */, ColorAttachmentDescriptor> descriptors);
66
67 const ColorAttachmentDescriptor* GetColorAttachmentDescriptor(
68 size_t index) const;
69
70 const std::map<size_t /* index */, ColorAttachmentDescriptor>&
71 GetColorAttachmentDescriptors() const;
72
73 const ColorAttachmentDescriptor* GetLegacyCompatibleColorAttachment() const;
74
75 PipelineDescriptor& SetDepthStencilAttachmentDescriptor(
76 std::optional<DepthAttachmentDescriptor> desc);
77
78 std::optional<DepthAttachmentDescriptor> GetDepthStencilAttachmentDescriptor()
79 const;
80
81 PipelineDescriptor& SetStencilAttachmentDescriptors(
82 std::optional<StencilAttachmentDescriptor> front_and_back);
83
84 PipelineDescriptor& SetStencilAttachmentDescriptors(
85 std::optional<StencilAttachmentDescriptor> front,
86 std::optional<StencilAttachmentDescriptor> back);
87
88 void ClearStencilAttachments();
89
90 void ClearDepthAttachment();
91
92 void ClearColorAttachment(size_t index);
93
94 std::optional<StencilAttachmentDescriptor>
95 GetFrontStencilAttachmentDescriptor() const;
96
97 std::optional<StencilAttachmentDescriptor>
98 GetBackStencilAttachmentDescriptor() const;
99
100 bool HasStencilAttachmentDescriptors() const;
101
102 PipelineDescriptor& SetDepthPixelFormat(PixelFormat format);
103
104 PixelFormat GetDepthPixelFormat() const;
105
106 PipelineDescriptor& SetStencilPixelFormat(PixelFormat format);
107
108 PixelFormat GetStencilPixelFormat() const;
109
110 // Comparable<PipelineDescriptor>
111 std::size_t GetHash() const override;
112
113 // Comparable<PipelineDescriptor>
114 bool IsEqual(const PipelineDescriptor& other) const override;
115
116 void ResetAttachments();
117
118 void SetCullMode(CullMode mode);
119
120 CullMode GetCullMode() const;
121
122 void SetWindingOrder(WindingOrder order);
123
124 WindingOrder GetWindingOrder() const;
125
126 void SetPrimitiveType(PrimitiveType type);
127
128 PrimitiveType GetPrimitiveType() const;
129
130 void SetPolygonMode(PolygonMode mode);
131
132 PolygonMode GetPolygonMode() const;
133
134 private:
135 std::string label_;
136 SampleCount sample_count_ = SampleCount::kCount1;
137 WindingOrder winding_order_ = WindingOrder::kClockwise;
138 CullMode cull_mode_ = CullMode::kNone;
139 std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
140 std::map<size_t /* index */, ColorAttachmentDescriptor>
141 color_attachment_descriptors_;
142 std::shared_ptr<VertexDescriptor> vertex_descriptor_;
143 PixelFormat depth_pixel_format_ = PixelFormat::kUnknown;
144 PixelFormat stencil_pixel_format_ = PixelFormat::kUnknown;
145 std::optional<DepthAttachmentDescriptor> depth_attachment_descriptor_;
146 std::optional<StencilAttachmentDescriptor>
147 front_stencil_attachment_descriptor_;
148 std::optional<StencilAttachmentDescriptor>
149 back_stencil_attachment_descriptor_;
150 PrimitiveType primitive_type_ = PrimitiveType::kTriangle;
151 PolygonMode polygon_mode_ = PolygonMode::kFill;
152 };
153
154 } // namespace impeller
impeller::PipelineDescriptor
Definition: pipeline_descriptor.h:30
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
impeller::PolygonMode
PolygonMode
Definition: formats.h:338
impeller::PipelineDescriptor::GetCullMode
CullMode GetCullMode() const
Definition: pipeline_descriptor.cc:252
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
formats.h
impeller::SampleCount::kCount1
@ kCount1
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:20
impeller::PipelineDescriptor::GetSampleCount
SampleCount GetSampleCount() const
Definition: pipeline_descriptor.h:42
impeller::PipelineDescriptor::GetVertexDescriptor
const std::shared_ptr< VertexDescriptor > & GetVertexDescriptor() const
Definition: pipeline_descriptor.cc:213
impeller::WindingOrder::kClockwise
@ kClockwise
impeller::PipelineDescriptor::GetEntrypointForStage
std::shared_ptr< const ShaderFunction > GetEntrypointForStage(ShaderStage stage) const
Definition: pipeline_descriptor.cc:222
impeller::WindingOrder
WindingOrder
Definition: tessellator.h:24
impeller::PolygonMode::kFill
@ kFill
impeller::PipelineDescriptor::SetCullMode
void SetCullMode(CullMode mode)
Definition: pipeline_descriptor.cc:248
tessellator.h
impeller::CullMode
CullMode
Definition: formats.h:314
impeller::PipelineDescriptor::SetColorAttachmentDescriptors
PipelineDescriptor & SetColorAttachmentDescriptors(std::map< size_t, ColorAttachmentDescriptor > descriptors)
Definition: pipeline_descriptor.cc:113
impeller::CullMode::kNone
@ kNone
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::Comparable
Definition: comparable.h:32
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
comparable.h
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::PrimitiveType::kTriangle
@ kTriangle
impeller::PipelineDescriptor::SetDepthStencilAttachmentDescriptor
PipelineDescriptor & SetDepthStencilAttachmentDescriptor(std::optional< DepthAttachmentDescriptor > desc)
Definition: pipeline_descriptor.cc:147
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
shader_types.h
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