SpuGatheringCollisionTask.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef SPU_GATHERING_COLLISION_TASK_H
00017 #define SPU_GATHERING_COLLISION_TASK_H
00018 
00019 #include "../PlatformDefinitions.h"
00020 //#define DEBUG_SPU_COLLISION_DETECTION 1
00021 
00022 
00024 struct SpuGatherAndProcessPairsTaskDesc 
00025 {
00026         ppu_address_t   m_inPairPtr;//m_pairArrayPtr;
00027         //mutex variable
00028         uint32_t        m_someMutexVariableInMainMemory;
00029 
00030         ppu_address_t   m_dispatcher;
00031 
00032         uint32_t        numOnLastPage;
00033 
00034         uint16_t numPages;
00035         uint16_t taskId;
00036         bool m_useEpa;
00037 
00038         struct  CollisionTask_LocalStoreMemory* m_lsMemory; 
00039 }
00040 
00041 #if  defined(__CELLOS_LV2__) || defined(USE_LIBSPE2)
00042 __attribute__ ((aligned (128)))
00043 #endif
00044 ;
00045 
00046 
00047 void    processCollisionTask(void* userPtr, void* lsMemory);
00048 
00049 void*   createCollisionLocalStoreMemory();
00050 void deleteCollisionLocalStoreMemory();
00051 
00052 #if defined(USE_LIBSPE2) && defined(__SPU__)
00053 #include "../SpuLibspe2Support.h"
00054 #include <spu_intrinsics.h>
00055 #include <spu_mfcio.h>
00056 #include <SpuFakeDma.h>
00057 
00058 //#define DEBUG_LIBSPE2_SPU_TASK
00059 
00060 
00061 
00062 int main(unsigned long long speid, addr64 argp, addr64 envp)
00063 {
00064         printf("SPU: hello \n");
00065         
00066         ATTRIBUTE_ALIGNED128(btSpuStatus status);
00067         ATTRIBUTE_ALIGNED16( SpuGatherAndProcessPairsTaskDesc taskDesc ) ;
00068         unsigned int received_message = Spu_Mailbox_Event_Nothing;
00069     bool shutdown = false;
00070 
00071         cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00072         cellDmaWaitTagStatusAll(DMA_MASK(3));
00073 
00074         status.m_status = Spu_Status_Free;
00075         status.m_lsMemory.p = createCollisionLocalStoreMemory();
00076 
00077         cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00078         cellDmaWaitTagStatusAll(DMA_MASK(3));
00079         
00080         
00081         while ( btLikely( !shutdown ) )
00082         {
00083                 
00084                 received_message = spu_read_in_mbox();
00085                 
00086                 if( btLikely( received_message == Spu_Mailbox_Event_Task ))
00087                 {
00088 #ifdef DEBUG_LIBSPE2_SPU_TASK
00089                         printf("SPU: received Spu_Mailbox_Event_Task\n");
00090 #endif //DEBUG_LIBSPE2_SPU_TASK
00091 
00092                         // refresh the status
00093                         cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00094                         cellDmaWaitTagStatusAll(DMA_MASK(3));
00095                 
00096                         btAssert(status.m_status==Spu_Status_Occupied);
00097                         
00098                         cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuGatherAndProcessPairsTaskDesc), DMA_TAG(3), 0, 0);
00099                         cellDmaWaitTagStatusAll(DMA_MASK(3));
00100 #ifdef DEBUG_LIBSPE2_SPU_TASK           
00101                         printf("SPU:processCollisionTask\n");   
00102 #endif //DEBUG_LIBSPE2_SPU_TASK
00103                         processCollisionTask((void*)&taskDesc, taskDesc.m_lsMemory);
00104                         
00105 #ifdef DEBUG_LIBSPE2_SPU_TASK
00106                         printf("SPU:finished processCollisionTask\n");
00107 #endif //DEBUG_LIBSPE2_SPU_TASK
00108                 }
00109                 else
00110                 {
00111 #ifdef DEBUG_LIBSPE2_SPU_TASK
00112                         printf("SPU: received ShutDown\n");
00113 #endif //DEBUG_LIBSPE2_SPU_TASK
00114                         if( btLikely( received_message == Spu_Mailbox_Event_Shutdown ) )
00115                         {
00116                                 shutdown = true;
00117                         }
00118                         else
00119                         {
00120                                 //printf("SPU - Sth. recieved\n");
00121                         }
00122                 }
00123 
00124                 // set to status free and wait for next task
00125                 status.m_status = Spu_Status_Free;
00126                 cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00127                 cellDmaWaitTagStatusAll(DMA_MASK(3));           
00128                                 
00129                 
00130         }
00131 
00132         printf("SPU: shutdown\n");
00133         return 0;
00134 }
00135 #endif // USE_LIBSPE2
00136 
00137 
00138 #endif //SPU_GATHERING_COLLISION_TASK_H
00139 
00140