Skip to content

Commit 531162f

Browse files
chinmaygardednfield
authored andcommitted
Minor fixups to pipeline creation.
1 parent b5ed864 commit 531162f

File tree

3 files changed

+74
-39
lines changed

3 files changed

+74
-39
lines changed

impeller/renderer/pipeline_builder.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ struct PipelineBuilder {
4848
static std::optional<PipelineDescriptor> MakeDefaultPipelineDescriptor(
4949
const Context& context) {
5050
PipelineDescriptor desc;
51+
if (InitializePipelineDescriptorDefaults(context, desc)) {
52+
return {std::move(desc)};
53+
} else {
54+
return std::nullopt;
55+
}
56+
}
5157

58+
[[nodiscard]] static bool InitializePipelineDescriptorDefaults(
59+
const Context& context,
60+
PipelineDescriptor& desc) {
5261
// Setup debug instrumentation.
5362
desc.SetLabel(SPrintF("%s Pipeline", VertexShader::kLabel.data()));
5463

@@ -61,7 +70,7 @@ struct PipelineBuilder {
6170

6271
if (!vertex_function || !fragment_function) {
6372
FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s).";
64-
return std::nullopt;
73+
return false;
6574
}
6675

6776
desc.AddStageEntrypoint(std::move(vertex_function));
@@ -74,35 +83,22 @@ struct PipelineBuilder {
7483
if (!vertex_descriptor->SetStageInputs(
7584
VertexShader::kAllShaderStageInputs)) {
7685
FML_LOG(ERROR) << "Could not configure vertex descriptor.";
77-
return std::nullopt;
86+
return false;
7887
}
7988
desc.SetVertexDescriptor(std::move(vertex_descriptor));
8089
}
8190

8291
// Setup fragment shader output descriptions.
8392
{
84-
// Configure the sole color attachments pixel format.
85-
// TODO(csg): This can be easily reflected but we are sticking to the
86-
// convention that the first stage output is the color output.
93+
// Configure the sole color attachments pixel format. This is by
94+
// convention.
8795
ColorAttachmentDescriptor color0;
8896
color0.format = PixelFormat::kB8G8R8A8UNormInt;
8997
color0.blending_enabled = true;
9098
desc.SetColorAttachmentDescriptor(0u, std::move(color0));
9199
}
92100

93-
// Setup depth and stencil attachment descriptions.
94-
{
95-
// Configure the stencil attachment.
96-
// TODO(csg): Make this configurable if possible as the D32 component is
97-
// wasted. This can even be moved out of the "default" descriptor
98-
// construction as a case can be made that this is caller responsibility.
99-
// const auto combined_depth_stencil_format =
100-
// PixelFormat::kPixelFormat_D32_Float_S8_UNormInt;
101-
// desc.SetDepthPixelFormat(combined_depth_stencil_format);
102-
// desc.SetStencilPixelFormat(combined_depth_stencil_format);
103-
}
104-
105-
return desc;
101+
return true;
106102
}
107103
};
108104

impeller/renderer/pipeline_descriptor.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,53 @@ PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors(
132132
return *this;
133133
}
134134

135+
void PipelineDescriptor::ResetAttachments() {
136+
color_attachment_descriptors_.clear();
137+
depth_attachment_descriptor_.reset();
138+
front_stencil_attachment_descriptor_.reset();
139+
back_stencil_attachment_descriptor_.reset();
140+
}
141+
142+
PixelFormat PipelineDescriptor::GetStencilPixelFormat() const {
143+
return stencil_pixel_format_;
144+
}
145+
146+
std::optional<StencilAttachmentDescriptor>
147+
PipelineDescriptor::GetFrontStencilAttachmentDescriptor() const {
148+
return front_stencil_attachment_descriptor_;
149+
}
150+
151+
std::optional<DepthAttachmentDescriptor>
152+
PipelineDescriptor::GetDepthStencilAttachmentDescriptor() const {
153+
return depth_attachment_descriptor_;
154+
}
155+
156+
const std::map<size_t /* index */, ColorAttachmentDescriptor>
157+
PipelineDescriptor::GetColorAttachmentDescriptors() const {
158+
return color_attachment_descriptors_;
159+
}
160+
161+
const std::shared_ptr<VertexDescriptor>&
162+
PipelineDescriptor::GetVertexDescriptor() const {
163+
return vertex_descriptor_;
164+
}
165+
166+
const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
167+
PipelineDescriptor::GetStageEntrypoints() const {
168+
return entrypoints_;
169+
}
170+
171+
const std::string& PipelineDescriptor::GetLabel() const {
172+
return label_;
173+
}
174+
175+
PixelFormat PipelineDescriptor::GetDepthPixelFormat() const {
176+
return depth_pixel_format_;
177+
}
178+
179+
std::optional<StencilAttachmentDescriptor>
180+
PipelineDescriptor::GetBackStencilAttachmentDescriptor() const {
181+
return back_stencil_attachment_descriptor_;
182+
}
183+
135184
} // namespace impeller

