Minor fixups to pipeline creation.

This commit is contained in:
Chinmay Garde
2021-11-09 15:55:13 -08:00
committed by Dan Field
parent b7cb641d6a
commit 791a4c34a6
3 changed files with 74 additions and 39 deletions

View File

@@ -48,7 +48,16 @@ struct PipelineBuilder {
static std::optional<PipelineDescriptor> MakeDefaultPipelineDescriptor(
const Context& context) {
PipelineDescriptor desc;
if (InitializePipelineDescriptorDefaults(context, desc)) {
return {std::move(desc)};
} else {
return std::nullopt;
}
}
[[nodiscard]] static bool InitializePipelineDescriptorDefaults(
const Context& context,
PipelineDescriptor& desc) {
// Setup debug instrumentation.
desc.SetLabel(SPrintF("%s Pipeline", VertexShader::kLabel.data()));
@@ -61,7 +70,7 @@ struct PipelineBuilder {
if (!vertex_function || !fragment_function) {
FML_LOG(ERROR) << "Could not resolve pipeline entrypoint(s).";
return std::nullopt;
return false;
}
desc.AddStageEntrypoint(std::move(vertex_function));
@@ -74,35 +83,22 @@ struct PipelineBuilder {
if (!vertex_descriptor->SetStageInputs(
VertexShader::kAllShaderStageInputs)) {
FML_LOG(ERROR) << "Could not configure vertex descriptor.";
return std::nullopt;
return false;
}
desc.SetVertexDescriptor(std::move(vertex_descriptor));
}
// Setup fragment shader output descriptions.
{
// Configure the sole color attachments pixel format.
// TODO(csg): This can be easily reflected but we are sticking to the
// convention that the first stage output is the color output.
// Configure the sole color attachments pixel format. This is by
// convention.
ColorAttachmentDescriptor color0;
color0.format = PixelFormat::kB8G8R8A8UNormInt;
color0.blending_enabled = true;
desc.SetColorAttachmentDescriptor(0u, std::move(color0));
}
// Setup depth and stencil attachment descriptions.
{
// Configure the stencil attachment.
// TODO(csg): Make this configurable if possible as the D32 component is
// wasted. This can even be moved out of the "default" descriptor
// construction as a case can be made that this is caller responsibility.
// const auto combined_depth_stencil_format =
// PixelFormat::kPixelFormat_D32_Float_S8_UNormInt;
// desc.SetDepthPixelFormat(combined_depth_stencil_format);
// desc.SetStencilPixelFormat(combined_depth_stencil_format);
}
return desc;
return true;
}
};

View File

@@ -132,4 +132,53 @@ PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors(
return *this;
}
void PipelineDescriptor::ResetAttachments() {
color_attachment_descriptors_.clear();
depth_attachment_descriptor_.reset();
front_stencil_attachment_descriptor_.reset();
back_stencil_attachment_descriptor_.reset();
}
PixelFormat PipelineDescriptor::GetStencilPixelFormat() const {
return stencil_pixel_format_;
}
std::optional<StencilAttachmentDescriptor>
PipelineDescriptor::GetFrontStencilAttachmentDescriptor() const {
return front_stencil_attachment_descriptor_;
}
std::optional<DepthAttachmentDescriptor>
PipelineDescriptor::GetDepthStencilAttachmentDescriptor() const {
return depth_attachment_descriptor_;
}
const std::map<size_t /* index */, ColorAttachmentDescriptor>
PipelineDescriptor::GetColorAttachmentDescriptors() const {
return color_attachment_descriptors_;
}
const std::shared_ptr<VertexDescriptor>&
PipelineDescriptor::GetVertexDescriptor() const {
return vertex_descriptor_;
}
const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
PipelineDescriptor::GetStageEntrypoints() const {
return entrypoints_;
}
const std::string& PipelineDescriptor::GetLabel() const {
return label_;
}
PixelFormat PipelineDescriptor::GetDepthPixelFormat() const {
return depth_pixel_format_;
}
std::optional<StencilAttachmentDescriptor>
PipelineDescriptor::GetBackStencilAttachmentDescriptor() const {
return back_stencil_attachment_descriptor_;
}
} // namespace impeller

View File

@@ -30,7 +30,7 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
PipelineDescriptor& SetLabel(std::string label);
const std::string& GetLabel() const { return label_; }
const std::string& GetLabel() const;
PipelineDescriptor& SetSampleCount(size_t samples);
@@ -40,16 +40,12 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
std::shared_ptr<const ShaderFunction> function);
const std::map<ShaderStage, std::shared_ptr<const ShaderFunction>>&
GetStageEntrypoints() const {
return entrypoints_;
}
GetStageEntrypoints() const;
PipelineDescriptor& SetVertexDescriptor(
std::shared_ptr<VertexDescriptor> vertex_descriptor);
const std::shared_ptr<VertexDescriptor>& GetVertexDescriptor() const {
return vertex_descriptor_;
}
const std::shared_ptr<VertexDescriptor>& GetVertexDescriptor() const;
PipelineDescriptor& SetColorAttachmentDescriptor(
size_t index,
@@ -59,17 +55,13 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
size_t index) const;
const std::map<size_t /* index */, ColorAttachmentDescriptor>
GetColorAttachmentDescriptors() const {
return color_attachment_descriptors_;
}
GetColorAttachmentDescriptors() const;
PipelineDescriptor& SetDepthStencilAttachmentDescriptor(
DepthAttachmentDescriptor desc);
std::optional<DepthAttachmentDescriptor> GetDepthStencilAttachmentDescriptor()
const {
return depth_attachment_descriptor_;
}
const;
PipelineDescriptor& SetStencilAttachmentDescriptors(
StencilAttachmentDescriptor front_and_back);
@@ -79,22 +71,18 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
StencilAttachmentDescriptor back);
std::optional<StencilAttachmentDescriptor>
GetFrontStencilAttachmentDescriptor() const {
return front_stencil_attachment_descriptor_;
}
GetFrontStencilAttachmentDescriptor() const;
std::optional<StencilAttachmentDescriptor>
GetBackStencilAttachmentDescriptor() const {
return back_stencil_attachment_descriptor_;
}
GetBackStencilAttachmentDescriptor() const;
PipelineDescriptor& SetDepthPixelFormat(PixelFormat format);
PixelFormat GetDepthPixelFormat() const { return depth_pixel_format_; }
PixelFormat GetDepthPixelFormat() const;
PipelineDescriptor& SetStencilPixelFormat(PixelFormat format);
PixelFormat GetStencilPixelFormat() const { return stencil_pixel_format_; }
PixelFormat GetStencilPixelFormat() const;
// Comparable<PipelineDescriptor>
std::size_t GetHash() const override;
@@ -102,6 +90,8 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
// Comparable<PipelineDescriptor>
bool IsEqual(const PipelineDescriptor& other) const override;
void ResetAttachments();
private:
std::string label_;
size_t sample_count_ = 1;