From 445fd42c61c0ce74a40a82d79fa5778528665d31 Mon Sep 17 00:00:00 2001 From: Anthony Roberts Date: Wed, 6 Mar 2024 15:46:43 +0100 Subject: [PATCH] Windows: Add ARM64 support * Only works on machines with a Qualcomm Snapdragon 8cx Gen3 or above. Older generation devices are not and will not be supported due to some driver issues * Requires VS2022 for building. * Uses new MSVC preprocessor for sse2neon compatibility. * SIMD is not enabled, waiting on conversion of blenlib to C++. Ref #119126 Pull Request: https://projects.blender.org/blender/blender/pulls/117036 --- CMakeLists.txt | 12 +++++-- .../cmake/config/blender_release.cmake | 19 ++++++---- .../cmake/platform/platform_win32.cmake | 36 +++++++++++++++---- build_files/windows/check_libraries.cmd | 6 +++- build_files/windows/configure_msbuild.cmd | 5 +++ build_files/windows/detect_architecture.cmd | 6 ++++ build_files/windows/find_dependencies.cmd | 18 ++++++++++ build_files/windows/format.cmd | 5 +++ build_files/windows/parse_arguments.cmd | 2 ++ build_files/windows/show_hashes.cmd | 6 +++- extern/cuew/include/cuew.h | 2 +- extern/hipew/include/hipew.h | 2 +- extern/lzo/README.blender | 2 +- extern/lzo/minilzo/lzodefs.h | 2 +- extern/lzo/minilzo/minilzo.c | 2 +- intern/ghost/intern/GHOST_WindowWin32.cc | 30 ++++++++++++---- intern/ghost/intern/GHOST_Wintab.hh | 22 ++++++++---- source/blender/blenlib/BLI_compiler_attrs.h | 4 +-- source/blender/blenlib/BLI_simd.h | 4 ++- source/blender/blenlib/intern/system.c | 18 ++++++++++ source/blender/blenlib/intern/system_win32.c | 14 +++++++- source/blender/blenlib/intern/threads.cc | 6 ++++ .../bmesh/intern/bmesh_mesh_validate.cc | 7 ++++ source/blender/draw/intern/draw_manager.cc | 4 ++- source/blender/gpu/opengl/gl_backend.cc | 12 ++++--- source/blender/imbuf/CMakeLists.txt | 4 +-- .../blender/imbuf/intern/oiio/CMakeLists.txt | 4 +-- source/blender/io/usd/CMakeLists.txt | 5 +++ source/blender/makesrna/RNA_access.hh | 3 ++ .../modifiers/intern/MOD_simpledeform.cc | 2 +- source/blender/render/hydra/CMakeLists.txt | 5 +++ source/creator/CMakeLists.txt | 17 +++++++-- 32 files changed, 233 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f41d455fa4..18381a94413 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -640,7 +640,7 @@ mark_as_advanced(WITH_CYCLES_PRECOMPUTE) mark_as_advanced(CYCLES_TEST_DEVICES) # NVIDIA CUDA & OptiX -if(NOT APPLE) +if(NOT APPLE AND NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES ARM64)) option(WITH_CYCLES_DEVICE_CUDA "Enable Cycles NVIDIA CUDA compute support" ON) option(WITH_CYCLES_DEVICE_OPTIX "Enable Cycles NVIDIA OptiX support" ON) mark_as_advanced(WITH_CYCLES_DEVICE_CUDA) @@ -675,7 +675,7 @@ When set, this path will be used at runtime to compile OptiX kernels." endif() # AMD HIP -if(NOT APPLE) +if(NOT APPLE AND NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES ARM64)) option(WITH_CYCLES_DEVICE_HIP "Enable Cycles AMD HIP support" ON) option(WITH_CYCLES_HIP_BINARIES "Build Cycles AMD HIP binaries" OFF) # Radeon VII (gfx906) not currently working with HIP SDK, so left out of the list. @@ -702,7 +702,7 @@ if(APPLE) endif() # oneAPI -if(NOT APPLE) +if(NOT APPLE AND NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES ARM64)) option(WITH_CYCLES_DEVICE_ONEAPI "Enable Cycles oneAPI compute support" OFF) option(WITH_CYCLES_ONEAPI_BINARIES "\ Enable Ahead-Of-Time compilation for Cycles oneAPI device" @@ -2140,8 +2140,14 @@ set(CMAKE_CXX_EXTENSIONS OFF) # Make MSVC properly report the value of the __cplusplus preprocessor macro # Available MSVC 15.7 (1914) and up, without this it reports 199711L regardless # of the C++ standard chosen above. +# In addition, for ARM64 devices, we need to tell MSVC to use the new preprocessor +# This is because sse2neon requires it. if(MSVC) string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + string(APPEND CMAKE_CXX_FLAGS " /Zc:preprocessor") + string(APPEND CMAKE_C_FLAGS " /Zc:preprocessor") + endif() endif() # Visual Studio has all standards it supports available by default diff --git a/build_files/cmake/config/blender_release.cmake b/build_files/cmake/config/blender_release.cmake index b3bb4bfa0d1..d289907b65d 100644 --- a/build_files/cmake/config/blender_release.cmake +++ b/build_files/cmake/config/blender_release.cmake @@ -87,12 +87,17 @@ endif() if(NOT APPLE) set(WITH_XR_OPENXR ON CACHE BOOL "" FORCE) - set(WITH_CYCLES_DEVICE_OPTIX ON CACHE BOOL "" FORCE) - set(WITH_CYCLES_CUDA_BINARIES ON CACHE BOOL "" FORCE) - set(WITH_CYCLES_HIP_BINARIES ON CACHE BOOL "" FORCE) - set(WITH_CYCLES_DEVICE_ONEAPI ON CACHE BOOL "" FORCE) - set(WITH_CYCLES_ONEAPI_BINARIES ON CACHE BOOL "" FORCE) + # Can't use CMAKE_SYSTEM_PROCESSOR here as it's not set yet, + # so fall back to checking the env for vcvarsall's VSCMD_ARG_TGT_ARCH + if(NOT (WIN32 AND "$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm64")) + set(WITH_CYCLES_DEVICE_OPTIX ON CACHE BOOL "" FORCE) + set(WITH_CYCLES_CUDA_BINARIES ON CACHE BOOL "" FORCE) + set(WITH_CYCLES_HIP_BINARIES ON CACHE BOOL "" FORCE) + set(WITH_CYCLES_DEVICE_ONEAPI ON CACHE BOOL "" FORCE) + set(WITH_CYCLES_ONEAPI_BINARIES ON CACHE BOOL "" FORCE) + endif() endif() -if(WIN32) - set(WITH_CYCLES_DEVICE_HIPRT ON CACHE BOOL "" FORCE) + +if(WIN32 AND NOT (WIN32 AND "$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "arm64")) + set(WITH_CYCLES_DEVICE_HIPRT ON CACHE BOOL "" FORCE) endif() diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index ccbd4d5008c..7c64160cade 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -257,7 +257,11 @@ set(PLATFORM_LINKFLAGS_RELEASE "${PLATFORM_LINKFLAGS} ${PDB_INFO_OVERRIDE_LINKER string(APPEND CMAKE_STATIC_LINKER_FLAGS " /ignore:4221") if(CMAKE_CL_64) - string(PREPEND PLATFORM_LINKFLAGS "/MACHINE:X64 ") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + string(PREPEND PLATFORM_LINKFLAGS "/MACHINE:ARM64 ") + else() + string(PREPEND PLATFORM_LINKFLAGS "/MACHINE:X64 ") + endif() else() string(PREPEND PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ") endif() @@ -266,7 +270,11 @@ if(NOT DEFINED LIBDIR) # Setup 64bit and 64bit windows systems if(CMAKE_CL_64) message(STATUS "64 bit compiler detected.") - set(LIBDIR_BASE "windows_x64") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + set(LIBDIR_BASE "windows_arm64") + else() + set(LIBDIR_BASE "windows_x64") + endif() else() message(FATAL_ERROR "32 bit compiler detected, blender no longer provides pre-build libraries for 32 bit windows, please set the LIBDIR cmake variable to your own library folder") endif() @@ -604,9 +612,15 @@ if(NOT WITH_WINDOWS_FIND_MODULES) if(NOT BOOST_VERSION) message(FATAL_ERROR "Unable to determine Boost version") endif() - set(BOOST_POSTFIX "vc142-mt-x64-${BOOST_VERSION}") - set(BOOST_DEBUG_POSTFIX "vc142-mt-gyd-x64-${BOOST_VERSION}") - set(BOOST_PREFIX "") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + set(BOOST_POSTFIX "vc143-mt-a64-${BOOST_VERSION}") + set(BOOST_DEBUG_POSTFIX "vc143-mt-gyd-a64-${BOOST_VERSION}") + set(BOOST_PREFIX "") + else() + set(BOOST_POSTFIX "vc142-mt-x64-${BOOST_VERSION}") + set(BOOST_DEBUG_POSTFIX "vc142-mt-gyd-x64-${BOOST_VERSION}") + set(BOOST_PREFIX "") + endif() endif() if(WITH_BOOST) @@ -625,8 +639,9 @@ if(WITH_BOOST) if(NOT Boost_FOUND) warn_hardcoded_paths(BOOST) # This is file new in 3.4 if it does not exist, assume we are building against 3.3 libs + # Note, as ARM64 was introduced in 4.x, this check is not needed set(BOOST_34_TRIGGER_FILE ${BOOST_LIBPATH}/${BOOST_PREFIX}boost_python${_PYTHON_VERSION_NO_DOTS}-${BOOST_DEBUG_POSTFIX}.lib) - if(NOT EXISTS ${BOOST_34_TRIGGER_FILE}) + if (NOT EXISTS ${BOOST_34_TRIGGER_FILE}) set(BOOST_DEBUG_POSTFIX "vc142-mt-gd-x64-${BOOST_VERSION}") set(BOOST_PREFIX "lib") endif() @@ -893,6 +908,15 @@ if(WITH_CODEC_SNDFILE) endif() endif() +if(WITH_CPU_SIMD AND SUPPORT_NEON_BUILD) + windows_find_package(sse2neon) + if(NOT SSE2NEON_FOUND) + set(SSE2NEON_ROOT_DIR ${LIBDIR}/sse2neon) + set(SSE2NEON_INCLUDE_DIRS ${LIBDIR}/sse2neon) + set(SSE2NEON_FOUND True) + endif() +endif() + if(WITH_CYCLES AND WITH_CYCLES_OSL) set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation") set(OSL_SHADER_DIR ${CYCLES_OSL}/shaders) diff --git a/build_files/windows/check_libraries.cmd b/build_files/windows/check_libraries.cmd index 8c92ac72aa8..1ef19e6a827 100644 --- a/build_files/windows/check_libraries.cmd +++ b/build_files/windows/check_libraries.cmd @@ -1,4 +1,8 @@ -set BUILD_VS_LIBDIR=lib/windows_x64 +if "%BUILD_ARCH%" == "arm64" ( + set BUILD_VS_LIBDIR=lib/windows_arm64 +) else ( + set BUILD_VS_LIBDIR=lib/windows_x64 +) if NOT "%verbose%" == "" ( echo Library Directory = "%BUILD_VS_LIBDIR%" diff --git a/build_files/windows/configure_msbuild.cmd b/build_files/windows/configure_msbuild.cmd index 9fbdef25641..d4be40aff4f 100644 --- a/build_files/windows/configure_msbuild.cmd +++ b/build_files/windows/configure_msbuild.cmd @@ -19,6 +19,11 @@ if "%WITH_PYDEBUG%"=="1" ( set PYDEBUG_CMAKE_ARGS=-DWINDOWS_PYTHON_DEBUG=On ) +if "%BUILD_ARCH%"=="arm64" ( + set MSBUILD_PLATFORM=arm64 + set BUILD_PLATFORM_SELECT=-A ARM64 +) + set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio %BUILD_VS_VER% %BUILD_VS_YEAR%%BUILD_GENERATOR_POST%" %BUILD_PLATFORM_SELECT% %TESTS_CMAKE_ARGS% %CLANG_CMAKE_ARGS% %ASAN_CMAKE_ARGS% %PYDEBUG_CMAKE_ARGS% if NOT EXIST %BUILD_DIR%\nul ( diff --git a/build_files/windows/detect_architecture.cmd b/build_files/windows/detect_architecture.cmd index 42663ef2d29..c78575f3605 100644 --- a/build_files/windows/detect_architecture.cmd +++ b/build_files/windows/detect_architecture.cmd @@ -5,12 +5,18 @@ if "%BUILD_ARCH%"=="" ( ) else if "%PROCESSOR_ARCHITEW6432%" == "AMD64" ( set WINDOWS_ARCH= Win64 set BUILD_ARCH=x64 + ) else if "%PROCESSOR_ARCHITECTURE%" == "ARM64" ( + set WINDOWS_ARCH= arm64 + set BUILD_ARCH=arm64 ) else ( echo Error: 32 bit builds of blender are no longer supported. goto ERR ) ) else if "%BUILD_ARCH%"=="x64" ( set WINDOWS_ARCH= Win64 +) else if "%BUILD_ARCH%"=="arm64" ( + set WINDOWS_ARCH= arm64 + set BUILD_ARCH=arm64 ) :EOF exit /b 0 diff --git a/build_files/windows/find_dependencies.cmd b/build_files/windows/find_dependencies.cmd index c697da2bccf..88c0fa6ba2b 100644 --- a/build_files/windows/find_dependencies.cmd +++ b/build_files/windows/find_dependencies.cmd @@ -23,6 +23,24 @@ if EXIST %PYTHON% ( goto detect_python_done ) +rem Additionally check for the ARM64 version +set PYTHON=%BLENDER_DIR%\lib\windows_arm64\python\310\bin\python.exe +if EXIST %PYTHON% ( + goto detect_python_done +) +set PYTHON=%BLENDER_DIR%\lib\windows_arm64\python\311\bin\python.exe +if EXIST %PYTHON% ( + goto detect_python_done +) +set PYTHON=%BLENDER_DIR%\lib\windows_arm64\python\312\bin\python.exe +if EXIST %PYTHON% ( + goto detect_python_done +) +set PYTHON=%BLENDER_DIR%\lib\windows_arm64\python\39\bin\python.exe +if EXIST %PYTHON% ( + goto detect_python_done +) + if NOT EXIST %PYTHON% ( if EXIST %BLENDER_DIR%\lib\windows_x64\.git ( echo Warning: Python not found, there is likely an issue with the library folder diff --git a/build_files/windows/format.cmd b/build_files/windows/format.cmd index 4546b04c295..d276521d83e 100644 --- a/build_files/windows/format.cmd +++ b/build_files/windows/format.cmd @@ -3,6 +3,11 @@ if EXIST %BLENDER_DIR%\lib\windows_x64\llvm\bin\clang-format.exe ( goto detect_done ) +if EXIST %BLENDER_DIR%\lib\windows_arm64\llvm\bin\clang-format.exe ( + set CF_PATH=lib\windows_arm64\llvm\bin + goto detect_done +) + echo clang-format not found exit /b 1 diff --git a/build_files/windows/parse_arguments.cmd b/build_files/windows/parse_arguments.cmd index 40a1c9dce11..937c56768a5 100644 --- a/build_files/windows/parse_arguments.cmd +++ b/build_files/windows/parse_arguments.cmd @@ -50,6 +50,8 @@ if NOT "%1" == "" ( goto ERR ) else if "%1" == "x64" ( set BUILD_ARCH=x64 + ) else if "%1" == "arm64" ( + set BUILD_ARCH=arm64 ) else if "%1" == "2019" ( set BUILD_VS_YEAR=2019 ) else if "%1" == "2019pre" ( diff --git a/build_files/windows/show_hashes.cmd b/build_files/windows/show_hashes.cmd index a4d8d36e06c..04a234b8207 100644 --- a/build_files/windows/show_hashes.cmd +++ b/build_files/windows/show_hashes.cmd @@ -9,7 +9,11 @@ cd "%BLENDER_DIR%/scripts/addons" for /f "delims=" %%i in ('"%GIT%" rev-parse --abbrev-ref HEAD') do echo Addons_Branch_name=%%i for /f "delims=" %%i in ('"%GIT%" rev-parse HEAD') do echo Addons_Branch_hash=%%i -cd "%BLENDER_DIR%/lib/windows_x64" +if "%BUILD_ARCH%" == "arm64" ( + cd "%BLENDER_DIR%/lib/windows_arm64" +) else ( + cd "%BLENDER_DIR%/lib/windows_x64" +) for /f "delims=" %%i in ('"%GIT%" rev-parse --abbrev-ref HEAD') do echo Libs_Branch_name=%%i for /f "delims=" %%i in ('"%GIT%" rev-parse HEAD') do echo Libs_Branch_hash=%%i diff --git a/extern/cuew/include/cuew.h b/extern/cuew/include/cuew.h index 278fb1172ee..6206c882063 100644 --- a/extern/cuew/include/cuew.h +++ b/extern/cuew/include/cuew.h @@ -127,7 +127,7 @@ typedef uint32_t cuuint32_t; typedef uint64_t cuuint64_t; #endif -#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) || defined (__aarch64__) || defined(__ppc64__) || defined(__PPC64__) +#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) || defined (__aarch64__) || defined(_M_ARM64) || defined(__ppc64__) || defined(__PPC64__) typedef unsigned long long CUdeviceptr; #else typedef unsigned int CUdeviceptr; diff --git a/extern/hipew/include/hipew.h b/extern/hipew/include/hipew.h index df7498aaeae..52bc26f8bbd 100644 --- a/extern/hipew/include/hipew.h +++ b/extern/hipew/include/hipew.h @@ -86,7 +86,7 @@ typedef uint32_t hipuint32_t; typedef uint64_t hipuint64_t; #endif -#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) || defined (__aarch64__) || defined(__ppc64__) || defined(__PPC64__) +#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) || defined (__aarch64__) || defined(_M_ARM64) || defined(__ppc64__) || defined(__PPC64__) typedef unsigned long long hipDeviceptr_t; #else typedef unsigned int hipDeviceptr_t; diff --git a/extern/lzo/README.blender b/extern/lzo/README.blender index d91500b7780..674f2413034 100644 --- a/extern/lzo/README.blender +++ b/extern/lzo/README.blender @@ -2,4 +2,4 @@ Project: miniLZO - mini subset of the LZO real-time data compression librar URL: http://www.oberhumer.com/opensource/lzo/ License: GPLv2+ Upstream version: 2.08 -Local modifications: None +Local modifications: Add #ifdef for Windows ARM64 (MSVC) platforms diff --git a/extern/lzo/minilzo/lzodefs.h b/extern/lzo/minilzo/lzodefs.h index f4ae9487ebe..feee5cdf3d2 100644 --- a/extern/lzo/minilzo/lzodefs.h +++ b/extern/lzo/minilzo/lzodefs.h @@ -770,7 +770,7 @@ #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 # define LZO_INFO_ARCH "i086" -#elif defined(__aarch64__) +#elif defined(__aarch64__) || defined(_M_ARM64) # define LZO_ARCH_ARM64 1 # define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) diff --git a/extern/lzo/minilzo/minilzo.c b/extern/lzo/minilzo/minilzo.c index ab2be5f4fd0..86fb4ecd2f2 100644 --- a/extern/lzo/minilzo/minilzo.c +++ b/extern/lzo/minilzo/minilzo.c @@ -790,7 +790,7 @@ #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 # define LZO_INFO_ARCH "i086" -#elif defined(__aarch64__) +#elif defined(__aarch64__) || defined(_M_ARM64) # define LZO_ARCH_ARM64 1 # define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) diff --git a/intern/ghost/intern/GHOST_WindowWin32.cc b/intern/ghost/intern/GHOST_WindowWin32.cc index d6c5e184705..2f7bf67533b 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cc +++ b/intern/ghost/intern/GHOST_WindowWin32.cc @@ -22,6 +22,10 @@ # include "GHOST_ContextVK.hh" #endif +#ifdef WIN32 +# include "BLI_path_util.h" +#endif + #include #include @@ -127,15 +131,27 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system, if (!setDrawingContextType(type)) { const char *title = "Blender - Unsupported Graphics Card Configuration"; - const char *text = - "A graphics card and driver with support for OpenGL 4.3 or higher is " - "required.\n\nInstalling the latest driver for your graphics card might resolve the " - "issue."; - if (GetSystemMetrics(SM_CMONITORS) > 1) { + const char *text = ""; +#if defined(WIN32) + if (strncmp(BLI_getenv("PROCESSOR_IDENTIFIER"), "ARM", 3) == 0) { + text = + "A driver with support for OpenGL 4.3 or higher is required.\n\n" + "If you are on a Qualcomm 8cx Gen3 device or newer, you need to download the" + "\"OpenCL™, OpenGL®, and Vulkan® Compatibility Pack\" from the MS Store."; + } + else +#endif + { text = "A graphics card and driver with support for OpenGL 4.3 or higher is " - "required.\n\nPlugging all monitors into your primary graphics card might resolve " - "this issue. Installing the latest driver for your graphics card could also help."; + "required.\n\nInstalling the latest driver for your graphics card might resolve the " + "issue."; + if (GetSystemMetrics(SM_CMONITORS) > 1) { + text = + "A graphics card and driver with support for OpenGL 4.3 or higher is " + "required.\n\nPlugging all monitors into your primary graphics card might resolve " + "this issue. Installing the latest driver for your graphics card could also help."; + } } MessageBox(m_hWnd, text, title, MB_OK | MB_ICONERROR); ::ReleaseDC(m_hWnd, m_hDC); diff --git a/intern/ghost/intern/GHOST_Wintab.hh b/intern/ghost/intern/GHOST_Wintab.hh index 2747d61716b..42f1f35012c 100644 --- a/intern/ghost/intern/GHOST_Wintab.hh +++ b/intern/ghost/intern/GHOST_Wintab.hh @@ -28,13 +28,23 @@ #define PACKETMODE 0 #include -#define WINTAB_PRINTF(x, ...) \ - { \ - if (GHOST_Wintab::getDebug()) { \ - printf(x, __VA_ARGS__); \ +#if !defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL +# define WINTAB_PRINTF(x, ...) \ + { \ + if (GHOST_Wintab::getDebug()) { \ + printf(x, __VA_ARGS__); \ + } \ } \ - } \ - (void)0 + (void)0 +#else +# define WINTAB_PRINTF(x, ...) \ + { \ + if (GHOST_Wintab::getDebug()) { \ + printf(x, ##__VA_ARGS__); \ + } \ + } \ + (void)0 +#endif /* Typedefs for Wintab functions to allow dynamic loading. */ typedef UINT(API *GHOST_WIN32_WTInfo)(UINT, UINT, LPVOID); diff --git a/source/blender/blenlib/BLI_compiler_attrs.h b/source/blender/blenlib/BLI_compiler_attrs.h index 0a9d20748cb..0f48ca0dd2d 100644 --- a/source/blender/blenlib/BLI_compiler_attrs.h +++ b/source/blender/blenlib/BLI_compiler_attrs.h @@ -86,7 +86,7 @@ /* Alignment directive */ #ifdef _WIN64 -# define ALIGN_STRUCT __declspec(align(64)) +# define BLI_ALIGN_STRUCT __declspec(align(64)) #else -# define ALIGN_STRUCT +# define BLI_ALIGN_STRUCT #endif diff --git a/source/blender/blenlib/BLI_simd.h b/source/blender/blenlib/BLI_simd.h index 3d348b35e88..885966d2cdf 100644 --- a/source/blender/blenlib/BLI_simd.h +++ b/source/blender/blenlib/BLI_simd.h @@ -10,7 +10,9 @@ * SIMD instruction support. */ -#if defined(__ARM_NEON) && defined(WITH_SSE2NEON) +// TODO: Re-enable this once blenlib is converted to C++ +#if (defined(__ARM_NEON) /* || (defined(_M_ARM64) && defined(_MSC_VER))*/) && \ + defined(WITH_SSE2NEON) /* SSE/SSE2 emulation on ARM Neon. Match SSE precision. */ # if !defined(SSE2NEON_PRECISE_MINMAX) # define SSE2NEON_PRECISE_MINMAX 1 diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c index 13cba35106d..888b20d2f89 100644 --- a/source/blender/blenlib/intern/system.c +++ b/source/blender/blenlib/intern/system.c @@ -127,6 +127,7 @@ static void __cpuid( char *BLI_cpu_brand_string(void) { +#if !defined(_M_ARM64) char buf[49] = {0}; int result[4] = {0}; __cpuid(result, 0x80000000); @@ -138,11 +139,27 @@ char *BLI_cpu_brand_string(void) /* TODO(sergey): Make it a bit more presentable by removing trademark. */ return brand; } +#else + // No CPUID on ARM64, so we pull from the registry (on Windows) instead + DWORD vendorIdentifierLength = 255; + char vendorIdentifier[255]; + if (RegGetValueA(HKEY_LOCAL_MACHINE, + "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", + "VendorIdentifier", + RRF_RT_REG_SZ, + NULL, + &vendorIdentifier, + &vendorIdentifierLength) == ERROR_SUCCESS) + { + return BLI_strdup(vendorIdentifier); + } +#endif return NULL; } int BLI_cpu_support_sse42(void) { +#if !defined(_M_ARM64) int result[4], num; __cpuid(result, 0); num = result[0]; @@ -151,6 +168,7 @@ int BLI_cpu_support_sse42(void) __cpuid(result, 0x00000001); return (result[2] & ((int)1 << 20)) != 0; } +#endif return 0; } diff --git a/source/blender/blenlib/intern/system_win32.c b/source/blender/blenlib/intern/system_win32.c index 8b384a670d5..2924db0f668 100644 --- a/source/blender/blenlib/intern/system_win32.c +++ b/source/blender/blenlib/intern/system_win32.c @@ -144,15 +144,27 @@ static bool BLI_windows_system_backtrace_run_trace(FILE *fp, HANDLE hThread, PCO symbolinfo->SizeOfStruct = sizeof(SYMBOL_INFO); STACKFRAME frame = {0}; + DWORD machineType = 0; +#if defined(_M_AMD64) frame.AddrPC.Offset = context->Rip; frame.AddrPC.Mode = AddrModeFlat; frame.AddrFrame.Offset = context->Rsp; frame.AddrFrame.Mode = AddrModeFlat; frame.AddrStack.Offset = context->Rsp; frame.AddrStack.Mode = AddrModeFlat; + machineType = IMAGE_FILE_MACHINE_AMD64; +#elif defined(_M_ARM64) + frame.AddrPC.Offset = context->Pc; + frame.AddrPC.Mode = AddrModeFlat; + frame.AddrFrame.Offset = context->Fp; + frame.AddrFrame.Mode = AddrModeFlat; + frame.AddrStack.Offset = context->Sp; + frame.AddrStack.Mode = AddrModeFlat; + machineType = IMAGE_FILE_MACHINE_ARM64; +#endif while (true) { - if (StackWalk64(IMAGE_FILE_MACHINE_AMD64, + if (StackWalk64(machineType, GetCurrentProcess(), hThread, &frame, diff --git a/source/blender/blenlib/intern/threads.cc b/source/blender/blenlib/intern/threads.cc index 959a5671413..71277b1c786 100644 --- a/source/blender/blenlib/intern/threads.cc +++ b/source/blender/blenlib/intern/threads.cc @@ -410,7 +410,13 @@ void BLI_spin_lock(SpinLock *spin) #elif defined(__APPLE__) BLI_mutex_lock(spin); #elif defined(_MSC_VER) +# if defined(_M_ARM64) + // InterlockedExchangeAcquire takes a long arg on MSVC ARM64 + static_assert(sizeof(long) == sizeof(SpinLock)); + while (InterlockedExchangeAcquire((volatile long *)spin, 1)) { +# else while (InterlockedExchangeAcquire(spin, 1)) { +# endif while (*spin) { /* Spin-lock hint for processors with hyper-threading. */ YieldProcessor(); diff --git a/source/blender/bmesh/intern/bmesh_mesh_validate.cc b/source/blender/bmesh/intern/bmesh_mesh_validate.cc index 3e81f446064..8a6adfe549d 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_validate.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_validate.cc @@ -28,6 +28,13 @@ errtot++; \ } \ (void)0 +# elif defined(_MSVC_TRADITIONAL) && !_MSVC_TRADITIONAL +# define ERRMSG(format, ...) \ + { \ + fprintf(stderr, "%s: " format ", " AT "\n", __func__, ##__VA_ARGS__); \ + errtot++; \ + } \ + (void)0 # else # define ERRMSG(format, ...) \ { \ diff --git a/source/blender/draw/intern/draw_manager.cc b/source/blender/draw/intern/draw_manager.cc index 4b4250069f7..d5868a39b1d 100644 --- a/source/blender/draw/intern/draw_manager.cc +++ b/source/blender/draw/intern/draw_manager.cc @@ -47,7 +47,9 @@ void Manager::begin_sync() acquired_textures.clear(); layer_attributes.clear(); -#ifndef NDEBUG +// For some reason, if this uninitialised data pattern was enabled (ie release asserts enabled), +// The viewport just gives up rendering objects on ARM64 devices. Possibly Mesa GLOn12-related. +#if !defined(NDEBUG) && !defined(_M_ARM64) /* Detect uninitialized data. */ memset(matrix_buf.current().data(), 0xF0, diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc index 667d3153262..8d563127cdd 100644 --- a/source/blender/gpu/opengl/gl_backend.cc +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -431,11 +431,15 @@ static void detect_workarounds() } } - /* Right now draw shader parameters are broken on Qualcomm devices - * regardless of driver version */ + /* Draw shader parameters are broken on Qualcomm Windows ARM64 devices + * on Mesa version < 24.0.0 */ if (GPU_type_matches(GPU_DEVICE_QUALCOMM, GPU_OS_WIN, GPU_DRIVER_ANY)) { - GCaps.shader_draw_parameters_support = false; - GLContext::shader_draw_parameters_support = false; + if (strstr(version, "Mesa 20.") || strstr(version, "Mesa 21.") || + strstr(version, "Mesa 22.") || strstr(version, "Mesa 23.")) + { + GCaps.shader_draw_parameters_support = false; + GLContext::shader_draw_parameters_support = false; + } } /* Some Intel drivers have issues with using mips as frame-buffer targets if diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt index c2ca3f2f3a7..4c179a88941 100644 --- a/source/blender/imbuf/CMakeLists.txt +++ b/source/blender/imbuf/CMakeLists.txt @@ -102,8 +102,8 @@ else() endif() # Keep until APPLE/ARM libraries are updated. -if(APPLE) - if(CMAKE_OSX_ARCHITECTURES MATCHES arm64) +if(APPLE OR WIN32) + if(CMAKE_OSX_ARCHITECTURES MATCHES arm64 OR CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) list(APPEND INC_SYS ${IMATH_INCLUDE_DIRS} ) diff --git a/source/blender/imbuf/intern/oiio/CMakeLists.txt b/source/blender/imbuf/intern/oiio/CMakeLists.txt index 76f9cde7b47..ed1fa1a0604 100644 --- a/source/blender/imbuf/intern/oiio/CMakeLists.txt +++ b/source/blender/imbuf/intern/oiio/CMakeLists.txt @@ -45,8 +45,8 @@ if(WITH_IMAGE_OPENEXR) endif() # Keep until APPLE/ARM libraries are updated. -if(APPLE) - if(CMAKE_OSX_ARCHITECTURES MATCHES arm64) +if(APPLE OR WIN32) + if(CMAKE_OSX_ARCHITECTURES MATCHES arm64 OR CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) list(APPEND INC_SYS ${IMATH_INCLUDE_DIRS} ) diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 26c77b19c55..bd17477e2cc 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -52,6 +52,11 @@ if(WIN32) # warning alert. # Silence them by restore warn C4100 back to w4 remove_cc_flag("/w34100") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + # USD currently does not support the new preprocessor, + # and does not use sse2neon, so we can remove it here + remove_cc_flag("/Zc:preprocessor") + endif() endif() set(INC diff --git a/source/blender/makesrna/RNA_access.hh b/source/blender/makesrna/RNA_access.hh index 106ad2b131b..ec675745201 100644 --- a/source/blender/makesrna/RNA_access.hh +++ b/source/blender/makesrna/RNA_access.hh @@ -791,6 +791,9 @@ StructRNA *ID_code_to_RNA_type(short idcode); /* macro which inserts the function name */ #if defined __GNUC__ # define RNA_warning(format, args...) _RNA_warning("%s: " format "\n", __func__, ##args) +#elif defined(_MSVC_TRADITIONAL) && \ + !_MSVC_TRADITIONAL // The "new preprocessor" is enabled via /Zc:preprocessor +# define RNA_warning(format, ...) _RNA_warning("%s: " format "\n", __FUNCTION__, ##__VA_ARGS__) #else # define RNA_warning(format, ...) _RNA_warning("%s: " format "\n", __FUNCTION__, __VA_ARGS__) #endif diff --git a/source/blender/modifiers/intern/MOD_simpledeform.cc b/source/blender/modifiers/intern/MOD_simpledeform.cc index 7ed2e677ea0..cb93c12f904 100644 --- a/source/blender/modifiers/intern/MOD_simpledeform.cc +++ b/source/blender/modifiers/intern/MOD_simpledeform.cc @@ -31,7 +31,7 @@ #define BEND_EPS 0.000001f -ALIGN_STRUCT struct DeformUserData { +BLI_ALIGN_STRUCT struct DeformUserData { bool invert_vgroup; char mode; char deform_axis; diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 9b1622f19ad..fa9fd282fb1 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -33,6 +33,11 @@ if(WIN32) # warning alert. # Silence them by restore warn C4100 back to w4 remove_cc_flag("/w34100") + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + # USD currently does not support the new preprocessor, + # and does not use sse2neon, so we can remove it here + remove_cc_flag("/Zc:preprocessor") + endif() endif() set(INC diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 13ed1176b00..54e8eab5f63 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -619,6 +619,11 @@ if(WIN32) ${LIBDIR}/OpenImageDenoise/bin/OpenImageDenoise.dll ${LIBDIR}/OpenImageDenoise/bin/OpenImageDenoise_core.dll ${LIBDIR}/OpenImageDenoise/bin/OpenImageDenoise_device_cpu.dll + ) + endif() + if(EXISTS ${LIBDIR}/OpenImageDenoise/bin/OpenImageDenoise_device_sycl.dll) # Platforms that have SyCL support + windows_install_shared_manifest( + FILES ${LIBDIR}/OpenImageDenoise/bin/OpenImageDenoise_device_sycl.dll ) endif() @@ -1345,14 +1350,20 @@ elseif(WIN32) endif() # this will exist for 4.1 lib folders - if(EXISTS ${LIBDIR}/openvdb/python/pyopenvdb_d.cp${_PYTHON_VERSION_NO_DOTS}-win_amd64.pyd) + if(CMAKE_SYSTEM_PROCESSOR MATCHES ARM64) + set(_openvdb_arch arm64) + else() + set(_openvdb_arch amd64) + endif() + + if(EXISTS ${LIBDIR}/openvdb/python/pyopenvdb_d.cp${_PYTHON_VERSION_NO_DOTS}-win_${_openvdb_arch}.pyd) install( - FILES ${LIBDIR}/openvdb/python/pyopenvdb_d.cp${_PYTHON_VERSION_NO_DOTS}-win_amd64.pyd + FILES ${LIBDIR}/openvdb/python/pyopenvdb_d.cp${_PYTHON_VERSION_NO_DOTS}-win_${_openvdb_arch}.pyd DESTINATION ${TARGETDIR_VER}/python/lib/site-packages CONFIGURATIONS Debug ) install( - FILES ${LIBDIR}/openvdb/python/pyopenvdb.cp${_PYTHON_VERSION_NO_DOTS}-win_amd64.pyd + FILES ${LIBDIR}/openvdb/python/pyopenvdb.cp${_PYTHON_VERSION_NO_DOTS}-win_${_openvdb_arch}.pyd DESTINATION ${TARGETDIR_VER}/python/lib/site-packages CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel )