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

Add loongarch platform support #322

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion physx/buildtools/cmake_generate_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def isMultiConfigPlatform(self):
return False
elif self.targetPlatform == 'linuxAarch64':
return False
elif self.targetPlatform == 'linuxLoongarch64':
return False
return True

def getCMakeSwitches(self):
Expand Down Expand Up @@ -215,13 +217,25 @@ def getPlatformCMakeParams(self):
outString = outString + ' -DCMAKE_TOOLCHAIN_FILE=\"' + \
cmake_modules_root + '/linux/LinuxAarch64.cmake\"'
return outString
elif self.targetPlatform == 'linuxLoongarch64':
outString = outString + ' -DTARGET_BUILD_PLATFORM=linux'
outString = outString + ' -DPX_OUTPUT_ARCH=loongarch64'
if self.compiler == 'clang':
if os.environ.get('PM_clang_PATH') is not None:
outString = outString + ' -DCMAKE_C_COMPILER=' + \
os.environ['PM_clang_PATH'] + '/bin/clang'
outString = outString + ' -DCMAKE_CXX_COMPILER=' + \
os.environ['PM_clang_PATH'] + '/bin/clang++'
else:
outString = outString + ' -DCMAKE_C_COMPILER=clang'
outString = outString + ' -DCMAKE_CXX_COMPILER=clang++'
return outString
elif self.targetPlatform == 'mac64':
outString = outString + ' -DTARGET_BUILD_PLATFORM=mac'
outString = outString + ' -DPX_OUTPUT_ARCH=x86'
return outString
return ''


def getCommonParams():
outString = '--no-warn-unused-cli'
outString = outString + ' -DCMAKE_PREFIX_PATH=\"' + os.environ['PM_PATHS'] + '\"'
Expand Down
11 changes: 11 additions & 0 deletions physx/buildtools/presets/public/linux-loongarch64.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<preset name="linux-loongarch64" comment="Linux-loongarch64 clang PhysX SDK general settings">
<platform targetPlatform="linuxLoongarch64" compiler="clang" />
<CMakeSwitches>
<cmakeSwitch name="PX_BUILDSNIPPETS" value="True" comment="Generate the snippets" />
<cmakeSwitch name="PX_GENERATE_STATIC_LIBRARIES" value="True" comment="Generate static libs" />
</CMakeSwitches>
<CMakeParams>
<cmakeParam name="CMAKE_INSTALL_PREFIX" value="install/linux-loongarch64/PhysX" comment="Install path relative to PhysX SDK root" />
</CMakeParams>
</preset>
7 changes: 6 additions & 1 deletion physx/generate_projects.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash +x

machine=`uname -m`
if [ "$machine"x = "loongarch64"x ]; then
export PM_PYTHON_EXT="python3"
fi

if [ -n "${BASH_SOURCE[0]}" ]; then
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
else
Expand Down Expand Up @@ -33,4 +38,4 @@ status=$?
if [ "$status" -ne "0" ]; then
echo "Error $status"
exit 1
fi
fi
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_LOONGARCH64
#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_APPLE_FAMILY || PX_LOONGARCH64)
#include "unix/PxUnixIntrinsics.h"
#elif PX_SWITCH
#include "switch/PxSwitchIntrinsics.h"
Expand Down
2 changes: 1 addition & 1 deletion physx/include/foundation/PxMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#pragma warning(pop)
#endif

