Many static objects

Post Reply
NaN
Posts: 9
Joined: Thu Mar 04, 2010 6:55 pm

Many static objects

Post by NaN »

Hi guys,

I am working on a car sim. The worlds consist of a lot static geometry with a 1-8 cars and some few dynamic track objects. the cars are using raycasts for wheels. Up until now I've been batching the geometry into a single btBvhTriangleMeshShape. But with the numbers of objects increasing I am moving towards geometry instancing. The question is how to get to speed with my use case?

Here are some observations using Bullet 2.77 and setForceUpdateAllAabbs(false).

bt32BitAxisSweep3 + one big btBvhTriangleMeshShape track object + car(current setup):

Code: Select all

......Profiling: internalSingleStepSimulation (total running time: 0.311 ms) ---
......0 -- updateActivationState (0.64 %) :: 0.002 ms / frame (1 calls)
......1 -- updateActions (79.42 %) :: 0.247 ms / frame (1 calls)
......2 -- integrateTransforms (0.64 %) :: 0.002 ms / frame (1 calls)
......3 -- solveConstraints (5.79 %) :: 0.018 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.64 %) :: 0.002 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (8.68 %) :: 0.027 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.64 %) :: 0.002 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 0.027 ms) ---
.........0 -- dispatchAllCollisionPairs (59.26 %) :: 0.016 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (3.70 %) :: 0.001 ms / frame (1 calls)
.........2 -- updateAabbs (18.52 %) :: 0.005 ms / frame (1 calls)
bt32BitAxisSweep3 + 550 btBvhTriangleMeshShape objects + car:

Code: Select all

......Profiling: internalSingleStepSimulation (total running time: 0.725 ms) ---
......0 -- updateActivationState (0.28 %) :: 0.002 ms / frame (1 calls)
......1 -- updateActions (45.66 %) :: 0.331 ms / frame (1 calls)
......2 -- integrateTransforms (0.41 %) :: 0.003 ms / frame (1 calls)
......3 -- solveConstraints (3.59 %) :: 0.026 ms / frame (1 calls)
......4 -- calculateSimulationIslands (1.24 %) :: 0.009 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (46.90 %) :: 0.340 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.41 %) :: 0.003 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 0.340 ms) ---
.........0 -- dispatchAllCollisionPairs (6.76 %) :: 0.023 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (0.59 %) :: 0.002 ms / frame (1 calls)
.........2 -- updateAabbs (90.88 %) :: 0.309 ms / frame (1 calls)
bt32BitAxisSweep3 + one big btCompoundShape track object + car:

Code: Select all

......Profiling: internalSingleStepSimulation (total running time: 1.972 ms) ---
......0 -- updateActivationState (0.10 %) :: 0.002 ms / frame (1 calls)
......1 -- updateActions (93.31 %) :: 1.840 ms / frame (1 calls)
......2 -- integrateTransforms (0.10 %) :: 0.002 ms / frame (1 calls)
......3 -- solveConstraints (1.42 %) :: 0.028 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.10 %) :: 0.002 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (4.21 %) :: 0.083 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.15 %) :: 0.003 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 0.083 ms) ---
.........0 -- dispatchAllCollisionPairs (80.72 %) :: 0.067 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (2.41 %) :: 0.002 ms / frame (1 calls)
.........2 -- updateAabbs (10.84 %) :: 0.009 ms / frame (1 calls)
Switching to btDbvtBroadphase gives almost the same numbers.

The btCompoundShape looks really great for the broadphase but it falls behind due to raycasts iterating over the child objects. Has anyone been working on this lately? Would it make sense to get rid of the wheel rays altogether, replace them with btGhostObject?

Thanks.
NaN
Posts: 9
Joined: Thu Mar 04, 2010 6:55 pm

Re: Many static objects

Post by NaN »

A more extreme example 2400 static objects and 1 rigid body using btDbvtBroadphase:

Code: Select all

......Profiling: internalSingleStepSimulation (total running time: 2.455 ms) ---
......0 -- updateActivationState (0.08 %) :: 0.002 ms / frame (1 calls)
......1 -- updateActions (16.99 %) :: 0.417 ms / frame (1 calls)
......2 -- integrateTransforms (0.24 %) :: 0.006 ms / frame (1 calls)
......3 -- solveConstraints (1.47 %) :: 0.036 ms / frame (1 calls)
......4 -- calculateSimulationIslands (3.18 %) :: 0.078 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (77.27 %) :: 1.897 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.16 %) :: 0.004 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 1.897 ms) ---
.........0 -- dispatchAllCollisionPairs (5.11 %) :: 0.097 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (0.47 %) :: 0.009 ms / frame (1 calls)
.........2 -- updateAabbs (94.10 %) :: 1.785 ms / frame (1 calls)
vs 1 batched static object and 1 rigid body:

