Bullet Collision Detection & Physics Library
btParallelConstraintSolver.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Sony Computer Entertainment Inc.
3  All rights reserved.
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 
17 #ifndef __BT_PARALLEL_CONSTRAINT_SOLVER_H
18 #define __BT_PARALLEL_CONSTRAINT_SOLVER_H
19 
21 
22 
23 
24 
25 #include "LinearMath/btScalar.h"
26 #include "PlatformDefinitions.h"
27 
28 
29 #define PFX_MAX_SOLVER_PHASES 64
30 #define PFX_MAX_SOLVER_BATCHES 16
31 #define PFX_MAX_SOLVER_PAIRS 128
32 #define PFX_MIN_SOLVER_PAIRS 16
33 
34 #ifdef __CELLOS_LV2__
36 #else
38 #endif
40 };
41 
42 #ifdef __CELLOS_LV2__
44 #else
46 #endif
50 };
51 
52 
53 
55  union {
56  uint8_t i8data[16];
57  uint16_t i16data[8];
58  uint32_t i32data[4];
59 #ifdef __SPU__
60  vec_uint4 vdata;
61 #endif
62  };
63 
64 #ifdef __SPU__
65  void set8(int elem,uint8_t data) {vdata=(vec_uint4)spu_insert(data,(vec_uchar16)vdata,elem);}
66  void set16(int elem,uint16_t data) {vdata=(vec_uint4)spu_insert(data,(vec_ushort8)vdata,elem);}
67  void set32(int elem,uint32_t data) {vdata=(vec_uint4)spu_insert(data,(vec_uint4)vdata,elem);}
68  uint8_t get8(int elem) const {return spu_extract((vec_uchar16)vdata,elem);}
69  uint16_t get16(int elem) const {return spu_extract((vec_ushort8)vdata,elem);}
70  uint32_t get32(int elem) const {return spu_extract((vec_uint4)vdata,elem);}
71 #else
72  void set8(int elem,uint8_t data) {i8data[elem] = data;}
73  void set16(int elem,uint16_t data) {i16data[elem] = data;}
74  void set32(int elem,uint32_t data) {i32data[elem] = data;}
75  uint8_t get8(int elem) const {return i8data[elem];}
76  uint16_t get16(int elem) const {return i16data[elem];}
77  uint32_t get32(int elem) const {return i32data[elem];}
78 #endif
79 };
80 
82 
83 
84 //J PfxBroadphasePair‚Æ‹¤’Ê
85 
86 SIMD_FORCE_INLINE void pfxSetConstraintId(PfxConstraintPair &pair,uint32_t i) {pair.set32(2,i);}
87 SIMD_FORCE_INLINE void pfxSetNumConstraints(PfxConstraintPair &pair,uint8_t n) {pair.set8(7,n);}
88 
89 SIMD_FORCE_INLINE uint32_t pfxGetConstraintId1(const PfxConstraintPair &pair) {return pair.get32(2);}
90 SIMD_FORCE_INLINE uint8_t pfxGetNumConstraints(const PfxConstraintPair &pair) {return pair.get8(7);}
91 
93 
94 SIMD_FORCE_INLINE void pfxSetRigidBodyIdA(PfxBroadphasePair &pair,uint16_t i) {pair.set16(0,i);}
95 SIMD_FORCE_INLINE void pfxSetRigidBodyIdB(PfxBroadphasePair &pair,uint16_t i) {pair.set16(1,i);}
96 SIMD_FORCE_INLINE void pfxSetMotionMaskA(PfxBroadphasePair &pair,uint8_t i) {pair.set8(4,i);}
97 SIMD_FORCE_INLINE void pfxSetMotionMaskB(PfxBroadphasePair &pair,uint8_t i) {pair.set8(5,i);}
98 SIMD_FORCE_INLINE void pfxSetBroadphaseFlag(PfxBroadphasePair &pair,uint8_t f) {pair.set8(6,(pair.get8(6)&0xf0)|(f&0x0f));}
99 SIMD_FORCE_INLINE void pfxSetActive(PfxBroadphasePair &pair,bool b) {pair.set8(6,(pair.get8(6)&0x0f)|((b?1:0)<<4));}
100 SIMD_FORCE_INLINE void pfxSetContactId(PfxBroadphasePair &pair,uint32_t i) {pair.set32(2,i);}
101 
102 SIMD_FORCE_INLINE uint16_t pfxGetRigidBodyIdA(const PfxBroadphasePair &pair) {return pair.get16(0);}
103 SIMD_FORCE_INLINE uint16_t pfxGetRigidBodyIdB(const PfxBroadphasePair &pair) {return pair.get16(1);}
104 SIMD_FORCE_INLINE uint8_t pfxGetMotionMaskA(const PfxBroadphasePair &pair) {return pair.get8(4);}
105 SIMD_FORCE_INLINE uint8_t pfxGetMotionMaskB(const PfxBroadphasePair &pair) {return pair.get8(5);}
106 SIMD_FORCE_INLINE uint8_t pfxGetBroadphaseFlag(const PfxBroadphasePair &pair) {return pair.get8(6)&0x0f;}
107 SIMD_FORCE_INLINE bool pfxGetActive(const PfxBroadphasePair &pair) {return (pair.get8(6)>>4)!=0;}
108 SIMD_FORCE_INLINE uint32_t pfxGetContactId1(const PfxBroadphasePair &pair) {return pair.get32(2);}
109 
110 
111 
112 #if defined(__PPU__) || defined (__SPU__)
114 #else
116 #endif
121  float mMassInv;
122  float friction;
123  float restitution;
124  float unused;
125  float unused2;
126  float unused3;
127  float unused4;
128  float unused5;
129 };
130 
131 
132 #ifdef __PPU__
133 #include "SpuDispatch/BulletPE2ConstraintSolverSpursSupport.h"
134 #endif
135 
137 {
138  float tmp[3] = {float(p[0]),float(p[1]),float(p[2])};
139  vmVector3 v;
140  loadXYZ(v, tmp);
141  return v;
142 }
143 
144 static SIMD_FORCE_INLINE vmQuat btReadQuat(const double* p)
145 {
146  float tmp[4] = {float(p[0]),float(p[1]),float(p[2]),float(p[4])};
147  vmQuat vq;
148  loadXYZW(vq, tmp);
149  return vq;
150 }
151 
152 static SIMD_FORCE_INLINE void btStoreVector3(const vmVector3 &src, double* p)
153 {
154  float tmp[3];
155  vmVector3 v = src;
156  storeXYZ(v, tmp);
157  p[0] = tmp[0];
158  p[1] = tmp[1];
159  p[2] = tmp[2];
160 }
161 
162 
164 {
165  vmVector3 v;
166  loadXYZ(v, p);
167  return v;
168 }
169 
170 static SIMD_FORCE_INLINE vmQuat btReadQuat(const float* p)
171 {
172  vmQuat vq;
173  loadXYZW(vq, p);
174  return vq;
175 }
176 
177 static SIMD_FORCE_INLINE void btStoreVector3(const vmVector3 &src, float* p)
178 {
179  vmVector3 v = src;
180  storeXYZ(v, p);
181 }
182 
183 
184 
185 
187 
188 enum {
195 };
196 
197 
199  PfxConstraintPair *offsetContactPairs;
207  float timeStep;
209 };
210 
211 
212 
216  PfxConstraintPair *contactPairs;
222  PfxConstraintPair *jointPairs;
229 
231 
233 
234 };
235 
240 };
241 
244  union {
248  };
249 
250  //SPU only
254 };
255 
256 
257 
258 
259 void SolverThreadFunc(void* userPtr,void* lsMemory);
260 void* SolverlsMemoryFunc();
264 {
265 
266 protected:
268 
270 
274 
275 
276 public:
277 
278  btParallelConstraintSolver(class btThreadSupportInterface* solverThreadSupport);
279 
280  virtual ~btParallelConstraintSolver();
281 
282  virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer,btDispatcher* dispatcher);
283 
284 };
285 
286 
287 
288 #endif //__BT_PARALLEL_CONSTRAINT_SOLVER_H
class btThreadSupportInterface * m_solverThreadSupport
PfxParallelGroup * jointParallelGroup
uint8_t pfxGetBroadphaseFlag(const PfxBroadphasePair &pair)
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
#define PFX_MAX_SOLVER_PHASES
btPersistentManifold * offsetContactManifolds
uint16_t get16(int elem) const
PfxParallelBatch * jointParallelBatches
#define ATTRIBUTE_ALIGNED128(a)
Definition: btScalar.h:61
PfxSetupContactConstraintsIO setupContactConstraints
void SolverThreadFunc(void *userPtr, void *lsMemory)
static void btStoreVector3(const vmVector3 &src, double *p)
void set8(int elem, uint8_t data)
PfxSolveConstraintsIO solveConstraints
void pfxSetMotionMaskA(PfxBroadphasePair &pair, uint8_t i)
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
PfxParallelBatch * contactParallelBatches
#define SIMD_FORCE_INLINE
Definition: btScalar.h:58
uint16_t pfxGetRigidBodyIdA(const PfxBroadphasePair &pair)
unsigned short uint16_t
uint32_t pfxGetContactId1(const PfxBroadphasePair &pair)
void set16(int elem, uint16_t data)
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btDispatcher *dispatcher)
btSequentialImpulseConstraintSolver Sequentially applies impulses
bool pfxGetActive(const PfxBroadphasePair &pair)
uint32_t get32(int elem) const
uint32_t pfxGetConstraintId1(const PfxConstraintPair &pair)
void pfxSetNumConstraints(PfxConstraintPair &pair, uint8_t n)
PfxSortData16 PfxBroadphasePair
PfxParallelGroup * contactParallelGroup
void set32(int elem, uint32_t data)
class btCriticalSection * criticalSection
The btParallelConstraintSolver performs computations on constraint rows in parallel Using the cross-p...
uint8_t pfxGetMotionMaskA(const PfxBroadphasePair &pair)
void pfxSetRigidBodyIdB(PfxBroadphasePair &pair, uint16_t i)
unsigned char uint8_t
uint16_t pfxGetRigidBodyIdB(const PfxBroadphasePair &pair)
void pfxSetContactId(PfxBroadphasePair &pair, uint32_t i)
btParallelConstraintSolver(class btThreadSupportInterface *solverThreadSupport)
uint8_t pfxGetMotionMaskB(const PfxBroadphasePair &pair)
void * SolverlsMemoryFunc()
void pfxSetRigidBodyIdA(PfxBroadphasePair &pair, uint16_t i)
btCollisionObject can be used to manage collision detection objects.
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:28
struct btSolverConstraint * offsetSolverConstraints
unsigned int uint32_t
void pfxSetActive(PfxBroadphasePair &pair, bool b)
void pfxSetConstraintId(PfxConstraintPair &pair, uint32_t i)
static vmQuat btReadQuat(const double *p)
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:59
#define PFX_MAX_SOLVER_BATCHES
btPersistentManifold * offsetContactManifolds
void loadXYZW(Quat &quat, const float *fptr)
uint8_t pfxGetNumConstraints(const PfxConstraintPair &pair)
void pfxSetMotionMaskB(PfxBroadphasePair &pair, uint8_t i)
struct btParallelSolverMemoryCache * m_memoryCache
TypedConstraint is the baseclass for Bullet constraints and vehicles.
__m128 vec_uint4
#define PFX_MAX_SOLVER_PAIRS
class btCriticalSection * m_criticalSection
btConstraintRow * offsetContactConstraintRows
PfxSortData16 PfxConstraintPair
struct btConstraintSolverIO * m_solverIO
void storeXYZ(const Vector3 &vec, float *fptr)
Definition: neon/vec_aos.h:105
uint8_t get8(int elem) const
static vmVector3 btReadVector3(const double *p)
void pfxSetBroadphaseFlag(PfxBroadphasePair &pair, uint8_t f)
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:69
__m128i vec_ushort8
__m128i vec_uchar16
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266
void loadXYZ(Vector3 &vec, const float *fptr)
Definition: neon/vec_aos.h:100