Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android platform support #40

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions physx/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
bin/
compiler/linux-*
compiler/vc*
compiler/android*
include/PxConfig.h
install/
30 changes: 29 additions & 1 deletion physx/buildtools/cmake_generate_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cmakeExt():


def filterPreset(presetName):
winPresetFilter = ['win','switch','crosscompile']
winPresetFilter = ['win','switch','crosscompile','android']
if sys.platform == 'win32':
if any(presetName.find(elem) != -1 for elem in winPresetFilter):
return True
Expand Down Expand Up @@ -101,6 +101,14 @@ def __init__(self, presetName):
cmParam = '-D' + cmakeParam.attrib['name'] + '=\"' + \
os.environ['PHYSX_ROOT_DIR'] + '/' + \
cmakeParam.attrib['value'] + '\"'
elif cmakeParam.attrib['name'] == 'ANDROID_ABI':
cmParam = '-D' + \
cmakeParam.attrib['name'] + '=\"' + \
cmakeParam.attrib['value'] + '\"'
if cmakeParam.attrib['value'].startswith('arm'):
cmParam = cmParam + ' -DPX_OUTPUT_ARCH=arm'
elif cmakeParam.attrib['value'].startswith('x86'):
cmParam = cmParam + ' -DPX_OUTPUT_ARCH=x86'
else:
cmParam = '-D' + \
cmakeParam.attrib['name'] + '=' + \
Expand All @@ -113,6 +121,8 @@ def isMultiConfigPlatform(self):
return False
elif self.targetPlatform == 'linuxAarch64':
return False
elif self.targetPlatform == 'android':
return False
return True

def getCMakeSwitches(self):
Expand Down Expand Up @@ -152,6 +162,8 @@ def getPlatformCMakeParams(self):
outString = outString + '-G \"Visual Studio 16 2019\"'
elif self.compiler == 'xcode':
outString = outString + '-G Xcode'
elif self.targetPlatform == 'android':
outString = outString + '-G \"MinGW Makefiles\"'
elif self.targetPlatform == 'linux':
outString = outString + '-G \"Unix Makefiles\"'
elif self.targetPlatform == 'linuxAarch64':
Expand Down Expand Up @@ -181,6 +193,22 @@ def getPlatformCMakeParams(self):
'/switch/NX64Toolchain.txt'
outString = outString + ' -DCMAKE_GENERATOR_PLATFORM=NX64'
return outString
elif self.targetPlatform == 'android':
outString = outString + ' -DTARGET_BUILD_PLATFORM=android'
if os.environ.get('ANDROID_NDK_HOME') is None:
print('Please provide path to android NDK in environment variable ANDROID_NDK_HOME.')
exit(-1)
else:
outString = outString + ' -DCMAKE_TOOLCHAIN_FILE=' + \
os.environ['ANDROID_NDK_HOME'] + \
'/build/cmake/android.toolchain.cmake'
outString = outString + ' -DANDROID_STL=\"c++_static\"'
outString = outString + ' -DCM_ANDROID_FP=\"softfp\"'
outString = outString + ' -DANDROID_NDK=' + \
os.environ['ANDROID_NDK_HOME']
outString = outString + ' -DCMAKE_MAKE_PROGRAM=\"' + \
os.environ['ANDROID_NDK_HOME'] + '\\prebuilt\\windows-x86_64\\bin\\make.exe\"'
return outString
elif self.targetPlatform == 'linux':
outString = outString + ' -DTARGET_BUILD_PLATFORM=linux'
outString = outString + ' -DPX_OUTPUT_ARCH=x86'
Expand Down
12 changes: 12 additions & 0 deletions physx/buildtools/presets/public/android-arm64-v8a.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<preset name="android-arm64-v8a" comment="Android-29, arm64-v8a PhysX SDK ">
<platform targetPlatform="android" compiler="clang" />
<CMakeSwitches>
<cmakeSwitch name="PX_GENERATE_STATIC_LIBRARIES" value="True" comment="Generate static libs" />
</CMakeSwitches>
<CMakeParams>
<cmakeParam name="CMAKE_INSTALL_PREFIX" value="install/android-29/PhysX" comment="Install path relative to PhysX SDK root" />
<cmakeParam name="ANDROID_NATIVE_API_LEVEL" value="android-29" comment="Android platform API level" />
<cmakeParam name="ANDROID_ABI" value="arm64-v8a" comment="Android arm 64 ABI" />
</CMakeParams>
</preset>
34 changes: 34 additions & 0 deletions physx/documentation/platformreadme/android/README_ANDROID.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# NVIDIA PhysX SDK for Android

