From 300d17912bb5d27e7dad034186b0c5f5743cc0b8 Mon Sep 17 00:00:00 2001 From: John O'Neil Date: Mon, 29 Jan 2024 15:53:10 -0800 Subject: [PATCH] Enable `_Float16` "half-float" Functionality Only When Available. (flutter/engine#49851) # Description: We're cross-compiling impeller for Android, but x86 Android targets don't have half float (`_Float16`) _ support. This change disables half float support in `impeller/geometry/half.h` for platforms where the `_Float16` builtin is lacking. As can be seen in `half.h`, `Float16` support is enabled for all non-windows platforms, which doesn't not allow our use case. # Issues I can't seem to find a way to file an issue describing this, but - [] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../flutter/impeller/geometry/geometry_unittests.cc | 11 ++++++----- engine/src/flutter/impeller/geometry/half.h | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/impeller/geometry/geometry_unittests.cc b/engine/src/flutter/impeller/geometry/geometry_unittests.cc index d9df8d1bf0..e5ebf3de82 100644 --- a/engine/src/flutter/impeller/geometry/geometry_unittests.cc +++ b/engine/src/flutter/impeller/geometry/geometry_unittests.cc @@ -1773,10 +1773,8 @@ TEST(GeometryTest, Gradient) { } TEST(GeometryTest, HalfConversions) { -#ifdef FML_OS_WIN - GTEST_SKIP() << "Half-precision floats (IEEE 754) are not portable and " - "unavailable on Windows."; -#else +#if defined(FML_OS_MACOSX) || defined(FML_OS_IOS) || \ + defined(FML_OS_IOS_SIMULATOR) ASSERT_EQ(ScalarToHalf(0.0), 0.0f16); ASSERT_EQ(ScalarToHalf(0.05), 0.05f16); ASSERT_EQ(ScalarToHalf(2.43), 2.43f16); @@ -1803,7 +1801,10 @@ TEST(GeometryTest, HalfConversions) { ASSERT_EQ(Half(0.5f), Half(0.5f16)); ASSERT_EQ(Half(0.5), Half(0.5f16)); ASSERT_EQ(Half(5), Half(5.0f16)); -#endif // FML_OS_WIN +#else + GTEST_SKIP() << "Half-precision floats (IEEE 754) are not portable and " + "only used on Apple platforms."; +#endif // FML_OS_MACOSX || FML_OS_IOS || FML_OS_IOS_SIMULATOR } } // namespace testing diff --git a/engine/src/flutter/impeller/geometry/half.h b/engine/src/flutter/impeller/geometry/half.h index 8ab60a0f57..1e819ce466 100644 --- a/engine/src/flutter/impeller/geometry/half.h +++ b/engine/src/flutter/impeller/geometry/half.h @@ -16,10 +16,11 @@ // NOLINTBEGIN(google-explicit-constructor) -#ifdef FML_OS_WIN -using InternalHalf = uint16_t; -#else +#if defined(FML_OS_MACOSX) || defined(FML_OS_IOS) || \ + defined(FML_OS_IOS_SIMULATOR) using InternalHalf = _Float16; +#else +using InternalHalf = uint16_t; #endif namespace impeller {