Code: Select all

......Profiling: internalSingleStepSimulation (total running time: 0.363 ms) ---
......0 -- updateActivationState (0.55 %) :: 0.002 ms / frame (1 calls)
......1 -- updateActions (72.73 %) :: 0.264 ms / frame (1 calls)
......2 -- integrateTransforms (0.55 %) :: 0.002 ms / frame (1 calls)
......3 -- solveConstraints (4.41 %) :: 0.016 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.55 %) :: 0.002 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (17.08 %) :: 0.062 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.83 %) :: 0.003 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 0.062 ms) ---
.........0 -- dispatchAllCollisionPairs (83.87 %) :: 0.052 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (3.23 %) :: 0.002 ms / frame (1 calls)
.........2 -- updateAabbs (3.23 %) :: 0.002 ms / frame (1 calls)
Am doing something wrong in my setup or is this the expected behavior?
NaN
Posts: 9
Joined: Thu Mar 04, 2010 6:55 pm

Re: Many static objects

Post by NaN »

Using BVH acceleration structure of btCompoundShape seems to help (debug build, 2400 objects in compound, updateActions runs 4 ray casts).

current:

Code: Select all

...Profiling: stepSimulation (total running time: 176.646 ms) ---
...0 -- synchronizeMotionStates (0.01 %) :: 0.026 ms / frame (1 calls)
...1 -- internalSingleStepSimulation (99.97 %) :: 176.590 ms / frame (1 calls)
...Unaccounted: (0.017 %) :: 0.030 ms
......----------------------------------
......Profiling: internalSingleStepSimulation (total running time: 176.590 ms) ---
......0 -- updateActivationState (0.01 %) :: 0.021 ms / frame (1 calls)
......1 -- updateActions (98.56 %) :: 174.048 ms / frame (1 calls)
......2 -- integrateTransforms (0.02 %) :: 0.031 ms / frame (1 calls)
......3 -- solveConstraints (0.09 %) :: 0.157 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.00 %) :: 0.007 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (1.28 %) :: 2.261 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.02 %) :: 0.028 ms / frame (1 calls)
......Unaccounted: (0.021 %) :: 0.037 ms
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 2.261 ms) ---
.........0 -- dispatchAllCollisionPairs (96.86 %) :: 2.190 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (1.15 %) :: 0.026 ms / frame (1 calls)
.........2 -- updateAabbs (1.64 %) :: 0.037 ms / frame (1 calls)
Dbvt accelerated:

Code: Select all

Profiling: Root (total running time: 9.112 ms) ---
0 -- stepSimulation (99.92 %) :: 9.105 ms / frame (1 calls)
Unaccounted: (0.077 %) :: 0.007 ms
...----------------------------------
...Profiling: stepSimulation (total running time: 9.105 ms) ---
...0 -- synchronizeMotionStates (0.30 %) :: 0.027 ms / frame (1 calls)
...1 -- internalSingleStepSimulation (99.58 %) :: 9.067 ms / frame (1 calls)
...Unaccounted: (0.121 %) :: 0.011 ms
......----------------------------------
......Profiling: internalSingleStepSimulation (total running time: 9.067 ms) ---
......0 -- updateActivationState (0.03 %) :: 0.003 ms / frame (1 calls)
......1 -- updateActions (70.49 %) :: 6.391 ms / frame (1 calls)
......2 -- integrateTransforms (0.32 %) :: 0.029 ms / frame (1 calls)
......3 -- solveConstraints (1.75 %) :: 0.159 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.28 %) :: 0.025 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (26.33 %) :: 2.387 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.39 %) :: 0.035 ms / frame (1 calls)
......Unaccounted: (0.419 %) :: 0.038 ms
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 2.387 ms) ---
.........0 -- dispatchAllCollisionPairs (97.03 %) :: 2.316 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (0.38 %) :: 0.009 ms / frame (1 calls)
.........2 -- updateAabbs (2.30 %) :: 0.055 ms / frame (1 calls)
Patch is here: http://code.google.com/p/bullet/issues/detail?id=25
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Many static objects

Post by pico »

Hi,

thanks for your patch.

