From 04d70c11fcf55c8b0fe17590d254e06b5cdd4a05 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 19 Jun 2024 21:22:10 +0300 Subject: [PATCH] [Windows/ARM64] Fix raycast/embree ARM64 build with LLVM/MinGW. --- modules/raycast/config.py | 2 +- platform/windows/detect.py | 1 + thirdparty/embree/common/simd/arm/sse2neon.h | 18 +++++++- .../embree/patches/mingw-llvm-arm64.diff | 46 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 thirdparty/embree/patches/mingw-llvm-arm64.diff diff --git a/modules/raycast/config.py b/modules/raycast/config.py index 0fd35af528f2..2fa0058f8838 100644 --- a/modules/raycast/config.py +++ b/modules/raycast/config.py @@ -1,6 +1,6 @@ def can_build(env, platform): # Supported architectures and platforms depend on the Embree library. - if env["arch"] == "arm64" and platform == "windows": + if env["arch"] == "arm64" and platform == "windows" and env.msvc: return False if env["arch"] in ["x86_64", "arm64", "wasm32"]: return True diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 5092c6fadffb..8cb8be45daae 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -678,6 +678,7 @@ def configure_mingw(env: "SConsEnvironment"): env["CXX"] = mingw_bin_prefix + "clang++" if try_cmd("as --version", env["mingw_prefix"], env["arch"]): env["AS"] = mingw_bin_prefix + "as" + env.Append(ASFLAGS=["-c"]) if try_cmd("ar --version", env["mingw_prefix"], env["arch"]): env["AR"] = mingw_bin_prefix + "ar" if try_cmd("ranlib --version", env["mingw_prefix"], env["arch"]): diff --git a/thirdparty/embree/common/simd/arm/sse2neon.h b/thirdparty/embree/common/simd/arm/sse2neon.h index b18d41e783f9..76579f949755 100644 --- a/thirdparty/embree/common/simd/arm/sse2neon.h +++ b/thirdparty/embree/common/simd/arm/sse2neon.h @@ -102,7 +102,9 @@ #include #include -#if defined(_WIN32) +// -- GODOT start -- +#if defined(_WIN32) && !defined(__MINGW32__) +// -- GODOT end -- /* Definitions for _mm_{malloc,free} are provided by * from both MinGW-w64 and MSVC. */ @@ -1888,7 +1890,13 @@ FORCE_INLINE __m128 _mm_div_ss(__m128 a, __m128 b) #if !defined(SSE2NEON_ALLOC_DEFINED) FORCE_INLINE void _mm_free(void *addr) { +// -- GODOT start -- +#if defined(_WIN32) + _aligned_free(addr); +#else free(addr); +#endif +// -- GODOT end -- } #endif @@ -2080,8 +2088,16 @@ FORCE_INLINE void *_mm_malloc(size_t size, size_t align) return malloc(size); if (align == 2 || (sizeof(void *) == 8 && align == 4)) align = sizeof(void *); +// -- GODOT start -- +#if defined(_WIN32) + ptr = _aligned_malloc(size, align); + if (ptr) + return ptr; +#else if (!posix_memalign(&ptr, align, size)) return ptr; +#endif +// -- GODOT end -- return NULL; } #endif diff --git a/thirdparty/embree/patches/mingw-llvm-arm64.diff b/thirdparty/embree/patches/mingw-llvm-arm64.diff new file mode 100644 index 000000000000..c2ad4fb1dc07 --- /dev/null +++ b/thirdparty/embree/patches/mingw-llvm-arm64.diff @@ -0,0 +1,46 @@ +diff --git a/thirdparty/embree/common/simd/arm/sse2neon.h b/thirdparty/embree/common/simd/arm/sse2neon.h +index b18d41e783..c54d0b7951 100644 +--- a/thirdparty/embree/common/simd/arm/sse2neon.h ++++ b/thirdparty/embree/common/simd/arm/sse2neon.h +@@ -102,7 +102,9 @@ + #include + #include + +-#if defined(_WIN32) ++// -- GODOT start -- ++#if defined(_WIN32) && !defined(__MINGW32__) ++// -- GODOT end -- + /* Definitions for _mm_{malloc,free} are provided by + * from both MinGW-w64 and MSVC. + */ +@@ -2080,8 +2082,16 @@ FORCE_INLINE void *_mm_malloc(size_t size, size_t align) + return malloc(size); + if (align == 2 || (sizeof(void *) == 8 && align == 4)) + align = sizeof(void *); +- if (!posix_memalign(&ptr, align, size)) ++// -- GODOT start -- ++#if defined(_WIN32) ++ ptr = _aligned_malloc(size, align); ++ if (ptr) + return ptr; ++#else ++ if (!posix_memalign(&ptr, align, size)) ++ return ptr; ++#endif ++// -- GODOT end -- + return NULL; + } + #endif +@@ -1890,7 +1890,13 @@ FORCE_INLINE __m128 _mm_div_ss(__m128 a, __m128 b) + #if !defined(SSE2NEON_ALLOC_DEFINED) + FORCE_INLINE void _mm_free(void *addr) + { ++// -- GODOT start -- ++#if defined(_WIN32) ++ _aligned_free(addr); ++#else + free(addr); ++#endif ++// -- GODOT end -- + } + #endif