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.
17 #ifndef BT_SPU_LIBSPE2_SUPPORT_H
18 #define BT_SPU_LIBSPE2_SUPPORT_H
20 #include <LinearMath/btScalar.h> //for uint32_t etc.
26 //#include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
27 #include "PlatformDefinitions.h"
30 //extern struct SpuGatherAndProcessPairsTaskDesc;
34 Spu_Mailbox_Event_Nothing = 0,
35 Spu_Mailbox_Event_Task = 1,
36 Spu_Mailbox_Event_Shutdown = 2,
38 Spu_Mailbox_Event_ForceDword = 0xFFFFFFFF
45 Spu_Status_Occupied = 1,
46 Spu_Status_Startup = 2,
48 Spu_Status_ForceDword = 0xFFFFFFFF
63 __attribute__ ((aligned (128)))
70 #include "LinearMath/btAlignedObjectArray.h"
71 #include "SpuCollisionTaskProcess.h"
72 #include "SpuSampleTaskProcess.h"
73 #include "btThreadSupportInterface.h"
80 typedef struct ppu_pthread_data
82 spe_context_ptr_t context;
88 spe_stop_info_t stopinfo;
92 static void *ppu_pthread_function(void *arg)
94 ppu_pthread_data_t * datap = (ppu_pthread_data_t *)arg;
99 spe_context_run(datap->context, &datap->entry, datap->flags, datap->argp.p, datap->envp.p, &datap->stopinfo);
100 if (datap->stopinfo.stop_reason == SPE_EXIT)
102 if (datap->stopinfo.result.spe_exit_code != 0)
104 perror("FAILED: SPE returned a non-zero exit status: \n");
110 perror("FAILED: SPE abnormally terminated\n");
115 //} while (rc > 0); // loop until exit or error, and while any stop & signal
124 ///SpuLibspe2Support helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
125 class SpuLibspe2Support : public btThreadSupportInterface
128 btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
131 //Setup and initialize SPU/CELL/Libspe2
132 SpuLibspe2Support(spe_program_handle_t *speprog,int numThreads);
134 // SPE program handle ptr.
135 spe_program_handle_t *program;
138 ppu_pthread_data_t data[MAX_SPUS];
140 //cleanup/shutdown Libspe2
141 ~SpuLibspe2Support();
143 ///send messages to SPUs
144 void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1=0);
146 //check for messages from SPUs
147 void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
149 //start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
150 virtual void startSPU();
152 //tell the task scheduler we are done with the SPU tasks
153 virtual void stopSPU();
155 virtual void setNumTasks(int numTasks)
157 //changing the number of tasks after initialization is not implemented (yet)
162 ///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
163 void internal_startSPU();
172 #endif // NOT __SPU__
176 #endif //BT_SPU_LIBSPE2_SUPPORT_H