diff --git a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp index 6aacc2480..89f3ae40b 100644 --- a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp +++ b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.cpp @@ -14,12 +14,12 @@ subject to the following restrictions: */ //#define __CELLOS_LV2__ 1 + +#define USE_SAMPLE_PROCESS 1 #ifdef USE_SAMPLE_PROCESS - -#include "SpuLibspe2Support.h" -#include "Win32ThreadSupport.h" +#include "btThreadSupportInterface.h" //#include "SPUAssert.h" #include @@ -43,20 +43,6 @@ void* SamplelsMemoryFunc() return 0; } -#ifdef USE_IBM_CELL_SDK -//SpuLibspe2Support gSampleSPU(SPU_ELF_SAMPLE,SAMPLE_NUM_WORKUNIT_TASKS); -#elif defined(WIN32) -Win32ThreadSupport gSampleSPU(Win32ThreadSupport::Win32ThreadConstructionInfo("sample", - SampleThreadFunc, - SamplelsMemoryFunc, - SAMPLE_NUM_WORKUNIT_TASKS)); -#elif defined(__CELLOS_LV2__) - -#include "CellSPURSSupport.ppu.h" -CellSPURSSupport gSampleSPU(SPU_ELF_SAMPLE); - -#endif - extern "C" { @@ -67,14 +53,15 @@ extern "C" { -//SpuSampleTaskDesc g_spuSampleTaskDesc[SAMPLE_NUM_WORKUNIT_TASKS]; - - - -SpuSampleTaskProcess::SpuSampleTaskProcess() +SpuSampleTaskProcess::SpuSampleTaskProcess(btThreadSupportInterface* threadInterface, unsigned int maxNumOutstandingTasks) +:m_threadInterface(threadInterface), +m_maxNumOutstandingTasks(maxNumOutstandingTasks) { - for (int i = 0; i < SAMPLE_NUM_WORKUNIT_TASKS; i++) + m_taskBusy.resize(m_maxNumOutstandingTasks); + m_spuSampleTaskDesc.resize(m_maxNumOutstandingTasks); + + for (int i = 0; i < m_maxNumOutstandingTasks; i++) { m_taskBusy[i] = false; } @@ -85,20 +72,12 @@ SpuSampleTaskProcess::SpuSampleTaskProcess() m_threadInterface->startSPU(); -#ifdef WIN32 - Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo( - "sample",SampleThreadFunc,SamplelsMemoryFunc); - - gSampleSPU.startSPU(threadConstructionInfo); -#else - gSampleSPU.startSPU(); -#endif } SpuSampleTaskProcess::~SpuSampleTaskProcess() { - gSampleSPU.stopSPU(); + m_threadInterface->stopSPU(); } @@ -110,7 +89,7 @@ void SpuSampleTaskProcess::initialize() printf("SpuSampleTaskProcess::initialize()\n"); #endif //DEBUG_SPU_TASK_SCHEDULING - for (int i = 0; i < SAMPLE_NUM_WORKUNIT_TASKS; i++) + for (int i = 0; i < m_maxNumOutstandingTasks; i++) { m_taskBusy[i] = false; } @@ -131,7 +110,7 @@ void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue) m_taskBusy[m_currentTask] = true; m_numBusyTasks++; - SpuSampleTaskDesc& taskDesc = g_spuSampleTaskDesc[m_currentTask]; + SpuSampleTaskDesc& taskDesc = m_spuSampleTaskDesc[m_currentTask]; { // send task description in event message // no error checking here... @@ -145,16 +124,16 @@ void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue) } - gSampleSPU.sendRequest(CMD_SAMPLE_TASK_COMMAND, (uint32_t) &taskDesc, m_currentTask); + m_threadInterface->sendRequest(CMD_SAMPLE_TASK_COMMAND, (uint32_t) &taskDesc, m_currentTask); // if all tasks busy, wait for spu event to clear the task. - if (m_numBusyTasks >= SAMPLE_NUM_WORKUNIT_TASKS) + if (m_numBusyTasks >= m_maxNumOutstandingTasks) { unsigned int taskId; unsigned int outputSize; - gSampleSPU.waitForResponse(&taskId, &outputSize); + m_threadInterface->waitForResponse(&taskId, &outputSize); //printf("PPU: after issue, received event: %u %d\n", taskId, outputSize); @@ -166,7 +145,7 @@ void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue) } // find new task buffer - for (unsigned int i = 0; i < SAMPLE_NUM_WORKUNIT_TASKS; i++) + for (unsigned int i = 0; i < m_maxNumOutstandingTasks; i++) { if (!m_taskBusy[i]) { @@ -200,7 +179,7 @@ void SpuSampleTaskProcess::flush() { - gSampleSPU.waitForResponse(&taskId, &outputSize); + m_threadInterface->waitForResponse(&taskId, &outputSize); } //printf("PPU: flushing, received event: %u %d\n", taskId, outputSize); diff --git a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h index 144ad2449..fffd55785 100644 --- a/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h +++ b/Extras/BulletMultiThreaded/SpuSampleTaskProcess.h @@ -23,9 +23,7 @@ subject to the following restrictions: #include -///maximum outstanding tasks -#define SAMPLE_NUM_WORKUNIT_TASKS 4 - +#include "LinearMath/btAlignedObjectArray.h" ///SpuSampleTaskDesc @@ -52,7 +50,9 @@ __attribute__ ((aligned (16))) class SpuSampleTaskProcess { // track task buffers that are being used, and total busy tasks - bool m_taskBusy[SAMPLE_NUM_WORKUNIT_TASKS]; + btAlignedObjectArray m_taskBusy; + btAlignedObjectArraym_spuSampleTaskDesc; + unsigned int m_numBusyTasks; // the current task and the current entry to insert a new work unit @@ -62,9 +62,14 @@ class SpuSampleTaskProcess void postProcess(int taskId, int outputSize); + class btThreadSupportInterface* m_threadInterface; + + unsigned int m_maxNumOutstandingTasks; + + public: - SpuSampleTaskProcess(); + SpuSampleTaskProcess(btThreadSupportInterface* threadInterface, unsigned int maxNumOutstandingTasks); ~SpuSampleTaskProcess();