1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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 SPU_GATHERING_COLLISION_TASK_H
17 #define SPU_GATHERING_COLLISION_TASK_H
18 
19 #include "../PlatformDefinitions.h"
20 //#define DEBUG_SPU_COLLISION_DETECTION 1
21 
22 
23 ///Task Description for SPU collision detection
24 struct SpuGatherAndProcessPairsTaskDesc
25 {
26 	ppu_address_t	m_inPairPtr;//m_pairArrayPtr;
27 	//mutex variable
28 	uint32_t	m_someMutexVariableInMainMemory;
29 
30 	ppu_address_t	m_dispatcher;
31 
32 	uint32_t	numOnLastPage;
33 
34 	uint16_t numPages;
35 	uint16_t taskId;
36 	bool m_useEpa;
37 
38 	struct	CollisionTask_LocalStoreMemory*	m_lsMemory;
39 }
40 
41 #if  defined(__CELLOS_LV2__) || defined(USE_LIBSPE2)
42 __attribute__ ((aligned (128)))
43 #endif
44 ;
45 
46 
47 void	processCollisionTask(void* userPtr, void* lsMemory);
48 
49 void*	createCollisionLocalStoreMemory();
50 
51 
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>
57 
58 //#define DEBUG_LIBSPE2_SPU_TASK
59 
60 
61 
main(unsigned long long speid,addr64 argp,addr64 envp)62 int main(unsigned long long speid, addr64 argp, addr64 envp)
63 {
64 	printf("SPU: hello \n");
65 
66 	ATTRIBUTE_ALIGNED128(btSpuStatus status);
67 	ATTRIBUTE_ALIGNED16( SpuGatherAndProcessPairsTaskDesc taskDesc ) ;
68 	unsigned int received_message = Spu_Mailbox_Event_Nothing;
69     bool shutdown = false;
70 
71 	cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
72 	cellDmaWaitTagStatusAll(DMA_MASK(3));
73 
74 	status.m_status = Spu_Status_Free;
75 	status.m_lsMemory.p = createCollisionLocalStoreMemory();
76 
77 	cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
78 	cellDmaWaitTagStatusAll(DMA_MASK(3));
79 
80 
81 	while ( btLikely( !shutdown ) )
82 	{
83 
84 		received_message = spu_read_in_mbox();
85 
86 		if( btLikely( received_message == Spu_Mailbox_Event_Task ))
87 		{
88 #ifdef DEBUG_LIBSPE2_SPU_TASK
89 			printf("SPU: received Spu_Mailbox_Event_Task\n");
90 #endif //DEBUG_LIBSPE2_SPU_TASK
91 
92 			// refresh the status
93 			cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
94 			cellDmaWaitTagStatusAll(DMA_MASK(3));
95 
96 			btAssert(status.m_status==Spu_Status_Occupied);
97 
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);
104 
105 #ifdef DEBUG_LIBSPE2_SPU_TASK
106 			printf("SPU:finished processCollisionTask\n");
107 #endif //DEBUG_LIBSPE2_SPU_TASK
108 		}
109 		else
110 		{
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 ) )
115 			{
116 				shutdown = true;
117 			}
118 			else
119 			{
120 				//printf("SPU - Sth. recieved\n");
121 			}
122 		}
123 
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));
128 
129 
130   	}
131 
132 	printf("SPU: shutdown\n");
133   	return 0;
134 }
135 #endif // USE_LIBSPE2
136 
137 
138 #endif //SPU_GATHERING_COLLISION_TASK_H
139 
140 
141