aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/LowLevel/common/include
diff options
context:
space:
mode:
Diffstat (limited to 'PhysX_3.4/Source/LowLevel/common/include')
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/collision/PxcContactMethodImpl.h98
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcCCDStateStreamPair.h29
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcConstraintBlockStream.h166
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcContactCache.h64
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcMaterialMethodImpl.h69
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpBatch.h65
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCache.h154
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCacheStreamPair.h63
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpContactPrepShared.h59
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpMemBlockPool.h119
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpThreadContext.h216
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpWorkUnit.h162
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcRigidBody.h117
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/utils/PxcScratchAllocator.h138
-rw-r--r--PhysX_3.4/Source/LowLevel/common/include/utils/PxcThreadCoherentCache.h150
15 files changed, 1669 insertions, 0 deletions
diff --git a/PhysX_3.4/Source/LowLevel/common/include/collision/PxcContactMethodImpl.h b/PhysX_3.4/Source/LowLevel/common/include/collision/PxcContactMethodImpl.h
new file mode 100644
index 00000000..193b20a5
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/collision/PxcContactMethodImpl.h
@@ -0,0 +1,98 @@
+// 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 PXC_CONTACTMETHODIMPL_H
+#define PXC_CONTACTMETHODIMPL_H
+
+#include "GuGeometryUnion.h"
+#include "CmPhysXCommon.h"
+#include "GuContactMethodImpl.h"
+
+namespace physx
+{
+namespace Cm
+{
+ class RenderOutput;
+}
+
+namespace Gu
+{
+ class ContactBuffer;
+ struct Cache;
+ struct NarrowPhaseParams;
+}
+
+struct PxcNpCache;
+class PxcNpThreadContext;
+class PxsContext;
+class PxcConvexTriangles;
+class PxsRigidBody;
+struct PxsCCDShape;
+
+namespace Cm
+{
+ class FastVertex2ShapeScaling;
+}
+
+/*!\file
+This file contains forward declarations of all implemented contact methods.
+*/
+
+
+/*! Parameter list without names to avoid unused parameter warnings
+*/
+#define CONTACT_METHOD_ARGS_UNUSED \
+ const Gu::GeometryUnion&, \
+ const Gu::GeometryUnion&, \
+ const PxTransform&, \
+ const PxTransform&, \
+ const Gu::NarrowPhaseParams&, \
+ Gu::Cache&, \
+ Gu::ContactBuffer&, \
+ Cm::RenderOutput*
+
+
+/*!
+Method prototype for contact generation routines
+*/
+typedef bool (*PxcContactMethod) (GU_CONTACT_METHOD_ARGS);
+
+
+// Matrix of types
+extern PxcContactMethod g_ContactMethodTable[][PxGeometryType::eGEOMETRY_COUNT];
+extern const bool g_CanUseContactCache[][PxGeometryType::eGEOMETRY_COUNT];
+extern PxcContactMethod g_PCMContactMethodTable[][PxGeometryType::eGEOMETRY_COUNT];
+
+extern bool gEnablePCMCaching[][PxGeometryType::eGEOMETRY_COUNT];
+
+extern bool gUnifiedHeightfieldCollision;
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcCCDStateStreamPair.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcCCDStateStreamPair.h
new file mode 100644
index 00000000..cf29bad0
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcCCDStateStreamPair.h
@@ -0,0 +1,29 @@
+// 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.
+
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcConstraintBlockStream.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcConstraintBlockStream.h
new file mode 100644
index 00000000..37c0ba8e
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcConstraintBlockStream.h
@@ -0,0 +1,166 @@
+// 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 PXC_CONSTRAINTBLOCKPOOL_H
+#define PXC_CONSTRAINTBLOCKPOOL_H
+
+#include "PxvConfig.h"
+#include "PsArray.h"
+#include "PsMutex.h"
+#include "PxcNpMemBlockPool.h"
+
+namespace physx
+{
+
+class PxsConstraintBlockManager
+{
+public:
+ PxsConstraintBlockManager(PxcNpMemBlockPool & blockPool):
+ mBlockPool(blockPool)
+ {
+ }
+
+
+ PX_FORCE_INLINE void reset()
+ {
+ mBlockPool.releaseConstraintBlocks(mTrackingArray);
+ }
+
+
+ PxcNpMemBlockArray mTrackingArray;
+ PxcNpMemBlockPool& mBlockPool;
+
+private:
+ PxsConstraintBlockManager& operator=(const PxsConstraintBlockManager&);
+};
+
+class PxcConstraintBlockStream
+{
+ PX_NOCOPY(PxcConstraintBlockStream)
+public:
+ PxcConstraintBlockStream(PxcNpMemBlockPool & blockPool):
+ mBlockPool(blockPool),
+ mBlock(NULL),
+ mUsed(0)
+ {
+ }
+
+ PX_FORCE_INLINE PxU8* reserve(PxU32 size, PxsConstraintBlockManager& manager)
+ {
+ size = (size+15)&~15;
+ if(size>PxcNpMemBlock::SIZE)
+ return mBlockPool.acquireExceptionalConstraintMemory(size);
+
+ if(mBlock == NULL || size+mUsed>PxcNpMemBlock::SIZE)
+ {
+ mBlock = mBlockPool.acquireConstraintBlock(manager.mTrackingArray);
+ PX_ASSERT(0==mBlock || mBlock->data == reinterpret_cast<PxU8*>(mBlock));
+ mUsed = size;
+ return reinterpret_cast<PxU8*>(mBlock);
+ }
+ PX_ASSERT(mBlock && mBlock->data == reinterpret_cast<PxU8*>(mBlock));
+ PxU8* PX_RESTRICT result = mBlock->data+mUsed;
+ mUsed += size;
+ return result;
+ }
+
+ PX_FORCE_INLINE void reset()
+ {
+ mBlock = NULL;
+ mUsed = 0;
+ }
+
+ PX_FORCE_INLINE PxcNpMemBlockPool& getMemBlockPool()
+ {
+ return mBlockPool;
+ }
+
+private:
+ PxcNpMemBlockPool& mBlockPool;
+ PxcNpMemBlock* mBlock; // current constraint block
+ PxU32 mUsed; // number of bytes used in constraint block
+ //Tracking peak allocations
+ PxU32 mPeakUsed;
+};
+
+class PxcContactBlockStream
+{
+ PX_NOCOPY(PxcContactBlockStream)
+public:
+ PxcContactBlockStream(PxcNpMemBlockPool & blockPool):
+ mBlockPool(blockPool),
+ mBlock(NULL),
+ mUsed(0)
+ {
+ }
+
+ PX_FORCE_INLINE PxU8* reserve(PxU32 size)
+ {
+ size = (size+15)&~15;
+
+ if(size>PxcNpMemBlock::SIZE)
+ return mBlockPool.acquireExceptionalConstraintMemory(size);
+
+ PX_ASSERT(size <= PxcNpMemBlock::SIZE);
+
+ if(mBlock == NULL || size+mUsed>PxcNpMemBlock::SIZE)
+ {
+ mBlock = mBlockPool.acquireContactBlock();
+ PX_ASSERT(0==mBlock || mBlock->data == reinterpret_cast<PxU8*>(mBlock));
+ mUsed = size;
+ return reinterpret_cast<PxU8*>(mBlock);
+ }
+ PX_ASSERT(mBlock && mBlock->data == reinterpret_cast<PxU8*>(mBlock));
+ PxU8* PX_RESTRICT result = mBlock->data+mUsed;
+ mUsed += size;
+ return result;
+ }
+
+ PX_FORCE_INLINE void reset()
+ {
+ mBlock = NULL;
+ mUsed = 0;
+ }
+
+ PX_FORCE_INLINE PxcNpMemBlockPool& getMemBlockPool()
+ {
+ return mBlockPool;
+ }
+
+private:
+ PxcNpMemBlockPool& mBlockPool;
+ PxcNpMemBlock* mBlock; // current constraint block
+ PxU32 mUsed; // number of bytes used in constraint block
+};
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcContactCache.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcContactCache.h
new file mode 100644
index 00000000..34174b35
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcContactCache.h
@@ -0,0 +1,64 @@
+// 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 PXC_CONTACT_CACHE_H
+#define PXC_CONTACT_CACHE_H
+
+#include "foundation/PxTransform.h"
+#include "PxvConfig.h"
+#include "PxcContactMethodImpl.h"
+
+namespace physx
+{
+ bool PxcCacheLocalContacts( PxcNpThreadContext& context, Gu::Cache& pairContactCache,
+ const PxTransform& tm0, const PxTransform& tm1,
+ const PxcContactMethod conMethod,
+ const Gu::GeometryUnion& shape0, const Gu::GeometryUnion& shape1);
+
+ struct PxcLocalContactsCache
+ {
+ PxTransform mTransform0;
+ PxTransform mTransform1;
+ PxU16 mNbCachedContacts;
+ bool mUseFaceIndices;
+ bool mSameNormal;
+
+ PX_FORCE_INLINE void operator = (const PxcLocalContactsCache& other)
+ {
+ mTransform0 = other.mTransform0;
+ mTransform1 = other.mTransform1;
+ mNbCachedContacts = other.mNbCachedContacts;
+ mUseFaceIndices = other.mUseFaceIndices;
+ mSameNormal = other.mSameNormal;
+ }
+ };
+
+}
+
+#endif // PXC_CONTACT_CACHE_H
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcMaterialMethodImpl.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcMaterialMethodImpl.h
new file mode 100644
index 00000000..b7260aa4
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcMaterialMethodImpl.h
@@ -0,0 +1,69 @@
+// 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 PXC_MATERIALMETHOD_H
+#define PXC_MATERIALMETHOD_H
+
+#include "CmPhysXCommon.h"
+#include "PxGeometry.h"
+
+namespace physx
+{
+
+struct PxsShapeCore;
+struct PxsMaterialInfo;
+class PxcNpThreadContext;
+
+#define MATERIAL_METHOD_ARGS \
+ const PxsShapeCore* shape0, \
+ const PxsShapeCore* shape1, \
+ PxcNpThreadContext& pairContext, \
+ PxsMaterialInfo* materialInfo
+
+
+#define SINGLE_MATERIAL_METHOD_ARGS \
+ const PxsShapeCore* shape, \
+ const PxU32 index, \
+ PxcNpThreadContext& pairContext, \
+ PxsMaterialInfo* materialInfo
+
+/*!
+Method prototype for fetch material routines
+*/
+typedef bool (*PxcGetMaterialMethod) (MATERIAL_METHOD_ARGS);
+
+typedef bool (*PxcGetSingleMaterialMethod) (SINGLE_MATERIAL_METHOD_ARGS);
+
+extern PxcGetMaterialMethod g_GetMaterialMethodTable[][PxGeometryType::eGEOMETRY_COUNT];
+
+extern PxcGetSingleMaterialMethod g_GetSingleMaterialMethodTable[PxGeometryType::eGEOMETRY_COUNT];
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpBatch.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpBatch.h
new file mode 100644
index 00000000..fe243aed
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpBatch.h
@@ -0,0 +1,65 @@
+// 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 PXC_NP_BATCH_H
+#define PXC_NP_BATCH_H
+
+#include "PxvConfig.h"
+
+namespace physx
+{
+ struct PxcNpWorkUnit;
+ class PxcNpThreadContext;
+
+struct PxcNpWorkUnit;
+class PxsContactManager;
+struct PxsContactManagerOutput;
+
+namespace Gu
+{
+ struct Cache;
+}
+
+namespace Cm
+{
+ class FlushPool;
+}
+
+class PxLightCpuTask;
+
+namespace Gu
+{
+ class PxgGpuNarrowphaseCoreInterface;
+}
+
+void PxcDiscreteNarrowPhase(PxcNpThreadContext& context, PxcNpWorkUnit& cmInput, Gu::Cache& cache, PxsContactManagerOutput& output);
+void PxcDiscreteNarrowPhasePCM(PxcNpThreadContext& context, PxcNpWorkUnit& cmInput, Gu::Cache& cache, PxsContactManagerOutput& output);
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCache.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCache.h
new file mode 100644
index 00000000..2ac7dde8
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCache.h
@@ -0,0 +1,154 @@
+// 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 PXC_NPCACHE_H
+#define PXC_NPCACHE_H
+
+#include "foundation/PxMemory.h"
+
+#include "PsIntrinsics.h"
+#include "PxcNpCacheStreamPair.h"
+
+#include "PsPool.h"
+#include "PsFoundation.h"
+#include "GuContactMethodImpl.h"
+#include "PsUtilities.h"
+
+namespace physx
+{
+
+template <typename T>
+void PxcNpCacheWrite(PxcNpCacheStreamPair& streams,
+ Gu::Cache& cache,
+ const T& payload,
+ PxU32 bytes,
+ const PxU8* data)
+{
+ const PxU32 payloadSize = (sizeof(payload)+3)&~3;
+ cache.mCachedSize = Ps::to16((payloadSize + 4 + bytes + 0xF)&~0xF);
+
+ PxU8* ls = streams.reserve(cache.mCachedSize);
+ cache.mCachedData = ls;
+ if(ls==NULL || (reinterpret_cast<PxU8*>(-1))==ls)
+ {
+ if(ls==NULL)
+ {
+ PX_WARN_ONCE(
+ "Reached limit set by PxSceneDesc::maxNbContactDataBlocks - ran out of buffer space for narrow phase. "
+ "Either accept dropped contacts or increase buffer size allocated for narrow phase by increasing PxSceneDesc::maxNbContactDataBlocks.");
+ return;
+ }
+ else
+ {
+ PX_WARN_ONCE(
+ "Attempting to allocate more than 16K of contact data for a single contact pair in narrowphase. "
+ "Either accept dropped contacts or simplify collision geometry.");
+ cache.mCachedData = NULL;
+ ls = NULL;
+ return;
+ }
+ }
+
+ *reinterpret_cast<T*>(ls) = payload;
+ *reinterpret_cast<PxU32*>(ls+payloadSize) = bytes;
+ if(data)
+ PxMemCopy(ls+payloadSize+sizeof(PxU32), data, bytes);
+}
+
+
+template <typename T>
+PxU8* PxcNpCacheWriteInitiate(PxcNpCacheStreamPair& streams, Gu::Cache& cache, const T& payload, PxU32 bytes)
+{
+ PX_UNUSED(payload);
+
+ const PxU32 payloadSize = (sizeof(payload)+3)&~3;
+ cache.mCachedSize = Ps::to16((payloadSize + 4 + bytes + 0xF)&~0xF);
+
+ PxU8* ls = streams.reserve(cache.mCachedSize);
+ cache.mCachedData = ls;
+ if(NULL==ls || reinterpret_cast<PxU8*>(-1)==ls)
+ {
+ if(NULL==ls)
+ {
+ PX_WARN_ONCE(
+ "Reached limit set by PxSceneDesc::maxNbContactDataBlocks - ran out of buffer space for narrow phase. "
+ "Either accept dropped contacts or increase buffer size allocated for narrow phase by increasing PxSceneDesc::maxNbContactDataBlocks.");
+ }
+ else
+ {
+ PX_WARN_ONCE(
+ "Attempting to allocate more than 16K of contact data for a single contact pair in narrowphase. "
+ "Either accept dropped contacts or simplify collision geometry.");
+ cache.mCachedData = NULL;
+ ls = NULL;
+ }
+ }
+ return ls;
+}
+
+template <typename T>
+PX_FORCE_INLINE void PxcNpCacheWriteFinalize(PxU8* ls, const T& payload, PxU32 bytes, const PxU8* data)
+{
+ const PxU32 payloadSize = (sizeof(payload)+3)&~3;
+ *reinterpret_cast<T*>(ls) = payload;
+ *reinterpret_cast<PxU32*>(ls+payloadSize) = bytes;
+ if(data)
+ PxMemCopy(ls+payloadSize+sizeof(PxU32), data, bytes);
+}
+
+
+template <typename T>
+PX_FORCE_INLINE PxU8* PxcNpCacheRead(Gu::Cache& cache, T*& payload)
+{
+ PxU8* ls = cache.mCachedData;
+ payload = reinterpret_cast<T*>(ls);
+ const PxU32 payloadSize = (sizeof(T)+3)&~3;
+ return reinterpret_cast<PxU8*>(ls+payloadSize+sizeof(PxU32));
+}
+
+template <typename T>
+const PxU8* PxcNpCacheRead2(Gu::Cache& cache, T& payload, PxU32& bytes)
+{
+ const PxU8* ls = cache.mCachedData;
+ if(ls==NULL)
+ {
+ bytes = 0;
+ return NULL;
+ }
+
+ const PxU32 payloadSize = (sizeof(payload)+3)&~3;
+ payload = *reinterpret_cast<const T*>(ls);
+ bytes = *reinterpret_cast<const PxU32*>(ls+payloadSize);
+ PX_ASSERT(cache.mCachedSize == ((payloadSize + 4 + bytes+0xF)&~0xF));
+ return reinterpret_cast<const PxU8*>(ls+payloadSize+sizeof(PxU32));
+}
+
+}
+
+#endif // #ifndef PXC_NPCACHE_H
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCacheStreamPair.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCacheStreamPair.h
new file mode 100644
index 00000000..08757b8c
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpCacheStreamPair.h
@@ -0,0 +1,63 @@
+// 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 PXC_NPCACHESTREAMPAIR_H
+#define PXC_NPCACHESTREAMPAIR_H
+
+#include "foundation/PxSimpleTypes.h"
+#include "PxvConfig.h"
+#include "PxcNpMemBlockPool.h"
+
+namespace physx
+{
+
+static const PxU32 PXC_NPCACHE_BLOCK_SIZE = 16384;
+
+
+struct PxcNpCacheStreamPair
+{
+public:
+ PxcNpCacheStreamPair(PxcNpMemBlockPool& blockPool);
+
+ // reserve can fail and return null.
+ PxU8* reserve(PxU32 byteCount);
+ void reset();
+private:
+ PxcNpMemBlockPool& mBlockPool;
+ PxcNpMemBlock* mBlock;
+ PxU32 mUsed;
+private:
+ PxcNpCacheStreamPair& operator=(const PxcNpCacheStreamPair&);
+};
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpContactPrepShared.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpContactPrepShared.h
new file mode 100644
index 00000000..4fc9c122
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpContactPrepShared.h
@@ -0,0 +1,59 @@
+// 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 PXC_NPCONTACTPREPSHARED_H
+#define PXC_NPCONTACTPREPSHARED_H
+
+namespace physx
+{
+class PxcNpThreadContext;
+struct PxsMaterialInfo;
+class PxsMaterialManager;
+class PxsConstraintBlockManager;
+class PxcConstraintBlockStream;
+struct PxsContactManagerOutput;
+
+namespace Gu
+{
+ struct ContactPoint;
+}
+
+static const PxReal PXC_SAME_NORMAL = 0.999f; //Around 6 degrees
+
+bool finishContacts(PxcNpWorkUnit& input, PxsContactManagerOutput& npOutput, PxcNpThreadContext& threadContext, PxsMaterialInfo* pMaterialInfo, const bool isMeshType);
+
+PxU32 writeCompressedContact(const Gu::ContactPoint* const PX_RESTRICT contactPoints, const PxU32 numContactPoints, PxcNpThreadContext* threadContext,
+ PxU8& writtenContactCount, PxU8*& outContactPatches, PxU8*& outContactPoints, PxU16& compressedContactSize, PxReal*& contactForces, PxU32 contactForceByteSize,
+ const PxsMaterialManager* materialManager, bool hasModifiableContacts, bool forceNoResponse, PxsMaterialInfo* PX_RESTRICT pMaterial, PxU8& numPatches,
+ PxU32 additionalHeaderSize = 0, PxsConstraintBlockManager* manager = NULL, PxcConstraintBlockStream* blockStream = NULL, bool insertAveragePoint = false,
+ PxcDataStreamPool* pool = NULL, PxcDataStreamPool* patchStreamPool = NULL, PxcDataStreamPool* forcePool = NULL, const bool isMeshType = false);
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpMemBlockPool.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpMemBlockPool.h
new file mode 100644
index 00000000..8374cfa9
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpMemBlockPool.h
@@ -0,0 +1,119 @@
+// 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 PXC_NP_MEM_BLOCK_POOL_H
+#define PXC_NP_MEM_BLOCK_POOL_H
+
+#include "PxvConfig.h"
+#include "PsArray.h"
+#include "PxcScratchAllocator.h"
+
+namespace physx
+{
+struct PxcNpMemBlock
+{
+ enum
+ {
+ SIZE = 16384
+ };
+ PxU8 data[SIZE];
+};
+
+typedef Ps::Array<PxcNpMemBlock*> PxcNpMemBlockArray;
+
+class PxcNpMemBlockPool
+{
+ PX_NOCOPY(PxcNpMemBlockPool)
+public:
+ PxcNpMemBlockPool(PxcScratchAllocator& allocator);
+ ~PxcNpMemBlockPool();
+
+ void init(PxU32 initial16KDataBlocks, PxU32 maxBlocks);
+ void flush();
+ void setBlockCount(PxU32 count);
+ PxU32 getUsedBlockCount() const;
+ PxU32 getMaxUsedBlockCount() const;
+ PxU32 getPeakConstraintBlockCount() const;
+ void releaseUnusedBlocks();
+
+ PxcNpMemBlock* acquireConstraintBlock();
+ PxcNpMemBlock* acquireConstraintBlock(PxcNpMemBlockArray& memBlocks);
+ PxcNpMemBlock* acquireContactBlock();
+ PxcNpMemBlock* acquireFrictionBlock();
+ PxcNpMemBlock* acquireNpCacheBlock();
+
+ PxU8* acquireExceptionalConstraintMemory(PxU32 size);
+
+ void acquireConstraintMemory();
+ void releaseConstraintMemory();
+ void releaseConstraintBlocks(PxcNpMemBlockArray& memBlocks);
+ void releaseContacts();
+ void swapFrictionStreams();
+ void swapNpCacheStreams();
+
+ void flushUnused();
+
+private:
+
+
+ Ps::Mutex mLock;
+ PxcNpMemBlockArray mConstraints;
+ PxcNpMemBlockArray mContacts[2];
+ PxcNpMemBlockArray mFriction[2];
+ PxcNpMemBlockArray mNpCache[2];
+ PxcNpMemBlockArray mScratchBlocks;
+ Ps::Array<PxU8*> mExceptionalConstraints;
+
+ PxcNpMemBlockArray mUnused;
+
+ PxU32 mNpCacheActiveStream;
+ PxU32 mFrictionActiveStream;
+ PxU32 mCCDCacheActiveStream;
+ PxU32 mContactIndex;
+ PxU32 mAllocatedBlocks;
+ PxU32 mMaxBlocks;
+ PxU32 mInitialBlocks;
+ PxU32 mUsedBlocks;
+ PxU32 mMaxUsedBlocks;
+ PxcNpMemBlock* mScratchBlockAddr;
+ PxU32 mNbScratchBlocks;
+ PxcScratchAllocator& mScratchAllocator;
+
+ PxU32 mPeakConstraintAllocations;
+ PxU32 mConstraintAllocations;
+
+ PxcNpMemBlock* acquire(PxcNpMemBlockArray& trackingArray, PxU32* allocationCount = NULL, PxU32* peakAllocationCount = NULL, bool isScratchAllocation = false);
+ void release(PxcNpMemBlockArray& deadArray, PxU32* allocationCount = NULL);
+};
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpThreadContext.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpThreadContext.h
new file mode 100644
index 00000000..ef731066
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpThreadContext.h
@@ -0,0 +1,216 @@
+// 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 PXC_NPTHREADCONTEXT_H
+#define PXC_NPTHREADCONTEXT_H
+
+#include "PxvConfig.h"
+#include "CmScaling.h"
+#include "CmRenderOutput.h"
+#include "PxcNpCacheStreamPair.h"
+#include "PxcConstraintBlockStream.h"
+#include "GuContactBuffer.h"
+#include "PxvContext.h"
+#include "PxcThreadCoherentCache.h"
+#include "CmBitMap.h"
+#include "../pcm/GuPersistentContactManifold.h"
+
+namespace physx
+{
+
+class PxsTransformCache;
+class PxsMaterialManager;
+
+namespace Bp
+{
+ class AABBManagerImpl;
+}
+
+namespace Sc
+{
+ class BodySim;
+}
+
+/*!
+Per-thread context used by contact generation routines.
+*/
+
+struct PxcDataStreamPool
+{
+ PxU8* mDataStream;
+ PxI32 mSharedDataIndex;
+ PxU32 mDataStreamSize;
+ PxU32 mSharedDataIndexGPU;
+
+ bool isOverflown() const
+ {
+ //FD: my expectaton is that reading those variables is atomic, shared indices are non-decreasing,
+ //so we can only get a false overflow alert because of concurrency issues, which is not a big deal as it means
+ //it did overflow a bit later
+ return mSharedDataIndex + mSharedDataIndexGPU >= mDataStreamSize;
+ }
+};
+
+struct PxcNpContext
+{
+ private:
+ PX_NOCOPY(PxcNpContext)
+ public:
+
+ PxcNpContext() :
+ mNpMemBlockPool (mScratchAllocator),
+ mMeshContactMargin (0.0f),
+ mToleranceLength (0.0f),
+ mCreateContactStream (false),
+ mContactStreamPool (NULL),
+ mPatchStreamPool (NULL),
+ mForceAndIndiceStreamPool(NULL),
+ mMaterialManager (NULL)
+ {
+ }
+
+ PxcScratchAllocator mScratchAllocator;
+ PxcNpMemBlockPool mNpMemBlockPool;
+ PxReal mMeshContactMargin;
+ PxReal mToleranceLength;
+ Cm::RenderBuffer mRenderBuffer;
+ bool mCreateContactStream; // flag to enforce that contacts are stored persistently per workunit. Used for PVD.
+ PxcDataStreamPool* mContactStreamPool;
+ PxcDataStreamPool* mPatchStreamPool;
+ PxcDataStreamPool* mForceAndIndiceStreamPool;
+ PxcDataStreamPool* mConstraintWriteBackStreamPool;
+ PxsMaterialManager* mMaterialManager;
+
+ PX_FORCE_INLINE PxReal getToleranceLength() const { return mToleranceLength; }
+ PX_FORCE_INLINE void setToleranceLength(PxReal x) { mToleranceLength = x; }
+ PX_FORCE_INLINE PxReal getMeshContactMargin() const { return mMeshContactMargin; }
+ PX_FORCE_INLINE void setMeshContactMargin(PxReal x) { mMeshContactMargin = x; }
+ PX_FORCE_INLINE bool getCreateContactStream() { return mCreateContactStream; }
+
+ PX_FORCE_INLINE PxcNpMemBlockPool& getNpMemBlockPool() { return mNpMemBlockPool; }
+ PX_FORCE_INLINE const PxcNpMemBlockPool& getNpMemBlockPool() const { return mNpMemBlockPool; }
+ PX_FORCE_INLINE void setMaterialManager(PxsMaterialManager* m){ mMaterialManager = m; }
+ PX_FORCE_INLINE PxsMaterialManager* getMaterialManager() const { return mMaterialManager; }
+
+ Cm::RenderOutput getRenderOutput() { return Cm::RenderOutput(mRenderBuffer); }
+};
+
+class PxcNpThreadContext : public PxcThreadCoherentCache<PxcNpThreadContext, PxcNpContext>::EntryBase
+{
+ PX_NOCOPY(PxcNpThreadContext)
+public:
+ PxcNpThreadContext(PxcNpContext* params);
+ ~PxcNpThreadContext();
+
+#if PX_ENABLE_SIM_STATS
+ void clearStats();
+#endif
+
+ PX_FORCE_INLINE void setCreateContactStream(bool to) { mCreateContactStream = to; }
+
+ PX_FORCE_INLINE void addLocalNewTouchCount(PxU32 newTouchCMCount) { mLocalNewTouchCount += newTouchCMCount; }
+ PX_FORCE_INLINE void addLocalLostTouchCount(PxU32 lostTouchCMCount) { mLocalLostTouchCount += lostTouchCMCount; }
+ PX_FORCE_INLINE PxU32 getLocalNewTouchCount() const { return mLocalNewTouchCount; }
+ PX_FORCE_INLINE PxU32 getLocalLostTouchCount() const { return mLocalLostTouchCount; }
+
+ PX_FORCE_INLINE void addLocalFoundPatchCount(PxU32 foundPatchCount) { mLocalFoundPatchCount += foundPatchCount; }
+ PX_FORCE_INLINE void addLocalLostPatchCount(PxU32 lostPatchCount) { mLocalLostPatchCount += lostPatchCount; }
+ PX_FORCE_INLINE PxU32 getLocalFoundPatchCount() const { return mLocalFoundPatchCount; }
+ PX_FORCE_INLINE PxU32 getLocalLostPatchCount() const { return mLocalLostPatchCount; }
+
+ PX_FORCE_INLINE Cm::BitMap& getLocalChangeTouch() { return mLocalChangeTouch; }
+
+ PX_FORCE_INLINE Cm::BitMap& getLocalPatchChangeMap() { return mLocalPatchCountChange; }
+
+ void reset(PxU32 cmCount);
+ // debugging
+ Cm::RenderOutput mRenderOutput;
+
+ // dsequeira: Need to think about this block pool allocation a bit more. Ideally we'd be
+ // taking blocks from a single pool, except that we want to be able to selectively reclaim
+ // blocks if the user needs to defragment, depending on which artifacts they're willing
+ // to tolerate, such that the blocks we don't reclaim are contiguous.
+#if PX_ENABLE_SIM_STATS
+ PxU32 mDiscreteContactPairs [PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT];
+ PxU32 mModifiedContactPairs [PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT];
+#endif
+ PxcContactBlockStream mContactBlockStream; // constraint block pool
+ PxcNpCacheStreamPair mNpCacheStreamPair; // narrow phase pairwise data cache
+
+ // Everything below here is scratch state. Most of it can even overlap.
+
+ // temporary contact buffer
+ Gu::ContactBuffer mContactBuffer;
+
+ PX_ALIGN(16, Gu::MultiplePersistentContactManifold mTempManifold);
+
+ Gu::NarrowPhaseParams mNarrowPhaseParams;
+
+ // DS: this stuff got moved here from the PxcNpPairContext. As Pierre says:
+ ////////// PT: those members shouldn't be there in the end, it's not necessary
+ Ps::Array<Sc::BodySim*> mBodySimPool;
+ PxsTransformCache* mTransformCache;
+ PxReal* mContactDistance;
+ bool mPCM;
+ bool mContactCache;
+ bool mCreateContactStream; // flag to enforce that contacts are stored persistently per workunit. Used for PVD.
+ bool mCreateAveragePoint; // flag to enforce whether we create average points
+#if PX_ENABLE_SIM_STATS
+ PxU32 mCompressedCacheSize;
+ PxU32 mNbDiscreteContactPairsWithCacheHits;
+ PxU32 mNbDiscreteContactPairsWithContacts;
+#endif
+ PxReal mDt; // AP: still needed for ccd
+ PxU32 mCCDPass;
+ PxU32 mCCDFaceIndex;
+
+ PxU32 mMaxPatches;
+ //PxU32 mTotalContactCount;
+ PxU32 mTotalCompressedCacheSize;
+ //PxU32 mTotalPatchCount;
+
+ PxcDataStreamPool* mContactStreamPool;
+ PxcDataStreamPool* mPatchStreamPool;
+ PxcDataStreamPool* mForceAndIndiceStreamPool; //this stream is used to store the force buffer and triangle index if we are performing mesh/heightfield contact gen
+ PxcDataStreamPool* mConstraintWriteBackStreamPool;
+ PxsMaterialManager* mMaterialManager;
+private:
+ // change touch handling.
+ Cm::BitMap mLocalChangeTouch;
+ Cm::BitMap mLocalPatchCountChange;
+ PxU32 mLocalNewTouchCount;
+ PxU32 mLocalLostTouchCount;
+ PxU32 mLocalFoundPatchCount;
+ PxU32 mLocalLostPatchCount;
+};
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpWorkUnit.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpWorkUnit.h
new file mode 100644
index 00000000..bfc4f0da
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcNpWorkUnit.h
@@ -0,0 +1,162 @@
+// 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 PXC_NPWORKUNIT_H
+#define PXC_NPWORKUNIT_H
+
+#include "PxcNpThreadContext.h"
+#include "PxcMaterialMethodImpl.h"
+#include "PxcNpCache.h"
+
+namespace physx
+{
+
+class PxvContact;
+
+struct PxsRigidCore;
+struct PxsShapeCore;
+
+class PxsMaterialManager;
+
+struct PxcNpWorkUnitFlag
+{
+ enum Enum
+ {
+ eOUTPUT_CONTACTS = 1,
+ eOUTPUT_CONSTRAINTS = 2,
+ eDISABLE_STRONG_FRICTION = 4,
+ eARTICULATION_BODY0 = 8,
+ eARTICULATION_BODY1 = 16,
+ eDYNAMIC_BODY0 = 32,
+ eDYNAMIC_BODY1 = 64,
+ eMODIFIABLE_CONTACT = 128,
+ eFORCE_THRESHOLD = 256,
+ eDETECT_DISCRETE_CONTACT = 512,
+ eHAS_KINEMATIC_ACTOR = 1024,
+ eDISABLE_RESPONSE = 2048,
+ eDETECT_CCD_CONTACTS = 4096
+ };
+};
+
+struct PxcNpWorkUnitStatusFlag
+{
+ enum Enum
+ {
+ eHAS_NO_TOUCH = (1 << 0),
+ eHAS_TOUCH = (1 << 1),
+ //eHAS_SOLVER_CONSTRAINTS = (1 << 2),
+ eREQUEST_CONSTRAINTS = (1 << 3),
+ eHAS_CCD_RETOUCH = (1 << 4), // Marks pairs that are touching at a CCD pass and were touching at discrete collision or at a previous CCD pass already
+ // but we can not tell whether they lost contact in a pass before. We send them as pure eNOTIFY_TOUCH_CCD events to the
+ // contact report callback if requested.
+ eDIRTY_MANAGER = (1 << 5),
+ eREFRESHED_WITH_TOUCH = (1 << 6),
+ eTOUCH_KNOWN = eHAS_NO_TOUCH | eHAS_TOUCH // The touch status is known (if narrowphase never ran for a pair then no flag will be set)
+ };
+};
+
+/*
+ * A struct to record the number of work units a particular constraint pointer references.
+ * This is created at the beginning of the constriant data and is used to bypass constraint preparation when the
+ * bodies are not moving a lot. In this case, we can recycle the constraints and save ourselves some cycles.
+*/
+struct PxcNpWorkUnit;
+struct PxcNpWorkUnitBatch
+{
+ PxcNpWorkUnit* mUnits[4];
+ PxU32 mSize;
+};
+
+struct PxcNpWorkUnit
+{
+
+ const PxsRigidCore* rigidCore0; // INPUT //4 //8
+ const PxsRigidCore* rigidCore1; // INPUT //8 //16
+
+ const PxsShapeCore* shapeCore0; // INPUT //12 //24
+ const PxsShapeCore* shapeCore1; // INPUT //16 //32
+
+ PxU8* ccdContacts; // OUTPUT //20 //40
+
+ PxU8* frictionDataPtr; // INOUT //24 //48
+
+ PxU16 flags; // INPUT //26 //50
+ PxU8 frictionPatchCount; // INOUT //27 //51
+ PxU8 statusFlags; // OUTPUT (see PxcNpWorkUnitStatusFlag) //28 //52
+
+ PxU8 dominance0; // INPUT //29 //53
+ PxU8 dominance1; // INPUT //30 //54
+ PxU8 geomType0; // INPUT //31 //55
+ PxU8 geomType1; // INPUT //32 //56
+
+ PxU32 index; // INPUT //36 //60
+
+ PxReal restDistance; // INPUT //40 //64
+
+ PxU32 mTransformCache0; // //44 //68
+ PxU32 mTransformCache1; // //48 //72
+
+ PxU32 mEdgeIndex; //inout the island gen edge index //52 //76
+ PxU32 mNpIndex; //INPUT //56 //80
+
+};
+
+//#if !defined(PX_P64)
+//PX_COMPILE_TIME_ASSERT(0 == (sizeof(PxcNpWorkUnit) & 0x0f));
+//#endif
+
+PX_FORCE_INLINE void PxcNpWorkUnitClearContactState(PxcNpWorkUnit& n)
+{
+ n.ccdContacts = NULL;
+}
+
+
+PX_FORCE_INLINE void PxcNpWorkUnitClearCachedState(PxcNpWorkUnit& n)
+{
+ n.frictionDataPtr = 0;
+ n.frictionPatchCount = 0;
+ n.ccdContacts = NULL;
+}
+
+PX_FORCE_INLINE void PxcNpWorkUnitClearFrictionCachedState(PxcNpWorkUnit& n)
+{
+ n.frictionDataPtr = 0;
+ n.frictionPatchCount = 0;
+ n.ccdContacts = NULL;
+}
+
+#if !defined(PX_P64)
+//PX_COMPILE_TIME_ASSERT(sizeof(PxcNpWorkUnit)==128);
+#endif
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcRigidBody.h b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcRigidBody.h
new file mode 100644
index 00000000..03870e4f
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/pipeline/PxcRigidBody.h
@@ -0,0 +1,117 @@
+// 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 PXC_RIGIDBODY_H
+#define PXC_RIGIDBODY_H
+
+#include "foundation/PxVec3.h"
+#include "foundation/PxTransform.h"
+#include "PxvDynamics.h"
+#include "CmSpatialVector.h"
+
+namespace physx
+{
+
+class PxsContactManager;
+struct PxsCCDPair;
+struct PxsCCDBody;
+
+#define PX_INTERNAL_LOCK_FLAG_START 7
+
+PX_ALIGN_PREFIX(16)
+class PxcRigidBody
+{
+public:
+
+ enum PxcRigidBodyFlag
+ {
+ eFROZEN = 1 << 0, //This flag indicates that the stabilization is enabled and the body is
+ //"frozen". By "frozen", we mean that the body's transform is unchanged
+ //from the previous frame. This permits various optimizations.
+ eFREEZE_THIS_FRAME = 1 << 1,
+ eUNFREEZE_THIS_FRAME = 1 << 2,
+ eACTIVATE_THIS_FRAME = 1 << 3,
+ eDEACTIVATE_THIS_FRAME = 1 << 4,
+ eDISABLE_GRAVITY = 1 << 5,
+ eSPECULATIVE_CCD = 1 << 6,
+ //KS - copied here for GPU simulation to avoid needing to pass another set of flags around.
+ eLOCK_LINEAR_X = 1 << (PX_INTERNAL_LOCK_FLAG_START),
+ eLOCK_LINEAR_Y = 1 << (PX_INTERNAL_LOCK_FLAG_START + 1),
+ eLOCK_LINEAR_Z = 1 << (PX_INTERNAL_LOCK_FLAG_START + 2),
+ eLOCK_ANGULAR_X = 1 << (PX_INTERNAL_LOCK_FLAG_START + 3),
+ eLOCK_ANGULAR_Y = 1 << (PX_INTERNAL_LOCK_FLAG_START + 4),
+ eLOCK_ANGULAR_Z = 1 << (PX_INTERNAL_LOCK_FLAG_START + 5)
+
+ };
+
+ PX_FORCE_INLINE PxcRigidBody(PxsBodyCore* core)
+ : mLastTransform(core->body2World),
+ mCCD(NULL),
+ mCore(core)
+ {
+ }
+
+ void adjustCCDLastTransform();
+
+protected:
+
+ ~PxcRigidBody()
+ {
+ }
+
+public:
+
+ PxTransform mLastTransform; //28 (28)
+
+ PxU16 mInternalFlags; //30 (30)
+ PxU16 solverIterationCounts; //32 (32)
+
+ PxsCCDBody* mCCD; //36 (40) // only valid during CCD
+
+ PxsBodyCore* mCore; //40 (48)
+
+#if !PX_P64_FAMILY
+ PxU32 alignmentPad[2]; //48 (48)
+#endif
+
+ PxVec3 sleepLinVelAcc; //60 (60)
+ PxReal freezeCount; //64 (64)
+
+ PxVec3 sleepAngVelAcc; //76 (76)
+ PxReal accelScale; //80 (80)
+
+
+}
+PX_ALIGN_SUFFIX(16);
+PX_COMPILE_TIME_ASSERT(0 == (sizeof(PxcRigidBody) & 0x0f));
+
+}
+
+#endif //PXC_RIGIDBODY_H
diff --git a/PhysX_3.4/Source/LowLevel/common/include/utils/PxcScratchAllocator.h b/PhysX_3.4/Source/LowLevel/common/include/utils/PxcScratchAllocator.h
new file mode 100644
index 00000000..aaf43626
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/utils/PxcScratchAllocator.h
@@ -0,0 +1,138 @@
+// 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 PXC_SCRATCHALLOCATOR_H
+#define PXC_SCRATCHALLOCATOR_H
+
+#include "foundation/PxAssert.h"
+#include "PxvConfig.h"
+#include "PsMutex.h"
+#include "PsArray.h"
+#include "PsAllocator.h"
+
+namespace physx
+{
+class PxcScratchAllocator
+{
+ PX_NOCOPY(PxcScratchAllocator)
+public:
+ PxcScratchAllocator() : mStack(PX_DEBUG_EXP("PxcScratchAllocator")), mStart(NULL), mSize(0)
+ {
+ mStack.reserve(64);
+ mStack.pushBack(0);
+ }
+
+ void setBlock(void* addr, PxU32 size)
+ {
+ // if the stack is not empty then some scratch memory was not freed on the previous frame. That's
+ // likely indicative of a problem, because when the scratch block is too small the memory will have
+ // come from the heap
+
+ PX_ASSERT(mStack.size()==1);
+ mStack.popBack();
+
+ mStart = reinterpret_cast<PxU8*>(addr);
+ mSize = size;
+ mStack.pushBack(mStart + size);
+ }
+
+ void* allocAll(PxU32& size)
+ {
+ Ps::Mutex::ScopedLock lock(mLock);
+ PX_ASSERT(mStack.size()>0);
+ size = PxU32(mStack.back()-mStart);
+
+ if(size==0)
+ return NULL;
+
+ mStack.pushBack(mStart);
+ return mStart;
+ }
+
+
+ void* alloc(PxU32 requestedSize, bool fallBackToHeap = false)
+ {
+ requestedSize = (requestedSize+15)&~15;
+
+ Ps::Mutex::ScopedLock lock(mLock);
+ PX_ASSERT(mStack.size()>=1);
+
+ PxU8* top = mStack.back();
+
+ if(top - mStart >= ptrdiff_t(requestedSize))
+ {
+ PxU8* addr = top - requestedSize;
+ mStack.pushBack(addr);
+ return addr;
+ }
+
+ if(!fallBackToHeap)
+ return NULL;
+
+ return PX_ALLOC(requestedSize, "Scratch Block Fallback");
+ }
+
+ void free(void* addr)
+ {
+ PX_ASSERT(addr!=NULL);
+ if(!isScratchAddr(addr))
+ {
+ PX_FREE(addr);
+ return;
+ }
+
+ Ps::Mutex::ScopedLock lock(mLock);
+ PX_ASSERT(mStack.size()>1);
+
+ PxU32 i=mStack.size()-1;
+ while(mStack[i]<addr)
+ i--;
+
+ PX_ASSERT(mStack[i]==addr);
+ mStack.remove(i);
+ }
+
+
+ bool isScratchAddr(void* addr) const
+ {
+ PxU8* a = reinterpret_cast<PxU8*>(addr);
+ return a>= mStart && a<mStart+mSize;
+ }
+
+private:
+ Ps::Mutex mLock;
+ Ps::Array<PxU8*> mStack;
+ PxU8* mStart;
+ PxU32 mSize;
+};
+
+}
+
+#endif
diff --git a/PhysX_3.4/Source/LowLevel/common/include/utils/PxcThreadCoherentCache.h b/PhysX_3.4/Source/LowLevel/common/include/utils/PxcThreadCoherentCache.h
new file mode 100644
index 00000000..ed8a37a5
--- /dev/null
+++ b/PhysX_3.4/Source/LowLevel/common/include/utils/PxcThreadCoherentCache.h
@@ -0,0 +1,150 @@
+// 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 PXC_THREADCOHERENTCACHE_H
+#define PXC_THREADCOHERENTCACHE_H
+
+#include "PsMutex.h"
+#include "PsAllocator.h"
+#include "PsSList.h"
+
+namespace physx
+{
+
+class PxsContext;
+/*!
+Controls a pool of large objects which must be thread safe.
+Tries to return the object most recently used by the thread(for better cache coherancy).
+Assumes the object has a default contructor.
+
+(Note the semantics are different to a pool because we dont want to construct/destroy each time
+an object is requested, which may be expensive).
+
+TODO: add thread coherancy.
+*/
+template<class T, class Params>
+class PxcThreadCoherentCache : public Ps::AlignedAllocator<16, Ps::ReflectionAllocator<T> >
+{
+ typedef Ps::AlignedAllocator<16, Ps::ReflectionAllocator<T> > Allocator;
+ PX_NOCOPY(PxcThreadCoherentCache)
+public:
+
+ typedef Ps::SListEntry EntryBase;
+
+ PX_INLINE PxcThreadCoherentCache(Params* params, const Allocator& alloc = Allocator()) : Allocator(alloc), mParams(params)
+ {
+ }
+
+ PX_INLINE ~PxcThreadCoherentCache()
+ {
+ T* np = static_cast<T*>(root.pop());
+
+ while(np!=NULL)
+ {
+ np->~T();
+ Allocator::deallocate(np);
+ np = static_cast<T*>(root.pop());
+ }
+ }
+
+ PX_INLINE T* get()
+ {
+ T* rv = static_cast<T*>(root.pop());
+ if(rv==NULL)
+ {
+ rv = reinterpret_cast<T*>(Allocator::allocate(sizeof(T), __FILE__, __LINE__));
+ new (rv) T(mParams);
+ }
+
+ return rv;
+ }
+
+ PX_INLINE void put(T* item)
+ {
+ root.push(*item);
+ }
+
+
+private:
+ Ps::SList root;
+ Params* mParams;
+
+ template<class T2, class P2>
+ friend class PxcThreadCoherentCacheIterator;
+};
+
+/*!
+Used to iterate over all objects controlled by the cache.
+
+Note: The iterator flushes the cache(extracts all items on construction and adds them back on
+destruction so we can iterate the list in a safe manner).
+*/
+template<class T, class Params>
+class PxcThreadCoherentCacheIterator
+{
+public:
+ PxcThreadCoherentCacheIterator(PxcThreadCoherentCache<T, Params>& cache) : mCache(cache)
+ {
+ mNext = cache.root.flush();
+ mFirst = mNext;
+ }
+ ~PxcThreadCoherentCacheIterator()
+ {
+ Ps::SListEntry* np = mFirst;
+ while(np != NULL)
+ {
+ Ps::SListEntry* npNext = np->next();
+ mCache.root.push(*np);
+ np = npNext;
+ }
+ }
+
+ PX_INLINE T* getNext()
+ {
+ if(mNext == NULL)
+ return NULL;
+
+ T* rv = static_cast<T*>(mNext);
+ mNext = mNext->next();
+
+ return rv;
+ }
+private:
+
+ PxcThreadCoherentCacheIterator<T, Params>& operator=(const PxcThreadCoherentCacheIterator<T, Params>&);
+ PxcThreadCoherentCache<T, Params> &mCache;
+ Ps::SListEntry* mNext;
+ Ps::SListEntry* mFirst;
+
+};
+
+}
+
+#endif