#if (PX_LINUX_FAMILY && !PX_ARM_FAMILY)
#if (PX_LINUX_FAMILY && !PX_ARM_FAMILY && !PX_LOONGARCH64)
// Force linking against nothing newer than glibc v2.17 to remain compatible with platforms with older glibc versions
__asm__(".symver expf,expf@GLIBC_2.2.5");
__asm__(".symver powf,powf@GLIBC_2.2.5");
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_APPLE_FAMILY || PX_LOONGARCH64)
#include "foundation/unix/PxUnixMathIntrinsics.h"
#elif PX_SWITCH
#include "foundation/switch/PxSwitchMathIntrinsics.h"
Expand Down
9 changes: 7 additions & 2 deletions physx/include/foundation/PxPreprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Architecture defines, see http://sourceforge.net/p/predef/wiki/Architectures/
#define PX_A64 1
#elif defined(__arm__) || defined(_M_ARM)
#define PX_ARM 1
#elif defined(__loongarch64__) || defined(__loongarch64)
#define PX_LOONGARCH64 1
#elif defined(__ppc__) || defined(_M_PPC) || defined(__CELLOS_LV2__)
#define PX_PPC 1
#else
Expand Down Expand Up @@ -171,6 +173,9 @@ define anything not defined on this platform to 0
#ifndef PX_ARM
#define PX_ARM 0
#endif
#ifndef PX_LOONGARCH64
#define PX_LOONGARCH64 0
#endif
#ifndef PX_PPC
#define PX_PPC 0
#endif
Expand Down Expand Up @@ -224,7 +229,7 @@ family shortcuts
// architecture
#define PX_INTEL_FAMILY (PX_X64 || PX_X86)
#define PX_ARM_FAMILY (PX_ARM || PX_A64)
#define PX_P64_FAMILY (PX_X64 || PX_A64) // shortcut for 64-bit architectures
#define PX_P64_FAMILY (PX_X64 || PX_A64 || PX_LOONGARCH64) // shortcut for 64-bit architectures

