introduce b3GpuSolverConstraint and fix Windows build

This commit is contained in:
erwin coumans
2013-07-09 18:03:51 -07:00
parent 282e19171f
commit a3c2456c65
4 changed files with 103 additions and 22 deletions

View File

@@ -40,8 +40,8 @@ B3_ATTRIBUTE_ALIGNED16 (struct) b3SolverConstraint
b3Vector3 m_angularComponentA; b3Vector3 m_angularComponentA;
b3Vector3 m_angularComponentB; b3Vector3 m_angularComponentB;
mutable b3Scalar m_appliedPushImpulse; mutable b3SimdScalar m_appliedPushImpulse;
mutable b3Scalar m_appliedImpulse; mutable b3SimdScalar m_appliedImpulse;
int m_padding1; int m_padding1;
int m_padding2; int m_padding2;
b3Scalar m_friction; b3Scalar m_friction;

View File

@@ -58,12 +58,12 @@ struct b3GpuPgsJacobiSolverInternalData
b3OpenCLArray<b3GpuSolverBody>* m_gpuSolverBodies; b3OpenCLArray<b3GpuSolverBody>* m_gpuSolverBodies;
b3OpenCLArray<b3BatchConstraint>* m_gpuBatchConstraints; b3OpenCLArray<b3BatchConstraint>* m_gpuBatchConstraints;
b3OpenCLArray<b3SolverConstraint>* m_gpuConstraintRows; b3OpenCLArray<b3GpuSolverConstraint>* m_gpuConstraintRows;
b3OpenCLArray<unsigned int>* m_gpuConstraintInfo1; b3OpenCLArray<unsigned int>* m_gpuConstraintInfo1;
// b3AlignedObjectArray<b3GpuSolverBody> m_cpuSolverBodies; // b3AlignedObjectArray<b3GpuSolverBody> m_cpuSolverBodies;
b3AlignedObjectArray<b3BatchConstraint> m_cpuBatchConstraints; b3AlignedObjectArray<b3BatchConstraint> m_cpuBatchConstraints;
b3AlignedObjectArray<b3SolverConstraint> m_cpuConstraintRows; b3AlignedObjectArray<b3GpuSolverConstraint> m_cpuConstraintRows;
b3AlignedObjectArray<unsigned int> m_cpuConstraintInfo1; b3AlignedObjectArray<unsigned int> m_cpuConstraintInfo1;
b3AlignedObjectArray<b3RigidBodyCL> m_cpuBodies; b3AlignedObjectArray<b3RigidBodyCL> m_cpuBodies;
@@ -125,7 +125,7 @@ b3GpuPgsJacobiSolver::b3GpuPgsJacobiSolver (cl_context ctx, cl_device_id device,
m_gpuData->m_gpuSolverBodies = new b3OpenCLArray<b3GpuSolverBody>(m_gpuData->m_context,m_gpuData->m_queue); m_gpuData->m_gpuSolverBodies = new b3OpenCLArray<b3GpuSolverBody>(m_gpuData->m_context,m_gpuData->m_queue);
m_gpuData->m_gpuBatchConstraints = new b3OpenCLArray<b3BatchConstraint>(m_gpuData->m_context,m_gpuData->m_queue); m_gpuData->m_gpuBatchConstraints = new b3OpenCLArray<b3BatchConstraint>(m_gpuData->m_context,m_gpuData->m_queue);
m_gpuData->m_gpuConstraintRows = new b3OpenCLArray<b3SolverConstraint>(m_gpuData->m_context,m_gpuData->m_queue); m_gpuData->m_gpuConstraintRows = new b3OpenCLArray<b3GpuSolverConstraint>(m_gpuData->m_context,m_gpuData->m_queue);
m_gpuData->m_gpuConstraintInfo1 = new b3OpenCLArray<unsigned int>(m_gpuData->m_context,m_gpuData->m_queue); m_gpuData->m_gpuConstraintInfo1 = new b3OpenCLArray<unsigned int>(m_gpuData->m_context,m_gpuData->m_queue);
cl_int errNum=0; cl_int errNum=0;
@@ -345,7 +345,7 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlySetup(b3OpenCLArray<b3Rigi
m_tmpSolverNonContactConstraintPool.resizeNoInitialize(totalNumRows); m_tmpSolverNonContactConstraintPool.resizeNoInitialize(totalNumRows);
m_gpuData->m_gpuConstraintRows->resize(totalNumRows); m_gpuData->m_gpuConstraintRows->resize(totalNumRows);
// b3ConstraintArray verify; // b3GpuConstraintArray verify;
if (useGpuInfo2) if (useGpuInfo2)
{ {
@@ -390,7 +390,7 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlySetup(b3OpenCLArray<b3Rigi
if (info1) if (info1)
{ {
b3SolverConstraint* currentConstraintRow = &m_tmpSolverNonContactConstraintPool[batchConstraints[i].m_constraintRowOffset]; b3GpuSolverConstraint* currentConstraintRow = &m_tmpSolverNonContactConstraintPool[batchConstraints[i].m_constraintRowOffset];
b3GpuGenericConstraint& constraint = m_gpuData->m_cpuConstraints[i]; b3GpuGenericConstraint& constraint = m_gpuData->m_cpuConstraints[i];
b3RigidBodyCL& rbA = m_gpuData->m_cpuBodies[ constraint.getRigidBodyA()]; b3RigidBodyCL& rbA = m_gpuData->m_cpuBodies[ constraint.getRigidBodyA()];
@@ -435,7 +435,7 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlySetup(b3OpenCLArray<b3Rigi
int j; int j;
for ( j=0;j<info1;j++) for ( j=0;j<info1;j++)
{ {
memset(&currentConstraintRow[j],0,sizeof(b3SolverConstraint)); memset(&currentConstraintRow[j],0,sizeof(b3GpuSolverConstraint));
currentConstraintRow[j].m_angularComponentA.setValue(0,0,0); currentConstraintRow[j].m_angularComponentA.setValue(0,0,0);
currentConstraintRow[j].m_angularComponentB.setValue(0,0,0); currentConstraintRow[j].m_angularComponentB.setValue(0,0,0);
currentConstraintRow[j].m_appliedImpulse = 0.f; currentConstraintRow[j].m_appliedImpulse = 0.f;
@@ -483,9 +483,9 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlySetup(b3OpenCLArray<b3Rigi
info2.m_J1angularAxis = currentConstraintRow->m_relpos1CrossNormal; info2.m_J1angularAxis = currentConstraintRow->m_relpos1CrossNormal;
info2.m_J2linearAxis = 0; info2.m_J2linearAxis = 0;
info2.m_J2angularAxis = currentConstraintRow->m_relpos2CrossNormal; info2.m_J2angularAxis = currentConstraintRow->m_relpos2CrossNormal;
info2.rowskip = sizeof(b3SolverConstraint)/sizeof(b3Scalar);//check this info2.rowskip = sizeof(b3GpuSolverConstraint)/sizeof(b3Scalar);//check this
///the size of b3SolverConstraint needs be a multiple of b3Scalar ///the size of b3GpuSolverConstraint needs be a multiple of b3Scalar
b3Assert(info2.rowskip*sizeof(b3Scalar)== sizeof(b3SolverConstraint)); b3Assert(info2.rowskip*sizeof(b3Scalar)== sizeof(b3GpuSolverConstraint));
info2.m_constraintError = &currentConstraintRow->m_rhs; info2.m_constraintError = &currentConstraintRow->m_rhs;
currentConstraintRow->m_cfm = infoGlobal.m_globalCfm; currentConstraintRow->m_cfm = infoGlobal.m_globalCfm;
info2.m_damping = infoGlobal.m_damping; info2.m_damping = infoGlobal.m_damping;
@@ -498,7 +498,7 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlySetup(b3OpenCLArray<b3Rigi
///finalize the constraint setup ///finalize the constraint setup
for ( j=0;j<info1;j++) for ( j=0;j<info1;j++)
{ {
b3SolverConstraint& solverConstraint = currentConstraintRow[j]; b3GpuSolverConstraint& solverConstraint = currentConstraintRow[j];
if (solverConstraint.m_upperLimit>=m_gpuData->m_cpuConstraints[i].getBreakingImpulseThreshold()) if (solverConstraint.m_upperLimit>=m_gpuData->m_cpuConstraints[i].getBreakingImpulseThreshold())
{ {
@@ -622,7 +622,7 @@ __inline void internalApplyImpulse( b3GpuSolverBody* body, const b3Vector3& lin
} }
void resolveSingleConstraintRowGeneric2( b3GpuSolverBody* body1, b3GpuSolverBody* body2, b3SolverConstraint* c) void resolveSingleConstraintRowGeneric2( b3GpuSolverBody* body1, b3GpuSolverBody* body2, b3GpuSolverConstraint* c)
{ {
float deltaImpulse = c->m_rhs-b3Scalar(c->m_appliedImpulse)*c->m_cfm; float deltaImpulse = c->m_rhs-b3Scalar(c->m_appliedImpulse)*c->m_cfm;
float deltaVel1Dotn = b3Dot(c->m_contactNormal,body1->m_deltaLinearVelocity) + b3Dot(c->m_relpos1CrossNormal,body1->m_deltaAngularVelocity); float deltaVel1Dotn = b3Dot(c->m_contactNormal,body1->m_deltaLinearVelocity) + b3Dot(c->m_relpos1CrossNormal,body1->m_deltaAngularVelocity);
@@ -678,7 +678,7 @@ void b3GpuPgsJacobiSolver::averageVelocities()
} }
b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlyIterations(b3OpenCLArray<b3SolverConstraint>* gpuConstraints,int numConstraints,const b3ContactSolverInfo& infoGlobal) b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlyIterations(b3OpenCLArray<b3GpuSolverConstraint>* gpuConstraints,int numConstraints,const b3ContactSolverInfo& infoGlobal)
{ {
//only create the batches once. //only create the batches once.
//@todo: incrementally update batches when constraints are added/activated and/or removed/deactivated //@todo: incrementally update batches when constraints are added/activated and/or removed/deactivated
@@ -766,7 +766,7 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlyIterations(b3OpenCLArray<b
for (int jj=0;jj<c.m_numConstraintRows;jj++) for (int jj=0;jj<c.m_numConstraintRows;jj++)
{ {
// //
b3SolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[c.m_constraintRowOffset+jj]; b3GpuSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[c.m_constraintRowOffset+jj];
//resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[constraint.m_solverBodyIdA],m_tmpSolverBodyPool[constraint.m_solverBodyIdB],constraint); //resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[constraint.m_solverBodyIdA],m_tmpSolverBodyPool[constraint.m_solverBodyIdB],constraint);
resolveSingleConstraintRowGeneric2(&m_tmpSolverBodyPool[constraint.m_solverBodyIdA],&m_tmpSolverBodyPool[constraint.m_solverBodyIdB],&constraint); resolveSingleConstraintRowGeneric2(&m_tmpSolverBodyPool[constraint.m_solverBodyIdA],&m_tmpSolverBodyPool[constraint.m_solverBodyIdB],&constraint);
@@ -804,7 +804,7 @@ b3Scalar b3GpuPgsJacobiSolver::solveGroupCacheFriendlyIterations(b3OpenCLArray<b
int numJoints = m_tmpSolverNonContactConstraintPool.size(); int numJoints = m_tmpSolverNonContactConstraintPool.size();
for (int j=0;j<numJoints;j++) for (int j=0;j<numJoints;j++)
{ {
b3SolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; b3GpuSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j];
resolveSingleConstraintRowGeneric2(&m_tmpSolverBodyPool[constraint.m_solverBodyIdA],&m_tmpSolverBodyPool[constraint.m_solverBodyIdB],&constraint); resolveSingleConstraintRowGeneric2(&m_tmpSolverBodyPool[constraint.m_solverBodyIdA],&m_tmpSolverBodyPool[constraint.m_solverBodyIdB],&constraint);
} }

View File

@@ -25,7 +25,7 @@ class b3Dispatcher;
#include "Bullet3Dynamics/ConstraintSolver/b3TypedConstraint.h" #include "Bullet3Dynamics/ConstraintSolver/b3TypedConstraint.h"
#include "Bullet3Dynamics/ConstraintSolver/b3ContactSolverInfo.h" #include "Bullet3Dynamics/ConstraintSolver/b3ContactSolverInfo.h"
#include "b3GpuSolverBody.h" #include "b3GpuSolverBody.h"
#include "Bullet3Dynamics/ConstraintSolver/b3SolverConstraint.h" #include "b3GpuSolverConstraint.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h" #include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h"
struct b3RigidBodyCL; struct b3RigidBodyCL;
struct b3InertiaCL; struct b3InertiaCL;
@@ -40,10 +40,10 @@ protected:
struct b3GpuPgsJacobiSolverInternalData* m_gpuData; struct b3GpuPgsJacobiSolverInternalData* m_gpuData;
protected: protected:
b3AlignedObjectArray<b3GpuSolverBody> m_tmpSolverBodyPool; b3AlignedObjectArray<b3GpuSolverBody> m_tmpSolverBodyPool;
b3ConstraintArray m_tmpSolverContactConstraintPool; b3GpuConstraintArray m_tmpSolverContactConstraintPool;
b3ConstraintArray m_tmpSolverNonContactConstraintPool; b3GpuConstraintArray m_tmpSolverNonContactConstraintPool;
b3ConstraintArray m_tmpSolverContactFrictionConstraintPool; b3GpuConstraintArray m_tmpSolverContactFrictionConstraintPool;
b3ConstraintArray m_tmpSolverContactRollingFrictionConstraintPool; b3GpuConstraintArray m_tmpSolverContactRollingFrictionConstraintPool;
b3AlignedObjectArray<unsigned int> m_tmpConstraintSizesPool; b3AlignedObjectArray<unsigned int> m_tmpConstraintSizesPool;
@@ -62,7 +62,7 @@ public:
b3GpuPgsJacobiSolver (cl_context ctx, cl_device_id device, cl_command_queue queue,bool usePgs); b3GpuPgsJacobiSolver (cl_context ctx, cl_device_id device, cl_command_queue queue,bool usePgs);
virtual~b3GpuPgsJacobiSolver (); virtual~b3GpuPgsJacobiSolver ();
virtual b3Scalar solveGroupCacheFriendlyIterations(b3OpenCLArray<b3SolverConstraint>* gpuConstraints,int numConstraints,const b3ContactSolverInfo& infoGlobal); virtual b3Scalar solveGroupCacheFriendlyIterations(b3OpenCLArray<b3GpuSolverConstraint>* gpuConstraints,int numConstraints,const b3ContactSolverInfo& infoGlobal);
virtual b3Scalar solveGroupCacheFriendlySetup(b3OpenCLArray<b3RigidBodyCL>* gpuBodies, b3OpenCLArray<b3InertiaCL>* gpuInertias, int numBodies,b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints,int numConstraints,const b3ContactSolverInfo& infoGlobal); virtual b3Scalar solveGroupCacheFriendlySetup(b3OpenCLArray<b3RigidBodyCL>* gpuBodies, b3OpenCLArray<b3InertiaCL>* gpuInertias, int numBodies,b3OpenCLArray<b3GpuGenericConstraint>* gpuConstraints,int numConstraints,const b3ContactSolverInfo& infoGlobal);
b3Scalar solveGroupCacheFriendlyFinish(b3OpenCLArray<b3RigidBodyCL>* gpuBodies,b3OpenCLArray<b3InertiaCL>* gpuInertias,int numBodies,const b3ContactSolverInfo& infoGlobal); b3Scalar solveGroupCacheFriendlyFinish(b3OpenCLArray<b3RigidBodyCL>* gpuBodies,b3OpenCLArray<b3InertiaCL>* gpuInertias,int numBodies,const b3ContactSolverInfo& infoGlobal);

View File

@@ -0,0 +1,81 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2013 Erwin Coumans http://github.com/erwincoumans/bullet3
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
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.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef B3_GPU_SOLVER_CONSTRAINT_H
#define B3_GPU_SOLVER_CONSTRAINT_H
class b3RigidBody;
#include "Bullet3Common/b3Vector3.h"
#include "Bullet3Common/b3Matrix3x3.h"
//#include "b3JacobianEntry.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
//#define NO_FRICTION_TANGENTIALS 1
///1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and friction constraints.
B3_ATTRIBUTE_ALIGNED16 (struct) b3GpuSolverConstraint
{
B3_DECLARE_ALIGNED_ALLOCATOR();
b3Vector3 m_relpos1CrossNormal;
b3Vector3 m_contactNormal;
b3Vector3 m_relpos2CrossNormal;
//b3Vector3 m_contactNormal2;//usually m_contactNormal2 == -m_contactNormal
b3Vector3 m_angularComponentA;
b3Vector3 m_angularComponentB;
mutable b3Scalar m_appliedPushImpulse;
mutable b3Scalar m_appliedImpulse;
int m_padding1;
int m_padding2;
b3Scalar m_friction;
b3Scalar m_jacDiagABInv;
b3Scalar m_rhs;
b3Scalar m_cfm;
b3Scalar m_lowerLimit;
b3Scalar m_upperLimit;
b3Scalar m_rhsPenetration;
union
{
void* m_originalContactPoint;
b3Scalar m_unusedPadding4;
};
int m_overrideNumSolverIterations;
int m_frictionIndex;
int m_solverBodyIdA;
int m_solverBodyIdB;
enum b3SolverConstraintType
{
B3_SOLVER_CONTACT_1D = 0,
B3_SOLVER_FRICTION_1D
};
};
typedef b3AlignedObjectArray<b3GpuSolverConstraint> b3GpuConstraintArray;
#endif //B3_GPU_SOLVER_CONSTRAINT_H