From 0b96fa88fd83d9f6ef91681695376f31ec64ad41 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 26 Feb 2025 09:54:53 -0800 Subject: [PATCH] [Impeller] work around for crashy Nexus 5 Driver. (#164040) Rewrites exp to work around crashes on Nexus 5. --- .../flutter/ci/licenses_golden/licenses_flutter | 2 ++ .../compiler/shader_lib/impeller/BUILD.gn | 1 + .../compiler/shader_lib/impeller/math.glsl | 16 ++++++++++++++++ .../impeller/entity/shaders/rrect_blur.frag | 7 ++++--- engine/src/flutter/impeller/tools/malioc.json | 2 +- 5 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 engine/src/flutter/impeller/compiler/shader_lib/impeller/math.glsl diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 7c45a24340..6848728c2e 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -41654,6 +41654,7 @@ ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/dithering.glsl + ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/external_texture_oes.glsl + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/gaussian.glsl + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/gradient.glsl + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/math.glsl + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/path.glsl + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/prefix_sum.glsl + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/shader_lib/impeller/texture.glsl + ../../../flutter/LICENSE @@ -44568,6 +44569,7 @@ FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/dithering.glsl FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/external_texture_oes.glsl FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/gaussian.glsl FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/gradient.glsl +FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/math.glsl FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/path.glsl FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/prefix_sum.glsl FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/texture.glsl diff --git a/engine/src/flutter/impeller/compiler/shader_lib/impeller/BUILD.gn b/engine/src/flutter/impeller/compiler/shader_lib/impeller/BUILD.gn index 08b2121ee5..1fc19bf293 100644 --- a/engine/src/flutter/impeller/compiler/shader_lib/impeller/BUILD.gn +++ b/engine/src/flutter/impeller/compiler/shader_lib/impeller/BUILD.gn @@ -13,6 +13,7 @@ copy("impeller") { "external_texture_oes.glsl", "gaussian.glsl", "gradient.glsl", + "math.glsl", "path.glsl", "texture.glsl", "tile_mode.glsl", diff --git a/engine/src/flutter/impeller/compiler/shader_lib/impeller/math.glsl b/engine/src/flutter/impeller/compiler/shader_lib/impeller/math.glsl new file mode 100644 index 0000000000..2c0651a1c2 --- /dev/null +++ b/engine/src/flutter/impeller/compiler/shader_lib/impeller/math.glsl @@ -0,0 +1,16 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MATH_GLSL_ +#define MATH_GLSL_ + +// pow(x, y) crashes the shader compiler on the Nexus 5. +// See also: https://skia-review.googlesource.com/c/skia/+/148480 +#ifdef IMPELLER_TARGET_OPENGLES +#define POW(x, y) exp2(y* log2(x)) +#else +#define POW(x, y) pow(x, y) +#endif + +#endif // MATH_GLSL_ diff --git a/engine/src/flutter/impeller/entity/shaders/rrect_blur.frag b/engine/src/flutter/impeller/entity/shaders/rrect_blur.frag index d0bba43561..934262de90 100644 --- a/engine/src/flutter/impeller/entity/shaders/rrect_blur.frag +++ b/engine/src/flutter/impeller/entity/shaders/rrect_blur.frag @@ -9,6 +9,7 @@ precision highp float; #include +#include #include uniform FragInfo { @@ -44,9 +45,9 @@ float computeErf7(float x) { // The length formula, but with an exponent other than 2 float powerDistance(vec2 p) { - float xp = pow(p.x, frag_info.exponent); - float yp = pow(p.y, frag_info.exponent); - return pow(xp + yp, frag_info.exponentInv); + float xp = POW(p.x, frag_info.exponent); + float yp = POW(p.y, frag_info.exponent); + return POW(xp + yp, frag_info.exponentInv); } void main() { diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index ffdb6a6235..4502526e9a 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -4365,7 +4365,7 @@ }, "thread_occupancy": 100, "uniform_registers_used": 4, - "work_registers_used": 3 + "work_registers_used": 2 } } }