[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.
This commit is contained in:
@@ -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<Point> 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;
|
||||
|
||||
@@ -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<Color> colors) {
|
||||
colors_ = std::move(colors);
|
||||
}
|
||||
@@ -76,7 +72,6 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer,
|
||||
frag_info.tile_mode = static_cast<Scalar>(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_;
|
||||
|
||||
@@ -45,8 +45,6 @@ class ConicalGradientContents final : public ColorSourceContents {
|
||||
|
||||
void SetTileMode(Entity::TileMode tile_mode);
|
||||
|
||||
void SetDither(bool dither);
|
||||
|
||||
void SetFocus(std::optional<Point> focus, Scalar radius);
|
||||
|
||||
private:
|
||||
@@ -65,7 +63,6 @@ class ConicalGradientContents final : public ColorSourceContents {
|
||||
Color decal_border_color_ = Color::BlackTransparent();
|
||||
std::optional<Point> focus_;
|
||||
Scalar focus_radius_ = 0.0f;
|
||||
bool dither_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ConicalGradientContents);
|
||||
};
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<Scalar> stops_;
|
||||
Entity::TileMode tile_mode_;
|
||||
Color decal_border_color_ = Color::BlackTransparent();
|
||||
bool dither_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(LinearGradientContents);
|
||||
};
|
||||
|
||||
@@ -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<Color> colors) {
|
||||
colors_ = std::move(colors);
|
||||
}
|
||||
@@ -82,7 +78,6 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer,
|
||||
frag_info.tile_mode = static_cast<Scalar>(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_);
|
||||
|
||||
@@ -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<Scalar> stops_;
|
||||
Entity::TileMode tile_mode_;
|
||||
Color decal_border_color_ = Color::BlackTransparent();
|
||||
bool dither_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(RadialGradientContents);
|
||||
};
|
||||
|
||||
@@ -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<Color>& SweepGradientContents::GetColors() const {
|
||||
return colors_;
|
||||
}
|
||||
@@ -88,7 +84,6 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer,
|
||||
frag_info.tile_mode = static_cast<Scalar>(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_);
|
||||
|
||||
@@ -45,8 +45,6 @@ class SweepGradientContents final : public ColorSourceContents {
|
||||
|
||||
void SetTileMode(Entity::TileMode tile_mode);
|
||||
|
||||
void SetDither(bool dither);
|
||||
|
||||
const std::vector<Color>& GetColors() const;
|
||||
|
||||
const std::vector<Scalar>& GetStops() const;
|
||||
@@ -67,7 +65,6 @@ class SweepGradientContents final : public ColorSourceContents {
|
||||
std::vector<Scalar> stops_;
|
||||
Entity::TileMode tile_mode_;
|
||||
Color decal_border_color_ = Color::BlackTransparent();
|
||||
bool dither_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(SweepGradientContents);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user