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

Commit 452b24c

Browse files
author
auto-submit[bot]
committed
Revert "[Impeller] adds a plus advanced blend for f16 pixel formats (#51589)"
This reverts commit 467b801.
1 parent cd4b8cc commit 452b24c

30 files changed

+179
-364
lines changed

display_list/testing/dl_test_surface_metal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ sk_sp<DlImage> DlMetalSurfaceProvider::MakeImpellerImage(
115115

116116
void DlMetalSurfaceProvider::InitScreenShotter() const {
117117
if (!snapshotter_) {
118-
snapshotter_.reset(new MetalScreenshotter(/*enable_wide_gamut=*/false));
118+
snapshotter_.reset(new MetalScreenshotter());
119119
auto typographer = impeller::TypographerContextSkia::Make();
120120
aiks_context_.reset(new impeller::AiksContext(
121121
snapshotter_->GetPlayground().GetContext(), typographer));

impeller/aiks/aiks_unittests.cc

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,76 +1102,6 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) {
11021102
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
11031103
}
11041104

1105-
// This makes sure the WideGamut named tests use 16bit float pixel format.
1106-
TEST_P(AiksTest, F16WideGamut) {
1107-
if (GetParam() != PlaygroundBackend::kMetal) {
1108-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
1109-
}
1110-
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1111-
PixelFormat::kR16G16B16A16Float);
1112-
EXPECT_FALSE(IsAlphaClampedToOne(
1113-
GetContext()->GetCapabilities()->GetDefaultColorFormat()));
1114-
}
1115-
1116-
TEST_P(AiksTest, NotF16) {
1117-
EXPECT_TRUE(IsAlphaClampedToOne(
1118-
GetContext()->GetCapabilities()->GetDefaultColorFormat()));
1119-
}
1120-
1121-
// Bug: https://github.com/flutter/flutter/issues/142549
1122-
TEST_P(AiksTest, BlendModePlusAlphaWideGamut) {
1123-
if (GetParam() != PlaygroundBackend::kMetal) {
1124-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
1125-
}
1126-
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1127-
PixelFormat::kR16G16B16A16Float);
1128-
auto texture = CreateTextureForFixture("airplane.jpg",
1129-
/*enable_mipmapping=*/true);
1130-
1131-
Canvas canvas;
1132-
canvas.Scale(GetContentScale());
1133-
canvas.DrawPaint({.color = Color(0.9, 1.0, 0.9, 1.0)});
1134-
canvas.SaveLayer({});
1135-
Paint paint;
1136-
paint.blend_mode = BlendMode::kPlus;
1137-
paint.color = Color::Red();
1138-
canvas.DrawRect(Rect::MakeXYWH(100, 100, 400, 400), paint);
1139-
paint.color = Color::White();
1140-
canvas.DrawImageRect(
1141-
std::make_shared<Image>(texture), Rect::MakeSize(texture->GetSize()),
1142-
Rect::MakeXYWH(100, 100, 400, 400).Expand(-100, -100), paint);
1143-
canvas.Restore();
1144-
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1145-
}
1146-
1147-
// Bug: https://github.com/flutter/flutter/issues/142549
1148-
TEST_P(AiksTest, BlendModePlusAlphaColorFilterWideGamut) {
1149-
if (GetParam() != PlaygroundBackend::kMetal) {
1150-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
1151-
}
1152-
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
1153-
PixelFormat::kR16G16B16A16Float);
1154-
auto texture = CreateTextureForFixture("airplane.jpg",
1155-
/*enable_mipmapping=*/true);
1156-
1157-
Canvas canvas;
1158-
canvas.Scale(GetContentScale());
1159-
canvas.DrawPaint({.color = Color(0.1, 0.2, 0.1, 1.0)});
1160-
canvas.SaveLayer({
1161-
.color_filter =
1162-
ColorFilter::MakeBlend(BlendMode::kPlus, Color(Vector4{1, 0, 0, 1})),
1163-
});
1164-
Paint paint;
1165-
paint.color = Color::Red();
1166-
canvas.DrawRect(Rect::MakeXYWH(100, 100, 400, 400), paint);
1167-
paint.color = Color::White();
1168-
canvas.DrawImageRect(
1169-
std::make_shared<Image>(texture), Rect::MakeSize(texture->GetSize()),
1170-
Rect::MakeXYWH(100, 100, 400, 400).Expand(-100, -100), paint);
1171-
canvas.Restore();
1172-
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1173-
}
1174-
11751105
TEST_P(AiksTest, ColorWheel) {
11761106
// Compare with https://fiddle.skia.org/c/@BlendModes
11771107

impeller/compiler/shader_lib/impeller/color.glsl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ f16vec4 IPHalfPremultiply(f16vec4 color) {
4646
return f16vec4(color.rgb * color.a, color.a);
4747
}
4848

49-
/// Performs the plus blend on `src` and `dst` which are premultiplied colors.
50-
//`max` determines the values the results are clamped to.
51-
f16vec4 IPHalfPlusBlend(f16vec4 src, f16vec4 dst) {
52-
float16_t min = 0.0hf;
53-
float16_t max = 1.0hf;
54-
return clamp(dst + src, min, max);
55-
}
56-
5749
#endif

impeller/core/formats.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ constexpr bool IsStencilWritable(PixelFormat format) {
138138
}
139139
}
140140

