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

@@ -1,93 +1,100 @@
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File # This is basically the overall name of the project in Visual Studio this is the name of the Solution File
# For every executable you have with a main method you should have an add_executable line below. # For every executable you have with a main method you should have an add_executable line below.
# For every add executable line you should list every .cpp and .h file you have associated with that executable. # For every add executable line you should list every .cpp and .h file you have associated with that executable.
# You shouldn't have to modify anything below this line # You shouldn't have to modify anything below this line
######################################################## ########################################################
IF (USE_GRAPHICAL_BENCHMARK) IF (USE_GRAPHICAL_BENCHMARK)
IF (USE_GLUT) IF (USE_GLUT)
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
) )
LINK_LIBRARIES( LINK_LIBRARIES(
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
) )
IF (WIN32) IF (WIN32)
ADD_EXECUTABLE(AppBenchmarks ADD_EXECUTABLE(AppBenchmarks
main.cpp main.cpp
BenchmarkDemo.cpp BenchmarkDemo.cpp
BenchmarkDemo.h BenchmarkDemo.h
${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc ${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
) )
ELSE() ELSE()
ADD_EXECUTABLE(AppBenchmarks ADD_EXECUTABLE(AppBenchmarks
main.cpp main.cpp
BenchmarkDemo.cpp BenchmarkDemo.cpp
BenchmarkDemo.h BenchmarkDemo.h
) )
ENDIF () ENDIF ()
IF (WIN32) IF (WIN32)
IF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES) IF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES)
IF (CMAKE_CL_64) IF (CMAKE_CL_64)
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
TARGET AppBenchmarks TARGET AppBenchmarks
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
) )
ELSE(CMAKE_CL_64) ELSE(CMAKE_CL_64)
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
TARGET AppBenchmarks TARGET AppBenchmarks
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
) )
ENDIF(CMAKE_CL_64) ENDIF(CMAKE_CL_64)
ENDIF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES) ENDIF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES DEBUG_POSTFIX "_Debug") SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
ENDIF(WIN32) ENDIF(WIN32)
ELSE (USE_GLUT) ELSE (USE_GLUT)
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
) )
LINK_LIBRARIES( IF (USE_MULTITHREADED_BENCHMARK)
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} LINK_LIBRARIES(
) OpenGLSupport BulletMultiThreaded BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ADD_EXECUTABLE(AppBenchmarks ELSE()
WIN32 LINK_LIBRARIES(
../OpenGL/Win32AppMain.cpp OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
BenchmarkDemo.cpp )
BenchmarkDemo.h
Win32BenchmarkDemo.cpp ENDIF()
${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
) ADD_EXECUTABLE(AppBenchmarks
ENDIF (USE_GLUT) WIN32
ELSE (USE_GRAPHICAL_BENCHMARK) ../OpenGL/Win32AppMain.cpp
BenchmarkDemo.cpp
INCLUDE_DIRECTORIES( BenchmarkDemo.h
${BULLET_PHYSICS_SOURCE_DIR}/src Win32BenchmarkDemo.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
) )
ENDIF (USE_GLUT)
LINK_LIBRARIES( ELSE (USE_GRAPHICAL_BENCHMARK)
BulletDynamics BulletCollision LinearMath
) INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
ADD_EXECUTABLE(AppBenchmarks )
main.cpp
BenchmarkDemo.cpp LINK_LIBRARIES(
) BulletDynamics BulletCollision LinearMath
)
ADD_EXECUTABLE(AppBenchmarks
main.cpp
BenchmarkDemo.cpp
)
ENDIF (USE_GRAPHICAL_BENCHMARK) ENDIF (USE_GRAPHICAL_BENCHMARK)

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