2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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 SPU_GATHERING_COLLISION_TASK_H
17 #define SPU_GATHERING_COLLISION_TASK_H
19 #include "../PlatformDefinitions.h"
20 //#define DEBUG_SPU_COLLISION_DETECTION 1
23 ///Task Description for SPU collision detection
24 struct SpuGatherAndProcessPairsTaskDesc
26 ppu_address_t m_inPairPtr;//m_pairArrayPtr;
28 uint32_t m_someMutexVariableInMainMemory;
30 ppu_address_t m_dispatcher;
32 uint32_t numOnLastPage;
38 struct CollisionTask_LocalStoreMemory* m_lsMemory;
41 #if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2)
42 __attribute__ ((aligned (128)))
47 void processCollisionTask(void* userPtr, void* lsMemory);
49 void* createCollisionLocalStoreMemory();
50 void deleteCollisionLocalStoreMemory();
52 #if defined(USE_LIBSPE2) && defined(__SPU__)
53 #include "../SpuLibspe2Support.h"
54 #include <spu_intrinsics.h>
55 #include <spu_mfcio.h>
56 #include <SpuFakeDma.h>
58 //#define DEBUG_LIBSPE2_SPU_TASK
62 int main(unsigned long long speid, addr64 argp, addr64 envp)
64 printf("SPU: hello \n");
66 ATTRIBUTE_ALIGNED128(btSpuStatus status);
67 ATTRIBUTE_ALIGNED16( SpuGatherAndProcessPairsTaskDesc taskDesc ) ;
68 unsigned int received_message = Spu_Mailbox_Event_Nothing;
69 bool shutdown = false;
71 cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
72 cellDmaWaitTagStatusAll(DMA_MASK(3));
74 status.m_status = Spu_Status_Free;
75 status.m_lsMemory.p = createCollisionLocalStoreMemory();
77 cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
78 cellDmaWaitTagStatusAll(DMA_MASK(3));
81 while ( btLikely( !shutdown ) )
84 received_message = spu_read_in_mbox();
86 if( btLikely( received_message == Spu_Mailbox_Event_Task ))
88 #ifdef DEBUG_LIBSPE2_SPU_TASK
89 printf("SPU: received Spu_Mailbox_Event_Task\n");
90 #endif //DEBUG_LIBSPE2_SPU_TASK
93 cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
94 cellDmaWaitTagStatusAll(DMA_MASK(3));
96 btAssert(status.m_status==Spu_Status_Occupied);
98 cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuGatherAndProcessPairsTaskDesc), DMA_TAG(3), 0, 0);
99 cellDmaWaitTagStatusAll(DMA_MASK(3));
100 #ifdef DEBUG_LIBSPE2_SPU_TASK
101 printf("SPU:processCollisionTask\n");
102 #endif //DEBUG_LIBSPE2_SPU_TASK
103 processCollisionTask((void*)&taskDesc, taskDesc.m_lsMemory);
105 #ifdef DEBUG_LIBSPE2_SPU_TASK
106 printf("SPU:finished processCollisionTask\n");
107 #endif //DEBUG_LIBSPE2_SPU_TASK
111 #ifdef DEBUG_LIBSPE2_SPU_TASK
112 printf("SPU: received ShutDown\n");
113 #endif //DEBUG_LIBSPE2_SPU_TASK
114 if( btLikely( received_message == Spu_Mailbox_Event_Shutdown ) )
120 //printf("SPU - Sth. recieved\n");
124 // set to status free and wait for next task
125 status.m_status = Spu_Status_Free;
126 cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
127 cellDmaWaitTagStatusAll(DMA_MASK(3));
132 printf("SPU: shutdown\n");
135 #endif // USE_LIBSPE2
138 #endif //SPU_GATHERING_COLLISION_TASK_H