2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
5
This software is provided 'as-is', without any express or implied warranty.
6
In no event will the authors be held liable for any damages arising from the use of this software.
7
Permission is granted to anyone to use this software for any purpose,
8
including commercial applications, and to alter it and redistribute it freely,
9
subject to the following restrictions:
11
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.
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
3. This notice may not be removed or altered from any source distribution.
16
//#define __CELLOS_LV2__ 1
18
#define USE_SAMPLE_PROCESS 1
19
#ifdef USE_SAMPLE_PROCESS
22
#include "SpuSampleTaskProcess.h"
29
void SampleThreadFunc(void* userPtr,void* lsMemory)
32
printf("hello world\n");
36
void* SamplelsMemoryFunc()
38
//don't create local store memory, just return 0
46
#include "btThreadSupportInterface.h"
48
//# include "SPUAssert.h"
54
extern char SPU_SAMPLE_ELF_SYMBOL[];
61
SpuSampleTaskProcess::SpuSampleTaskProcess(btThreadSupportInterface* threadInterface, int maxNumOutstandingTasks)
62
:m_threadInterface(threadInterface),
63
m_maxNumOutstandingTasks(maxNumOutstandingTasks)
66
m_taskBusy.resize(m_maxNumOutstandingTasks);
67
m_spuSampleTaskDesc.resize(m_maxNumOutstandingTasks);
69
for (int i = 0; i < m_maxNumOutstandingTasks; i++)
71
m_taskBusy[i] = false;
76
m_initialized = false;
78
m_threadInterface->startSPU();
83
SpuSampleTaskProcess::~SpuSampleTaskProcess()
85
m_threadInterface->stopSPU();
91
void SpuSampleTaskProcess::initialize()
93
#ifdef DEBUG_SPU_TASK_SCHEDULING
94
printf("SpuSampleTaskProcess::initialize()\n");
95
#endif //DEBUG_SPU_TASK_SCHEDULING
97
for (int i = 0; i < m_maxNumOutstandingTasks; i++)
99
m_taskBusy[i] = false;
103
m_initialized = true;
108
void SpuSampleTaskProcess::issueTask(void* sampleMainMemPtr,int sampleValue,int sampleCommand)
111
#ifdef DEBUG_SPU_TASK_SCHEDULING
112
printf("SpuSampleTaskProcess::issueTask (m_currentTask= %d\)n", m_currentTask);
113
#endif //DEBUG_SPU_TASK_SCHEDULING
115
m_taskBusy[m_currentTask] = true;
118
SpuSampleTaskDesc& taskDesc = m_spuSampleTaskDesc[m_currentTask];
120
// send task description in event message
121
// no error checking here...
122
// but, currently, event queue can be no larger than NUM_WORKUNIT_TASKS.
124
taskDesc.m_mainMemoryPtr = reinterpret_cast<uint64_t>(sampleMainMemPtr);
125
taskDesc.m_sampleValue = sampleValue;
126
taskDesc.m_sampleCommand = sampleCommand;
128
//some bookkeeping to recognize finished tasks
129
taskDesc.m_taskId = m_currentTask;
133
m_threadInterface->sendRequest(1, (ppu_address_t) &taskDesc, m_currentTask);
135
// if all tasks busy, wait for spu event to clear the task.
137
if (m_numBusyTasks >= m_maxNumOutstandingTasks)
140
unsigned int outputSize;
142
for (int i=0;i<m_maxNumOutstandingTasks;i++)
150
m_threadInterface->waitForResponse(&taskId, &outputSize);
152
//printf("PPU: after issue, received event: %u %d\n", taskId, outputSize);
154
postProcess(taskId, outputSize);
156
m_taskBusy[taskId] = false;
161
// find new task buffer
162
for (int i = 0; i < m_maxNumOutstandingTasks; i++)
173
///Optional PPU-size post processing for each task
174
void SpuSampleTaskProcess::postProcess(int taskId, int outputSize)
180
void SpuSampleTaskProcess::flush()
182
#ifdef DEBUG_SPU_TASK_SCHEDULING
183
printf("\nSpuCollisionTaskProcess::flush()\n");
184
#endif //DEBUG_SPU_TASK_SCHEDULING
187
// all tasks are issued, wait for all tasks to be complete
188
while(m_numBusyTasks > 0)
190
// Consolidating SPU code
192
unsigned int outputSize;
194
for (int i=0;i<m_maxNumOutstandingTasks;i++)
204
m_threadInterface->waitForResponse(&taskId, &outputSize);
207
//printf("PPU: flushing, received event: %u %d\n", taskId, outputSize);
209
postProcess(taskId, outputSize);
211
m_taskBusy[taskId] = false;
222
#endif //USE_SAMPLE_PROCESS