diff --git a/engine/src/flutter/impeller/compositor/BUILD.gn b/engine/src/flutter/impeller/compositor/BUILD.gn index 0a9c708e14d..a82dff11109 100644 --- a/engine/src/flutter/impeller/compositor/BUILD.gn +++ b/engine/src/flutter/impeller/compositor/BUILD.gn @@ -42,6 +42,8 @@ impeller_component("compositor") { "range.h", "render_pass.h", "render_pass.mm", + "render_pass_descriptor.h", + "render_pass_descriptor.mm", "renderer.h", "renderer.mm", "sampler.h", diff --git a/engine/src/flutter/impeller/compositor/formats.h b/engine/src/flutter/impeller/compositor/formats.h index 6de3d173be7..fac00782edb 100644 --- a/engine/src/flutter/impeller/compositor/formats.h +++ b/engine/src/flutter/impeller/compositor/formats.h @@ -6,20 +6,24 @@ #include #include +#include #include #include "flutter/fml/hash_combine.h" #include "flutter/fml/macros.h" +#include "impeller/geometry/color.h" namespace impeller { +class Texture; + enum class PixelFormat { kUnknown, - kPixelFormat_R8G8B8A8_UNormInt, - kPixelFormat_R8G8B8A8_UNormInt_SRGB, - kPixelFormat_B8G8R8A8_UNormInt, - kPixelFormat_B8G8R8A8_UNormInt_SRGB, - kPixelFormat_D32_Float_S8_UNormInt, + kR8G8B8A8_UNormInt, + kR8G8B8A8_UNormInt_SRGB, + kB8G8R8A8_UNormInt, + kB8G8R8A8_UNormInt_SRGB, + kD32_Float_S8_UNormInt, }; enum class BlendFactor { @@ -108,12 +112,12 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) { switch (format) { case PixelFormat::kUnknown: return 0u; - case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt: - case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt_SRGB: - case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt: - case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt_SRGB: + case PixelFormat::kR8G8B8A8_UNormInt: + case PixelFormat::kR8G8B8A8_UNormInt_SRGB: + case PixelFormat::kB8G8R8A8_UNormInt: + case PixelFormat::kB8G8R8A8_UNormInt_SRGB: return 4u; - case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt: + case PixelFormat::kD32_Float_S8_UNormInt: // This is an esoteric format and implementations may use 64 bits. // Impeller doesn't work with these natively and this return is only here // for completeness. The 40 bits is as documented. @@ -278,6 +282,26 @@ struct StencilAttachmentDescriptor { } }; +struct RenderPassAttachment { + std::shared_ptr texture = nullptr; + LoadAction load_action = LoadAction::kDontCare; + StoreAction store_action = StoreAction::kStore; + + constexpr operator bool() const { return static_cast(texture); } +}; + +struct ColorRenderPassAttachment : public RenderPassAttachment { + Color clear_color = Color::BlackTransparent(); +}; + +struct DepthRenderPassAttachment : public RenderPassAttachment { + double clear_depth = 0.0; +}; + +struct StencilRenderPassAttachment : public RenderPassAttachment { + uint32_t clear_stencil = 0; +}; + } // namespace impeller namespace std { diff --git a/engine/src/flutter/impeller/compositor/formats_metal.h b/engine/src/flutter/impeller/compositor/formats_metal.h index 6a4a1addaa7..e0acf04462b 100644 --- a/engine/src/flutter/impeller/compositor/formats_metal.h +++ b/engine/src/flutter/impeller/compositor/formats_metal.h @@ -21,15 +21,15 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) { switch (format) { case PixelFormat::kUnknown: return MTLPixelFormatInvalid; - case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt: + case PixelFormat::kB8G8R8A8_UNormInt: return MTLPixelFormatBGRA8Unorm; - case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt_SRGB: + case PixelFormat::kB8G8R8A8_UNormInt_SRGB: return MTLPixelFormatBGRA8Unorm_sRGB; - case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt: + case PixelFormat::kD32_Float_S8_UNormInt: return MTLPixelFormatDepth32Float_Stencil8; - case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt: + case PixelFormat::kR8G8B8A8_UNormInt: return MTLPixelFormatRGBA8Unorm; - case PixelFormat::kPixelFormat_R8G8B8A8_UNormInt_SRGB: + case PixelFormat::kR8G8B8A8_UNormInt_SRGB: return MTLPixelFormatRGBA8Unorm_sRGB; } return MTLPixelFormatInvalid; diff --git a/engine/src/flutter/impeller/compositor/pipeline_builder.h b/engine/src/flutter/impeller/compositor/pipeline_builder.h index a0f7513686f..cfc110b32b6 100644 --- a/engine/src/flutter/impeller/compositor/pipeline_builder.h +++ b/engine/src/flutter/impeller/compositor/pipeline_builder.h @@ -85,7 +85,7 @@ struct PipelineBuilder { // 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; - color0.format = PixelFormat::kPixelFormat_B8G8R8A8_UNormInt; + color0.format = PixelFormat::kB8G8R8A8_UNormInt; desc.SetColorAttachmentDescriptor(0u, std::move(color0)); } diff --git a/engine/src/flutter/impeller/compositor/render_pass.h b/engine/src/flutter/impeller/compositor/render_pass.h index 67d405ab7ce..bf1129d9866 100644 --- a/engine/src/flutter/impeller/compositor/render_pass.h +++ b/engine/src/flutter/impeller/compositor/render_pass.h @@ -13,6 +13,7 @@ #include "impeller/compositor/command.h" #include "impeller/compositor/formats.h" #include "impeller/compositor/host_buffer.h" +#include "impeller/compositor/render_pass_descriptor.h" #include "impeller/compositor/texture.h" #include "impeller/geometry/color.h" #include "impeller/geometry/size.h" @@ -21,53 +22,6 @@ namespace impeller { class CommandBuffer; -struct RenderPassAttachment { - std::shared_ptr texture; - LoadAction load_action = LoadAction::kDontCare; - StoreAction store_action = StoreAction::kStore; - - constexpr operator bool() const { return static_cast(texture); } -}; - -struct ColorRenderPassAttachment : public RenderPassAttachment { - Color clear_color = Color::BlackTransparent(); -}; - -struct DepthRenderPassAttachment : public RenderPassAttachment { - double clear_depth = 0.0; -}; - -struct StencilRenderPassAttachment : public RenderPassAttachment { - uint32_t clear_stencil = 0; -}; - -class RenderPassDescriptor { - public: - RenderPassDescriptor(); - - ~RenderPassDescriptor(); - - bool HasColorAttachment(size_t index) const; - - std::optional GetColorAttachmentSize(size_t index) const; - - RenderPassDescriptor& SetColorAttachment(ColorRenderPassAttachment attachment, - size_t index); - - RenderPassDescriptor& SetDepthAttachment( - DepthRenderPassAttachment attachment); - - RenderPassDescriptor& SetStencilAttachment( - StencilRenderPassAttachment attachment); - - MTLRenderPassDescriptor* ToMTLRenderPassDescriptor() const; - - private: - std::map colors_; - std::optional depth_; - std::optional stencil_; -}; - class RenderPass { public: ~RenderPass(); diff --git a/engine/src/flutter/impeller/compositor/render_pass.mm b/engine/src/flutter/impeller/compositor/render_pass.mm index d835c2ad72c..188b6e19b0b 100644 --- a/engine/src/flutter/impeller/compositor/render_pass.mm +++ b/engine/src/flutter/impeller/compositor/render_pass.mm @@ -17,53 +17,6 @@ namespace impeller { -RenderPassDescriptor::RenderPassDescriptor() = default; - -RenderPassDescriptor::~RenderPassDescriptor() = default; - -bool RenderPassDescriptor::HasColorAttachment(size_t index) const { - if (auto found = colors_.find(index); found != colors_.end()) { - return true; - } - return false; -} - -std::optional RenderPassDescriptor::GetColorAttachmentSize( - size_t index) const { - auto found = colors_.find(index); - - if (found == colors_.end()) { - return std::nullopt; - } - - return found->second.texture->GetSize(); -} - -RenderPassDescriptor& RenderPassDescriptor::SetColorAttachment( - ColorRenderPassAttachment attachment, - size_t index) { - if (attachment) { - colors_[index] = attachment; - } - return *this; -} - -RenderPassDescriptor& RenderPassDescriptor::SetDepthAttachment( - DepthRenderPassAttachment attachment) { - if (attachment) { - depth_ = std::move(attachment); - } - return *this; -} - -RenderPassDescriptor& RenderPassDescriptor::SetStencilAttachment( - StencilRenderPassAttachment attachment) { - if (attachment) { - stencil_ = std::move(attachment); - } - return *this; -} - static bool ConfigureAttachment(const RenderPassAttachment& desc, MTLRenderPassAttachmentDescriptor* attachment) { if (!desc.texture) { diff --git a/engine/src/flutter/impeller/compositor/render_pass_descriptor.h b/engine/src/flutter/impeller/compositor/render_pass_descriptor.h new file mode 100644 index 00000000000..baab8445137 --- /dev/null +++ b/engine/src/flutter/impeller/compositor/render_pass_descriptor.h @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include +#include + +#include + +#include "flutter/fml/macros.h" +#include "impeller/compositor/formats.h" +#include "impeller/geometry/size.h" + +namespace impeller { + +class RenderPassDescriptor { + public: + RenderPassDescriptor(); + + ~RenderPassDescriptor(); + + bool HasColorAttachment(size_t index) const; + + std::optional GetColorAttachmentSize(size_t index) const; + + RenderPassDescriptor& SetColorAttachment(ColorRenderPassAttachment attachment, + size_t index); + + RenderPassDescriptor& SetDepthAttachment( + DepthRenderPassAttachment attachment); + + RenderPassDescriptor& SetStencilAttachment( + StencilRenderPassAttachment attachment); + + MTLRenderPassDescriptor* ToMTLRenderPassDescriptor() const; + + private: + std::map colors_; + std::optional depth_; + std::optional stencil_; +}; + +} // namespace impeller diff --git a/engine/src/flutter/impeller/compositor/render_pass_descriptor.mm b/engine/src/flutter/impeller/compositor/render_pass_descriptor.mm new file mode 100644 index 00000000000..b8802582e87 --- /dev/null +++ b/engine/src/flutter/impeller/compositor/render_pass_descriptor.mm @@ -0,0 +1,58 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/compositor/render_pass_descriptor.h" + +#include "impeller/compositor/texture.h" + +namespace impeller { + +RenderPassDescriptor::RenderPassDescriptor() = default; + +RenderPassDescriptor::~RenderPassDescriptor() = default; + +bool RenderPassDescriptor::HasColorAttachment(size_t index) const { + if (auto found = colors_.find(index); found != colors_.end()) { + return true; + } + return false; +} + +std::optional RenderPassDescriptor::GetColorAttachmentSize( + size_t index) const { + auto found = colors_.find(index); + + if (found == colors_.end()) { + return std::nullopt; + } + + return found->second.texture->GetSize(); +} + +RenderPassDescriptor& RenderPassDescriptor::SetColorAttachment( + ColorRenderPassAttachment attachment, + size_t index) { + if (attachment) { + colors_[index] = attachment; + } + return *this; +} + +RenderPassDescriptor& RenderPassDescriptor::SetDepthAttachment( + DepthRenderPassAttachment attachment) { + if (attachment) { + depth_ = std::move(attachment); + } + return *this; +} + +RenderPassDescriptor& RenderPassDescriptor::SetStencilAttachment( + StencilRenderPassAttachment attachment) { + if (attachment) { + stencil_ = std::move(attachment); + } + return *this; +} + +} // namespace impeller diff --git a/engine/src/flutter/impeller/playground/playground.mm b/engine/src/flutter/impeller/playground/playground.mm index 8b836e23985..1825aa1be8b 100644 --- a/engine/src/flutter/impeller/playground/playground.mm +++ b/engine/src/flutter/impeller/playground/playground.mm @@ -131,7 +131,7 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) { } TextureDescriptor color0_desc; - color0_desc.format = PixelFormat::kPixelFormat_B8G8R8A8_UNormInt; + color0_desc.format = PixelFormat::kB8G8R8A8_UNormInt; color0_desc.size = { static_cast(current_drawable.texture.width), static_cast(current_drawable.texture.height)}; @@ -181,7 +181,7 @@ std::shared_ptr Playground::CreateTextureForFixture( } auto texture_descriptor = TextureDescriptor{}; - texture_descriptor.format = PixelFormat::kPixelFormat_R8G8B8A8_UNormInt; + texture_descriptor.format = PixelFormat::kR8G8B8A8_UNormInt; texture_descriptor.size = image.GetSize(); texture_descriptor.mip_count = 1u;