Skip to content

Commit

Permalink
[Impeller] force render pass construction on all backends to ensure i…
Browse files Browse the repository at this point in the history
…mage layout is transitioned/render pass state setup. (flutter#50539)

Fixes flutter/flutter#142358

We rely on the render pass encoding to transition image textures from undefined to shader read layout. If an empty pass is created with no clear color, we still need to create the pass on the Vulkan backend.
  • Loading branch information
jonahwilliams authored Feb 12, 2024
1 parent a190775 commit 09c3166
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 185 deletions.
22 changes: 22 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,28 @@ TEST_P(AiksTest, CanPictureConvertToImage) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

// Regression test for https://github.com/flutter/flutter/issues/142358 .
// Without a change to force render pass construction the image is left in an
// undefined layout and triggers a validation error.
TEST_P(AiksTest, CanEmptyPictureConvertToImage) {
Canvas recorder_canvas;

Canvas canvas;
AiksContext renderer(GetContext(), nullptr);
Paint paint;
paint.color = Color::BlackTransparent();
canvas.DrawPaint(paint);
Picture picture = recorder_canvas.EndRecordingAsPicture();
auto image = picture.ToImage(renderer, ISize{1000, 1000});
if (image) {
canvas.DrawImage(image, Point(), Paint());
paint.color = Color{0.1, 0.1, 0.1, 0.2};
canvas.DrawRect(Rect::MakeSize(ISize{1000, 1000}), paint);
}

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, BlendModeShouldCoverWholeScreen) {
Canvas canvas;
Paint paint;
Expand Down
7 changes: 4 additions & 3 deletions impeller/entity/entity_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,10 @@ bool EntityPass::OnRender(
}
auto clear_color_size = pass_target.GetRenderTarget().GetRenderTargetSize();

if (!collapsed_parent_pass && GetClearColor(clear_color_size).has_value()) {
// Force the pass context to create at least one new pass if the clear color
// is present.
if (!collapsed_parent_pass) {
// Always force the pass to construct the render pass object, even if there
// is not a clear color. This ensures that the attachment textures are
// cleared/transitioned to the right state.
pass_context.GetRenderPass(pass_depth);
}

Expand Down
Loading

0 comments on commit 09c3166

Please sign in to comment.