Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 09c3166

Browse files
author
Jonah Williams
authored
[Impeller] force render pass construction on all backends to ensure image layout is transitioned/render pass state setup. (#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.
1 parent a190775 commit 09c3166

File tree

3 files changed

+96
-185
lines changed

3 files changed

+96
-185
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,28 @@ TEST_P(AiksTest, CanPictureConvertToImage) {
503503
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
504504
}
505505

506+
// Regression test for https://github.com/flutter/flutter/issues/142358 .
507+
// Without a change to force render pass construction the image is left in an
508+
// undefined layout and triggers a validation error.
509+
TEST_P(AiksTest, CanEmptyPictureConvertToImage) {
510+
Canvas recorder_canvas;
511+
512+
Canvas canvas;
513+
AiksContext renderer(GetContext(), nullptr);
514+
Paint paint;
515+
paint.color = Color::BlackTransparent();
516+
canvas.DrawPaint(paint);
517+
Picture picture = recorder_canvas.EndRecordingAsPicture();
518+
auto image = picture.ToImage(renderer, ISize{1000, 1000});
519+
if (image) {
520+
canvas.DrawImage(image, Point(), Paint());
521+
paint.color = Color{0.1, 0.1, 0.1, 0.2};
522+
canvas.DrawRect(Rect::MakeSize(ISize{1000, 1000}), paint);
523+
}
524+
525+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
526+
}
527+
506528
TEST_P(AiksTest, BlendModeShouldCoverWholeScreen) {
507529
Canvas canvas;
508530
Paint paint;

impeller/entity/entity_pass.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,10 @@ bool EntityPass::OnRender(
901901
}
902902
auto clear_color_size = pass_target.GetRenderTarget().GetRenderTargetSize();
903903

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

0 commit comments

Comments
 (0)