parallel solver: slightly overallocate to reduce how often allocation is needed
This commit is contained in:
@@ -892,6 +892,12 @@ static void setupSpatialGridBatchesMt(
|
|||||||
memHelper.addChunk( (void**) &constraintBatchIds, sizeof( int ) * numConstraints );
|
memHelper.addChunk( (void**) &constraintBatchIds, sizeof( int ) * numConstraints );
|
||||||
memHelper.addChunk( (void**) &constraintRowBatchIds, sizeof( int ) * numConstraintRows );
|
memHelper.addChunk( (void**) &constraintRowBatchIds, sizeof( int ) * numConstraintRows );
|
||||||
size_t scratchSize = memHelper.getSizeToAllocate();
|
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 );
|
scratchMemory->resizeNoInitialize( scratchSize );
|
||||||
char* memPtr = &scratchMemory->at(0);
|
char* memPtr = &scratchMemory->at(0);
|
||||||
memHelper.setChunkPointers( memPtr );
|
memHelper.setChunkPointers( memPtr );
|
||||||
|
|||||||
@@ -568,10 +568,22 @@ void btSequentialImpulseConstraintSolverMt::allocAllContactConstraints(btPersist
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_tmpSolverContactConstraintPool.resizeNoInitialize(numContacts);
|
{
|
||||||
m_rollingFrictionIndexTable.resizeNoInitialize(numContacts);
|
BT_PROFILE( "allocPools" );
|
||||||
m_tmpSolverContactFrictionConstraintPool.resizeNoInitialize(numContacts*m_numFrictionDirections);
|
if ( m_tmpSolverContactConstraintPool.capacity() < numContacts )
|
||||||
m_tmpSolverContactRollingFrictionConstraintPool.resizeNoInitialize(numRollingFrictionConstraints);
|
{
|
||||||
|
// 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]);
|
AllocContactConstraintsLoop loop(this, &cachedInfoArray[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user