Skip to content

Commit

Permalink
[Impeller] Avoid errors due to triangle fans usage on Molten. (flutte…
Browse files Browse the repository at this point in the history
…r#56321)

Added the test case for flutter/flutter#157885 to the corpus but Jonah fixed it in flutter#56310.

Fixes flutter/flutter#158024 which is more of an inconvenience on macOS.
  • Loading branch information
chinmaygarde authored Nov 6, 2024
1 parent 20ea348 commit 78f9dcf
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
80 changes: 78 additions & 2 deletions impeller/display_list/aiks_dl_text_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "display_list/dl_tile_mode.h"
#include "display_list/effects/dl_color_source.h"
#include "display_list/effects/dl_mask_filter.h"
#include "flutter/impeller/display_list/aiks_unittests.h"

#include "flutter/display_list/dl_builder.h"
#include "flutter/display_list/dl_color.h"
#include "flutter/display_list/dl_paint.h"
#include "flutter/fml/build_config.h"
#include "flutter/impeller/display_list/aiks_unittests.h"
#include "flutter/testing/testing.h"
#include "impeller/geometry/matrix.h"
#include "impeller/typographer/backends/skia/text_frame_skia.h"
Expand Down Expand Up @@ -483,5 +483,81 @@ TEST_P(AiksTest, TextForegroundShaderWithTransform) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

// Regression test for https://github.com/flutter/flutter/issues/157885.
TEST_P(AiksTest, DifferenceClipsMustRenderIdenticallyAcrossBackends) {
DisplayListBuilder builder;

DlPaint paint;
DlColor clear_color(1.0, 0.5, 0.5, 0.5, DlColorSpace::kSRGB);
paint.setColor(clear_color);
builder.DrawPaint(paint);

DlMatrix identity = {
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
};
builder.Save();
builder.Transform(identity);

DlRect frame = DlRect::MakeLTRB(1.0, 1.0, 1278.0, 763.0);
DlColor white(1.0, 1.0, 1.0, 1.0, DlColorSpace::kSRGB);
paint.setColor(white);
builder.DrawRect(frame, paint);

builder.Save();
builder.ClipRect(frame, DlCanvas::ClipOp::kIntersect);

DlMatrix rect_xform = {
0.8241262, 0.56640625, 0.0, 0.0, -0.56640625, 0.8241262, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 271.1137, 489.4733, 0.0, 1.0,
};
builder.Save();
builder.Transform(rect_xform);

DlRect rect = DlRect::MakeLTRB(0.0, 0.0, 100.0, 100.0);
DlColor bluish(1.0, 0.184, 0.501, 0.929, DlColorSpace::kSRGB);
paint.setColor(bluish);
DlRoundRect rrect = DlRoundRect::MakeRectRadius(rect, 18.0);
builder.DrawRoundRect(rrect, paint);

builder.Save();
builder.ClipRect(rect, DlCanvas::ClipOp::kIntersect);
builder.Restore();

builder.Restore();

DlMatrix path_xform = {
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0, 675.0, 279.5, 0.0, 1.0,
};
builder.Save();
builder.Transform(path_xform);

SkPath path;
path.moveTo(87.5, 349.5);
path.lineTo(25.0, 29.5);
path.lineTo(150.0, 118.0);
path.lineTo(25.0, 118.0);
path.lineTo(150.0, 29.5);
path.close();

DlColor fill_color(1.0, 1.0, 0.0, 0.0, DlColorSpace::kSRGB);
DlColor stroke_color(1.0, 0.0, 0.0, 0.0, DlColorSpace::kSRGB);
paint.setColor(fill_color);
paint.setDrawStyle(DlDrawStyle::kFill);
builder.DrawPath(DlPath(path), paint);

paint.setColor(stroke_color);
paint.setStrokeWidth(2.0);
paint.setDrawStyle(DlDrawStyle::kStroke);
builder.DrawPath(path, paint);

builder.Restore();
builder.Restore();
builder.Restore();

ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

} // namespace testing
} // namespace impeller
8 changes: 7 additions & 1 deletion impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ bool CapabilitiesVK::SetPhysicalDevice(
ISize{device_properties_.limits.maxFramebufferWidth,
device_properties_.limits.maxFramebufferHeight};

// Molten, Vulkan on Metal, cannot support triangle fans because Metal doesn't
// support triangle fans.
// See VUID-VkPipelineInputAssemblyStateCreateInfo-triangleFans-04452.
has_triangle_fans_ =
!HasExtension(OptionalDeviceExtensionVK::kVKKHRPortabilitySubset);

return true;
}

Expand Down Expand Up @@ -746,7 +752,7 @@ CapabilitiesVK::GetSupportedFRCRate(CompressionType compression_type,
}

bool CapabilitiesVK::SupportsTriangleFan() const {
return true;
return has_triangle_fans_;
}

ISize CapabilitiesVK::GetMaximumRenderPassAttachmentSize() const {
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/capabilities_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class CapabilitiesVK final : public Capabilities,
bool supports_device_transient_textures_ = false;
bool supports_texture_fixed_rate_compression_ = false;
ISize max_render_pass_attachment_size_ = ISize{0, 0};
bool has_triangle_fans_ = true;
bool is_valid_ = false;

// The embedder.h API is responsible for providing the instance and device
Expand Down
3 changes: 3 additions & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ impeller_Play_AiksTest_CoverageOriginShouldBeAccountedForInSubpasses_Vulkan.png
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_Metal.png
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_OpenGLES.png
impeller_Play_AiksTest_DestructiveBlendColorFilterFloodsClip_Vulkan.png
impeller_Play_AiksTest_DifferenceClipsMustRenderIdenticallyAcrossBackends_Metal.png
impeller_Play_AiksTest_DifferenceClipsMustRenderIdenticallyAcrossBackends_OpenGLES.png
impeller_Play_AiksTest_DifferenceClipsMustRenderIdenticallyAcrossBackends_Vulkan.png
impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_Metal.png
impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_OpenGLES.png
impeller_Play_AiksTest_DispatcherDoesNotCullPerspectiveTransformedChildDisplayLists_Vulkan.png
Expand Down

0 comments on commit 78f9dcf

Please sign in to comment.