[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3OpenCL / RigidBody / b3GpuPgsConstraintSolver.h
1 /*
2 Copyright (c) 2013 Advanced Micro Devices, Inc.  
3
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose, 
7 including commercial applications, and to alter it and redistribute it freely, 
8 subject to the following restrictions:
9
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.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14 //Originally written by Erwin Coumans
15
16 #ifndef B3_GPU_PGS_CONSTRAINT_SOLVER_H
17 #define B3_GPU_PGS_CONSTRAINT_SOLVER_H
18
19 struct b3Contact4;
20 struct b3ContactPoint;
21
22 class b3Dispatcher;
23
24 #include "Bullet3Dynamics/ConstraintSolver/b3TypedConstraint.h"
25 #include "Bullet3Dynamics/ConstraintSolver/b3ContactSolverInfo.h"
26 #include "b3GpuSolverBody.h"
27 #include "b3GpuSolverConstraint.h"
28 #include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h"
29 struct b3RigidBodyData;
30 struct b3InertiaData;
31
32 #include "Bullet3OpenCL/Initialize/b3OpenCLInclude.h"
33 #include "b3GpuGenericConstraint.h"
34
35 class b3GpuPgsConstraintSolver
36 {
37 protected:
38         int m_staticIdx;
39         struct b3GpuPgsJacobiSolverInternalData* m_gpuData;
40
41 protected:
42         b3AlignedObjectArray<b3GpuSolverBody> m_tmpSolverBodyPool;
43         b3GpuConstraintArray m_tmpSolverContactConstraintPool;
44         b3GpuConstraintArray m_tmpSolverNonContactConstraintPool;
45         b3GpuConstraintArray m_tmpSolverContactFrictionConstraintPool;
46         b3GpuConstraintArray m_tmpSolverContactRollingFrictionConstraintPool;
47
48         b3AlignedObjectArray<unsigned int> m_tmpConstraintSizesPool;
49
50         bool m_usePgs;
51         void averageVelocities();
52
53         int m_maxOverrideNumSolverIterations;
54
55         int m_numSplitImpulseRecoveries;
56
57         //      int     getOrInitSolverBody(int bodyIndex, b3RigidBodyData* bodies,b3InertiaData* inertias);
58         void initSolverBody(int bodyIndex, b3GpuSolverBody* solverBody, b3RigidBodyData* rb);
59
60 public:
61         b3GpuPgsConstraintSolver(cl_context ctx, cl_device_id device, cl_command_queue queue, bool usePgs);
62         virtual ~b3GpuPgsConstraintSolver();
63
64         virtual b3Scalar solveGroupCacheFriendlyIterations(b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints1, int numConstraints, const b3ContactSolverInfo& infoGlobal);
65         virtual b3Scalar solveGroupCacheFriendlySetup(b3OpenCLArray<b3RigidBodyData>* gpuBodies, b3OpenCLArray<b3InertiaData>* gpuInertias, int numBodies, b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
66         b3Scalar solveGroupCacheFriendlyFinish(b3OpenCLArray<b3RigidBodyData>* gpuBodies, b3OpenCLArray<b3InertiaData>* gpuInertias, int numBodies, b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
67
68         b3Scalar solveGroup(b3OpenCLArray<b3RigidBodyData>* gpuBodies, b3OpenCLArray<b3InertiaData>* gpuInertias, int numBodies, b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints, int numConstraints, const b3ContactSolverInfo& infoGlobal);
69         void solveJoints(int numBodies, b3OpenCLArray<b3RigidBodyData>* gpuBodies, b3OpenCLArray<b3InertiaData>* gpuInertias,
70                                          int numConstraints, b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints);
71
72         int sortConstraintByBatch3(struct b3BatchConstraint* cs, int numConstraints, int simdWidth, int staticIdx, int numBodies);
73         void recomputeBatches();
74 };
75
76 #endif  //B3_GPU_PGS_CONSTRAINT_SOLVER_H