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 #ifndef BT_SPU_SAMPLE_TASK_PROCESS_H
17 #define BT_SPU_SAMPLE_TASK_PROCESS_H
22 #include "PlatformDefinitions.h"
26 #include "LinearMath/btAlignedObjectArray.h"
29 #include "SpuSampleTask/SpuSampleTask.h"
32 //just add your commands here, try to keep them globally unique for debugging purposes
33 #define CMD_SAMPLE_TASK_COMMAND 10
37 /// SpuSampleTaskProcess handles SPU processing of collision pairs.
38 /// When PPU issues a task, it will look for completed task buffers
39 /// PPU will do postprocessing, dependent on workunit output (not likely)
40 class SpuSampleTaskProcess
42 // track task buffers that are being used, and total busy tasks
43 btAlignedObjectArray<bool> m_taskBusy;
44 btAlignedObjectArray<SpuSampleTaskDesc>m_spuSampleTaskDesc;
48 // the current task and the current entry to insert a new work unit
53 void postProcess(int taskId, int outputSize);
55 class btThreadSupportInterface* m_threadInterface;
57 int m_maxNumOutstandingTasks;
62 SpuSampleTaskProcess(btThreadSupportInterface* threadInterface, int maxNumOutstandingTasks);
64 ~SpuSampleTaskProcess();
66 ///call initialize in the beginning of the frame, before addCollisionPairToTask
69 void issueTask(void* sampleMainMemPtr,int sampleValue,int sampleCommand);
71 ///call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished
76 #if defined(USE_LIBSPE2) && defined(__SPU__)
77 ////////////////////MAIN/////////////////////////////
78 #include "../SpuLibspe2Support.h"
79 #include <spu_intrinsics.h>
80 #include <spu_mfcio.h>
81 #include <SpuFakeDma.h>
83 void * SamplelsMemoryFunc();
84 void SampleThreadFunc(void* userPtr,void* lsMemory);
86 //#define DEBUG_LIBSPE2_MAINLOOP
88 int main(unsigned long long speid, addr64 argp, addr64 envp)
90 printf("SPU is up \n");
92 ATTRIBUTE_ALIGNED128(btSpuStatus status);
93 ATTRIBUTE_ALIGNED16( SpuSampleTaskDesc taskDesc ) ;
94 unsigned int received_message = Spu_Mailbox_Event_Nothing;
95 bool shutdown = false;
97 cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
98 cellDmaWaitTagStatusAll(DMA_MASK(3));
100 status.m_status = Spu_Status_Free;
101 status.m_lsMemory.p = SamplelsMemoryFunc();
103 cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
104 cellDmaWaitTagStatusAll(DMA_MASK(3));
109 received_message = spu_read_in_mbox();
113 switch(received_message)
115 case Spu_Mailbox_Event_Shutdown:
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);
124 cellDmaWaitTagStatusAll(DMA_MASK(3));
126 btAssert(status.m_status==Spu_Status_Occupied);
128 cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuSampleTaskDesc), DMA_TAG(3), 0, 0);
129 cellDmaWaitTagStatusAll(DMA_MASK(3));
131 SampleThreadFunc((void*)&taskDesc, reinterpret_cast<void*> (taskDesc.m_mainMemoryPtr) );
133 case Spu_Mailbox_Event_Nothing:
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);
141 cellDmaWaitTagStatusAll(DMA_MASK(3));
147 //////////////////////////////////////////////////////
152 #endif // BT_SPU_SAMPLE_TASK_PROCESS_H