Bullet Collision Detection & Physics Library
SpuSampleTaskProcess.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 #ifndef BT_SPU_SAMPLE_TASK_PROCESS_H
17 #define BT_SPU_SAMPLE_TASK_PROCESS_H
18 
19 #include <assert.h>
20 
21 
22 #include "PlatformDefinitions.h"
23 
24 #include <stdlib.h>
25 
27 
28 
30 
31 
32 //just add your commands here, try to keep them globally unique for debugging purposes
33 #define CMD_SAMPLE_TASK_COMMAND 10
34 
35 
36 
41 {
42  // track task buffers that are being used, and total busy tasks
45 
47 
48  // the current task and the current entry to insert a new work unit
50 
52 
53  void postProcess(int taskId, int outputSize);
54 
56 
58 
59 
60 
61 public:
62  SpuSampleTaskProcess(btThreadSupportInterface* threadInterface, int maxNumOutstandingTasks);
63 
65 
67  void initialize();
68 
69  void issueTask(void* sampleMainMemPtr,int sampleValue,int sampleCommand);
70 
72  void flush();
73 };
74 
75 
76 #if defined(USE_LIBSPE2) && defined(__SPU__)
77 #include "../SpuLibspe2Support.h"
79 #include <spu_intrinsics.h>
80 #include <spu_mfcio.h>
81 #include <SpuFakeDma.h>
82 
83 void * SamplelsMemoryFunc();
84 void SampleThreadFunc(void* userPtr,void* lsMemory);
85 
86 //#define DEBUG_LIBSPE2_MAINLOOP
87 
88 int main(unsigned long long speid, addr64 argp, addr64 envp)
89 {
90  printf("SPU is up \n");
91 
92  ATTRIBUTE_ALIGNED128(btSpuStatus status);
94  unsigned int received_message = Spu_Mailbox_Event_Nothing;
95  bool shutdown = false;
96 
97  cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
99 
100  status.m_status = Spu_Status_Free;
101  status.m_lsMemory.p = SamplelsMemoryFunc();
102 
103  cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
105 
106 
107  while (!shutdown)
108  {
109  received_message = spu_read_in_mbox();
110 
111 
112 
113  switch(received_message)
114  {
115  case Spu_Mailbox_Event_Shutdown:
116  shutdown = true;
117  break;
118  case Spu_Mailbox_Event_Task:
119  // refresh the status
120 #ifdef DEBUG_LIBSPE2_MAINLOOP
121  printf("SPU recieved Task \n");
122 #endif //DEBUG_LIBSPE2_MAINLOOP
123  cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
125 
126  btAssert(status.m_status==Spu_Status_Occupied);
127 
128  cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuSampleTaskDesc), DMA_TAG(3), 0, 0);
130 
131  SampleThreadFunc((void*)&taskDesc, reinterpret_cast<void*> (taskDesc.m_mainMemoryPtr) );
132  break;
133  case Spu_Mailbox_Event_Nothing:
134  default:
135  break;
136  }
137 
138  // set to status free and wait for next task
139  status.m_status = Spu_Status_Free;
140  cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
142 
143 
144  }
145  return 0;
146 }
148 #endif
149 
150 
151 
152 #endif // BT_SPU_SAMPLE_TASK_PROCESS_H
153 
SpuSampleTaskProcess(btThreadSupportInterface *threadInterface, int maxNumOutstandingTasks)
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
void postProcess(int taskId, int outputSize)
Optional PPU-size post processing for each task.
void issueTask(void *sampleMainMemPtr, int sampleValue, int sampleCommand)
#define DMA_MASK(a)
Definition: SpuFakeDma.h:113
#define btAssert(x)
Definition: btScalar.h:101
#define DMA_TAG(a)
Definition: SpuFakeDma.h:112
btAlignedObjectArray< bool > m_taskBusy
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
void initialize()
call initialize in the beginning of the frame, before addCollisionPairToTask
void cellDmaWaitTagStatusAll(int ignore)
cellDmaWaitTagStatusAll Win32 replacements for Cell DMA to allow simulating most of the SPU code (jus...
Definition: SpuFakeDma.cpp:210
void flush()
call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished...
SpuSampleTaskProcess handles SPU processing of collision pairs.
class btThreadSupportInterface * m_threadInterface
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:59
This file provides some platform/compiler checks for common definitions.
btAlignedObjectArray< SpuSampleTaskDesc > m_spuSampleTaskDesc