impeller/renderer/pipeline_descriptor.h

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
3030

3131
PipelineDescriptor& SetLabel(std::string label);
3232

33-
const std::string& GetLabel() const { return label_; }
33+
const std::string& GetLabel() const;
3434

3535
PipelineDescriptor& SetSampleCount(size_t samples);
3636

@@ -40,16 +40,12 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
4040
std::shared_ptr<const ShaderFunction> function);
4141

4242
const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
43-
GetStageEntrypoints() const {
44-
return entrypoints_;
45-
}
43+
GetStageEntrypoints() const;
4644

4745
PipelineDescriptor& SetVertexDescriptor(
4846
std::shared_ptr<VertexDescriptor> vertex_descriptor);
4947

50-
const std::shared_ptr<VertexDescriptor>& GetVertexDescriptor() const {
51-
return vertex_descriptor_;
52-
}
48+
const std::shared_ptr<VertexDescriptor>& GetVertexDescriptor() const;
5349

5450
PipelineDescriptor& SetColorAttachmentDescriptor(
5551
size_t index,
@@ -59,17 +55,13 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
5955
size_t index) const;
6056

6157
const std::map<size_t /* index */, ColorAttachmentDescriptor>
62-
GetColorAttachmentDescriptors() const {
63-
return color_attachment_descriptors_;
64-
}
58+
GetColorAttachmentDescriptors() const;
6559

6660
PipelineDescriptor& SetDepthStencilAttachmentDescriptor(
6761
DepthAttachmentDescriptor desc);
6862

6963
std::optional<DepthAttachmentDescriptor> GetDepthStencilAttachmentDescriptor()
70-
const {
71-
return depth_attachment_descriptor_;
72-
}
64+
const;
7365

7466
PipelineDescriptor& SetStencilAttachmentDescriptors(
7567
StencilAttachmentDescriptor front_and_back);
@@ -79,29 +71,27 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
7971
StencilAttachmentDescriptor back);
8072

8173
std::optional<StencilAttachmentDescriptor>
82-
GetFrontStencilAttachmentDescriptor() const {
83-
return front_stencil_attachment_descriptor_;
84-
}
74+
GetFrontStencilAttachmentDescriptor() const;
8575

8676
std::optional<StencilAttachmentDescriptor>
87-
GetBackStencilAttachmentDescriptor() const {
88-
return back_stencil_attachment_descriptor_;
89-
}
77+
GetBackStencilAttachmentDescriptor() const;
9078

9179
PipelineDescriptor& SetDepthPixelFormat(PixelFormat format);
9280

93-
PixelFormat GetDepthPixelFormat() const { return depth_pixel_format_; }
81+
PixelFormat GetDepthPixelFormat() const;
9482

9583
PipelineDescriptor& SetStencilPixelFormat(PixelFormat format);
9684

97-
PixelFormat GetStencilPixelFormat() const { return stencil_pixel_format_; }
85+
PixelFormat GetStencilPixelFormat() const;
9886

9987
// Comparable<PipelineDescriptor>
10088
std::size_t GetHash() const override;
10189

10290
// Comparable<PipelineDescriptor>
10391
bool IsEqual(const PipelineDescriptor& other) const override;
10492

93+
void ResetAttachments();
94+
10595
private:
10696
std::string label_;
10797
size_t sample_count_ = 1;

0 commit comments

Comments
 (0)