Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef BT_SPU_LIBSPE2_SUPPORT_H
00018 #define BT_SPU_LIBSPE2_SUPPORT_H
00019
00020 #include <LinearMath/btScalar.h>
00021
00022 #ifdef USE_LIBSPE2
00023
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026
00027 #include "PlatformDefinitions.h"
00028
00029
00030
00031
00032 enum
00033 {
00034 Spu_Mailbox_Event_Nothing = 0,
00035 Spu_Mailbox_Event_Task = 1,
00036 Spu_Mailbox_Event_Shutdown = 2,
00037
00038 Spu_Mailbox_Event_ForceDword = 0xFFFFFFFF
00039
00040 };
00041
00042 enum
00043 {
00044 Spu_Status_Free = 0,
00045 Spu_Status_Occupied = 1,
00046 Spu_Status_Startup = 2,
00047
00048 Spu_Status_ForceDword = 0xFFFFFFFF
00049
00050 };
00051
00052
00053 struct btSpuStatus
00054 {
00055 uint32_t m_taskId;
00056 uint32_t m_commandId;
00057 uint32_t m_status;
00058
00059 addr64 m_taskDesc;
00060 addr64 m_lsMemory;
00061
00062 }
00063 __attribute__ ((aligned (128)))
00064 ;
00065
00066
00067
00068 #ifndef __SPU__
00069
00070 #include "LinearMath/btAlignedObjectArray.h"
00071 #include "SpuCollisionTaskProcess.h"
00072 #include "SpuSampleTaskProcess.h"
00073 #include "btThreadSupportInterface.h"
00074 #include <libspe2.h>
00075 #include <pthread.h>
00076 #include <sched.h>
00077
00078 #define MAX_SPUS 4
00079
00080 typedef struct ppu_pthread_data
00081 {
00082 spe_context_ptr_t context;
00083 pthread_t pthread;
00084 unsigned int entry;
00085 unsigned int flags;
00086 addr64 argp;
00087 addr64 envp;
00088 spe_stop_info_t stopinfo;
00089 } ppu_pthread_data_t;
00090
00091
00092 static void *ppu_pthread_function(void *arg)
00093 {
00094 ppu_pthread_data_t * datap = (ppu_pthread_data_t *)arg;
00095
00096
00097
00098
00099 spe_context_run(datap->context, &datap->entry, datap->flags, datap->argp.p, datap->envp.p, &datap->stopinfo);
00100 if (datap->stopinfo.stop_reason == SPE_EXIT)
00101 {
00102 if (datap->stopinfo.result.spe_exit_code != 0)
00103 {
00104 perror("FAILED: SPE returned a non-zero exit status: \n");
00105 exit(1);
00106 }
00107 }
00108 else
00109 {
00110 perror("FAILED: SPE abnormally terminated\n");
00111 exit(1);
00112 }
00113
00114
00115
00116 pthread_exit(NULL);
00117 }
00118
00119
00120
00121
00122
00123
00125 class SpuLibspe2Support : public btThreadSupportInterface
00126 {
00127
00128 btAlignedObjectArray<btSpuStatus> m_activeSpuStatus;
00129
00130 public:
00131
00132 SpuLibspe2Support(spe_program_handle_t *speprog,int numThreads);
00133
00134
00135 spe_program_handle_t *program;
00136
00137
00138 ppu_pthread_data_t data[MAX_SPUS];
00139
00140
00141 ~SpuLibspe2Support();
00142
00144 void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1=0);
00145
00146
00147 void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
00148
00149
00150 virtual void startSPU();
00151
00152
00153 virtual void stopSPU();
00154
00155 virtual void setNumTasks(int numTasks)
00156 {
00157
00158 }
00159
00160 private:
00161
00163 void internal_startSPU();
00164
00165
00166
00167
00168 int numThreads;
00169
00170 };
00171
00172 #endif // NOT __SPU__
00173
00174 #endif //USE_LIBSPE2
00175
00176 #endif //BT_SPU_LIBSPE2_SUPPORT_H
00177
00178
00179
00180