RavEngine
Loading...
Searching...
No Matches
DyDynamics.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef DY_DYNAMICS_H
30#define DY_DYNAMICS_H
31
32#include "PxvConfig.h"
33#include "CmSpatialVector.h"
34#include "CmTask.h"
35#include "CmPool.h"
36#include "PxcThreadCoherentCache.h"
37#include "DyThreadContext.h"
38#include "PxcConstraintBlockStream.h"
39#include "DySolverBody.h"
40#include "DyContext.h"
41#include "PxsIslandManagerTypes.h"
42#include "PxvNphaseImplementationContext.h"
43#include "solver/PxSolverDefs.h"
44
45namespace physx
46{
47
48namespace Cm
49{
50 class FlushPool;
51}
52
53namespace IG
54{
55 class SimpleIslandManager;
56 struct Edge;
57}
58
59class PxsRigidBody;
60
61struct PxsBodyCore;
62class PxsIslandIndices;
63struct PxsIndexedInteraction;
64struct PxsIndexedContactManager;
65struct PxSolverConstraintDesc;
66
67namespace Cm
68{
69 class SpatialVector;
70}
71
72namespace Dy
73{
74 class SolverCore;
75 struct SolverIslandParams;
76 struct ArticulationSolverDesc;
77 class Articulation;
78 class DynamicsContext;
79
80
81
82
83#define SOLVER_PARALLEL_METHOD_ARGS \
84 DynamicsContext& context, \
85 SolverIslandParams& params, \
86 IG::IslandSim& islandSim
87
88//typedef void (*PxsSolveParallelMethod)(SOLVER_PARALLEL_METHOD_ARGS);
89//extern PxsSolveParallelMethod solveParallel[3];
90
91void solveParallel(SOLVER_PARALLEL_METHOD_ARGS);
92void solveParallelCouloumFriction(SOLVER_PARALLEL_METHOD_ARGS);
93
94
95struct SolverIslandObjects;
96
101class SolverBodyPool : public PxArray<PxSolverBody, PxAlignedAllocator<128, PxReflectionAllocator<PxSolverBody> > >
102{
103 PX_NOCOPY(SolverBodyPool)
104public:
105 SolverBodyPool() {}
106};
107
112class SolverBodyDataPool : public PxArray<PxSolverBodyData, PxAlignedAllocator<128, PxReflectionAllocator<PxSolverBodyData> > >
113{
114 PX_NOCOPY(SolverBodyDataPool)
115public:
117};
118
119class SolverConstraintDescPool : public PxArray<PxSolverConstraintDesc, PxAlignedAllocator<128, PxReflectionAllocator<PxSolverConstraintDesc> > >
120{
121 PX_NOCOPY(SolverConstraintDescPool)
122public:
124};
125
131{
132 //The thread context for this island (set in in the island start task, released in the island end task)
133 ThreadContext* mThreadContext;
134 PxsIslandIndices mCounts;
135};
136
137
142#if PX_VC
143 #pragma warning(push)
144 #pragma warning( disable : 4324 ) // Padding was added at the end of a structure because of a __declspec(align) value.
145#endif
146
147
149{
150 PX_NOCOPY(DynamicsContext)
151public:
152
157 static DynamicsContext* create( PxcNpMemBlockPool* memBlockPool,
158 PxcScratchAllocator& scratchAllocator,
159 Cm::FlushPool& taskPool,
160 PxvSimStats& simStats,
161 PxTaskManager* taskManager,
163 PxsMaterialManager* materialManager,
164 IG::SimpleIslandManager* islandManager,
165 PxU64 contextID,
166 const bool enableStabilization,
167 const bool useEnhancedDeterminism,
168 const PxReal maxBiasCoefficient,
169 const bool frictionEveryIteration,
170 const PxReal lengthScale
171 );
172
176 void destroy();
177
182 PX_FORCE_INLINE PxSolverBody& getWorldSolverBody() { return mWorldSolverBody; }
183
184 PX_FORCE_INLINE Cm::FlushPool& getTaskPool() { return mTaskPool; }
185
186 PX_FORCE_INLINE ThresholdStream& getThresholdStream() { return *mThresholdStream; }
187
188 PX_FORCE_INLINE PxvSimStats& getSimStats() { return mSimStats; }
189
190#if PX_ENABLE_SIM_STATS
191 void addThreadStats(const ThreadContext::ThreadSimStats& stats);
192#else
193 PX_CATCH_UNDEFINED_ENABLE_SIM_STATS
194#endif
195
210 virtual void update(IG::SimpleIslandManager& simpleIslandManager, PxBaseTask* continuation, PxBaseTask* lostTouchTask,
211 PxvNphaseImplementationContext* nPhase, const PxU32 maxPatchesPerCM, const PxU32 maxArticulationLinks, const PxReal dt, const PxVec3& gravity, PxBitMapPinned& changedHandleMap);
212
213
214 void updatePostKinematic(IG::SimpleIslandManager& simpleIslandManager, PxBaseTask* continuation, PxBaseTask* lostTouchTask, const PxU32 maxLinks);
215
216 virtual void processLostPatches(IG::SimpleIslandManager& /*simpleIslandManager*/, PxsContactManager** /*lostPatchManagers*/, PxU32 /*nbLostPatchManagers*/, PxsContactManagerOutputCounts* /*outCounts*/){}
217 virtual void processFoundPatches(IG::SimpleIslandManager& /*simpleIslandManager*/, PxsContactManager** /*foundPatchManagers*/, PxU32 /*nbFoundPatchManagers*/, PxsContactManagerOutputCounts* /*outCounts*/) {}
218
219 virtual void updateBodyCore(PxBaseTask* continuation);
220
221 virtual void setSimulationController(PxsSimulationController* simulationController ){ mSimulationController = simulationController; }
225 virtual void mergeResults();
226
227 virtual void getDataStreamBase(void*& /*contactStreamBase*/, void*& /*patchStreamBase*/, void*& /*forceAndIndicesStreamBase*/){}
228
229 virtual PxSolverType::Enum getSolverType() const { return PxSolverType::ePGS; }
230
239
248
249
250 PX_FORCE_INLINE PxU32 getKinematicCount() const { return mKinematicCount; }
251 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
252
253protected:
254
258 DynamicsContext(PxcNpMemBlockPool* memBlockPool,
259 PxcScratchAllocator& scratchAllocator,
260 Cm::FlushPool& taskPool,
261 PxvSimStats& simStats,
262 PxTaskManager* taskManager,
263 PxVirtualAllocatorCallback* allocator,
264 PxsMaterialManager* materialManager,
265 IG::SimpleIslandManager* islandManager,
266 PxU64 contextID,
267 const bool enableStabilization,
268 const bool useEnhancedDeterminism,
269 const PxReal maxBiasCoefficient,
270 const bool frictionEveryIteration,
271 const PxReal lengthScale
272 );
276 virtual ~DynamicsContext();
277
278
279 // Solver helper-methods
285
291 void setDescFromIndices(PxSolverConstraintDesc& desc, const IG::IslandSim& islandSim,
292 const PxsIndexedInteraction& constraint, const PxU32 solverBodyOffset);
293
294
295 void setDescFromIndices(PxSolverConstraintDesc& desc, IG::EdgeIndex edgeIndex,
296 const IG::SimpleIslandManager& islandManager, PxU32* bodyRemapTable, const PxU32 solverBodyOffset);
297
313 const PxF32 dt,
314 PxsBodyCore*const* bodyArray, // INOUT: core body attributes
315 PxsRigidBody*const* originalBodyArray, // IN: original body atom names (LEGACY - DON'T deref the ptrs!!)
316 PxU32 const* nodeIndexArray, // IN: island node index
317 PxU32 bodyCount, // IN: body count
318 PxSolverBody* solverBodyPool, // IN: solver atom pool (space preallocated)
319 PxSolverBodyData* solverBodyDataPool,
320 Cm::SpatialVector* motionVelocityArray, // OUT: motion velocities
321 PxU32& maxSolverPositionIterations,
322 PxU32& maxSolverVelocityIterations,
323 PxBaseTask& integrateTask
324 );
325
333
334
335
336 void integrateCoreParallel(SolverIslandParams& params, Cm::SpatialVectorF* deltaV, IG::IslandSim& islandSim);
337
338
339
340
344 void resetThreadContexts();
345
351
352 //Data
353
357 PX_ALIGN(16, PxSolverBody mWorldSolverBody);
361 PX_ALIGN(16, PxSolverBodyData mWorldSolverBodyData);
362
367
372
377
382
387
392
397
402
407
416
417
418 ThresholdStream* mExceededForceThresholdStream[2]; //this store previous and current exceeded force thresholdStream
419
420 PxArray<PxU32> mExceededForceThresholdStreamMask;
421
427
428 PxArray<PxU32> mSolverBodyRemapTable; //Remaps from the "active island" index to the index within a solver island
429
430 PxArray<PxU32> mNodeIndexArray; //island node index
431
433
438
443
444
445
446 PxsMaterialManager* mMaterialManager;
447
448 PxsContactManagerOutputIterator mOutputIterator;
449
450private:
451 //private:
452 PxcScratchAllocator& mScratchAllocator;
453 Cm::FlushPool& mTaskPool;
454 PxTaskManager* mTaskManager;
455 PxU32 mCurrentIndex; // this is the index point to the current exceeded force threshold stream
456
457 PxU64 mContextID;
458
459 protected:
460
461 friend class PxsSolverStartTask;
462 friend class PxsSolverAticulationsTask;
463 friend class PxsSolverSetupConstraintsTask;
466 friend class PxsSolverSetupSolveTask;
467 friend class PxsSolverIntegrateTask;
468 friend class PxsSolverEndTask;
470 friend class PxsForceThresholdTask;
471 friend class SolverArticulationUpdateTask;
472
473 friend void solveParallel(SOLVER_PARALLEL_METHOD_ARGS);
474};
475
476#if PX_VC
477 #pragma warning(pop)
478#endif
479
480}
481}
482
483#endif
Definition base.h:1940
Definition CmFlushPool.h:49
Definition CmSpatialVector.h:46
Definition DyContext.h:76
Encapsules the data used by the constraint solver.
Definition DyDynamics.h:149
PX_FORCE_INLINE PxcScratchAllocator & getScratchAllocator()
Returns the scratch memory allocator.
Definition DyDynamics.h:350
void resetThreadContexts()
Resets the thread contexts.
Definition DyDynamics.cpp:146
SolverConstraintDescPool mSolverConstraintDescPool
Solver constraint desc array.
Definition DyDynamics.h:371
virtual void mergeResults()
This method combines the results of several islands, e.g. constructing scene-level simulation statist...
Definition DyDynamics.cpp:2384
SolverCore * mSolverCore[PxFrictionType::eFRICTION_COUNT]
Interface to the solver core.
Definition DyDynamics.h:426
PxArray< PxConstraintBatchHeader > mContactConstraintBatchHeaders
An array of contact constraint batch headers.
Definition DyDynamics.h:386
PxI32 mThresholdStreamOut
Atomic counter for the number of threshold stream elements.
Definition DyDynamics.h:442
void computeUnconstrainedVelocity(PxsRigidBody *atom) const
Computes the unconstrained velocity for a given PxsRigidBody.
PxArray< PxsBodyCore * > mBodyCoreArray
Array of body core pointers for all bodies in the scene.
Definition DyDynamics.h:396
virtual PX_CATCH_UNDEFINED_ENABLE_SIM_STATS void update(IG::SimpleIslandManager &simpleIslandManager, PxBaseTask *continuation, PxBaseTask *lostTouchTask, PxvNphaseImplementationContext *nPhase, const PxU32 maxPatchesPerCM, const PxU32 maxArticulationLinks, const PxReal dt, const PxVec3 &gravity, PxBitMapPinned &changedHandleMap)
The entry point for the constraint solver.
Definition DyDynamics.cpp:2107
virtual void updateBodyCore(PxBaseTask *continuation)
This method copy gpu solver body data to cpu body core.
Definition DyDynamics.cpp:2379
PX_ALIGN(16, PxSolverBody mWorldSolverBody)
Body to represent the world static body.
SolverConstraintDescPool mTempSolverConstraintDescPool
A temporary array of constraint descs used for partitioning.
Definition DyDynamics.h:381
PX_ALIGN(16, PxSolverBodyData mWorldSolverBodyData)
Body data to represent the world static body.
virtual ~DynamicsContext()
Destructor for DynamicsContext.
Definition DyDynamics.cpp:209
PxU32 mKinematicCount
The total number of kinematic bodies in the scene.
Definition DyDynamics.h:437
SolverBodyDataPool mSolverBodyDataPool
Global pool for solver body data. Kinematic bodies are at the start, and then dynamic bodies.
Definition DyDynamics.h:415
void setDescFromIndices(PxSolverConstraintDesc &desc, const IG::IslandSim &islandSim, const PxsIndexedInteraction &constraint, const PxU32 solverBodyOffset)
fills in a PxSolverConstraintDesc from an indexed interaction
Definition DyDynamics.cpp:234
void destroy()
Destroys this DynamicsContext.
Definition DyDynamics.cpp:140
void solveParallel(SolverIslandParams &params, IG::IslandSim &islandSim, Cm::SpatialVectorF *Z, Cm::SpatialVectorF *deltaV)
Solves an island in parallel.
Definition DyDynamics.cpp:2538
PxArray< FeatherstoneArticulation * > mArticulationArray
Array of articulation pointers for all articulations in the scene.
Definition DyDynamics.h:406
void preIntegrationParallel(const PxF32 dt, PxsBodyCore *const *bodyArray, PxsRigidBody *const *originalBodyArray, PxU32 const *nodeIndexArray, PxU32 bodyCount, PxSolverBody *solverBodyPool, PxSolverBodyData *solverBodyDataPool, Cm::SpatialVector *motionVelocityArray, PxU32 &maxSolverPositionIterations, PxU32 &maxSolverVelocityIterations, PxBaseTask &integrateTask)
Compute the unconstrained velocity for set of bodies in parallel. This function may spawn additional ...
Definition DyDynamics.cpp:2476
PxArray< PxsRigidBody * > mRigidBodyArray
Array of rigid body pointers for all bodies in the scene.
Definition DyDynamics.h:401
PX_FORCE_INLINE PxSolverBody & getWorldSolverBody()
Returns the static world solver body.
Definition DyDynamics.h:182
PxArray< Cm::SpatialVector > mMotionVelocityArray
Array of motion velocities for all bodies in the scene.
Definition DyDynamics.h:391
SolverConstraintDescPool mOrderedSolverConstraintDescPool
Ordered sover constraint desc array (after partitioning)
Definition DyDynamics.h:376
PX_FORCE_INLINE ThreadContext * getThreadContext()
Allocates and returns a thread context object.
Definition DyDynamics.h:235
SolverBodyPool mSolverBodyPool
Global pool for solver bodies. Kinematic bodies are at the start, and then dynamic bodies.
Definition DyDynamics.h:411
static DynamicsContext * create(PxcNpMemBlockPool *memBlockPool, PxcScratchAllocator &scratchAllocator, Cm::FlushPool &taskPool, PxvSimStats &simStats, PxTaskManager *taskManager, PxVirtualAllocatorCallback *allocator, PxsMaterialManager *materialManager, IG::SimpleIslandManager *islandManager, PxU64 contextID, const bool enableStabilization, const bool useEnhancedDeterminism, const PxReal maxBiasCoefficient, const bool frictionEveryIteration, const PxReal lengthScale)
Creates a DynamicsContext associated with a PxsContext.
Definition DyDynamics.cpp:114
void putThreadContext(ThreadContext *context)
Returns a thread context to the thread context pool.
Definition DyDynamics.h:244
PxcThreadCoherentCache< ThreadContext, PxcNpMemBlockPool > mThreadContextPool
A thread context pool.
Definition DyDynamics.h:366
Definition DyDynamics.cpp:611
Definition DyDynamics.cpp:1405
Definition DyDynamics.cpp:1861
Definition DyDynamics.cpp:1488
Definition DyDynamics.cpp:830
Definition DyDynamics.cpp:740
Solver body data pool (array) that enforces 128-byte alignment for base address of array.
Definition DyDynamics.h:113
Solver body pool (array) that enforces 128-byte alignment for base address of array.
Definition DyDynamics.h:102
Definition DyDynamics.h:120
Definition DySolverCore.h:217
Definition DyThreadContext.h:65
Definition DyThresholdTable.h:81
Definition PxsIslandSim.h:412
Definition PxsSimpleIslandManager.h:87
Definition PxArray.h:53
Base class of all task types.
Definition PxTask.h:45
The PxTaskManager interface.
Definition PxTaskManager.h:81
Definition PxAllocator.h:140
Definition PxcNpMemBlockPool.h:52
Definition PxcScratchAllocator.h:42
Definition PxcThreadCoherentCache.h:52
Definition PxvNphaseImplementationContext.h:81
Definition PxsIslandManagerTypes.h:78
Definition PxsMaterialManager.h:126
Definition PxsRigidBody.h:43
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition CmSpatialVector.h:134
Encapsulates an island's context.
Definition DyDynamics.h:131
Definition DySolverCore.h:155
@ eFRICTION_COUNT
The total number of friction models supported by the SDK.
Definition PxSceneDesc.h:75
Struct that the solver uses to store the state and other properties of a body.
Definition PxSolverDefs.h:74
Struct that the solver uses to store velocity updates for a body.
Definition PxSolverDefs.h:55
Constraint descriptor used inside the solver.
Definition PxSolverDefs.h:108
Enum
Definition PxSceneDesc.h:89
@ ePGS
Projected Gauss-Seidel iterative solver.
Definition PxSceneDesc.h:90
Definition PxvDynamics.h:74
Each contact manager or constraint references two separate bodies, where a body can be a dynamic rigi...
Definition PxsIslandManagerTypes.h:101
Definition PxvSimStats.h:52