From 791a4c34a69eec52f116de1995683ab29f8c0a4a Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 9 Nov 2021 15:55:13 -0800 Subject: [PATCH] Minor fixups to pipeline creation. --- .../impeller/renderer/pipeline_builder.h | 32 ++++++------ .../impeller/renderer/pipeline_descriptor.cc | 49 +++++++++++++++++++ .../impeller/renderer/pipeline_descriptor.h | 32 +++++------- 3 files changed, 74 insertions(+), 39 deletions(-) diff --git a/engine/src/flutter/impeller/renderer/pipeline_builder.h b/engine/src/flutter/impeller/renderer/pipeline_builder.h index f157b7fcc9..8cc488c512 100644 --- a/engine/src/flutter/impeller/renderer/pipeline_builder.h +++ b/engine/src/flutter/impeller/renderer/pipeline_builder.h @@ -48,7 +48,16 @@ struct PipelineBuilder { static std::optional 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; } }; diff --git a/engine/src/flutter/impeller/renderer/pipeline_descriptor.cc b/engine/src/flutter/impeller/renderer/pipeline_descriptor.cc index b367d4d009..0f7af4a651 100644 --- a/engine/src/flutter/impeller/renderer/pipeline_descriptor.cc +++ b/engine/src/flutter/impeller/renderer/pipeline_descriptor.cc @@ -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 +PipelineDescriptor::GetFrontStencilAttachmentDescriptor() const { + return front_stencil_attachment_descriptor_; +} + +std::optional +PipelineDescriptor::GetDepthStencilAttachmentDescriptor() const { + return depth_attachment_descriptor_; +} + +const std::map +PipelineDescriptor::GetColorAttachmentDescriptors() const { + return color_attachment_descriptors_; +} + +const std::shared_ptr& +PipelineDescriptor::GetVertexDescriptor() const { + return vertex_descriptor_; +} + +const std::map>& +PipelineDescriptor::GetStageEntrypoints() const { + return entrypoints_; +} + +const std::string& PipelineDescriptor::GetLabel() const { + return label_; +} + +PixelFormat PipelineDescriptor::GetDepthPixelFormat() const { + return depth_pixel_format_; +} + +std::optional +PipelineDescriptor::GetBackStencilAttachmentDescriptor() const { + return back_stencil_attachment_descriptor_; +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/renderer/pipeline_descriptor.h b/engine/src/flutter/impeller/renderer/pipeline_descriptor.h index 3413b755fd..3e43df2d0b 100644 --- a/engine/src/flutter/impeller/renderer/pipeline_descriptor.h +++ b/engine/src/flutter/impeller/renderer/pipeline_descriptor.h @@ -30,7 +30,7 @@ class PipelineDescriptor final : public Comparable { 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 { std::shared_ptr function); const std::map>& - GetStageEntrypoints() const { - return entrypoints_; - } + GetStageEntrypoints() const; PipelineDescriptor& SetVertexDescriptor( std::shared_ptr vertex_descriptor); - const std::shared_ptr& GetVertexDescriptor() const { - return vertex_descriptor_; - } + const std::shared_ptr& GetVertexDescriptor() const; PipelineDescriptor& SetColorAttachmentDescriptor( size_t index, @@ -59,17 +55,13 @@ class PipelineDescriptor final : public Comparable { size_t index) const; const std::map - GetColorAttachmentDescriptors() const { - return color_attachment_descriptors_; - } + GetColorAttachmentDescriptors() const; PipelineDescriptor& SetDepthStencilAttachmentDescriptor( DepthAttachmentDescriptor desc); std::optional GetDepthStencilAttachmentDescriptor() - const { - return depth_attachment_descriptor_; - } + const; PipelineDescriptor& SetStencilAttachmentDescriptors( StencilAttachmentDescriptor front_and_back); @@ -79,22 +71,18 @@ class PipelineDescriptor final : public Comparable { StencilAttachmentDescriptor back); std::optional - GetFrontStencilAttachmentDescriptor() const { - return front_stencil_attachment_descriptor_; - } + GetFrontStencilAttachmentDescriptor() const; std::optional - 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 std::size_t GetHash() const override; @@ -102,6 +90,8 @@ class PipelineDescriptor final : public Comparable { // Comparable bool IsEqual(const PipelineDescriptor& other) const override; + void ResetAttachments(); + private: std::string label_; size_t sample_count_ = 1;