diff --git a/filament/src/Froxelizer.cpp b/filament/src/Froxelizer.cpp index 995fc76af24..52e0d71a845 100644 --- a/filament/src/Froxelizer.cpp +++ b/filament/src/Froxelizer.cpp @@ -81,6 +81,21 @@ struct Froxelizer::FroxelThreadData : public std::array { }; + +// Returns false if the two matrices are different. May return false if they're the +// same, with some elements only differing by +0 or -0. Behaviour is undefined with NaNs. +static bool fuzzyEqual(mat4f const& UTILS_RESTRICT l, mat4f const& UTILS_RESTRICT r) noexcept { + auto const li = reinterpret_cast( reinterpret_cast(&l) ); + auto const ri = reinterpret_cast( reinterpret_cast(&r) ); + uint32_t result = 0; + for (size_t i = 0; i < sizeof(mat4f) / sizeof(uint32_t); i++) { + // clang fully vectorizes this + result |= li[i] ^ ri[i]; + } + return result == 0; +} + + Froxelizer::Froxelizer(FEngine& engine) : mArena("froxel", PER_FROXELDATA_ARENA_SIZE), mZLightNear(FROXEL_FIRST_SLICE_DEPTH), @@ -144,9 +159,8 @@ void Froxelizer::setViewport(filament::Viewport const& viewport) noexcept { } void Froxelizer::setProjection(const mat4f& projection, - float near, - UTILS_UNUSED float far) noexcept { - if (UTILS_UNLIKELY(mat4f::fuzzyEqual(mProjection, projection))) { + float near, UTILS_UNUSED float far) noexcept { + if (UTILS_UNLIKELY(!fuzzyEqual(mProjection, projection))) { mProjection = projection; mNear = near; mDirtyFlags |= PROJECTION_CHANGED; diff --git a/libs/math/include/math/mat2.h b/libs/math/include/math/mat2.h index 551fe4451ed..dba9ca47230 100644 --- a/libs/math/include/math/mat2.h +++ b/libs/math/include/math/mat2.h @@ -235,23 +235,6 @@ class MATH_EMPTY_BASES TMat22 : return r; } - // returns false if the two matrices are different. May return false if they're the - // same, with some elements only differing by +0 or -0. Behaviour is undefined with NaNs. - static constexpr bool fuzzyEqual(TMat22 l, TMat22 r) noexcept { - uint64_t const* const li = reinterpret_cast(&l); - uint64_t const* const ri = reinterpret_cast(&r); - uint64_t result = 0; - // For some reason clang is not able to vectoize this loop when the number of iteration - // is known and constant (!?!?!). Still this is better than operator==. -#if defined(__clang__) -#pragma clang loop vectorize_width(2) -#endif - for (size_t i = 0; i < sizeof(TMat22) / sizeof(uint64_t); i++) { - result |= li[i] ^ ri[i]; - } - return result != 0; - } - template static constexpr TMat22 translation(const TVec2& t) noexcept { TMat22 r; diff --git a/libs/math/include/math/mat4.h b/libs/math/include/math/mat4.h index fa5301adfaa..d44081b2648 100644 --- a/libs/math/include/math/mat4.h +++ b/libs/math/include/math/mat4.h @@ -272,24 +272,6 @@ class MATH_EMPTY_BASES TMat44 : template constexpr TMat44(const TMat33& matrix, const TVec4& column3) noexcept; - /* - * helpers - */ - - // returns false if the two matrices are different. May return false if they're the - // same, with some elements only differing by +0 or -0. Behaviour is undefined with NaNs. - static constexpr bool fuzzyEqual(TMat44 const& l, TMat44 const& r) noexcept { - uint64_t const* const li = reinterpret_cast(&l); - uint64_t const* const ri = reinterpret_cast(&r); - uint64_t result = 0; - // For some reason clang is not able to vectorize this loop when the number of iteration - // is known and constant (!?!?!). Still this is better than operator==. - for (size_t i = 0; i < sizeof(TMat44) / sizeof(uint64_t); i++) { - result |= li[i] ^ ri[i]; - } - return result != 0; - } - static constexpr TMat44 ortho(T left, T right, T bottom, T top, T near, T far) noexcept; static constexpr TMat44 frustum(T left, T right, T bottom, T top, T near, T far) noexcept;