141-
/// Returns `true` if the pixel format has an implicit `clamp(x, 0, 1)` in the
142-
/// pixel format. This is important for example when performing the `Plus` blend
143-
/// where we don't want alpha values over 1.0.
144-
constexpr bool IsAlphaClampedToOne(PixelFormat pixel_format) {
145-
return !(pixel_format == PixelFormat::kR32G32B32A32Float ||
146-
pixel_format == PixelFormat::kR16G16B16A16Float);
147-
}
148-
149141
constexpr const char* PixelFormatToString(PixelFormat format) {
150142
switch (format) {
151143
case PixelFormat::kUnknown:

impeller/entity/contents/content_context.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
124124
color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
125125
break;
126126
case BlendMode::kPlus:
127-
// The kPlusAdvanced should be used instead.
128-
FML_DCHECK(IsAlphaClampedToOne(color_attachment_pixel_format));
129127
color0.dst_alpha_blend_factor = BlendFactor::kOne;
130128
color0.dst_color_blend_factor = BlendFactor::kOne;
131129
color0.src_alpha_blend_factor = BlendFactor::kOne;
@@ -326,10 +324,6 @@ ContentContext::ContentContext(
326324
framebuffer_blend_lighten_pipelines_.CreateDefault(
327325
*context_, options_trianglestrip,
328326
{static_cast<Scalar>(BlendSelectValues::kLighten), supports_decal});
329-
framebuffer_blend_plus_advanced_pipelines_.CreateDefault(
330-
*context_, options_trianglestrip,
331-
{static_cast<Scalar>(BlendSelectValues::kPlusAdvanced),
332-
supports_decal});
333327
framebuffer_blend_luminosity_pipelines_.CreateDefault(
334328
*context_, options_trianglestrip,
335329
{static_cast<Scalar>(BlendSelectValues::kLuminosity), supports_decal});
@@ -377,9 +371,6 @@ ContentContext::ContentContext(
377371
blend_lighten_pipelines_.CreateDefault(
378372
*context_, options_trianglestrip,
379373
{static_cast<Scalar>(BlendSelectValues::kLighten), supports_decal});
380-
blend_plus_advanced_pipelines_.CreateDefault(
381-
*context_, options_trianglestrip,
382-
{static_cast<Scalar>(BlendSelectValues::kPlusAdvanced), supports_decal});
383374
blend_luminosity_pipelines_.CreateDefault(
384375
*context_, options_trianglestrip,
385376
{static_cast<Scalar>(BlendSelectValues::kLuminosity), supports_decal});

impeller/entity/contents/content_context.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ using BlendHuePipeline =
197197
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
198198
using BlendLightenPipeline =
199199
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
200-
using BlendPlusAdvancedPipeline =
201-
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
202200
using BlendLuminosityPipeline =
203201
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
204202
using BlendMultiplyPipeline =
@@ -239,9 +237,6 @@ using FramebufferBlendHuePipeline =
239237
using FramebufferBlendLightenPipeline =
240238
RenderPipelineT<FramebufferBlendVertexShader,
241239
FramebufferBlendFragmentShader>;
242-
using FramebufferBlendPlusAdvancedPipeline =
243-
RenderPipelineT<FramebufferBlendVertexShader,
244-
FramebufferBlendFragmentShader>;
245240
using FramebufferBlendLuminosityPipeline =
246241
RenderPipelineT<FramebufferBlendVertexShader,
247242
FramebufferBlendFragmentShader>;
@@ -645,11 +640,6 @@ class ContentContext {
645640
return GetPipeline(blend_lighten_pipelines_, opts);
646641
}
647642

648-
std::shared_ptr<Pipeline<PipelineDescriptor>> GetBlendPlusAdvancedPipeline(
649-
ContentContextOptions opts) const {
650-
return GetPipeline(blend_plus_advanced_pipelines_, opts);
651-
}
652-
653643
std::shared_ptr<Pipeline<PipelineDescriptor>> GetBlendLuminosityPipeline(
654644
ContentContextOptions opts) const {
655645
return GetPipeline(blend_luminosity_pipelines_, opts);
@@ -735,12 +725,6 @@ class ContentContext {
735725
return GetPipeline(framebuffer_blend_lighten_pipelines_, opts);
736726
}
737727

738-
std::shared_ptr<Pipeline<PipelineDescriptor>>
739-
GetFramebufferBlendPlusAdvancedPipeline(ContentContextOptions opts) const {
740-
FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
741-
return GetPipeline(framebuffer_blend_plus_advanced_pipelines_, opts);
742-
}
743-
744728
std::shared_ptr<Pipeline<PipelineDescriptor>>
745729
GetFramebufferBlendLuminosityPipeline(ContentContextOptions opts) const {
746730
FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
@@ -1005,7 +989,6 @@ class ContentContext {
1005989
mutable Variants<BlendHardLightPipeline> blend_hardlight_pipelines_;
1006990
mutable Variants<BlendHuePipeline> blend_hue_pipelines_;
1007991
mutable Variants<BlendLightenPipeline> blend_lighten_pipelines_;
1008-
mutable Variants<BlendPlusAdvancedPipeline> blend_plus_advanced_pipelines_;
1009992
mutable Variants<BlendLuminosityPipeline> blend_luminosity_pipelines_;
1010993
mutable Variants<BlendMultiplyPipeline> blend_multiply_pipelines_;
1011994
mutable Variants<BlendOverlayPipeline> blend_overlay_pipelines_;
@@ -1031,8 +1014,6 @@ class ContentContext {
10311014
framebuffer_blend_hue_pipelines_;
10321015
mutable Variants<FramebufferBlendLightenPipeline>
10331016
framebuffer_blend_lighten_pipelines_;
1034-
mutable Variants<FramebufferBlendPlusAdvancedPipeline>
1035-
framebuffer_blend_plus_advanced_pipelines_;
10361017
mutable Variants<FramebufferBlendLuminosityPipeline>
10371018
framebuffer_blend_luminosity_pipelines_;
10381019
mutable Variants<FramebufferBlendMultiplyPipeline>

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
338338
case BlendMode::kColor:
339339
pass.SetPipeline(renderer.GetBlendColorPipeline(options));
340340
break;
341-
case BlendMode::kPlusAdvanced:
342-
pass.SetPipeline(renderer.GetBlendPlusAdvancedPipeline(options));
343-
break;
344341
case BlendMode::kLuminosity:
345342
pass.SetPipeline(renderer.GetBlendLuminosityPipeline(options));
346343
break;
@@ -586,7 +583,6 @@ void BlendFilterContents::SetBlendMode(BlendMode blend_mode) {
586583
BLEND_CASE(Hue)
587584
BLEND_CASE(Saturation)
588585
BLEND_CASE(Color)
589-
BLEND_CASE(PlusAdvanced)
590586
BLEND_CASE(Luminosity)
591587
default:
592588
FML_UNREACHABLE();
@@ -615,26 +611,19 @@ std::optional<Entity> BlendFilterContents::RenderFilter(
615611
std::nullopt, GetAbsorbOpacity(), GetAlpha());
616612
}
617613

618-
BlendMode blend_mode = blend_mode_;
619-
if (blend_mode == BlendMode::kPlus &&
620-
!IsAlphaClampedToOne(
621-
renderer.GetContext()->GetCapabilities()->GetDefaultColorFormat())) {
622-
blend_mode = BlendMode::kPlusAdvanced;
623-
}
624-
625-
if (blend_mode <= Entity::kLastPipelineBlendMode) {
626-
return PipelineBlend(inputs, renderer, entity, coverage, blend_mode,
614+
if (blend_mode_ <= Entity::kLastPipelineBlendMode) {
615+
return PipelineBlend(inputs, renderer, entity, coverage, blend_mode_,
627616
foreground_color_, GetAbsorbOpacity(), GetAlpha());
628617
}
629618

630-
if (blend_mode <= Entity::kLastAdvancedBlendMode) {
619+
if (blend_mode_ <= Entity::kLastAdvancedBlendMode) {
631620
if (inputs.size() == 1 && foreground_color_.has_value() &&
632621
GetAbsorbOpacity() == ColorFilterContents::AbsorbOpacity::kYes) {
633622
return CreateForegroundAdvancedBlend(
634623
inputs[0], renderer, entity, coverage, foreground_color_.value(),
635-
blend_mode, GetAlpha(), GetAbsorbOpacity());
624+
blend_mode_, GetAlpha(), GetAbsorbOpacity());
636625
}
637-
return advanced_blend_proc_(inputs, renderer, entity, coverage, blend_mode,
626+
return advanced_blend_proc_(inputs, renderer, entity, coverage, blend_mode_,
638627
foreground_color_, GetAbsorbOpacity(),
639628
GetAlpha());
640629
}

impeller/entity/contents/framebuffer_blend_contents.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
118118
case BlendMode::kColor:
119119
pass.SetPipeline(renderer.GetFramebufferBlendColorPipeline(options));
120120
break;
121-
case BlendMode::kPlusAdvanced:
122-
pass.SetPipeline(
123-
renderer.GetFramebufferBlendPlusAdvancedPipeline(options));
124-
break;
125121
case BlendMode::kLuminosity:
126122
pass.SetPipeline(renderer.GetFramebufferBlendLuminosityPipeline(options));
127123
break;

impeller/entity/contents/framebuffer_blend_contents.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ enum class BlendSelectValues {
2727
kHue,
2828
kSaturation,
2929
kColor,
30-
kPlusAdvanced,
3130
kLuminosity,
3231
};
3332

impeller/entity/entity_pass.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,6 @@ bool EntityPass::OnRender(
970970
/// Setup advanced blends.
971971
///
972972

973-
if (result.entity.GetBlendMode() == BlendMode::kPlus &&
974-
!IsAlphaClampedToOne(pass_context.GetPassTarget()
975-
.GetRenderTarget()
976-
.GetRenderTargetPixelFormat())) {
977-
result.entity.SetBlendMode(BlendMode::kPlusAdvanced);
978-
}
979-
980973
if (result.entity.GetBlendMode() > Entity::kLastPipelineBlendMode) {
981974
if (renderer.GetDeviceCapabilities().SupportsFramebufferFetch()) {
982975
auto src_contents = result.entity.GetContents();

impeller/entity/shaders/blending/advanced_blend.frag

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,22 @@ f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) {
3636
}
3737

3838
void main() {
39-
f16vec4 premultiplied_dst =
40-
Sample(texture_sampler_dst, // sampler
41-
v_dst_texture_coords // texture coordinates
42-
);
43-
int nblend_type = int(blend_type);
44-
45-
if (nblend_type == /*BlendSelectValues::kPlusAdvanced*/ 14) {
46-
f16vec4 premultiplied_src =
47-
Sample(texture_sampler_src, // sampler
48-
v_src_texture_coords // texture coordinates
49-
);
50-
frag_color = IPHalfPlusBlend(premultiplied_src, premultiplied_dst);
51-
} else {
52-
f16vec4 dst = IPHalfUnpremultiply(premultiplied_dst);
53-
dst *= blend_info.dst_input_alpha;
39+
f16vec4 dst =
40+
IPHalfUnpremultiply(Sample(texture_sampler_dst, // sampler
41+
v_dst_texture_coords // texture coordinates
42+
));
43+
dst *= blend_info.dst_input_alpha;
44+
f16vec4 src = blend_info.color_factor > 0.0hf
45+
? blend_info.color
46+
: IPHalfUnpremultiply(Sample(
47+
texture_sampler_src, // sampler
48+
v_src_texture_coords // texture coordinates
49+
));
50+
if (blend_info.color_factor == 0.0hf) {
51+
src.a *= blend_info.src_input_alpha;
52+
}
5453

55-
f16vec4 src = blend_info.color_factor > 0.0hf
56-
? blend_info.color
57-
: IPHalfUnpremultiply(Sample(
58-
texture_sampler_src, // sampler
59-
v_src_texture_coords // texture coordinates
60-
));
61-
if (blend_info.color_factor == 0.0hf) {
62-
src.a *= blend_info.src_input_alpha;
63-
}
54+
f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, int(blend_type));
6455

65-
f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, nblend_type);
66-
frag_color = IPApplyBlendedColor(dst, src, blend_result);
67-
}
56+
frag_color = IPApplyBlendedColor(dst, src, blend_result);
6857
}

impeller/entity/shaders/blending/blend_select.glsl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// kHue,
2121
// kSaturation,
2222
// kColor,
23-
// kPlusAdvanced,
2423
// kLuminosity,
2524
// Note, this isn't a switch as GLSL ES 1.0 does not support them.
2625
f16vec3 AdvancedBlend(f16vec3 dst, f16vec3 src, int blend_type) {
@@ -66,9 +65,7 @@ f16vec3 AdvancedBlend(f16vec3 dst, f16vec3 src, int blend_type) {
6665
if (blend_type == 13) {
6766
return IPBlendColor(dst, src);
6867
}
69-
// 14 is `PlusAdvanced`, it's handled in advanced_blend.frag and
70-
// framebuffer_blend.frag.
71-
if (blend_type == 15) {
68+
if (blend_type == 14) {
7269
return IPBlendLuminosity(dst, src);
7370
}
7471
return f16vec3(0.0hf);

impeller/entity/shaders/blending/framebuffer_blend.frag

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,14 @@ vec4 Sample(sampler2D texture_sampler, vec2 texture_coords) {
4343
}
4444

4545
void main() {
46-
f16vec4 premultiplied_dst = f16vec4(ReadDestination());
47-
f16vec4 premultiplied_src =
46+
f16vec4 dst = IPHalfUnpremultiply(f16vec4(ReadDestination()));
47+
f16vec4 src = IPHalfUnpremultiply(
4848
f16vec4(Sample(texture_sampler_src, // sampler
4949
v_src_texture_coords // texture coordinates
50-
));
51-
int nblend_type = int(blend_type);
52-
53-
if (nblend_type == /*BlendSelectValues::kPlusAdvanced*/ 14) {
54-
frag_color = IPHalfPlusBlend(premultiplied_src, premultiplied_dst);
55-
} else {
56-
f16vec4 dst = IPHalfUnpremultiply(premultiplied_dst);
57-
f16vec4 src = IPHalfUnpremultiply(premultiplied_src);
58-
src.a *= frag_info.src_input_alpha;
59-
60-
f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, nblend_type);
61-
frag_color = IPApplyBlendedColor(dst, src, blend_result);
62-
}
50+
)));
51+
src.a *= frag_info.src_input_alpha;
52+
53+
f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, int(blend_type));
54+
55+
frag_color = IPApplyBlendedColor(dst, src, blend_result);
6356
}

impeller/geometry/color.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ Color Color::Blend(Color src, BlendMode blend_mode) const {
276276
return (src.Premultiply() * (1 - dst.alpha) +
277277
dst.Premultiply() * (1 - src.alpha))
278278
.Unpremultiply();
279-
case BlendMode::kPlusAdvanced:
280-
[[fallthrough]];
281279
case BlendMode::kPlus:
282280
// r = min(s + d, 1)
283281
return (Min(src.Premultiply() + dst.Premultiply(), 1)).Unpremultiply();

0 commit comments

Comments
 (0)