diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /PhysX_3.4/Source/LowLevelDynamics/include | |
| download | physx-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/LowLevelDynamics/include')
7 files changed, 1166 insertions, 0 deletions
diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DyArticulation.h b/PhysX_3.4/Source/LowLevelDynamics/include/DyArticulation.h new file mode 100644 index 00000000..2072b25e --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DyArticulation.h @@ -0,0 +1,283 @@ +// 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 PXD_ARTICULATION_H +#define PXD_ARTICULATION_H + +#include "foundation/PxVec3.h" +#include "foundation/PxQuat.h" +#include "foundation/PxTransform.h" +#include "PsVecMath.h" +#include "CmUtils.h" +#include "CmSpatialVector.h" +#include "PxArticulationJoint.h" + +namespace physx +{ + +class PxcRigidBody; +struct PxsBodyCore; + +namespace Sc +{ + class ArticulationSim; +} + + +#define DY_DEBUG_ARTICULATION 0 + + +namespace Dy +{ +static const size_t DY_ARTICULATION_MAX_SIZE = 64; +struct ArticulationJointTransforms; +struct FsInertia; +struct FsData; +struct ArticulationCore +{ +//= ATTENTION! ===================================================================================== +// Changing the data layout of this class breaks the binary serialization format. See comments for +// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData +// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION +// accordingly. +//================================================================================================== + + PxU32 internalDriveIterations; + PxU32 externalDriveIterations; + PxU32 maxProjectionIterations; + PxU16 solverIterationCounts; //KS - made a U16 so that it matches PxsRigidCore + PxReal separationTolerance; + PxReal sleepThreshold; + PxReal freezeThreshold; + PxReal wakeCounter; +}; + +struct ArticulationJointCore +{ +//= ATTENTION! ===================================================================================== +// Changing the data layout of this class breaks the binary serialization format. See comments for +// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData +// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION +// accordingly. +//================================================================================================== + + // attachment points + PxTransform parentPose; + PxTransform childPose; + + // drive model + PxQuat targetPosition; + PxVec3 targetVelocity; + + PxReal spring; + PxReal damping; + + PxReal solverSpring; + PxReal solverDamping; + + PxReal internalCompliance; + PxReal externalCompliance; + + // limit model + + PxReal swingYLimit; + PxReal swingZLimit; + PxReal swingLimitContactDistance; + bool swingLimited; + + PxU8 driveType; + + PxReal tangentialStiffness; + PxReal tangentialDamping; + + PxReal twistLimitHigh; + PxReal twistLimitLow; + PxReal twistLimitContactDistance; + bool twistLimited; + + PxReal tanQSwingY; + PxReal tanQSwingZ; + PxReal tanQSwingPad; + PxReal tanQTwistHigh; + PxReal tanQTwistLow; + PxReal tanQTwistPad; + + ArticulationJointCore() + { + Cm::markSerializedMem(this, sizeof(ArticulationJointCore)); + parentPose = PxTransform(PxIdentity); + childPose = PxTransform(PxIdentity); + internalCompliance = 0; + externalCompliance = 0; + swingLimitContactDistance = 0.05f; + twistLimitContactDistance = 0.05f; + driveType = PxArticulationJointDriveType::eTARGET; + } +// PX_SERIALIZATION + ArticulationJointCore(const PxEMPTY&) {} +//~PX_SERIALIZATION + +}; + +#define DY_ARTICULATION_LINK_NONE 0xffffffff + +typedef PxU64 ArticulationBitField; + +struct ArticulationLink +{ + ArticulationBitField children; // child bitmap + ArticulationBitField pathToRoot; // path to root, including link and root + PxcRigidBody* body; + PxsBodyCore* bodyCore; + const ArticulationJointCore* inboundJoint; + PxU32 parent; +}; + +typedef size_t ArticulationLinkHandle; + +struct ArticulationSolverDesc +{ + FsData* fsData; + const ArticulationLink* links; + Cm::SpatialVectorV* motionVelocity; + Cm::SpatialVector* acceleration; + PxTransform* poses; + physx::shdfnd::aos::Mat33V* externalLoads; + physx::shdfnd::aos::Mat33V* internalLoads; + const ArticulationCore* core; + char* scratchMemory; + PxU16 totalDataSize; + PxU16 solverDataSize; + PxU8 linkCount; + PxU8 numInternalConstraints; + PxU16 scratchMemorySize; +}; + +#if PX_VC + #pragma warning(push) + #pragma warning( disable : 4324 ) // Padding was added at the end of a structure because of a __declspec(align) value. +#endif +PX_ALIGN_PREFIX(64) +class Articulation +{ +public: + // public interface + + Articulation(Sc::ArticulationSim*); + ~Articulation(); + + // solver methods + PxU32 getLinkIndex(ArticulationLinkHandle handle) const; + PxU32 getBodyCount() const { return mSolverDesc->linkCount; } + FsData* getFsDataPtr() const { return mSolverDesc->fsData; } + PxU32 getSolverDataSize() const { return mSolverDesc->solverDataSize; } + PxU32 getTotalDataSize() const { return mSolverDesc->totalDataSize; } + void getSolverDesc(ArticulationSolverDesc& d) const { d = *mSolverDesc; } + void setSolverDesc(const ArticulationSolverDesc& d) { mSolverDesc = &d; } + + const ArticulationSolverDesc* getSolverDescPtr() const { return mSolverDesc; } + const ArticulationCore* getCore() const { return mSolverDesc->core;} + PxU16 getIterationCounts() const { return mSolverDesc->core->solverIterationCounts; } + + Sc::ArticulationSim* getArticulationSim() const { return mArticulationSim; } + + + // get data sizes for allocation at higher levels + static void getDataSizes(PxU32 linkCount, + PxU32 &solverDataSize, + PxU32& totalSize, + PxU32& scratchSize); + +private: + + const ArticulationSolverDesc* mSolverDesc; + Sc::ArticulationSim* mArticulationSim; + +#if DY_DEBUG_ARTICULATION + // debug quantities + + Cm::SpatialVector computeMomentum(const FsInertia *inertia) const; + void computeResiduals(const Cm::SpatialVector *, + const ArticulationJointTransforms* jointTransforms, + bool dump = false) const; + void checkLimits() const; +#endif + +} PX_ALIGN_SUFFIX(64); + +#if PX_VC + #pragma warning(pop) +#endif + +class PxvArticulationDriveCache +{ +public: + // drive cache stuff + static void initialize(FsData &cache, + PxU16 linkCount, + const ArticulationLink* links, + PxReal compliance, + PxU32 iterations, + char* scratchMemory, + PxU32 scratchMemorySize); + + static PxU32 getLinkCount(const FsData& cache); + + static void applyImpulses(const FsData& cache, + Cm::SpatialVectorV* Z, + Cm::SpatialVectorV* V); + + static void getImpulseResponse(const FsData& cache, + PxU32 linkID, + const Cm::SpatialVectorV& impulse, + Cm::SpatialVectorV& deltaV); +}; + +void PxvRegisterArticulations(); + + +static const size_t DY_ARTICULATION_IDMASK = DY_ARTICULATION_MAX_SIZE-1; + +PX_FORCE_INLINE Articulation* getArticulation(ArticulationLinkHandle handle) +{ + return reinterpret_cast<Articulation*>(handle & ~DY_ARTICULATION_IDMASK); +} + +PX_FORCE_INLINE bool isArticulationRootLink(ArticulationLinkHandle handle) +{ + return !(handle & DY_ARTICULATION_IDMASK); +} + + +} + +} + +#endif diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DyConstraint.h b/PhysX_3.4/Source/LowLevelDynamics/include/DyConstraint.h new file mode 100644 index 00000000..4a78876c --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DyConstraint.h @@ -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. + + +#ifndef PXD_SHADER_H +#define PXD_SHADER_H + +#include "foundation/PxVec3.h" +#include "foundation/PxTransform.h" +#include "PxvConfig.h" +#include "PxvDynamics.h" +#include "PxConstraint.h" +#include "DyConstraintWriteBack.h" + +namespace physx +{ + +class PxsRigidBody; + +namespace Dy +{ + + +#if PX_VC + #pragma warning(push) + #pragma warning( disable : 4324 ) // Padding was added at the end of a structure because of a __declspec(align) value. +#endif +PX_ALIGN_PREFIX(16) +struct Constraint +{ +public: + + PxReal linBreakForce; //0 + PxReal angBreakForce; //4 + PxU32 constantBlockSize; //8 + + PxConstraintSolverPrep solverPrep; //12 + PxConstraintProject project; //16 + void* constantBlock; //20 + + PxsRigidBody* body0; //24 + PxsRigidBody* body1; //28 + + PxsBodyCore* bodyCore0; //32 + PxsBodyCore* bodyCore1; //36 + PxU32 flags; //40 + PxU32 index; //44 //this is also a constraint write back index + PxReal minResponseThreshold; //48 +} +PX_ALIGN_SUFFIX(16); +#if PX_VC + #pragma warning(pop) +#endif + +#if !PX_P64_FAMILY +PX_COMPILE_TIME_ASSERT(64==sizeof(Constraint)); +#endif + +} + +} + +#endif diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DyConstraintWriteBack.h b/PhysX_3.4/Source/LowLevelDynamics/include/DyConstraintWriteBack.h new file mode 100644 index 00000000..0068c7b7 --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DyConstraintWriteBack.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 PXD_CONSTRAINT_WRITE_BACK_H +#define PXD_CONSTRAINT_WRITE_BACK_H + +#include "foundation/PxVec3.h" +#include "PxvConfig.h" +#include "PxvDynamics.h" + +namespace physx +{ + namespace Dy + { + + PX_ALIGN_PREFIX(16) + struct ConstraintWriteback + { + public: + + void initialize() + { + linearImpulse = PxVec3(0); + angularImpulse = PxVec3(0); + broken = false; + } + + PxVec3 linearImpulse; + PxU32 broken; + PxVec3 angularImpulse; + PxU32 pad; + } + PX_ALIGN_SUFFIX(16); + + } +} + +#endif diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DyContext.h b/PhysX_3.4/Source/LowLevelDynamics/include/DyContext.h new file mode 100644 index 00000000..5212e0fa --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DyContext.h @@ -0,0 +1,370 @@ +// 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 PXV_DYNAMICS_CONTEXT_H +#define PXV_DYNAMICS_CONTEXT_H + +#include "CmPhysXCommon.h" +#include "PxSceneDesc.h" +#include "DyThresholdTable.h" +#include "DyGpuAPI.h" +#include "PxcNpThreadContext.h" +#include "PxsSimulationController.h" +#include "DyConstraintWriteBack.h" +#include "PsAllocator.h" + + + +namespace physx +{ + +class PxsIslandManager; +class PxcNpMemBlockPool; + +namespace Cm +{ + class EventProfiler; + class FlushPool; +} + +namespace IG +{ + class SimpleIslandManager; + class IslandSim; +} + +template<typename T, typename P> class PxcThreadCoherentCache; +class PxcScratchAllocator; +struct PxvSimStats; +class PxTaskManager; +class PxcNpMemBlockPool; +struct PxgDynamicsMemoryConfig; +class PxsContactManagerOutputIterator; +struct PxsContactManagerOutput; +class PxsKernelWranglerManager; +class PxsHeapMemoryAllocator; +class PxsMemoryManager; + + +namespace Dy +{ + + +class Context +{ + PX_NOCOPY(Context) +public: + /** + \brief Returns the bounce threshold + \return The bounce threshold. + */ + PX_FORCE_INLINE PxReal getBounceThreshold() const { return mBounceThreshold; } + /** + \brief Returns the friction offset threshold + \return The friction offset threshold. + */ + PX_FORCE_INLINE PxReal getFrictionOffsetThreshold() const { return mFrictionOffsetThreshold; } + /** + \brief Returns the correlation distance + \return The correlation distance. + */ + PX_FORCE_INLINE PxReal getCorrelationDistance() const { return mCorrelationDistance; } + + /** + \brief Returns the CCD separation threshold + \return The CCD separation threshold. + */ + PX_FORCE_INLINE PxReal getCCDSeparationThreshold() const { return mCCDSeparationThreshold; } + + /** + \brief Sets the bounce threshold + \param[in] f The bounce threshold + */ + PX_FORCE_INLINE void setBounceThreshold(PxReal f) { mBounceThreshold = f; } + /** + \brief Sets the correlation distance + \param[in] f The correlation distance + */ + PX_FORCE_INLINE void setCorrelationDistance(PxReal f) { mCorrelationDistance = f; } + /** + \brief Sets the friction offset threshold + \param[in] offset The friction offset threshold + */ + PX_FORCE_INLINE void setFrictionOffsetThreshold(PxReal offset) { mFrictionOffsetThreshold = offset; } + /** + \brief Sets the friction offset threshold + \param[in] offset The friction offset threshold + */ + PX_FORCE_INLINE void setCCDSeparationThreshold(PxReal offset) { mCCDSeparationThreshold = offset; } + + + /** + \brief Returns the solver batch size + \return The solver batch size. + */ + PX_FORCE_INLINE PxU32 getSolverBatchSize() const { return mSolverBatchSize; } + /** + \brief Sets the solver batch size + \param[in] f The solver batch size + */ + PX_FORCE_INLINE void setSolverBatchSize(PxU32 f) { mSolverBatchSize = f; } + /** + \brief Returns the maximum solver constraint size + \return The maximum solver constraint size in this island in bytes. + */ + PX_FORCE_INLINE PxU32 getMaxSolverConstraintSize() const { return mMaxSolverConstraintSize; } + + /** + \brief Returns the friction model being used. + \return The friction model being used. + */ + PX_FORCE_INLINE PxFrictionType::Enum getFrictionType() const { return mFrictionType; } + + /** + \brief Returns the threshold stream + \return The threshold stream + */ + PX_FORCE_INLINE ThresholdStream& getThresholdStream() { return *mThresholdStream; } + + PX_FORCE_INLINE ThresholdStream& getForceChangedThresholdStream() { return *mForceChangedThresholdStream; } + + /** + \brief Returns the threshold table + \return The threshold table + */ + PX_FORCE_INLINE ThresholdTable& getThresholdTable() { return mThresholdTable; } + + /** + \brief Sets the friction model to be used. + \param[in] f The friction model to be used. + */ + PX_FORCE_INLINE void setFrictionType(PxFrictionType::Enum f) { mFrictionType = f; } + + /** + \brief Destroys this dynamics context + */ + virtual void destroy() = 0; + + + + PX_FORCE_INLINE PxcDataStreamPool& getContactStreamPool() { return mContactStreamPool; } + + PX_FORCE_INLINE PxcDataStreamPool& getPatchStreamPool() { return mPatchStreamPool; } + + PX_FORCE_INLINE PxcDataStreamPool& getForceStreamPool() { return mForceStreamPool; } + + PX_FORCE_INLINE Ps::Array<Dy::ConstraintWriteback, Ps::VirtualAllocator>& getConstraintWriteBackPool() { return mConstraintWriteBackPool; } + + + /** + \brief Returns the current frame's timestep + \return The current frame's timestep. + */ + PX_FORCE_INLINE PxReal getDt() const { return mDt; } + /** + \brief Returns 1/(current frame's timestep) + \return 1/(current frame's timestep). + */ + PX_FORCE_INLINE PxReal getInvDt() const { return mInvDt; } + + PX_FORCE_INLINE PxVec3 getGravity() const { return mGravity; } + + + + /** + \brief The entry point for the constraint solver. + \param[in] dt The simulation time-step + \param[in] continuation The continuation task for the solver + \param[in] processLostTouchTask The task that processes lost touches + + This method is called after the island generation has completed. Its main responsibilities are: + (1) Reserving the solver body pools + (2) Initializing the static and kinematic solver bodies, which are shared resources between islands. + (3) Construct the solver task chains for each island + + Each island is solved as an independent solver task chain. In addition, large islands may be solved using multiple parallel tasks. + Island solving is asynchronous. Once all islands have been solved, the continuation task will be called. + + */ + virtual void update(IG::SimpleIslandManager& simpleIslandManager, PxBaseTask* continuation, PxBaseTask* processLostTouchTask, + PxsContactManager** foundPatchManagers, PxU32 nbFoundPatchManagers, PxsContactManager** lostPatchManagers, PxU32 nbLostPatchManagers, PxU32 maxPatchesPerCM, + PxsContactManagerOutputIterator& iterator, PxsContactManagerOutput* gpuOutputs, const PxReal dt, const PxVec3& gravity, const PxU32 bitMapWordCounts) = 0; + + virtual void processLostPatches(IG::SimpleIslandManager& simpleIslandManager, PxsContactManager** lostPatchManagers, PxU32 nbLostPatchManagers, PxsContactManagerOutputIterator& iterator) = 0; + + + /** + \brief This method copy gpu solver body data to cpu body core + */ + virtual void updateBodyCore(PxBaseTask* continuation) = 0; + + /** + \brief Called after update's task chain has completed. This collects the results of the solver together + */ + virtual void mergeResults() = 0; + + virtual void setSimulationController(PxsSimulationController* simulationController) = 0; + + virtual void getDataStreamBase(void*& contactStreamBase, void*& patchStreamBase, void*& forceAndIndiceStreamBase) = 0; + + void createThresholdStream(Ps::VirtualAllocatorCallback& callback) { PX_ASSERT(mThresholdStream == NULL); mThresholdStream = PX_PLACEMENT_NEW(PX_ALLOC(sizeof(ThresholdStream), PX_DEBUG_EXP("ThresholdStream")), ThresholdStream(callback));} + + void createForceChangeThresholdStream(Ps::VirtualAllocatorCallback& callback) { PX_ASSERT(mForceChangedThresholdStream == NULL); mForceChangedThresholdStream = PX_PLACEMENT_NEW(PX_ALLOC(sizeof(ThresholdStream), PX_DEBUG_EXP("ThresholdStream")), ThresholdStream(callback));} + + + +protected: + + Context(IG::IslandSim* accurateIslandSim, Ps::VirtualAllocatorCallback* allocatorCallback, + PxvSimStats& simStats, bool enableStabilization, bool useEnhancedDeterminism, bool useAdaptiveForce) : + mThresholdStream(NULL), + mForceChangedThresholdStream(NULL), + mAccurateIslandSim(accurateIslandSim), + mDt (1.0f), + mInvDt (1.0f), + mEnableStabilization (enableStabilization), + mUseEnhancedDeterminism (useEnhancedDeterminism), + mUseAdaptiveForce (useAdaptiveForce), + mBounceThreshold(-2.0f), + mSolverBatchSize(32), + mConstraintWriteBackPool(Ps::VirtualAllocator(allocatorCallback)), + mSimStats(simStats) + { + } + + virtual ~Context() + { + if(mThresholdStream) + { + mThresholdStream->~ThresholdStream(); + PX_FREE(mThresholdStream); + } + mThresholdStream = NULL; + if(mForceChangedThresholdStream) + { + mForceChangedThresholdStream->~ThresholdStream(); + PX_FREE(mForceChangedThresholdStream); + } + mForceChangedThresholdStream = NULL; + } + + ThresholdStream* mThresholdStream; + ThresholdStream* mForceChangedThresholdStream; + ThresholdTable mThresholdTable; + + IG::IslandSim* mAccurateIslandSim; + PxsSimulationController* mSimulationController; + /** + \brief Time-step. + */ + PxReal mDt; + /** + \brief 1/time-step. + */ + PxReal mInvDt; + + const bool mEnableStabilization; + + const bool mUseEnhancedDeterminism; + + const bool mUseAdaptiveForce; + + PxVec3 mGravity; + /** + \brief max solver constraint size + */ + PxU32 mMaxSolverConstraintSize; + + /** + \brief Threshold controlling the relative velocity at which the solver transitions between restitution and bias for solving normal contact constraint. + */ + PxReal mBounceThreshold; + /** + \brief Threshold controlling whether friction anchors are constructed or not. If the separation is above mFrictionOffsetThreshold, the contact will not be considered to become a friction anchor + */ + PxReal mFrictionOffsetThreshold; + + /** + \brief Threshold controlling whether distant contacts are processed using bias, restitution or a combination of the two. This only has effect on pairs involving bodies that have enabled speculative CCD simulation mode. + */ + PxReal mCCDSeparationThreshold; + + /** + \brief Threshold for controlling friction correlation + */ + PxReal mCorrelationDistance; + /** + \brief The minimum size of an island to generate a solver task chain. + */ + PxU32 mSolverBatchSize; + + /** + \brief The current friction model being used + */ + PxFrictionType::Enum mFrictionType; + + /** + \brief Structure to encapsulate contact stream allocations. Used by GPU solver to reference pre-allocated pinned host memory + */ + PxcDataStreamPool mContactStreamPool; + + /** + \brief Struct to encapsulate the contact patch stream allocations. Used by GPU solver to reference pre-allocated pinned host memory + */ + + PxcDataStreamPool mPatchStreamPool; + + /** + \brief Structure to encapsulate force stream allocations. Used by GPU solver to reference pre-allocated pinned host memory for force reports. + */ + PxcDataStreamPool mForceStreamPool; + + /** + \brief Structure to encapsulate constraint write back allocations. Used by GPU/CPU solver to reference pre-allocated pinned host memory for breakable joint reports. + */ + Ps::Array<Dy::ConstraintWriteback, Ps::VirtualAllocator> mConstraintWriteBackPool; + + PxvSimStats& mSimStats; + + +}; + +Context* createDynamicsContext( PxcNpMemBlockPool* memBlockPool, + PxcScratchAllocator& scratchAllocator, Cm::FlushPool& taskPool, + PxvSimStats& simStats, PxTaskManager* taskManager, Ps::VirtualAllocatorCallback* allocatorCallback, PxsMaterialManager* materialManager, + IG::IslandSim* accurateIslandSim, PxU64 contextID, + const bool enableStabilization, const bool useEnhancedDeterminism, const bool useAdaptiveForce + ); + +} + +} + +#endif + diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DyGpuAPI.h b/PhysX_3.4/Source/LowLevelDynamics/include/DyGpuAPI.h new file mode 100644 index 00000000..0e24bc5e --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DyGpuAPI.h @@ -0,0 +1,38 @@ +// 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 PXV_GPU_API_H +#define PXV_GPU_API_H + +#if PX_SUPPORT_GPU_PHYSX +#include "Pxg.h" +#endif + + +#endif // !PXV_GPU_API_H diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DySleepingConfigulation.h b/PhysX_3.4/Source/LowLevelDynamics/include/DySleepingConfigulation.h new file mode 100644 index 00000000..e28d626e --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DySleepingConfigulation.h @@ -0,0 +1,42 @@ +// 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 PXD_SLEEPING_CONFIGULATION_H +#define PXD_SLEEPING_CONFIGULATION_H + +#define PXD_FREEZE_INTERVAL 1.5f +#define PXD_FREE_EXIT_THRESHOLD 4.f +#define PXD_FREEZE_TOLERANCE 0.25f + +#define PXD_SLEEP_DAMPING 0.5f +#define PXD_ACCEL_LOSS 0.9f +#define PXD_FREEZE_SCALE 0.1f + +#endif diff --git a/PhysX_3.4/Source/LowLevelDynamics/include/DyThresholdTable.h b/PhysX_3.4/Source/LowLevelDynamics/include/DyThresholdTable.h new file mode 100644 index 00000000..56405e8d --- /dev/null +++ b/PhysX_3.4/Source/LowLevelDynamics/include/DyThresholdTable.h @@ -0,0 +1,279 @@ +// 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 PXD_THRESHOLDTABLE_H +#define PXD_THRESHOLDTABLE_H +#include "Ps.h" +#include "PsArray.h" +#include "CmPhysXCommon.h" +#include "PsAllocator.h" +#include "PsHash.h" +#include "foundation/PxMemory.h" + +namespace physx +{ + +class PxsRigidBody; + +namespace Sc +{ + class ShapeInteraction; +} + +namespace Dy +{ + +struct ThresholdStreamElement +{ + Sc::ShapeInteraction* shapeInteraction; //4 8 + PxReal normalForce; //8 12 + PxReal threshold; //12 16 + PxU32 nodeIndexA; //this is the unique node index in island gen which corresonding to that body and it is persistent 16 20 + PxU32 nodeIndexB; //This is the unique node index in island gen which corresonding to that body and it is persistent 20 24 + PxReal accumulatedForce; //24 28 + PxU32 pad; //28 32 + +#if !PX_P64_FAMILY + PxU32 pad1; //32 +#endif // !PX_X64 + + PX_CUDA_CALLABLE bool operator <= (const ThresholdStreamElement& otherPair) const + { + return ((nodeIndexA < otherPair.nodeIndexA) ||(nodeIndexA == otherPair.nodeIndexA && nodeIndexB <= otherPair.nodeIndexB)); + } + +}; + +typedef Ps::Array<ThresholdStreamElement, Ps::VirtualAllocator> ThresholdArray; + +class ThresholdStream : public ThresholdArray +{ +public: + ThresholdStream(Ps::VirtualAllocatorCallback& allocatorCallback) : ThresholdArray(Ps::VirtualAllocator(&allocatorCallback)) + { + } + +}; + +class ThresholdTable +{ +public: + + ThresholdTable() + : mBuffer(NULL), + mHash(NULL), + mHashSize(0), + mHashCapactiy(0), + mPairs(NULL), + mNexts(NULL), + mPairsSize(0), + mPairsCapacity(0) + { + } + + ~ThresholdTable() + { + if(mBuffer) PX_FREE(mBuffer); + } + + void build(const ThresholdStream& stream); + + bool check(const ThresholdStream& stream, const PxU32 nodexIndexA, const PxU32 nodexIndexB, PxReal dt); + + bool check(const ThresholdStream& stream, const ThresholdStreamElement& elem, PxU32& thresholdIndex); + +//private: + + static const PxU32 NO_INDEX = 0xffffffff; + + struct Pair + { + PxU32 thresholdStreamIndex; + PxReal accumulatedForce; + //PxU32 next; // hash key & next ptr + }; + + PxU8* mBuffer; + + PxU32* mHash; + PxU32 mHashSize; + PxU32 mHashCapactiy; + + Pair* mPairs; + PxU32* mNexts; + PxU32 mPairsSize; + PxU32 mPairsCapacity; +}; + +namespace +{ + static PX_FORCE_INLINE PxU32 computeHashKey(const PxU32 nodeIndexA, const PxU32 nodeIndexB, const PxU32 hashCapacity) + { + return (Ps::hash(PxU64(nodeIndexA)<<32 | PxU64(nodeIndexB)) % hashCapacity); + } +} + +inline bool ThresholdTable::check(const ThresholdStream& stream, const ThresholdStreamElement& elem, PxU32& thresholdIndex) +{ + PxU32* PX_RESTRICT hashes = mHash; + PxU32* PX_RESTRICT nextIndices = mNexts; + Pair* PX_RESTRICT pairs = mPairs; + + PX_ASSERT(elem.nodeIndexA < elem.nodeIndexB); + PxU32 hashKey = computeHashKey(elem.nodeIndexA, elem.nodeIndexB, mHashSize); + + PxU32 pairIndex = hashes[hashKey]; + + while(NO_INDEX != pairIndex) + { + Pair& pair = pairs[pairIndex]; + const PxU32 thresholdStreamIndex = pair.thresholdStreamIndex; + PX_ASSERT(thresholdStreamIndex < stream.size()); + const ThresholdStreamElement& otherElement = stream[thresholdStreamIndex]; + if(otherElement.nodeIndexA==elem.nodeIndexA && otherElement.nodeIndexB==elem.nodeIndexB && otherElement.shapeInteraction == elem.shapeInteraction) + { + thresholdIndex = thresholdStreamIndex; + return true; + } + pairIndex = nextIndices[pairIndex]; + } + + thresholdIndex = NO_INDEX; + return false; +} + + +inline void ThresholdTable::build(const ThresholdStream& stream) +{ + //Handle the case of an empty stream. + if(0==stream.size()) + { + mPairsSize=0; + mPairsCapacity=0; + mHashSize=0; + mHashCapactiy=0; + if(mBuffer) PX_FREE(mBuffer); + mBuffer = NULL; + return; + } + + //Realloc/resize if necessary. + const PxU32 pairsCapacity = stream.size(); + const PxU32 hashCapacity = pairsCapacity*2+1; + if((pairsCapacity > mPairsCapacity) || (pairsCapacity < (mPairsCapacity >> 2))) + { + if(mBuffer) PX_FREE(mBuffer); + const PxU32 pairsByteSize = sizeof(Pair)*pairsCapacity; + const PxU32 nextsByteSize = sizeof(PxU32)*pairsCapacity; + const PxU32 hashByteSize = sizeof(PxU32)*hashCapacity; + const PxU32 totalByteSize = pairsByteSize + nextsByteSize + hashByteSize; + mBuffer = reinterpret_cast<PxU8*>(PX_ALLOC(totalByteSize, "PxThresholdStream")); + + PxU32 offset = 0; + mPairs = reinterpret_cast<Pair*>(mBuffer + offset); + offset += pairsByteSize; + mNexts = reinterpret_cast<PxU32*>(mBuffer + offset); + offset += nextsByteSize; + mHash = reinterpret_cast<PxU32*>(mBuffer + offset); + offset += hashByteSize; + PX_ASSERT(totalByteSize == offset); + + mPairsCapacity = pairsCapacity; + mHashCapactiy = hashCapacity; + } + + + //Set each entry of the hash table to 0xffffffff + PxMemSet(mHash, 0xff, sizeof(PxU32)*hashCapacity); + + //Init the sizes of the pairs array and hash array. + mPairsSize = 0; + mHashSize = hashCapacity; + + PxU32* PX_RESTRICT hashes = mHash; + PxU32* PX_RESTRICT nextIndices = mNexts; + Pair* PX_RESTRICT pairs = mPairs; + + //Add all the pairs from the stream. + PxU32 pairsSize = 0; + for(PxU32 i = 0; i < pairsCapacity; i++) + { + const ThresholdStreamElement& element = stream[i]; + const PxU32 nodeIndexA = element.nodeIndexA; + const PxU32 nodeIndexB = element.nodeIndexB; + + const PxF32 force = element.normalForce; + + PX_ASSERT(nodeIndexA < nodeIndexB); + + const PxU32 hashKey = computeHashKey(nodeIndexA, nodeIndexB, hashCapacity); + + //Get the index of the first pair found that resulted in a hash that matched hashKey. + PxU32 prevPairIndex = hashKey; + PxU32 pairIndex = hashes[hashKey]; + + //Search through all pairs found that resulted in a hash that matched hashKey. + //Search until the exact same body pair is found. + //Increment the accumulated force if the exact same body pair is found. + while(NO_INDEX != pairIndex) + { + Pair& pair = pairs[pairIndex]; + const PxU32 thresholdStreamIndex = pair.thresholdStreamIndex; + PX_ASSERT(thresholdStreamIndex < stream.size()); + const ThresholdStreamElement& otherElement = stream[thresholdStreamIndex]; + if(nodeIndexA == otherElement.nodeIndexA && nodeIndexB==otherElement.nodeIndexB) + { + pair.accumulatedForce += force; + prevPairIndex = NO_INDEX; + pairIndex = NO_INDEX; + break; + } + prevPairIndex = pairIndex; + pairIndex = nextIndices[pairIndex]; + } + + if(NO_INDEX != prevPairIndex) + { + nextIndices[pairsSize] = hashes[hashKey]; + hashes[hashKey] = pairsSize; + Pair& newPair = pairs[pairsSize]; + newPair.thresholdStreamIndex = i; + newPair.accumulatedForce = force; + pairsSize++; + } + } + mPairsSize = pairsSize; +} + +} + +} + +#endif //DY_THRESHOLDTABLE_H |