Override btCollisionWorld::addCollisionObject with flags more appropriate for btDynamicsWorld (StaticFilter)

Minor fixes (#ifndef SPU_COLLISION_OBJECT_WRAPPER_H block etc)
Only update 'setNumTasks' when necessary
Revert vectormath.h include (can't resolve conflicts with PS3 SDK, need additional #include path)
This commit is contained in:
erwin.coumans
2009-09-09 22:49:43 +00:00
parent df550730da
commit 659b215a69
17 changed files with 159 additions and 114 deletions

View File

@@ -88,6 +88,8 @@ btCollisionWorld::~btCollisionWorld()
void btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup,short int collisionFilterMask)
{
btAssert(collisionObject);
//check that the object isn't already added
btAssert( m_collisionObjects.findLinearSearch(collisionObject) == m_collisionObjects.size());
@@ -705,7 +707,7 @@ struct btSingleRayCallback : public btBroadphaseRayCallback
void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const
{
BT_PROFILE("rayTest");
//BT_PROFILE("rayTest");
/// use the broadphase to accelerate the search for objects, based on their aabb
/// and for each object with ray-aabb overlap, perform an exact ray test
btSingleRayCallback rayCB(rayFromWorld,rayToWorld,this,resultCallback);

View File

@@ -32,6 +32,11 @@ public:
return 3;
}
btVector3& getVertexPtr(int index)
{
return m_vertices1[index];
}
const btVector3& getVertexPtr(int index) const
{
return m_vertices1[index];
@@ -77,7 +82,10 @@ public:
}
btTriangleShape() : btPolyhedralConvexShape ()
{
m_shapeType = TRIANGLE_SHAPE_PROXYTYPE;
}
btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2) : btPolyhedralConvexShape ()
{

View File

@@ -421,6 +421,11 @@ btVector3 btDiscreteDynamicsWorld::getGravity () const
return m_gravity;
}
void btDiscreteDynamicsWorld::addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup,short int collisionFilterMask)
{
btCollisionWorld::addCollisionObject(collisionObject,collisionFilterGroup,collisionFilterMask);
}
void btDiscreteDynamicsWorld::removeCollisionObject(btCollisionObject* collisionObject)
{
btRigidBody* body = btRigidBody::upcast(collisionObject);
@@ -436,6 +441,7 @@ void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body)
btCollisionWorld::removeCollisionObject(body);
}
void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{
if (!body->isStaticOrKinematicObject())

View File

@@ -124,6 +124,8 @@ public:
virtual btVector3 getGravity () const;
virtual void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::StaticFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
virtual void addRigidBody(btRigidBody* body);
virtual void addRigidBody(btRigidBody* body, short group, short mask);

View File

@@ -13,6 +13,9 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SPU_COLLISION_OBJECT_WRAPPER_H
#define SPU_COLLISION_OBJECT_WRAPPER_H
#include "PlatformDefinitions.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
@@ -33,3 +36,5 @@ public:
ppu_address_t getCollisionObjectPtr () const;
};
#endif //SPU_COLLISION_OBJECT_WRAPPER_H

View File

