Skip to content

Commit bb633ca

Browse files
chinmaygardednfield
authored andcommitted
Fix alpha writes while rendering to texture.
1 parent 398b74f commit bb633ca

File tree

12 files changed

+48
-23
lines changed

12 files changed

+48
-23
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TEST_F(AiksTest, CanRenderImage) {
5656
auto image = std::make_shared<Image>(CreateTextureForFixture("kalimba.jpg"));
5757
paint.color = Color::Red();
5858
canvas.DrawImage(image, Point::MakeXY(100.0, 100.0), paint);
59-
// ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
59+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
6060
}
6161

6262
TEST_F(AiksTest, DISABLED_CanRenderImageRect) {
@@ -122,8 +122,8 @@ TEST_F(AiksTest, CanRenderGroupOpacity) {
122122
canvas.SaveLayer(alpha);
123123

124124
canvas.DrawRect({000, 000, 100, 100}, red);
125-
// canvas.DrawRect({020, 020, 100, 100}, green);
126-
// canvas.DrawRect({040, 040, 100, 100}, blue);
125+
canvas.DrawRect({020, 020, 100, 100}, green);
126+
canvas.DrawRect({040, 040, 100, 100}, blue);
127127

128128
canvas.Restore();
129129

impeller/aiks/canvas_pass.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ bool CanvasPass::Render(ContentRenderer& renderer,
104104

105105
auto sub_command_buffer = context->CreateRenderCommandBuffer();
106106

107+
sub_command_buffer->SetLabel("Offscreen Command Buffer");
108+
107109
if (!sub_command_buffer) {
108110
return false;
109111
}
@@ -124,7 +126,9 @@ bool CanvasPass::Render(ContentRenderer& renderer,
124126
return false;
125127
}
126128

127-
sub_command_buffer->SubmitCommands();
129+
if (!sub_command_buffer->SubmitCommands()) {
130+
return false;
131+
}
128132

129133
auto offscreen_texture_contents = std::make_shared<TextureContents>();
130134
offscreen_texture_contents->SetTexture(

impeller/entity/contents.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer,
8787
cmd.label = "LinearGradientFill";
8888
cmd.pipeline = renderer.GetGradientFillPipeline();
8989
cmd.stencil_reference = entity.GetStencilDepth();
90-
cmd.BindVertices(vertices_builder.CreateVertexBuffer(
91-
*renderer.GetContext()->GetPermanentsAllocator()));
90+
cmd.BindVertices(
91+
vertices_builder.CreateVertexBuffer(pass.GetTransientsBuffer()));
9292
cmd.primitive_type = PrimitiveType::kTriangle;
9393
FS::BindGradientInfo(
9494
cmd, pass.GetTransientsBuffer().EmplaceUniform(gradient_info));

impeller/entity/shaders/texture_fill.frag

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ in vec2 v_texture_coords;
99
out vec4 frag_color;
1010

1111
void main() {
12-
frag_color = texture(texture_sampler, v_texture_coords);
12+
vec4 sampled = texture(texture_sampler, v_texture_coords);
13+
frag_color = sampled;
1314
}

impeller/geometry/size.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ struct TSize {
3333
std::numeric_limits<Type>::max()};
3434
}
3535

36-
constexpr TSize operator*(Type scale) const {
36+
constexpr TSize operator*(Scalar scale) const {
3737
return {width * scale, height * scale};
3838
}
3939

40+
constexpr TSize operator/(Scalar scale) const {
41+
return {static_cast<Scalar>(width) / scale,
42+
static_cast<Scalar>(height) / scale};
43+
}
44+
4045
constexpr bool operator==(const TSize& s) const {
4146
return s.width == width && s.height == height;
4247
}

impeller/renderer/backend/metal/command_buffer_mtl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ class CommandBufferMTL final : public CommandBuffer {
2626

2727
CommandBufferMTL(id<MTLCommandQueue> queue);
2828

29+
// |CommandBuffer|
30+
void SetLabel(const std::string& label) const override;
31+
2932
// |CommandBuffer|
3033
bool IsValid() const override;
3134

3235
// |CommandBuffer|
33-
void SubmitCommands(CompletionCallback callback) override;
36+
bool SubmitCommands(CompletionCallback callback) override;
3437

3538
// |CommandBuffer|
3639
void ReserveSpotInQueue() override;

impeller/renderer/backend/metal/command_buffer_mtl.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
return is_valid_;
2323
}
2424

25+
void CommandBufferMTL::SetLabel(const std::string& label) const {
26+
if (label.empty()) {
27+
return;
28+
}
29+
30+
[buffer_ setLabel:@(label.data())];
31+
}
32+
2533
static CommandBuffer::Status ToCommitResult(MTLCommandBufferStatus status) {
2634
switch (status) {
2735
case MTLCommandBufferStatusCompleted:
@@ -34,13 +42,13 @@
3442
return CommandBufferMTL::Status::kError;
3543
}
3644

37-
void CommandBufferMTL::SubmitCommands(CompletionCallback callback) {
45+
bool CommandBufferMTL::SubmitCommands(CompletionCallback callback) {
3846
if (!buffer_) {
3947
// Already committed. This is caller error.
4048
if (callback) {
4149
callback(Status::kError);
4250
}
43-
return;
51+
return false;
4452
}
4553

4654
if (callback) {
@@ -51,6 +59,7 @@
5159

5260
[buffer_ commit];
5361
buffer_ = nil;
62+
return true;
5463
}
5564

5665
void CommandBufferMTL::ReserveSpotInQueue() {

impeller/renderer/command_buffer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ CommandBuffer::CommandBuffer() = default;
1010

1111
CommandBuffer::~CommandBuffer() = default;
1212

13-
void CommandBuffer::SubmitCommands() {
14-
SubmitCommands(nullptr);
13+
bool CommandBuffer::SubmitCommands() {
14+
return SubmitCommands(nullptr);
1515
}
1616

1717
} // namespace impeller

impeller/renderer/command_buffer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class CommandBuffer {
4141

4242
virtual bool IsValid() const = 0;
4343

44+
virtual void SetLabel(const std::string& label) const = 0;
45+
4446
//----------------------------------------------------------------------------
4547
/// @brief Schedule the command encoded by render passes within this
4648
/// command buffer on the GPU.
@@ -49,9 +51,9 @@ class CommandBuffer {
4951
///
5052
/// @param[in] callback The completion callback.
5153
///
52-
virtual void SubmitCommands(CompletionCallback callback) = 0;
54+
[[nodiscard]] virtual bool SubmitCommands(CompletionCallback callback) = 0;
5355

54-
void SubmitCommands();
56+
[[nodiscard]] bool SubmitCommands();
5557

5658
virtual void ReserveSpotInQueue() = 0;
5759

impeller/renderer/formats.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ enum class ColorWriteMask : uint64_t {
138138
kGreen = 1 << 1,
139139
kBlue = 1 << 2,
140140
kAlpha = 1 << 3,
141-
kAll = kRed | kGreen | kBlue,
141+
kAll = kRed | kGreen | kBlue | kAlpha,
142142
};
143143

144144
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
@@ -163,7 +163,7 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
163163
/// @brief Describe the color attachment that will be used with this
164164
/// pipeline.
165165
///
166-
/// Blending at specific color attachments follows the pseudocode:
166+
/// Blending at specific color attachments follows the pseudo-code:
167167
/// ```
168168
/// if (blending_enabled) {
169169
/// final_color.rgb = (src_color_blend_factor * new_color.rgb)
@@ -248,7 +248,7 @@ enum class StencilOperation {
248248
kDecrementClamp,
249249
/// Perform a logical bitwise invert on the current stencil value.
250250
kInvert,
251-
/// Increment the current stencil value by 1. If at maxium, set to zero.
251+
/// Increment the current stencil value by 1. If at maximum, set to zero.
252252
kIncrementWrap,
253253
/// Decrement the current stencil value by 1. If at zero, set to maximum.
254254
kDecrementWrap,

0 commit comments

Comments
 (0)