Bullet Collision Detection & Physics Library
MiniCLTaskScheduler.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4 
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:
10 
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.
14 */
15 
16 
17 
18 #ifndef MINICL_TASK_SCHEDULER_H
19 #define MINICL_TASK_SCHEDULER_H
20 
21 #include <assert.h>
22 
23 
25 
26 #include <stdlib.h>
27 
29 
30 
31 #include "MiniCLTask/MiniCLTask.h"
32 
33 //just add your commands here, try to keep them globally unique for debugging purposes
34 #define CMD_SAMPLE_TASK_COMMAND 10
35 
36 struct MiniCLKernel;
37 
42 {
43  // track task buffers that are being used, and total busy tasks
46 
47 
49 
50 
52 
53  // the current task and the current entry to insert a new work unit
55 
57 
58  void postProcess(int taskId, int outputSize);
59 
61 
63 
64 
65 
66 public:
67  MiniCLTaskScheduler(btThreadSupportInterface* threadInterface, int maxNumOutstandingTasks);
68 
70 
72  void initialize();
73 
74  void issueTask(int firstWorkUnit, int lastWorkUnit, MiniCLKernel* kernel);
75 
77  void flush();
78 
80  {
81  return m_threadInterface;
82  }
83 
84  int findProgramCommandIdByName(const char* programName) const;
85 
87  {
89  }
90 
92  {
93  m_kernels.push_back(kernel);
94  }
95 };
96 
97 typedef void (*kernelLauncherCB)(MiniCLTaskDesc* taskDesc, int guid);
98 
100 {
102 
103 // int m_kernelProgramCommandId;
104 
106  unsigned int m_numArgs;
108  void* m_pCode;
109  void updateLauncher();
111 
114 };
115 
116 
117 #if defined(USE_LIBSPE2) && defined(__SPU__)
118 #include "../SpuLibspe2Support.h"
120 #include <spu_intrinsics.h>
121 #include <spu_mfcio.h>
122 #include <SpuFakeDma.h>
123 
124 void * SamplelsMemoryFunc();
125 void SampleThreadFunc(void* userPtr,void* lsMemory);
126 
127 //#define DEBUG_LIBSPE2_MAINLOOP
128 
129 int main(unsigned long long speid, addr64 argp, addr64 envp)
130 {
131  printf("SPU is up \n");
132 
133  ATTRIBUTE_ALIGNED128(btSpuStatus status);
135  unsigned int received_message = Spu_Mailbox_Event_Nothing;
136  bool shutdown = false;
137 
138  cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
140 
141  status.m_status = Spu_Status_Free;
142  status.m_lsMemory.p = SamplelsMemoryFunc();
143 
144  cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
146 
147 
148  while (!shutdown)
149  {
150  received_message = spu_read_in_mbox();
151 
152 
153 
154  switch(received_message)
155  {
156  case Spu_Mailbox_Event_Shutdown:
157  shutdown = true;
158  break;
159  case Spu_Mailbox_Event_Task:
160  // refresh the status
161 #ifdef DEBUG_LIBSPE2_MAINLOOP
162  printf("SPU recieved Task \n");
163 #endif //DEBUG_LIBSPE2_MAINLOOP
164  cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
166 
167  btAssert(status.m_status==Spu_Status_Occupied);
168 
169  cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuSampleTaskDesc), DMA_TAG(3), 0, 0);
171 
172  SampleThreadFunc((void*)&taskDesc, reinterpret_cast<void*> (taskDesc.m_mainMemoryPtr) );
173  break;
174  case Spu_Mailbox_Event_Nothing:
175  default:
176  break;
177  }
178 
179  // set to status free and wait for next task
180  status.m_status = Spu_Status_Free;
181  cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
183 
184 
185  }
186  return 0;
187 }
189 #endif
190 
191 
192 
193 #endif // MINICL_TASK_SCHEDULER_H
194 
int m_argSizes[MINI_CL_MAX_ARG]
void push_back(const T &_Val)
char m_name[MINI_CL_MAX_KERNEL_NAME]
int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
Definition: SpuFakeDma.cpp:173
#define ATTRIBUTE_ALIGNED128(a)
Definition: btScalar.h:61
class btThreadSupportInterface * m_threadInterface
#define DMA_MASK(a)
Definition: SpuFakeDma.h:113
#define btAssert(x)
Definition: btScalar.h:101
#define DMA_TAG(a)
Definition: SpuFakeDma.h:112
int cellDmaLargePut(const void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
cellDmaLargePut Win32 replacements for Cell DMA to allow simulating most of the SPU code (just memcpy...
Definition: SpuFakeDma.cpp:192
MiniCLTaskScheduler handles SPU processing of collision pairs.
btAlignedObjectArray< bool > m_taskBusy
unsigned int m_numArgs
int getMaxNumOutstandingTasks() const
void registerKernel(MiniCLKernel *kernel)
void postProcess(int taskId, int outputSize)
Optional PPU-size post processing for each task.
void cellDmaWaitTagStatusAll(int ignore)
cellDmaWaitTagStatusAll Win32 replacements for Cell DMA to allow simulating most of the SPU code (jus...
Definition: SpuFakeDma.cpp:210
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:59
void issueTask(int firstWorkUnit, int lastWorkUnit, MiniCLKernel *kernel)
btAlignedObjectArray< MiniCLTaskDesc > m_spuSampleTaskDesc
This file provides some platform/compiler checks for common definitions.
class btThreadSupportInterface * getThreadSupportInterface()
MiniCLTaskScheduler * m_scheduler
int findProgramCommandIdByName(const char *programName) const
void flush()
call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished...
void(* kernelLauncherCB)(MiniCLTaskDesc *taskDesc, int guid)
void * m_argData[MINI_CL_MAX_ARG]
void initialize()
call initialize in the beginning of the frame, before addCollisionPairToTask
#define MINI_CL_MAX_KERNEL_NAME
Definition: MiniCLTask.h:27
MiniCLKernel * registerSelf()
btAlignedObjectArray< const MiniCLKernel * > m_kernels
#define MINI_CL_MAX_ARG
Definition: MiniCLTask.h:26
MiniCLTaskScheduler(btThreadSupportInterface *threadInterface, int maxNumOutstandingTasks)
kernelLauncherCB m_launcher