diff --git a/impeller/playground/playground.mm b/impeller/playground/playground.mm index 67fe3807683e9..a0d9dcbeacf6f 100644 --- a/impeller/playground/playground.mm +++ b/impeller/playground/playground.mm @@ -140,14 +140,14 @@ static void PlaygroundKeyCallback(GLFWwindow* window, static_cast(current_drawable.texture.width), static_cast(current_drawable.texture.height)}; - RenderPassColorAttachment color0; + ColorAttachment color0; color0.texture = std::make_shared(color0_desc, current_drawable.texture); color0.clear_color = Color::SkyBlue(); color0.load_action = LoadAction::kClear; color0.store_action = StoreAction::kStore; - RenderPassDescriptor desc; + RenderTarget desc; desc.SetColorAttachment(color0, 0u); Surface surface(desc); diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.h b/impeller/renderer/backend/metal/command_buffer_mtl.h index b5551f09f3fb5..9b438455f4923 100644 --- a/impeller/renderer/backend/metal/command_buffer_mtl.h +++ b/impeller/renderer/backend/metal/command_buffer_mtl.h @@ -34,7 +34,7 @@ class CommandBufferMTL final : public CommandBuffer { // |CommandBuffer| std::shared_ptr CreateRenderPass( - const RenderPassDescriptor& desc) const override; + const RenderTarget& desc) const override; FML_DISALLOW_COPY_AND_ASSIGN(CommandBufferMTL); }; diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.mm b/impeller/renderer/backend/metal/command_buffer_mtl.mm index b6c12464aca38..5b4f7628cc39d 100644 --- a/impeller/renderer/backend/metal/command_buffer_mtl.mm +++ b/impeller/renderer/backend/metal/command_buffer_mtl.mm @@ -53,7 +53,7 @@ } std::shared_ptr CommandBufferMTL::CreateRenderPass( - const RenderPassDescriptor& desc) const { + const RenderTarget& desc) const { if (!buffer_) { return nullptr; } diff --git a/impeller/renderer/backend/metal/formats_mtl.h b/impeller/renderer/backend/metal/formats_mtl.h index 6b3f6e25c3de8..4d3d7cc6cee89 100644 --- a/impeller/renderer/backend/metal/formats_mtl.h +++ b/impeller/renderer/backend/metal/formats_mtl.h @@ -15,7 +15,7 @@ namespace impeller { -class RenderPassDescriptor; +class RenderTarget; constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) { switch (format) { diff --git a/impeller/renderer/backend/metal/render_pass_mtl.h b/impeller/renderer/backend/metal/render_pass_mtl.h index 40b92e7553701..530a60c2b0a2d 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.h +++ b/impeller/renderer/backend/metal/render_pass_mtl.h @@ -27,7 +27,7 @@ class RenderPassMTL final : public RenderPass { std::string label_; bool is_valid_ = false; - RenderPassMTL(id buffer, const RenderPassDescriptor& desc); + RenderPassMTL(id buffer, const RenderTarget& desc); // |RenderPass| bool IsValid() const override; diff --git a/impeller/renderer/backend/metal/render_pass_mtl.mm b/impeller/renderer/backend/metal/render_pass_mtl.mm index fe21cf84e50db..2a505888f293a 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.mm +++ b/impeller/renderer/backend/metal/render_pass_mtl.mm @@ -17,7 +17,7 @@ namespace impeller { -static bool ConfigureAttachment(const RenderPassAttachment& desc, +static bool ConfigureAttachment(const Attachment& desc, MTLRenderPassAttachmentDescriptor* attachment) { if (!desc.texture) { return false; @@ -30,7 +30,7 @@ static bool ConfigureAttachment(const RenderPassAttachment& desc, } static bool ConfigureColorAttachment( - const RenderPassColorAttachment& desc, + const ColorAttachment& desc, MTLRenderPassColorAttachmentDescriptor* attachment) { if (!ConfigureAttachment(desc, attachment)) { return false; @@ -40,7 +40,7 @@ static bool ConfigureColorAttachment( } static bool ConfigureDepthAttachment( - const RenderPassDepthAttachment& desc, + const DepthAttachment& desc, MTLRenderPassDepthAttachmentDescriptor* attachment) { if (!ConfigureAttachment(desc, attachment)) { return false; @@ -50,7 +50,7 @@ static bool ConfigureDepthAttachment( } static bool ConfigureStencilAttachment( - const RenderPassStencilAttachment& desc, + const StencilAttachment& desc, MTLRenderPassStencilAttachmentDescriptor* attachment) { if (!ConfigureAttachment(desc, attachment)) { return false; @@ -61,7 +61,7 @@ static bool ConfigureStencilAttachment( // TODO(csg): Move this to formats_mtl.h static MTLRenderPassDescriptor* ToMTLRenderPassDescriptor( - const RenderPassDescriptor& desc) { + const RenderTarget& desc) { auto result = [MTLRenderPassDescriptor renderPassDescriptor]; const auto& colors = desc.GetColorAttachments(); @@ -93,7 +93,7 @@ static bool ConfigureStencilAttachment( } RenderPassMTL::RenderPassMTL(id buffer, - const RenderPassDescriptor& desc) + const RenderTarget& desc) : buffer_(buffer), desc_(ToMTLRenderPassDescriptor(desc)), transients_buffer_(HostBuffer::Create()) { diff --git a/impeller/renderer/command_buffer.h b/impeller/renderer/command_buffer.h index 5108453b35112..554d595c2412f 100644 --- a/impeller/renderer/command_buffer.h +++ b/impeller/renderer/command_buffer.h @@ -13,7 +13,7 @@ namespace impeller { class Context; class RenderPass; -class RenderPassDescriptor; +class RenderTarget; //------------------------------------------------------------------------------ /// @brief A collection of encoded commands to be submitted to the GPU for @@ -59,7 +59,7 @@ class CommandBuffer { /// @return A valid render pass or null. /// virtual std::shared_ptr CreateRenderPass( - const RenderPassDescriptor& desc) const = 0; + const RenderTarget& desc) const = 0; protected: CommandBuffer(); diff --git a/impeller/renderer/formats.h b/impeller/renderer/formats.h index 59d24535f6f78..c826d0c26397e 100644 --- a/impeller/renderer/formats.h +++ b/impeller/renderer/formats.h @@ -319,7 +319,7 @@ struct PipelineStencilAttachment { } }; -struct RenderPassAttachment { +struct Attachment { std::shared_ptr texture = nullptr; LoadAction load_action = LoadAction::kDontCare; StoreAction store_action = StoreAction::kStore; @@ -327,15 +327,15 @@ struct RenderPassAttachment { constexpr operator bool() const { return static_cast(texture); } }; -struct RenderPassColorAttachment : public RenderPassAttachment { +struct ColorAttachment : public Attachment { Color clear_color = Color::BlackTransparent(); }; -struct RenderPassDepthAttachment : public RenderPassAttachment { +struct DepthAttachment : public Attachment { double clear_depth = 0.0; }; -struct RenderPassStencilAttachment : public RenderPassAttachment { +struct StencilAttachment : public Attachment { uint32_t clear_stencil = 0; }; diff --git a/impeller/renderer/render_pass.h b/impeller/renderer/render_pass.h index 42e242d7a035a..d0b2ee8c921f1 100644 --- a/impeller/renderer/render_pass.h +++ b/impeller/renderer/render_pass.h @@ -13,6 +13,13 @@ namespace impeller { class HostBuffer; class Allocator; +//------------------------------------------------------------------------------ +/// @brief Render passes encode render commands directed as one specific +/// render target into an underlying command buffer. +/// +/// Render passes can be obtained from the command buffer in which +/// the pass is meant to encode commands into. +/// class RenderPass { public: virtual ~RenderPass(); diff --git a/impeller/renderer/render_pass_descriptor.cc b/impeller/renderer/render_pass_descriptor.cc index bbd8f326b7cfc..f8dbb732cdd41 100644 --- a/impeller/renderer/render_pass_descriptor.cc +++ b/impeller/renderer/render_pass_descriptor.cc @@ -8,19 +8,18 @@ namespace impeller { -RenderPassDescriptor::RenderPassDescriptor() = default; +RenderTarget::RenderTarget() = default; -RenderPassDescriptor::~RenderPassDescriptor() = default; +RenderTarget::~RenderTarget() = default; -bool RenderPassDescriptor::HasColorAttachment(size_t index) const { +bool RenderTarget::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 { +std::optional RenderTarget::GetColorAttachmentSize(size_t index) const { auto found = colors_.find(index); if (found == colors_.end()) { @@ -30,43 +29,39 @@ std::optional RenderPassDescriptor::GetColorAttachmentSize( return found->second.texture->GetSize(); } -RenderPassDescriptor& RenderPassDescriptor::SetColorAttachment( - RenderPassColorAttachment attachment, - size_t index) { +RenderTarget& RenderTarget::SetColorAttachment(ColorAttachment attachment, + size_t index) { if (attachment) { colors_[index] = attachment; } return *this; } -RenderPassDescriptor& RenderPassDescriptor::SetDepthAttachment( - RenderPassDepthAttachment attachment) { +RenderTarget& RenderTarget::SetDepthAttachment(DepthAttachment attachment) { if (attachment) { depth_ = std::move(attachment); } return *this; } -RenderPassDescriptor& RenderPassDescriptor::SetStencilAttachment( - RenderPassStencilAttachment attachment) { +RenderTarget& RenderTarget::SetStencilAttachment(StencilAttachment attachment) { if (attachment) { stencil_ = std::move(attachment); } return *this; } -const std::map& -RenderPassDescriptor::GetColorAttachments() const { +const std::map& RenderTarget::GetColorAttachments() + const { return colors_; } -const std::optional& -RenderPassDescriptor::GetDepthAttachment() const { +const std::optional& RenderTarget::GetDepthAttachment() const { return depth_; } -const std::optional& -RenderPassDescriptor::GetStencilAttachment() const { +const std::optional& RenderTarget::GetStencilAttachment() + const { return stencil_; } diff --git a/impeller/renderer/render_pass_descriptor.h b/impeller/renderer/render_pass_descriptor.h index d0f17f1c696e2..5ace1b2aca138 100644 --- a/impeller/renderer/render_pass_descriptor.h +++ b/impeller/renderer/render_pass_descriptor.h @@ -13,37 +13,32 @@ namespace impeller { -class RenderPassDescriptor { +class RenderTarget { public: - RenderPassDescriptor(); + RenderTarget(); - ~RenderPassDescriptor(); + ~RenderTarget(); bool HasColorAttachment(size_t index) const; std::optional GetColorAttachmentSize(size_t index) const; - RenderPassDescriptor& SetColorAttachment(RenderPassColorAttachment attachment, - size_t index); + RenderTarget& SetColorAttachment(ColorAttachment attachment, size_t index); - RenderPassDescriptor& SetDepthAttachment( - RenderPassDepthAttachment attachment); + RenderTarget& SetDepthAttachment(DepthAttachment attachment); - RenderPassDescriptor& SetStencilAttachment( - RenderPassStencilAttachment attachment); + RenderTarget& SetStencilAttachment(StencilAttachment attachment); - const std::map& GetColorAttachments() - const; + const std::map& GetColorAttachments() const; - const std::optional& GetDepthAttachment() const; + const std::optional& GetDepthAttachment() const; - const std::optional& GetStencilAttachment() - const; + const std::optional& GetStencilAttachment() const; private: - std::map colors_; - std::optional depth_; - std::optional stencil_; + std::map colors_; + std::optional depth_; + std::optional stencil_; }; } // namespace impeller diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index 496637f822161..3cf50fc5f6b1b 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -198,7 +198,7 @@ TEST_F(RendererTest, CanRenderToTexture) { std::shared_ptr r2t_pass; { - RenderPassColorAttachment color0; + ColorAttachment color0; color0.load_action = LoadAction::kClear; color0.store_action = StoreAction::kStore; @@ -218,7 +218,7 @@ TEST_F(RendererTest, CanRenderToTexture) { color0.texture->SetLabel("r2t_target"); - RenderPassDescriptor r2t_desc; + RenderTarget r2t_desc; r2t_desc.SetColorAttachment(color0, 0u); auto cmd_buffer = context->CreateRenderCommandBuffer(); r2t_pass = cmd_buffer->CreateRenderPass(r2t_desc); diff --git a/impeller/renderer/surface.cc b/impeller/renderer/surface.cc index 4c699497956a9..3882d9bcda74f 100644 --- a/impeller/renderer/surface.cc +++ b/impeller/renderer/surface.cc @@ -8,8 +8,7 @@ namespace impeller { -Surface::Surface(RenderPassDescriptor target_desc) - : desc_(std::move(target_desc)) { +Surface::Surface(RenderTarget target_desc) : desc_(std::move(target_desc)) { if (auto size = desc_.GetColorAttachmentSize(0u); size.has_value()) { size_ = size.value(); } else { @@ -29,7 +28,7 @@ bool Surface::IsValid() const { return is_valid_; } -const RenderPassDescriptor& Surface::GetTargetRenderPassDescriptor() const { +const RenderTarget& Surface::GetTargetRenderPassDescriptor() const { return desc_; } diff --git a/impeller/renderer/surface.h b/impeller/renderer/surface.h index 2fb2d85a821dc..7a7515ffe4029 100644 --- a/impeller/renderer/surface.h +++ b/impeller/renderer/surface.h @@ -16,7 +16,7 @@ namespace impeller { class Surface { public: - Surface(RenderPassDescriptor target_desc); + Surface(RenderTarget target_desc); ~Surface(); @@ -24,10 +24,10 @@ class Surface { bool IsValid() const; - const RenderPassDescriptor& GetTargetRenderPassDescriptor() const; + const RenderTarget& GetTargetRenderPassDescriptor() const; private: - RenderPassDescriptor desc_; + RenderTarget desc_; ISize size_; bool is_valid_ = false;