diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 428b6ccbb484f..07fae56e3a32d 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -56,7 +56,7 @@ TEST_F(AiksTest, CanRenderImage) { auto image = std::make_shared(CreateTextureForFixture("kalimba.jpg")); paint.color = Color::Red(); canvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint); - // ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } TEST_F(AiksTest, DISABLED_CanRenderImageRect) { @@ -122,8 +122,8 @@ TEST_F(AiksTest, CanRenderGroupOpacity) { canvas.SaveLayer(alpha); canvas.DrawRect({000, 000, 100, 100}, red); - // canvas.DrawRect({020, 020, 100, 100}, green); - // canvas.DrawRect({040, 040, 100, 100}, blue); + canvas.DrawRect({020, 020, 100, 100}, green); + canvas.DrawRect({040, 040, 100, 100}, blue); canvas.Restore(); diff --git a/impeller/aiks/canvas_pass.cc b/impeller/aiks/canvas_pass.cc index 1c534133a8f6f..ad3aa1fb52892 100644 --- a/impeller/aiks/canvas_pass.cc +++ b/impeller/aiks/canvas_pass.cc @@ -104,6 +104,8 @@ bool CanvasPass::Render(ContentRenderer& renderer, auto sub_command_buffer = context->CreateRenderCommandBuffer(); + sub_command_buffer->SetLabel("Offscreen Command Buffer"); + if (!sub_command_buffer) { return false; } @@ -124,7 +126,9 @@ bool CanvasPass::Render(ContentRenderer& renderer, return false; } - sub_command_buffer->SubmitCommands(); + if (!sub_command_buffer->SubmitCommands()) { + return false; + } auto offscreen_texture_contents = std::make_shared(); offscreen_texture_contents->SetTexture( diff --git a/impeller/entity/contents.cc b/impeller/entity/contents.cc index 9d15c959e6cbe..3bf1c0daba8a9 100644 --- a/impeller/entity/contents.cc +++ b/impeller/entity/contents.cc @@ -87,8 +87,8 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer, cmd.label = "LinearGradientFill"; cmd.pipeline = renderer.GetGradientFillPipeline(); cmd.stencil_reference = entity.GetStencilDepth(); - cmd.BindVertices(vertices_builder.CreateVertexBuffer( - *renderer.GetContext()->GetPermanentsAllocator())); + cmd.BindVertices( + vertices_builder.CreateVertexBuffer(pass.GetTransientsBuffer())); cmd.primitive_type = PrimitiveType::kTriangle; FS::BindGradientInfo( cmd, pass.GetTransientsBuffer().EmplaceUniform(gradient_info)); diff --git a/impeller/entity/shaders/texture_fill.frag b/impeller/entity/shaders/texture_fill.frag index 8c12a8be15fb7..9c4dd1ec58b30 100644 --- a/impeller/entity/shaders/texture_fill.frag +++ b/impeller/entity/shaders/texture_fill.frag @@ -9,5 +9,6 @@ in vec2 v_texture_coords; out vec4 frag_color; void main() { - frag_color = texture(texture_sampler, v_texture_coords); + vec4 sampled = texture(texture_sampler, v_texture_coords); + frag_color = sampled; } diff --git a/impeller/geometry/size.h b/impeller/geometry/size.h index 2c24c05456c9a..450f11b19a4de 100644 --- a/impeller/geometry/size.h +++ b/impeller/geometry/size.h @@ -33,10 +33,15 @@ struct TSize { std::numeric_limits::max()}; } - constexpr TSize operator*(Type scale) const { + constexpr TSize operator*(Scalar scale) const { return {width * scale, height * scale}; } + constexpr TSize operator/(Scalar scale) const { + return {static_cast(width) / scale, + static_cast(height) / scale}; + } + constexpr bool operator==(const TSize& s) const { return s.width == width && s.height == height; } diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.h b/impeller/renderer/backend/metal/command_buffer_mtl.h index f9a27f15d0024..d2e5ee31bab51 100644 --- a/impeller/renderer/backend/metal/command_buffer_mtl.h +++ b/impeller/renderer/backend/metal/command_buffer_mtl.h @@ -26,11 +26,14 @@ class CommandBufferMTL final : public CommandBuffer { CommandBufferMTL(id queue); + // |CommandBuffer| + void SetLabel(const std::string& label) const override; + // |CommandBuffer| bool IsValid() const override; // |CommandBuffer| - void SubmitCommands(CompletionCallback callback) override; + bool SubmitCommands(CompletionCallback callback) override; // |CommandBuffer| void ReserveSpotInQueue() override; diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.mm b/impeller/renderer/backend/metal/command_buffer_mtl.mm index 8c55ae10a0119..672edfa0a36d2 100644 --- a/impeller/renderer/backend/metal/command_buffer_mtl.mm +++ b/impeller/renderer/backend/metal/command_buffer_mtl.mm @@ -22,6 +22,14 @@ return is_valid_; } +void CommandBufferMTL::SetLabel(const std::string& label) const { + if (label.empty()) { + return; + } + + [buffer_ setLabel:@(label.data())]; +} + static CommandBuffer::Status ToCommitResult(MTLCommandBufferStatus status) { switch (status) { case MTLCommandBufferStatusCompleted: @@ -34,13 +42,13 @@ return CommandBufferMTL::Status::kError; } -void CommandBufferMTL::SubmitCommands(CompletionCallback callback) { +bool CommandBufferMTL::SubmitCommands(CompletionCallback callback) { if (!buffer_) { // Already committed. This is caller error. if (callback) { callback(Status::kError); } - return; + return false; } if (callback) { @@ -51,6 +59,7 @@ [buffer_ commit]; buffer_ = nil; + return true; } void CommandBufferMTL::ReserveSpotInQueue() { diff --git a/impeller/renderer/command_buffer.cc b/impeller/renderer/command_buffer.cc index 73f4b71c70c0b..51ecf9b9dffe0 100644 --- a/impeller/renderer/command_buffer.cc +++ b/impeller/renderer/command_buffer.cc @@ -10,8 +10,8 @@ CommandBuffer::CommandBuffer() = default; CommandBuffer::~CommandBuffer() = default; -void CommandBuffer::SubmitCommands() { - SubmitCommands(nullptr); +bool CommandBuffer::SubmitCommands() { + return SubmitCommands(nullptr); } } // namespace impeller diff --git a/impeller/renderer/command_buffer.h b/impeller/renderer/command_buffer.h index c377baa3fbd05..10ac6a65a4247 100644 --- a/impeller/renderer/command_buffer.h +++ b/impeller/renderer/command_buffer.h @@ -41,6 +41,8 @@ class CommandBuffer { virtual bool IsValid() const = 0; + virtual void SetLabel(const std::string& label) const = 0; + //---------------------------------------------------------------------------- /// @brief Schedule the command encoded by render passes within this /// command buffer on the GPU. @@ -49,9 +51,9 @@ class CommandBuffer { /// /// @param[in] callback The completion callback. /// - virtual void SubmitCommands(CompletionCallback callback) = 0; + [[nodiscard]] virtual bool SubmitCommands(CompletionCallback callback) = 0; - void SubmitCommands(); + [[nodiscard]] bool SubmitCommands(); virtual void ReserveSpotInQueue() = 0; diff --git a/impeller/renderer/formats.h b/impeller/renderer/formats.h index 7088e16dcba43..10608fa8bea1a 100644 --- a/impeller/renderer/formats.h +++ b/impeller/renderer/formats.h @@ -138,7 +138,7 @@ enum class ColorWriteMask : uint64_t { kGreen = 1 << 1, kBlue = 1 << 2, kAlpha = 1 << 3, - kAll = kRed | kGreen | kBlue, + kAll = kRed | kGreen | kBlue | kAlpha, }; constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) { @@ -163,7 +163,7 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) { /// @brief Describe the color attachment that will be used with this /// pipeline. /// -/// Blending at specific color attachments follows the pseudocode: +/// Blending at specific color attachments follows the pseudo-code: /// ``` /// if (blending_enabled) { /// final_color.rgb = (src_color_blend_factor * new_color.rgb) @@ -248,7 +248,7 @@ enum class StencilOperation { kDecrementClamp, /// Perform a logical bitwise invert on the current stencil value. kInvert, - /// Increment the current stencil value by 1. If at maxium, set to zero. + /// Increment the current stencil value by 1. If at maximum, set to zero. kIncrementWrap, /// Decrement the current stencil value by 1. If at zero, set to maximum. kDecrementWrap, diff --git a/impeller/renderer/render_target.cc b/impeller/renderer/render_target.cc index 0fabd12ced91c..922f81a71ec82 100644 --- a/impeller/renderer/render_target.cc +++ b/impeller/renderer/render_target.cc @@ -4,6 +4,7 @@ #include "impeller/renderer/render_target.h" +#include "impeller/base/strings.h" #include "impeller/renderer/allocator.h" #include "impeller/renderer/context.h" #include "impeller/renderer/texture.h" @@ -110,7 +111,7 @@ RenderTarget RenderTarget::CreateOffscreen(const Context& context, return {}; } - color0.texture->SetLabel(label); + color0.texture->SetLabel(SPrintF("%sColorTexture", label.c_str())); StencilAttachment stencil0; stencil0.load_action = LoadAction::kClear; @@ -123,7 +124,7 @@ RenderTarget RenderTarget::CreateOffscreen(const Context& context, return {}; } - stencil0.texture->SetLabel(label); + stencil0.texture->SetLabel(SPrintF("%sStencilTexture", label.c_str())); RenderTarget target; target.SetColorAttachment(std::move(color0), 0u); diff --git a/impeller/renderer/renderer.cc b/impeller/renderer/renderer.cc index f7e5662f99f50..2a77090a2cb47 100644 --- a/impeller/renderer/renderer.cc +++ b/impeller/renderer/renderer.cc @@ -45,6 +45,8 @@ bool Renderer::Render(const Surface& surface, return false; } + command_buffer->SetLabel("Onscreen Command Buffer"); + auto render_pass = command_buffer->CreateRenderPass(surface.GetTargetRenderPassDescriptor()); if (!render_pass) { @@ -63,15 +65,13 @@ bool Renderer::Render(const Surface& surface, return false; } - command_buffer->SubmitCommands( + return command_buffer->SubmitCommands( [sema = frames_in_flight_sema_](CommandBuffer::Status result) { sema->Signal(); if (result != CommandBuffer::Status::kCompleted) { FML_LOG(ERROR) << "Could not commit command buffer."; } }); - - return true; } std::shared_ptr Renderer::GetContext() const {