[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.
This commit is contained in:
Jonah Williams
2023-06-10 10:14:29 -07:00
committed by GitHub
parent e95110fbd6
commit 2142fff539
2 changed files with 15 additions and 17 deletions

View File

@@ -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 <impeller/gradient.glsl>
#include <impeller/texture.glsl>
#include <impeller/types.glsl>
@@ -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;
}

View File

@@ -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
}
}