Bullet Collision Detection & Physics Library
SpuCollisionTaskProcess.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4 
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:
10 
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.
14 */
15 
16 #ifndef BT_SPU_COLLISION_TASK_PROCESS_H
17 #define BT_SPU_COLLISION_TASK_PROCESS_H
18 
19 #include <assert.h>
20 
21 #include "LinearMath/btScalar.h"
22 
23 #include "PlatformDefinitions.h"
25 #include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h" // for definitions processCollisionTask and createCollisionLocalStoreMemory
26 
28 
29 
30 //#include "SPUAssert.h"
31 #include <string.h>
32 
33 
37 
39 
40 #include <stdio.h>
41 
42 
43 #define DEBUG_SpuCollisionTaskProcess 1
44 
45 
46 #define CMD_GATHER_AND_PROCESS_PAIRLIST 1
47 
48 class btCollisionObject;
50 class btDispatcher;
51 
52 
54 //struct SpuGatherAndProcessPairsTaskDesc
55 //{
56 // uint64_t inPtr;//m_pairArrayPtr;
57 // //mutex variable
58 // uint32_t m_someMutexVariableInMainMemory;
59 //
60 // uint64_t m_dispatcher;
61 //
62 // uint32_t numOnLastPage;
63 //
64 // uint16_t numPages;
65 // uint16_t taskId;
66 //
67 // struct CollisionTask_LocalStoreMemory* m_lsMemory;
68 //}
69 //
70 //#if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2)
71 //__attribute__ ((aligned (16)))
72 //#endif
73 //;
74 
75 
78 {
82 };
83 
84 
85 
86 
94 {
95 
96  unsigned char *m_workUnitTaskBuffers;
97 
98 
99  // track task buffers that are being used, and total busy tasks
102 
104 
106 
107  unsigned int m_numBusyTasks;
108 
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;
113 
114  bool m_useEpa;
115 
116 #ifdef DEBUG_SpuCollisionTaskProcess
118 #endif
119  void issueTask2();
120  //void postProcess(unsigned int taskId, int outputSize);
121 
122 public:
123  SpuCollisionTaskProcess(btThreadSupportInterface* threadInterface, unsigned int maxNumOutstandingTasks);
124 
126 
128  void initialize2(bool useEpa = false);
129 
131  void addWorkToTask(void* pairArrayPtr,int startIndex,int endIndex);
132 
134  void flush2();
135 
137  void setNumTasks(int maxNumTasks);
138 
139  int getNumTasks() const
140  {
142  }
143 };
144 
145 
146 
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)
151 
152 
153 #define MIDPHASE_WORKUNIT_PAGE_SIZE (16)
154 //#define MIDPHASE_WORKUNIT_PAGE_SIZE (128)
155 
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)
160 
161 
162 #endif // BT_SPU_COLLISION_TASK_PROCESS_H
163 
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
void setNumTasks(int maxNumTasks)
set the maximum number of SPU tasks allocated
unsigned long int uint64_t
SpuCollisionTaskProcess handles SPU processing of collision pairs.
void initialize2(bool useEpa=false)
call initialize in the beginning of the frame, before addCollisionPairToTask
void flush2()
call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished...
btAlignedObjectArray< bool > m_taskBusy
SpuCollisionTaskProcess(btThreadSupportInterface *threadInterface, unsigned int maxNumOutstandingTasks)
class btThreadSupportInterface * m_threadInterface
void addWorkToTask(void *pairArrayPtr, int startIndex, int endIndex)
batch up additional work to a current task for SPU processing. When batch is full, it issues the task.
MidphaseWorkUnitInput stores individual primitive versus mesh collision detection input...
btCollisionObject can be used to manage collision detection objects.
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:59
btAlignedObjectArray< SpuGatherAndProcessPairsTaskDesc > m_spuGatherTaskDesc
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:69