add option to compile benchmark using BulletMultiThreaded (for now the option is only tested on Windows)

This commit is contained in:
erwin.coumans
2010-02-08 23:50:33 +00:00
parent 7d4e2873e2
commit f567130d78
6 changed files with 247 additions and 102 deletions

View File

@@ -13,6 +13,12 @@ ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF) OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" OFF) OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" OFF)
OPTION(USE_MULTITHREADED_BENCHMARK "Use Multithreaded Benchmark" OFF)
IF (USE_MULTITHREADED_BENCHMARK)
ADD_DEFINITIONS(-DUSE_PARALLEL_SOLVER_BENCHMARK -DUSE_PARALLEL_DISPATCHER_BENCHMARK)
ENDIF()
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON) OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" ON) OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" ON)

View File

@@ -34,7 +34,15 @@ subject to the following restrictions:
#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h" #include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
#ifdef USE_PARALLEL_DISPATCHER_BENCHMARK
#include "BulletMultiThreaded/Win32ThreadSupport.h"
#include "BulletMultiThreaded/SpuGatheringCollisionDispatcher.h"
#endif
#ifdef USE_PARALLEL_SOLVER_BENCHMARK
#include "BulletMultiThreaded/btParallelConstraintSolver.h"
#endif
class btRaycastBar2 class btRaycastBar2
{ {
@@ -285,20 +293,20 @@ void BenchmarkDemo::initPhysics()
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
#if 0 #if USE_PARALLEL_DISPATCHER_BENCHMARK
SequentialThreadSupport::SequentialThreadConstructionInfo sci("spuCD",
processCollisionTask,
createCollisionLocalStoreMemory);
SequentialThreadSupport* seq = new SequentialThreadSupport(sci); int maxNumOutstandingTasks = 4;
m_dispatcher = new SpuGatheringCollisionDispatcher(seq,1,m_collisionConfiguration); Win32ThreadSupport* threadSupportCollision = new Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo( "collision",processCollisionTask, createCollisionLocalStoreMemory,maxNumOutstandingTasks));
//SequentialThreadSupport::SequentialThreadConstructionInfo sci("spuCD", processCollisionTask, createCollisionLocalStoreMemory);
//SequentialThreadSupport* seq = new SequentialThreadSupport(sci);
m_dispatcher = new SpuGatheringCollisionDispatcher(threadSupportCollision,1,m_collisionConfiguration);
#endif #endif
///the maximum size of the collision world. Make sure objects stay within these boundaries ///the maximum size of the collision world. Make sure objects stay within these boundaries
///Don't make the world AABB size too large, it will harm simulation quality and performance ///Don't make the world AABB size too large, it will harm simulation quality and performance
btVector3 worldAabbMin(-10000,-10000,-10000); btVector3 worldAabbMin(-1000,-1000,-1000);
btVector3 worldAabbMax(10000,10000,10000); btVector3 worldAabbMax(1000,1000,1000);
btHashedOverlappingPairCache* pairCache = new btHashedOverlappingPairCache(); btHashedOverlappingPairCache* pairCache = new btHashedOverlappingPairCache();
m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,3500,pairCache); m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,3500,pairCache);
@@ -306,17 +314,21 @@ void BenchmarkDemo::initPhysics()
// m_overlappingPairCache = new btDbvtBroadphase(); // m_overlappingPairCache = new btDbvtBroadphase();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
#ifdef USE_PARALLEL_SOLVER_BENCHMARK
btSequentialImpulseConstraintSolver* sol = new btParallelConstraintSolver;
#else
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver; btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
#endif //USE_PARALLEL_DISPATCHER_BENCHMARK
m_solver = sol; m_solver = sol;
btDiscreteDynamicsWorld* dynamicsWorld; btDiscreteDynamicsWorld* dynamicsWorld;
m_dynamicsWorld = dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration); m_dynamicsWorld = dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
dynamicsWorld->getSimulationIslandManager()->setSplitIslands(false);
dynamicsWorld->getDispatchInfo().m_useConvexConservativeDistanceUtil = true;
dynamicsWorld->getDispatchInfo().m_convexConservativeDistanceThreshold = btScalar(0.01); dynamicsWorld->getSolverInfo().m_numIterations = 4;
m_dynamicsWorld->setGravity(btVector3(0,-10,0)); m_dynamicsWorld->setGravity(btVector3(0,-10,0));
@@ -324,14 +336,14 @@ void BenchmarkDemo::initPhysics()
if (m_benchmark<5) if (m_benchmark<5)
{ {
///create a few basic rigid bodies ///create a few basic rigid bodies
// btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(250.),btScalar(50.),btScalar(250.)));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),0); // btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),0);
m_collisionShapes.push_back(groundShape); m_collisionShapes.push_back(groundShape);
btTransform groundTransform; btTransform groundTransform;
groundTransform.setIdentity(); groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,0,0)); groundTransform.setOrigin(btVector3(0,-50,0));
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here: //We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
{ {

View File

@@ -61,10 +61,17 @@ ELSE (USE_GLUT)
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
) )
IF (USE_MULTITHREADED_BENCHMARK)
LINK_LIBRARIES(
OpenGLSupport BulletMultiThreaded BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ELSE()
LINK_LIBRARIES( LINK_LIBRARIES(
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
) )
ENDIF()
ADD_EXECUTABLE(AppBenchmarks ADD_EXECUTABLE(AppBenchmarks
WIN32 WIN32
../OpenGL/Win32AppMain.cpp ../OpenGL/Win32AppMain.cpp

View File

@@ -30,6 +30,10 @@ ADD_LIBRARY(BulletMultiThreaded
SpuGatheringCollisionDispatcher.cpp SpuGatheringCollisionDispatcher.cpp
SpuContactManifoldCollisionAlgorithm.cpp SpuContactManifoldCollisionAlgorithm.cpp
SpuContactManifoldCollisionAlgorithm.h SpuContactManifoldCollisionAlgorithm.h
btParallelConstraintSolver.cpp
btParallelConstraintSolver.h
SpuNarrowPhaseCollisionTask/Box.h SpuNarrowPhaseCollisionTask/Box.h
SpuNarrowPhaseCollisionTask/boxBoxDistance.cpp SpuNarrowPhaseCollisionTask/boxBoxDistance.cpp
SpuNarrowPhaseCollisionTask/boxBoxDistance.h SpuNarrowPhaseCollisionTask/boxBoxDistance.h

View File

@@ -0,0 +1,74 @@
/*
Copyright (C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "btParallelConstraintSolver.h"
#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
btParallelConstraintSolver::btParallelConstraintSolver()
{
//initialize MiniCL here
}
btParallelConstraintSolver::~btParallelConstraintSolver()
{
//exit MiniCL
}
btScalar btParallelConstraintSolver::solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc)
{
{
int i;
btPersistentManifold* manifold = 0;
// btCollisionObject* colObj0=0,*colObj1=0;
for (i=0;i<numManifolds;i++)
{
manifold = manifoldPtr[i];
convertContact(manifold,infoGlobal);
}
}
btContactSolverInfo info = infoGlobal;
int numConstraintPool = m_tmpSolverContactConstraintPool.size();
int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size();
///@todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
m_orderTmpConstraintPool.resize(numConstraintPool);
m_orderFrictionConstraintPool.resize(numFrictionPool);
{
int i;
for (i=0;i<numConstraintPool;i++)
{
m_orderTmpConstraintPool[i] = i;
}
for (i=0;i<numFrictionPool;i++)
{
m_orderFrictionConstraintPool[i] = i;
}
}
return 0.f;
}

View File

@@ -0,0 +1,42 @@
/*
Copyright (C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef __BT_PARALLEL_CONSTRAINT_SOLVER_H
#define __BT_PARALLEL_CONSTRAINT_SOLVER_H
#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
class btParallelConstraintSolver : public btSequentialImpulseConstraintSolver
{
protected:
public:
btParallelConstraintSolver();
virtual ~btParallelConstraintSolver();
//virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer, btStackAlloc* stackAlloc,btDispatcher* dispatcher);
btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);
};
#endif //__BT_PARALLEL_CONSTRAINT_SOLVER_H