Skip to content

Commit d590c88

Browse files
Try to add Apple Silicon (macOS arm64) support
Co-Authored-By: Niklas Gray <niklas@ourmachinery.com>
1 parent c3d5537 commit d590c88

7 files changed

Lines changed: 39 additions & 14 deletions

File tree

externals/cmakemodules/GetCompilerAndPlatform.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ FUNCTION (GetPlatformBinName PLATFORM_BIN_NAME LIBPATH_SUFFIX)
103103
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "uwp")
104104
SET(RETVAL "uwp.${PX_OUTPUT_ARCH}_${LIBPATH_SUFFIX}.${COMPILER}")
105105
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "mac")
106-
SET(RETVAL "mac.x86_${LIBPATH_SUFFIX}")
106+
IF(PX_OUTPUT_ARCH STREQUAL "x86")
107+
SET(RETVAL "mac.x86_${LIBPATH_SUFFIX}")
108+
ELSEIF(PX_OUTPUT_ARCH STREQUAL "arm")
109+
SET(RETVAL "mac.arm_${LIBPATH_SUFFIX}")
110+
ELSE()
111+
SET(RETVAL "mac.universal")
112+
ENDIF()
107113
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "ios")
108114
SET(RETVAL "ios.arm_${LIBPATH_SUFFIX}")
109115
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "ps4")

physx/source/compiler/cmake/mac/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@
2525
##
2626
## Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
2727

