Dramatic slow down when using SAT convex.

Post Reply
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Dramatic slow down when using SAT convex.

Post by bram »

First things first: Amazing job on Bullet! I find the convex collisions a lot more stable and accurate than what I get on OpenDE.
The bad news is that the performance seems to be a lot lower, as seen in this video:

https://www.youtube.com/watch?v=PiMK5A2 ... e=youtu.be

When I use

Code: Select all

btDispatcherInfo.m_enableSatConvex = true
I see some dramatic slow down.

Even 20 or so convex shapes brings my 240Hz sim to 2fps. This is on Debug build of Bullet3.

When not using SAT, I also see a slow down, but not as dramatic as the SAT case.

I read in the docs that the single contact was faster, but is a large spike like this expected?
Is there an O(N**2) or O(N**3) in there somewhere, maybe?

Linux perf shows that the cycles are burnt in PolyhedralContactClipping::findSeparatingAxis()

This is how I set up the world:

Code: Select all

        // Build the broadphase
        btBroadphaseInterface* broadphase = new btDbvtBroadphase();

        // Set up the collision configuration and dispatcher
        btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);

        // The actual physics solver
        btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
        //btSolveProjectedGaussSeidel* mlcp = new btSolveProjectedGaussSeidel;
        //btMLCPSolver* solver = new btMLCPSolver( mlcp );

        // The world.
        world = new btDiscreteDynamicsWorld( dispatcher, broadphase, solver, collisionConfiguration );
        world->setGravity( btVector3( 0,0,-9.8f ) );

#if 1
        // Set this to have multiple contact points per convex shape.
        btDispatcherInfo& di = world->getDispatchInfo();
        di.m_enableSatConvex = true;
#endif

        btContactSolverInfo& si = world->getSolverInfo();
        si.m_numIterations = 20;
        si.m_erp = 0.7f;
        si.m_erp2 = si.m_erp / 2;
        si.m_globalCfm = 0.05f;
        //si.m_minimumSolverBatchSize = 1;
        si.m_solverMode =
                SOLVER_USE_WARMSTARTING |
                SOLVER_SIMD |
                SOLVER_RANDMIZE_ORDER;

User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Dramatic slow down when using SAT convex.

Post by Erwin Coumans »

Our SAT is not used by default and not well optimized. The default settings using GJK+EPA+ incremental persistent contact manifold should work really well, especially at 240hz. We accumulate up to 4 points, so there won't be single contacts for long.


>> When not using SAT, I also see a slow down,

slow down compared to what? Possibly penetration (EPA) happens, which is slower than GJK. Always use enough collision margins to avoid EPA, since EPA is slow.

Please do profile in release/optimized mode.
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Re: Dramatic slow down when using SAT convex.

Post by bram »

Thanks Erwin,

For proper benchmarking, I switched to Release.

I also decided to add a new Benchmark demo to your Example Browser for this purpose.

Image

I've added it, but the results are puzzling to me:
https://youtu.be/YrcxyKLkBcE

I've gone over the code many times, but I can't see what could be causing the fragments to behave this strangely?

If you want, I can create a pull request for the demo code, but here is the meat of it:

Code: Select all

void BenchmarkDemo::createTest8()
{
        float dist = 8;
        float pitch = -15;
        float yaw = 20;
        float targetPos[3] = {0, 1, 0};
        m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]);
        // Create a shape and rigid body for each Voronoi cell.
        const float fallHeight = 3.5f;
        for (int i=0; i<halton_numc; ++i)
        {
                btConvexHullShape* shp = new btConvexHullShape();
                const float* verts  = halton_verts[i];
                const float* origin = halton_pos[i];
                for (int v=0; v<halton_numv[i]; ++v)
                {
                        btVector3 vtx(verts[0],verts[1]+fallHeight,verts[2]);
                        shp->addPoint(vtx);
                        verts += 3;
                }
                shp->initializePolyhedralFeatures();
                shp->setMargin(0.04f);
                btTransform transform;
                transform.setIdentity();
                transform.setOrigin(btVector3(origin[0],origin[1],origin[2]));
                const float mass = halton_volu[i];
                //const float mass = 1;
                btVector3 inertia(0,0,0);
                shp->calculateLocalInertia(mass, inertia);
                //btDefaultMotionState* mst = new btDefaultMotionState(transform);
                btRigidBody::btRigidBodyConstructionInfo ci(mass, 0, shp, inertia);
                ci.m_startWorldTransform = transform;
                btRigidBody* body = new btRigidBody(ci);
                body->setFriction(0.6f);
                m_dynamicsWorld->addRigidBody(body);
        }
        m_dynamicsWorld->getSolverInfo().m_numIterations = 20;
        // Create a ground plane
        btCollisionShape* groundplane = new btStaticPlaneShape(btVector3(0,1,0),0);
        groundplane->setMargin(0.04f);
        btRigidBody::btRigidBodyConstructionInfo rc(0.0f, 0, groundplane, btVector3(0,0,0));
        btRigidBody* groundbody = new btRigidBody(rc);
        m_dynamicsWorld->addRigidBody(groundbody);
#if 0
        // Use SAT
        btDispatcherInfo& di = m_dynamicsWorld->getDispatchInfo();
        di.m_enableSatConvex = true;
#endif
}
Any idea why the fragments dance around like that?
They don't do that in my own codebase, by the way.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Dramatic slow down when using SAT convex.

Post by Erwin Coumans »

>> Any idea why the fragments dance around like that?

Perhaps the vertices are not centered around the origin? The center of mass needs to be at [0,0,0].

There is a similar demo in the example browser under Experiments/VoronoiFracture.
(note that that demo has a small issue, after removing the constraint, it doesn't re-enable collisions, will be fixed soon).
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Re: Dramatic slow down when using SAT convex.

Post by bram »

Erwin Coumans wrote: Fri Nov 02, 2018 3:48 pm >> Any idea why the fragments dance around like that?

Perhaps the vertices are not centered around the origin? The center of mass needs to be at [0,0,0].
Argh, YES, thank you.

I had added the fall height to the shape verts, instead of the body world tramsform.

It all makes sense now.

Thanks again.
bram
Posts: 51
Joined: Sun Nov 23, 2008 4:43 pm

Re: Dramatic slow down when using SAT convex.

Post by bram »

Works beautifully now: https://youtu.be/D57gCD78YpI

Nice to see that the sim is deterministic too!

On my machine I see a factor 15 between the performance of single-contact versus SAT.
6ms versus 90ms or so.

But the non-SAT version seems quite usable.

Thanks, Erwin.

PS: I've send you a pull request in case you want to add the demo. I think it can be useful for keeping an eye on SAT/non-SAT perf.
Post Reply