From f567130d7806021fcace602d7a608280a1f74f6c Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Mon, 8 Feb 2010 23:50:33 +0000 Subject: [PATCH] add option to compile benchmark using BulletMultiThreaded (for now the option is only tested on Windows) --- CMakeLists.txt | 6 + Demos/Benchmarks/BenchmarkDemo.cpp | 42 ++-- Demos/Benchmarks/CMakeLists.txt | 181 +++++++++--------- src/BulletMultiThreaded/CMakeLists.txt | 4 + .../btParallelConstraintSolver.cpp | 74 +++++++ .../btParallelConstraintSolver.h | 42 ++++ 6 files changed, 247 insertions(+), 102 deletions(-) create mode 100644 src/BulletMultiThreaded/btParallelConstraintSolver.cpp create mode 100644 src/BulletMultiThreaded/btParallelConstraintSolver.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 00466283b..d59359640 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,12 @@ ENDIF (NOT CMAKE_BUILD_TYPE) OPTION(USE_DOUBLE_PRECISION "Use double precision" 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_INCREMENTAL_LINKING "Use MSVC Incremental Linking" ON) diff --git a/Demos/Benchmarks/BenchmarkDemo.cpp b/Demos/Benchmarks/BenchmarkDemo.cpp index c6ad70073..c986c3e34 100644 --- a/Demos/Benchmarks/BenchmarkDemo.cpp +++ b/Demos/Benchmarks/BenchmarkDemo.cpp @@ -34,7 +34,15 @@ subject to the following restrictions: #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 { @@ -285,20 +293,20 @@ void BenchmarkDemo::initPhysics() ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); -#if 0 - SequentialThreadSupport::SequentialThreadConstructionInfo sci("spuCD", - processCollisionTask, - createCollisionLocalStoreMemory); +#if USE_PARALLEL_DISPATCHER_BENCHMARK - SequentialThreadSupport* seq = new SequentialThreadSupport(sci); - m_dispatcher = new SpuGatheringCollisionDispatcher(seq,1,m_collisionConfiguration); + int maxNumOutstandingTasks = 4; + 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 ///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 - btVector3 worldAabbMin(-10000,-10000,-10000); - btVector3 worldAabbMax(10000,10000,10000); + btVector3 worldAabbMin(-1000,-1000,-1000); + btVector3 worldAabbMax(1000,1000,1000); btHashedOverlappingPairCache* pairCache = new btHashedOverlappingPairCache(); m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,3500,pairCache); @@ -306,17 +314,21 @@ void BenchmarkDemo::initPhysics() // m_overlappingPairCache = new btDbvtBroadphase(); - ///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; +#endif //USE_PARALLEL_DISPATCHER_BENCHMARK + m_solver = sol; btDiscreteDynamicsWorld* dynamicsWorld; 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)); @@ -324,14 +336,14 @@ void BenchmarkDemo::initPhysics() if (m_benchmark<5) { ///create a few basic rigid bodies - // btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); - btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),0); + btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(250.),btScalar(50.),btScalar(250.))); + // btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),0); m_collisionShapes.push_back(groundShape); btTransform groundTransform; 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: { diff --git a/Demos/Benchmarks/CMakeLists.txt b/Demos/Benchmarks/CMakeLists.txt index 0f81f63c8..c750d313e 100644 --- a/Demos/Benchmarks/CMakeLists.txt +++ b/Demos/Benchmarks/CMakeLists.txt @@ -1,93 +1,100 @@ -# 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 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 -######################################################## - -IF (USE_GRAPHICAL_BENCHMARK) -IF (USE_GLUT) - INCLUDE_DIRECTORIES( - ${BULLET_PHYSICS_SOURCE_DIR}/src - ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL - ) - - LINK_LIBRARIES( - OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} - ) - IF (WIN32) - ADD_EXECUTABLE(AppBenchmarks - main.cpp - BenchmarkDemo.cpp - BenchmarkDemo.h - ${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc - ) - ELSE() - ADD_EXECUTABLE(AppBenchmarks - main.cpp - BenchmarkDemo.cpp - BenchmarkDemo.h - ) - ENDIF () - IF (WIN32) - IF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES) - IF (CMAKE_CL_64) - ADD_CUSTOM_COMMAND( - TARGET AppBenchmarks - POST_BUILD - COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR} - ) - ELSE(CMAKE_CL_64) - ADD_CUSTOM_COMMAND( - TARGET AppBenchmarks - POST_BUILD - COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR} - ) - ENDIF(CMAKE_CL_64) - ENDIF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES) +# 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 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 +######################################################## + +IF (USE_GRAPHICAL_BENCHMARK) +IF (USE_GLUT) + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL + ) + + LINK_LIBRARIES( + OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + IF (WIN32) + ADD_EXECUTABLE(AppBenchmarks + main.cpp + BenchmarkDemo.cpp + BenchmarkDemo.h + ${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc + ) + ELSE() + ADD_EXECUTABLE(AppBenchmarks + main.cpp + BenchmarkDemo.cpp + BenchmarkDemo.h + ) + ENDIF () + IF (WIN32) + IF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES) + IF (CMAKE_CL_64) + ADD_CUSTOM_COMMAND( + TARGET AppBenchmarks + POST_BUILD + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR} + ) + ELSE(CMAKE_CL_64) + ADD_CUSTOM_COMMAND( + TARGET AppBenchmarks + POST_BUILD + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR} + ) + ENDIF(CMAKE_CL_64) + ENDIF (NOT INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES) IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES DEBUG_POSTFIX "_Debug") SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") SET_TARGET_PROPERTIES(AppBenchmarks PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) - - ENDIF(WIN32) -ELSE (USE_GLUT) - INCLUDE_DIRECTORIES( - ${BULLET_PHYSICS_SOURCE_DIR}/src - ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL - ) - - LINK_LIBRARIES( - OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} - ) - - ADD_EXECUTABLE(AppBenchmarks - WIN32 - ../OpenGL/Win32AppMain.cpp - BenchmarkDemo.cpp - BenchmarkDemo.h - Win32BenchmarkDemo.cpp - ${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc - ) -ENDIF (USE_GLUT) -ELSE (USE_GRAPHICAL_BENCHMARK) - - INCLUDE_DIRECTORIES( - ${BULLET_PHYSICS_SOURCE_DIR}/src - ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL - ) - - LINK_LIBRARIES( - BulletDynamics BulletCollision LinearMath - ) - - - ADD_EXECUTABLE(AppBenchmarks - main.cpp - BenchmarkDemo.cpp - ) + + ENDIF(WIN32) +ELSE (USE_GLUT) + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${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( + OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + + ENDIF() + + ADD_EXECUTABLE(AppBenchmarks + WIN32 + ../OpenGL/Win32AppMain.cpp + BenchmarkDemo.cpp + BenchmarkDemo.h + Win32BenchmarkDemo.cpp + ${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc + ) +ENDIF (USE_GLUT) +ELSE (USE_GRAPHICAL_BENCHMARK) + + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL + ) + + LINK_LIBRARIES( + BulletDynamics BulletCollision LinearMath + ) + + + ADD_EXECUTABLE(AppBenchmarks + main.cpp + BenchmarkDemo.cpp + ) ENDIF (USE_GRAPHICAL_BENCHMARK) \ No newline at end of file diff --git a/src/BulletMultiThreaded/CMakeLists.txt b/src/BulletMultiThreaded/CMakeLists.txt index 90ac8a467..d39ebfabb 100644 --- a/src/BulletMultiThreaded/CMakeLists.txt +++ b/src/BulletMultiThreaded/CMakeLists.txt @@ -30,6 +30,10 @@ ADD_LIBRARY(BulletMultiThreaded SpuGatheringCollisionDispatcher.cpp SpuContactManifoldCollisionAlgorithm.cpp SpuContactManifoldCollisionAlgorithm.h + + btParallelConstraintSolver.cpp + btParallelConstraintSolver.h + SpuNarrowPhaseCollisionTask/Box.h SpuNarrowPhaseCollisionTask/boxBoxDistance.cpp SpuNarrowPhaseCollisionTask/boxBoxDistance.h diff --git a/src/BulletMultiThreaded/btParallelConstraintSolver.cpp b/src/BulletMultiThreaded/btParallelConstraintSolver.cpp new file mode 100644 index 000000000..4667dd718 --- /dev/null +++ b/src/BulletMultiThreaded/btParallelConstraintSolver.cpp @@ -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