Bullet slow down in graphics engine

nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Bullet slow down in graphics engine

Post by nickfla1 »

Hi everyone I've just finished implementing Bullet in my engine but when I run the application
there's a massive fps drop, for eg:
without Bullet 500/600fps ;
with Bullet 15/25fp.
This happens even if there's only a few physics objects in the scene.

I'm using Bullet like so:

Code: Select all

void Init(){
m_pCollisionConfiguration = new btDefaultCollisionConfiguration();
m_pCollisionDispatcher = new btCollisionDispatcher(m_pCollisionConfiguration);
float bound = 1000000.0F;
btVector3 worldMin(-bound, -bound, -bound);
btVector3 worldMax(bound, bound, bound);
m_pBroadPhase = new btAxisSweep3(worldMin, worldMax, 32766);
m_pConstraintSolver = new btSequentialImpulseConstraintSolver();
m_pDynamicWorld = new btDiscreteDynamicsWorld(m_pCollisionDispatcher, m_pBroadPhase, m_pConstraintSolver, m_pCollisionConfiguration);
m_pDynamicWorld->getDispatchInfo().m_enableSPU = true;
m_pDynamicWorld->setGravity(btVector3(0.0F, -9.8F, 0.0F));

//ground
btTransform t;
t.setIdentity();
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0.0F, 1.0F, 0.0F), 0.0F);	m_pCollisionShapes.push_back(groundShape);
btRigidBody* groundBody = CreateRigidBody(0.0F, t, groundShape);
groundBody->setRestitution(0);
groundBody->setFriction(1.0F);
m_pDynamicWorld->addRigidBody(groundBody);
}

void Update(float elapsedTime){
if(m_pDynamicWorld)
	m_pDynamicWorld->stepSimulation(elapsedTime);
}
I really hope someone can help me.
Thanks.

Ps: Sorry for any english mistakes, it's not my mother language
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Bullet slow down in graphics engine

Post by Basroil »

Are you sure that there isn't anything wrong with the graphics engine instead? Tried testing your objects moving kinematically (just update x y and z based on a function of time) without bullet? Perhaps your engine is simply skipping steps without bullet, resulting in unrealistic results. Or perhaps you aren't putting elapsed time in correctly and bullet is calculating many times real-time (i.e. forget to multiply/divide by 1000 somewhere and suddenly bullet is calculating 1000 frames per frame!). Unfortunately we can't see what you're putting into elapsedTime, but stepSimulation runs in seconds while most timing functions use microseconds, so unless you're dividing by a million somewhere, you're asking a lot of the computer (and certainly will drop performance)
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Bullet slow down in graphics engine

Post by nickfla1 »

The graphics engine has no problems for the moment and I already have moving objects.
I get my 'elapsedTime' variable like so:

Code: Select all

void InitTimer(){
    QueryPerformanceFrequency( (LARGE_INTEGER *)&m_ticksPerSecond );

    m_currentTime = m_lastTime = m_lastFPSUpdate = 0;
    m_numFrames = 0;
    m_runningTime = m_timeElapsed = m_fps = 0.0f;
    m_FPSUpdateInterval = m_ticksPerSecond >> 1;
    m_timerStopped = TRUE;
}

void StartTimer(){
    if(!m_timerStopped){
        return;
    }
    QueryPerformanceCounter((LARGE_INTEGER *)&m_lastTime);
    m_timerStopped = FALSE;
}

void UpdateTimer(){
    if (m_timerStopped){
        return;
    }

    QueryPerformanceCounter((LARGE_INTEGER *)&m_currentTime);
    
    m_timeElapsed = (float)(m_currentTime - m_lastTime) / (float)m_ticksPerSecond;
    m_runningTime += m_timeElapsed;

    m_numFrames++;
    if (m_currentTime - m_lastFPSUpdate >= m_FPSUpdateInterval){
        float currentTime = (float)m_currentTime / (float)m_ticksPerSecond;
        float lastTime = (float)m_lastFPSUpdate / (float)m_ticksPerSecond;
        m_fps = (float)m_numFrames / (currentTime - lastTime);

        m_lastFPSUpdate = m_currentTime;
        m_numFrames = 0;
    }

    m_lastTime = m_currentTime;
}

float GetElepsedTime(){
    return m_timeElapsed;
}
And I get a value between 0.0010... and 0.0013... without physics enabled & a value between 0.02... and 0.03... with physics enabled
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Bullet slow down in graphics engine

Post by xexuxjy »

Is there any printf output enabled anywhere? I've seen that drag things down to a crawl.
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Bullet slow down in graphics engine

Post by nickfla1 »

No there isn't any printf in the code just a few sprintf for writing data into a char* I use for debugging
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Bullet slow down in graphics engine

Post by xexuxjy »

ok. other things to check (aside from bullet itself sometimes using printf) :

running in release mode.
what sort of collision shapes are you using on your rigid bodies?
what collision masks do they have.
what size are they.
does the framerate stay consistently low, or does it improve again as the various physics objects end up in a sleeping state.
can you make use of btQuickProf to see where bullet is spending the time?
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Bullet slow down in graphics engine

Post by nickfla1 »

Okay, man.
I don't know why but now that I compiled the whole project in release mode the fps are normal again.
Anyway:
-There's just a few cubes and a static plane
-I'm not using any kind of collision mask
-The cubes a are 1x1x1
-Now there isn't any huge change of fps when the physics objects are in sleeping mode, before there was.
-I'm quite new to Bullet and I don't know if I can use btQuickProf, I'll do some research.

Thanks :)
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Bullet slow down in graphics engine

Post by Basroil »

nickfla1 wrote:Okay, man.
I don't know why but now that I compiled the whole project in release mode the fps are normal again.
Anyway:
-There's just a few cubes and a static plane
-I'm not using any kind of collision mask
-The cubes a are 1x1x1
-Now there isn't any huge change of fps when the physics objects are in sleeping mode, before there was.
-I'm quite new to Bullet and I don't know if I can use btQuickProf, I'll do some research.

Thanks :)
The speed difference between debug and release is huge, and there's plenty of optional settings that improve it further (like SMID, DX11/OpenCL for softbody, etc), I've had a simple (but high frame rate and iterations) take 25ms/frame in debug but under 1ms in release, and that surely could throw a wrench in your engine!

btQuickProf is used in the demo apps, so you might learn more about it by reading up the demo app code, sure beats the documentation.
nickfla1
Posts: 9
Joined: Wed Jun 19, 2013 8:41 am

Re: Bullet slow down in graphics engine

Post by nickfla1 »

Thanks ^^
Anyway I'm getting strange results with the btKinematicCharacterController, can I continue this topic or should I open another one?