[Impeller] Fix issue about saveLayer ignoring opacity of paint with advanced blend mode (flutter/engine#41972)

fix https://github.com/flutter/flutter/issues/126532

without patch
![56V3vfllrj](https://github.com/flutter/engine/assets/31977171/ec51dd6d-6ae0-4dcd-b18f-c023d3a2ad5e)

with patch
![StzXmubqcV](https://github.com/flutter/engine/assets/31977171/232a2de7-05c3-4bbe-93d2-5daa2f8d64b5)
This commit is contained in:
ColdPaleLight
2023-05-16 16:05:16 +08:00
committed by GitHub
parent 9640e89255
commit b2846ca26e
6 changed files with 167 additions and 132 deletions

View File

@@ -2131,6 +2131,18 @@ TEST_P(AiksTest,
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
TEST_P(AiksTest, TranslucentSaveLayerWithAdvancedBlendModeDrawsCorrectly) {
Canvas canvas;
canvas.DrawRect({0, 0, 400, 400}, {.color = Color::Red()});
canvas.SaveLayer({
.color = Color::Black().WithAlpha(0.5),
.blend_mode = BlendMode::kLighten,
});
canvas.DrawCircle({200, 200}, 100, {.color = Color::Green()});
canvas.Restore();
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
/// This is a regression check for https://github.com/flutter/engine/pull/41129
/// The entire screen is green if successful. If failing, no frames will render,
/// or the entire screen will be transparent black.

View File

@@ -148,6 +148,7 @@ static std::optional<Entity> AdvancedBlend(
auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_sampler_descriptor);
blend_info.color_factor = 0;
blend_info.src_input_alpha = src_snapshot->opacity;
FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);
frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
}

View File

@@ -133,6 +133,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
}
VS::FrameInfo frame_info;
FS::FragInfo frag_info;
auto src_sampler_descriptor = src_snapshot->sampler_descriptor;
if (!renderer.GetDeviceCapabilities().SupportsDecalTileMode()) {
@@ -148,9 +149,10 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
src_snapshot->transform;
frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
frag_info.src_input_alpha = src_snapshot->opacity;
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
return pass.AddCommand(cmd);
}

View File

@@ -9,6 +9,7 @@
uniform BlendInfo {
float16_t dst_input_alpha;
float16_t src_input_alpha;
float16_t color_factor;
f16vec4 color; // This color input is expected to be unpremultiplied.
}
@@ -40,10 +41,11 @@ void main() {
f16vec4 dst = IPHalfUnpremultiply(dst_sample);
f16vec4 src = blend_info.color_factor > 0.0hf
? blend_info.color
: IPHalfUnpremultiply(Sample(
texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
: IPHalfUnpremultiply(
Sample(texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
) *
blend_info.src_input_alpha);
f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a;

View File

@@ -26,6 +26,11 @@ vec4 ReadDestination() {
uniform sampler2D texture_sampler_src;
uniform FragInfo {
float16_t src_input_alpha;
}
frag_info;
in vec2 v_src_texture_coords;
out vec4 frag_color;
@@ -36,7 +41,8 @@ void main() {
f16vec4 src = IPHalfUnpremultiply(
f16vec4(texture(texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
)));
)) *
frag_info.src_input_alpha);
f16vec4 blended = f16vec4(Blend(dst.rgb, src.rgb), 1.0hf) * dst.a;

View File

@@ -132,8 +132,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.59375,
0.59375,
0.625,
0.625,
0.28125,
0.25,
0.0,
@@ -167,8 +167,8 @@
"arith_fma"
],
"total_cycles": [
0.59375,
0.59375,
0.625,
0.625,
0.328125,
0.25,
0.0,
@@ -178,8 +178,8 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"work_registers_used": 12
"uniform_registers_used": 12,
"work_registers_used": 13
}
}
}
@@ -206,7 +206,7 @@
],
"longest_path_cycles": [
0.421875,
0.265625,
0.296875,
0.421875,
0.3125,
0.0,
@@ -241,7 +241,7 @@
],
"total_cycles": [
0.46875,
0.265625,
0.296875,
0.46875,
0.3125,
0.0,
@@ -252,7 +252,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 12,
"work_registers_used": 15
"work_registers_used": 16
}
}
}
@@ -279,7 +279,7 @@
],
"longest_path_cycles": [
0.421875,
0.234375,
0.265625,
0.421875,
0.3125,
0.0,
@@ -314,7 +314,7 @@
],
"total_cycles": [
0.46875,
0.234375,
0.265625,
0.46875,
0.3125,
0.0,
@@ -325,7 +325,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 12,
"work_registers_used": 13
"work_registers_used": 14
}
}
}
@@ -351,8 +351,8 @@
"texture"
],
"longest_path_cycles": [
0.1875,
0.171875,
0.203125,
0.203125,
0.1875,
0.125,
0.0,
@@ -387,7 +387,7 @@
],
"total_cycles": [
0.234375,
0.171875,
0.203125,
0.234375,
0.125,
0.0,
@@ -398,7 +398,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 11
"work_registers_used": 12
}
}
}
@@ -424,8 +424,8 @@
"texture"
],
"longest_path_cycles": [
0.203125,
0.203125,
0.234375,
0.234375,
0.15625,
0.125,
0.0,
@@ -459,8 +459,8 @@
"texture"
],
"total_cycles": [
0.203125,
0.203125,
0.234375,
0.234375,
0.203125,
0.125,
0.0,
@@ -471,7 +471,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 11
"work_registers_used": 12
}
}
}
@@ -497,8 +497,8 @@
"texture"
],
"longest_path_cycles": [
0.28125,
0.28125,
0.3125,
0.3125,
0.15625,
0.125,
0.0,
@@ -534,8 +534,8 @@
"texture"
],
"total_cycles": [
0.28125,
0.28125,
0.3125,
0.3125,
0.203125,
0.125,
0.0,
@@ -546,7 +546,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 12
"work_registers_used": 13
}
}
}
@@ -568,12 +568,14 @@
"has_stack_spilling": false,
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma",
"varying",
"texture"
],
"longest_path_cycles": [
0.46875,
0.46875,
0.5,
0.5,
0.21875,
0.125,
0.0,
@@ -603,12 +605,14 @@
0.25
],
"total_bound_pipelines": [
"arith_total",
"arith_fma",
"varying",
"texture"
],
"total_cycles": [
0.46875,
0.46875,
0.5,
0.5,
0.265625,
0.125,
0.0,
@@ -618,8 +622,8 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 15
"uniform_registers_used": 10,
"work_registers_used": 16
}
}
}
@@ -645,8 +649,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.699999988079071,
0.699999988079071,
0.737500011920929,
0.737500011920929,
0.453125,
0.3125,
0.0,
@@ -680,8 +684,8 @@
"arith_fma"
],
"total_cycles": [
0.699999988079071,
0.699999988079071,
0.737500011920929,
0.737500011920929,
0.53125,
0.3125,
0.0,
@@ -691,7 +695,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 13
}
}
@@ -718,8 +722,8 @@
"texture"
],
"longest_path_cycles": [
0.1875,
0.171875,
0.203125,
0.203125,
0.1875,
0.125,
0.0,
@@ -754,7 +758,7 @@
],
"total_cycles": [
0.234375,
0.171875,
0.203125,
0.234375,
0.125,
0.0,
@@ -765,7 +769,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 11
"work_registers_used": 12
}
}
}
@@ -791,8 +795,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.59375,
0.59375,
0.625,
0.625,
0.28125,
0.25,
0.0,
@@ -826,8 +830,8 @@
"arith_fma"
],
"total_cycles": [
0.59375,
0.59375,
0.625,
0.625,
0.328125,
0.25,
0.0,
@@ -837,8 +841,8 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"work_registers_used": 12
"uniform_registers_used": 12,
"work_registers_used": 13
}
}
}
@@ -864,8 +868,8 @@
"texture"
],
"longest_path_cycles": [
0.203125,
0.203125,
0.234375,
0.234375,
0.15625,
0.125,
0.0,
@@ -899,8 +903,8 @@
"texture"
],
"total_cycles": [
0.203125,
0.203125,
0.234375,
0.234375,
0.203125,
0.125,
0.0,
@@ -911,7 +915,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 11
"work_registers_used": 12
}
}
}
@@ -933,12 +937,14 @@
"has_stack_spilling": false,
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma",
"varying",
"texture"
],
"longest_path_cycles": [
0.46875,
0.46875,
0.5,
0.5,
0.21875,
0.125,
0.0,
@@ -968,12 +974,14 @@
0.25
],
"total_bound_pipelines": [
"arith_total",
"arith_fma",
"varying",
"texture"
],
"total_cycles": [
0.46875,
0.46875,
0.5,
0.5,
0.265625,
0.125,
0.0,
@@ -983,8 +991,8 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 15
"uniform_registers_used": 10,
"work_registers_used": 16
}
}
}
@@ -1010,8 +1018,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.699999988079071,
0.699999988079071,
0.737500011920929,
0.737500011920929,
0.453125,
0.3125,
0.0,
@@ -1045,8 +1053,8 @@
"arith_fma"
],
"total_cycles": [
0.699999988079071,
0.699999988079071,
0.737500011920929,
0.737500011920929,
0.53125,
0.3125,
0.0,
@@ -1056,7 +1064,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 13
}
}
@@ -1083,8 +1091,8 @@
"texture"
],
"longest_path_cycles": [
0.25,
0.25,
0.28125,
0.28125,
0.15625,
0.125,
0.0,
@@ -1118,8 +1126,8 @@
"texture"
],
"total_cycles": [
0.25,
0.25,
0.28125,
0.28125,
0.203125,
0.125,
0.0,
@@ -1130,7 +1138,7 @@
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 11
"work_registers_used": 12
}
}
}
@@ -1156,8 +1164,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.78125,
0.78125,
0.8125,
0.8125,
0.359375,
0.3125,
0.0,
@@ -1191,8 +1199,8 @@
"arith_fma"
],
"total_cycles": [
0.78125,
0.78125,
0.8125,
0.8125,
0.40625,
0.3125,
0.0,
@@ -1202,7 +1210,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 12,
"uniform_registers_used": 14,
"work_registers_used": 21
}
}
@@ -3823,11 +3831,12 @@
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma",
"arith_sfu"
],
"longest_path_cycles": [
0.625,
0.59375,
0.625,
0.53125,
0.625,
0.0,
@@ -3858,11 +3867,12 @@
],
"total_bound_pipelines": [
"arith_total",
"arith_fma",
"arith_sfu"
],
"total_cycles": [
0.625,
0.59375,
0.625,
0.578125,
0.625,
0.0,
@@ -3872,7 +3882,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 20
}
}
@@ -3945,7 +3955,7 @@
],
"longest_path_cycles": [
0.6875,
0.265625,
0.296875,
0.675000011920929,
0.6875,
0.0,
@@ -3980,7 +3990,7 @@
],
"total_cycles": [
0.71875,
0.265625,
0.296875,
0.71875,
0.6875,
0.0,
@@ -3990,7 +4000,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 26
}
}
@@ -4063,7 +4073,7 @@
],
"longest_path_cycles": [
0.6875,
0.234375,
0.265625,
0.675000011920929,
0.6875,
0.0,
@@ -4098,7 +4108,7 @@
],
"total_cycles": [
0.71875,
0.234375,
0.265625,
0.71875,
0.6875,
0.0,
@@ -4108,7 +4118,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 26
}
}
@@ -4183,7 +4193,7 @@
],
"longest_path_cycles": [
0.5,
0.171875,
0.203125,
0.4375,
0.5,
0.0,
@@ -4220,7 +4230,7 @@
],
"total_cycles": [
0.5,
0.171875,
0.203125,
0.484375,
0.5,
0.0,
@@ -4269,7 +4279,7 @@
"arithmetic"
],
"total_cycles": [
6.666666507720947,
6.333333492279053,
2.0,
2.0
]
@@ -4305,7 +4315,7 @@
],
"longest_path_cycles": [
0.5,
0.203125,
0.234375,
0.40625,
0.5,
0.0,
@@ -4344,7 +4354,7 @@
],
"total_cycles": [
0.5,
0.203125,
0.234375,
0.453125,
0.5,
0.0,
@@ -4393,7 +4403,7 @@
"arithmetic"
],
"total_cycles": [
6.666666507720947,
6.333333492279053,
2.0,
2.0
]
@@ -4429,7 +4439,7 @@
],
"longest_path_cycles": [
0.5,
0.265625,
0.296875,
0.40625,
0.5,
0.0,
@@ -4468,7 +4478,7 @@
],
"total_cycles": [
0.5,
0.265625,
0.296875,
0.453125,
0.5,
0.0,
@@ -4517,7 +4527,7 @@
"arithmetic"
],
"total_cycles": [
7.333333492279053,
7.0,
2.0,
2.0
]
@@ -4553,7 +4563,7 @@
],
"longest_path_cycles": [
0.5,
0.453125,
0.484375,
0.46875,
0.5,
0.0,
@@ -4588,7 +4598,7 @@
],
"total_cycles": [
0.515625,
0.453125,
0.484375,
0.515625,
0.5,
0.0,
@@ -4598,7 +4608,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"uniform_registers_used": 10,
"work_registers_used": 25
}
}
@@ -4637,7 +4647,7 @@
"arithmetic"
],
"total_cycles": [
8.333333015441895,
8.0,
2.0,
2.0
]
@@ -4670,8 +4680,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.699999988079071,
0.699999988079071,
0.737500011920929,
0.737500011920929,
0.6875,
0.6875,
0.0,
@@ -4706,7 +4716,7 @@
],
"total_cycles": [
0.78125,
0.699999988079071,
0.737500011920929,
0.78125,
0.6875,
0.0,
@@ -4716,7 +4726,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 21
}
}
@@ -4755,7 +4765,7 @@
"arithmetic"
],
"total_cycles": [
13.0,
12.666666984558105,
2.0,
2.0
]
@@ -4791,7 +4801,7 @@
],
"longest_path_cycles": [
0.5,
0.171875,
0.203125,
0.4375,
0.5,
0.0,
@@ -4828,7 +4838,7 @@
],
"total_cycles": [
0.5,
0.171875,
0.203125,
0.484375,
0.5,
0.0,
@@ -4877,7 +4887,7 @@
"arithmetic"
],
"total_cycles": [
6.666666507720947,
6.333333492279053,
2.0,
2.0
]
@@ -4907,11 +4917,12 @@
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma",
"arith_sfu"
],
"longest_path_cycles": [
0.625,
0.59375,
0.625,
0.53125,
0.625,
0.0,
@@ -4942,11 +4953,12 @@
],
"total_bound_pipelines": [
"arith_total",
"arith_fma",
"arith_sfu"
],
"total_cycles": [
0.625,
0.59375,
0.625,
0.578125,
0.625,
0.0,
@@ -4956,7 +4968,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 20
}
}
@@ -5031,7 +5043,7 @@
],
"longest_path_cycles": [
0.5,
0.203125,
0.234375,
0.40625,
0.5,
0.0,
@@ -5070,7 +5082,7 @@
],
"total_cycles": [
0.5,
0.203125,
0.234375,
0.453125,
0.5,
0.0,
@@ -5119,7 +5131,7 @@
"arithmetic"
],
"total_cycles": [
7.0,
6.666666507720947,
2.0,
2.0
]
@@ -5155,7 +5167,7 @@
],
"longest_path_cycles": [
0.5,
0.453125,
0.484375,
0.46875,
0.5,
0.0,
@@ -5190,7 +5202,7 @@
],
"total_cycles": [
0.515625,
0.453125,
0.484375,
0.515625,
0.5,
0.0,
@@ -5200,7 +5212,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"uniform_registers_used": 10,
"work_registers_used": 25
}
}
@@ -5272,8 +5284,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.699999988079071,
0.699999988079071,
0.737500011920929,
0.737500011920929,
0.6875,
0.6875,
0.0,
@@ -5308,7 +5320,7 @@
],
"total_cycles": [
0.78125,
0.699999988079071,
0.737500011920929,
0.78125,
0.6875,
0.0,
@@ -5318,7 +5330,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 10,
"uniform_registers_used": 12,
"work_registers_used": 21
}
}
@@ -5357,7 +5369,7 @@
"arithmetic"
],
"total_cycles": [
13.333333015441895,
13.0,
2.0,
2.0
]
@@ -5393,7 +5405,7 @@
],
"longest_path_cycles": [
0.5,
0.234375,
0.265625,
0.40625,
0.5,
0.0,
@@ -5432,7 +5444,7 @@
],
"total_cycles": [
0.5,
0.234375,
0.265625,
0.453125,
0.5,
0.0,
@@ -5481,7 +5493,7 @@
"arithmetic"
],
"total_cycles": [
7.0,
6.666666507720947,
2.0,
2.0
]
@@ -5514,8 +5526,8 @@
"arith_fma"
],
"longest_path_cycles": [
0.71875,
0.71875,
0.75,
0.75,
0.609375,
0.6875,
0.0,
@@ -5549,8 +5561,8 @@
"arith_fma"
],
"total_cycles": [
0.71875,
0.71875,
0.75,
0.75,
0.65625,
0.6875,
0.0,
@@ -5560,7 +5572,7 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 12,
"uniform_registers_used": 14,
"work_registers_used": 32
}
}