However, i don't think the current (non compound) scenario is right.
UpdateAABBs cpu usage should not grow linear with the number of static items in the world
(at least when setForceUpdateAllAabbs is false).

Maybe something got broke in a bullet update?

You may want to check out this thread:
http://www.bulletphysics.org/Bullet/php ... f=9&t=4991
NaN
Posts: 9
Joined: Thu Mar 04, 2010 6:55 pm

Re: Many static objects

Post by NaN »

Turns out that I've missed to setActivationState(DISABLE_SIMULATION) for my static objects. After applying it the results look much better. Though there is still the overhead of simulation island recalculation and isActive() check for all collision objects.

6500 static objects

Code: Select all

...Profiling: stepSimulation (total running time: 1.017 ms) ---
...0 -- synchronizeMotionStates (0.39 %) :: 0.004 ms / frame (1 calls)
...1 -- internalSingleStepSimulation (87.32 %) :: 0.888 ms / frame (1 calls)
...Unaccounted: (12.291 %) :: 0.125 ms
......----------------------------------
......Profiling: internalSingleStepSimulation (total running time: 0.888 ms) ---
......0 -- updateActivationState (0.23 %) :: 0.002 ms / frame (1 calls)
......1 -- updateActions (35.02 %) :: 0.311 ms / frame (1 calls)
......2 -- integrateTransforms (0.56 %) :: 0.005 ms / frame (1 calls)
......3 -- solveConstraints (3.94 %) :: 0.035 ms / frame (1 calls)
......4 -- calculateSimulationIslands (38.85 %) :: 0.345 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (19.14 %) :: 0.170 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.34 %) :: 0.003 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 0.170 ms) ---
.........0 -- dispatchAllCollisionPairs (6.47 %) :: 0.011 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (3.53 %) :: 0.006 ms / frame (1 calls)
.........2 -- updateAabbs (86.47 %) :: 0.147 ms / frame (1 calls)
compound, 6500 children shapes

Code: Select all

...Profiling: stepSimulation (total running time: 0.407 ms) ---
...0 -- synchronizeMotionStates (0.74 %) :: 0.003 ms / frame (1 calls)
...1 -- internalSingleStepSimulation (98.03 %) :: 0.399 ms / frame (1 calls)
...Unaccounted: (1.229 %) :: 0.005 ms
......----------------------------------
......Profiling: internalSingleStepSimulation (total running time: 0.399 ms) ---
......0 -- updateActivationState (0.25 %) :: 0.001 ms / frame (1 calls)
......1 -- updateActions (59.40 %) :: 0.237 ms / frame (1 calls)
......2 -- integrateTransforms (0.75 %) :: 0.003 ms / frame (1 calls)
......3 -- solveConstraints (5.01 %) :: 0.020 ms / frame (1 calls)
......4 -- calculateSimulationIslands (0.50 %) :: 0.002 ms / frame (1 calls)
......5 -- performDiscreteCollisionDetection (30.58 %) :: 0.122 ms / frame (1 calls)
......6 -- predictUnconstraintMotion (0.50 %) :: 0.002 ms / frame (1 calls)
.........----------------------------------
.........Profiling: performDiscreteCollisionDetection (total running time: 0.122 ms) ---
.........0 -- dispatchAllCollisionPairs (90.16 %) :: 0.110 ms / frame (1 calls)
.........1 -- calculateOverlappingPairs (2.46 %) :: 0.003 ms / frame (1 calls)
.........2 -- updateAabbs (4.10 %) :: 0.005 ms / frame (1 calls)
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Many static objects

Post by pico »

[quote="NaN"]Turns out that I've missed to setActivationState(DISABLE_SIMULATION) for my static objects. After applying it the results look much better. Though there is still the overhead of simulation island recalculation and isActive() check for all collision objects.

Hi,

thats right due to the updateAabbs function. To disable AABB recalc any object must be set to inActive.
The island recalculation time seems to be the issue in the thread i mentioned above.
Last edited by pico on Thu Mar 10, 2011 9:17 am, edited 1 time in total.
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Many static objects

Post by pico »

pico wrote: The island recalculation time seems to be the issue in the thread i mentioned above.
Don't care about that threaad. I've taken a look at the source and the island recalc issue for statics is already fixed.

However, Bullet currently still needs to go through all bodies for certain task and so this can become a problem for large worlds with mainly static/kinematic bodies.

Issue #128 addressed that problem and hopefully Bullet 3.x will go for it.
Post Reply