diff --git a/Extras/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.cpp b/Extras/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.cpp new file mode 100644 index 000000000..2ea1280ce --- /dev/null +++ b/Extras/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.cpp @@ -0,0 +1,75 @@ +/* +Bullet Continuous Collision Detection and Physics Library, Copyright (c) 2007 Erwin Coumans + +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 "SpuSampleTask.h" +#include "BulletDynamics/Dynamics/btRigidBody.h" +#include "../PlatformDefinitions.h" +#include "../SpuFakeDma.h" +#include "LinearMath/btMinMax.h" +#include + + +struct SampleTask_LocalStoreMemory +{ + +}; + + + +//-- MAIN METHOD +void processSampleTask(void* userPtr, void* lsMemory) +{ +// BT_PROFILE("processSampleTask"); + + SampleTask_LocalStoreMemory* localMemory = (SampleTask_LocalStoreMemory*)lsMemory; + + SpuSampleTaskDesc* taskDescPtr = (SpuSampleTaskDesc*)userPtr; + SpuSampleTaskDesc& taskDesc = *taskDescPtr; + + switch (taskDesc.m_sampleCommand) + { + case CMD_SAMPLE_INTEGRATE_BODIES: + { +#ifdef __SPU__ + spu_printf("hello SPU world\n"); +#else + printf("hello world\n"); +#endif + break; + } + default: + { + + } + }; +} + + +#if defined(__CELLOS_LV2__) || defined (LIBSPE2) + +ATTRIBUTE_ALIGNED16(SampleTask_LocalStoreMemory gLocalStoreMemory); + +void* createSampleLocalStoreMemory() +{ + return &gLocalStoreMemory; +} +#else +void* createSampleLocalStoreMemory() +{ + return new SampleTask_LocalStoreMemory; +}; + +#endif diff --git a/Extras/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.h b/Extras/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.h new file mode 100644 index 000000000..9c02401e5 --- /dev/null +++ b/Extras/BulletMultiThreaded/SpuSampleTask/SpuSampleTask.h @@ -0,0 +1,53 @@ +/* +Bullet Continuous Collision Detection and Physics Library, Copyright (c) 2007 Erwin Coumans + +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 SPU_SAMPLE_TASK_H +#define SPU_SAMPLE_TASK_H + +#include "../PlatformDefinitions.h" +#include "LinearMath/btScalar.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btMatrix3x3.h" + +#include "LinearMath/btAlignedAllocator.h" + + +enum +{ + CMD_SAMPLE_INTEGRATE_BODIES = 1 +}; + + + +ATTRIBUTE_ALIGNED16(struct) SpuSampleTaskDesc +{ + BT_DECLARE_ALIGNED_ALLOCATOR(); + + uint32_t m_sampleCommand; + uint32_t m_taskId; + + uint64_t m_mainMemoryPtr; + int m_sampleValue; + + +}; + + +void processSampleTask(void* userPtr, void* lsMemory); +void* createSampleLocalStoreMemory(); + + +#endif //SPU_SAMPLE_TASK_H + diff --git a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp index e8556f75c..351d0fc7a 100644 --- a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp +++ b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp @@ -105,7 +105,7 @@ void SpuSampleTaskProcess::initialize() } -void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue) +void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue,int sampleCommand) { #ifdef DEBUG_SPU_TASK_SCHEDULING @@ -123,13 +123,14 @@ void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue) taskDesc.m_mainMemoryPtr = reinterpret_cast(sampleMainMemPtr); taskDesc.m_sampleValue = sampleValue; + taskDesc.m_sampleCommand = sampleCommand; //some bookkeeping to recognize finished tasks taskDesc.m_taskId = m_currentTask; } - m_threadInterface->sendRequest(CMD_SAMPLE_TASK_COMMAND, (uint32_t) &taskDesc, m_currentTask); + m_threadInterface->sendRequest(1, (uint32_t) &taskDesc, m_currentTask); // if all tasks busy, wait for spu event to clear the task. diff --git a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h index 473f80489..d4cba3adf 100644 --- a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h +++ b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h @@ -26,18 +26,8 @@ subject to the following restrictions: #include "LinearMath/btAlignedObjectArray.h" -///SpuSampleTaskDesc -struct SpuSampleTaskDesc -{ - uint64_t m_mainMemoryPtr; - int m_sampleValue; - - uint16_t m_taskId; -} -#if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2) -__attribute__ ((aligned (16))) -#endif -; +#include "SpuSampleTask/SpuSampleTask.h" + //just add your commands here, try to keep them globally unique for debugging purposes #define CMD_SAMPLE_TASK_COMMAND 10 @@ -76,7 +66,7 @@ public: ///call initialize in the beginning of the frame, before addCollisionPairToTask void initialize(); - void issueTask(void* sampleMainMemPtr,int sampleValue); + void issueTask(void* sampleMainMemPtr,int sampleValue,int sampleCommand); ///call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished void flush(); diff --git a/src/LinearMath/btQuadWord.h b/src/LinearMath/btQuadWord.h index 2e5950ebd..c14481928 100644 --- a/src/LinearMath/btQuadWord.h +++ b/src/LinearMath/btQuadWord.h @@ -18,6 +18,14 @@ subject to the following restrictions: #include "btScalar.h" #include "btMinMax.h" +#include +#ifdef __PPU__ +#include +#endif + +#ifdef __SPU__ +#include +#endif //ATTRIBUTE_ALIGNED16(class) btQuadWordStorage //some issues under PS3 Linux with IBM 2.1 SDK, gcc compiler prevent from using aligned quadword. todo: look into this @@ -25,10 +33,35 @@ subject to the following restrictions: class btQuadWordStorage { protected: +#if defined __PPU__ || defined __SPU__ + union { + vec_float4 m_Vec128; + struct + { +#endif btScalar m_x; btScalar m_y; btScalar m_z; btScalar m_unusedW; +#if defined __PPU__ || defined __SPU__ + }; + }; +#endif + +public: +#if defined __PPU__ || defined __SPU__ + + inline const vec_float4 get128( ) const + { + return m_Vec128; + } + + inline vec_float4 get128( ) + { + return m_Vec128; + } +#endif // + }; diff --git a/src/LinearMath/btVector3.h b/src/LinearMath/btVector3.h index 1e331272d..d68e0279f 100644 --- a/src/LinearMath/btVector3.h +++ b/src/LinearMath/btVector3.h @@ -47,7 +47,14 @@ public: SIMD_FORCE_INLINE btVector3& operator+=(const btVector3& v) { + +#ifdef __PPU__ + m_Vec128 = vec_add( m_Vec128, v.get128() ); +#elif defined __SPU__ + m_Vec128 = spu_add( m_Vec128, v.get128() ); +#else m_x += v.x(); m_y += v.y(); m_z += v.z(); +#endif return *this; }