Skip to content

Commit 7d27bbe

Browse files
authored
Android platform support (#1)
## What's new? - Added Android platform support to PhysX 5.1. - New build preset `android-arm64-v8a` added. Initial support focused on 64-bit arm8 architecture with NEON SIMD instructions. - Support for generating PhysX as either static or dynamic libraries. - New android platform readme. ## Out of Scope The following points are considered out of scope, they can be added in the future: - Support for PhysX Snippets. - Support for Omniverse Visual Debugger (OmniPVD) . - Support for other architectures: arm7, x86, x86_64. - Support for other SIMD instructions set: SSE. ## Known Errors/Limitations - The name of the bin folder for android will appear as `bin\UNKNOWN`. **To fix this nVidia has to modify the CMakeModules package it's downloaded from packman when building PhysX** (NVIDIA-Omniverse#59). The file that needs to be modified is `GetCompilerAndPlatform.cmake`, adding the following lines to the `if` condition inside `GetPlatformBinName` function: ```` ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "android") SET(RETVAL "android.${ANDROID_ABI}") ```` - PhysX Systems that require a CUDA capable GPU are not supported in Android, for example particle system or cloth simulation. ## Testing - Built PhysX 5.1 successfully on android in debug, checked, profile and release using `PX_GENERATE_STATIC_LIBRARIES` set to both true and false. The right output binaries were generated in `bin/android.arm64-v8a` - Built cmake `install` target successfully. It generated the correct output for Android under `install/android-29` folder, only including necessary headers for Android. - Runtime tested using `Open 3D Engine (O3DE)` with an early integration [branch](https://github.com/aws-lumberyard-dev/o3de/tree/PhysX5Support). The following video shows O3DE running PhysX 5.1 on Android. https://user-images.githubusercontent.com/27999040/203624867-6ed19905-d0dc-4dfe-943a-46e584fd9983.mp4 Signed-off-by: moraaar <[email protected]>
1 parent 5044420 commit 7d27bbe

40 files changed

+1136
-27
lines changed

physx/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
bin/
22
compiler/linux-*
33
compiler/vc*
4+
compiler/android*
45
include/PxConfig.h
6+
install/

physx/buildtools/cmake_generate_projects.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def cmakeExt():
2020

2121

2222
def filterPreset(presetName):
23-
winPresetFilter = ['win','switch','crosscompile']
23+
winPresetFilter = ['win','switch','crosscompile','android']
2424
if sys.platform == 'win32':
2525
if any(presetName.find(elem) != -1 for elem in winPresetFilter):
2626
return True
@@ -101,6 +101,14 @@ def __init__(self, presetName):
101101
cmParam = '-D' + cmakeParam.attrib['name'] + '=\"' + \
102102
os.environ['PHYSX_ROOT_DIR'] + '/' + \
103103
cmakeParam.attrib['value'] + '\"'
104+
elif cmakeParam.attrib['name'] == 'ANDROID_ABI':
105+
cmParam = '-D' + \
106+
cmakeParam.attrib['name'] + '=\"' + \
107+
cmakeParam.attrib['value'] + '\"'
108+
if cmakeParam.attrib['value'].startswith('arm'):
109+
cmParam = cmParam + ' -DPX_OUTPUT_ARCH=arm'
110+
elif cmakeParam.attrib['value'].startswith('x86'):
111+
cmParam = cmParam + ' -DPX_OUTPUT_ARCH=x86'
104112
else:
105113
cmParam = '-D' + \
106114
cmakeParam.attrib['name'] + '=' + \
@@ -113,6 +121,8 @@ def isMultiConfigPlatform(self):
113121
return False
114122
elif self.targetPlatform == 'linuxAarch64':
115123
return False
124+
elif self.targetPlatform == 'android':
125+
return False
116126
return True
117127

118128
def getCMakeSwitches(self):
@@ -152,6 +162,8 @@ def getPlatformCMakeParams(self):
152162
outString = outString + '-G \"Visual Studio 16 2019\"'
153163
elif self.compiler == 'xcode':
154164
outString = outString + '-G Xcode'
165+
elif self.targetPlatform == 'android':
166+
outString = outString + '-G \"MinGW Makefiles\"'
155167
elif self.targetPlatform == 'linux':
156168
outString = outString + '-G \"Unix Makefiles\"'
157169
elif self.targetPlatform == 'linuxAarch64':
@@ -181,6 +193,22 @@ def getPlatformCMakeParams(self):
181193
'/switch/NX64Toolchain.txt'
182194
outString = outString + ' -DCMAKE_GENERATOR_PLATFORM=NX64'
183195
return outString
196+
elif self.targetPlatform == 'android':
197+
outString = outString + ' -DTARGET_BUILD_PLATFORM=android'
198+
if os.environ.get('ANDROID_NDK_HOME') is None:
199+
print('Please provide path to android NDK in environment variable ANDROID_NDK_HOME.')
200+
exit(-1)
201+
else:
202+
outString = outString + ' -DCMAKE_TOOLCHAIN_FILE=' + \
203+
os.environ['ANDROID_NDK_HOME'] + \
204+
'/build/cmake/android.toolchain.cmake'
205+
outString = outString + ' -DANDROID_STL=\"c++_static\"'
206+
outString = outString + ' -DCM_ANDROID_FP=\"softfp\"'
207+
outString = outString + ' -DANDROID_NDK=' + \
208+
os.environ['ANDROID_NDK_HOME']
209+
outString = outString + ' -DCMAKE_MAKE_PROGRAM=\"' + \
210+
os.environ['ANDROID_NDK_HOME'] + '\\prebuilt\\windows-x86_64\\bin\\make.exe\"'
211+
return outString
184212
elif self.targetPlatform == 'linux':
185213
outString = outString + ' -DTARGET_BUILD_PLATFORM=linux'
186214
outString = outString + ' -DPX_OUTPUT_ARCH=x86'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<preset name="android-arm64-v8a" comment="Android-29, arm64-v8a PhysX SDK ">
3+
<platform targetPlatform="android" compiler="clang" />
4+
<CMakeSwitches>
5+
<cmakeSwitch name="PX_GENERATE_STATIC_LIBRARIES" value="True" comment="Generate static libs" />
6+
</CMakeSwitches>
7+
<CMakeParams>
8+
<cmakeParam name="CMAKE_INSTALL_PREFIX" value="install/android-29/PhysX" comment="Install path relative to PhysX SDK root" />
9+
<cmakeParam name="ANDROID_NATIVE_API_LEVEL" value="android-29" comment="Android platform API level" />
10+
<cmakeParam name="ANDROID_ABI" value="arm64-v8a" comment="Android arm 64 ABI" />
11+
</CMakeParams>
12+
</preset>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# NVIDIA PhysX SDK for Android
2+
3+
## Location of Binaries:
4+
5+
* SDK libraries: bin/android.arm64-v8a
6+
7+
8+
## Required packages to generate projects:
9+
10+
* CMake, minimum version 3.14
11+
* Python, minimum version 3.5
12+
* Android SDK, minimum version 29
13+
* Android NDK, minimum version 22
14+
15+
16+
## Generating Makefiles:
17+
18+
* Set the environment variable ANDROID_NDK_HOME to the path to Android NDK.
19+
* Makefiles are generated through a script in physx root directory: generate_projects.bat
20+
* Script generate_projects.bat expects a preset name as a parameter, if a parameter is not provided it does list the available presets and you can select one.
21+
* Supported preset for android platform is: android-arm64-v8a.
22+
* Generated solutions are in folder compiler/android-arm64-v8a-debug, compiler/android-arm64-v8a-checked, compiler/android-arm64-v8a-profile, compiler/android-arm64-v8a-release.
23+
24+
25+
## Building SDK:
26+
27+
* Makefiles are in compiler/android-arm64-v8a-debug, etc.
28+
* Build solution: cmake --build .
29+
30+
## Limitations:
31+
32+
* PhysX Snippets are not supported.
33+
* PhysX Systems that require a CUDA capable GPU are not supported, for example particle system or cloth simulation.
34+
* Omniverse Visual Debugger (OmniPVD) is not supported.

physx/include/foundation/PxAlloca.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class PxScopedPointer : private Alloc
6262
#if PX_WINDOWS_FAMILY
6363
#include <malloc.h>
6464
#define PxAlloca(x) _alloca(x)
65-
#elif PX_LINUX
65+
#elif PX_LINUX || PX_ANDROID
6666
#include <malloc.h>
6767
#define PxAlloca(x) alloca(x)
6868
#elif PX_APPLE_FAMILY

physx/include/foundation/PxIntrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#if PX_WINDOWS_FAMILY
3535
#include "windows/PxWindowsIntrinsics.h"
36-
#elif(PX_LINUX || PX_APPLE_FAMILY)
36+
#elif(PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY)
3737
#include "unix/PxUnixIntrinsics.h"
3838
#elif PX_SWITCH
3939
#include "switch/PxSwitchIntrinsics.h"

physx/include/foundation/PxMathIntrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#if PX_WINDOWS_FAMILY
3535
#include "foundation/windows/PxWindowsMathIntrinsics.h"
36-
#elif(PX_LINUX || PX_APPLE_FAMILY)
36+
#elif(PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY)
3737
#include "foundation/unix/PxUnixMathIntrinsics.h"
3838
#elif PX_SWITCH
3939
#include "foundation/switch/PxSwitchMathIntrinsics.h"

physx/include/foundation/PxPreprocessor.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSyst
9595
#define PX_WIN64 1
9696
#elif defined(_WIN32) // note: _M_PPC implies _WIN32
9797
#define PX_WIN32 1
98-
#elif defined(__linux__) || defined (__EMSCRIPTEN__)
98+
#elif defined(__ANDROID__)
99+
#define PX_ANDROID 1
100+
#elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
99101
#define PX_LINUX 1
100102
#elif defined(__APPLE__)
101103
#define PX_OSX 1
@@ -155,6 +157,9 @@ define anything not defined on this platform to 0
155157
#ifndef PX_WIN32
156158
#define PX_WIN32 0
157159
#endif
160+
#ifndef PX_ANDROID
161+
#define PX_ANDROID 0
162+
#endif
158163
#ifndef PX_LINUX
159164
#define PX_LINUX 0
160165
#endif
@@ -218,7 +223,7 @@ family shortcuts
218223
#define PX_GCC_FAMILY (PX_CLANG || PX_GCC)
219224
// os
220225
#define PX_WINDOWS_FAMILY (PX_WIN32 || PX_WIN64)
221-
#define PX_LINUX_FAMILY PX_LINUX
226+
#define PX_LINUX_FAMILY (PX_LINUX || PX_ANDROID)
222227
#define PX_APPLE_FAMILY PX_OSX // equivalent to #if __APPLE__
223228
#define PX_UNIX_FAMILY (PX_LINUX_FAMILY || PX_APPLE_FAMILY) // shortcut for unix/posix platforms
224229
#if defined(__EMSCRIPTEN__)
@@ -461,7 +466,7 @@ PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const&)
461466
char _;
462467
long a;
463468
};
464-
#elif PX_CLANG && PX_ARM
469+
#elif PX_ANDROID || (PX_CLANG && PX_ARM)
465470
struct PxPackValidation
466471
{
467472
char _;
@@ -512,7 +517,7 @@ protected: \
512517
#endif
513518

514519
#ifndef PX_SUPPORT_EXTERN_TEMPLATE
515-
#define PX_SUPPORT_EXTERN_TEMPLATE (PX_VC != 11)
520+
#define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
516521
#else
517522
#define PX_SUPPORT_EXTERN_TEMPLATE 0
518523
#endif

physx/include/foundation/PxThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#if PX_WINDOWS_FAMILY
3838
#define PxSpinLockPause() __asm pause
39-
#elif PX_LINUX || PX_APPLE_FAMILY || PX_SWITCH
39+
#elif PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY || PX_SWITCH
4040
#define PxSpinLockPause() asm("nop")
4141
#else
4242
#error "Platform not supported!"

physx/include/foundation/PxTime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "foundation/PxSimpleTypes.h"
3333
#include "foundation/PxFoundationConfig.h"
3434

35-
#if PX_LINUX
35+
#if PX_LINUX || PX_ANDROID
3636
#include <time.h>
3737
#endif
3838

@@ -83,7 +83,7 @@ class PX_FOUNDATION_API PxTime
8383
Second getLastTime() const;
8484

8585
private:
86-
#if PX_LINUX || PX_APPLE_FAMILY
86+
#if PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY
8787
Second mLastTime;
8888
#else
8989
PxI64 mTickCount;

0 commit comments

Comments
 (0)