aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/PhysX/src/gpu
diff options
context:
space:
mode:
authorgit perforce import user <a@b>2016-10-25 12:29:14 -0600
committerSheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees>2016-10-25 18:56:37 -0500
commit3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch)
treefa6485c169e50d7415a651bf838f5bcd0fd3bfbd /PhysX_3.4/Source/PhysX/src/gpu
downloadphysx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz
physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip
Initial commit:
PhysX 3.4.0 Update @ 21294896 APEX 1.4.0 Update @ 21275617 [CL 21300167]
Diffstat (limited to 'PhysX_3.4/Source/PhysX/src/gpu')
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.cpp291
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.h101
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/PxGpu.cpp68
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/PxParticleDeviceExclusive.cpp130
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/PxParticleGpu.cpp89
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/PxPhysXGpuModuleLoader.cpp141
-rw-r--r--PhysX_3.4/Source/PhysX/src/gpu/PxPhysXIndicatorDeviceExclusive.cpp50
7 files changed, 870 insertions, 0 deletions
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.cpp b/PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.cpp
new file mode 100644
index 00000000..2ed19c55
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.cpp
@@ -0,0 +1,291 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+
+#include "NpPhysicsGpu.h"
+
+#if PX_SUPPORT_GPU_PHYSX
+
+#include "NpPhysics.h"
+#include "PxvGlobals.h"
+#include "PxPhysXGpu.h"
+#include "PxParticleGpu.h"
+#include "NpScene.h"
+
+using namespace physx;
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+Ps::Array<NpPhysicsGpu::MeshMirror>::Iterator NpPhysicsGpu::findMeshMirror(const void* meshAddress)
+{
+ Ps::Array<MeshMirror>::Iterator i = mMeshMirrors.begin();
+ while (i != mMeshMirrors.end() && i->meshAddress != meshAddress)
+ i++;
+
+ return i;
+}
+
+Ps::Array<NpPhysicsGpu::MeshMirror>::Iterator NpPhysicsGpu::findMeshMirror(const void* meshAddress, PxCudaContextManager& ctx)
+{
+ Ps::Array<MeshMirror>::Iterator i = mMeshMirrors.begin();
+ while (i != mMeshMirrors.end() && (i->meshAddress != meshAddress || i->ctx != &ctx))
+ i++;
+
+ return i;
+}
+
+PxPhysXGpu* NpPhysicsGpu::getPhysXGpu(bool createIfNeeded, const char* functionName, bool doWarn)
+{
+ PxPhysXGpu* physXGpu = PxvGetPhysXGpu(createIfNeeded);
+
+ if (!physXGpu && doWarn)
+ Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "%s, GPU implementation not available.", functionName);
+
+ return physXGpu;
+}
+
+bool NpPhysicsGpu::checkNewMirror(const void* meshPtr, PxCudaContextManager& ctx, const char* functionName)
+{
+ Ps::Array<MeshMirror>::Iterator it = findMeshMirror(meshPtr, ctx);
+ if (it == mMeshMirrors.end())
+ return true;
+
+ Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "%s has no effect. Mirror already exists.", functionName);
+ return false;
+}
+
+bool NpPhysicsGpu::checkMirrorExists(Ps::Array<MeshMirror>::Iterator it, const char* functionName)
+{
+ if (it != mMeshMirrors.end())
+ return true;
+
+ Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "%s has no effect. Mirror doesn't exist.", functionName);
+ return false;
+}
+
+bool NpPhysicsGpu::checkMirrorHandle(PxU32 mirrorHandle, const char* functionName)
+{
+ if (mirrorHandle != PX_INVALID_U32)
+ return true;
+
+ Ps::getFoundation().error(PxErrorCode::eOUT_OF_MEMORY, __FILE__, __LINE__, "%s failed.", functionName);
+ return false;
+}
+
+void NpPhysicsGpu::addMeshMirror(const void* meshPtr, PxU32 mirrorHandle, PxCudaContextManager& ctx)
+{
+ MeshMirror& meshMirror = mMeshMirrors.insert();
+ meshMirror.meshAddress = meshPtr;
+ meshMirror.ctx = &ctx;
+ meshMirror.mirrorHandle = mirrorHandle;
+}
+
+void NpPhysicsGpu::releaseMeshMirror(const void* meshPtr, const char* functionName, PxCudaContextManager* ctx)
+{
+ PxPhysXGpu* physXGpu = getPhysXGpu(false, functionName, ctx != NULL);
+ if (!physXGpu)
+ return;
+
+ if (ctx)
+ {
+ Ps::Array<MeshMirror>::Iterator mirrorIt = findMeshMirror(meshPtr, *ctx);
+ if (!checkMirrorExists(mirrorIt, functionName))
+ return;
+
+ physXGpu->releaseMirror(mirrorIt->mirrorHandle);
+ mMeshMirrors.replaceWithLast(mirrorIt);
+ }
+ else
+ {
+ //remove all mesh mirrors for all contexts.
+ Ps::Array<MeshMirror>::Iterator mirrorIt;
+ while ((mirrorIt = findMeshMirror(meshPtr)) != mMeshMirrors.end())
+ {
+ physXGpu->releaseMirror(mirrorIt->mirrorHandle);
+ mMeshMirrors.replaceWithLast(mirrorIt);
+ }
+ }
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+
+bool NpPhysicsGpu::createTriangleMeshMirror(const PxTriangleMesh& triangleMesh, PxCudaContextManager& contextManager)
+{
+ const char* functionName = "PxParticleGpu::createTriangleMeshMirror()";
+ PxPhysXGpu* physXGpu = getPhysXGpu(true, functionName);
+ if (!physXGpu)
+ return false;
+
+ const void* meshPtr = (const void*)&triangleMesh;
+ if (!checkNewMirror(meshPtr, contextManager, functionName))
+ return true;
+
+ PxU32 mirrorHandle = physXGpu->createTriangleMeshMirror(triangleMesh, contextManager);
+ if (!checkMirrorHandle(mirrorHandle, functionName))
+ return false;
+
+ addMeshMirror(meshPtr, mirrorHandle, contextManager);
+ return true;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void NpPhysicsGpu::releaseTriangleMeshMirror(const PxTriangleMesh& triangleMesh, PxCudaContextManager* contextManager)
+{
+ releaseMeshMirror((const void*)&triangleMesh, "PxParticleGpu::releaseTriangleMeshMirror()", contextManager);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+bool NpPhysicsGpu::createHeightFieldMirror(const PxHeightField& heightField, PxCudaContextManager& contextManager)
+{
+ const char* functionName = "PxParticleGpu::createHeightFieldMirror()";
+ PxPhysXGpu* physXGpu = getPhysXGpu(true, functionName);
+ if (!physXGpu)
+ return false;
+
+ const void* meshPtr = (const void*)&heightField;
+ if (!checkNewMirror(meshPtr, contextManager, functionName))
+ return true;
+
+ PxU32 mirrorHandle = physXGpu->createHeightFieldMirror(heightField, contextManager);
+ if (!checkMirrorHandle(mirrorHandle, functionName))
+ return false;
+
+ addMeshMirror(meshPtr, mirrorHandle, contextManager);
+ return true;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void NpPhysicsGpu::releaseHeightFieldMirror(const PxHeightField& heightField, PxCudaContextManager* contextManager)
+{
+ releaseMeshMirror((const void*)&heightField, "PxParticleGpu::releaseHeightFieldMirror()", contextManager);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+bool NpPhysicsGpu::createConvexMeshMirror(const PxConvexMesh& convexMesh, PxCudaContextManager& contextManager)
+{
+ const char* functionName = "PxParticleGpu::createConvexMeshMirror()";
+ PxPhysXGpu* physXGpu = getPhysXGpu(true, functionName);
+ if (!physXGpu)
+ return false;
+
+ const void* meshPtr = (const void*)&convexMesh;
+ if (!checkNewMirror(meshPtr, contextManager, functionName))
+ return true;
+
+ PxU32 mirrorHandle = physXGpu->createConvexMeshMirror(convexMesh, contextManager);
+ if (!checkMirrorHandle(mirrorHandle, functionName))
+ return false;
+
+ addMeshMirror(meshPtr, mirrorHandle, contextManager);
+ return true;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void NpPhysicsGpu::releaseConvexMeshMirror(const PxConvexMesh& convexMesh, PxCudaContextManager* contextManager)
+{
+ releaseMeshMirror((const void*)&convexMesh, "PxParticleGpu::releaseConvexMeshMirror()", contextManager);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+namespace
+{
+ PxSceneGpu* getSceneGpu(const PxScene& scene)
+ {
+#if PX_SUPPORT_GPU_PHYSX
+ return ((NpScene*)&scene)->mScene.getScScene().getSceneGpu(true);
+#else
+ return NULL;
+#endif
+ }
+}
+
+void NpPhysicsGpu::setExplicitCudaFlushCountHint(const class PxScene& scene, PxU32 cudaFlushCount)
+{
+ const char* functionName = "PxParticleGpu::setExplicitCudaFlushCountHint()";
+ PxPhysXGpu* physXGpu = getPhysXGpu(true, functionName);
+ if (physXGpu)
+ {
+ PxSceneGpu* gpuScene = getSceneGpu(scene);
+ PX_ASSERT(gpuScene);
+ physXGpu->setExplicitCudaFlushCountHint((PxgSceneGpu&)(*gpuScene), cudaFlushCount);
+ }
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+bool NpPhysicsGpu::setTriangleMeshCacheSizeHint(const class PxScene& scene, PxU32 size)
+{
+ const char* functionName = "PxParticleGpu::setTriangleMeshCacheSizeHint()";
+ PxPhysXGpu* physXGpu = getPhysXGpu(true, functionName);
+ if (physXGpu)
+ {
+ PxSceneGpu* gpuScene = getSceneGpu(scene);
+ PX_ASSERT(gpuScene);
+ return physXGpu->setTriangleMeshCacheSizeHint((PxgSceneGpu&)(*gpuScene), size);
+ }
+ return false;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+PxTriangleMeshCacheStatistics NpPhysicsGpu::getTriangleMeshCacheStatistics(const class PxScene& scene)
+{
+ PxTriangleMeshCacheStatistics stats;
+
+ const char* functionName = "PxParticleGpu::getTriangleMeshCacheStatistics()";
+ PxPhysXGpu* physXGpu = getPhysXGpu(true, functionName);
+ if (physXGpu)
+ {
+ PxSceneGpu* gpuScene = getSceneGpu(scene);
+ PX_ASSERT(gpuScene);
+ stats = physXGpu->getTriangleMeshCacheStatistics((PxgSceneGpu&)(*gpuScene));
+ }
+ return stats;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+NpPhysicsGpu::NpPhysicsGpu(NpPhysics& npPhysics) : mMeshMirrors(PX_DEBUG_EXP("NpPhysicsGpu:mMeshMirrors")), mNpPhysics(npPhysics)
+{}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+NpPhysicsGpu::~NpPhysicsGpu()
+{}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+#endif // PX_SUPPORT_GPU_PHYSX
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.h b/PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.h
new file mode 100644
index 00000000..5f3ceb6e
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/NpPhysicsGpu.h
@@ -0,0 +1,101 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+
+#ifndef PX_PHYSICS_NP_PHYSICS_GPU
+#define PX_PHYSICS_NP_PHYSICS_GPU
+
+#include "PxPhysXCommonConfig.h"
+#include "PxPhysXConfig.h"
+
+#if PX_SUPPORT_GPU_PHYSX
+
+#include "CmPhysXCommon.h"
+#include "PsArray.h"
+
+namespace physx
+{
+ class PxCudaContextManager;
+}
+
+namespace physx
+{
+
+ struct PxTriangleMeshCacheStatistics;
+
+ class NpPhysicsGpu
+ {
+ public:
+
+ bool createTriangleMeshMirror(const class PxTriangleMesh& triangleMesh, physx::PxCudaContextManager& contextManager);
+ void releaseTriangleMeshMirror(const class PxTriangleMesh& triangleMesh, physx::PxCudaContextManager* contextManager = NULL);
+
+ bool createHeightFieldMirror(const class PxHeightField& heightField, physx::PxCudaContextManager& contextManager);
+ void releaseHeightFieldMirror(const class PxHeightField& heightField, physx::PxCudaContextManager* contextManager = NULL);
+
+ bool createConvexMeshMirror(const class PxConvexMesh& convexMesh, physx::PxCudaContextManager& contextManager);
+ void releaseConvexMeshMirror(const class PxConvexMesh& convexMesh, physx::PxCudaContextManager* contextManager = NULL);
+
+ void setExplicitCudaFlushCountHint(const class PxScene& scene, PxU32 cudaFlushCount);
+ bool setTriangleMeshCacheSizeHint(const class PxScene& scene, PxU32 size);
+ PxTriangleMeshCacheStatistics getTriangleMeshCacheStatistics(const class PxScene& scene);
+
+ NpPhysicsGpu(class NpPhysics& npPhysics);
+ virtual ~NpPhysicsGpu();
+
+ private:
+
+ NpPhysicsGpu& operator=(const NpPhysicsGpu&);
+
+ struct MeshMirror
+ {
+ PxU32 mirrorHandle;
+ physx::PxCudaContextManager* ctx;
+ const void* meshAddress;
+ };
+
+ Ps::Array<MeshMirror>::Iterator findMeshMirror(const void* meshAddress);
+ Ps::Array<MeshMirror>::Iterator findMeshMirror(const void* meshAddress, physx::PxCudaContextManager& ctx);
+ class PxPhysXGpu* getPhysXGpu(bool createIfNeeded, const char* functionName, bool doWarn = true);
+ bool checkNewMirror(const void* meshPtr, physx::PxCudaContextManager& ctx, const char* functionName);
+ bool checkMirrorExists(Ps::Array<MeshMirror>::Iterator it, const char* functionName);
+ bool checkMirrorHandle(PxU32 mirrorHandle, const char* functionName);
+ void addMeshMirror(const void* meshPtr, PxU32 mirrorHandle, physx::PxCudaContextManager& ctx);
+ void removeMeshMirror(const void* meshPtr, PxU32 mirrorHandle);
+ void releaseMeshMirror(const void* meshPtr, const char* functionName, physx::PxCudaContextManager* ctx);
+
+ Ps::Array<MeshMirror> mMeshMirrors;
+ class NpPhysics& mNpPhysics;
+ };
+
+}
+
+#endif
+#endif
+
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/PxGpu.cpp b/PhysX_3.4/Source/PhysX/src/gpu/PxGpu.cpp
new file mode 100644
index 00000000..7b8611b9
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/PxGpu.cpp
@@ -0,0 +1,68 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+
+#include "PxPhysXConfig.h"
+
+#if PX_SUPPORT_GPU_PHYSX
+
+#include "PxGpu.h"
+
+namespace physx
+{
+ //forward declare stuff from PxPhysXGpuModuleLoader.cpp
+ void PxLoadPhysxGPUModule(const char* appGUID);
+ typedef physx::PxCudaContextManager* (PxCreateCudaContextManager_FUNC)(physx::PxFoundation& foundation, const physx::PxCudaContextManagerDesc& desc);
+ typedef int (PxGetSuggestedCudaDeviceOrdinal_FUNC)(physx::PxErrorCallback& errc);
+ extern PxCreateCudaContextManager_FUNC* g_PxCreateCudaContextManager_Func;
+ extern PxGetSuggestedCudaDeviceOrdinal_FUNC* g_PxGetSuggestedCudaDeviceOrdinal_Func;
+
+} // end physx namespace
+
+physx::PxCudaContextManager* PxCreateCudaContextManager(physx::PxFoundation& foundation, const physx::PxCudaContextManagerDesc& desc)
+{
+ if (!physx::g_PxCreateCudaContextManager_Func)
+ physx::PxLoadPhysxGPUModule(desc.appGUID);
+
+ if (physx::g_PxCreateCudaContextManager_Func)
+ return physx::g_PxCreateCudaContextManager_Func(foundation, desc);
+ else
+ return NULL;
+}
+
+int PxGetSuggestedCudaDeviceOrdinal(physx::PxErrorCallback& errc)
+{
+ if (!physx::g_PxGetSuggestedCudaDeviceOrdinal_Func)
+ physx::PxLoadPhysxGPUModule(NULL);
+
+ if (physx::g_PxGetSuggestedCudaDeviceOrdinal_Func)
+ return physx::g_PxGetSuggestedCudaDeviceOrdinal_Func(errc);
+ else
+ return -1;
+}
+
+#endif // PX_SUPPORT_GPU_PHYSX
+
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/PxParticleDeviceExclusive.cpp b/PhysX_3.4/Source/PhysX/src/gpu/PxParticleDeviceExclusive.cpp
new file mode 100644
index 00000000..69ae7456
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/PxParticleDeviceExclusive.cpp
@@ -0,0 +1,130 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include "PxPhysXConfig.h"
+
+#if PX_USE_PARTICLE_SYSTEM_API
+#if PX_SUPPORT_GPU_PHYSX
+
+#include "PxParticleDeviceExclusive.h"
+#include "NpParticleSystem.h"
+#include "NpParticleFluid.h"
+
+using namespace physx;
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxParticleDeviceExclusive::enable(PxParticleBase& particleBase)
+{
+ if (particleBase.is<PxParticleSystem>())
+ static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->enableDeviceExclusiveModeGpu();
+ else if (particleBase.is<PxParticleFluid>())
+ static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->enableDeviceExclusiveModeGpu();
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+bool PxParticleDeviceExclusive::isEnabled(PxParticleBase& particleBase)
+{
+ if (particleBase.is<PxParticleSystem>())
+ return static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->isDeviceExclusiveModeEnabledGpu();
+ else if (particleBase.is<PxParticleFluid>())
+ return static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->isDeviceExclusiveModeEnabledGpu();
+
+ return false;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxParticleDeviceExclusive::getReadWriteCudaBuffers(PxParticleBase& particleBase, PxCudaReadWriteParticleBuffers& buffers)
+{
+ if (particleBase.is<PxParticleSystem>())
+ static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->getReadWriteCudaBuffersGpu(buffers);
+ else if (particleBase.is<PxParticleFluid>())
+ static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->getReadWriteCudaBuffersGpu(buffers);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxParticleDeviceExclusive::setValidParticleRange(PxParticleBase& particleBase, PxU32 validParticleRange)
+{
+ if (particleBase.is<PxParticleSystem>())
+ static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->setValidParticleRangeGpu(validParticleRange);
+ else if (particleBase.is<PxParticleFluid>())
+ static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->setValidParticleRangeGpu(validParticleRange);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxParticleDeviceExclusive::setFlags(PxParticleBase& particleBase, PxParticleDeviceExclusiveFlags flags)
+{
+ if (particleBase.is<PxParticleSystem>())
+ static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->setDeviceExclusiveModeFlagsGpu(reinterpret_cast<PxU32&>(flags));
+ else if (particleBase.is<PxParticleFluid>())
+ static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->setDeviceExclusiveModeFlagsGpu(reinterpret_cast<PxU32&>(flags));
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+class physx::PxBaseTask* PxParticleDeviceExclusive::getLaunchTask(class PxParticleBase& particleBase)
+{
+ if (particleBase.is<PxParticleSystem>())
+ return static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->getLaunchTaskGpu();
+ else if (particleBase.is<PxParticleFluid>())
+ return static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->getLaunchTaskGpu();
+
+ return NULL;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxParticleDeviceExclusive::addLaunchTaskDependent(class PxParticleBase& particleBase, class physx::PxBaseTask& dependent)
+{
+ if (particleBase.is<PxParticleSystem>())
+ static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->addLaunchTaskDependentGpu(dependent);
+ else if (particleBase.is<PxParticleFluid>())
+ static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->addLaunchTaskDependentGpu(dependent);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+CUstream PxParticleDeviceExclusive::getCudaStream(class PxParticleBase& particleBase)
+{
+ if (particleBase.is<PxParticleSystem>())
+ return (CUstream)static_cast<NpParticleSystem*>(particleBase.is<PxParticleSystem>())->getCudaStreamGpu();
+ else if (particleBase.is<PxParticleFluid>())
+ return (CUstream)static_cast<NpParticleFluid*>(particleBase.is<PxParticleFluid>())->getCudaStreamGpu();
+
+ return NULL;
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+#endif // PX_SUPPORT_GPU_PHYSX
+#endif // PX_USE_PARTICLE_SYSTEM_API
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/PxParticleGpu.cpp b/PhysX_3.4/Source/PhysX/src/gpu/PxParticleGpu.cpp
new file mode 100644
index 00000000..a2793b95
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/PxParticleGpu.cpp
@@ -0,0 +1,89 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+
+#include "PxParticleGpu.h"
+
+#if PX_SUPPORT_GPU_PHYSX
+
+#include "NpPhysics.h"
+#include "NpPhysicsGpu.h"
+
+using namespace physx;
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+bool PxParticleGpu::createTriangleMeshMirror(const class PxTriangleMesh& triangleMesh, PxCudaContextManager& contextManager)
+{
+ return NpPhysics::getInstance().getNpPhysicsGpu().createTriangleMeshMirror(triangleMesh, contextManager);
+}
+
+void PxParticleGpu::releaseTriangleMeshMirror(const class PxTriangleMesh& triangleMesh, PxCudaContextManager* contextManager)
+{
+ NpPhysics::getInstance().getNpPhysicsGpu().releaseTriangleMeshMirror(triangleMesh, contextManager);
+}
+
+bool PxParticleGpu::createHeightFieldMirror(const class PxHeightField& heightField, PxCudaContextManager& contextManager)
+{
+ return NpPhysics::getInstance().getNpPhysicsGpu().createHeightFieldMirror(heightField, contextManager);
+}
+
+void PxParticleGpu::releaseHeightFieldMirror(const class PxHeightField& heightField, PxCudaContextManager* contextManager)
+{
+ NpPhysics::getInstance().getNpPhysicsGpu().releaseHeightFieldMirror(heightField, contextManager);
+}
+
+bool PxParticleGpu::createConvexMeshMirror(const class PxConvexMesh& convexMesh, PxCudaContextManager& contextManager)
+{
+ return NpPhysics::getInstance().getNpPhysicsGpu().createConvexMeshMirror(convexMesh, contextManager);
+}
+
+void PxParticleGpu::releaseConvexMeshMirror(const class PxConvexMesh& convexMesh, PxCudaContextManager* contextManager)
+{
+ NpPhysics::getInstance().getNpPhysicsGpu().releaseConvexMeshMirror(convexMesh, contextManager);
+}
+
+void PxParticleGpu::setExplicitCudaFlushCountHint(const class PxScene& scene, PxU32 cudaFlushCount)
+{
+ NpPhysics::getInstance().getNpPhysicsGpu().setExplicitCudaFlushCountHint(scene, cudaFlushCount);
+}
+
+bool PxParticleGpu::setTriangleMeshCacheSizeHint(const class PxScene& scene, PxU32 size)
+{
+ return NpPhysics::getInstance().getNpPhysicsGpu().setTriangleMeshCacheSizeHint(scene, size);
+}
+
+PxTriangleMeshCacheStatistics PxParticleGpu::getTriangleMeshCacheStatistics(const class PxScene& scene)
+{
+ return NpPhysics::getInstance().getNpPhysicsGpu().getTriangleMeshCacheStatistics(scene);
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+#endif // PX_SUPPORT_GPU_PHYSX
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/PxPhysXGpuModuleLoader.cpp b/PhysX_3.4/Source/PhysX/src/gpu/PxPhysXGpuModuleLoader.cpp
new file mode 100644
index 00000000..1d5f7388
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/PxPhysXGpuModuleLoader.cpp
@@ -0,0 +1,141 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+
+#include "PxPhysXConfig.h"
+
+#if PX_SUPPORT_GPU_PHYSX
+
+#include "foundation/Px.h"
+#include "PsFoundation.h"
+#include "PxPhysics.h"
+
+#include "cudamanager/PxCudaContextManager.h"
+
+#define STRINGIFY(x) #x
+#define GETSTRING(x) STRINGIFY(x)
+
+#if PX_X86
+#define PLATFORM_SUB_STR "x86"
+#elif PX_X64
+#define PLATFORM_SUB_STR "x64"
+#endif
+
+#if defined(PX_PHYSX_DLL_NAME_POSTFIX)
+#define CONFIG_SUB_STR GETSTRING(PX_PHYSX_DLL_NAME_POSTFIX)
+#else
+#define CONFIG_SUB_STR
+#endif
+
+#if PX_WINDOWS
+
+#include "windows/PsWindowsInclude.h"
+#include "windows/CmWindowsModuleUpdateLoader.h"
+static const char* gPhysXGpuLibraryName = "PhysX3Gpu" CONFIG_SUB_STR "_" PLATFORM_SUB_STR ".dll";
+
+#elif PX_LINUX
+
+#include <dlfcn.h>
+static const char* gPhysXGpuLibraryName = "./libPhysX3Gpu" CONFIG_SUB_STR "_" PLATFORM_SUB_STR ".so";
+
+#endif // PX_LINUX
+
+#undef GETSTRING
+#undef STRINGIFY
+
+namespace physx
+{
+#if PX_VC
+#pragma warning(disable: 4191) //'operator/operation' : unsafe conversion from 'type of expression' to 'type required'
+#endif
+
+ class PxFoundation;
+ class PxPhysXGpu;
+
+ typedef physx::PxPhysXGpu* (PxCreatePhysXGpu_FUNC)();
+ typedef physx::PxCudaContextManager* (PxCreateCudaContextManager_FUNC)(physx::PxFoundation& foundation, const physx::PxCudaContextManagerDesc& desc);
+ typedef int (PxGetSuggestedCudaDeviceOrdinal_FUNC)(physx::PxErrorCallback& errc);
+
+ PxCreatePhysXGpu_FUNC* g_PxCreatePhysXGpu_Func = NULL;
+ PxCreateCudaContextManager_FUNC* g_PxCreateCudaContextManager_Func = NULL;
+ PxGetSuggestedCudaDeviceOrdinal_FUNC* g_PxGetSuggestedCudaDeviceOrdinal_Func = NULL;
+
+#if PX_WINDOWS
+
+#define DEFAULT_PHYSX_GPU_GUID "D79FA4BF-177C-4841-8091-4375D311D6A3"
+
+ void PxLoadPhysxGPUModule(const char* appGUID)
+ {
+ static HMODULE s_library;
+
+ if (s_library == NULL)
+ s_library = GetModuleHandle(gPhysXGpuLibraryName);
+
+ if (s_library == NULL)
+ {
+ Cm::CmModuleUpdateLoader moduleLoader(UPDATE_LOADER_DLL_NAME);
+ s_library = moduleLoader.LoadModule(gPhysXGpuLibraryName, appGUID == NULL ? DEFAULT_PHYSX_GPU_GUID : appGUID);
+ }
+
+ if (s_library)
+ {
+ g_PxCreatePhysXGpu_Func = (PxCreatePhysXGpu_FUNC*)GetProcAddress(s_library, "PxCreatePhysXGpu");
+ g_PxCreateCudaContextManager_Func = (PxCreateCudaContextManager_FUNC*)GetProcAddress(s_library, "PxCreateCudaContextManager");
+ g_PxGetSuggestedCudaDeviceOrdinal_Func = (PxGetSuggestedCudaDeviceOrdinal_FUNC*)GetProcAddress(s_library, "PxGetSuggestedCudaDeviceOrdinal");
+ }
+ }
+
+#elif PX_LINUX
+
+ void PxLoadPhysxGPUModule(const char*)
+ {
+ static void* s_library;
+
+ if (s_library == NULL)
+ {
+ // load libcuda.so here since gcc configured with --as-needed won't link to it
+ // if there is no call from the binary to it.
+ void* hLibCuda = dlopen("libcuda.so", RTLD_NOW | RTLD_GLOBAL);
+ if (hLibCuda)
+ {
+ s_library = dlopen(gPhysXGpuLibraryName, RTLD_NOW);
+ }
+ }
+
+ // no UpdateLoader
+ if (s_library)
+ {
+ *reinterpret_cast<void**>(&g_PxCreatePhysXGpu_Func) = dlsym(s_library, "PxCreatePhysXGpu");
+ *reinterpret_cast<void**>(&g_PxCreateCudaContextManager_Func) = dlsym(s_library, "PxCreateCudaContextManager");
+ *reinterpret_cast<void**>(&g_PxGetSuggestedCudaDeviceOrdinal_Func) = dlsym(s_library, "PxGetSuggestedCudaDeviceOrdinal");
+ }
+ }
+
+#endif // PX_LINUX
+
+} // end physx namespace
+
+#endif // PX_SUPPORT_GPU_PHYSX \ No newline at end of file
diff --git a/PhysX_3.4/Source/PhysX/src/gpu/PxPhysXIndicatorDeviceExclusive.cpp b/PhysX_3.4/Source/PhysX/src/gpu/PxPhysXIndicatorDeviceExclusive.cpp
new file mode 100644
index 00000000..4c32a1dc
--- /dev/null
+++ b/PhysX_3.4/Source/PhysX/src/gpu/PxPhysXIndicatorDeviceExclusive.cpp
@@ -0,0 +1,50 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2016 NVIDIA Corporation. All rights reserved.
+// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
+// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
+
+#include "PxPhysXConfig.h"
+#include "PxPhysXIndicatorDeviceExclusive.h"
+#include "NpPhysics.h"
+
+using namespace physx;
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxPhysXIndicatorDeviceExclusive::registerPhysXIndicatorGpuClient(class PxPhysics& physics)
+{
+ static_cast<NpPhysics*>(&physics)->registerPhysXIndicatorGpuClient();
+}
+
+//-------------------------------------------------------------------------------------------------------------------//
+
+void PxPhysXIndicatorDeviceExclusive::unregisterPhysXIndicatorGpuClient(class PxPhysics& physics)
+{
+ static_cast<NpPhysics*>(&physics)->unregisterPhysXIndicatorGpuClient();
+}
+
+//-------------------------------------------------------------------------------------------------------------------//