Bullet Collision Detection & Physics Library
btSequentialImpulseConstraintSolverMt.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
17 #define BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
18 
20 #include "btBatchedConstraints.h"
21 #include "LinearMath/btThreads.h"
22 
58 {
59 public:
60  virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) BT_OVERRIDE;
61  virtual btScalar solveSingleIteration(int iteration, btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) BT_OVERRIDE;
62  virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) BT_OVERRIDE;
63  virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
64 
65  // temp struct used to collect info from persistent manifolds into a cache-friendly struct using multiple threads
67  {
68  static const int MAX_NUM_CONTACT_POINTS = 4;
69 
71  int solverBodyIds[2];
74  bool contactHasRollingFriction[MAX_NUM_CONTACT_POINTS];
75  btManifoldPoint* contactPoints[MAX_NUM_CONTACT_POINTS];
76  };
77  // temp struct used for setting up joint constraints in parallel
78  struct JointParams
79  {
83  };
84  void internalInitMultipleJoints(btTypedConstraint * *constraints, int iBegin, int iEnd);
85  void internalConvertMultipleJoints(const btAlignedObjectArray<JointParams>& jointParamsArray, btTypedConstraint** constraints, int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
86 
87  // parameters to control batching
88  static bool s_allowNestedParallelForLoops; // whether to allow nested parallel operations
89  static int s_minimumContactManifoldsForBatching; // don't even try to batch if fewer manifolds than this
92  static int s_minBatchSize; // desired number of constraints per batch
93  static int s_maxBatchSize;
94 
95 protected:
96  static const int CACHE_LINE_SIZE = 64;
97 
104  btAlignedObjectArray<int> m_rollingFrictionIndexTable; // lookup table mapping contact index to rolling friction index
106  char m_antiFalseSharingPadding[CACHE_LINE_SIZE]; // padding to keep mutexes in separate cachelines
109 
110  virtual void randomizeConstraintOrdering(int iteration, int numIterations);
111  virtual btScalar resolveAllJointConstraints(int iteration);
112  virtual btScalar resolveAllContactConstraints();
113  virtual btScalar resolveAllContactFrictionConstraints();
114  virtual btScalar resolveAllContactConstraintsInterleaved();
115  virtual btScalar resolveAllRollingFrictionConstraints();
116 
117  virtual void setupBatchedContactConstraints();
118  virtual void setupBatchedJointConstraints();
119  virtual void convertJoints(btTypedConstraint * *constraints, int numConstraints, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
120  virtual void convertContacts(btPersistentManifold * *manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
121  virtual void convertBodies(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal) BT_OVERRIDE;
122 
123  int getOrInitSolverBodyThreadsafe(btCollisionObject & body, btScalar timeStep);
124  void allocAllContactConstraints(btPersistentManifold * *manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
125  void setupAllContactConstraints(const btContactSolverInfo& infoGlobal);
126  void randomizeBatchedConstraintOrdering(btBatchedConstraints * batchedConstraints);
127 
128 public:
130 
133 
134  btScalar resolveMultipleJointConstraints(const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd, int iteration);
135  btScalar resolveMultipleContactConstraints(const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd);
136  btScalar resolveMultipleContactSplitPenetrationImpulseConstraints(const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd);
137  btScalar resolveMultipleContactFrictionConstraints(const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd);
138  btScalar resolveMultipleContactRollingFrictionConstraints(const btAlignedObjectArray<int>& consIndices, int batchBegin, int batchEnd);
139  btScalar resolveMultipleContactConstraintsInterleaved(const btAlignedObjectArray<int>& contactIndices, int batchBegin, int batchEnd);
140 
141  void internalCollectContactManifoldCachedInfo(btContactManifoldCachedInfo * cachedInfoArray, btPersistentManifold * *manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
142  void internalAllocContactConstraints(const btContactManifoldCachedInfo* cachedInfoArray, int numManifolds);
143  void internalSetupContactConstraints(int iContactConstraint, const btContactSolverInfo& infoGlobal);
144  void internalConvertBodies(btCollisionObject * *bodies, int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
145  void internalWriteBackContacts(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
146  void internalWriteBackJoints(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
147  void internalWriteBackBodies(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
148 };
149 
150 #endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_MT_H
btSequentialImpulseConstraintSolverMt::m_numFrictionDirections
int m_numFrictionDirections
Definition: btSequentialImpulseConstraintSolverMt.h:100
btSequentialImpulseConstraintSolverMt::s_allowNestedParallelForLoops
static bool s_allowNestedParallelForLoops
Definition: btSequentialImpulseConstraintSolverMt.h:88
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:74
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:48
btSequentialImpulseConstraintSolverMt::m_rollingFrictionIndexTable
btAlignedObjectArray< int > m_rollingFrictionIndexTable
Definition: btSequentialImpulseConstraintSolverMt.h:104
btSequentialImpulseConstraintSolverMt::m_batchedJointConstraints
btBatchedConstraints m_batchedJointConstraints
Definition: btSequentialImpulseConstraintSolverMt.h:99
btContactSolverInfo
Definition: btContactSolverInfo.h:69
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:294
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo::numTouchingContacts
int numTouchingContacts
Definition: btSequentialImpulseConstraintSolverMt.h:70
BT_OVERRIDE
#define BT_OVERRIDE
Definition: btThreads.h:26
btSequentialImpulseConstraintSolverMt::m_batchedContactConstraints
btBatchedConstraints m_batchedContactConstraints
Definition: btSequentialImpulseConstraintSolverMt.h:98
btSequentialImpulseConstraintSolverMt
btSequentialImpulseConstraintSolverMt
Definition: btSequentialImpulseConstraintSolverMt.h:56
btSequentialImpulseConstraintSolverMt::JointParams::m_solverConstraint
int m_solverConstraint
Definition: btSequentialImpulseConstraintSolverMt.h:80
btThreads.h
btSequentialImpulseConstraintSolverMt::JointParams
Definition: btSequentialImpulseConstraintSolverMt.h:78
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo::rollingFrictionIndex
int rollingFrictionIndex
Definition: btSequentialImpulseConstraintSolverMt.h:73
btSequentialImpulseConstraintSolverMt::JointParams::m_solverBodyB
int m_solverBodyB
Definition: btSequentialImpulseConstraintSolverMt.h:82
btSequentialImpulseConstraintSolverMt::JointParams::m_solverBodyA
int m_solverBodyA
Definition: btSequentialImpulseConstraintSolverMt.h:81
btSequentialImpulseConstraintSolverMt::s_minBatchSize
static int s_minBatchSize
Definition: btSequentialImpulseConstraintSolverMt.h:92
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:26
btManifoldPoint
ManifoldContactPoint collects and maintains persistent contactpoints.
Definition: btManifoldPoint.h:51
btBatchedConstraints.h
btSequentialImpulseConstraintSolverMt::m_scratchMemory
btAlignedObjectArray< char > m_scratchMemory
Definition: btSequentialImpulseConstraintSolverMt.h:108
btSequentialImpulseConstraintSolverMt::m_manifoldCachedInfoArray
btAlignedObjectArray< btContactManifoldCachedInfo > m_manifoldCachedInfoArray
Definition: btSequentialImpulseConstraintSolverMt.h:103
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo::contactIndex
int contactIndex
Definition: btSequentialImpulseConstraintSolverMt.h:72
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo
Definition: btSequentialImpulseConstraintSolverMt.h:66
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:405
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:63
btSequentialImpulseConstraintSolverMt::m_bodySolverArrayMutex
btSpinMutex m_bodySolverArrayMutex
Definition: btSequentialImpulseConstraintSolverMt.h:105
btBatchedConstraints
Definition: btBatchedConstraints.h:26
btSequentialImpulseConstraintSolverMt::m_kinematicBodyUniqueIdToSolverBodyTableMutex
btSpinMutex m_kinematicBodyUniqueIdToSolverBodyTableMutex
Definition: btSequentialImpulseConstraintSolverMt.h:107
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:84
btSequentialImpulseConstraintSolverMt::m_useBatching
bool m_useBatching
Definition: btSequentialImpulseConstraintSolverMt.h:101
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:52
btSequentialImpulseConstraintSolver.h
btSequentialImpulseConstraintSolver
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
Definition: btSequentialImpulseConstraintSolver.h:33
btSpinMutex
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep becaus...
Definition: btThreads.h:45
btSequentialImpulseConstraintSolverMt::m_useObsoleteJointConstraints
bool m_useObsoleteJointConstraints
Definition: btSequentialImpulseConstraintSolverMt.h:102
btSequentialImpulseConstraintSolverMt::s_maxBatchSize
static int s_maxBatchSize
Definition: btSequentialImpulseConstraintSolverMt.h:93
btSequentialImpulseConstraintSolverMt::s_contactBatchingMethod
static btBatchedConstraints::BatchingMethod s_contactBatchingMethod
Definition: btSequentialImpulseConstraintSolverMt.h:90
btSequentialImpulseConstraintSolverMt::s_minimumContactManifoldsForBatching
static int s_minimumContactManifoldsForBatching
Definition: btSequentialImpulseConstraintSolverMt.h:89
btSequentialImpulseConstraintSolverMt::s_jointBatchingMethod
static btBatchedConstraints::BatchingMethod s_jointBatchingMethod
Definition: btSequentialImpulseConstraintSolverMt.h:91
btBatchedConstraints::BatchingMethod
BatchingMethod
Definition: btBatchedConstraints.h:28