Skip to content

Commit

Permalink
MLCP solver: make it threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
lunkhound committed May 28, 2015
1 parent 670d0b3 commit 2b583fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/BulletDynamics/MLCPSolvers/btMLCPSolver.cpp
Expand Up @@ -216,12 +216,12 @@ void btMLCPSolver::createMLCPFast(const btContactSolverInfo& infoGlobal)
jointNodeArray.reserve(2*m_allConstraintPtrArray.size());
}

static btMatrixXu J3;
btMatrixXu& J3 = m_scratchJ3;
{
BT_PROFILE("J3.resize");
J3.resize(2*m,8);
}
static btMatrixXu JinvM3;
btMatrixXu& JinvM3 = m_scratchJInvM3;
{
BT_PROFILE("JinvM3.resize/setZero");

Expand All @@ -231,7 +231,7 @@ void btMLCPSolver::createMLCPFast(const btContactSolverInfo& infoGlobal)
}
int cur=0;
int rowOffset = 0;
static btAlignedObjectArray<int> ofs;
btAlignedObjectArray<int>& ofs = m_scratchOfs;
{
BT_PROFILE("ofs resize");
ofs.resize(0);
Expand Down Expand Up @@ -490,7 +490,7 @@ void btMLCPSolver::createMLCP(const btContactSolverInfo& infoGlobal)
}
}

static btMatrixXu Minv;
btMatrixXu& Minv = m_scratchMInv;
Minv.resize(6*numBodies,6*numBodies);
Minv.setZero();
for (int i=0;i<numBodies;i++)
Expand All @@ -507,7 +507,7 @@ void btMLCPSolver::createMLCP(const btContactSolverInfo& infoGlobal)
setElem(Minv,i*6+3+r,i*6+3+c,orgBody? orgBody->getInvInertiaTensorWorld()[r][c] : 0);
}

static btMatrixXu J;
btMatrixXu& J = m_scratchJ;
J.resize(numConstraintRows,6*numBodies);
J.setZero();

Expand Down Expand Up @@ -542,10 +542,10 @@ void btMLCPSolver::createMLCP(const btContactSolverInfo& infoGlobal)
}
}

static btMatrixXu J_transpose;
btMatrixXu& J_transpose = m_scratchJTranspose;
J_transpose= J.transpose();

static btMatrixXu tmp;
btMatrixXu& tmp = m_scratchTmp;

{
{
Expand Down
11 changes: 11 additions & 0 deletions src/BulletDynamics/MLCPSolvers/btMLCPSolver.h
Expand Up @@ -44,6 +44,17 @@ class btMLCPSolver : public btSequentialImpulseConstraintSolver
int m_fallback;
btScalar m_cfm;

/// The following scratch variables are not stateful -- contents are cleared prior to each use.
/// They are only cached here to avoid extra memory allocations and deallocations and to ensure
/// that multiple instances of the solver can be run in parallel.
btMatrixXu m_scratchJ3;
btMatrixXu m_scratchJInvM3;
btAlignedObjectArray<int> m_scratchOfs;
btMatrixXu m_scratchMInv;
btMatrixXu m_scratchJ;
btMatrixXu m_scratchJTranspose;
btMatrixXu m_scratchTmp;

virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);

Expand Down

0 comments on commit 2b583fc

Please sign in to comment.