From 5e9cf0816ea39494128421b8e773b62596dafcb6 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Sun, 18 Jul 2021 14:50:03 -0700 Subject: [PATCH] Better disambiguate attachment descriptors for pipelines and stencils. --- .../src/flutter/impeller/compositor/formats.h | 20 ++++++++--------- .../impeller/compositor/formats_metal.h | 8 +++---- .../impeller/compositor/formats_metal.mm | 12 +++++----- .../impeller/compositor/pipeline_builder.h | 2 +- .../impeller/compositor/pipeline_descriptor.h | 22 +++++++++---------- .../compositor/pipeline_descriptor.mm | 14 ++++++------ 6 files changed, 38 insertions(+), 40 deletions(-) diff --git a/engine/src/flutter/impeller/compositor/formats.h b/engine/src/flutter/impeller/compositor/formats.h index 062a890d0e..2d51ecb711 100644 --- a/engine/src/flutter/impeller/compositor/formats.h +++ b/engine/src/flutter/impeller/compositor/formats.h @@ -126,7 +126,7 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) { return 0u; } -struct ColorAttachmentDescriptor { +struct PipelineColorAttachment { PixelFormat format = PixelFormat::kUnknown; bool blending_enabled = false; @@ -159,7 +159,7 @@ struct ColorAttachmentDescriptor { std::underlying_type_t write_mask = static_cast(ColorWriteMask::kAll); - constexpr bool operator==(const ColorAttachmentDescriptor& o) const { + constexpr bool operator==(const PipelineColorAttachment& o) const { return format == o.format && // blending_enabled == o.blending_enabled && // src_color_blend_factor == o.src_color_blend_factor && // @@ -217,7 +217,7 @@ enum class StencilOperation { kDecrementWrap, }; -struct DepthAttachmentDescriptor { +struct PipelineDepthAttachment { //---------------------------------------------------------------------------- /// Indicates how to compare the value with that in the depth buffer. /// @@ -227,7 +227,7 @@ struct DepthAttachmentDescriptor { /// bool depth_write_enabled = false; - constexpr bool operator==(const DepthAttachmentDescriptor& o) const { + constexpr bool operator==(const PipelineDepthAttachment& o) const { return depth_compare == o.depth_compare && depth_write_enabled == o.depth_write_enabled; } @@ -237,7 +237,7 @@ struct DepthAttachmentDescriptor { } }; -struct StencilAttachmentDescriptor { +struct PipelineStencilAttachment { //---------------------------------------------------------------------------- /// Indicates the operation to perform between the reference value and the /// value in the stencil buffer. Both values have the read_mask applied to @@ -268,7 +268,7 @@ struct StencilAttachmentDescriptor { /// uint32_t write_mask = ~0; - constexpr bool operator==(const StencilAttachmentDescriptor& o) const { + constexpr bool operator==(const PipelineStencilAttachment& o) const { return stencil_compare == o.stencil_compare && stencil_failure == o.stencil_failure && depth_failure == o.depth_failure && @@ -307,17 +307,17 @@ struct RenderPassStencilAttachment : public RenderPassAttachment { namespace std { template <> -struct hash { +struct hash { constexpr std::size_t operator()( - const impeller::DepthAttachmentDescriptor& des) const { + const impeller::PipelineDepthAttachment& des) const { return des.GetHash(); } }; template <> -struct hash { +struct hash { constexpr std::size_t operator()( - const impeller::StencilAttachmentDescriptor& des) const { + const impeller::PipelineStencilAttachment& des) const { return des.GetHash(); } }; diff --git a/engine/src/flutter/impeller/compositor/formats_metal.h b/engine/src/flutter/impeller/compositor/formats_metal.h index e0acf04462..e713b841f2 100644 --- a/engine/src/flutter/impeller/compositor/formats_metal.h +++ b/engine/src/flutter/impeller/compositor/formats_metal.h @@ -251,12 +251,12 @@ constexpr MTLClearColor ToMTLClearColor(const Color& color) { MTLRenderPipelineColorAttachmentDescriptor* ToMTLRenderPipelineColorAttachmentDescriptor( - ColorAttachmentDescriptor descriptor); + PipelineColorAttachment descriptor); MTLDepthStencilDescriptor* ToMTLDepthStencilDescriptor( - std::optional depth, - std::optional front, - std::optional back); + std::optional depth, + std::optional front, + std::optional back); MTLTextureDescriptor* ToMTLTextureDescriptor(const TextureDescriptor& desc); diff --git a/engine/src/flutter/impeller/compositor/formats_metal.mm b/engine/src/flutter/impeller/compositor/formats_metal.mm index d0bffb5b79..b3b7b472a1 100644 --- a/engine/src/flutter/impeller/compositor/formats_metal.mm +++ b/engine/src/flutter/impeller/compositor/formats_metal.mm @@ -12,7 +12,7 @@ namespace impeller { MTLRenderPipelineColorAttachmentDescriptor* ToMTLRenderPipelineColorAttachmentDescriptor( - ColorAttachmentDescriptor descriptor) { + PipelineColorAttachment descriptor) { auto des = [[MTLRenderPipelineColorAttachmentDescriptor alloc] init]; des.pixelFormat = ToMTLPixelFormat(descriptor.format); @@ -35,7 +35,7 @@ ToMTLRenderPipelineColorAttachmentDescriptor( } MTLStencilDescriptor* ToMTLStencilDescriptor( - const StencilAttachmentDescriptor& descriptor) { + const PipelineStencilAttachment& descriptor) { auto des = [[MTLStencilDescriptor alloc] init]; des.stencilCompareFunction = ToMTLCompareFunction(descriptor.stencil_compare); des.stencilFailureOperation = @@ -51,11 +51,11 @@ MTLStencilDescriptor* ToMTLStencilDescriptor( } MTLDepthStencilDescriptor* ToMTLDepthStencilDescriptor( - std::optional depth, - std::optional front, - std::optional back) { + std::optional depth, + std::optional front, + std::optional back) { if (!depth) { - depth = DepthAttachmentDescriptor{ + depth = PipelineDepthAttachment{ // Always pass the depth test. .depth_compare = CompareFunction::kAlways, .depth_write_enabled = false, diff --git a/engine/src/flutter/impeller/compositor/pipeline_builder.h b/engine/src/flutter/impeller/compositor/pipeline_builder.h index cfc110b32b..dd5dd22e08 100644 --- a/engine/src/flutter/impeller/compositor/pipeline_builder.h +++ b/engine/src/flutter/impeller/compositor/pipeline_builder.h @@ -84,7 +84,7 @@ struct PipelineBuilder { // 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. - ColorAttachmentDescriptor color0; + PipelineColorAttachment color0; color0.format = PixelFormat::kB8G8R8A8_UNormInt; desc.SetColorAttachmentDescriptor(0u, std::move(color0)); } diff --git a/engine/src/flutter/impeller/compositor/pipeline_descriptor.h b/engine/src/flutter/impeller/compositor/pipeline_descriptor.h index f81da73fe1..0e60d4585c 100644 --- a/engine/src/flutter/impeller/compositor/pipeline_descriptor.h +++ b/engine/src/flutter/impeller/compositor/pipeline_descriptor.h @@ -42,20 +42,20 @@ class PipelineDescriptor final : public Comparable { PipelineDescriptor& SetColorAttachmentDescriptor( size_t index, - ColorAttachmentDescriptor desc); + PipelineColorAttachment desc); - const ColorAttachmentDescriptor* GetColorAttachmentDescriptor( + const PipelineColorAttachment* GetColorAttachmentDescriptor( size_t index) const; PipelineDescriptor& SetDepthStencilAttachmentDescriptor( - DepthAttachmentDescriptor desc); + PipelineDepthAttachment desc); PipelineDescriptor& SetStencilAttachmentDescriptors( - StencilAttachmentDescriptor front_and_back); + PipelineStencilAttachment front_and_back); PipelineDescriptor& SetStencilAttachmentDescriptors( - StencilAttachmentDescriptor front, - StencilAttachmentDescriptor back); + PipelineStencilAttachment front, + PipelineStencilAttachment back); PipelineDescriptor& SetDepthPixelFormat(PixelFormat format); @@ -76,15 +76,13 @@ class PipelineDescriptor final : public Comparable { std::string label_; size_t sample_count_ = 1; std::map> entrypoints_; - std::map color_attachment_descriptors_; + std::map color_attachment_descriptors_; std::shared_ptr vertex_descriptor_; PixelFormat depth_pixel_format_ = PixelFormat::kUnknown; PixelFormat stencil_pixel_format_ = PixelFormat::kUnknown; - std::optional depth_attachment_descriptor_; - std::optional - front_stencil_attachment_descriptor_; - std::optional - back_stencil_attachment_descriptor_; + std::optional depth_attachment_descriptor_; + std::optional front_stencil_attachment_descriptor_; + std::optional back_stencil_attachment_descriptor_; }; } // namespace impeller diff --git a/engine/src/flutter/impeller/compositor/pipeline_descriptor.mm b/engine/src/flutter/impeller/compositor/pipeline_descriptor.mm index b743948744..91fc29bf0f 100644 --- a/engine/src/flutter/impeller/compositor/pipeline_descriptor.mm +++ b/engine/src/flutter/impeller/compositor/pipeline_descriptor.mm @@ -89,13 +89,13 @@ PipelineDescriptor& PipelineDescriptor::SetVertexDescriptor( PipelineDescriptor& PipelineDescriptor::SetColorAttachmentDescriptor( size_t index, - ColorAttachmentDescriptor desc) { + PipelineColorAttachment desc) { color_attachment_descriptors_[index] = std::move(desc); return *this; } -const ColorAttachmentDescriptor* -PipelineDescriptor::GetColorAttachmentDescriptor(size_t index) const { +const PipelineColorAttachment* PipelineDescriptor::GetColorAttachmentDescriptor( + size_t index) const { auto found = color_attachment_descriptors_.find(index); return found == color_attachment_descriptors_.end() ? nullptr : &found->second; @@ -114,19 +114,19 @@ PipelineDescriptor& PipelineDescriptor::SetStencilPixelFormat( } PipelineDescriptor& PipelineDescriptor::SetDepthStencilAttachmentDescriptor( - DepthAttachmentDescriptor desc) { + PipelineDepthAttachment desc) { depth_attachment_descriptor_ = desc; return *this; } PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors( - StencilAttachmentDescriptor front_and_back) { + PipelineStencilAttachment front_and_back) { return SetStencilAttachmentDescriptors(front_and_back, front_and_back); } PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors( - StencilAttachmentDescriptor front, - StencilAttachmentDescriptor back) { + PipelineStencilAttachment front, + PipelineStencilAttachment back) { front_stencil_attachment_descriptor_ = front; back_stencil_attachment_descriptor_ = back; return *this;