2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 #ifndef BT_SPU_COLLISION_TASK_PROCESS_H
17 #define BT_SPU_COLLISION_TASK_PROCESS_H
21 #include "LinearMath/btScalar.h"
23 #include "PlatformDefinitions.h"
24 #include "LinearMath/btAlignedObjectArray.h"
25 #include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h" // for definitions processCollisionTask and createCollisionLocalStoreMemory
27 #include "btThreadSupportInterface.h"
30 //#include "SPUAssert.h"
34 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
35 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
36 #include "BulletCollision/CollisionShapes/btConvexShape.h"
38 #include "LinearMath/btAlignedAllocator.h"
43 #define DEBUG_SpuCollisionTaskProcess 1
46 #define CMD_GATHER_AND_PROCESS_PAIRLIST 1
48 class btCollisionObject;
49 class btPersistentManifold;
53 /////Task Description for SPU collision detection
54 //struct SpuGatherAndProcessPairsTaskDesc
56 // uint64_t inPtr;//m_pairArrayPtr;
58 // uint32_t m_someMutexVariableInMainMemory;
60 // uint64_t m_dispatcher;
62 // uint32_t numOnLastPage;
67 // struct CollisionTask_LocalStoreMemory* m_lsMemory;
70 //#if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2)
71 //__attribute__ ((aligned (16)))
76 ///MidphaseWorkUnitInput stores individual primitive versus mesh collision detection input, to be processed by the SPU.
77 ATTRIBUTE_ALIGNED16(struct) SpuGatherAndProcessWorkUnitInput
79 uint64_t m_pairArrayPtr;
87 /// SpuCollisionTaskProcess handles SPU processing of collision pairs.
88 /// Maintains a set of task buffers.
89 /// When the task is full, the task is issued for SPUs to process. Contact output goes into btPersistentManifold
90 /// associated with each task.
91 /// When PPU issues a task, it will look for completed task buffers
92 /// PPU will do postprocessing, dependent on workunit output (not likely)
93 class SpuCollisionTaskProcess
96 unsigned char *m_workUnitTaskBuffers;
99 // track task buffers that are being used, and total busy tasks
100 btAlignedObjectArray<bool> m_taskBusy;
101 btAlignedObjectArray<SpuGatherAndProcessPairsTaskDesc> m_spuGatherTaskDesc;
103 class btThreadSupportInterface* m_threadInterface;
105 unsigned int m_maxNumOutstandingTasks;
107 unsigned int m_numBusyTasks;
109 // the current task and the current entry to insert a new work unit
110 unsigned int m_currentTask;
111 unsigned int m_currentPage;
112 unsigned int m_currentPageEntry;
116 #ifdef DEBUG_SpuCollisionTaskProcess
120 //void postProcess(unsigned int taskId, int outputSize);
123 SpuCollisionTaskProcess(btThreadSupportInterface* threadInterface, unsigned int maxNumOutstandingTasks);
125 ~SpuCollisionTaskProcess();
127 ///call initialize in the beginning of the frame, before addCollisionPairToTask
128 void initialize2(bool useEpa = false);
130 ///batch up additional work to a current task for SPU processing. When batch is full, it issues the task.
131 void addWorkToTask(void* pairArrayPtr,int startIndex,int endIndex);
133 ///call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished
136 /// set the maximum number of SPU tasks allocated
137 void setNumTasks(int maxNumTasks);
139 int getNumTasks() const
141 return m_maxNumOutstandingTasks;
147 #define MIDPHASE_TASK_PTR(task) (&m_workUnitTaskBuffers[0] + MIDPHASE_WORKUNIT_TASK_SIZE*task)
148 #define MIDPHASE_ENTRY_PTR(task,page,entry) (MIDPHASE_TASK_PTR(task) + MIDPHASE_WORKUNIT_PAGE_SIZE*page + sizeof(SpuGatherAndProcessWorkUnitInput)*entry)
149 #define MIDPHASE_OUTPUT_PTR(task) (&m_contactOutputBuffers[0] + MIDPHASE_MAX_CONTACT_BUFFER_SIZE*task)
150 #define MIDPHASE_TREENODES_PTR(task) (&m_complexShapeBuffers[0] + MIDPHASE_COMPLEX_SHAPE_BUFFER_SIZE*task)
153 #define MIDPHASE_WORKUNIT_PAGE_SIZE (16)
154 //#define MIDPHASE_WORKUNIT_PAGE_SIZE (128)
156 #define MIDPHASE_NUM_WORKUNIT_PAGES 1
157 #define MIDPHASE_WORKUNIT_TASK_SIZE (MIDPHASE_WORKUNIT_PAGE_SIZE*MIDPHASE_NUM_WORKUNIT_PAGES)
158 #define MIDPHASE_NUM_WORKUNITS_PER_PAGE (MIDPHASE_WORKUNIT_PAGE_SIZE / sizeof(SpuGatherAndProcessWorkUnitInput))
159 #define MIDPHASE_NUM_WORKUNITS_PER_TASK (MIDPHASE_NUM_WORKUNITS_PER_PAGE*MIDPHASE_NUM_WORKUNIT_PAGES)
162 #endif // BT_SPU_COLLISION_TASK_PROCESS_H