From 620b67b7529fbd72ba5b8ecb352420b5afbc91a9 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Mon, 13 Aug 2007 04:27:36 +0000 Subject: [PATCH] some changes towards libspe2 support --- .../BulletMultiThreaded/SpuLibspe2Support.cpp | 60 ++++++++----------- .../BulletMultiThreaded/SpuLibspe2Support.h | 47 ++++++++++++--- 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/Extras/BulletMultiThreaded/SpuLibspe2Support.cpp b/Extras/BulletMultiThreaded/SpuLibspe2Support.cpp index f22428ca2..daef6fc11 100644 --- a/Extras/BulletMultiThreaded/SpuLibspe2Support.cpp +++ b/Extras/BulletMultiThreaded/SpuLibspe2Support.cpp @@ -23,9 +23,11 @@ subject to the following restrictions: ///SpuLibspe2Support helps to initialize/shutdown libspe2, start/stop SPU tasks and communication ///Setup and initialize SPU/CELL/Libspe2 -SpuLibspe2Support::SpuLibspe2Support(SpuLibspe2ElfId_t elfId,int numThreads) +SpuLibspe2Support::SpuLibspe2Support(spe_program_handle_t *speprog,int numThreads) { + program = speprog startSPUs(numThreads); + N = numThreads; } ///cleanup/shutdown Libspe2 @@ -38,6 +40,7 @@ SpuLibspe2Support::~SpuLibspe2Support() #include +#ifdef WIN32 DWORD WINAPI Thread_no_1( LPVOID lpParam ) { @@ -66,7 +69,7 @@ DWORD WINAPI Thread_no_1( LPVOID lpParam ) return 0; } - +#endif ///send messages to SPUs void SpuLibspe2Support::sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1) { @@ -168,43 +171,24 @@ void SpuLibspe2Support::waitForResponse(unsigned int *puiArgument0, unsigned int } -///start the spus group (can be called at the beginning of each frame, to make sure that the right SPU program is loaded) +///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded) void SpuLibspe2Support::startSPUs(int numThreads) { - +#ifdef WIN32 m_activeSpuStatus.resize(numThreads); +#endif for (int i=0;i +#include /** @@ -31,6 +33,7 @@ subject to the following restrictions: * Mixing up these values will cause the wrong code to execute, for instance, the * solver may be asked to do a collision detection job. */ +#ifdef WIN32 // original enum, but for libspe2 will pass the SPE program handle ptr directly typedef enum { SPU_ELF_COLLISION_DETECTION=0, SPU_ELF_SAMPLE, @@ -38,7 +41,7 @@ typedef enum { //SPU_ELF_SOLVER, SPU_ELF_LAST, } SpuLibspe2ElfId_t; - +#endif #ifdef WIN32 #include #define memalign(alignment, size) malloc(size); @@ -46,6 +49,27 @@ typedef enum { #include #endif // WIN32 +#define MAXSPUS 16 +typedef struct ppu_pthread_data { +spe_context_ptr_t context; +pthread_t pthread; +unsigned int entry; +unsigned int flags; +void *argp; +void *envp; +spe_stop_info_t stopinfo; +} ppu_pthread_data_t; + +void *ppu_pthread_function(void *arg) +{ + ppu_pthread_data_t datap = *(ppu_pthread_data_t *)arg; + int rc; + do { + rc = spe_context_run(datap->context, &datap->entry, datap->flags, datap->argp, datap->envp, &datap->stopinfo); + } while (rc > 0); // loop until exit or error, and while any stop & signal + pthread_exit(NULL); +} + #include //for uint32_t etc. @@ -78,25 +102,30 @@ class SpuLibspe2Support { public: ///Setup and initialize SPU/CELL/Libspe2 - SpuLibspe2Support(SpuLibspe2ElfId_t elfId,int numThreads); - -///cleanup/shutdown Libspe2 + SpuLibspe2Support(spe_program_handle_t *speprog,int numThreads); + // SPE program handle ptr. + spe_program_handle_t *program; + // SPE program data + ppu_pthread_data_t data[MAX_SPUS]; + // num SPE Threads + unsigned int N; + ///cleanup/shutdown Libspe2 ~SpuLibspe2Support(); -///send messages to SPUs + ///send messages to SPUs void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1=0); -///check for messages from SPUs + ///check for messages from SPUs 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) + ///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded) void startSPUs(int numThreads); -///tell the task scheduler we are done with the SPU tasks + ///tell the task scheduler we are done with the SPU tasks void stopSPUs(); }; #endif //SPU_LIBSPE2_SUPPORT_H -#endif //USE_LIBSPE2 \ No newline at end of file +#endif //USE_LIBSPE2