## Location of Binaries:

* SDK libraries: bin/android.arm64-v8a


## Required packages to generate projects:

* CMake, minimum version 3.14
* Python, minimum version 3.5
* Android SDK, minimum version 29
* Android NDK, minimum version 22


## Generating Makefiles:

* Set the environment variable ANDROID_NDK_HOME to the path to Android NDK.
* Makefiles are generated through a script in physx root directory: generate_projects.bat
* 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.
* Supported preset for android platform is: android-arm64-v8a.
* 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.


## Building SDK:

* Makefiles are in compiler/android-arm64-v8a-debug, etc.
* Build solution: cmake --build .

## Limitations:

* PhysX Snippets are not supported.
* PhysX Systems that require a CUDA capable GPU are not supported, for example particle system or cloth simulation.
* Omniverse Visual Debugger (OmniPVD) is not supported.
2 changes: 1 addition & 1 deletion physx/include/foundation/PxAlloca.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PxScopedPointer : private Alloc
#if PX_WINDOWS_FAMILY
#include <malloc.h>
#define PxAlloca(x) _alloca(x)
#elif PX_LINUX
#elif PX_LINUX || PX_ANDROID
#include <malloc.h>
#define PxAlloca(x) alloca(x)
#elif PX_APPLE_FAMILY
Expand Down
2 changes: 1 addition & 1 deletion physx/include/foundation/PxIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#if PX_WINDOWS_FAMILY
#include "windows/PxWindowsIntrinsics.h"
#elif(PX_LINUX || PX_APPLE_FAMILY)
#elif(PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY)
#include "unix/PxUnixIntrinsics.h"
#elif PX_SWITCH
#include "switch/PxSwitchIntrinsics.h"
Expand Down
2 changes: 1 addition & 1 deletion physx/include/foundation/PxMathIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#if PX_WINDOWS_FAMILY
#include "foundation/windows/PxWindowsMathIntrinsics.h"
#elif(PX_LINUX || PX_APPLE_FAMILY)
#elif(PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY)
#include "foundation/unix/PxUnixMathIntrinsics.h"
#elif PX_SWITCH
#include "foundation/switch/PxSwitchMathIntrinsics.h"
Expand Down
13 changes: 9 additions & 4 deletions physx/include/foundation/PxPreprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSyst
#define PX_WIN64 1
#elif defined(_WIN32) // note: _M_PPC implies _WIN32
#define PX_WIN32 1
#elif defined(__linux__) || defined (__EMSCRIPTEN__)
#elif defined(__ANDROID__)
#define PX_ANDROID 1
#elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
#define PX_LINUX 1
#elif defined(__APPLE__)
#define PX_OSX 1
Expand Down Expand Up @@ -155,6 +157,9 @@ define anything not defined on this platform to 0
#ifndef PX_WIN32
#define PX_WIN32 0
#endif
#ifndef PX_ANDROID
#define PX_ANDROID 0
#endif
#ifndef PX_LINUX
#define PX_LINUX 0
#endif
Expand Down Expand Up @@ -218,7 +223,7 @@ family shortcuts
#define PX_GCC_FAMILY (PX_CLANG || PX_GCC)
// os
#define PX_WINDOWS_FAMILY (PX_WIN32 || PX_WIN64)
#define PX_LINUX_FAMILY PX_LINUX
#define PX_LINUX_FAMILY (PX_LINUX || PX_ANDROID)
#define PX_APPLE_FAMILY PX_OSX // equivalent to #if __APPLE__
#define PX_UNIX_FAMILY (PX_LINUX_FAMILY || PX_APPLE_FAMILY) // shortcut for unix/posix platforms
#if defined(__EMSCRIPTEN__)
Expand Down Expand Up @@ -461,7 +466,7 @@ PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const&)
char _;
long a;
};
#elif PX_CLANG && PX_ARM
#elif PX_ANDROID || (PX_CLANG && PX_ARM)
struct PxPackValidation
{
char _;
Expand Down Expand Up @@ -512,7 +517,7 @@ protected: \
#endif

#ifndef PX_SUPPORT_EXTERN_TEMPLATE
#define PX_SUPPORT_EXTERN_TEMPLATE (PX_VC != 11)
#define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
#else
#define PX_SUPPORT_EXTERN_TEMPLATE 0
#endif
Expand Down
2 changes: 1 addition & 1 deletion physx/include/foundation/PxThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#if PX_WINDOWS_FAMILY
#define PxSpinLockPause() __asm pause
#elif PX_LINUX || PX_APPLE_FAMILY || PX_SWITCH
#elif PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY || PX_SWITCH
#define PxSpinLockPause() asm("nop")
#else
#error "Platform not supported!"
Expand Down
4 changes: 2 additions & 2 deletions physx/include/foundation/PxTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "foundation/PxSimpleTypes.h"
#include "foundation/PxFoundationConfig.h"

#if PX_LINUX
#if PX_LINUX || PX_ANDROID
#include <time.h>
#endif

Expand Down Expand Up @@ -83,7 +83,7 @@ class PX_FOUNDATION_API PxTime
Second getLastTime() const;

private:
#if PX_LINUX || PX_APPLE_FAMILY
#if PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY
Second mLastTime;
#else
PxI64 mTickCount;
Expand Down
2 changes: 2 additions & 0 deletions physx/include/foundation/PxUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ __attribute__((noreturn))
{
#if PX_WINDOWS
__debugbreak();
#elif PX_ANDROID
raise(SIGTRAP); // works better than __builtin_trap. Proper call stack and can be continued.
#elif PX_LINUX
__builtin_trap();
#elif PX_GCC_FAMILY
Expand Down
2 changes: 2 additions & 0 deletions physx/include/foundation/PxVecMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#if !defined(PX_SIMD_DISABLED)
#if PX_INTEL_FAMILY && (!defined(__EMSCRIPTEN__) || defined(__SSE2__))
#define COMPILE_VECTOR_INTRINSICS 1
#elif PX_ANDROID && PX_NEON
#define COMPILE_VECTOR_INTRINSICS 1
#elif PX_SWITCH
#define COMPILE_VECTOR_INTRINSICS 1
#else
Expand Down
21 changes: 20 additions & 1 deletion physx/include/foundation/unix/PxUnixIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
#include "foundation/PxAssert.h"
#include <math.h>

#if PX_ANDROID
#include <signal.h> // for PxDebugBreak() { raise(SIGTRAP); }
#endif

// this file is for internal intrinsics - that is, intrinsics that are used in
// cross platform code but do not appear in the API

#if !(PX_LINUX || PX_APPLE_FAMILY)
#if !(PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY)
#error "This file should only be included by unix builds!!"
#endif

Expand Down Expand Up @@ -88,6 +92,20 @@ PX_FORCE_INLINE void PxPrefetchLine(const void* ptr, uint32_t offset = 0)
/*!
Prefetch \c count bytes starting at \c ptr.
*/
#if PX_ANDROID
PX_FORCE_INLINE void PxPrefetch(const void* ptr, uint32_t count = 1)
{
const char* cp = static_cast<const char*>(ptr);
size_t p = reinterpret_cast<size_t>(ptr);
uint32_t startLine = uint32_t(p >> 5), endLine = uint32_t((p + count - 1) >> 5);
uint32_t lines = endLine - startLine + 1;
do
{
PxPrefetchLine(cp);
cp += 32;
} while(--lines);
}
#else
PX_FORCE_INLINE void PxPrefetch(const void* ptr, uint32_t count = 1)
{
const char* cp = reinterpret_cast<const char*>(ptr);
Expand All @@ -100,6 +118,7 @@ PX_FORCE_INLINE void PxPrefetch(const void* ptr, uint32_t count = 1)
cp += 64;
} while(--lines);
}
#endif

#if !PX_DOXYGEN
} // namespace physx
Expand Down
2 changes: 1 addition & 1 deletion physx/include/foundation/unix/PxUnixMathIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "foundation/Px.h"
#include "foundation/PxAssert.h"

