SpuSampleTaskProcess.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2007 Erwin Coumans  http://bulletphysics.com
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 BT_SPU_SAMPLE_TASK_PROCESS_H
00017 #define BT_SPU_SAMPLE_TASK_PROCESS_H
00018 
00019 #include <assert.h>
00020 
00021 
00022 #include "PlatformDefinitions.h"
00023 
00024 #include <stdlib.h>
00025 
00026 #include "LinearMath/btAlignedObjectArray.h"
00027 
00028 
00029 #include "SpuSampleTask/SpuSampleTask.h"
00030 
00031 
00032 //just add your commands here, try to keep them globally unique for debugging purposes
00033 #define CMD_SAMPLE_TASK_COMMAND 10
00034 
00035 
00036 
00040 class SpuSampleTaskProcess
00041 {
00042         // track task buffers that are being used, and total busy tasks
00043         btAlignedObjectArray<bool>      m_taskBusy;
00044         btAlignedObjectArray<SpuSampleTaskDesc>m_spuSampleTaskDesc;
00045         
00046         int   m_numBusyTasks;
00047 
00048         // the current task and the current entry to insert a new work unit
00049         int   m_currentTask;
00050 
00051         bool m_initialized;
00052 
00053         void postProcess(int taskId, int outputSize);
00054         
00055         class   btThreadSupportInterface*       m_threadInterface;
00056 
00057         int     m_maxNumOutstandingTasks;
00058 
00059 
00060 
00061 public:
00062         SpuSampleTaskProcess(btThreadSupportInterface*  threadInterface, int maxNumOutstandingTasks);
00063         
00064         ~SpuSampleTaskProcess();
00065         
00067         void initialize();
00068 
00069         void issueTask(void* sampleMainMemPtr,int sampleValue,int sampleCommand);
00070 
00072         void flush();
00073 };
00074 
00075 
00076 #if defined(USE_LIBSPE2) && defined(__SPU__)
00077 
00078 #include "../SpuLibspe2Support.h"
00079 #include <spu_intrinsics.h>
00080 #include <spu_mfcio.h>
00081 #include <SpuFakeDma.h>
00082 
00083 void * SamplelsMemoryFunc();
00084 void SampleThreadFunc(void* userPtr,void* lsMemory);
00085 
00086 //#define DEBUG_LIBSPE2_MAINLOOP
00087 
00088 int main(unsigned long long speid, addr64 argp, addr64 envp)
00089 {
00090         printf("SPU is up \n");
00091         
00092         ATTRIBUTE_ALIGNED128(btSpuStatus status);
00093         ATTRIBUTE_ALIGNED16( SpuSampleTaskDesc taskDesc ) ;
00094         unsigned int received_message = Spu_Mailbox_Event_Nothing;
00095         bool shutdown = false;
00096 
00097         cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00098         cellDmaWaitTagStatusAll(DMA_MASK(3));
00099 
00100         status.m_status = Spu_Status_Free;
00101         status.m_lsMemory.p = SamplelsMemoryFunc();
00102 
00103         cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00104         cellDmaWaitTagStatusAll(DMA_MASK(3));
00105         
00106         
00107         while (!shutdown)
00108         {
00109                 received_message = spu_read_in_mbox();
00110                 
00111 
00112                 
00113                 switch(received_message)
00114                 {
00115                 case Spu_Mailbox_Event_Shutdown:
00116                         shutdown = true;
00117                         break; 
00118                 case Spu_Mailbox_Event_Task:
00119                         // refresh the status
00120 #ifdef DEBUG_LIBSPE2_MAINLOOP
00121                         printf("SPU recieved Task \n");
00122 #endif //DEBUG_LIBSPE2_MAINLOOP
00123                         cellDmaGet(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00124                         cellDmaWaitTagStatusAll(DMA_MASK(3));
00125                 
00126                         btAssert(status.m_status==Spu_Status_Occupied);
00127                         
00128                         cellDmaGet(&taskDesc, status.m_taskDesc.p, sizeof(SpuSampleTaskDesc), DMA_TAG(3), 0, 0);
00129                         cellDmaWaitTagStatusAll(DMA_MASK(3));
00130                         
00131                         SampleThreadFunc((void*)&taskDesc, reinterpret_cast<void*> (taskDesc.m_mainMemoryPtr) );
00132                         break;
00133                 case Spu_Mailbox_Event_Nothing:
00134                 default:
00135                         break;
00136                 }
00137 
00138                 // set to status free and wait for next task
00139                 status.m_status = Spu_Status_Free;
00140                 cellDmaLargePut(&status, argp.ull, sizeof(btSpuStatus), DMA_TAG(3), 0, 0);
00141                 cellDmaWaitTagStatusAll(DMA_MASK(3));           
00142                                 
00143                 
00144         }
00145         return 0;
00146 }
00148 #endif
00149 
00150 
00151 
00152 #endif // BT_SPU_SAMPLE_TASK_PROCESS_H
00153