Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] In advanced blends, unpremultiply and apply src_input_alpha only if there is no foreground color #50260

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ TEST_P(AiksTest, CanRenderColorFilterWithInvertColorsDrawPaint) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer) {
Canvas canvas;

Rect layer_rect = Rect::MakeXYWH(0, 0, 500, 500);
canvas.ClipRect(layer_rect);

canvas.SaveLayer(
{
.color_filter = ColorFilter::MakeBlend(BlendMode::kDifference,
Color(0, 1, 0, 0.5)),
},
layer_rect);

Paint paint;
canvas.DrawPaint({.color = Color::Black()});
canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300),
{.color = Color::White()});
canvas.Restore();

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

namespace {
bool GenerateMipmap(const std::shared_ptr<Context>& context,
std::shared_ptr<Texture> texture,
Expand Down
16 changes: 9 additions & 7 deletions impeller/entity/shaders/blending/advanced_blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ void main() {
v_dst_texture_coords // texture coordinates
));
dst *= blend_info.dst_input_alpha;
f16vec4 src = IPHalfUnpremultiply(
blend_info.color_factor > 0.0hf
? blend_info.color
: Sample(texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
src *= blend_info.src_input_alpha;
f16vec4 src = blend_info.color_factor > 0.0hf
? blend_info.color
: IPHalfUnpremultiply(Sample(
texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
if (blend_info.color_factor == 0.0hf) {
src.a *= blend_info.src_input_alpha;
}

f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, int(blend_type));

Expand Down
48 changes: 24 additions & 24 deletions impeller/tools/malioc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"uses_late_zs_update": false,
"variants": {
"Main": {
"fp16_arithmetic": 0,
"fp16_arithmetic": 2,
"has_stack_spilling": false,
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma"
],
"longest_path_cycles": [
0.625,
0.625,
0.578125,
0.578125,
0.21875,
0.125,
0.0,
Expand All @@ -42,10 +42,10 @@
"arith_fma"
],
"shortest_path_cycles": [
0.625,
0.625,
0.234375,
0.125,
0.53125,
0.53125,
0.203125,
0.0625,
0.0,
0.25,
0.25
Expand All @@ -55,8 +55,8 @@
"arith_fma"
],
"total_cycles": [
0.625,
0.625,
0.578125,
0.578125,
0.296875,
0.125,
0.0,
Expand All @@ -66,8 +66,8 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"work_registers_used": 24
"uniform_registers_used": 12,
"work_registers_used": 25
}
}
}
Expand Down Expand Up @@ -1423,16 +1423,16 @@
"uses_late_zs_update": false,
"variants": {
"Main": {
"fp16_arithmetic": 0,
"fp16_arithmetic": 2,
"has_stack_spilling": false,
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma"
],
"longest_path_cycles": [
0.625,
0.625,
0.578125,
0.578125,
0.265625,
0.125,
0.0,
Expand All @@ -1453,10 +1453,10 @@
"arith_fma"
],
"shortest_path_cycles": [
0.625,
0.625,
0.25,
0.125,
0.53125,
0.53125,
0.21875,
0.0625,
0.0,
0.25,
0.25
Expand All @@ -1466,8 +1466,8 @@
"arith_fma"
],
"total_cycles": [
0.625,
0.625,
0.578125,
0.578125,
0.34375,
0.125,
0.0,
Expand All @@ -1477,8 +1477,8 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 12,
"work_registers_used": 22
"uniform_registers_used": 14,
"work_registers_used": 23
}
}
},
Expand All @@ -1495,7 +1495,7 @@
"arithmetic"
],
"longest_path_cycles": [
3.630000114440918,
4.289999961853027,
2.0,
2.0
],
Expand All @@ -1516,7 +1516,7 @@
"arithmetic"
],
"total_cycles": [
4.0,
4.666666507720947,
2.0,
2.0
]
Expand Down
2 changes: 1 addition & 1 deletion testing/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
ENCODING = 'UTF-8'

# This number must be updated when adding new golden tests to impeller.
_NUM_EXPECTED_GENERATED_IMPELLER_GOLDEN_FILES = 551
_NUM_EXPECTED_GENERATED_IMPELLER_GOLDEN_FILES = 554

logger = logging.getLogger(__name__)
logger_handler = logging.StreamHandler()
Expand Down