From 599579803ed9de38c006b33b5c052a2a1db84505 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Thu, 13 Dec 2007 03:47:47 +0000 Subject: [PATCH] Added portable non-parallel implementation for btThreadSupportInterface: SequentialThreadSupport, Thanks John McCutchan (JMC) Added CMake support for BulletMultiThreaded. --- Extras/BulletMultiThreaded/CMakeLists.txt | 53 +++++++++++ .../SequentialThreadSupport.cpp | 92 +++++++++++++++++++ .../SequentialThreadSupport.h | 84 +++++++++++++++++ .../Win32ThreadSupport.cpp | 2 +- .../BulletMultiThreaded/Win32ThreadSupport.h | 43 +++++---- Extras/CMakeLists.txt | 2 +- src/BulletDynamics/Vehicle/btRaycastVehicle.h | 8 +- 7 files changed, 258 insertions(+), 26 deletions(-) create mode 100644 Extras/BulletMultiThreaded/CMakeLists.txt create mode 100644 Extras/BulletMultiThreaded/SequentialThreadSupport.cpp create mode 100644 Extras/BulletMultiThreaded/SequentialThreadSupport.h diff --git a/Extras/BulletMultiThreaded/CMakeLists.txt b/Extras/BulletMultiThreaded/CMakeLists.txt new file mode 100644 index 000000000..3ae2a40fe --- /dev/null +++ b/Extras/BulletMultiThreaded/CMakeLists.txt @@ -0,0 +1,53 @@ +INCLUDE_DIRECTORIES( +${BULLET_PHYSICS_SOURCE_DIR}/Extras/BulletMultiThreaded/ +${BULLET_PHYSICS_SOURCE_DIR}/src +) + +ADD_LIBRARY(LibBulletMultiThreaded + PlatformDefinitions.h + SpuFakeDma.cpp + SpuFakeDma.h + SpuSync.h + SpuDoubleBuffer.h + SpuLibspe2Support.cpp + SpuLibspe2Support.h + btThreadSupportInterface.cpp + btThreadSupportInterface.h + + Win32ThreadSupport.cpp + Win32ThreadSupport.h + SequentialThreadSupport.cpp + SequentialThreadSupport.h + SpuSampleTaskProcess.h + SpuSampleTaskProcess.cpp + + SpuCollisionTaskProcess.h + SpuCollisionTaskProcess.cpp + SpuGatheringCollisionDispatcher.h + SpuGatheringCollisionDispatcher.cpp + SpuContactManifoldCollisionAlgorithm.cpp + SpuContactManifoldCollisionAlgorithm.h + SpuNarrowPhaseCollisionTask/SpuContactResult.cpp + SpuNarrowPhaseCollisionTask/SpuContactResult.h + SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.cpp + SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.h + SpuNarrowPhaseCollisionTask/SpuConvexPenetrationDepthSolver.h + SpuNarrowPhaseCollisionTask/SpuPreferredPenetrationDirections.h + SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp + SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h + SpuNarrowPhaseCollisionTask/SpuVoronoiSimplexSolver.cpp + SpuNarrowPhaseCollisionTask/SpuVoronoiSimplexSolver.h + SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.cpp + SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.h + SpuNarrowPhaseCollisionTask/SpuLocalSupport.h + + SpuParallelSolver.cpp + SpuParallelSolver.h + SpuSolverTask/SpuParallellSolverTask.cpp + SpuSolverTask/SpuParallellSolverTask.h + +# SpuRaycastTaskProcess.cpp +# SpuRaycastTaskProcess.h +# SpuRaycastTask/SpuRaycastTask.cpp +# SpuRaycastTask/SpuRaycastTask.h +) diff --git a/Extras/BulletMultiThreaded/SequentialThreadSupport.cpp b/Extras/BulletMultiThreaded/SequentialThreadSupport.cpp new file mode 100644 index 000000000..b7158cd61 --- /dev/null +++ b/Extras/BulletMultiThreaded/SequentialThreadSupport.cpp @@ -0,0 +1,92 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com + +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 "SequentialThreadSupport.h" + + +#include "SpuCollisionTaskProcess.h" +#include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h" + +SequentialThreadSupport::SequentialThreadSupport(SequentialThreadConstructionInfo& threadConstructionInfo) +{ + startThreads(threadConstructionInfo); +} + +///cleanup/shutdown Libspe2 +SequentialThreadSupport::~SequentialThreadSupport() +{ + stopSPU(); +} + +#include + +///send messages to SPUs +void SequentialThreadSupport::sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t taskId) +{ + switch (uiCommand) + { + case CMD_GATHER_AND_PROCESS_PAIRLIST: + { + btSpuStatus& spuStatus = m_activeSpuStatus[0]; + spuStatus.m_userPtr=(void*)uiArgument0; + spuStatus.m_userThreadFunc(spuStatus.m_userPtr,spuStatus.m_lsMemory); + } + break; + default: + { + ///not implemented + btAssert(0 && "Not implemented"); + } + + }; + + +} + + +///check for messages from SPUs +void SequentialThreadSupport::waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1) +{ + btAssert(m_activeSpuStatus.size()); + btSpuStatus& spuStatus = m_activeSpuStatus[0]; + *puiArgument0 = spuStatus.m_taskId; + *puiArgument1 = spuStatus.m_status; +} + + + +void SequentialThreadSupport::startThreads(SequentialThreadConstructionInfo& threadConstructionInfo) +{ + m_activeSpuStatus.resize(1); + printf("STS: Not starting any threads\n"); + btSpuStatus& spuStatus = m_activeSpuStatus[0]; + spuStatus.m_userPtr = 0; + spuStatus.m_taskId = 0; + spuStatus.m_commandId = 0; + spuStatus.m_status = 0; + spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc(); + spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc; + printf("STS: Created local store at %p for function %p\n",spuStatus.m_lsMemory, spuStatus.m_userThreadFunc); +} + +void SequentialThreadSupport::startSPU() +{ +} + +void SequentialThreadSupport::stopSPU() +{ + m_activeSpuStatus.clear(); +} + diff --git a/Extras/BulletMultiThreaded/SequentialThreadSupport.h b/Extras/BulletMultiThreaded/SequentialThreadSupport.h new file mode 100644 index 000000000..cb8f48f1f --- /dev/null +++ b/Extras/BulletMultiThreaded/SequentialThreadSupport.h @@ -0,0 +1,84 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com + +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 "LinearMath/btScalar.h" +#include "PlatformDefinitions.h" + + +#ifndef SEQUENTIAL_THREAD_SUPPORT_H +#define SEQUENTIAL_THREAD_SUPPORT_H + +#include "LinearMath/btAlignedObjectArray.h" + +#include "btThreadSupportInterface.h" + +typedef void (*SequentialThreadFunc)(void* userPtr,void* lsMemory); +typedef void* (*SequentiallsMemorySetupFunc)(); + + + +///SequentialThreadSupport is a portable non-parallel implementation of the btThreadSupportInterface +class SequentialThreadSupport : public btThreadSupportInterface +{ +public: + struct btSpuStatus + { + uint32_t m_taskId; + uint32_t m_commandId; + uint32_t m_status; + + SequentialThreadFunc m_userThreadFunc; + + void* m_userPtr; //for taskDesc etc + void* m_lsMemory; //initialized using SequentiallsMemorySetupFunc + }; +private: + btAlignedObjectArray m_activeSpuStatus; + btAlignedObjectArray m_completeHandles; +public: + struct SequentialThreadConstructionInfo + { + SequentialThreadConstructionInfo (char* uniqueName, + SequentialThreadFunc userThreadFunc, + SequentiallsMemorySetupFunc lsMemoryFunc + ) + :m_uniqueName(uniqueName), + m_userThreadFunc(userThreadFunc), + m_lsMemoryFunc(lsMemoryFunc) + { + + } + + char* m_uniqueName; + SequentialThreadFunc m_userThreadFunc; + SequentiallsMemorySetupFunc m_lsMemoryFunc; + }; + + SequentialThreadSupport(SequentialThreadConstructionInfo& threadConstructionInfo); + virtual ~SequentialThreadSupport(); + void startThreads(SequentialThreadConstructionInfo& threadInfo); +///send messages to SPUs + virtual void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1); +///check for messages from SPUs + virtual void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1); +///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded) + virtual void startSPU(); +///tell the task scheduler we are done with the SPU tasks + virtual void stopSPU(); + +}; + +#endif //SEQUENTIAL_THREAD_SUPPORT_H + diff --git a/Extras/BulletMultiThreaded/Win32ThreadSupport.cpp b/Extras/BulletMultiThreaded/Win32ThreadSupport.cpp index 81a001342..842f3d6c9 100644 --- a/Extras/BulletMultiThreaded/Win32ThreadSupport.cpp +++ b/Extras/BulletMultiThreaded/Win32ThreadSupport.cpp @@ -46,7 +46,7 @@ Win32ThreadSupport::~Win32ThreadSupport() DWORD WINAPI Thread_no_1( LPVOID lpParam ) { - btSpuStatus* status = (btSpuStatus*)lpParam; + Win32ThreadSupport::btSpuStatus* status = (Win32ThreadSupport::btSpuStatus*)lpParam; while (1) diff --git a/Extras/BulletMultiThreaded/Win32ThreadSupport.h b/Extras/BulletMultiThreaded/Win32ThreadSupport.h index c3fc7a639..dadf645dd 100644 --- a/Extras/BulletMultiThreaded/Win32ThreadSupport.h +++ b/Extras/BulletMultiThreaded/Win32ThreadSupport.h @@ -30,33 +30,36 @@ typedef void (*Win32ThreadFunc)(void* userPtr,void* lsMemory); typedef void* (*Win32lsMemorySetupFunc)(); -///placeholder, until libspe2 support is there -struct btSpuStatus -{ - uint32_t m_taskId; - uint32_t m_commandId; - uint32_t m_status; - Win32ThreadFunc m_userThreadFunc; - void* m_userPtr; //for taskDesc etc - void* m_lsMemory; //initialized using Win32LocalStoreMemorySetupFunc - - void* m_threadHandle; //this one is calling 'Win32ThreadFunc' - - void* m_eventStartHandle; - char m_eventStartHandleName[32]; - - void* m_eventCompletetHandle; - char m_eventCompletetHandleName[32]; - - -}; ///Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication class Win32ThreadSupport : public btThreadSupportInterface { +public: + ///placeholder, until libspe2 support is there + struct btSpuStatus + { + uint32_t m_taskId; + uint32_t m_commandId; + uint32_t m_status; + + Win32ThreadFunc m_userThreadFunc; + void* m_userPtr; //for taskDesc etc + void* m_lsMemory; //initialized using Win32LocalStoreMemorySetupFunc + + void* m_threadHandle; //this one is calling 'Win32ThreadFunc' + + void* m_eventStartHandle; + char m_eventStartHandleName[32]; + + void* m_eventCompletetHandle; + char m_eventCompletetHandleName[32]; + + + }; +private: btAlignedObjectArray m_activeSpuStatus; btAlignedObjectArray m_completeHandles; diff --git a/Extras/CMakeLists.txt b/Extras/CMakeLists.txt index f48e3fba8..d520e3670 100644 --- a/Extras/CMakeLists.txt +++ b/Extras/CMakeLists.txt @@ -1 +1 @@ -SUBDIRS( BulletColladaConverter LibXML COLLADA_DOM GIMPACT ) +SUBDIRS( BulletMultiThreaded BulletColladaConverter LibXML COLLADA_DOM GIMPACT ) diff --git a/src/BulletDynamics/Vehicle/btRaycastVehicle.h b/src/BulletDynamics/Vehicle/btRaycastVehicle.h index 836e79d51..8361dcabe 100644 --- a/src/BulletDynamics/Vehicle/btRaycastVehicle.h +++ b/src/BulletDynamics/Vehicle/btRaycastVehicle.h @@ -24,9 +24,9 @@ class btVehicleTuning; class btRaycastVehicle : public btTypedConstraint { - btAlignedObjectArray m_forwardWS; - btAlignedObjectArray m_axle; - btAlignedObjectArray m_forwardImpulse; + btAlignedObjectArray m_forwardWS; + btAlignedObjectArray m_axle; + btAlignedObjectArray m_forwardImpulse; btAlignedObjectArray m_sideImpulse; public: @@ -120,7 +120,7 @@ public: void updateSuspension(btScalar deltaTime); - void updateFriction(btScalar timeStep); + virtual void updateFriction(btScalar timeStep);