/**
C++ standard library defines
Expand Down Expand Up @@ -522,7 +527,7 @@ protected: \
//#define DISABLE_CUDA_PHYSX
#ifndef DISABLE_CUDA_PHYSX
//CUDA is currently supported on x86_64 windows and linux, and ARM_64 linux
#define PX_SUPPORT_GPU_PHYSX ((PX_X64 && (PX_WINDOWS_FAMILY || PX_LINUX)) || (PX_A64 && PX_LINUX))
#define PX_SUPPORT_GPU_PHYSX ((PX_X64 && (PX_WINDOWS_FAMILY || PX_LINUX)) || (PX_A64 && PX_LINUX) || PX_LOONGARCH64)
#else
#define PX_SUPPORT_GPU_PHYSX 0
#endif
Expand Down
2 changes: 1 addition & 1 deletion physx/include/foundation/PxSIMDHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace physx
const QuatV qV = V4LoadU(&q.x);
Vec3V column0V, column1V, column2V;
QuatGetMat33V(qV, column0V, column1V, column2V);
#if defined(PX_SIMD_DISABLED) || (PX_LINUX && (PX_ARM || PX_A64))
#if defined(PX_SIMD_DISABLED) || (PX_LINUX && (PX_ARM || PX_A64 || PX_LOONGARCH64))
V3StoreU(column0V, column0);
V3StoreU(column1V, column1);
V3StoreU(column2V, column2);
Expand Down
4 changes: 2 additions & 2 deletions physx/snippets/compiler/cmake/linux/SnippetRender.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Build SnippetRender
#

IF(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
IF(NOT (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "loongarch64"))
FIND_PACKAGE(OpenGL $ENV{PM_OpenGL_VERSION} CONFIG REQUIRED) # Pull in OpenGL and GLUT
ENDIF()

Expand All @@ -46,7 +46,7 @@ SET(SNIPPETRENDER_COMPILE_DEFS
SET(SNIPPETRENDER_PLATFORM_INCLUDES)

# gwoolery: aarch64 requires glut library to be lower case, for whatever reason
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64")
SET(GLUT_LIB "glut")
ELSE()
SET(GLUT_LIB "GLUT")
Expand Down
2 changes: 1 addition & 1 deletion physx/snippets/compiler/cmake/linux/SnippetTemplate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ IF(${SNIPPET_NAME} STREQUAL "ArticulationLoader")
ENDIF()

# gwoolery: aarch64 requires glut library to be lower case, for whatever reason
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64")
SET(GLUT_LIB "glut")
ELSE()
SET(GLUT_LIB "GLUT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ SET(SNIPPET_PLATFORM_SOURCES
)

# gwoolery: aarch64 requires glut library to be lower case, for whatever reason
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64")
SET(GLUT_LIB "glut")
ELSE()
SET(GLUT_LIB "GLUT")
Expand Down
5 changes: 5 additions & 0 deletions physx/source/compiler/cmake/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ IF(${CMAKE_CROSSCOMPILING} AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
ELSE()
SET(PX_SUPPORT_OMNI_PVD_FLAG "PX_SUPPORT_OMNI_PVD=1")
ENDIF()

IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64")
SET(GPU_LIB_COPIED 1 CACHE INTERNAL "PhysX GPU so files not copied")
ENDIF()

SET(PHYSX_LINUX_COMPILE_DEFS "${PHYSX_AUTOBUILD};${PUBLIC_RELEASE_FLAG};${FEATURES_UNDER_CONSTRUCTION_FLAG}" CACHE INTERNAL "Base PhysX preprocessor definitions")
SET(PHYSX_LINUX_DEBUG_COMPILE_DEFS "PX_DEBUG=1;PX_CHECKED=1;${NVTX_FLAG};PX_SUPPORT_PVD=1;${PX_SUPPORT_OMNI_PVD_FLAG}" CACHE INTERNAL "Debug PhysX preprocessor definitions")
SET(PHYSX_LINUX_CHECKED_COMPILE_DEFS "NDEBUG;PX_CHECKED=1;${NVTX_FLAG};PX_SUPPORT_PVD=1;${PX_SUPPORT_OMNI_PVD_FLAG}" CACHE INTERNAL "Checked PhysX preprocessor definitions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ FUNCTION (GetPlatformBinName PLATFORM_BIN_NAME LIBPATH_SUFFIX)
SET(RETVAL "linux.clang")
ELSEIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
SET(RETVAL "linux.aarch64")
ELSEIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "loongarch64")
SET(RETVAL "linux.loongarch64")
ENDIF()
ENDIF()

Expand Down
1 change: 1 addition & 0 deletions physx/source/foundation/unix/FdUnixThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ void PxThreadImpl::yieldProcessor()
{
#if (PX_ARM || PX_A64)
__asm__ __volatile__("yield");
#elif PX_LOONGARCH64
#else
__asm__ __volatile__("pause");
#endif
Expand Down
10 changes: 7 additions & 3 deletions physx/source/physxextensions/src/serialization/SnSerialUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace physx;
namespace
{

#define SN_NUM_BINARY_PLATFORMS 9
#define SN_NUM_BINARY_PLATFORMS 10
const PxU32 sBinaryPlatformTags[SN_NUM_BINARY_PLATFORMS] =
{
PX_MAKE_FOURCC('W','_','3','2'),
Expand All @@ -49,7 +49,8 @@ const PxU32 sBinaryPlatformTags[SN_NUM_BINARY_PLATFORMS] =
PX_MAKE_FOURCC('M','_','6','4'),
PX_MAKE_FOURCC('N','X','3','2'),
PX_MAKE_FOURCC('N','X','6','4'),
PX_MAKE_FOURCC('L','A','6','4')
PX_MAKE_FOURCC('L','A','6','4'),
PX_MAKE_FOURCC('L','O','6','4')
};

const char* sBinaryPlatformNames[SN_NUM_BINARY_PLATFORMS] =
Expand All @@ -62,7 +63,8 @@ const char* sBinaryPlatformNames[SN_NUM_BINARY_PLATFORMS] =
"mac64",
"switch32",
"switch64",
"linuxaarch64"
"linuxaarch64",
"loongarch64"
};

}
Expand All @@ -89,6 +91,8 @@ PxU32 getBinaryPlatformTag()
return sBinaryPlatformTags[7];
#elif PX_LINUX && PX_A64
return sBinaryPlatformTags[8];
#elif PX_LINUX && PX_LOONGARCH64
return sBinaryPlatformTags[9];
#else
#error Unknown binary platform
#endif
Expand Down