Bullet Collision Detection & Physics Library: btSequentialImpulseConstraintSolverMt.h Source File

Bullet Collision Detection & Physics Library

btSequentialImpulseConstraintSolverMt.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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
19#include "btSequentialImpulseConstraintSolver.h"
20#include "btBatchedConstraints.h"
21#include "LinearMath/btThreads.h"
22
56 ATTRIBUTE_ALIGNED16(class)
57 btSequentialImpulseConstraintSolverMt : public btSequentialImpulseConstraintSolver
58{
59public:
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
66 struct btContactManifoldCachedInfo
67 {
68 static const int MAX_NUM_CONTACT_POINTS = 4;
69
70 int numTouchingContacts;
71 int solverBodyIds[2];
72 int contactIndex;
73 int rollingFrictionIndex;
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 {
80 int m_solverConstraint;
81 int m_solverBodyA;
82 int m_solverBodyB;
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
90 static btBatchedConstraints::BatchingMethod s_contactBatchingMethod;
91 static btBatchedConstraints::BatchingMethod s_jointBatchingMethod;
92 static int s_minBatchSize; // desired number of constraints per batch
93 static int s_maxBatchSize;
94
95protected:
96 static const int CACHE_LINE_SIZE = 64;
97
98 btBatchedConstraints m_batchedContactConstraints;
99 btBatchedConstraints m_batchedJointConstraints;
100 int m_numFrictionDirections;
101 bool m_useBatching;
102 bool m_useObsoleteJointConstraints;
103 btAlignedObjectArray<btContactManifoldCachedInfo> m_manifoldCachedInfoArray;
104 btAlignedObjectArray<int> m_rollingFrictionIndexTable; // lookup table mapping contact index to rolling friction index
105 btSpinMutex m_bodySolverArrayMutex;
106 char m_antiFalseSharingPadding[CACHE_LINE_SIZE]; // padding to keep mutexes in separate cachelines
107 btSpinMutex m_kinematicBodyUniqueIdToSolverBodyTableMutex;
108 btAlignedObjectArray<char> m_scratchMemory;
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
128public:
129 BT_DECLARE_ALIGNED_ALLOCATOR();
130
131 btSequentialImpulseConstraintSolverMt();
132 virtual ~btSequentialImpulseConstraintSolverMt();
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
btBatchedConstraints.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
btSequentialImpulseConstraintSolver.h
btThreads.h
BT_OVERRIDE
#define BT_OVERRIDE
Definition: btThreads.h:26
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:46
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:51
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
btManifoldPoint
ManifoldContactPoint collects and maintains persistent contactpoints.
Definition: btManifoldPoint.h:52
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:65
btSequentialImpulseConstraintSolverMt
btSequentialImpulseConstraintSolverMt
Definition: btSequentialImpulseConstraintSolverMt.h:58
btSequentialImpulseConstraintSolverMt::m_batchedJointConstraints
btBatchedConstraints m_batchedJointConstraints
Definition: btSequentialImpulseConstraintSolverMt.h:99
btSequentialImpulseConstraintSolverMt::m_kinematicBodyUniqueIdToSolverBodyTableMutex
btSpinMutex m_kinematicBodyUniqueIdToSolverBodyTableMutex
Definition: btSequentialImpulseConstraintSolverMt.h:107
btSequentialImpulseConstraintSolverMt::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btSequentialImpulseConstraintSolverMt::m_rollingFrictionIndexTable
btAlignedObjectArray< int > m_rollingFrictionIndexTable
Definition: btSequentialImpulseConstraintSolverMt.h:104
btSequentialImpulseConstraintSolverMt::s_contactBatchingMethod
static btBatchedConstraints::BatchingMethod s_contactBatchingMethod
Definition: btSequentialImpulseConstraintSolverMt.h:90
btSequentialImpulseConstraintSolverMt::m_numFrictionDirections
int m_numFrictionDirections
Definition: btSequentialImpulseConstraintSolverMt.h:100
btSequentialImpulseConstraintSolverMt::m_batchedContactConstraints
btBatchedConstraints m_batchedContactConstraints
Definition: btSequentialImpulseConstraintSolverMt.h:98
btSequentialImpulseConstraintSolverMt::m_useBatching
bool m_useBatching
Definition: btSequentialImpulseConstraintSolverMt.h:101
btSequentialImpulseConstraintSolverMt::m_scratchMemory
btAlignedObjectArray< char > m_scratchMemory
Definition: btSequentialImpulseConstraintSolverMt.h:108
btSequentialImpulseConstraintSolverMt::s_allowNestedParallelForLoops
static bool s_allowNestedParallelForLoops
Definition: btSequentialImpulseConstraintSolverMt.h:88
btSequentialImpulseConstraintSolverMt::s_minBatchSize
static int s_minBatchSize
Definition: btSequentialImpulseConstraintSolverMt.h:92
btSequentialImpulseConstraintSolverMt::m_bodySolverArrayMutex
btSpinMutex m_bodySolverArrayMutex
Definition: btSequentialImpulseConstraintSolverMt.h:105
btSequentialImpulseConstraintSolverMt::s_maxBatchSize
static int s_maxBatchSize
Definition: btSequentialImpulseConstraintSolverMt.h:93
btSequentialImpulseConstraintSolverMt::m_useObsoleteJointConstraints
bool m_useObsoleteJointConstraints
Definition: btSequentialImpulseConstraintSolverMt.h:102
btSequentialImpulseConstraintSolverMt::s_minimumContactManifoldsForBatching
static int s_minimumContactManifoldsForBatching
Definition: btSequentialImpulseConstraintSolverMt.h:89
btSequentialImpulseConstraintSolverMt::m_manifoldCachedInfoArray
btAlignedObjectArray< btContactManifoldCachedInfo > m_manifoldCachedInfoArray
Definition: btSequentialImpulseConstraintSolverMt.h:103
btSequentialImpulseConstraintSolverMt::s_jointBatchingMethod
static btBatchedConstraints::BatchingMethod s_jointBatchingMethod
Definition: btSequentialImpulseConstraintSolverMt.h:91
btSequentialImpulseConstraintSolver
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
Definition: btSequentialImpulseConstraintSolver.h:52
btSpinMutex
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep becaus...
Definition: btThreads.h:46
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:76
btBatchedConstraints
Definition: btBatchedConstraints.h:27
btBatchedConstraints::BatchingMethod
BatchingMethod
Definition: btBatchedConstraints.h:29
btContactSolverInfo
Definition: btContactSolverInfo.h:76
btSequentialImpulseConstraintSolverMt::JointParams
Definition: btSequentialImpulseConstraintSolverMt.h:79
btSequentialImpulseConstraintSolverMt::JointParams::m_solverBodyA
int m_solverBodyA
Definition: btSequentialImpulseConstraintSolverMt.h:81
btSequentialImpulseConstraintSolverMt::JointParams::m_solverConstraint
int m_solverConstraint
Definition: btSequentialImpulseConstraintSolverMt.h:80
btSequentialImpulseConstraintSolverMt::JointParams::m_solverBodyB
int m_solverBodyB
Definition: btSequentialImpulseConstraintSolverMt.h:82
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo
Definition: btSequentialImpulseConstraintSolverMt.h:67
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo::rollingFrictionIndex
int rollingFrictionIndex
Definition: btSequentialImpulseConstraintSolverMt.h:73
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo::numTouchingContacts
int numTouchingContacts
Definition: btSequentialImpulseConstraintSolverMt.h:70
btSequentialImpulseConstraintSolverMt::btContactManifoldCachedInfo::contactIndex
int contactIndex
Definition: btSequentialImpulseConstraintSolverMt.h:72