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_COLLISION_TASK_PROCESS_H 00017 #define BT_SPU_COLLISION_TASK_PROCESS_H 00018 00019 #include <assert.h> 00020 00021 #include "LinearMath/btScalar.h" 00022 00023 #include "PlatformDefinitions.h" 00024 #include "LinearMath/btAlignedObjectArray.h" 00025 #include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h" // for definitions processCollisionTask and createCollisionLocalStoreMemory 00026 00027 #include "btThreadSupportInterface.h" 00028 00029 00030 //#include "SPUAssert.h" 00031 #include <string.h> 00032 00033 00034 #include "BulletCollision/CollisionDispatch/btCollisionObject.h" 00035 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 00036 #include "BulletCollision/CollisionShapes/btConvexShape.h" 00037 00038 #include "LinearMath/btAlignedAllocator.h" 00039 00040 #include <stdio.h> 00041 00042 00043 #define DEBUG_SpuCollisionTaskProcess 1 00044 00045 00046 #define CMD_GATHER_AND_PROCESS_PAIRLIST 1 00047 00048 class btCollisionObject; 00049 class btPersistentManifold; 00050 class btDispatcher; 00051 00052 00054 //struct SpuGatherAndProcessPairsTaskDesc 00055 //{ 00056 // uint64_t inPtr;//m_pairArrayPtr; 00057 // //mutex variable 00058 // uint32_t m_someMutexVariableInMainMemory; 00059 // 00060 // uint64_t m_dispatcher; 00061 // 00062 // uint32_t numOnLastPage; 00063 // 00064 // uint16_t numPages; 00065 // uint16_t taskId; 00066 // 00067 // struct CollisionTask_LocalStoreMemory* m_lsMemory; 00068 //} 00069 // 00070 //#if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2) 00071 //__attribute__ ((aligned (16))) 00072 //#endif 00073 //; 00074 00075 00077 ATTRIBUTE_ALIGNED16(struct) SpuGatherAndProcessWorkUnitInput 00078 { 00079 uint64_t m_pairArrayPtr; 00080 int m_startIndex; 00081 int m_endIndex; 00082 }; 00083 00084 00085 00086 00093 class SpuCollisionTaskProcess 00094 { 00095 00096 unsigned char *m_workUnitTaskBuffers; 00097 00098 00099 // track task buffers that are being used, and total busy tasks 00100 btAlignedObjectArray<bool> m_taskBusy; 00101 btAlignedObjectArray<SpuGatherAndProcessPairsTaskDesc> m_spuGatherTaskDesc; 00102 00103 class btThreadSupportInterface* m_threadInterface; 00104 00105 unsigned int m_maxNumOutstandingTasks; 00106 00107 unsigned int m_numBusyTasks; 00108 00109 // the current task and the current entry to insert a new work unit 00110 unsigned int m_currentTask; 00111 unsigned int m_currentPage; 00112 unsigned int m_currentPageEntry; 00113 00114 bool m_useEpa; 00115 00116 #ifdef DEBUG_SpuCollisionTaskProcess 00117 bool m_initialized; 00118 #endif 00119 void issueTask2(); 00120 //void postProcess(unsigned int taskId, int outputSize); 00121 00122 public: 00123 SpuCollisionTaskProcess(btThreadSupportInterface* threadInterface, unsigned int maxNumOutstandingTasks); 00124 00125 ~SpuCollisionTaskProcess(); 00126 00128 void initialize2(bool useEpa = false); 00129 00131 void addWorkToTask(void* pairArrayPtr,int startIndex,int endIndex); 00132 00134 void flush2(); 00135 00137 void setNumTasks(int maxNumTasks); 00138 00139 int getNumTasks() const 00140 { 00141 return m_maxNumOutstandingTasks; 00142 } 00143 }; 00144 00145 00146 00147 #define MIDPHASE_TASK_PTR(task) (&m_workUnitTaskBuffers[0] + MIDPHASE_WORKUNIT_TASK_SIZE*task) 00148 #define MIDPHASE_ENTRY_PTR(task,page,entry) (MIDPHASE_TASK_PTR(task) + MIDPHASE_WORKUNIT_PAGE_SIZE*page + sizeof(SpuGatherAndProcessWorkUnitInput)*entry) 00149 #define MIDPHASE_OUTPUT_PTR(task) (&m_contactOutputBuffers[0] + MIDPHASE_MAX_CONTACT_BUFFER_SIZE*task) 00150 #define MIDPHASE_TREENODES_PTR(task) (&m_complexShapeBuffers[0] + MIDPHASE_COMPLEX_SHAPE_BUFFER_SIZE*task) 00151 00152 00153 #define MIDPHASE_WORKUNIT_PAGE_SIZE (16) 00154 //#define MIDPHASE_WORKUNIT_PAGE_SIZE (128) 00155 00156 #define MIDPHASE_NUM_WORKUNIT_PAGES 1 00157 #define MIDPHASE_WORKUNIT_TASK_SIZE (MIDPHASE_WORKUNIT_PAGE_SIZE*MIDPHASE_NUM_WORKUNIT_PAGES) 00158 #define MIDPHASE_NUM_WORKUNITS_PER_PAGE (MIDPHASE_WORKUNIT_PAGE_SIZE / sizeof(SpuGatherAndProcessWorkUnitInput)) 00159 #define MIDPHASE_NUM_WORKUNITS_PER_TASK (MIDPHASE_NUM_WORKUNITS_PER_PAGE*MIDPHASE_NUM_WORKUNIT_PAGES) 00160 00161 00162 #endif // BT_SPU_COLLISION_TASK_PROCESS_H 00163