#if !(PX_LINUX || PX_APPLE_FAMILY)
#if !(PX_LINUX || PX_ANDROID || PX_APPLE_FAMILY)
#error "This file should only be included by Unix builds!!"
#endif

Expand Down
8 changes: 6 additions & 2 deletions physx/include/foundation/unix/neon/PxUnixNeonInlineAoS.h
Original file line number Diff line number Diff line change
Expand Up @@ -3530,9 +3530,13 @@ template <> PX_FORCE_INLINE VecU32V V4U32SplatElement<3>(VecU32V a) { return vdu
template <int index>
PX_FORCE_INLINE Vec4V V4SplatElement(Vec4V a)
{
if(index < 2)
if(index == 0)
{
return vdupq_lane_f32(vget_low_f32(a), 0);
}
else if (index == 1)
{
return vdupq_lane_f32(vget_low_f32(a), index);
return vdupq_lane_f32(vget_low_f32(a), 1);
}
else if(index == 2)
{
Expand Down
2 changes: 1 addition & 1 deletion physx/snippets/compiler/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ IF(NOT PUBLIC_RELEASE AND NOT PX_GENERATE_SOURCE_DISTRO)
ENDIF()

#TODO, create a propper define for whether GPU features are enabled or not!
IF ((PUBLIC_RELEASE OR PX_GENERATE_GPU_PROJECTS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
IF ((PUBLIC_RELEASE OR PX_GENERATE_GPU_PROJECTS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8) AND (TARGET_BUILD_PLATFORM STREQUAL "windows" OR TARGET_BUILD_PLATFORM STREQUAL "linux"))
LIST(APPEND SNIPPETS_LIST ${GPU_SNIPPET_LIST})
ENDIF()

Expand Down
4 changes: 2 additions & 2 deletions physx/source/compiler/cmake/PhysXExtensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SET(PHYSX_EXTENSIONS_SOURCE
)

#TODO, create a propper define for whether GPU features are enabled or not!
IF ((PUBLIC_RELEASE OR PX_GENERATE_GPU_PROJECTS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
IF ((PUBLIC_RELEASE OR PX_GENERATE_GPU_PROJECTS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8) AND (TARGET_BUILD_PLATFORM STREQUAL "windows" OR TARGET_BUILD_PLATFORM STREQUAL "linux"))
LIST(APPEND PHYSX_EXTENSIONS_SOURCE "${LL_SOURCE_DIR}/ExtParticleExt.cpp")
LIST(APPEND PHYSX_EXTENSIONS_SOURCE "${LL_SOURCE_DIR}/ExtParticleClothCooker.cpp")
ENDIF()
Expand Down Expand Up @@ -199,7 +199,7 @@ SET(PHYSX_EXTENSIONS_HEADERS
)

#TODO, create a propper define for whether GPU features are enabled or not!
IF ((PUBLIC_RELEASE OR PX_GENERATE_GPU_PROJECTS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
IF ((PUBLIC_RELEASE OR PX_GENERATE_GPU_PROJECTS) AND (CMAKE_SIZEOF_VOID_P EQUAL 8) AND (TARGET_BUILD_PLATFORM STREQUAL "windows" OR TARGET_BUILD_PLATFORM STREQUAL "linux"))
LIST(APPEND PHYSX_EXTENSIONS_HEADERS "${PHYSX_ROOT_DIR}/include/extensions/PxParticleClothCooker.h")
LIST(APPEND PHYSX_EXTENSIONS_HEADERS "${PHYSX_ROOT_DIR}/include/extensions/PxParticleExt.h")
ENDIF()
Expand Down
Loading