This commit is contained in:
erwin coumans
2013-04-19 18:30:24 -07:00
20 changed files with 3228 additions and 24 deletions

View File

@@ -1,42 +0,0 @@
#ifndef BT_CONTACT4_H
#define BT_CONTACT4_H
#include "Bullet3Common/b3Vector3.h"
ATTRIBUTE_ALIGNED16(struct) b3Contact4
{
BT_DECLARE_ALIGNED_ALLOCATOR();
b3Vector3 m_worldPos[4];
b3Vector3 m_worldNormal;
// float m_restituitionCoeff;
// float m_frictionCoeff;
unsigned short m_restituitionCoeffCmp;
unsigned short m_frictionCoeffCmp;
int m_batchIdx;
int m_bodyAPtrAndSignBit;
int m_bodyBPtrAndSignBit;
int getBodyA()const {return abs(m_bodyAPtrAndSignBit);}
int getBodyB()const {return abs(m_bodyBPtrAndSignBit);}
bool isBodyAFixed()const { return m_bodyAPtrAndSignBit<0;}
bool isBodyBFixed()const { return m_bodyBPtrAndSignBit<0;}
// todo. make it safer
int& getBatchIdx() { return m_batchIdx; }
const int& getBatchIdx() const { return m_batchIdx; }
float getRestituitionCoeff() const { return ((float)m_restituitionCoeffCmp/(float)0xffff); }
void setRestituitionCoeff( float c ) { btAssert( c >= 0.f && c <= 1.f ); m_restituitionCoeffCmp = (unsigned short)(c*0xffff); }
float getFrictionCoeff() const { return ((float)m_frictionCoeffCmp/(float)0xffff); }
void setFrictionCoeff( float c ) { btAssert( c >= 0.f && c <= 1.f ); m_frictionCoeffCmp = (unsigned short)(c*0xffff); }
float& getNPoints() { return m_worldNormal[3]; }
float getNPoints() const { return m_worldNormal[3]; }
float getPenetration(int idx) const { return m_worldPos[idx][3]; }
bool isInvalid() const { return (getBodyA()==0 || getBodyB()==0); }
};
#endif //BT_CONTACT4_H

View File

@@ -3,12 +3,12 @@
#define _CONVEX_HULL_CONTACT_H
#include "parallel_primitives/host/btOpenCLArray.h"
#include "b3RigidBodyCL.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
#include "b3ConvexUtility.h"
#include "b3ConvexPolyhedronCL.h"
#include "b3Collidable.h"
#include "b3Contact4.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3Contact4.h"
#include "parallel_primitives/host/btInt2.h"
#include "parallel_primitives/host/btInt4.h"
#include "b3OptimizedBvh.h"

View File

@@ -1,35 +0,0 @@
#ifndef BT_RIGID_BODY_CL
#define BT_RIGID_BODY_CL
#include "Bullet3Common/b3Scalar.h"
#include "Bullet3Common/b3Matrix3x3.h"
ATTRIBUTE_ALIGNED16(struct) b3RigidBodyCL
{
BT_DECLARE_ALIGNED_ALLOCATOR();
b3Vector3 m_pos;
b3Quaternion m_quat;
b3Vector3 m_linVel;
b3Vector3 m_angVel;
int m_collidableIdx;
float m_invMass;
float m_restituitionCoeff;
float m_frictionCoeff;
float getInvMass() const
{
return m_invMass;
}
};
struct btInertiaCL
{
b3Matrix3x3 m_invInertiaWorld;
b3Matrix3x3 m_initInvInertia;
};
#endif//BT_RIGID_BODY_CL

View File

@@ -4,8 +4,8 @@
#include "../../basic_initialize/b3OpenCLInclude.h"
#include "../../parallel_primitives/host/btOpenCLArray.h"
#include "../../gpu_narrowphase/host/b3RigidBodyCL.h"
#include "../../gpu_narrowphase/host/b3Contact4.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3Contact4.h"
#include "b3GpuConstraint4.h"
class b3GpuBatchingPgsSolver

View File

