Tree perf (#179)
- Optimizations for falling trees. - Increased B3_MAX_MESH_CONTACT_TRIANGLES from 256 to 512.
This commit is contained in:
parent
e77352cd60
commit
16f7f4cf4c
36 changed files with 1926 additions and 1110 deletions
|
|
@ -19,27 +19,27 @@
|
|||
// Double precision accumulates body positions in double, so the settle/sleep step and the
|
||||
// state hash differ from the float build. Both modes are internally deterministic.
|
||||
#if defined( BOX3D_DOUBLE_PRECISION )
|
||||
#define RAGDOLL_SLEEP_STEP 273
|
||||
#define RAGDOLL_HASH 0x0F4DD1EB
|
||||
#define WAVE_PILE_SLEEP_STEP 314
|
||||
#define WAVE_PILE_HASH 0x03B509B6
|
||||
#define RAGDOLL_SLEEP_STEP 266
|
||||
#define RAGDOLL_HASH 0x68FC7728
|
||||
#define WAVE_PILE_SLEEP_STEP 312
|
||||
#define WAVE_PILE_HASH 0xFD6BD36B
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0x9B96A098
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0x5B4429DC
|
||||
#define MESH_DROP_SLEEP_STEP 217
|
||||
#define MESH_DROP_HASH 0xCF946437
|
||||
#define MESH_DROP_SLEEP_STEP 218
|
||||
#define MESH_DROP_HASH 0x26F9A566
|
||||
#else
|
||||
#define RAGDOLL_SLEEP_STEP 274
|
||||
#define RAGDOLL_HASH 0x773AB8ED
|
||||
#define WAVE_PILE_SLEEP_STEP 314
|
||||
#define WAVE_PILE_HASH 0x8CB8F656
|
||||
#define RAGDOLL_SLEEP_STEP 267
|
||||
#define RAGDOLL_HASH 0x9BCA269D
|
||||
#define WAVE_PILE_SLEEP_STEP 270
|
||||
#define WAVE_PILE_HASH 0xAD7C3901
|
||||
#define QUERY_SPAWN_SLEEP_STEP 242
|
||||
#define QUERY_SPAWN_HASH 0xF1EDEF47
|
||||
#define QUERY_SPAWN_HIT_COUNT 59
|
||||
#define QUERY_SPAWN_QUERY_HASH 0xE3271F3D
|
||||
#define MESH_DROP_SLEEP_STEP 217
|
||||
#define MESH_DROP_HASH 0x256BC40B
|
||||
#define MESH_DROP_SLEEP_STEP 218
|
||||
#define MESH_DROP_HASH 0x0A23CFA2
|
||||
#endif
|
||||
|
||||
// The goldens above pin exact values for the default four point manifold. A build that
|
||||
|
|
@ -436,6 +436,118 @@ static int SingleRollingMixTest( int workerCount, DeterminismResult* reference )
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Mesh contacts are grouped across lanes by manifold count and padded to the largest count in the group. Width 8 groups
|
||||
// differ from width 4 groups, so mixing large and small shapes on a fine mesh gives each body a width dependent number
|
||||
// of padded manifolds. The hash covers velocities and impulses bitwise to catch a padded manifold flipping a signed zero.
|
||||
static int SingleMeshMixTest( int workerCount, DeterminismResult* reference )
|
||||
{
|
||||
b3WorldDef worldDef = b3DefaultWorldDef();
|
||||
worldDef.workerCount = workerCount;
|
||||
b3WorldId worldId = b3CreateWorld( &worldDef );
|
||||
|
||||
b3MeshData* mesh = b3CreateWaveMesh( 40, 40, 0.5f, 0.3f, 0.2f, 0.3f );
|
||||
{
|
||||
b3BodyDef groundDef = b3DefaultBodyDef();
|
||||
groundDef.position = (b3Pos){ -10.0f, 0.0f, -10.0f };
|
||||
b3BodyId groundId = b3CreateBody( worldId, &groundDef );
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one );
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
rowCount = 8,
|
||||
columnCount = 8,
|
||||
bodyCount = rowCount * columnCount
|
||||
};
|
||||
|
||||
b3BodyId bodyIds[bodyCount];
|
||||
b3BoxHull smallBox = b3MakeBoxHull( 0.2f, 0.2f, 0.2f );
|
||||
b3BoxHull largeBox = b3MakeBoxHull( 0.9f, 0.3f, 0.9f );
|
||||
b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.3f };
|
||||
b3Capsule capsule = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, 0.2f };
|
||||
|
||||
uint32_t seed = 314159u;
|
||||
for ( int i = 0; i < bodyCount; ++i )
|
||||
{
|
||||
int row = i / columnCount;
|
||||
int column = i % columnCount;
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = (b3Pos){ 2.2f * (float)column - 7.7f, 1.2f, 2.2f * (float)row - 7.7f };
|
||||
bodyIds[i] = b3CreateBody( worldId, &bodyDef );
|
||||
|
||||
seed = seed * 1664525u + 1013904223u;
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.density = 1.0f;
|
||||
shapeDef.baseMaterial.rollingResistance = ( seed >> 28 ) < 5 ? 0.2f : 0.0f;
|
||||
|
||||
switch ( ( seed >> 24 ) & 3 )
|
||||
{
|
||||
case 0:
|
||||
b3CreateHullShape( bodyIds[i], &shapeDef, &largeBox.base );
|
||||
break;
|
||||
case 1:
|
||||
b3CreateHullShape( bodyIds[i], &shapeDef, &smallBox.base );
|
||||
break;
|
||||
case 2:
|
||||
b3CreateSphereShape( bodyIds[i], &shapeDef, &sphere );
|
||||
break;
|
||||
default:
|
||||
b3CreateCapsuleShape( bodyIds[i], &shapeDef, &capsule );
|
||||
break;
|
||||
}
|
||||
|
||||
float sign = ( i & 1 ) ? -1.0f : 1.0f;
|
||||
b3Body_SetLinearVelocity( bodyIds[i], (b3Vec3){ -0.0f, -0.5f, -0.0f } );
|
||||
b3Body_SetAngularVelocity( bodyIds[i], (b3Vec3){ -0.0f, sign * 0.5f, -0.0f } );
|
||||
}
|
||||
|
||||
uint32_t hash = B3_HASH_INIT;
|
||||
int stepCount = 180;
|
||||
for ( int step = 0; step < stepCount; ++step )
|
||||
{
|
||||
b3World_Step( worldId, 1.0f / 60.0f, 4 );
|
||||
|
||||
for ( int i = 0; i < bodyCount; ++i )
|
||||
{
|
||||
b3WorldTransform xf = b3Body_GetTransform( bodyIds[i] );
|
||||
hash = b3Hash( hash, (const uint8_t*)&xf, sizeof( b3WorldTransform ) );
|
||||
|
||||
b3Vec3 v = b3Body_GetLinearVelocity( bodyIds[i] );
|
||||
b3Vec3 w = b3Body_GetAngularVelocity( bodyIds[i] );
|
||||
hash = HashFloats( hash, &v.x, 3 );
|
||||
hash = HashFloats( hash, &w.x, 3 );
|
||||
|
||||
b3ContactData contactData[8];
|
||||
int contactCount = b3Body_GetContactData( bodyIds[i], contactData, ARRAY_COUNT( contactData ) );
|
||||
for ( int c = 0; c < contactCount; ++c )
|
||||
{
|
||||
for ( int m = 0; m < contactData[c].manifoldCount; ++m )
|
||||
{
|
||||
const b3Manifold* manifold = contactData[c].manifolds + m;
|
||||
hash = HashFloats( hash, &manifold->rollingImpulse.x, 3 );
|
||||
hash = HashFloats( hash, &manifold->frictionImpulse.x, 3 );
|
||||
hash = HashFloats( hash, &manifold->twistImpulse, 1 );
|
||||
|
||||
for ( int p = 0; p < manifold->pointCount; ++p )
|
||||
{
|
||||
hash = HashFloats( hash, &manifold->points[p].normalImpulse, 1 );
|
||||
hash = HashFloats( hash, &manifold->points[p].totalNormalImpulse, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b3DestroyWorld( worldId );
|
||||
b3DestroyMesh( mesh );
|
||||
|
||||
ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = stepCount, .hash = hash } ) == 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef int SceneFcn( int workerCount, DeterminismResult* reference );
|
||||
|
||||
static int RunSceneAtWidth( SceneFcn* scene, int width, DeterminismResult* result )
|
||||
|
|
@ -458,7 +570,7 @@ static int SIMDWidthTest( void )
|
|||
}
|
||||
|
||||
SceneFcn* scenes[] = {
|
||||
SingleMultithreadingTest, SingleWavePileTest, SingleQuerySpawnTest, SingleMeshDropTest, SingleRollingMixTest,
|
||||
SingleMultithreadingTest, SingleWavePileTest, SingleQuerySpawnTest, SingleMeshDropTest, SingleRollingMixTest, SingleMeshMixTest,
|
||||
};
|
||||
|
||||
for ( int i = 0; i < ARRAY_COUNT( scenes ); ++i )
|
||||
|
|
|
|||
Loading…
Reference in a new issue