[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3OpenCL / RigidBody / kernels / solverUtils.h
1 //this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
2 static const char* solverUtilsCL =
3         "/*\n"
4         "Copyright (c) 2013 Advanced Micro Devices, Inc.  \n"
5         "This software is provided 'as-is', without any express or implied warranty.\n"
6         "In no event will the authors be held liable for any damages arising from the use of this software.\n"
7         "Permission is granted to anyone to use this software for any purpose, \n"
8         "including commercial applications, and to alter it and redistribute it freely, \n"
9         "subject to the following restrictions:\n"
10         "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.\n"
11         "2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\n"
12         "3. This notice may not be removed or altered from any source distribution.\n"
13         "*/\n"
14         "//Originally written by Erwin Coumans\n"
15         "#ifndef B3_CONTACT4DATA_H\n"
16         "#define B3_CONTACT4DATA_H\n"
17         "#ifndef B3_FLOAT4_H\n"
18         "#define B3_FLOAT4_H\n"
19         "#ifndef B3_PLATFORM_DEFINITIONS_H\n"
20         "#define B3_PLATFORM_DEFINITIONS_H\n"
21         "struct MyTest\n"
22         "{\n"
23         "       int bla;\n"
24         "};\n"
25         "#ifdef __cplusplus\n"
26         "#else\n"
27         "//keep B3_LARGE_FLOAT*B3_LARGE_FLOAT < FLT_MAX\n"
28         "#define B3_LARGE_FLOAT 1e18f\n"
29         "#define B3_INFINITY 1e18f\n"
30         "#define b3Assert(a)\n"
31         "#define b3ConstArray(a) __global const a*\n"
32         "#define b3AtomicInc atomic_inc\n"
33         "#define b3AtomicAdd atomic_add\n"
34         "#define b3Fabs fabs\n"
35         "#define b3Sqrt native_sqrt\n"
36         "#define b3Sin native_sin\n"
37         "#define b3Cos native_cos\n"
38         "#define B3_STATIC\n"
39         "#endif\n"
40         "#endif\n"
41         "#ifdef __cplusplus\n"
42         "#else\n"
43         "       typedef float4  b3Float4;\n"
44         "       #define b3Float4ConstArg const b3Float4\n"
45         "       #define b3MakeFloat4 (float4)\n"
46         "       float b3Dot3F4(b3Float4ConstArg v0,b3Float4ConstArg v1)\n"
47         "       {\n"
48         "               float4 a1 = b3MakeFloat4(v0.xyz,0.f);\n"
49         "               float4 b1 = b3MakeFloat4(v1.xyz,0.f);\n"
50         "               return dot(a1, b1);\n"
51         "       }\n"
52         "       b3Float4 b3Cross3(b3Float4ConstArg v0,b3Float4ConstArg v1)\n"
53         "       {\n"
54         "               float4 a1 = b3MakeFloat4(v0.xyz,0.f);\n"
55         "               float4 b1 = b3MakeFloat4(v1.xyz,0.f);\n"
56         "               return cross(a1, b1);\n"
57         "       }\n"
58         "       #define b3MinFloat4 min\n"
59         "       #define b3MaxFloat4 max\n"
60         "       #define b3Normalized(a) normalize(a)\n"
61         "#endif \n"
62         "               \n"
63         "inline bool b3IsAlmostZero(b3Float4ConstArg v)\n"
64         "{\n"
65         "       if(b3Fabs(v.x)>1e-6 || b3Fabs(v.y)>1e-6 || b3Fabs(v.z)>1e-6)    \n"
66         "               return false;\n"
67         "       return true;\n"
68         "}\n"
69         "inline int    b3MaxDot( b3Float4ConstArg vec, __global const b3Float4* vecArray, int vecLen, float* dotOut )\n"
70         "{\n"
71         "    float maxDot = -B3_INFINITY;\n"
72         "    int i = 0;\n"
73         "    int ptIndex = -1;\n"
74         "    for( i = 0; i < vecLen; i++ )\n"
75         "    {\n"
76         "        float dot = b3Dot3F4(vecArray[i],vec);\n"
77         "            \n"
78         "        if( dot > maxDot )\n"
79         "        {\n"
80         "            maxDot = dot;\n"
81         "            ptIndex = i;\n"
82         "        }\n"
83         "    }\n"
84         "       b3Assert(ptIndex>=0);\n"
85         "    if (ptIndex<0)\n"
86         "       {\n"
87         "               ptIndex = 0;\n"
88         "       }\n"
89         "    *dotOut = maxDot;\n"
90         "    return ptIndex;\n"
91         "}\n"
92         "#endif //B3_FLOAT4_H\n"
93         "typedef  struct b3Contact4Data b3Contact4Data_t;\n"
94         "struct b3Contact4Data\n"
95         "{\n"
96         "       b3Float4        m_worldPosB[4];\n"
97         "//     b3Float4        m_localPosA[4];\n"
98         "//     b3Float4        m_localPosB[4];\n"
99         "       b3Float4        m_worldNormalOnB;       //      w: m_nPoints\n"
100         "       unsigned short  m_restituitionCoeffCmp;\n"
101         "       unsigned short  m_frictionCoeffCmp;\n"
102         "       int m_batchIdx;\n"
103         "       int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr\n"
104         "       int m_bodyBPtrAndSignBit;\n"
105         "       int     m_childIndexA;\n"
106         "       int     m_childIndexB;\n"
107         "       int m_unused1;\n"
108         "       int m_unused2;\n"
109         "};\n"
110         "inline int b3Contact4Data_getNumPoints(const struct b3Contact4Data* contact)\n"
111         "{\n"
112         "       return (int)contact->m_worldNormalOnB.w;\n"
113         "};\n"
114         "inline void b3Contact4Data_setNumPoints(struct b3Contact4Data* contact, int numPoints)\n"
115         "{\n"
116         "       contact->m_worldNormalOnB.w = (float)numPoints;\n"
117         "};\n"
118         "#endif //B3_CONTACT4DATA_H\n"
119         "#pragma OPENCL EXTENSION cl_amd_printf : enable\n"
120         "#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable\n"
121         "#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n"
122         "#pragma OPENCL EXTENSION cl_khr_local_int32_extended_atomics : enable\n"
123         "#pragma OPENCL EXTENSION cl_khr_global_int32_extended_atomics : enable\n"
124         "#ifdef cl_ext_atomic_counters_32\n"
125         "#pragma OPENCL EXTENSION cl_ext_atomic_counters_32 : enable\n"
126         "#else\n"
127         "#define counter32_t volatile global int*\n"
128         "#endif\n"
129         "typedef unsigned int u32;\n"
130         "typedef unsigned short u16;\n"
131         "typedef unsigned char u8;\n"
132         "#define GET_GROUP_IDX get_group_id(0)\n"
133         "#define GET_LOCAL_IDX get_local_id(0)\n"
134         "#define GET_GLOBAL_IDX get_global_id(0)\n"
135         "#define GET_GROUP_SIZE get_local_size(0)\n"
136         "#define GET_NUM_GROUPS get_num_groups(0)\n"
137         "#define GROUP_LDS_BARRIER barrier(CLK_LOCAL_MEM_FENCE)\n"
138         "#define GROUP_MEM_FENCE mem_fence(CLK_LOCAL_MEM_FENCE)\n"
139         "#define AtomInc(x) atom_inc(&(x))\n"
140         "#define AtomInc1(x, out) out = atom_inc(&(x))\n"
141         "#define AppendInc(x, out) out = atomic_inc(x)\n"
142         "#define AtomAdd(x, value) atom_add(&(x), value)\n"
143         "#define AtomCmpxhg(x, cmp, value) atom_cmpxchg( &(x), cmp, value )\n"
144         "#define AtomXhg(x, value) atom_xchg ( &(x), value )\n"
145         "#define SELECT_UINT4( b, a, condition ) select( b,a,condition )\n"
146         "#define make_float4 (float4)\n"
147         "#define make_float2 (float2)\n"
148         "#define make_uint4 (uint4)\n"
149         "#define make_int4 (int4)\n"
150         "#define make_uint2 (uint2)\n"
151         "#define make_int2 (int2)\n"
152         "#define max2 max\n"
153         "#define min2 min\n"
154         "///////////////////////////////////////\n"
155         "//     Vector\n"
156         "///////////////////////////////////////\n"
157         "__inline\n"
158         "float fastDiv(float numerator, float denominator)\n"
159         "{\n"
160         "       return native_divide(numerator, denominator);   \n"
161         "//     return numerator/denominator;   \n"
162         "}\n"
163         "__inline\n"
164         "float4 fastDiv4(float4 numerator, float4 denominator)\n"
165         "{\n"
166         "       return native_divide(numerator, denominator);   \n"
167         "}\n"
168         "__inline\n"
169         "float fastSqrtf(float f2)\n"
170         "{\n"
171         "       return native_sqrt(f2);\n"
172         "//     return sqrt(f2);\n"
173         "}\n"
174         "__inline\n"
175         "float fastRSqrt(float f2)\n"
176         "{\n"
177         "       return native_rsqrt(f2);\n"
178         "}\n"
179         "__inline\n"
180         "float fastLength4(float4 v)\n"
181         "{\n"
182         "       return fast_length(v);\n"
183         "}\n"
184         "__inline\n"
185         "float4 fastNormalize4(float4 v)\n"
186         "{\n"
187         "       return fast_normalize(v);\n"
188         "}\n"
189         "__inline\n"
190         "float sqrtf(float a)\n"
191         "{\n"
192         "//     return sqrt(a);\n"
193         "       return native_sqrt(a);\n"
194         "}\n"
195         "__inline\n"
196         "float4 cross3(float4 a1, float4 b1)\n"
197         "{\n"
198         "       float4  a=make_float4(a1.xyz,0.f);\n"
199         "       float4  b=make_float4(b1.xyz,0.f);\n"
200         "       //float4        a=a1;\n"
201         "       //float4        b=b1;\n"
202         "       return cross(a,b);\n"
203         "}\n"
204         "__inline\n"
205         "float dot3F4(float4 a, float4 b)\n"
206         "{\n"
207         "       float4 a1 = make_float4(a.xyz,0.f);\n"
208         "       float4 b1 = make_float4(b.xyz,0.f);\n"
209         "       return dot(a1, b1);\n"
210         "}\n"
211         "__inline\n"
212         "float length3(const float4 a)\n"
213         "{\n"
214         "       return sqrtf(dot3F4(a,a));\n"
215         "}\n"
216         "__inline\n"
217         "float dot4(const float4 a, const float4 b)\n"
218         "{\n"
219         "       return dot( a, b );\n"
220         "}\n"
221         "//     for height\n"
222         "__inline\n"
223         "float dot3w1(const float4 point, const float4 eqn)\n"
224         "{\n"
225         "       return dot3F4(point,eqn) + eqn.w;\n"
226         "}\n"
227         "__inline\n"
228         "float4 normalize3(const float4 a)\n"
229         "{\n"
230         "       float4 n = make_float4(a.x, a.y, a.z, 0.f);\n"
231         "       return fastNormalize4( n );\n"
232         "//     float length = sqrtf(dot3F4(a, a));\n"
233         "//     return 1.f/length * a;\n"
234         "}\n"
235         "__inline\n"
236         "float4 normalize4(const float4 a)\n"
237         "{\n"
238         "       float length = sqrtf(dot4(a, a));\n"
239         "       return 1.f/length * a;\n"
240         "}\n"
241         "__inline\n"
242         "float4 createEquation(const float4 a, const float4 b, const float4 c)\n"
243         "{\n"
244         "       float4 eqn;\n"
245         "       float4 ab = b-a;\n"
246         "       float4 ac = c-a;\n"
247         "       eqn = normalize3( cross3(ab, ac) );\n"
248         "       eqn.w = -dot3F4(eqn,a);\n"
249         "       return eqn;\n"
250         "}\n"
251         "///////////////////////////////////////\n"
252         "//     Matrix3x3\n"
253         "///////////////////////////////////////\n"
254         "typedef struct\n"
255         "{\n"
256         "       float4 m_row[3];\n"
257         "}Matrix3x3;\n"
258         "__inline\n"
259         "Matrix3x3 mtZero();\n"
260         "__inline\n"
261         "Matrix3x3 mtIdentity();\n"
262         "__inline\n"
263         "Matrix3x3 mtTranspose(Matrix3x3 m);\n"
264         "__inline\n"
265         "Matrix3x3 mtMul(Matrix3x3 a, Matrix3x3 b);\n"
266         "__inline\n"
267         "float4 mtMul1(Matrix3x3 a, float4 b);\n"
268         "__inline\n"
269         "float4 mtMul3(float4 a, Matrix3x3 b);\n"
270         "__inline\n"
271         "Matrix3x3 mtZero()\n"
272         "{\n"
273         "       Matrix3x3 m;\n"
274         "       m.m_row[0] = (float4)(0.f);\n"
275         "       m.m_row[1] = (float4)(0.f);\n"
276         "       m.m_row[2] = (float4)(0.f);\n"
277         "       return m;\n"
278         "}\n"
279         "__inline\n"
280         "Matrix3x3 mtIdentity()\n"
281         "{\n"
282         "       Matrix3x3 m;\n"
283         "       m.m_row[0] = (float4)(1,0,0,0);\n"
284         "       m.m_row[1] = (float4)(0,1,0,0);\n"
285         "       m.m_row[2] = (float4)(0,0,1,0);\n"
286         "       return m;\n"
287         "}\n"
288         "__inline\n"
289         "Matrix3x3 mtTranspose(Matrix3x3 m)\n"
290         "{\n"
291         "       Matrix3x3 out;\n"
292         "       out.m_row[0] = (float4)(m.m_row[0].x, m.m_row[1].x, m.m_row[2].x, 0.f);\n"
293         "       out.m_row[1] = (float4)(m.m_row[0].y, m.m_row[1].y, m.m_row[2].y, 0.f);\n"
294         "       out.m_row[2] = (float4)(m.m_row[0].z, m.m_row[1].z, m.m_row[2].z, 0.f);\n"
295         "       return out;\n"
296         "}\n"
297         "__inline\n"
298         "Matrix3x3 mtMul(Matrix3x3 a, Matrix3x3 b)\n"
299         "{\n"
300         "       Matrix3x3 transB;\n"
301         "       transB = mtTranspose( b );\n"
302         "       Matrix3x3 ans;\n"
303         "       //      why this doesn't run when 0ing in the for{}\n"
304         "       a.m_row[0].w = 0.f;\n"
305         "       a.m_row[1].w = 0.f;\n"
306         "       a.m_row[2].w = 0.f;\n"
307         "       for(int i=0; i<3; i++)\n"
308         "       {\n"
309         "//     a.m_row[i].w = 0.f;\n"
310         "               ans.m_row[i].x = dot3F4(a.m_row[i],transB.m_row[0]);\n"
311         "               ans.m_row[i].y = dot3F4(a.m_row[i],transB.m_row[1]);\n"
312         "               ans.m_row[i].z = dot3F4(a.m_row[i],transB.m_row[2]);\n"
313         "               ans.m_row[i].w = 0.f;\n"
314         "       }\n"
315         "       return ans;\n"
316         "}\n"
317         "__inline\n"
318         "float4 mtMul1(Matrix3x3 a, float4 b)\n"
319         "{\n"
320         "       float4 ans;\n"
321         "       ans.x = dot3F4( a.m_row[0], b );\n"
322         "       ans.y = dot3F4( a.m_row[1], b );\n"
323         "       ans.z = dot3F4( a.m_row[2], b );\n"
324         "       ans.w = 0.f;\n"
325         "       return ans;\n"
326         "}\n"
327         "__inline\n"
328         "float4 mtMul3(float4 a, Matrix3x3 b)\n"
329         "{\n"
330         "       float4 colx = make_float4(b.m_row[0].x, b.m_row[1].x, b.m_row[2].x, 0);\n"
331         "       float4 coly = make_float4(b.m_row[0].y, b.m_row[1].y, b.m_row[2].y, 0);\n"
332         "       float4 colz = make_float4(b.m_row[0].z, b.m_row[1].z, b.m_row[2].z, 0);\n"
333         "       float4 ans;\n"
334         "       ans.x = dot3F4( a, colx );\n"
335         "       ans.y = dot3F4( a, coly );\n"
336         "       ans.z = dot3F4( a, colz );\n"
337         "       return ans;\n"
338         "}\n"
339         "///////////////////////////////////////\n"
340         "//     Quaternion\n"
341         "///////////////////////////////////////\n"
342         "typedef float4 Quaternion;\n"
343         "__inline\n"
344         "Quaternion qtMul(Quaternion a, Quaternion b);\n"
345         "__inline\n"
346         "Quaternion qtNormalize(Quaternion in);\n"
347         "__inline\n"
348         "float4 qtRotate(Quaternion q, float4 vec);\n"
349         "__inline\n"
350         "Quaternion qtInvert(Quaternion q);\n"
351         "__inline\n"
352         "Quaternion qtMul(Quaternion a, Quaternion b)\n"
353         "{\n"
354         "       Quaternion ans;\n"
355         "       ans = cross3( a, b );\n"
356         "       ans += a.w*b+b.w*a;\n"
357         "//     ans.w = a.w*b.w - (a.x*b.x+a.y*b.y+a.z*b.z);\n"
358         "       ans.w = a.w*b.w - dot3F4(a, b);\n"
359         "       return ans;\n"
360         "}\n"
361         "__inline\n"
362         "Quaternion qtNormalize(Quaternion in)\n"
363         "{\n"
364         "       return fastNormalize4(in);\n"
365         "//     in /= length( in );\n"
366         "//     return in;\n"
367         "}\n"
368         "__inline\n"
369         "float4 qtRotate(Quaternion q, float4 vec)\n"
370         "{\n"
371         "       Quaternion qInv = qtInvert( q );\n"
372         "       float4 vcpy = vec;\n"
373         "       vcpy.w = 0.f;\n"
374         "       float4 out = qtMul(qtMul(q,vcpy),qInv);\n"
375         "       return out;\n"
376         "}\n"
377         "__inline\n"
378         "Quaternion qtInvert(Quaternion q)\n"
379         "{\n"
380         "       return (Quaternion)(-q.xyz, q.w);\n"
381         "}\n"
382         "__inline\n"
383         "float4 qtInvRotate(const Quaternion q, float4 vec)\n"
384         "{\n"
385         "       return qtRotate( qtInvert( q ), vec );\n"
386         "}\n"
387         "#define WG_SIZE 64\n"
388         "typedef struct\n"
389         "{\n"
390         "       float4 m_pos;\n"
391         "       Quaternion m_quat;\n"
392         "       float4 m_linVel;\n"
393         "       float4 m_angVel;\n"
394         "       u32 m_shapeIdx;\n"
395         "       float m_invMass;\n"
396         "       float m_restituitionCoeff;\n"
397         "       float m_frictionCoeff;\n"
398         "} Body;\n"
399         "typedef struct\n"
400         "{\n"
401         "       Matrix3x3 m_invInertia;\n"
402         "       Matrix3x3 m_initInvInertia;\n"
403         "} Shape;\n"
404         "typedef struct\n"
405         "{\n"
406         "       float4 m_linear;\n"
407         "       float4 m_worldPos[4];\n"
408         "       float4 m_center;        \n"
409         "       float m_jacCoeffInv[4];\n"
410         "       float m_b[4];\n"
411         "       float m_appliedRambdaDt[4];\n"
412         "       float m_fJacCoeffInv[2];        \n"
413         "       float m_fAppliedRambdaDt[2];    \n"
414         "       u32 m_bodyA;\n"
415         "       u32 m_bodyB;\n"
416         "       int m_batchIdx;\n"
417         "       u32 m_paddings;\n"
418         "} Constraint4;\n"
419         "__kernel void CountBodiesKernel(__global struct b3Contact4Data* manifoldPtr, __global unsigned int* bodyCount, __global int2* contactConstraintOffsets, int numContactManifolds, int fixedBodyIndex)\n"
420         "{\n"
421         "       int i = GET_GLOBAL_IDX;\n"
422         "       \n"
423         "       if( i < numContactManifolds)\n"
424         "       {\n"
425         "               int pa = manifoldPtr[i].m_bodyAPtrAndSignBit;\n"
426         "               bool isFixedA = (pa <0) || (pa == fixedBodyIndex);\n"
427         "               int bodyIndexA = abs(pa);\n"
428         "               if (!isFixedA)\n"
429         "               {\n"
430         "                        AtomInc1(bodyCount[bodyIndexA],contactConstraintOffsets[i].x);\n"
431         "               }\n"
432         "               barrier(CLK_GLOBAL_MEM_FENCE);\n"
433         "               int pb = manifoldPtr[i].m_bodyBPtrAndSignBit;\n"
434         "               bool isFixedB = (pb <0) || (pb == fixedBodyIndex);\n"
435         "               int bodyIndexB = abs(pb);\n"
436         "               if (!isFixedB)\n"
437         "               {\n"
438         "                       AtomInc1(bodyCount[bodyIndexB],contactConstraintOffsets[i].y);\n"
439         "               } \n"
440         "       }\n"
441         "}\n"
442         "__kernel void ClearVelocitiesKernel(__global float4* linearVelocities,__global float4* angularVelocities, int numSplitBodies)\n"
443         "{\n"
444         "       int i = GET_GLOBAL_IDX;\n"
445         "       \n"
446         "       if( i < numSplitBodies)\n"
447         "       {\n"
448         "               linearVelocities[i] = make_float4(0);\n"
449         "               angularVelocities[i] = make_float4(0);\n"
450         "       }\n"
451         "}\n"
452         "__kernel void AverageVelocitiesKernel(__global Body* gBodies,__global int* offsetSplitBodies,__global const unsigned int* bodyCount,\n"
453         "__global float4* deltaLinearVelocities, __global float4* deltaAngularVelocities, int numBodies)\n"
454         "{\n"
455         "       int i = GET_GLOBAL_IDX;\n"
456         "       if (i<numBodies)\n"
457         "       {\n"
458         "               if (gBodies[i].m_invMass)\n"
459         "               {\n"
460         "                       int bodyOffset = offsetSplitBodies[i];\n"
461         "                       int count = bodyCount[i];\n"
462         "                       float factor = 1.f/((float)count);\n"
463         "                       float4 averageLinVel = make_float4(0.f);\n"
464         "                       float4 averageAngVel = make_float4(0.f);\n"
465         "                       \n"
466         "                       for (int j=0;j<count;j++)\n"
467         "                       {\n"
468         "                               averageLinVel += deltaLinearVelocities[bodyOffset+j]*factor;\n"
469         "                               averageAngVel += deltaAngularVelocities[bodyOffset+j]*factor;\n"
470         "                       }\n"
471         "                       \n"
472         "                       for (int j=0;j<count;j++)\n"
473         "                       {\n"
474         "                               deltaLinearVelocities[bodyOffset+j] = averageLinVel;\n"
475         "                               deltaAngularVelocities[bodyOffset+j] = averageAngVel;\n"
476         "                       }\n"
477         "                       \n"
478         "               }//bodies[i].m_invMass\n"
479         "       }//i<numBodies\n"
480         "}\n"
481         "void setLinearAndAngular( float4 n, float4 r0, float4 r1, float4* linear, float4* angular0, float4* angular1)\n"
482         "{\n"
483         "       *linear = make_float4(n.xyz,0.f);\n"
484         "       *angular0 = cross3(r0, n);\n"
485         "       *angular1 = -cross3(r1, n);\n"
486         "}\n"
487         "float calcRelVel( float4 l0, float4 l1, float4 a0, float4 a1, float4 linVel0, float4 angVel0, float4 linVel1, float4 angVel1 )\n"
488         "{\n"
489         "       return dot3F4(l0, linVel0) + dot3F4(a0, angVel0) + dot3F4(l1, linVel1) + dot3F4(a1, angVel1);\n"
490         "}\n"
491         "float calcJacCoeff(const float4 linear0, const float4 linear1, const float4 angular0, const float4 angular1,\n"
492         "                                       float invMass0, const Matrix3x3* invInertia0, float invMass1, const Matrix3x3* invInertia1, float countA, float countB)\n"
493         "{\n"
494         "       //      linear0,1 are normlized\n"
495         "       float jmj0 = invMass0;//dot3F4(linear0, linear0)*invMass0;\n"
496         "       float jmj1 = dot3F4(mtMul3(angular0,*invInertia0), angular0);\n"
497         "       float jmj2 = invMass1;//dot3F4(linear1, linear1)*invMass1;\n"
498         "       float jmj3 = dot3F4(mtMul3(angular1,*invInertia1), angular1);\n"
499         "       return -1.f/((jmj0+jmj1)*countA+(jmj2+jmj3)*countB);\n"
500         "}\n"
501         "void btPlaneSpace1 (float4 n, float4* p, float4* q);\n"
502         " void btPlaneSpace1 (float4 n, float4* p, float4* q)\n"
503         "{\n"
504         "  if (fabs(n.z) > 0.70710678f) {\n"
505         "    // choose p in y-z plane\n"
506         "    float a = n.y*n.y + n.z*n.z;\n"
507         "    float k = 1.f/sqrt(a);\n"
508         "    p[0].x = 0;\n"
509         "       p[0].y = -n.z*k;\n"
510         "       p[0].z = n.y*k;\n"
511         "    // set q = n x p\n"
512         "    q[0].x = a*k;\n"
513         "       q[0].y = -n.x*p[0].z;\n"
514         "       q[0].z = n.x*p[0].y;\n"
515         "  }\n"
516         "  else {\n"
517         "    // choose p in x-y plane\n"
518         "    float a = n.x*n.x + n.y*n.y;\n"
519         "    float k = 1.f/sqrt(a);\n"
520         "    p[0].x = -n.y*k;\n"
521         "       p[0].y = n.x*k;\n"
522         "       p[0].z = 0;\n"
523         "    // set q = n x p\n"
524         "    q[0].x = -n.z*p[0].y;\n"
525         "       q[0].y = n.z*p[0].x;\n"
526         "       q[0].z = a*k;\n"
527         "  }\n"
528         "}\n"
529         "void solveContact(__global Constraint4* cs,\n"
530         "                       float4 posA, float4* linVelA, float4* angVelA, float invMassA, Matrix3x3 invInertiaA,\n"
531         "                       float4 posB, float4* linVelB, float4* angVelB, float invMassB, Matrix3x3 invInertiaB,\n"
532         "                       float4* dLinVelA, float4* dAngVelA, float4* dLinVelB, float4* dAngVelB)\n"
533         "{\n"
534         "       float minRambdaDt = 0;\n"
535         "       float maxRambdaDt = FLT_MAX;\n"
536         "       for(int ic=0; ic<4; ic++)\n"
537         "       {\n"
538         "               if( cs->m_jacCoeffInv[ic] == 0.f ) continue;\n"
539         "               float4 angular0, angular1, linear;\n"
540         "               float4 r0 = cs->m_worldPos[ic] - posA;\n"
541         "               float4 r1 = cs->m_worldPos[ic] - posB;\n"
542         "               setLinearAndAngular( cs->m_linear, r0, r1, &linear, &angular0, &angular1 );\n"
543         "       \n"
544         "               float rambdaDt = calcRelVel( cs->m_linear, -cs->m_linear, angular0, angular1, \n"
545         "                       *linVelA+*dLinVelA, *angVelA+*dAngVelA, *linVelB+*dLinVelB, *angVelB+*dAngVelB ) + cs->m_b[ic];\n"
546         "               rambdaDt *= cs->m_jacCoeffInv[ic];\n"
547         "               \n"
548         "               {\n"
549         "                       float prevSum = cs->m_appliedRambdaDt[ic];\n"
550         "                       float updated = prevSum;\n"
551         "                       updated += rambdaDt;\n"
552         "                       updated = max2( updated, minRambdaDt );\n"
553         "                       updated = min2( updated, maxRambdaDt );\n"
554         "                       rambdaDt = updated - prevSum;\n"
555         "                       cs->m_appliedRambdaDt[ic] = updated;\n"
556         "               }\n"
557         "                       \n"
558         "               float4 linImp0 = invMassA*linear*rambdaDt;\n"
559         "               float4 linImp1 = invMassB*(-linear)*rambdaDt;\n"
560         "               float4 angImp0 = mtMul1(invInertiaA, angular0)*rambdaDt;\n"
561         "               float4 angImp1 = mtMul1(invInertiaB, angular1)*rambdaDt;\n"
562         "               \n"
563         "               if (invMassA)\n"
564         "               {\n"
565         "                       *dLinVelA += linImp0;\n"
566         "                       *dAngVelA += angImp0;\n"
567         "               }\n"
568         "               if (invMassB)\n"
569         "               {\n"
570         "                       *dLinVelB += linImp1;\n"
571         "                       *dAngVelB += angImp1;\n"
572         "               }\n"
573         "       }\n"
574         "}\n"
575         "//     solveContactConstraint( gBodies, gShapes, &gConstraints[i] ,contactConstraintOffsets,offsetSplitBodies, deltaLinearVelocities, deltaAngularVelocities);\n"
576         "void solveContactConstraint(__global Body* gBodies, __global Shape* gShapes, __global Constraint4* ldsCs, \n"
577         "__global int2* contactConstraintOffsets,__global unsigned int* offsetSplitBodies,\n"
578         "__global float4* deltaLinearVelocities, __global float4* deltaAngularVelocities)\n"
579         "{\n"
580         "       //float frictionCoeff = ldsCs[0].m_linear.w;\n"
581         "       int aIdx = ldsCs[0].m_bodyA;\n"
582         "       int bIdx = ldsCs[0].m_bodyB;\n"
583         "       float4 posA = gBodies[aIdx].m_pos;\n"
584         "       float4 linVelA = gBodies[aIdx].m_linVel;\n"
585         "       float4 angVelA = gBodies[aIdx].m_angVel;\n"
586         "       float invMassA = gBodies[aIdx].m_invMass;\n"
587         "       Matrix3x3 invInertiaA = gShapes[aIdx].m_invInertia;\n"
588         "       float4 posB = gBodies[bIdx].m_pos;\n"
589         "       float4 linVelB = gBodies[bIdx].m_linVel;\n"
590         "       float4 angVelB = gBodies[bIdx].m_angVel;\n"
591         "       float invMassB = gBodies[bIdx].m_invMass;\n"
592         "       Matrix3x3 invInertiaB = gShapes[bIdx].m_invInertia;\n"
593         "                       \n"
594         "       float4 dLinVelA = make_float4(0,0,0,0);\n"
595         "       float4 dAngVelA = make_float4(0,0,0,0);\n"
596         "       float4 dLinVelB = make_float4(0,0,0,0);\n"
597         "       float4 dAngVelB = make_float4(0,0,0,0);\n"
598         "                       \n"
599         "       int bodyOffsetA = offsetSplitBodies[aIdx];\n"
600         "       int constraintOffsetA = contactConstraintOffsets[0].x;\n"
601         "       int splitIndexA = bodyOffsetA+constraintOffsetA;\n"
602         "       \n"
603         "       if (invMassA)\n"
604         "       {\n"
605         "               dLinVelA = deltaLinearVelocities[splitIndexA];\n"
606         "               dAngVelA = deltaAngularVelocities[splitIndexA];\n"
607         "       }\n"
608         "       int bodyOffsetB = offsetSplitBodies[bIdx];\n"
609         "       int constraintOffsetB = contactConstraintOffsets[0].y;\n"
610         "       int splitIndexB= bodyOffsetB+constraintOffsetB;\n"
611         "       if (invMassB)\n"
612         "       {\n"
613         "               dLinVelB = deltaLinearVelocities[splitIndexB];\n"
614         "               dAngVelB = deltaAngularVelocities[splitIndexB];\n"
615         "       }\n"
616         "       solveContact( ldsCs, posA, &linVelA, &angVelA, invMassA, invInertiaA,\n"
617         "                       posB, &linVelB, &angVelB, invMassB, invInertiaB ,&dLinVelA, &dAngVelA, &dLinVelB, &dAngVelB);\n"
618         "       if (invMassA)\n"
619         "       {\n"
620         "               deltaLinearVelocities[splitIndexA] = dLinVelA;\n"
621         "               deltaAngularVelocities[splitIndexA] = dAngVelA;\n"
622         "       } \n"
623         "       if (invMassB)\n"
624         "       {\n"
625         "               deltaLinearVelocities[splitIndexB] = dLinVelB;\n"
626         "               deltaAngularVelocities[splitIndexB] = dAngVelB;\n"
627         "       }\n"
628         "}\n"
629         "__kernel void SolveContactJacobiKernel(__global Constraint4* gConstraints, __global Body* gBodies, __global Shape* gShapes ,\n"
630         "__global int2* contactConstraintOffsets,__global unsigned int* offsetSplitBodies,__global float4* deltaLinearVelocities, __global float4* deltaAngularVelocities,\n"
631         "float deltaTime, float positionDrift, float positionConstraintCoeff, int fixedBodyIndex, int numManifolds\n"
632         ")\n"
633         "{\n"
634         "       int i = GET_GLOBAL_IDX;\n"
635         "       if (i<numManifolds)\n"
636         "       {\n"
637         "               solveContactConstraint( gBodies, gShapes, &gConstraints[i] ,&contactConstraintOffsets[i],offsetSplitBodies, deltaLinearVelocities, deltaAngularVelocities);\n"
638         "       }\n"
639         "}\n"
640         "void solveFrictionConstraint(__global Body* gBodies, __global Shape* gShapes, __global Constraint4* ldsCs,\n"
641         "                                                       __global int2* contactConstraintOffsets,__global unsigned int* offsetSplitBodies,\n"
642         "                                                       __global float4* deltaLinearVelocities, __global float4* deltaAngularVelocities)\n"
643         "{\n"
644         "       float frictionCoeff = 0.7f;//ldsCs[0].m_linear.w;\n"
645         "       int aIdx = ldsCs[0].m_bodyA;\n"
646         "       int bIdx = ldsCs[0].m_bodyB;\n"
647         "       float4 posA = gBodies[aIdx].m_pos;\n"
648         "       float4 linVelA = gBodies[aIdx].m_linVel;\n"
649         "       float4 angVelA = gBodies[aIdx].m_angVel;\n"
650         "       float invMassA = gBodies[aIdx].m_invMass;\n"
651         "       Matrix3x3 invInertiaA = gShapes[aIdx].m_invInertia;\n"
652         "       float4 posB = gBodies[bIdx].m_pos;\n"
653         "       float4 linVelB = gBodies[bIdx].m_linVel;\n"
654         "       float4 angVelB = gBodies[bIdx].m_angVel;\n"
655         "       float invMassB = gBodies[bIdx].m_invMass;\n"
656         "       Matrix3x3 invInertiaB = gShapes[bIdx].m_invInertia;\n"
657         "       \n"
658         "       float4 dLinVelA = make_float4(0,0,0,0);\n"
659         "       float4 dAngVelA = make_float4(0,0,0,0);\n"
660         "       float4 dLinVelB = make_float4(0,0,0,0);\n"
661         "       float4 dAngVelB = make_float4(0,0,0,0);\n"
662         "                       \n"
663         "       int bodyOffsetA = offsetSplitBodies[aIdx];\n"
664         "       int constraintOffsetA = contactConstraintOffsets[0].x;\n"
665         "       int splitIndexA = bodyOffsetA+constraintOffsetA;\n"
666         "       \n"
667         "       if (invMassA)\n"
668         "       {\n"
669         "               dLinVelA = deltaLinearVelocities[splitIndexA];\n"
670         "               dAngVelA = deltaAngularVelocities[splitIndexA];\n"
671         "       }\n"
672         "       int bodyOffsetB = offsetSplitBodies[bIdx];\n"
673         "       int constraintOffsetB = contactConstraintOffsets[0].y;\n"
674         "       int splitIndexB= bodyOffsetB+constraintOffsetB;\n"
675         "       if (invMassB)\n"
676         "       {\n"
677         "               dLinVelB = deltaLinearVelocities[splitIndexB];\n"
678         "               dAngVelB = deltaAngularVelocities[splitIndexB];\n"
679         "       }\n"
680         "       {\n"
681         "               float maxRambdaDt[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX};\n"
682         "               float minRambdaDt[4] = {0.f,0.f,0.f,0.f};\n"
683         "               float sum = 0;\n"
684         "               for(int j=0; j<4; j++)\n"
685         "               {\n"
686         "                       sum +=ldsCs[0].m_appliedRambdaDt[j];\n"
687         "               }\n"
688         "               frictionCoeff = 0.7f;\n"
689         "               for(int j=0; j<4; j++)\n"
690         "               {\n"
691         "                       maxRambdaDt[j] = frictionCoeff*sum;\n"
692         "                       minRambdaDt[j] = -maxRambdaDt[j];\n"
693         "               }\n"
694         "               \n"
695         "//             solveFriction( ldsCs, posA, &linVelA, &angVelA, invMassA, invInertiaA,\n"
696         "//                     posB, &linVelB, &angVelB, invMassB, invInertiaB, maxRambdaDt, minRambdaDt );\n"
697         "               \n"
698         "               \n"
699         "               {\n"
700         "                       \n"
701         "                       __global Constraint4* cs = ldsCs;\n"
702         "                       \n"
703         "                       if( cs->m_fJacCoeffInv[0] == 0 && cs->m_fJacCoeffInv[0] == 0 ) return;\n"
704         "                       const float4 center = cs->m_center;\n"
705         "                       \n"
706         "                       float4 n = -cs->m_linear;\n"
707         "                       \n"
708         "                       float4 tangent[2];\n"
709         "                       btPlaneSpace1(n,&tangent[0],&tangent[1]);\n"
710         "                       float4 angular0, angular1, linear;\n"
711         "                       float4 r0 = center - posA;\n"
712         "                       float4 r1 = center - posB;\n"
713         "                       for(int i=0; i<2; i++)\n"
714         "                       {\n"
715         "                               setLinearAndAngular( tangent[i], r0, r1, &linear, &angular0, &angular1 );\n"
716         "                               float rambdaDt = calcRelVel(linear, -linear, angular0, angular1,\n"
717         "                                                                                       linVelA+dLinVelA, angVelA+dAngVelA, linVelB+dLinVelB, angVelB+dAngVelB );\n"
718         "                               rambdaDt *= cs->m_fJacCoeffInv[i];\n"
719         "                               \n"
720         "                               {\n"
721         "                                       float prevSum = cs->m_fAppliedRambdaDt[i];\n"
722         "                                       float updated = prevSum;\n"
723         "                                       updated += rambdaDt;\n"
724         "                                       updated = max2( updated, minRambdaDt[i] );\n"
725         "                                       updated = min2( updated, maxRambdaDt[i] );\n"
726         "                                       rambdaDt = updated - prevSum;\n"
727         "                                       cs->m_fAppliedRambdaDt[i] = updated;\n"
728         "                               }\n"
729         "                               \n"
730         "                               float4 linImp0 = invMassA*linear*rambdaDt;\n"
731         "                               float4 linImp1 = invMassB*(-linear)*rambdaDt;\n"
732         "                               float4 angImp0 = mtMul1(invInertiaA, angular0)*rambdaDt;\n"
733         "                               float4 angImp1 = mtMul1(invInertiaB, angular1)*rambdaDt;\n"
734         "                               \n"
735         "                               dLinVelA += linImp0;\n"
736         "                               dAngVelA += angImp0;\n"
737         "                               dLinVelB += linImp1;\n"
738         "                               dAngVelB += angImp1;\n"
739         "                       }\n"
740         "                       {       //      angular damping for point constraint\n"
741         "                               float4 ab = normalize3( posB - posA );\n"
742         "                               float4 ac = normalize3( center - posA );\n"
743         "                               if( dot3F4( ab, ac ) > 0.95f  || (invMassA == 0.f || invMassB == 0.f))\n"
744         "                               {\n"
745         "                                       float angNA = dot3F4( n, angVelA );\n"
746         "                                       float angNB = dot3F4( n, angVelB );\n"
747         "                                       \n"
748         "                                       dAngVelA -= (angNA*0.1f)*n;\n"
749         "                                       dAngVelB -= (angNB*0.1f)*n;\n"
750         "                               }\n"
751         "                       }\n"
752         "               }\n"
753         "               \n"
754         "               \n"
755         "       }\n"
756         "       if (invMassA)\n"
757         "       {\n"
758         "               deltaLinearVelocities[splitIndexA] = dLinVelA;\n"
759         "               deltaAngularVelocities[splitIndexA] = dAngVelA;\n"
760         "       } \n"
761         "       if (invMassB)\n"
762         "       {\n"
763         "               deltaLinearVelocities[splitIndexB] = dLinVelB;\n"
764         "               deltaAngularVelocities[splitIndexB] = dAngVelB;\n"
765         "       }\n"
766         " \n"
767         "}\n"
768         "__kernel void SolveFrictionJacobiKernel(__global Constraint4* gConstraints, __global Body* gBodies, __global Shape* gShapes ,\n"
769         "                                                                               __global int2* contactConstraintOffsets,__global unsigned int* offsetSplitBodies,\n"
770         "                                                                               __global float4* deltaLinearVelocities, __global float4* deltaAngularVelocities,\n"
771         "                                                                               float deltaTime, float positionDrift, float positionConstraintCoeff, int fixedBodyIndex, int numManifolds\n"
772         ")\n"
773         "{\n"
774         "       int i = GET_GLOBAL_IDX;\n"
775         "       if (i<numManifolds)\n"
776         "       {\n"
777         "               solveFrictionConstraint( gBodies, gShapes, &gConstraints[i] ,&contactConstraintOffsets[i],offsetSplitBodies, deltaLinearVelocities, deltaAngularVelocities);\n"
778         "       }\n"
779         "}\n"
780         "__kernel void UpdateBodyVelocitiesKernel(__global Body* gBodies,__global int* offsetSplitBodies,__global const unsigned int* bodyCount,\n"
781         "                                                                       __global float4* deltaLinearVelocities, __global float4* deltaAngularVelocities, int numBodies)\n"
782         "{\n"
783         "       int i = GET_GLOBAL_IDX;\n"
784         "       if (i<numBodies)\n"
785         "       {\n"
786         "               if (gBodies[i].m_invMass)\n"
787         "               {\n"
788         "                       int bodyOffset = offsetSplitBodies[i];\n"
789         "                       int count = bodyCount[i];\n"
790         "                       if (count)\n"
791         "                       {\n"
792         "                               gBodies[i].m_linVel += deltaLinearVelocities[bodyOffset];\n"
793         "                               gBodies[i].m_angVel += deltaAngularVelocities[bodyOffset];\n"
794         "                       }\n"
795         "               }\n"
796         "       }\n"
797         "}\n"
798         "void setConstraint4( const float4 posA, const float4 linVelA, const float4 angVelA, float invMassA, const Matrix3x3 invInertiaA,\n"
799         "       const float4 posB, const float4 linVelB, const float4 angVelB, float invMassB, const Matrix3x3 invInertiaB, \n"
800         "       __global struct b3Contact4Data* src, float dt, float positionDrift, float positionConstraintCoeff,float countA, float countB,\n"
801         "       Constraint4* dstC )\n"
802         "{\n"
803         "       dstC->m_bodyA = abs(src->m_bodyAPtrAndSignBit);\n"
804         "       dstC->m_bodyB = abs(src->m_bodyBPtrAndSignBit);\n"
805         "       float dtInv = 1.f/dt;\n"
806         "       for(int ic=0; ic<4; ic++)\n"
807         "       {\n"
808         "               dstC->m_appliedRambdaDt[ic] = 0.f;\n"
809         "       }\n"
810         "       dstC->m_fJacCoeffInv[0] = dstC->m_fJacCoeffInv[1] = 0.f;\n"
811         "       dstC->m_linear = src->m_worldNormalOnB;\n"
812         "       dstC->m_linear.w = 0.7f ;//src->getFrictionCoeff() );\n"
813         "       for(int ic=0; ic<4; ic++)\n"
814         "       {\n"
815         "               float4 r0 = src->m_worldPosB[ic] - posA;\n"
816         "               float4 r1 = src->m_worldPosB[ic] - posB;\n"
817         "               if( ic >= src->m_worldNormalOnB.w )//npoints\n"
818         "               {\n"
819         "                       dstC->m_jacCoeffInv[ic] = 0.f;\n"
820         "                       continue;\n"
821         "               }\n"
822         "               float relVelN;\n"
823         "               {\n"
824         "                       float4 linear, angular0, angular1;\n"
825         "                       setLinearAndAngular(src->m_worldNormalOnB, r0, r1, &linear, &angular0, &angular1);\n"
826         "                       dstC->m_jacCoeffInv[ic] = calcJacCoeff(linear, -linear, angular0, angular1,\n"
827         "                               invMassA, &invInertiaA, invMassB, &invInertiaB , countA, countB);\n"
828         "                       relVelN = calcRelVel(linear, -linear, angular0, angular1,\n"
829         "                               linVelA, angVelA, linVelB, angVelB);\n"
830         "                       float e = 0.f;//src->getRestituitionCoeff();\n"
831         "                       if( relVelN*relVelN < 0.004f ) e = 0.f;\n"
832         "                       dstC->m_b[ic] = e*relVelN;\n"
833         "                       //float penetration = src->m_worldPosB[ic].w;\n"
834         "                       dstC->m_b[ic] += (src->m_worldPosB[ic].w + positionDrift)*positionConstraintCoeff*dtInv;\n"
835         "                       dstC->m_appliedRambdaDt[ic] = 0.f;\n"
836         "               }\n"
837         "       }\n"
838         "       if( src->m_worldNormalOnB.w > 0 )//npoints\n"
839         "       {       //      prepare friction\n"
840         "               float4 center = make_float4(0.f);\n"
841         "               for(int i=0; i<src->m_worldNormalOnB.w; i++) \n"
842         "                       center += src->m_worldPosB[i];\n"
843         "               center /= (float)src->m_worldNormalOnB.w;\n"
844         "               float4 tangent[2];\n"
845         "               btPlaneSpace1(-src->m_worldNormalOnB,&tangent[0],&tangent[1]);\n"
846         "               \n"
847         "               float4 r[2];\n"
848         "               r[0] = center - posA;\n"
849         "               r[1] = center - posB;\n"
850         "               for(int i=0; i<2; i++)\n"
851         "               {\n"
852         "                       float4 linear, angular0, angular1;\n"
853         "                       setLinearAndAngular(tangent[i], r[0], r[1], &linear, &angular0, &angular1);\n"
854         "                       dstC->m_fJacCoeffInv[i] = calcJacCoeff(linear, -linear, angular0, angular1,\n"
855         "                               invMassA, &invInertiaA, invMassB, &invInertiaB ,countA, countB);\n"
856         "                       dstC->m_fAppliedRambdaDt[i] = 0.f;\n"
857         "               }\n"
858         "               dstC->m_center = center;\n"
859         "       }\n"
860         "       for(int i=0; i<4; i++)\n"
861         "       {\n"
862         "               if( i<src->m_worldNormalOnB.w )\n"
863         "               {\n"
864         "                       dstC->m_worldPos[i] = src->m_worldPosB[i];\n"
865         "               }\n"
866         "               else\n"
867         "               {\n"
868         "                       dstC->m_worldPos[i] = make_float4(0.f);\n"
869         "               }\n"
870         "       }\n"
871         "}\n"
872         "__kernel\n"
873         "__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
874         "void ContactToConstraintSplitKernel(__global const struct b3Contact4Data* gContact, __global const Body* gBodies, __global const Shape* gShapes, __global Constraint4* gConstraintOut, \n"
875         "__global const unsigned int* bodyCount,\n"
876         "int nContacts,\n"
877         "float dt,\n"
878         "float positionDrift,\n"
879         "float positionConstraintCoeff\n"
880         ")\n"
881         "{\n"
882         "       int gIdx = GET_GLOBAL_IDX;\n"
883         "       \n"
884         "       if( gIdx < nContacts )\n"
885         "       {\n"
886         "               int aIdx = abs(gContact[gIdx].m_bodyAPtrAndSignBit);\n"
887         "               int bIdx = abs(gContact[gIdx].m_bodyBPtrAndSignBit);\n"
888         "               float4 posA = gBodies[aIdx].m_pos;\n"
889         "               float4 linVelA = gBodies[aIdx].m_linVel;\n"
890         "               float4 angVelA = gBodies[aIdx].m_angVel;\n"
891         "               float invMassA = gBodies[aIdx].m_invMass;\n"
892         "               Matrix3x3 invInertiaA = gShapes[aIdx].m_invInertia;\n"
893         "               float4 posB = gBodies[bIdx].m_pos;\n"
894         "               float4 linVelB = gBodies[bIdx].m_linVel;\n"
895         "               float4 angVelB = gBodies[bIdx].m_angVel;\n"
896         "               float invMassB = gBodies[bIdx].m_invMass;\n"
897         "               Matrix3x3 invInertiaB = gShapes[bIdx].m_invInertia;\n"
898         "               Constraint4 cs;\n"
899         "               float countA = invMassA != 0.f ? (float)bodyCount[aIdx] : 1;\n"
900         "               float countB = invMassB != 0.f ? (float)bodyCount[bIdx] : 1;\n"
901         "       setConstraint4( posA, linVelA, angVelA, invMassA, invInertiaA, posB, linVelB, angVelB, invMassB, invInertiaB,\n"
902         "                       &gContact[gIdx], dt, positionDrift, positionConstraintCoeff,countA,countB,\n"
903         "                       &cs  );\n"
904         "               \n"
905         "               cs.m_batchIdx = gContact[gIdx].m_batchIdx;\n"
906         "               gConstraintOut[gIdx] = cs;\n"
907         "       }\n"
908         "}\n";