From 07e83e3f94bb6fa213c912aced1f79483cbc0df8 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Tue, 24 Oct 2023 16:23:04 -0700 Subject: [PATCH] [Impeller] Unconditionally dither in gradient shader fragments. (flutter/engine#46746) Partial work towards https://github.com/flutter/flutter/issues/112498. Won't land this until https://github.com/flutter/engine/pull/46745 is merged, so expect some redness until then. --- .../src/flutter/impeller/aiks/color_source.cc | 4 -- .../contents/conical_gradient_contents.cc | 5 -- .../contents/conical_gradient_contents.h | 3 - .../contents/linear_gradient_contents.cc | 5 -- .../contents/linear_gradient_contents.h | 3 - .../contents/radial_gradient_contents.cc | 5 -- .../contents/radial_gradient_contents.h | 3 - .../contents/sweep_gradient_contents.cc | 5 -- .../entity/contents/sweep_gradient_contents.h | 3 - .../shaders/conical_gradient_ssbo_fill.frag | 7 +- .../shaders/linear_gradient_ssbo_fill.frag | 7 +- .../shaders/radial_gradient_ssbo_fill.frag | 7 +- .../shaders/sweep_gradient_ssbo_fill.frag | 7 +- engine/src/flutter/impeller/tools/malioc.json | 71 ++++++++++--------- 14 files changed, 45 insertions(+), 90 deletions(-) diff --git a/engine/src/flutter/impeller/aiks/color_source.cc b/engine/src/flutter/impeller/aiks/color_source.cc index da3191f2d6..f88dcc57ad 100644 --- a/engine/src/flutter/impeller/aiks/color_source.cc +++ b/engine/src/flutter/impeller/aiks/color_source.cc @@ -59,7 +59,6 @@ ColorSource ColorSource::MakeLinearGradient(Point start_point, contents->SetStops(stops); contents->SetEndPoints(start_point, end_point); contents->SetTileMode(tile_mode); - contents->SetDither(paint.dither); contents->SetEffectTransform(effect_transform); std::vector bounds{start_point, end_point}; @@ -92,7 +91,6 @@ ColorSource ColorSource::MakeConicalGradient(Point center, contents->SetStops(stops); contents->SetCenterAndRadius(center, radius); contents->SetTileMode(tile_mode); - contents->SetDither(paint.dither); contents->SetEffectTransform(effect_transform); contents->SetFocus(focus_center, focus_radius); @@ -124,7 +122,6 @@ ColorSource ColorSource::MakeRadialGradient(Point center, contents->SetStops(stops); contents->SetCenterAndRadius(center, radius); contents->SetTileMode(tile_mode); - contents->SetDither(paint.dither); contents->SetEffectTransform(effect_transform); auto radius_pt = Point(radius, radius); @@ -156,7 +153,6 @@ ColorSource ColorSource::MakeSweepGradient(Point center, contents->SetColors(colors); contents->SetStops(stops); contents->SetTileMode(tile_mode); - contents->SetDither(paint.dither); contents->SetEffectTransform(effect_transform); return contents; diff --git a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc index 8447364a39..a1e7320142 100644 --- a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc @@ -29,10 +29,6 @@ void ConicalGradientContents::SetTileMode(Entity::TileMode tile_mode) { tile_mode_ = tile_mode; } -void ConicalGradientContents::SetDither(bool dither) { - dither_ = dither; -} - void ConicalGradientContents::SetColors(std::vector colors) { colors_ = std::move(colors); } @@ -76,7 +72,6 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; frag_info.alpha = GetOpacityFactor(); - frag_info.dither = dither_; if (focus_) { frag_info.focus = focus_.value(); frag_info.focus_radius = focus_radius_; diff --git a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.h b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.h index 55a2ac16a3..f9701a5a44 100644 --- a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.h +++ b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.h @@ -45,8 +45,6 @@ class ConicalGradientContents final : public ColorSourceContents { void SetTileMode(Entity::TileMode tile_mode); - void SetDither(bool dither); - void SetFocus(std::optional focus, Scalar radius); private: @@ -65,7 +63,6 @@ class ConicalGradientContents final : public ColorSourceContents { Color decal_border_color_ = Color::BlackTransparent(); std::optional focus_; Scalar focus_radius_ = 0.0f; - bool dither_ = false; FML_DISALLOW_COPY_AND_ASSIGN(ConicalGradientContents); }; diff --git a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc index 4432494cd9..79bb69609a 100644 --- a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc @@ -56,10 +56,6 @@ bool LinearGradientContents::IsOpaque() const { return true; } -void LinearGradientContents::SetDither(bool dither) { - dither_ = dither; -} - bool LinearGradientContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { @@ -150,7 +146,6 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, auto colors = CreateGradientColors(colors_, stops_); frag_info.colors_length = colors.size(); - frag_info.dither = dither_; auto color_buffer = host_buffer.Emplace(colors.data(), colors.size() * sizeof(StopData), DefaultUniformAlignment()); diff --git a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.h b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.h index e7556af744..58509f709a 100644 --- a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.h +++ b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.h @@ -49,8 +49,6 @@ class LinearGradientContents final : public ColorSourceContents { void SetTileMode(Entity::TileMode tile_mode); - void SetDither(bool dither); - private: bool RenderTexture(const ContentContext& renderer, const Entity& entity, @@ -66,7 +64,6 @@ class LinearGradientContents final : public ColorSourceContents { std::vector stops_; Entity::TileMode tile_mode_; Color decal_border_color_ = Color::BlackTransparent(); - bool dither_ = false; FML_DISALLOW_COPY_AND_ASSIGN(LinearGradientContents); }; diff --git a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc index 1513aa5652..6a2a651414 100644 --- a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc @@ -29,10 +29,6 @@ void RadialGradientContents::SetTileMode(Entity::TileMode tile_mode) { tile_mode_ = tile_mode; } -void RadialGradientContents::SetDither(bool dither) { - dither_ = dither; -} - void RadialGradientContents::SetColors(std::vector colors) { colors_ = std::move(colors); } @@ -82,7 +78,6 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; frag_info.alpha = GetOpacityFactor(); - frag_info.dither = dither_; auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); diff --git a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h index 6464943f4c..5db915289c 100644 --- a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h +++ b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h @@ -48,8 +48,6 @@ class RadialGradientContents final : public ColorSourceContents { void SetTileMode(Entity::TileMode tile_mode); - void SetDither(bool dither); - private: bool RenderTexture(const ContentContext& renderer, const Entity& entity, @@ -64,7 +62,6 @@ class RadialGradientContents final : public ColorSourceContents { std::vector stops_; Entity::TileMode tile_mode_; Color decal_border_color_ = Color::BlackTransparent(); - bool dither_ = false; FML_DISALLOW_COPY_AND_ASSIGN(RadialGradientContents); }; diff --git a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc index 88343ee641..14701170f2 100644 --- a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc @@ -42,10 +42,6 @@ void SweepGradientContents::SetTileMode(Entity::TileMode tile_mode) { tile_mode_ = tile_mode; } -void SweepGradientContents::SetDither(bool dither) { - dither_ = dither; -} - const std::vector& SweepGradientContents::GetColors() const { return colors_; } @@ -88,7 +84,6 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.tile_mode = static_cast(tile_mode_); frag_info.decal_border_color = decal_border_color_; frag_info.alpha = GetOpacityFactor(); - frag_info.dither = dither_; auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); diff --git a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.h b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.h index 6d76baf39a..bb86437dbb 100644 --- a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.h +++ b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.h @@ -45,8 +45,6 @@ class SweepGradientContents final : public ColorSourceContents { void SetTileMode(Entity::TileMode tile_mode); - void SetDither(bool dither); - const std::vector& GetColors() const; const std::vector& GetStops() const; @@ -67,7 +65,6 @@ class SweepGradientContents final : public ColorSourceContents { std::vector stops_; Entity::TileMode tile_mode_; Color decal_border_color_ = Color::BlackTransparent(); - bool dither_ = false; FML_DISALLOW_COPY_AND_ASSIGN(SweepGradientContents); }; diff --git a/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag index 39084ae1c6..80289969b1 100644 --- a/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag @@ -29,7 +29,6 @@ uniform FragInfo { int colors_length; vec2 focus; float focus_radius; - bool dither; } frag_info; @@ -64,9 +63,7 @@ void main() { } } } - frag_color = IPPremultiply(result_color) * frag_info.alpha; - if (frag_info.dither) { - frag_color = IPOrderedDither8x8(frag_color, v_position); - } + frag_color = IPPremultiply(result_color) * frag_info.alpha; + frag_color = IPOrderedDither8x8(frag_color, v_position); } diff --git a/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag index 818db480e9..dcfc5918a1 100644 --- a/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/linear_gradient_ssbo_fill.frag @@ -26,7 +26,6 @@ uniform FragInfo { float tile_mode; vec4 decal_border_color; int colors_length; - bool dither; } frag_info; @@ -60,9 +59,7 @@ void main() { } } } - frag_color = IPPremultiply(frag_color) * frag_info.alpha; - if (frag_info.dither) { - frag_color = IPOrderedDither8x8(frag_color, v_position); - } + frag_color = IPPremultiply(frag_color) * frag_info.alpha; + frag_color = IPOrderedDither8x8(frag_color, v_position); } diff --git a/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag index 13fc105905..afb5d7a799 100644 --- a/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/radial_gradient_ssbo_fill.frag @@ -27,7 +27,6 @@ uniform FragInfo { vec4 decal_border_color; float alpha; int colors_length; - bool dither; } frag_info; @@ -60,9 +59,7 @@ void main() { } } } - frag_color = IPPremultiply(result_color) * frag_info.alpha; - if (frag_info.dither) { - frag_color = IPOrderedDither8x8(frag_color, v_position); - } + frag_color = IPPremultiply(result_color) * frag_info.alpha; + frag_color = IPOrderedDither8x8(frag_color, v_position); } diff --git a/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag b/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag index 39f14d6b39..00a39ccbd5 100644 --- a/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag +++ b/engine/src/flutter/impeller/entity/shaders/sweep_gradient_ssbo_fill.frag @@ -27,7 +27,6 @@ uniform FragInfo { vec4 decal_border_color; float alpha; int colors_length; - bool dither; } frag_info; @@ -61,9 +60,7 @@ void main() { } } } - frag_color = IPPremultiply(result_color) * frag_info.alpha; - if (frag_info.dither) { - frag_color = IPOrderedDither8x8(frag_color, v_position); - } + frag_color = IPPremultiply(result_color) * frag_info.alpha; + frag_color = IPOrderedDither8x8(frag_color, v_position); } diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index 17828b671d..4e61378f06 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -2144,13 +2144,14 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_sfu" ], "shortest_path_cycles": [ - 0.21875, - 0.0625, - 0.21875, - 0.0, + 0.5, + 0.109375, + 0.328125, + 0.5, 0.0, 0.25, 0.0 @@ -2159,9 +2160,9 @@ "load_store" ], "total_cycles": [ - 1.4874999523162842, - 0.875, - 1.4874999523162842, + 1.4500000476837158, + 0.862500011920929, + 1.4500000476837158, 0.875, 4.0, 0.25, @@ -10352,7 +10353,7 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 37, + "fp16_arithmetic": 35, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ @@ -10377,13 +10378,14 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_sfu" ], "shortest_path_cycles": [ - 0.1875, - 0.15625, - 0.1875, - 0.0625, + 0.5625, + 0.203125, + 0.296875, + 0.5625, 0.0, 0.25, 0.0 @@ -10392,9 +10394,9 @@ "load_store" ], "total_cycles": [ - 0.8125, - 0.4375, - 0.8125, + 0.78125, + 0.421875, + 0.78125, 0.625, 4.0, 0.25, @@ -11220,7 +11222,7 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 55, + "fp16_arithmetic": 54, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ @@ -11245,13 +11247,14 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "arith_total", + "arith_sfu" ], "shortest_path_cycles": [ - 0.203125, - 0.171875, - 0.203125, - 0.0625, + 0.5625, + 0.21875, + 0.3125, + 0.5625, 0.0, 0.25, 0.0 @@ -11260,9 +11263,9 @@ "load_store" ], "total_cycles": [ - 0.78125, - 0.4375, - 0.78125, + 0.75, + 0.421875, + 0.75, 0.625, 4.0, 0.25, @@ -12052,13 +12055,13 @@ ], "shortest_path_bound_pipelines": [ "arith_total", - "arith_fma" + "arith_sfu" ], "shortest_path_cycles": [ - 0.390625, - 0.390625, - 0.28125, - 0.3125, + 0.8125, + 0.421875, + 0.359375, + 0.8125, 0.0, 0.25, 0.0 @@ -12068,8 +12071,8 @@ ], "total_cycles": [ 0.875, - 0.71875, - 0.84375, + 0.6875, + 0.800000011920929, 0.875, 4.0, 0.25, @@ -12078,7 +12081,7 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 30, + "uniform_registers_used": 28, "work_registers_used": 23 } }