Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletMultiThreaded/SpuLibspe2Support.h @ 1971

Last change on this file since 1971 was 1966, checked in by rgrieder, 16 years ago

Let's go for multithreaded physics!

  • Property svn:eol-style set to native
File size: 4.0 KB
RevLine 
[1966]1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2007 Erwin Coumans  http://bulletphysics.com
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16
17#ifndef SPU_LIBSPE2_SUPPORT_H
18#define SPU_LIBSPE2_SUPPORT_H
19
20#include <LinearMath/btScalar.h> //for uint32_t etc.
21
22#ifdef USE_LIBSPE2
23
24#include <stdlib.h>
25#include <stdio.h>
26//#include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
27#include "PlatformDefinitions.h"
28
29
30//extern struct SpuGatherAndProcessPairsTaskDesc;
31
32enum
33{
34        Spu_Mailbox_Event_Nothing = 0,
35        Spu_Mailbox_Event_Task = 1,
36        Spu_Mailbox_Event_Shutdown = 2,
37       
38        Spu_Mailbox_Event_ForceDword = 0xFFFFFFFF
39       
40};
41
42enum
43{
44        Spu_Status_Free = 0,
45        Spu_Status_Occupied = 1,
46        Spu_Status_Startup = 2,
47       
48        Spu_Status_ForceDword = 0xFFFFFFFF
49       
50};
51
52
53struct btSpuStatus
54{
55        uint32_t        m_taskId;
56        uint32_t        m_commandId;
57        uint32_t        m_status;
58
59        addr64 m_taskDesc;
60        addr64 m_lsMemory;
61       
62}
63__attribute__ ((aligned (128)))
64;
65
66
67
68#ifndef __SPU__
69
70#include "LinearMath/btAlignedObjectArray.h"
71#include "SpuCollisionTaskProcess.h"
72#include "SpuSampleTaskProcess.h"
73#include "btThreadSupportInterface.h"
74#include <libspe2.h>
75#include <pthread.h>
76#include <sched.h>
77
78#define MAX_SPUS 4
79
80typedef struct ppu_pthread_data
81{
82        spe_context_ptr_t context;
83        pthread_t pthread;
84        unsigned int entry;
85        unsigned int flags;
86        addr64 argp;
87        addr64 envp;
88        spe_stop_info_t stopinfo;
89} ppu_pthread_data_t;
90
91
92static void *ppu_pthread_function(void *arg)
93{
94    ppu_pthread_data_t * datap = (ppu_pthread_data_t *)arg;
95    /*
96    int rc;
97    do
98    {*/
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) 
101        {
102           if (datap->stopinfo.result.spe_exit_code != 0) 
103           {
104             perror("FAILED: SPE returned a non-zero exit status: \n");
105             exit(1);
106           }
107         } 
108        else 
109         {
110           perror("FAILED: SPE abnormally terminated\n");
111           exit(1);
112         }
113       
114       
115    //} while (rc > 0); // loop until exit or error, and while any stop & signal
116    pthread_exit(NULL);
117}
118
119
120
121
122
123
124///SpuLibspe2Support helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
125class SpuLibspe2Support : public btThreadSupportInterface
126{
127
128        btAlignedObjectArray<btSpuStatus>       m_activeSpuStatus;
129       
130public:
131        //Setup and initialize SPU/CELL/Libspe2
132        SpuLibspe2Support(spe_program_handle_t *speprog,int numThreads);
133       
134        // SPE program handle ptr.
135        spe_program_handle_t *program;
136       
137        // SPE program data
138        ppu_pthread_data_t data[MAX_SPUS];
139       
140        //cleanup/shutdown Libspe2
141        ~SpuLibspe2Support();
142
143        ///send messages to SPUs
144        void sendRequest(uint32_t uiCommand, uint32_t uiArgument0, uint32_t uiArgument1=0);
145
146        //check for messages from SPUs
147        void waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1);
148
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();
151
152        //tell the task scheduler we are done with the SPU tasks
153        virtual void stopSPU();
154
155private:
156       
157        ///start the spus (can be called at the beginning of each frame, to make sure that the right SPU program is loaded)
158        void internal_startSPU();
159       
160       
161        int numThreads;
162
163};
164
165#endif // NOT __SPU__
166
167#endif //USE_LIBSPE2
168
169#endif //SPU_LIBSPE2_SUPPORT_H
170
171
172
173
Note: See TracBrowser for help on using the repository browser.