@@ -9,14 +9,18 @@
#include "../../gpu_broadphase/host/b3SapAabb.h"
#include "../../gpu_broadphase/host/b3GpuSapBroadphase.h"
#include "parallel_primitives/host/btLauncherCL.h"
#include "Bullet3Dynamics/ConstraintSolver/b3PgsJacobiSolver.h"
//#define TEST_OTHER_GPU_SOLVER
#ifdef TEST_OTHER_GPU_SOLVER
#include "btGpuJacobiSolver.h"
#include "btPgsJacobiSolver.h"
#include "b3PgsJacobiSolver.h"
#endif //TEST_OTHER_GPU_SOLVER
#include "../../gpu_narrowphase/host/b3RigidBodyCL.h"
#include "../../gpu_narrowphase/host/b3Contact4.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3Contact4.h"
#include "b3GpuBatchingPgsSolver.h"
#include "b3Solver.h"
@@ -31,8 +35,11 @@ b3GpuRigidBodyPipeline::b3GpuRigidBodyPipeline(cl_context ctx,cl_device_id devic
m_data->m_context = ctx;
m_data->m_device = device;
m_data->m_queue = q;
m_data->m_solver = new b3PgsJacobiSolver();
#ifdef TEST_OTHER_GPU_SOLVER
m_data->m_solver = new btPgsJacobiSolver();
m_data->m_solver3 = new btGpuJacobiSolver(ctx,device,q,config.m_maxBroadphasePairs);
#endif // TEST_OTHER_GPU_SOLVER
b3Config config;
@@ -66,9 +73,10 @@ b3GpuRigidBodyPipeline::b3GpuRigidBodyPipeline(cl_context ctx,cl_device_id devic
b3GpuRigidBodyPipeline::~b3GpuRigidBodyPipeline()
{
clReleaseKernel(m_data->m_integrateTransformsKernel);
#ifdef TEST_OTHER_GPU_SOLVER
delete m_data->m_solver;
#ifdef TEST_OTHER_GPU_SOLVER
delete m_data->m_solver3;
#endif //TEST_OTHER_GPU_SOLVER
@@ -141,7 +149,20 @@ void b3GpuRigidBodyPipeline::stepSimulation(float deltaTime)
btOpenCLArray<b3Contact4> gpuContacts(m_data->m_context,m_data->m_queue,0,true);
gpuContacts.setFromOpenCLBuffer(m_data->m_narrowphase->getContactsGpu(),m_data->m_narrowphase->getNumContactsGpu());
bool useJacobi = false;
bool useBullet2CpuSolver = false;
if (useBullet2CpuSolver)
{
b3AlignedObjectArray<b3RigidBodyCL> hostBodies;
gpuBodies.copyToHost(hostBodies);
b3AlignedObjectArray<btInertiaCL> hostInertias;
gpuInertias.copyToHost(hostInertias);
b3AlignedObjectArray<b3Contact4> hostContacts;
gpuContacts.copyToHost(hostContacts);
{
m_data->m_solver->solveContacts(m_data->m_narrowphase->getNumBodiesGpu(),&hostBodies[0],&hostInertias[0],numContacts,&hostContacts[0]);
}
gpuBodies.copyFromHost(hostBodies);
} else
#ifdef TEST_OTHER_GPU_SOLVER
if (useJacobi)
{

View File

@@ -18,7 +18,7 @@ struct b3GpuRigidBodyPipelineInternalData
cl_kernel m_integrateTransformsKernel;
cl_kernel m_updateAabbsKernel;
class btPgsJacobiSolver* m_solver;
class b3PgsJacobiSolver* m_solver;
class b3GpuBatchingPgsSolver* m_solver2;
class btGpuJacobiSolver* m_solver3;

View File

@@ -19,8 +19,8 @@ subject to the following restrictions:
#include "../../parallel_primitives/host/btOpenCLArray.h"
#include "../host/b3GpuConstraint4.h"
#include "../../gpu_narrowphase/host/b3RigidBodyCL.h"
#include "../../gpu_narrowphase/host/b3Contact4.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3Contact4.h"
#include "../host/b3GpuConstraint4.h"
#include "../../parallel_primitives/host/btPrefixScanCL.h"