28-
SET(OSX_BITNESS "-arch x86_64")
29-
SET(CMAKE_OSX_ARCHITECTURES "x86_64")
28+
IF(PX_OUTPUT_ARCH STREQUAL "x86")
29+
SET(OSX_BITNESS "-arch x86_64 -msse2")
30+
SET(CMAKE_OSX_ARCHITECTURES "x86_64")
31+
ELSEIF(PX_OUTPUT_ARCH STREQUAL "arm")
32+
SET(OSX_BITNESS "-arch arm64")
33+
SET(CMAKE_OSX_ARCHITECTURES "arm64")
34+
ELSE()
35+
SET(OSX_BITNESS "-arch x86_64 -arch arm64 -msse2")
36+
SET(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
37+
ENDIF()
3038

31-
SET(PHYSX_CXX_FLAGS "${OSX_BITNESS} -msse2 -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -Werror -ferror-limit=0 -Wall -Wextra -fstrict-aliasing -Wstrict-aliasing=2 -Weverything -Wno-unknown-warning-option -Wno-documentation-deprecated-sync -Wno-documentation-unknown-command -Wno-float-equal -Wno-padded -Wno-weak-vtables -Wno-cast-align -Wno-conversion -Wno-missing-noreturn -Wno-missing-variable-declarations -Wno-shift-sign-overflow -Wno-covered-switch-default -Wno-exit-time-destructors -Wno-global-constructors -Wno-missing-prototypes -Wno-unreachable-code -Wno-unused-macros -Wno-unused-member-function -Wno-used-but-marked-unused -Wno-weak-template-vtables -Wno-deprecated -Wno-non-virtual-dtor -Wno-invalid-noreturn -Wno-return-type-c-linkage -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-unused-local-typedef -Wno-old-style-cast -Wno-newline-eof -Wno-unused-private-field -Wno-undefined-reinterpret-cast -Wno-invalid-offsetof -Wno-zero-as-null-pointer-constant -Wno-atomic-implicit-seq-cst -gdwarf-2" CACHE INTERNAL "PhysX CXX")
39+
SET(PHYSX_CXX_FLAGS "${OSX_BITNESS} -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -Werror -ferror-limit=0 -Wall -Wextra -fstrict-aliasing -Wstrict-aliasing=2 -Weverything -Wno-unknown-warning-option -Wno-documentation-deprecated-sync -Wno-documentation-unknown-command -Wno-float-equal -Wno-padded -Wno-weak-vtables -Wno-cast-align -Wno-conversion -Wno-missing-noreturn -Wno-missing-variable-declarations -Wno-shift-sign-overflow -Wno-covered-switch-default -Wno-exit-time-destructors -Wno-global-constructors -Wno-missing-prototypes -Wno-unreachable-code -Wno-unused-macros -Wno-unused-member-function -Wno-used-but-marked-unused -Wno-weak-template-vtables -Wno-deprecated -Wno-non-virtual-dtor -Wno-invalid-noreturn -Wno-return-type-c-linkage -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-unused-local-typedef -Wno-old-style-cast -Wno-newline-eof -Wno-unused-private-field -Wno-undefined-reinterpret-cast -Wno-invalid-offsetof -Wno-zero-as-null-pointer-constant -Wno-atomic-implicit-seq-cst -gdwarf-2" CACHE INTERNAL "PhysX CXX")
3240

3341
SET(CMAKE_SHARED_LINKER_FLAGS_CHECKED "")
3442
SET(CMAKE_SHARED_LINKER_FLAGS_PROFILE "")

physx/source/foundation/include/PsVecMath.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
#define COMPILE_VECTOR_INTRINSICS 1
5757
#elif PX_IOS && PX_NEON
5858
#define COMPILE_VECTOR_INTRINSICS 1
59+
#elif PX_OSX && PX_NEON
60+
#define COMPILE_VECTOR_INTRINSICS 1
5961
#elif PX_SWITCH
6062
#define COMPILE_VECTOR_INTRINSICS 1
6163
#else

physx/source/foundation/src/unix/PsUnixFPU.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
PX_COMPILE_TIME_ASSERT(8 * sizeof(uint32_t) >= sizeof(fenv_t));
3434
#endif
3535

36-
#if PX_OSX
36+
#if PX_OSX && (PX_X86 || PX_X64)
3737
// osx defines SIMD as standard for floating point operations.
3838
#include <xmmintrin.h>
3939
#endif
@@ -47,7 +47,7 @@ physx::shdfnd::FPUGuard::FPUGuard()
4747
#elif PX_PS4
4848
// not supported
4949
PX_UNUSED(mControlWords);
50-
#elif PX_OSX
50+
#elif PX_OSX && (PX_X86 || PX_X64)
5151
mControlWords[0] = _mm_getcsr();
5252
// set default (disable exceptions: _MM_MASK_MASK) and FTZ (_MM_FLUSH_ZERO_ON), DAZ (_MM_DENORMALS_ZERO_ON: (1<<6))
5353
_mm_setcsr(_MM_MASK_MASK | _MM_FLUSH_ZERO_ON | (1 << 6));
@@ -76,7 +76,7 @@ physx::shdfnd::FPUGuard::~FPUGuard()
7676
// not supported unless ARM_HARD_FLOAT is enabled.
7777
#elif PX_PS4
7878
// not supported
79-
#elif PX_OSX
79+
#elif PX_OSX && (PX_X86 || PX_X64)
8080
// restore control word and clear exception flags
8181
// (setting exception state flags cause exceptions on the first following fp operation)
8282
_mm_setcsr(mControlWords[0] & ~_MM_EXCEPT_MASK);
@@ -92,7 +92,7 @@ PX_FOUNDATION_API void physx::shdfnd::enableFPExceptions()
9292
#if PX_LINUX && !defined(__EMSCRIPTEN__)
9393
feclearexcept(FE_ALL_EXCEPT);
9494
feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
95-
#elif PX_OSX
95+
#elif PX_OSX && (PX_X86 || PX_X64)
9696
// clear any pending exceptions
9797
// (setting exception state flags cause exceptions on the first following fp operation)
9898
uint32_t control = _mm_getcsr() & ~_MM_EXCEPT_MASK;
@@ -108,7 +108,7 @@ PX_FOUNDATION_API void physx::shdfnd::disableFPExceptions()
108108
{
109109
#if PX_LINUX && !defined(__EMSCRIPTEN__)
110110
fedisableexcept(FE_ALL_EXCEPT);
111-
#elif PX_OSX
111+
#elif PX_OSX && (PX_X86 || PX_X64)
112112
// clear any pending exceptions
113113
// (setting exception state flags cause exceptions on the first following fp operation)
114114
uint32_t control = _mm_getcsr() & ~_MM_EXCEPT_MASK;

physx/source/geomutils/include/GuSIMDHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace Gu
7272
const QuatV qV = V4LoadU(&q.x);
7373
Vec3V column0V, column1V, column2V;
7474
QuatGetMat33V(qV, column0V, column1V, column2V);
75-
#if defined(PX_SIMD_DISABLED) || PX_ANDROID || (PX_LINUX && (PX_ARM || PX_A64)) || (PX_UWP && (PX_ARM || PX_A64))
75+
#if defined(PX_SIMD_DISABLED) || PX_ANDROID || (PX_LINUX && (PX_ARM || PX_A64)) || (PX_UWP && (PX_ARM || PX_A64)) || (PX_OSX && PX_A64)
7676
V3StoreU(column0V, column0);
7777
V3StoreU(column1V, column1);
7878
V3StoreU(column2V, column2);

physx/source/physxextensions/src/serialization/SnSerialUtils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using namespace physx;
3939
namespace
4040
{
4141

42-
#define SN_NUM_BINARY_PLATFORMS 16
42+
#define SN_NUM_BINARY_PLATFORMS 17
4343
const PxU32 sBinaryPlatformTags[SN_NUM_BINARY_PLATFORMS] =
4444
{
4545
PX_MAKE_FOURCC('W','_','3','2'),
@@ -58,6 +58,7 @@ const PxU32 sBinaryPlatformTags[SN_NUM_BINARY_PLATFORMS] =
5858
PX_MAKE_FOURCC('L','A','6','4'),
5959
PX_MAKE_FOURCC('W','A','3','2'),
6060
PX_MAKE_FOURCC('W','A','6','4'),
61+
PX_MAKE_FOURCC('M','A','6','4'),
6162
};
6263

6364
const char* sBinaryPlatformNames[SN_NUM_BINARY_PLATFORMS] =
@@ -78,6 +79,7 @@ const char* sBinaryPlatformNames[SN_NUM_BINARY_PLATFORMS] =
7879
"linuxaarch64",
7980
"uwparm",
8081
"uwparm64",
82+
"macaarch64"
8183
};
8284

8385
}
@@ -118,6 +120,8 @@ PxU32 getBinaryPlatformTag()
118120
return sBinaryPlatformTags[14];
119121
#elif PX_UWP && PX_A64
120122
return sBinaryPlatformTags[15];
123+
#elif PX_OSX && PX_A64
124+
return sBinaryPlatformTags[16];
121125
#else
122126
#error Unknown binary platform
123127
#endif

pxshared/include/foundation/PxPreprocessor.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,15 @@ Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSyst
100100
#define PX_ANDROID 1
101101
#elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
102102
#define PX_LINUX 1
103-
#elif defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
104-
#define PX_IOS 1
105103
#elif defined(__APPLE__)
106-
#define PX_OSX 1
104+
#include <TargetConditionals.h>
105+
#if TARGET_OS_IPHONE && TARGET_OS_MACCATALYST
106+
#define PX_OSX 1
107+
#elif TARGET_OS_IPHONE
108+
#define PX_IOS 1
109+
#else
110+
#define PX_OSX 1
111+
#endif
107112
#elif defined(__ORBIS__)
108113
#define PX_PS4 1
109114
#elif defined(__NX__)

0 commit comments

Comments
 (0)