some changes towards libspe2 support
This commit is contained in:
@@ -23,9 +23,11 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
///SpuLibspe2Support helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
|
///SpuLibspe2Support helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
|
||||||
///Setup and initialize SPU/CELL/Libspe2
|
///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);
|
startSPUs(numThreads);
|
||||||
|
N = numThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
///cleanup/shutdown Libspe2
|
///cleanup/shutdown Libspe2
|
||||||
@@ -38,6 +40,7 @@ SpuLibspe2Support::~SpuLibspe2Support()
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
DWORD WINAPI Thread_no_1( LPVOID lpParam )
|
DWORD WINAPI Thread_no_1( LPVOID lpParam )
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -66,7 +69,7 @@ DWORD WINAPI Thread_no_1( LPVOID lpParam )
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
///send messages to SPUs
|
///send messages to SPUs
|
||||||
void SpuLibspe2Support::sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1)
|
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)
|
void SpuLibspe2Support::startSPUs(int numThreads)
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32
|
||||||
m_activeSpuStatus.resize(numThreads);
|
m_activeSpuStatus.resize(numThreads);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i=0;i<numThreads;i++)
|
for (int i=0;i<numThreads;i++)
|
||||||
{
|
{
|
||||||
printf("starting thread %d\n",i);
|
printf("starting thread %d\n",i);
|
||||||
|
|
||||||
btSpuStatus& spuStatus = m_activeSpuStatus[i];
|
data[i].context = spe_context_create(0, NULL);
|
||||||
|
spe_program_load(data[i].context, program);
|
||||||
LPSECURITY_ATTRIBUTES lpThreadAttributes=NULL;
|
data[i].entry = SPE_DEFAULT_ENTRY;
|
||||||
SIZE_T dwStackSize=65535;
|
data[i].flags = 0;
|
||||||
LPTHREAD_START_ROUTINE lpStartAddress=&Thread_no_1;
|
data[i].argp = NULL;
|
||||||
LPVOID lpParameter=&spuStatus;
|
data[i].envp = NULL;
|
||||||
DWORD dwCreationFlags=0;
|
pthread_create(&data[i].pthread, NULL, &ppu_pthread_function, &data[i]);
|
||||||
LPDWORD lpThreadId=0;
|
|
||||||
|
|
||||||
spuStatus.m_taskDesc = 0;
|
|
||||||
|
|
||||||
sprintf(spuStatus.m_eventStartHandleName,"eventStart%d",i);
|
|
||||||
spuStatus.m_eventStartHandle = CreateEvent(0,false,false,spuStatus.m_eventStartHandleName);
|
|
||||||
|
|
||||||
sprintf(spuStatus.m_eventCompletetHandleName,"eventComplete%d",i);
|
|
||||||
spuStatus.m_eventCompletetHandle = CreateEvent(0,false,false,spuStatus.m_eventCompletetHandleName);
|
|
||||||
|
|
||||||
|
|
||||||
HANDLE handle = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter, dwCreationFlags,lpThreadId);
|
|
||||||
SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL);
|
|
||||||
|
|
||||||
spuStatus.m_taskId = i;
|
|
||||||
spuStatus.m_commandId = 0;
|
|
||||||
spuStatus.m_status = 0;
|
|
||||||
spuStatus.m_threadHandle = handle;
|
|
||||||
spuStatus.m_lsMemory = createLocalStoreMemory();
|
|
||||||
|
|
||||||
printf("started thread %d with threadHandle %d\n",i,handle);
|
printf("started thread %d with threadHandle %d\n",i,handle);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -214,9 +198,17 @@ void SpuLibspe2Support::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 SpuLibspe2Support::stopSPUs()
|
void SpuLibspe2Support::stopSPUs()
|
||||||
{
|
{
|
||||||
// m_activeSpuStatus.pop_back();
|
// wait for all threads to finish
|
||||||
// WaitForSingleObject(spuStatus.bla, INFINITE);
|
for ( i=0; i<N; i++ ) {
|
||||||
// CloseHandle(spuStatus.m_threadHandle);
|
pthread_join (data[i].pthread, NULL);
|
||||||
|
}
|
||||||
|
// close SPE program
|
||||||
|
spe_image_close(program);
|
||||||
|
// destroy SPE contexts
|
||||||
|
for ( i=0; i<N; i++ ) {
|
||||||
|
spe_context_destroy (data[i].context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ subject to the following restrictions:
|
|||||||
#define SPU_LIBSPE2_SUPPORT_H
|
#define SPU_LIBSPE2_SUPPORT_H
|
||||||
|
|
||||||
#include "LinearMath/btAlignedObjectArray.h"
|
#include "LinearMath/btAlignedObjectArray.h"
|
||||||
|
#include <libspe2.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,6 +33,7 @@ subject to the following restrictions:
|
|||||||
* Mixing up these values will cause the wrong code to execute, for instance, the
|
* Mixing up these values will cause the wrong code to execute, for instance, the
|
||||||
* solver may be asked to do a collision detection job.
|
* 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 {
|
typedef enum {
|
||||||
SPU_ELF_COLLISION_DETECTION=0,
|
SPU_ELF_COLLISION_DETECTION=0,
|
||||||
SPU_ELF_SAMPLE,
|
SPU_ELF_SAMPLE,
|
||||||
@@ -38,7 +41,7 @@ typedef enum {
|
|||||||
//SPU_ELF_SOLVER,
|
//SPU_ELF_SOLVER,
|
||||||
SPU_ELF_LAST,
|
SPU_ELF_LAST,
|
||||||
} SpuLibspe2ElfId_t;
|
} SpuLibspe2ElfId_t;
|
||||||
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#define memalign(alignment, size) malloc(size);
|
#define memalign(alignment, size) malloc(size);
|
||||||
@@ -46,6 +49,27 @@ typedef enum {
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif // WIN32
|
#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 <LinearMath/btScalar.h> //for uint32_t etc.
|
#include <LinearMath/btScalar.h> //for uint32_t etc.
|
||||||
@@ -78,8 +102,13 @@ class SpuLibspe2Support {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
///Setup and initialize SPU/CELL/Libspe2
|
///Setup and initialize SPU/CELL/Libspe2
|
||||||
SpuLibspe2Support(SpuLibspe2ElfId_t elfId,int numThreads);
|
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
|
///cleanup/shutdown Libspe2
|
||||||
~SpuLibspe2Support();
|
~SpuLibspe2Support();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user