diff --git a/src/BulletMultiThreaded/SpuGatheringCollisionDispatcher.cpp b/src/BulletMultiThreaded/SpuGatheringCollisionDispatcher.cpp index ee0832f12..dad166b6b 100644 --- a/src/BulletMultiThreaded/SpuGatheringCollisionDispatcher.cpp +++ b/src/BulletMultiThreaded/SpuGatheringCollisionDispatcher.cpp @@ -23,6 +23,8 @@ subject to the following restrictions: #include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "LinearMath/btQuickprof.h" +#include "BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h" + @@ -127,11 +129,33 @@ public: { int proxyType0 = colObj0->getCollisionShape()->getShapeType(); int proxyType1 = colObj1->getCollisionShape()->getShapeType(); - if (m_dispatcher->supportsDispatchPairOnSpu(proxyType0,proxyType1) + bool supportsSpuDispatch = m_dispatcher->supportsDispatchPairOnSpu(proxyType0,proxyType1) && (colObj0->getCollisionFlags() != btCollisionObject::CF_DISABLE_SPU_COLLISION_PROCESSING) - && (colObj1->getCollisionFlags() != btCollisionObject::CF_DISABLE_SPU_COLLISION_PROCESSING) - ) + && (colObj1->getCollisionFlags() != btCollisionObject::CF_DISABLE_SPU_COLLISION_PROCESSING); + + if (proxyType0 == COMPOUND_SHAPE_PROXYTYPE) { + btCompoundShape* compound = (btCompoundShape*)colObj0->getCollisionShape(); + if (compound->getNumChildShapes()>MAX_SPU_COMPOUND_SUBSHAPES) + { + //printf("PPU fallback, compound->getNumChildShapes(%d)>%d\n",compound->getNumChildShapes(),MAX_SPU_COMPOUND_SUBSHAPES); + supportsSpuDispatch = false; + } + } + + if (proxyType1 == COMPOUND_SHAPE_PROXYTYPE) + { + btCompoundShape* compound = (btCompoundShape*)colObj1->getCollisionShape(); + if (compound->getNumChildShapes()>MAX_SPU_COMPOUND_SUBSHAPES) + { + //printf("PPU fallback, compound->getNumChildShapes(%d)>%d\n",compound->getNumChildShapes(),MAX_SPU_COMPOUND_SUBSHAPES); + supportsSpuDispatch = false; + } + } + + if (supportsSpuDispatch) + { + int so = sizeof(SpuContactManifoldCollisionAlgorithm); #ifdef ALLOCATE_SEPARATELY void* mem = btAlignedAlloc(so,16);//m_dispatcher->allocateCollisionAlgorithm(so); diff --git a/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h b/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h index d369395e1..aa8a29104 100644 --- a/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h +++ b/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h @@ -33,7 +33,9 @@ subject to the following restrictions: #include "BulletCollision/CollisionShapes/btConvexHullShape.h" #include "BulletCollision/CollisionShapes/btCompoundShape.h" -#define MAX_NUM_SPU_CONVEX_POINTS 128 +#define MAX_NUM_SPU_CONVEX_POINTS 128 //@fallback to PPU if a btConvexHullShape has more than MAX_NUM_SPU_CONVEX_POINTS points +#define MAX_SPU_COMPOUND_SUBSHAPES 16 //@fallback on PPU if compound has more than MAX_SPU_COMPOUND_SUBSHAPES child shapes +#define MAX_SHAPE_SIZE 256 //@todo: assert on this ATTRIBUTE_ALIGNED16(struct) SpuConvexPolyhedronVertexData { @@ -44,7 +46,7 @@ ATTRIBUTE_ALIGNED16(struct) SpuConvexPolyhedronVertexData ATTRIBUTE_ALIGNED16(btVector3 g_convexPointBuffer[MAX_NUM_SPU_CONVEX_POINTS]); }; -#define MAX_SHAPE_SIZE 256 + ATTRIBUTE_ALIGNED16(struct) CollisionShape_LocalStoreMemory { @@ -54,7 +56,7 @@ ATTRIBUTE_ALIGNED16(struct) CollisionShape_LocalStoreMemory ATTRIBUTE_ALIGNED16(struct) CompoundShape_LocalStoreMemory { // Compound data -#define MAX_SPU_COMPOUND_SUBSHAPES 16 + ATTRIBUTE_ALIGNED16(btCompoundShapeChild gSubshapes[MAX_SPU_COMPOUND_SUBSHAPES]); ATTRIBUTE_ALIGNED16(char gSubshapeShape[MAX_SPU_COMPOUND_SUBSHAPES][MAX_SHAPE_SIZE]); }; diff --git a/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp b/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp index c3dfaa793..80a98ffc7 100644 --- a/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp +++ b/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp @@ -864,7 +864,9 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas cellDmaWaitTagStatusAll(DMA_MASK(1)); int childShapeCount0 = spuCompoundShape0->getNumChildShapes(); + btAssert(childShapeCount0< MAX_SPU_COMPOUND_SUBSHAPES); int childShapeCount1 = spuCompoundShape1->getNumChildShapes(); + btAssert(childShapeCount1< MAX_SPU_COMPOUND_SUBSHAPES); // Start the N^2 for (int i = 0; i < childShapeCount0; ++i) @@ -910,6 +912,7 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas cellDmaWaitTagStatusAll(DMA_MASK(1)); int childShapeCount = spuCompoundShape->getNumChildShapes(); + btAssert(childShapeCount< MAX_SPU_COMPOUND_SUBSHAPES); for (int i = 0; i < childShapeCount; ++i) { @@ -942,6 +945,8 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas cellDmaWaitTagStatusAll(DMA_MASK(1)); int childShapeCount = spuCompoundShape->getNumChildShapes(); + btAssert(childShapeCount< MAX_SPU_COMPOUND_SUBSHAPES); + for (int i = 0; i < childShapeCount; ++i) {