@@ -25,6 +25,8 @@ subject to the following restrictions:
void SpuCollisionTaskProcess::setNumTasks(int maxNumTasks)
{
if (m_maxNumOutstandingTasks != maxNumTasks)
{
m_maxNumOutstandingTasks = maxNumTasks;
m_taskBusy.resize(m_maxNumOutstandingTasks);
@@ -43,6 +45,7 @@ void SpuCollisionTaskProcess::setNumTasks(int maxNumTasks)
m_workUnitTaskBuffers = (unsigned char *)btAlignedAlloc(MIDPHASE_WORKUNIT_TASK_SIZE*m_maxNumOutstandingTasks, 128);
m_workUnitTaskBuffers = (unsigned char *)btAlignedAlloc(MIDPHASE_WORKUNIT_TASK_SIZE*6, 128);
}
}
@@ -50,7 +53,7 @@ void SpuCollisionTaskProcess::setNumTasks(int maxNumTasks)
SpuCollisionTaskProcess::SpuCollisionTaskProcess(class btThreadSupportInterface* threadInterface, unsigned int maxNumOutstandingTasks)
:m_threadInterface(threadInterface),
m_maxNumOutstandingTasks(maxNumOutstandingTasks)
m_maxNumOutstandingTasks(0)
{
m_workUnitTaskBuffers = (unsigned char *)0;
setNumTasks(maxNumOutstandingTasks);
@@ -130,7 +133,7 @@ void SpuCollisionTaskProcess::issueTask2()
// no error checking here...
// but, currently, event queue can be no larger than NUM_WORKUNIT_TASKS.
taskDesc.inPtr = reinterpret_cast<uint64_t>(MIDPHASE_TASK_PTR(m_currentTask));
taskDesc.m_inPairPtr = reinterpret_cast<uint64_t>(MIDPHASE_TASK_PTR(m_currentTask));
taskDesc.taskId = m_currentTask;
taskDesc.numPages = m_currentPage+1;

View File

@@ -74,7 +74,7 @@ class btDispatcher;
///MidphaseWorkUnitInput stores individual primitive versus mesh collision detection input, to be processed by the SPU.
struct SpuGatherAndProcessWorkUnitInput
ATTRIBUTE_ALIGNED16(struct) SpuGatherAndProcessWorkUnitInput
{
uint64_t m_pairArrayPtr;
int m_startIndex;
@@ -151,6 +151,7 @@ public:
#define MIDPHASE_WORKUNIT_PAGE_SIZE (16)
//#define MIDPHASE_WORKUNIT_PAGE_SIZE (128)
#define MIDPHASE_NUM_WORKUNIT_PAGES 1
#define MIDPHASE_WORKUNIT_TASK_SIZE (MIDPHASE_WORKUNIT_PAGE_SIZE*MIDPHASE_NUM_WORKUNIT_PAGES)

View File

@@ -61,8 +61,11 @@ DoubleBuffer<T,size>::backBufferDmaGet(uint64_t ea, unsigned int numBytes, unsig
{
m_dmaPending = true;
m_dmaTag = tag;
if (numBytes)
{
m_backBuffer = (T*)cellDmaLargeGetReadOnly(m_backBuffer, ea, numBytes, tag, 0, 0);
}
}
template<class T, int size>
void

View File

@@ -22,6 +22,7 @@ subject to the following restrictions:
#include "SpuContactManifoldCollisionAlgorithm.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
#include "LinearMath/btQuickprof.h"
@@ -152,6 +153,9 @@ void SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPai
{
m_maxNumOutstandingTasks = m_threadInterface->getNumTasks();
{
BT_PROFILE("processAllOverlappingPairs");
if (!m_spuCollisionTaskProcess)
m_spuCollisionTaskProcess = new SpuCollisionTaskProcess(m_threadInterface,m_maxNumOutstandingTasks);
@@ -167,11 +171,14 @@ void SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPai
pairCache->processAllOverlappingPairs(&collisionCallback,dispatcher);
}
}
//send one big batch
int numTotalPairs = pairCache->getNumOverlappingPairs();
btBroadphasePair* pairPtr = pairCache->getOverlappingPairArrayPtr();
int i;
{
BT_PROFILE("addWorkToTask");
for (i=0;i<numTotalPairs;)
{
//Performance Hint: tweak this number during benchmarking
@@ -180,7 +187,10 @@ void SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPai
m_spuCollisionTaskProcess->addWorkToTask(pairPtr,i,endIndex);
i = endIndex;
}
}
{
BT_PROFILE("PPU fallback");
//handle PPU fallback pairs
for (i=0;i<numTotalPairs;i++)
{
@@ -212,9 +222,12 @@ void SpuGatheringCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPai
}
}
}
}
{
BT_PROFILE("flush2");
//make sure all SPU work is done
m_spuCollisionTaskProcess->flush2();
}
} else
{

View File

@@ -23,8 +23,10 @@ subject to the following restrictions:
#endif
#include <math.h>
#include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"
//<vectormath_aos.h>
//#include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"
#include <vectormath_aos.h>
using namespace Vectormath::Aos;

View File

@@ -34,22 +34,23 @@ subject to the following restrictions:
#define MAX_NUM_SPU_CONVEX_POINTS 128
struct SpuConvexPolyhedronVertexData
ATTRIBUTE_ALIGNED16(struct) SpuConvexPolyhedronVertexData
{
void* gSpuConvexShapePtr;
btVector3* gConvexPoints;
int gNumConvexPoints;
int unused;
ATTRIBUTE_ALIGNED16(btVector3 g_convexPointBuffer[MAX_NUM_SPU_CONVEX_POINTS]);
};
#define MAX_SHAPE_SIZE 256
struct CollisionShape_LocalStoreMemory
ATTRIBUTE_ALIGNED16(struct) CollisionShape_LocalStoreMemory
{
ATTRIBUTE_ALIGNED16(char collisionShape[MAX_SHAPE_SIZE]);
};
struct CompoundShape_LocalStoreMemory
ATTRIBUTE_ALIGNED16(struct) CompoundShape_LocalStoreMemory
{
// Compound data
#define MAX_SPU_COMPOUND_SUBSHAPES 16
@@ -57,7 +58,7 @@ struct CompoundShape_LocalStoreMemory
ATTRIBUTE_ALIGNED16(char gSubshapeShape[MAX_SPU_COMPOUND_SUBSHAPES][MAX_SHAPE_SIZE]);
};
struct bvhMeshShape_LocalStoreMemory
ATTRIBUTE_ALIGNED16(struct) bvhMeshShape_LocalStoreMemory
{
//ATTRIBUTE_ALIGNED16(btOptimizedBvh gOptimizedBvh);
ATTRIBUTE_ALIGNED16(char gOptimizedBvh[sizeof(btOptimizedBvh)+16]);

View File

@@ -22,13 +22,13 @@ subject to the following restrictions:
class btStackAlloc;
class btIDebugDraw;
class SpuVoronoiSimplexSolver;
#include "BulletCollision/NarrowphaseCollision/btConvexPenetrationDepthSolver.h"
#include <LinearMath/btTransform.h>
///ConvexPenetrationDepthSolver provides an interface for penetration depth calculation.
class SpuConvexPenetrationDepthSolver
class SpuConvexPenetrationDepthSolver : public btConvexPenetrationDepthSolver
{
public:

View File

@@ -273,11 +273,13 @@ SIMD_FORCE_INLINE void small_cache_read_triple( void* ls0, ppu_address_t ea0,
class spuNodeCallback : public btNodeOverlapCallback
{
SpuCollisionPairInput* m_wuInput;
SpuContactResult& m_spuContacts;
CollisionTask_LocalStoreMemory* m_lsMemPtr;
ATTRIBUTE_ALIGNED16(btTriangleShape) m_tmpTriangleShape;
ATTRIBUTE_ALIGNED16(btVector3 spuTriangleVertices[3]);
ATTRIBUTE_ALIGNED16(btScalar spuUnscaledVertex[4]);
@@ -345,8 +347,7 @@ public:
&spuUnscaledVertex[2],(ppu_address_t)&graphicsbasePtr[2],
sizeof(btScalar));
spuTriangleVertices[j] = btVector3(
spuUnscaledVertex[0]*meshScaling.getX(),
m_tmpTriangleShape.getVertexPtr(j).setValue(spuUnscaledVertex[0]*meshScaling.getX(),
spuUnscaledVertex[1]*meshScaling.getY(),
spuUnscaledVertex[2]*meshScaling.getZ());
@@ -354,13 +355,9 @@ public:
}
ATTRIBUTE_ALIGNED16(btTriangleShape) tmpTriangleShape(spuTriangleVertices[0],spuTriangleVertices[1],spuTriangleVertices[2]);
SpuCollisionPairInput triangleConcaveInput(*m_wuInput);
// triangleConcaveInput.m_spuCollisionShapes[1] = &spuTriangleVertices[0];
triangleConcaveInput.m_spuCollisionShapes[1] = &tmpTriangleShape;
triangleConcaveInput.m_spuCollisionShapes[1] = &m_tmpTriangleShape;
triangleConcaveInput.m_shapeType1 = TRIANGLE_SHAPE_PROXYTYPE;
m_spuContacts.setShapeIdentifiersB(subPart,triangleIndex);
@@ -479,6 +476,9 @@ void ProcessConvexConcaveSpuCollision(SpuCollisionPairInput* wuInput, CollisionT
}
int stats[11]={0,0,0,0,0,0,0,0,0,0,0};
int degenerateStats[11]={0,0,0,0,0,0,0,0,0,0,0};
////////////////////////
/// Convex versus Convex collision detection (handles collision between sphere, box, cylinder, triangle, cone, convex polyhedron etc)
@@ -507,22 +507,19 @@ void ProcessSpuConvexConvexCollision(SpuCollisionPairInput* wuInput, CollisionTa
btVoronoiSimplexSolver simplexSolver;
btGjkEpaPenetrationDepthSolver epaPenetrationSolver2;
btConvexPenetrationDepthSolver* penetrationSolver = (btConvexPenetrationDepthSolver*)&epaPenetrationSolver2;
btConvexPenetrationDepthSolver* penetrationSolver = &epaPenetrationSolver2;
#if 0
SpuVoronoiSimplexSolver vsSolver;
SpuMinkowskiPenetrationDepthSolver minkowskiPenetrationSolver;
//SpuMinkowskiPenetrationDepthSolver minkowskiPenetrationSolver;
#ifdef ENABLE_EPA
SpuEpaPenetrationDepthSolver epaPenetrationSolver;
if (gUseEpa)
{
penetrationSolver = &epaPenetrationSolver;
penetrationSolver = &epaPenetrationSolver2;
} else
#endif
{
penetrationSolver = &minkowskiPenetrationSolver;
//penetrationSolver = &minkowskiPenetrationSolver;
}
#endif
///DMA in the vertices for convex shapes
ATTRIBUTE_ALIGNED16(char convexHullShape0[sizeof(btConvexHullShape)]);
@@ -616,6 +613,10 @@ void ProcessSpuConvexConvexCollision(SpuCollisionPairInput* wuInput, CollisionTa
{
btGjkPairDetector gjk(shape0Ptr,shape1Ptr,shapeType0,shapeType1,marginA,marginB,&simplexSolver,penetrationSolver);//&vsSolver,penetrationSolver);
gjk.getClosestPoints(cpInput,spuContacts,0);//,debugDraw);
stats[gjk.m_lastUsedMethod]++;
degenerateStats[gjk.m_degenerateSimplex]++;
#ifdef USE_SEPDISTANCE_UTIL
btScalar sepDist = gjk.getCachedSeparatingDistance()+spuManifold->getContactBreakingThreshold();
lsMemPtr->getlocalCollisionAlgorithm()->m_sepDistance.initSeparatingDistance(gjk.getCachedSeparatingAxis(),sepDist,wuInput->m_worldTransform0,wuInput->m_worldTransform1);
@@ -880,7 +881,7 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
////////////////////
ppu_address_t dmaInPtr = taskDesc.inPtr;
ppu_address_t dmaInPtr = taskDesc.m_inPairPtr;
unsigned int numPages = taskDesc.numPages;
unsigned int numOnLastPage = taskDesc.numOnLastPage;
@@ -1036,7 +1037,6 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
btVector3 normalInB;
if (//!gUseEpa &&
#ifdef USE_SEPDISTANCE_UTIL
lsMem.getlocalCollisionAlgorithm()->m_sepDistance.getConservativeSeparatingDistance()<=0.f
@@ -1045,7 +1045,7 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
#endif
)
{
#define USE_PE_BOX_BOX 1
//#define USE_PE_BOX_BOX 1
#ifdef USE_PE_BOX_BOX
{
@@ -1163,9 +1163,7 @@ void processCollisionTask(void* userPtr, void* lsMemPtr)
#endif //USE_SEPDISTANCE_UTIL
)
{
handleCollisionPair(collisionPairInput, lsMem, spuContacts,
(ppu_address_t)lsMem.getColObj0()->getCollisionShape(), &lsMem.gCollisionShapes[0].collisionShape,
(ppu_address_t)lsMem.getColObj1()->getCollisionShape(), &lsMem.gCollisionShapes[1].collisionShape);
handleCollisionPair(collisionPairInput, lsMem, spuContacts, (ppu_address_t)lsMem.getColObj0()->getCollisionShape(), &lsMem.gCollisionShapes[0].collisionShape, (ppu_address_t)lsMem.getColObj1()->getCollisionShape(), &lsMem.gCollisionShapes[1].collisionShape);
} else
{
//spu_printf("boxbox dist = %f\n",distance);

View File

@@ -23,7 +23,7 @@ subject to the following restrictions:
///Task Description for SPU collision detection
struct SpuGatherAndProcessPairsTaskDesc
{
ppu_address_t inPtr;//m_pairArrayPtr;
ppu_address_t m_inPairPtr;//m_pairArrayPtr;
//mutex variable
uint32_t m_someMutexVariableInMainMemory;

View File

@@ -67,16 +67,14 @@ btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
};
bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( btVoronoiSimplexSolver& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB,
btTransform& transA,const btTransform& transB,
btVector3& v, btVector3& pa, btVector3& pb,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc,
struct SpuConvexPolyhedronVertexData* convexVertexDataA,
struct SpuConvexPolyhedronVertexData* convexVertexDataB
) const
{
bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& simplexSolver,
const btConvexShape* convexA,const btConvexShape* convexB,
const btTransform& transA,const btTransform& transB,
btVector3& v, btVector3& pa, btVector3& pb,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc)
{
#if 0
(void)stackAlloc;
(void)v;
@@ -342,6 +340,8 @@ bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( btVoronoiSimplexSolver& s
//btAssert (false);
}
return res.m_hasResult;
#endif
return false;
}

View File

@@ -18,7 +18,7 @@ subject to the following restrictions:
#define MINKOWSKI_PENETRATION_DEPTH_SOLVER_H
#include "SpuConvexPenetrationDepthSolver.h"
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
class btStackAlloc;
class btIDebugDraw;
@@ -27,18 +27,18 @@ class btConvexShape;
///MinkowskiPenetrationDepthSolver implements bruteforce penetration depth estimation.
///Implementation is based on sampling the depth using support mapping, and using GJK step to get the witness points.
class SpuMinkowskiPenetrationDepthSolver : public SpuConvexPenetrationDepthSolver
class SpuMinkowskiPenetrationDepthSolver : public btConvexPenetrationDepthSolver
{
public:
SpuMinkowskiPenetrationDepthSolver() {}
virtual ~SpuMinkowskiPenetrationDepthSolver() {};
virtual bool calcPenDepth( btVoronoiSimplexSolver& simplexSolver,
btConvexShape* convexA,btConvexShape* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB,
btTransform& transA,const btTransform& transB,
virtual bool calcPenDepth( btSimplexSolverInterface& simplexSolver,
const btConvexShape* convexA,const btConvexShape* convexB,
const btTransform& transA,const btTransform& transB,
btVector3& v, btVector3& pa, btVector3& pb,
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc,
struct SpuConvexPolyhedronVertexData* convexVertexDataA,
struct SpuConvexPolyhedronVertexData* convexVertexDataB
) const;
class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
);
};

View File

@@ -30,8 +30,9 @@
#ifndef AOS_VECTORMATH_BULLET_CONVERT_H
#define AOS_VECTORMATH_BULLET_CONVERT_H
//#include <vectormath_aos.h>
#include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"
#include <vectormath_aos.h>
//#include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btQuaternion.h"
#include "LinearMath/btMatrix3x3.h"