parallel solver: slightly overallocate to reduce how often allocation is needed

This commit is contained in:
Lunkhound 2018-03-13 04:19:02 -07:00
parent eec478709a
commit e526e48df8
2 changed files with 22 additions and 4 deletions

View File

@ -892,6 +892,12 @@ static void setupSpatialGridBatchesMt(
memHelper.addChunk( (void**) &constraintBatchIds, sizeof( int ) * numConstraints );
memHelper.addChunk( (void**) &constraintRowBatchIds, sizeof( int ) * numConstraintRows );
size_t scratchSize = memHelper.getSizeToAllocate();
// if we need to reallocate
if (scratchMemory->capacity() < scratchSize)
{
// allocate 6.25% extra to avoid repeated reallocs
scratchMemory->reserve( scratchSize + scratchSize/16 );
}
scratchMemory->resizeNoInitialize( scratchSize );
char* memPtr = &scratchMemory->at(0);
memHelper.setChunkPointers( memPtr );

View File

@ -568,10 +568,22 @@ void btSequentialImpulseConstraintSolverMt::allocAllContactConstraints(btPersist
}
}
}
m_tmpSolverContactConstraintPool.resizeNoInitialize(numContacts);
m_rollingFrictionIndexTable.resizeNoInitialize(numContacts);
m_tmpSolverContactFrictionConstraintPool.resizeNoInitialize(numContacts*m_numFrictionDirections);
m_tmpSolverContactRollingFrictionConstraintPool.resizeNoInitialize(numRollingFrictionConstraints);
{
BT_PROFILE( "allocPools" );
if ( m_tmpSolverContactConstraintPool.capacity() < numContacts )
{
// if we need to reallocate, reserve some extra so we don't have to reallocate again next frame
int extraReserve = numContacts / 16;
m_tmpSolverContactConstraintPool.reserve( numContacts + extraReserve );
m_rollingFrictionIndexTable.reserve( numContacts + extraReserve );
m_tmpSolverContactFrictionConstraintPool.reserve( ( numContacts + extraReserve )*m_numFrictionDirections );
m_tmpSolverContactRollingFrictionConstraintPool.reserve( numRollingFrictionConstraints + extraReserve );
}
m_tmpSolverContactConstraintPool.resizeNoInitialize( numContacts );
m_rollingFrictionIndexTable.resizeNoInitialize( numContacts );
m_tmpSolverContactFrictionConstraintPool.resizeNoInitialize( numContacts*m_numFrictionDirections );
m_tmpSolverContactRollingFrictionConstraintPool.resizeNoInitialize( numRollingFrictionConstraints );
}
}
{
AllocContactConstraintsLoop loop(this, &cachedInfoArray[0]);