diff --git a/common/cmake/clang.cmake b/common/cmake/clang.cmake index 2666d1be8b..abd6e67ded 100644 --- a/common/cmake/clang.cmake +++ b/common/cmake/clang.cmake @@ -7,6 +7,12 @@ MACRO(_SET_IF_EMPTY VAR VALUE) ENDIF() ENDMACRO() +# Detect ARM64 for Windows +IF(WIN32 AND (CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64|arm64")) + SET(EMBREE_ARM TRUE) + MESSAGE(STATUS "Detected Windows ARM64 build") +ENDIF() + IF (EMBREE_ARM) IF ("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES) # set ARM an x86 flags for macOS universal binary build @@ -16,12 +22,15 @@ IF (EMBREE_ARM) SET(FLAGS_AVX2 "-D__AVX2__ -D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__BMI__ -D__BMI2__ -D__LZCNT__ -mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2") _SET_IF_EMPTY(FLAGS_AVX512 "-march=skx") ELSE () - SET(FLAGS_SSE2 "-D__SSE__ -D__SSE2__") - SET(FLAGS_SSE42 "-D__SSE4_2__ -D__SSE4_1__") - SET(FLAGS_AVX "-D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__BMI__ -D__BMI2__ -D__LZCNT__") - SET(FLAGS_AVX2 "-D__AVX2__ -D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__BMI__ -D__BMI2__ -D__LZCNT__") + # Pure ARM build - no x86 flags + SET(FLAGS_SSE2 "") + SET(FLAGS_SSE42 "") + SET(FLAGS_AVX "") + SET(FLAGS_AVX2 "") + SET(FLAGS_AVX512 "") ENDIF () ELSE () + # x86/x64 build - set SSE/AVX flags # for `thread` keyword _SET_IF_EMPTY(FLAGS_SSE2 "-msse -msse2 -mno-sse4.2") _SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2") @@ -36,7 +45,12 @@ IF (WIN32) SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /EHsc") # catch C++ exceptions only and extern "C" functions never throw a C++ exception # SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /MP") # compile source files in parallel SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /GR") # enable runtime type information (on by default) - SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -Xclang -fcxx-exceptions") # enable C++ exceptions in Clang + + # Only add Clang-specific exception flags if not using MSVC + IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -Xclang -fcxx-exceptions") # enable C++ exceptions in Clang + ENDIF() + SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /w") # disable all warnings SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /Gy") # package individual functions IF (EMBREE_STACK_PROTECTOR) diff --git a/common/cmake/dpcpp.cmake b/common/cmake/dpcpp.cmake index a15c179ab9..08bea47e5d 100644 --- a/common/cmake/dpcpp.cmake +++ b/common/cmake/dpcpp.cmake @@ -7,11 +7,14 @@ MACRO(_SET_IF_EMPTY VAR VALUE) ENDIF() ENDMACRO() -_SET_IF_EMPTY(FLAGS_SSE2 "-msse2") -_SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2") -_SET_IF_EMPTY(FLAGS_AVX "-mavx") -_SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2") -_SET_IF_EMPTY(FLAGS_AVX512 "-march=skx") +# Skip x86-only ISA flags on Windows ARM64 +IF(NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|aarch64|arm64")) + _SET_IF_EMPTY(FLAGS_SSE2 "-msse2") + _SET_IF_EMPTY(FLAGS_SSE42 "-msse4.2") + _SET_IF_EMPTY(FLAGS_AVX "-mavx") + _SET_IF_EMPTY(FLAGS_AVX2 "-mf16c -mavx2 -mfma -mlzcnt -mbmi -mbmi2") + _SET_IF_EMPTY(FLAGS_AVX512 "-march=skx") +ENDIF() IF (NOT WIN32) OPTION(EMBREE_IGNORE_CMAKE_CXX_FLAGS "When enabled Embree ignores default CMAKE_CXX_FLAGS." ON) diff --git a/common/simd/arm/sse2neon.h b/common/simd/arm/sse2neon.h index 35e50a6e3e..c8bf92405d 100644 --- a/common/simd/arm/sse2neon.h +++ b/common/simd/arm/sse2neon.h @@ -56,6 +56,12 @@ * x86 SSE. (e.g. would solve a hole or NaN pixel in the rendering result) */ /* _mm_min|max_ps|ss|pd|sd */ +#ifdef _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#endif #ifndef SSE2NEON_PRECISE_MINMAX #define SSE2NEON_PRECISE_MINMAX (0) #endif @@ -9038,7 +9044,7 @@ FORCE_INLINE int _sse2neon_sido_negative(int res, int lb, int imm8, int bound) FORCE_INLINE int _sse2neon_clz(unsigned int x) { #if _MSC_VER - unsigned long cnt = 0; + DWORD cnt = 0; if (_BitScanForward(&cnt, x)) return cnt; return 32; @@ -9050,7 +9056,7 @@ FORCE_INLINE int _sse2neon_clz(unsigned int x) FORCE_INLINE int _sse2neon_ctz(unsigned int x) { #if _MSC_VER - unsigned long cnt = 0; + DWORD cnt = 0; if (_BitScanReverse(&cnt, x)) return 31 - cnt; return 32; diff --git a/common/sys/platform.h b/common/sys/platform.h index 6dc0cf3318..2d5e6d825c 100644 --- a/common/sys/platform.h +++ b/common/sys/platform.h @@ -3,6 +3,13 @@ #pragma once +// Prevent Windows from defining min/max macros that conflict with std::numeric_limits +#ifdef _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif +#endif + #if !defined(_CRT_SECURE_NO_WARNINGS) #define _CRT_SECURE_NO_WARNINGS #endif diff --git a/common/tasking/taskschedulertbb.cpp b/common/tasking/taskschedulertbb.cpp index cb2e710ce3..38b09edf49 100644 --- a/common/tasking/taskschedulertbb.cpp +++ b/common/tasking/taskschedulertbb.cpp @@ -45,7 +45,7 @@ namespace embree #endif /* now either keep default settings or configure number of threads */ - if (numThreads == std::numeric_limits::max()) { + if (numThreads == (std::numeric_limits::max)()) { // parentheses defeat Windows max() macro numThreads = threadCount(); } else {