Added portable non-parallel implementation for btThreadSupportInterface: SequentialThreadSupport, Thanks John McCutchan (JMC)
Added CMake support for BulletMultiThreaded.
This commit is contained in:
53
Extras/BulletMultiThreaded/CMakeLists.txt
Normal file
53
Extras/BulletMultiThreaded/CMakeLists.txt
Normal file
@@ -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
|
||||||
|
)
|
||||||
92
Extras/BulletMultiThreaded/SequentialThreadSupport.cpp
Normal file
92
Extras/BulletMultiThreaded/SequentialThreadSupport.cpp
Normal file
@@ -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 <stdio.h>
|
||||||
|
|
||||||
|
///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();
|
||||||
|
}
|
||||||
|
|
||||||
84
Extras/BulletMultiThreaded/SequentialThreadSupport.h
Normal file
84
Extras/BulletMultiThreaded/SequentialThreadSupport.h
Normal file
@@ -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<btSpuStatus> m_activeSpuStatus;
|
||||||
|
btAlignedObjectArray<void*> 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
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ Win32ThreadSupport::~Win32ThreadSupport()
|
|||||||
DWORD WINAPI Thread_no_1( LPVOID lpParam )
|
DWORD WINAPI Thread_no_1( LPVOID lpParam )
|
||||||
{
|
{
|
||||||
|
|
||||||
btSpuStatus* status = (btSpuStatus*)lpParam;
|
Win32ThreadSupport::btSpuStatus* status = (Win32ThreadSupport::btSpuStatus*)lpParam;
|
||||||
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ typedef void (*Win32ThreadFunc)(void* userPtr,void* lsMemory);
|
|||||||
typedef void* (*Win32lsMemorySetupFunc)();
|
typedef void* (*Win32lsMemorySetupFunc)();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
|
||||||
|
class Win32ThreadSupport : public btThreadSupportInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
///placeholder, until libspe2 support is there
|
///placeholder, until libspe2 support is there
|
||||||
struct btSpuStatus
|
struct btSpuStatus
|
||||||
{
|
{
|
||||||
@@ -51,12 +59,7 @@ struct btSpuStatus
|
|||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
///Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
|
|
||||||
class Win32ThreadSupport : public btThreadSupportInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
|
btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
|
||||||
btAlignedObjectArray<void*> m_completeHandles;
|
btAlignedObjectArray<void*> m_completeHandles;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
SUBDIRS( BulletColladaConverter LibXML COLLADA_DOM GIMPACT )
|
SUBDIRS( BulletMultiThreaded BulletColladaConverter LibXML COLLADA_DOM GIMPACT )
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public:
|
|||||||
|
|
||||||
void updateSuspension(btScalar deltaTime);
|
void updateSuspension(btScalar deltaTime);
|
||||||
|
|
||||||
void updateFriction(btScalar timeStep);
|
virtual void updateFriction(btScalar timeStep);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user