From 2142fff539f2198cd61dc28c41e506c87fe6e162 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Sat, 10 Jun 2023 10:14:29 -0700 Subject: [PATCH] [Impeller] Fix vulkan gradient nan issue. (flutter/engine#42715) Fixes https://github.com/flutter/flutter/issues/128603 We were hitting a nan issue. GLSL has different relaxed precision semantics than vulkan does, and didn't hit it for some reason. --- .../shaders/linear_gradient_ssbo_fill.frag | 14 ++++++-------- engine/src/flutter/impeller/tools/malioc.json | 18 +++++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) 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 183b3b7978..1b2990d9eb 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 @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include #include #include @@ -30,9 +29,9 @@ highp in vec2 v_position; out vec4 frag_color; void main() { - vec2 start_to_end = frag_info.end_point - frag_info.start_point; - vec2 start_to_position = v_position - frag_info.start_point; - float t = + highp vec2 start_to_end = frag_info.end_point - frag_info.start_point; + highp vec2 start_to_position = v_position - frag_info.start_point; + highp float t = dot(start_to_position, start_to_end) / dot(start_to_end, start_to_end); if ((t < 0.0 || t > 1.0) && frag_info.tile_mode == kTileModeDecal) { @@ -41,21 +40,20 @@ void main() { } t = IPFloatTile(t, frag_info.tile_mode); - vec4 result_color = vec4(0); for (int i = 1; i < frag_info.colors_length; i++) { ColorPoint prev_point = color_data.colors[i - 1]; ColorPoint current_point = color_data.colors[i]; if (t >= prev_point.stop && t <= current_point.stop) { float delta = (current_point.stop - prev_point.stop); if (delta < 0.001) { - result_color = current_point.color; + frag_color = current_point.color; } else { float ratio = (t - prev_point.stop) / delta; - result_color = mix(prev_point.color, current_point.color, ratio); + frag_color = mix(prev_point.color, current_point.color, ratio); } break; } } frag_color = - vec4(result_color.xyz * result_color.a, result_color.a) * frag_info.alpha; + vec4(frag_color.xyz * frag_color.a, frag_color.a) * frag_info.alpha; } diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index aef3c8891d..27784bffa5 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -11338,7 +11338,7 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 70, + "fp16_arithmetic": 32, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ @@ -11366,10 +11366,10 @@ "varying" ], "shortest_path_cycles": [ - 0.109375, + 0.125, 0.09375, - 0.109375, - 0.0, + 0.125, + 0.0625, 0.0, 0.25, 0.0 @@ -11378,10 +11378,10 @@ "load_store" ], "total_cycles": [ - 0.59375, - 0.359375, - 0.59375, - 0.0625, + 0.65625, + 0.375, + 0.65625, + 0.125, 4.0, 0.25, 0.0 @@ -11389,7 +11389,7 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 12, + "uniform_registers_used": 14, "work_registers_used": 15 } }