From 10d103b50e1e5ce9bd1b893d231b0ed580e63564 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Wed, 8 Oct 2008 20:59:26 +0000 Subject: [PATCH] Disable TEST_NON_VIRTUAL debugging for btGjkPairDetector Reverted BulletMultiThreaded, there are some performance issues to be resolved. --- .../SpuCollisionShapes.cpp | 192 +-- .../SpuCollisionShapes.h | 76 +- .../SpuContactResult.cpp | 2 +- .../SpuContactResult.h | 226 ++-- .../SpuConvexPenetrationDepthSolver.h | 4 +- .../SpuEpaPenetrationDepthSolver.cpp | 7 +- .../SpuEpaPenetrationDepthSolver.h | 4 +- .../SpuGatheringCollisionTask.cpp | 1076 +++++++---------- .../SpuGjkPairDetector.cpp | 2 +- .../SpuGjkPairDetector.h | 9 +- .../SpuMinkowskiPenetrationDepthSolver.cpp | 16 +- .../SpuMinkowskiPenetrationDepthSolver.h | 4 +- .../SpuRaycastTask/SpuRaycastTask.cpp | 2 +- .../SpuSubSimplexConvexCast.cpp | 2 +- .../SpuRaycastTask/SpuSubSimplexConvexCast.h | 6 +- 15 files changed, 641 insertions(+), 987 deletions(-) diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp index 18a51b9f0..4fc0115b4 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.cpp @@ -16,155 +16,6 @@ subject to the following restrictions: #include "SpuCollisionShapes.h" -#if 0 -int SpuInternalShape::dmaShapeTypeIntoShapeStorage (ppu_address_t ppuAddress, uint32_t dmaTag) -{ - m_ppuConvexShapePtr = ppuAddress; - /* This assumes that m_shapeType is the first entry in the struct */ - cellDmaSmallGet (m_collisionShape, m_ppuConvexShapePtr, 4, DMA_TAG(dmaTag), 0, 0); - cellDmaWaitTagStatusAll(DMA_MASK(dmaTag)); - return m_collisionShape->getShapeType (); -} -#endif - -void SpuInternalShape::dmaShapeData (ppu_address_t ppuAddress, int shapeType, uint32_t dmaTag) -{ - m_ppuConvexShapePtr = ppuAddress; - uint32_t shapeSize = getShapeTypeSize (shapeType); - cellDmaGet (m_collisionShape, m_ppuConvexShapePtr, shapeSize, DMA_TAG(dmaTag), 0, 0); -} - - -void SpuInternalConvexHull::dmaPointsData (const SpuInternalShape& shape, uint32_t dmaTag) -{ - btAssert (shape.m_collisionShape->getShapeType () == CONVEX_HULL_SHAPE_PROXYTYPE); - btConvexHullShape* convexHullShape = (btConvexHullShape*)shape.m_collisionShape; - ppu_address_t ppuPointsAddress = (ppu_address_t)convexHullShape->getPoints(); - int numPoints = convexHullShape->getNumPoints (); - dmaPointsData (ppuPointsAddress, numPoints, dmaTag); -} - -void SpuInternalConvexHull::dmaPointsData (ppu_address_t ppuPointsAddress, int numPoints, uint32_t dmaTag) -{ - m_ppuPointsPtr = ppuPointsAddress; - m_numPoints = numPoints; - cellDmaGet (m_points, m_ppuPointsPtr, sizeof(btVector3)*numPoints, DMA_TAG(dmaTag), 0, 0); -} - -void SpuCompoundShape::dmaChildShapeInfo (btCompoundShape* compoundShape, uint32_t dmaTag) -{ - register int dmaSize; - register ppu_address_t dmaPpuAddress; - int childShapeCount = compoundShape->getNumChildShapes(); - dmaSize = childShapeCount * sizeof(btCompoundShapeChild); - dmaPpuAddress = (ppu_address_t)compoundShape->getChildList(); - cellDmaGet(&m_subshapes[0], dmaPpuAddress, dmaSize, DMA_TAG(dmaTag), 0, 0); -} - -void SpuCompoundShape::dmaChildShape (int childShape, - SpuInternalShape* localShape, - SpuInternalConvexHull* localShapeHull, - uint32_t dmaTag) -{ - btCompoundShapeChild& compoundChildShape = m_subshapes[childShape]; - localShape->dmaShapeData ((ppu_address_t)compoundChildShape.m_childShape, compoundChildShape.m_childShapeType, dmaTag); - cellDmaWaitTagStatusAll (DMA_MASK(dmaTag)); - if (compoundChildShape.m_childShapeType == CONVEX_HULL_SHAPE_PROXYTYPE) - { - localShapeHull->dmaPointsData (*localShape, dmaTag); - } -} - - -void dmaBvhShapeData (bvhMeshShape_LocalStoreMemory* bvhMeshShape, btBvhTriangleMeshShape* triMeshShape) -{ - register int dmaSize; - register ppu_address_t dmaPpuAddress2; - - dmaSize = sizeof(btTriangleIndexVertexArray); - dmaPpuAddress2 = reinterpret_cast(triMeshShape->getMeshInterface()); - // spu_printf("trimeshShape->getMeshInterface() == %llx\n",dmaPpuAddress2); -#ifdef __SPU__ - cellDmaGet(&bvhMeshShape->gTriangleMeshInterfaceStorage, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); - bvhMeshShape->gTriangleMeshInterfacePtr = &bvhMeshShape->gTriangleMeshInterfaceStorage; -#else - bvhMeshShape->gTriangleMeshInterfacePtr = (btTriangleIndexVertexArray*)cellDmaGetReadOnly(&bvhMeshShape->gTriangleMeshInterfaceStorage, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); -#endif - - //cellDmaWaitTagStatusAll(DMA_MASK(1)); - - ///now DMA over the BVH - - dmaSize = sizeof(btOptimizedBvh); - dmaPpuAddress2 = reinterpret_cast(triMeshShape->getOptimizedBvh()); - //spu_printf("trimeshShape->getOptimizedBvh() == %llx\n",dmaPpuAddress2); - cellDmaGet(&bvhMeshShape->gOptimizedBvh, dmaPpuAddress2 , dmaSize, DMA_TAG(2), 0, 0); - //cellDmaWaitTagStatusAll(DMA_MASK(2)); - cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); -} - -void dmaBvhIndexedMesh (btIndexedMesh* IndexMesh, IndexedMeshArray& indexArray, int index, uint32_t dmaTag) -{ - cellDmaGet(IndexMesh, (ppu_address_t)&indexArray[index] , sizeof(btIndexedMesh), DMA_TAG(dmaTag), 0, 0); - -} - -void dmaBvhSubTreeHeaders (btBvhSubtreeInfo* subTreeHeaders, ppu_address_t subTreePtr, int batchSize, uint32_t dmaTag) -{ - cellDmaGet(subTreeHeaders, subTreePtr, batchSize * sizeof(btBvhSubtreeInfo), DMA_TAG(dmaTag), 0, 0); -} - -void dmaBvhSubTreeNodes (btQuantizedBvhNode* nodes, const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag) -{ - cellDmaGet(nodes, reinterpret_cast(&nodeArray[subtree.m_rootNodeIndex]) , subtree.m_subtreeSize* sizeof(btQuantizedBvhNode), DMA_TAG(2), 0, 0); -} - - -void SpuBvhMeshShape::dmaMeshInterfaceAndOptimizedBvh (const SpuInternalShape& triangleMeshShape, uint32_t dmaTag1, uint32_t dmaTag2) -{ - register int dmaSize; - register ppu_address_t dmaPpuAddress; - - btBvhTriangleMeshShape* triMeshShape = (btBvhTriangleMeshShape*)triangleMeshShape.m_collisionShape; - - // DMA: triangle mesh interface - dmaSize = sizeof(btTriangleIndexVertexArray); - dmaPpuAddress = reinterpret_cast(triMeshShape->getMeshInterface()); -#ifdef __SPU__ - cellDmaGet(&m_triangleMeshInterfaceBuffer, dmaPpuAddress, dmaSize, DMA_TAG(dmaTag1), 0, 0); -#else - m_triangleMeshInterface = (btTriangleIndexVertexArray*)cellDmaGetReadOnly(&m_triangleMeshInterfaceBuffer, dmaPpuAddress, dmaSize, DMA_TAG(dmaTag1), 0, 0); -#endif - - //cellDmaWaitTagStatusAll(DMA_MASK(dmaTag1)); - - // DMA: btOptimizedBvh - dmaSize = sizeof(btOptimizedBvh); - dmaPpuAddress = reinterpret_cast(triMeshShape->getOptimizedBvh()); - cellDmaGet(m_optimizedBvh, dmaPpuAddress , dmaSize, DMA_TAG(dmaTag2), 0, 0); - - //cellDmaWaitTagStatusAll(DMA_MASK(dmaTag2)); - - // wait for both triangle mesh interface and optimized bvh - cellDmaWaitTagStatusAll(DMA_MASK(dmaTag1) | DMA_MASK(dmaTag2)); -} - -void SpuBvhMeshShape::dmaIndexedMesh (int index, uint32_t dmaTag) -{ - cellDmaGet(&m_indexMesh, (ppu_address_t)&m_triangleMeshInterface->getIndexedMeshArray()[index] , sizeof(btIndexedMesh), DMA_TAG(dmaTag), 0, 0); -} - -void SpuBvhMeshShape::dmaSubTreeHeaders (ppu_address_t subTreePtr, int numHeaders, uint32_t dmaTag) -{ - cellDmaGet(&m_subtreeHeaders[0], subTreePtr, numHeaders * sizeof(btBvhSubtreeInfo), DMA_TAG(dmaTag), 0, 0); -} - -void SpuBvhMeshShape::dmaSubTreeNodes (const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag) -{ - cellDmaGet(&m_subtreeNodes[0], reinterpret_cast(&nodeArray[subtree.m_rootNodeIndex]) , subtree.m_subtreeSize* sizeof(btQuantizedBvhNode), DMA_TAG(dmaTag), 0, 0); -} - - btPoint3 localGetSupportingVertexWithoutMargin(int shapeType, void* shape, const btVector3& localDir,struct SpuConvexPolyhedronVertexData* convexVertexData)//, int *featureIndex) { switch (shapeType) @@ -447,6 +298,49 @@ void computeAabb (btVector3& aabbMin, btVector3& aabbMax, btConvexInternalShape* }; } +void dmaBvhShapeData (bvhMeshShape_LocalStoreMemory* bvhMeshShape, btBvhTriangleMeshShape* triMeshShape) +{ + register int dmaSize; + register ppu_address_t dmaPpuAddress2; + + dmaSize = sizeof(btTriangleIndexVertexArray); + dmaPpuAddress2 = reinterpret_cast(triMeshShape->getMeshInterface()); + // spu_printf("trimeshShape->getMeshInterface() == %llx\n",dmaPpuAddress2); +#ifdef __SPU__ + cellDmaGet(&bvhMeshShape->gTriangleMeshInterfaceStorage, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); + bvhMeshShape->gTriangleMeshInterfacePtr = &bvhMeshShape->gTriangleMeshInterfaceStorage; +#else + bvhMeshShape->gTriangleMeshInterfacePtr = (btTriangleIndexVertexArray*)cellDmaGetReadOnly(&bvhMeshShape->gTriangleMeshInterfaceStorage, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); +#endif + + //cellDmaWaitTagStatusAll(DMA_MASK(1)); + + ///now DMA over the BVH + + dmaSize = sizeof(btOptimizedBvh); + dmaPpuAddress2 = reinterpret_cast(triMeshShape->getOptimizedBvh()); + //spu_printf("trimeshShape->getOptimizedBvh() == %llx\n",dmaPpuAddress2); + cellDmaGet(&bvhMeshShape->gOptimizedBvh, dmaPpuAddress2 , dmaSize, DMA_TAG(2), 0, 0); + //cellDmaWaitTagStatusAll(DMA_MASK(2)); + cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); +} + +void dmaBvhIndexedMesh (btIndexedMesh* IndexMesh, IndexedMeshArray& indexArray, int index, uint32_t dmaTag) +{ + cellDmaGet(IndexMesh, (ppu_address_t)&indexArray[index] , sizeof(btIndexedMesh), DMA_TAG(dmaTag), 0, 0); + +} + +void dmaBvhSubTreeHeaders (btBvhSubtreeInfo* subTreeHeaders, ppu_address_t subTreePtr, int batchSize, uint32_t dmaTag) +{ + cellDmaGet(subTreeHeaders, subTreePtr, batchSize * sizeof(btBvhSubtreeInfo), DMA_TAG(dmaTag), 0, 0); +} + +void dmaBvhSubTreeNodes (btQuantizedBvhNode* nodes, const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag) +{ + cellDmaGet(nodes, reinterpret_cast(&nodeArray[subtree.m_rootNodeIndex]) , subtree.m_subtreeSize* sizeof(btQuantizedBvhNode), DMA_TAG(2), 0, 0); +} + ///getShapeTypeSize could easily be optimized, but it is not likely a bottleneck int getShapeTypeSize(int shapeType) { diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h index 8a2a5c049..4c2d88017 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h @@ -4,7 +4,6 @@ #include "../SpuDoubleBuffer.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" -#include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "BulletCollision/CollisionShapes/btConvexInternalShape.h" #include "BulletCollision/CollisionShapes/btCylinderShape.h" @@ -19,69 +18,8 @@ #include "BulletCollision/CollisionShapes/btConvexHullShape.h" #include "BulletCollision/CollisionShapes/btCompoundShape.h" -#define MAX_SHAPE_SIZE 256 #define MAX_NUM_SPU_CONVEX_POINTS 128 -struct SpuInternalShape -{ - ATTRIBUTE_ALIGNED16(char m_collisionShapeStorage[MAX_SHAPE_SIZE]); - btConvexShape* m_convexShape; - btCollisionShape* m_collisionShape; - ppu_address_t m_ppuConvexShapePtr; - SpuInternalShape () - { - m_convexShape = (btConvexShape*)&m_collisionShapeStorage[0]; - m_collisionShape = (btCollisionShape*)&m_collisionShapeStorage[0]; - m_ppuConvexShapePtr = 0; - } - - void dmaShapeData (ppu_address_t ppuAddress, int shapeType, uint32_t dmaTag); -}; - -struct SpuInternalConvexHull -{ - ATTRIBUTE_ALIGNED16(btVector3 m_pointsBuffer[MAX_NUM_SPU_CONVEX_POINTS]); - int m_numPoints; - btVector3* m_points; - ppu_address_t m_ppuPointsPtr; - - SpuInternalConvexHull () - { - m_points = (btVector3*)&m_pointsBuffer[0]; - m_numPoints = 0; - m_ppuPointsPtr = 0; - } - - void dmaPointsData (const SpuInternalShape& shape, uint32_t dmaTag); - void dmaPointsData (ppu_address_t ppuPointsAddress, int numPoints, uint32_t dmaTag); -}; - - - -struct SpuBvhMeshShape -{ - ATTRIBUTE_ALIGNED16(char m_optimizedBvhBuffer[sizeof(btOptimizedBvh)+16]); - ATTRIBUTE_ALIGNED16(btTriangleIndexVertexArray m_triangleMeshInterfaceBuffer); - #define MAX_SPU_SUBTREE_HEADERS 32 - ///only a single mesh part for now, we can add support for multiple parts, but quantized trees don't support this at the moment - ATTRIBUTE_ALIGNED16(btIndexedMesh m_indexMesh); - ATTRIBUTE_ALIGNED16(btBvhSubtreeInfo m_subtreeHeaders[MAX_SPU_SUBTREE_HEADERS]); - ATTRIBUTE_ALIGNED16(btQuantizedBvhNode m_subtreeNodes[MAX_SUBTREE_SIZE_IN_BYTES/sizeof(btQuantizedBvhNode)]); - btOptimizedBvh* m_optimizedBvh; - btTriangleIndexVertexArray* m_triangleMeshInterface; - - SpuBvhMeshShape () - { - m_optimizedBvh = (btOptimizedBvh*)&m_optimizedBvhBuffer[0]; - m_triangleMeshInterface = (btTriangleIndexVertexArray*)&m_triangleMeshInterfaceBuffer; - } - - void dmaMeshInterfaceAndOptimizedBvh (const SpuInternalShape& triangleMeshShape, uint32_t dmaTag1, uint32_t dmaTag2); - void dmaIndexedMesh (int index, uint32_t dmaTag); - void dmaSubTreeHeaders (ppu_address_t subTreePtr, int numHeaders, uint32_t dmaTag); - void dmaSubTreeNodes (const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag); -}; - struct SpuConvexPolyhedronVertexData { void* gSpuConvexShapePtr; @@ -90,19 +28,7 @@ struct SpuConvexPolyhedronVertexData ATTRIBUTE_ALIGNED16(btPoint3 g_convexPointBuffer[MAX_NUM_SPU_CONVEX_POINTS]); }; -struct SpuCompoundShape -{ - #define MAX_SPU_COMPOUND_SUBSHAPES 16 - ATTRIBUTE_ALIGNED16(btCompoundShapeChild m_subshapes[MAX_SPU_COMPOUND_SUBSHAPES]); - - void dmaChildShapeInfo (btCompoundShape* compoundShape, uint32_t dmaTag); - void dmaChildShape (int childShape, - SpuInternalShape* localShape, - SpuInternalConvexHull* localShapeHull, - uint32_t dmaTag); -}; - - +#define MAX_SHAPE_SIZE 256 struct CollisionShape_LocalStoreMemory { diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.cpp index b9dbe03ac..4cc00afb9 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.cpp @@ -170,7 +170,7 @@ void SpuContactResult::writeDoubleBufferedManifold(btPersistentManifold* lsManif //no, the swapBuffers does the wait } -void SpuContactResult::addContactPoint(const btVector3& normalOnBInWorld,const btPoint3& pointInWorld,btScalar depth) +void SpuContactResult::addContactPoint(const btVector3& normalOnBInWorld,const btPoint3& pointInWorld,float depth) { //spu_printf("*** SpuContactResult::addContactPoint: depth = %f\n",depth); diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.h index bcacd4d43..6752cbd53 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuContactResult.h @@ -1,113 +1,113 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -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 SPU_CONTACT_RESULT2_H -#define SPU_CONTACT_RESULT2_H - - -#ifndef WIN32 -#include -#endif - - - -#include "../SpuDoubleBuffer.h" - - -#include "LinearMath/btTransform.h" -#include "LinearMath/btPoint3.h" - - -#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" -#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h" - -struct SpuCollisionPairInput -{ - ppu_address_t m_collisionShapes[2]; - void* m_spuCollisionShapes[2]; - - ppu_address_t m_persistentManifoldPtr; - btVector3 m_primitiveDimensions0; - btVector3 m_primitiveDimensions1; - int m_shapeType0; - int m_shapeType1; - float m_collisionMargin0; - float m_collisionMargin1; - - btTransform m_worldTransform0; - btTransform m_worldTransform1; - - bool m_isSwapped; - bool m_useEpa; -}; - -struct SpuClosestPointInput -{ - SpuClosestPointInput() - :m_maximumDistanceSquared(float(1e30)), - m_stackAlloc(0) - { - } - - btTransform m_transformA; - btTransform m_transformB; - float m_maximumDistanceSquared; - class btStackAlloc* m_stackAlloc; - struct SpuConvexPolyhedronVertexData* m_convexVertexData[2]; -}; - - -///SpuContactResult exports the contact points using double-buffered DMA transfers, only when needed -///So when an existing contact point is duplicated, no transfer/refresh is performed. -class SpuContactResult : public btDiscreteCollisionDetectorInterface::Result -{ - btTransform m_rootWorldTransform0; - btTransform m_rootWorldTransform1; - ppu_address_t m_manifoldAddress; - - btPersistentManifold* m_spuManifold; - bool m_RequiresWriteBack; - btScalar m_combinedFriction; - btScalar m_combinedRestitution; - - bool m_isSwapped; - - DoubleBuffer g_manifoldDmaExport; - - public: - SpuContactResult(); - virtual ~SpuContactResult(); - - btPersistentManifold* GetSpuManifold() const - { - return m_spuManifold; - } - - virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1); - - void setContactInfo(btPersistentManifold* spuManifold, ppu_address_t manifoldAddress,const btTransform& worldTrans0,const btTransform& worldTrans1, btScalar restitution0,btScalar restitution1, btScalar friction0,btScalar friction01, bool isSwapped); - - - void writeDoubleBufferedManifold(btPersistentManifold* lsManifold, btPersistentManifold* mmManifold); - - virtual void addContactPoint(const btVector3& normalOnBInWorld,const btPoint3& pointInWorld,btScalar depth); - - void flush(); -}; - - - -#endif //SPU_CONTACT_RESULT2_H - +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +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 SPU_CONTACT_RESULT2_H +#define SPU_CONTACT_RESULT2_H + + +#ifndef WIN32 +#include +#endif + + + +#include "../SpuDoubleBuffer.h" + + +#include "LinearMath/btTransform.h" +#include "LinearMath/btPoint3.h" + + +#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" + + +struct SpuCollisionPairInput +{ + ppu_address_t m_collisionShapes[2]; + void* m_spuCollisionShapes[2]; + + ppu_address_t m_persistentManifoldPtr; + btVector3 m_primitiveDimensions0; + btVector3 m_primitiveDimensions1; + int m_shapeType0; + int m_shapeType1; + float m_collisionMargin0; + float m_collisionMargin1; + + btTransform m_worldTransform0; + btTransform m_worldTransform1; + + bool m_isSwapped; + bool m_useEpa; +}; + + +struct SpuClosestPointInput +{ + SpuClosestPointInput() + :m_maximumDistanceSquared(float(1e30)), + m_stackAlloc(0) + { + } + + btTransform m_transformA; + btTransform m_transformB; + float m_maximumDistanceSquared; + class btStackAlloc* m_stackAlloc; + struct SpuConvexPolyhedronVertexData* m_convexVertexData[2]; +}; + +///SpuContactResult exports the contact points using double-buffered DMA transfers, only when needed +///So when an existing contact point is duplicated, no transfer/refresh is performed. +class SpuContactResult +{ + btTransform m_rootWorldTransform0; + btTransform m_rootWorldTransform1; + ppu_address_t m_manifoldAddress; + + btPersistentManifold* m_spuManifold; + bool m_RequiresWriteBack; + btScalar m_combinedFriction; + btScalar m_combinedRestitution; + + bool m_isSwapped; + + DoubleBuffer g_manifoldDmaExport; + + public: + SpuContactResult(); + virtual ~SpuContactResult(); + + btPersistentManifold* GetSpuManifold() const + { + return m_spuManifold; + } + + virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1); + + void setContactInfo(btPersistentManifold* spuManifold, ppu_address_t manifoldAddress,const btTransform& worldTrans0,const btTransform& worldTrans1, btScalar restitution0,btScalar restitution1, btScalar friction0,btScalar friction01, bool isSwapped); + + + void writeDoubleBufferedManifold(btPersistentManifold* lsManifold, btPersistentManifold* mmManifold); + + virtual void addContactPoint(const btVector3& normalOnBInWorld,const btPoint3& pointInWorld,float depth); + + void flush(); +}; + + + +#endif //SPU_CONTACT_RESULT2_H + diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuConvexPenetrationDepthSolver.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuConvexPenetrationDepthSolver.h index 67e10e08a..2a18fa2ba 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuConvexPenetrationDepthSolver.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuConvexPenetrationDepthSolver.h @@ -22,7 +22,7 @@ subject to the following restrictions: class btStackAlloc; class btIDebugDraw; -class btVoronoiSimplexSolver; +class SpuVoronoiSimplexSolver; #include #include @@ -34,7 +34,7 @@ class SpuConvexPenetrationDepthSolver public: virtual ~SpuConvexPenetrationDepthSolver() {}; - virtual bool calcPenDepth( btVoronoiSimplexSolver& simplexSolver, + virtual bool calcPenDepth( SpuVoronoiSimplexSolver& simplexSolver, void* convexA,void* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB, btTransform& transA,const btTransform& transB, btVector3& v, btPoint3& pa, btPoint3& pb, diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.cpp index cc412cee3..3765ac354 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.cpp @@ -13,14 +13,13 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" -#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" - #include "SpuEpaPenetrationDepthSolver.h" +#include "SpuVoronoiSimplexSolver.h" +#include "SpuGjkPairDetector.h" #include "SpuContactResult.h" #include "SpuGjkEpa2.h" -bool SpuEpaPenetrationDepthSolver::calcPenDepth( btVoronoiSimplexSolver& simplexSolver, +bool SpuEpaPenetrationDepthSolver::calcPenDepth( SpuVoronoiSimplexSolver& simplexSolver, void* convexA,void* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB, btTransform& transA,const btTransform& transB, btVector3& v, btPoint3& pa, btPoint3& pb, diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.h index 60bafff53..7074a7aea 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuEpaPenetrationDepthSolver.h @@ -22,7 +22,7 @@ subject to the following restrictions: class btStackAlloc; class btIDebugDraw; -class btVoronoiSimplexSolver; +class SpuVoronoiSimplexSolver; ///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. @@ -30,7 +30,7 @@ class SpuEpaPenetrationDepthSolver : public SpuConvexPenetrationDepthSolver { public: - virtual bool calcPenDepth( btVoronoiSimplexSolver& simplexSolver, + virtual bool calcPenDepth( SpuVoronoiSimplexSolver& simplexSolver, void* convexA,void* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB, btTransform& transA,const btTransform& transB, btVector3& v, btPoint3& pa, btPoint3& pb, diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp index 0260f688f..c6e211677 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.cpp @@ -1,23 +1,3 @@ -#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" -#include "BulletCollision/CollisionDispatch/btCollisionObject.h" - -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" -#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" -#include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h" -#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h" - -#include "BulletCollision/CollisionShapes/btConvexShape.h" -#include "BulletCollision/CollisionShapes/btOptimizedBvh.h" -#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h" -#include "BulletCollision/CollisionShapes/btSphereShape.h" -#include "BulletCollision/CollisionShapes/btTriangleShape.h" -#include "BulletCollision/CollisionShapes/btCapsuleShape.h" -#include "BulletCollision/CollisionShapes/btConvexShape.h" -#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" -#include "BulletCollision/CollisionShapes/btConvexHullShape.h" -#include "BulletCollision/CollisionShapes/btCompoundShape.h" -#include "BulletCollision/CollisionShapes/btConvexPointCloudShape.h" - #include "SpuGatheringCollisionTask.h" @@ -27,8 +7,25 @@ #include "../SpuCollisionTaskProcess.h" #include "../SpuGatheringCollisionDispatcher.h" //for SPU_BATCHSIZE_BROADPHASE_PAIRS +#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" #include "../SpuContactManifoldCollisionAlgorithm.h" +#include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "SpuContactResult.h" +#include "BulletCollision/CollisionShapes/btOptimizedBvh.h" +#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h" +#include "BulletCollision/CollisionShapes/btSphereShape.h" + +#include "BulletCollision/CollisionShapes/btCapsuleShape.h" + +#include "BulletCollision/CollisionShapes/btConvexShape.h" +#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" +#include "BulletCollision/CollisionShapes/btConvexHullShape.h" +#include "BulletCollision/CollisionShapes/btCompoundShape.h" + +#include "SpuMinkowskiPenetrationDepthSolver.h" +#include "SpuEpaPenetrationDepthSolver.h" +#include "SpuGjkPairDetector.h" +#include "SpuVoronoiSimplexSolver.h" #include "SpuCollisionShapes.h" //definition of SpuConvexPolyhedronVertexData @@ -104,20 +101,17 @@ bool gUseEpa = false; ///Make sure no destructors are called on this memory struct CollisionTask_LocalStoreMemory { - ATTRIBUTE_ALIGNED16(char bufferProxy0[16]); - ATTRIBUTE_ALIGNED16(char bufferProxy1[16]); + ATTRIBUTE_ALIGNED16(char bufferProxy0[16]); + ATTRIBUTE_ALIGNED16(char bufferProxy1[16]); + ATTRIBUTE_ALIGNED16(btBroadphaseProxy* gProxyPtr0); ATTRIBUTE_ALIGNED16(btBroadphaseProxy* gProxyPtr1); - btBroadphaseProxy* getProxyPtr0 () - { - return (btBroadphaseProxy*)bufferProxy0; - } - btBroadphaseProxy* getProxyPtr1 () - { - return (btBroadphaseProxy*)bufferProxy1; - } + + //ATTRIBUTE_ALIGNED16(btCollisionObject gColObj0); + //ATTRIBUTE_ALIGNED16(btCollisionObject gColObj1); ATTRIBUTE_ALIGNED16(char gColObj0 [sizeof(btCollisionObject)+16]); ATTRIBUTE_ALIGNED16(char gColObj1 [sizeof(btCollisionObject)+16]); + btCollisionObject* getColObj0() { return (btCollisionObject*) gColObj0; @@ -126,31 +120,33 @@ struct CollisionTask_LocalStoreMemory { return (btCollisionObject*) gColObj1; } + DoubleBuffer g_workUnitTaskBuffers; ATTRIBUTE_ALIGNED16(btBroadphasePair gBroadphasePairs[SPU_BATCHSIZE_BROADPHASE_PAIRS]); + + + //SpuContactManifoldCollisionAlgorithm gSpuContactManifoldAlgo; + //ATTRIBUTE_ALIGNED16(char gSpuContactManifoldAlgo[sizeof(SpuContactManifoldCollisionAlgorithm)+128]); + SpuContactManifoldCollisionAlgorithm gSpuContactManifoldAlgo; + SpuContactManifoldCollisionAlgorithm* getlocalCollisionAlgorithm() { return (SpuContactManifoldCollisionAlgorithm*)&gSpuContactManifoldAlgo; } - btPersistentManifold gPersistentManifold; - SpuInternalShape gInternalShapes[3]; // the third is temporary storage - SpuInternalConvexHull gInternalConvexHull[3]; // the third is for temporary storage + btPersistentManifold gPersistentManifold; + + CollisionShape_LocalStoreMemory gCollisionShapes[2]; ///we reserve 32bit integer indices, even though they might be 16bit ATTRIBUTE_ALIGNED16(int spuIndices[16]); - SpuBvhMeshShape gBvhMeshShape; - SpuCompoundShape compoundShapeData[2]; + + bvhMeshShape_LocalStoreMemory bvhShapeData; + SpuConvexPolyhedronVertexData convexVertexData[2]; + CompoundShape_LocalStoreMemory compoundShapeData[2]; }; -static void print_size_stats () -{ - spu_printf("sizeof(CollisionTask_LocalStoreMemory) = %d\n", sizeof(CollisionTask_LocalStoreMemory)); - spu_printf("sizeof(SpuInternalShape) = %d\n", sizeof(SpuInternalShape)); - spu_printf("sizeof(SpuInternalConvexHull) = %d\n", sizeof(SpuInternalConvexHull)); - spu_printf("sizeof(SpuBvhMeshShape) = %d\n", sizeof(SpuBvhMeshShape)); -} #if defined(__CELLOS_LV2__) || defined(USE_LIBSPE2) @@ -158,7 +154,6 @@ ATTRIBUTE_ALIGNED16(CollisionTask_LocalStoreMemory gLocalStoreMemory); void* createCollisionLocalStoreMemory() { - //print_size_stats (); return &gLocalStoreMemory; } #else @@ -244,7 +239,110 @@ SIMD_FORCE_INLINE void small_cache_read_triple( void* ls0, ppu_address_t ea0, -#if 0 +class spuNodeCallback : public btNodeOverlapCallback +{ + SpuCollisionPairInput* m_wuInput; + SpuContactResult& m_spuContacts; + CollisionTask_LocalStoreMemory* m_lsMemPtr; + + ATTRIBUTE_ALIGNED16(btVector3 spuTriangleVertices[3]); + ATTRIBUTE_ALIGNED16(btScalar spuUnscaledVertex[4]); + + + +public: + spuNodeCallback(SpuCollisionPairInput* wuInput, CollisionTask_LocalStoreMemory* lsMemPtr,SpuContactResult& spuContacts) + : m_wuInput(wuInput), + m_lsMemPtr(lsMemPtr), + m_spuContacts(spuContacts) + { + } + + virtual void processNode(int subPart, int triangleIndex) + { + ///Create a triangle on the stack, call process collision, with GJK + ///DMA the vertices, can benefit from software caching + + // spu_printf("processNode with triangleIndex %d\n",triangleIndex); + +///TODO: add switch between short int, and int indices, based on indexType + + // ugly solution to support both 16bit and 32bit indices + if (m_lsMemPtr->bvhShapeData.gIndexMesh.m_indexType == PHY_SHORT) + { + unsigned short int* indexBasePtr = (unsigned short int*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexBase+triangleIndex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexStride); + ATTRIBUTE_ALIGNED16(unsigned short int tmpIndices[3]); + + small_cache_read_triple(&tmpIndices[0],(ppu_address_t)&indexBasePtr[0], + &tmpIndices[1],(ppu_address_t)&indexBasePtr[1], + &tmpIndices[2],(ppu_address_t)&indexBasePtr[2], + sizeof(unsigned short int)); + + m_lsMemPtr->spuIndices[0] = int(tmpIndices[0]); + m_lsMemPtr->spuIndices[1] = int(tmpIndices[1]); + m_lsMemPtr->spuIndices[2] = int(tmpIndices[2]); + } else + { + unsigned int* indexBasePtr = (unsigned int*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexBase+triangleIndex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_triangleIndexStride); + + small_cache_read_triple(&m_lsMemPtr->spuIndices[0],(ppu_address_t)&indexBasePtr[0], + &m_lsMemPtr->spuIndices[1],(ppu_address_t)&indexBasePtr[1], + &m_lsMemPtr->spuIndices[2],(ppu_address_t)&indexBasePtr[2], + sizeof(int)); + } + + // spu_printf("SPU index0=%d ,",spuIndices[0]); + // spu_printf("SPU index1=%d ,",spuIndices[1]); + // spu_printf("SPU index2=%d ,",spuIndices[2]); + // spu_printf("SPU: indexBasePtr=%llx\n",indexBasePtr); + + const btVector3& meshScaling = m_lsMemPtr->bvhShapeData.gTriangleMeshInterfacePtr->getScaling(); + for (int j=2;btLikely( j>=0 );j--) + { + int graphicsindex = m_lsMemPtr->spuIndices[j]; + + // spu_printf("SPU index=%d ,",graphicsindex); + btScalar* graphicsbasePtr = (btScalar*)(m_lsMemPtr->bvhShapeData.gIndexMesh.m_vertexBase+graphicsindex*m_lsMemPtr->bvhShapeData.gIndexMesh.m_vertexStride); + // spu_printf("SPU graphicsbasePtr=%llx\n",graphicsbasePtr); + + + ///handle un-aligned vertices... + + //another DMA for each vertex + small_cache_read_triple(&spuUnscaledVertex[0],(ppu_address_t)&graphicsbasePtr[0], + &spuUnscaledVertex[1],(ppu_address_t)&graphicsbasePtr[1], + &spuUnscaledVertex[2],(ppu_address_t)&graphicsbasePtr[2], + sizeof(btScalar)); + + spuTriangleVertices[j] = btVector3( + spuUnscaledVertex[0]*meshScaling.getX(), + spuUnscaledVertex[1]*meshScaling.getY(), + spuUnscaledVertex[2]*meshScaling.getZ()); + + // spu_printf("SPU:triangle vertices:%f,%f,%f\n",spuTriangleVertices[j].x(),spuTriangleVertices[j].y(),spuTriangleVertices[j].z()); + } + + + + //btTriangleShape tmpTriangleShape(spuTriangleVertices[0],spuTriangleVertices[1],spuTriangleVertices[2]); + + + SpuCollisionPairInput triangleConcaveInput(*m_wuInput); + triangleConcaveInput.m_spuCollisionShapes[1] = &spuTriangleVertices[0]; + triangleConcaveInput.m_shapeType1 = TRIANGLE_SHAPE_PROXYTYPE; + + m_spuContacts.setShapeIdentifiers(-1,-1,subPart,triangleIndex); + + // m_spuContacts.flush(); + + ProcessSpuConvexConvexCollision(&triangleConcaveInput, m_lsMemPtr,m_spuContacts); + ///this flush should be automatic + // m_spuContacts.flush(); + } + +}; + + //////////////////////// /// Convex versus Concave triangle mesh collision detection (handles concave triangle mesh versus sphere, box, cylinder, triangle, cone, convex polyhedron etc) /////////////////// @@ -349,7 +447,128 @@ void ProcessConvexConcaveSpuCollision(SpuCollisionPairInput* wuInput, CollisionT } } -#endif + + + +//////////////////////// +/// Convex versus Convex collision detection (handles collision between sphere, box, cylinder, triangle, cone, convex polyhedron etc) +/////////////////// +void ProcessSpuConvexConvexCollision(SpuCollisionPairInput* wuInput, CollisionTask_LocalStoreMemory* lsMemPtr, SpuContactResult& spuContacts) +{ + register int dmaSize; + register ppu_address_t dmaPpuAddress2; + +#ifdef DEBUG_SPU_COLLISION_DETECTION + //spu_printf("SPU: ProcessSpuConvexConvexCollision\n"); +#endif //DEBUG_SPU_COLLISION_DETECTION + //CollisionShape* shape0 = (CollisionShape*)wuInput->m_collisionShapes[0]; + //CollisionShape* shape1 = (CollisionShape*)wuInput->m_collisionShapes[1]; + btPersistentManifold* manifold = (btPersistentManifold*)wuInput->m_persistentManifoldPtr; + + bool genericGjk = true; + + if (genericGjk) + { + //try generic GJK + + SpuVoronoiSimplexSolver vsSolver; + SpuEpaPenetrationDepthSolver epaPenetrationSolver; + SpuMinkowskiPenetrationDepthSolver minkowskiPenetrationSolver; + SpuConvexPenetrationDepthSolver* penetrationSolver; + + if (gUseEpa) + { + penetrationSolver = &epaPenetrationSolver; + } else { + penetrationSolver = &minkowskiPenetrationSolver; + } + + + ///DMA in the vertices for convex shapes + ATTRIBUTE_ALIGNED16(char convexHullShape0[sizeof(btConvexHullShape)]); + ATTRIBUTE_ALIGNED16(char convexHullShape1[sizeof(btConvexHullShape)]); + + if ( btLikely( wuInput->m_shapeType0== CONVEX_HULL_SHAPE_PROXYTYPE ) ) + { + // spu_printf("SPU: DMA btConvexHullShape\n"); + + dmaSize = sizeof(btConvexHullShape); + dmaPpuAddress2 = wuInput->m_collisionShapes[0]; + + cellDmaGet(&convexHullShape0, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); + //cellDmaWaitTagStatusAll(DMA_MASK(1)); + } + + if ( btLikely( wuInput->m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE ) ) + { + // spu_printf("SPU: DMA btConvexHullShape\n"); + dmaSize = sizeof(btConvexHullShape); + dmaPpuAddress2 = wuInput->m_collisionShapes[1]; + cellDmaGet(&convexHullShape1, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); + //cellDmaWaitTagStatusAll(DMA_MASK(1)); + } + + if ( btLikely( wuInput->m_shapeType0 == CONVEX_HULL_SHAPE_PROXYTYPE ) ) + { + cellDmaWaitTagStatusAll(DMA_MASK(1)); + dmaConvexVertexData (&lsMemPtr->convexVertexData[0], (btConvexHullShape*)&convexHullShape0); + lsMemPtr->convexVertexData[0].gSpuConvexShapePtr = wuInput->m_spuCollisionShapes[0]; + } + + + if ( btLikely( wuInput->m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE ) ) + { + cellDmaWaitTagStatusAll(DMA_MASK(1)); + dmaConvexVertexData (&lsMemPtr->convexVertexData[1], (btConvexHullShape*)&convexHullShape1); + lsMemPtr->convexVertexData[1].gSpuConvexShapePtr = wuInput->m_spuCollisionShapes[1]; + } + + if ( btLikely( wuInput->m_shapeType0 == CONVEX_HULL_SHAPE_PROXYTYPE ) ) + { + cellDmaWaitTagStatusAll(DMA_MASK(2)); + lsMemPtr->convexVertexData[0].gConvexPoints = &lsMemPtr->convexVertexData[0].g_convexPointBuffer[0]; + } + + if ( btLikely( wuInput->m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE ) ) + { + cellDmaWaitTagStatusAll(DMA_MASK(2)); + lsMemPtr->convexVertexData[1].gConvexPoints = &lsMemPtr->convexVertexData[1].g_convexPointBuffer[0]; + } + + + void* shape0Ptr = wuInput->m_spuCollisionShapes[0]; + void* shape1Ptr = wuInput->m_spuCollisionShapes[1]; + int shapeType0 = wuInput->m_shapeType0; + int shapeType1 = wuInput->m_shapeType1; + float marginA = wuInput->m_collisionMargin0; + float marginB = wuInput->m_collisionMargin1; + + SpuClosestPointInput cpInput; + cpInput.m_convexVertexData[0] = &lsMemPtr->convexVertexData[0]; + cpInput.m_convexVertexData[1] = &lsMemPtr->convexVertexData[1]; + cpInput.m_transformA = wuInput->m_worldTransform0; + cpInput.m_transformB = wuInput->m_worldTransform1; + float sumMargin = (marginA+marginB+lsMemPtr->gPersistentManifold.getContactBreakingThreshold()); + cpInput.m_maximumDistanceSquared = sumMargin * sumMargin; + + ppu_address_t manifoldAddress = (ppu_address_t)manifold; + + btPersistentManifold* spuManifold=&lsMemPtr->gPersistentManifold; + //spuContacts.setContactInfo(spuManifold,manifoldAddress,wuInput->m_worldTransform0,wuInput->m_worldTransform1,wuInput->m_isSwapped); + spuContacts.setContactInfo(spuManifold,manifoldAddress,lsMemPtr->getColObj0()->getWorldTransform(), + lsMemPtr->getColObj1()->getWorldTransform(), + lsMemPtr->getColObj0()->getRestitution(),lsMemPtr->getColObj1()->getRestitution(), + lsMemPtr->getColObj0()->getFriction(),lsMemPtr->getColObj1()->getFriction(), + wuInput->m_isSwapped); + + SpuGjkPairDetector gjk(shape0Ptr,shape1Ptr,shapeType0,shapeType1,marginA,marginB,&vsSolver,penetrationSolver); + gjk.getClosestPoints(cpInput,spuContacts);//,debugDraw); + } + + +} + + template void DoSwap(T& a, T& b) { char tmp[sizeof(T)]; @@ -378,415 +597,63 @@ SIMD_FORCE_INLINE void dmaAndSetupCollisionObjects(SpuCollisionPairInput& collis } -void SpuConvexConvexCollisionAlgorithm (SpuCollisionPairInput& collisionPairInput, - CollisionTask_LocalStoreMemory& lsMem, - SpuContactResult &spuContacts, - SpuInternalShape* shape0Internal, - SpuInternalShape* shape1Internal, - SpuInternalConvexHull* shape0Points, - SpuInternalConvexHull* shape1Points) -{ - btConvexPointCloudShape shape0ConvexHull (NULL, 0, false); - btConvexPointCloudShape shape1ConvexHull (NULL, 0, false); - btConvexShape* shape0; - btConvexShape* shape1; - btPersistentManifold* manifold = (btPersistentManifold*)collisionPairInput.m_persistentManifoldPtr; - -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("SpuConvexConvexCollisionAlgorithm ()\n"); -#endif - if (collisionPairInput.m_shapeType0== CONVEX_HULL_SHAPE_PROXYTYPE ) - { - shape0ConvexHull.setPoints (shape0Points->m_points, shape0Points->m_numPoints, false); - { - btVector3 aabbMin, aabbMax; - btPolyhedralConvexShape* pcs = (btPolyhedralConvexShape*)shape0Internal->m_convexShape; - pcs->getCachedLocalAabb (aabbMin, aabbMax); - shape0ConvexHull.setCachedLocalAabb (aabbMin, aabbMax); - } - shape0 = &shape0ConvexHull; - } else { - shape0 = shape0Internal->m_convexShape; - } - - if (collisionPairInput.m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE ) - { - shape1ConvexHull.setPoints (shape1Points->m_points, shape1Points->m_numPoints, false); - { - btVector3 aabbMin, aabbMax; - btPolyhedralConvexShape* pcs = (btPolyhedralConvexShape*)shape1Internal->m_convexShape; - pcs->getCachedLocalAabb (aabbMin, aabbMax); - shape1ConvexHull.setCachedLocalAabb (aabbMin, aabbMax); - } - shape1 = &shape1ConvexHull; - } else { - shape1 = shape1Internal->m_convexShape; - } - -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("shape0 = %p shape1 = %p\n", shape0, shape1); -#endif - { - btVoronoiSimplexSolver vsSolver; - btConvexPenetrationDepthSolver* penetrationSolver = NULL; -//#define SPU_ENABLE_EPA 1 -#ifdef SPU_ENABLE_EPA - btGjkEpaPenetrationDepthSolver epaPenetrationSolver; - btMinkowskiPenetrationDepthSolver minkowskiPenetrationSolver; - if (gUseEpa) - { - penetrationSolver = &epaPenetrationSolver; - } else { - penetrationSolver = &minkowskiPenetrationSolver; - } -#else - btMinkowskiPenetrationDepthSolver minkowskiPenetrationSolver; - penetrationSolver = &minkowskiPenetrationSolver; -#endif - btDiscreteCollisionDetectorInterface::ClosestPointInput cpInput; - cpInput.m_transformA = collisionPairInput.m_worldTransform0; - cpInput.m_transformB = collisionPairInput.m_worldTransform1; - btPersistentManifold* spuManifold= &lsMem.gPersistentManifold; - ppu_address_t manifoldAddress = (ppu_address_t)manifold; - spuContacts.setContactInfo(spuManifold,manifoldAddress, - lsMem.getColObj0()->getWorldTransform(), - lsMem.getColObj1()->getWorldTransform(), - lsMem.getColObj0()->getRestitution(), - lsMem.getColObj1()->getRestitution(), - lsMem.getColObj0()->getFriction(), - lsMem.getColObj1()->getFriction(), - collisionPairInput.m_isSwapped); - -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("start GJK\n"); -#endif - btGjkPairDetector gjk(shape0,shape1,&vsSolver,penetrationSolver); - gjk.getClosestPoints(cpInput,spuContacts, NULL);//,debugDraw); -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("stop GJK\n"); -#endif - } -} - -class spuNodeCallback : public btNodeOverlapCallback -{ - const SpuCollisionPairInput& m_collisionPairInput; - CollisionTask_LocalStoreMemory& m_lsMem; - SpuContactResult& m_spuContacts; - - ATTRIBUTE_ALIGNED16(btVector3 spuTriangleVertices[3]); - ATTRIBUTE_ALIGNED16(btScalar spuUnscaledVertex[4]); -public: - spuNodeCallback(const SpuCollisionPairInput& collisionPairInput, - CollisionTask_LocalStoreMemory& lsMem, - SpuContactResult& spuContacts) - : m_collisionPairInput(collisionPairInput), - m_lsMem(lsMem), - m_spuContacts(spuContacts) - { - } - - virtual void processNode(int subPart, int triangleIndex) - { - ///Create a triangle on the stack, call process collision, with GJK - ///DMA the vertices, can benefit from software caching - - //spu_printf("processNode with triangleIndex %d\n",triangleIndex); - - ///TODO: add switch between short int, and int indices, based on indexType - - // ugly solution to support both 16bit and 32bit indices - if (m_lsMem.gBvhMeshShape.m_indexMesh.m_indexType == PHY_SHORT) - { - unsigned short int* indexBasePtr = (unsigned short int*)(m_lsMem.gBvhMeshShape.m_indexMesh.m_triangleIndexBase+triangleIndex*m_lsMem.gBvhMeshShape.m_indexMesh.m_triangleIndexStride); - ATTRIBUTE_ALIGNED16(unsigned short int tmpIndices[3]); - - small_cache_read_triple(&tmpIndices[0],(ppu_address_t)&indexBasePtr[0], - &tmpIndices[1],(ppu_address_t)&indexBasePtr[1], - &tmpIndices[2],(ppu_address_t)&indexBasePtr[2], - sizeof(unsigned short int)); - - m_lsMem.spuIndices[0] = int(tmpIndices[0]); - m_lsMem.spuIndices[1] = int(tmpIndices[1]); - m_lsMem.spuIndices[2] = int(tmpIndices[2]); - } else - { - unsigned int* indexBasePtr = (unsigned int*)(m_lsMem.gBvhMeshShape.m_indexMesh.m_triangleIndexBase+triangleIndex*m_lsMem.gBvhMeshShape.m_indexMesh.m_triangleIndexStride); - - small_cache_read_triple(&m_lsMem.spuIndices[0],(ppu_address_t)&indexBasePtr[0], - &m_lsMem.spuIndices[1],(ppu_address_t)&indexBasePtr[1], - &m_lsMem.spuIndices[2],(ppu_address_t)&indexBasePtr[2], - sizeof(int)); - } - - //spu_printf("SPU index0=%d ,",spuIndices[0]); - //spu_printf("SPU index1=%d ,",spuIndices[1]); - //spu_printf("SPU index2=%d ,",spuIndices[2]); - //spu_printf("SPU: indexBasePtr=%llx\n",indexBasePtr); - - const btVector3& meshScaling = m_lsMem.gBvhMeshShape.m_triangleMeshInterface->getScaling(); - for (int j=2;btLikely( j>=0 );j--) - { - int graphicsindex = m_lsMem.spuIndices[j]; - - //spu_printf("SPU index=%d ,",graphicsindex); - btScalar* graphicsbasePtr = (btScalar*)(m_lsMem.gBvhMeshShape.m_indexMesh.m_vertexBase+graphicsindex*m_lsMem.gBvhMeshShape.m_indexMesh.m_vertexStride); - //spu_printf("SPU graphicsbasePtr=%llx\n",graphicsbasePtr); - - - ///handle un-aligned vertices... - - //another DMA for each vertex - small_cache_read_triple(&spuUnscaledVertex[0],(ppu_address_t)&graphicsbasePtr[0], - &spuUnscaledVertex[1],(ppu_address_t)&graphicsbasePtr[1], - &spuUnscaledVertex[2],(ppu_address_t)&graphicsbasePtr[2], - sizeof(btScalar)); - - spuTriangleVertices[j] = btVector3( - spuUnscaledVertex[0]*meshScaling.getX(), - spuUnscaledVertex[1]*meshScaling.getY(), - spuUnscaledVertex[2]*meshScaling.getZ()); - - //spu_printf("SPU:triangle vertices:%f,%f,%f\n",spuTriangleVertices[j].x(),spuTriangleVertices[j].y(),spuTriangleVertices[j].z()); - } - - btTriangleShape tmpTriangleShape (spuTriangleVertices[0], spuTriangleVertices[1], spuTriangleVertices[2]); - - SpuCollisionPairInput triangleConcaveInput(m_collisionPairInput); - triangleConcaveInput.m_shapeType1 = TRIANGLE_SHAPE_PROXYTYPE; - m_spuContacts.setShapeIdentifiers(-1,-1,subPart,triangleIndex); - - //m_spuContacts.flush(); - - m_lsMem.gInternalShapes[2].m_collisionShape = &tmpTriangleShape; - m_lsMem.gInternalShapes[2].m_convexShape = &tmpTriangleShape; - - SpuConvexConvexCollisionAlgorithm (triangleConcaveInput, - m_lsMem, - m_spuContacts, - &m_lsMem.gInternalShapes[0], - &m_lsMem.gInternalShapes[2], - &m_lsMem.gInternalConvexHull[0], - NULL); - ///this flush should be automatic - //m_spuContacts.flush(); - } - -}; - -void SpuConvexConcaveCollisionAlgorithm (SpuCollisionPairInput& collisionPairInput, - CollisionTask_LocalStoreMemory& lsMem, - SpuContactResult &spuContacts, - SpuInternalShape* shape0Internal, - SpuInternalShape* shape1Internal, - SpuInternalConvexHull* shape0Points, - SpuInternalConvexHull* shape1Points) -{ - btConvexPointCloudShape shape0ConvexHull (NULL, 0, false); - btConvexShape* shape0; - -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("SpuConvexConcaveCollisionAlgorithm ()\n"); -#endif - if (collisionPairInput.m_shapeType0== CONVEX_HULL_SHAPE_PROXYTYPE ) - { - shape0ConvexHull.setPoints (shape0Points->m_points, shape0Points->m_numPoints, false); - { - btVector3 aabbMin, aabbMax; - btPolyhedralConvexShape* pcs = (btPolyhedralConvexShape*)shape0Internal->m_convexShape; - pcs->getCachedLocalAabb (aabbMin, aabbMax); - shape0ConvexHull.setCachedLocalAabb (aabbMin, aabbMax); - } - shape0 = &shape0ConvexHull; - } else { - shape0 = shape0Internal->m_convexShape; - } - - SpuBvhMeshShape* bvhShape = &lsMem.gBvhMeshShape; - - bvhShape->dmaMeshInterfaceAndOptimizedBvh (*shape1Internal, 1, 2); - cellDmaWaitTagStatusAll (DMA_MASK(1) | DMA_MASK(2)); - - // determine aabb of convex shape in triangle mesh - btVector3 aabbMin; - btVector3 aabbMax; - btTransform convexInTriangleSpace; - convexInTriangleSpace = collisionPairInput.m_worldTransform1.inverse() * collisionPairInput.m_worldTransform0; - shape0->getAabbNonVirtual (convexInTriangleSpace, aabbMin, aabbMax); - - // btScalar extraMargin = collisionMarginTriangle; - // btVector3 extra(extraMargin,extraMargin,extraMargin); - // aabbMax += extra; - // aabbMin -= extra; - - //quantize query AABB - unsigned short int quantizedQueryAabbMin[3]; - unsigned short int quantizedQueryAabbMax[3]; - bvhShape->m_optimizedBvh->quantizeWithClamp(quantizedQueryAabbMin,aabbMin,0); - bvhShape->m_optimizedBvh->quantizeWithClamp(quantizedQueryAabbMax,aabbMax,1); - - QuantizedNodeArray& nodeArray = bvhShape->m_optimizedBvh->getQuantizedNodeArray(); - //spu_printf("SPU: numNodes = %d\n",nodeArray.size()); - - BvhSubtreeInfoArray& subTrees = bvhShape->m_optimizedBvh->getSubtreeInfoArray(); - spuNodeCallback nodeCallback(collisionPairInput,lsMem,spuContacts); - IndexedMeshArray& indexArray = bvhShape->m_triangleMeshInterface->getIndexedMeshArray(); - //spu_printf("SPU:indexArray.size() = %d\n",indexArray.size()); - //spu_printf("SPU: numSubTrees = %d\n",subTrees.size()); - if (subTrees.size() && indexArray.size() == 1) - { - //DMA in the index info, we only support meshes with a single index (hence the '0') - bvhShape->dmaIndexedMesh (0, 1); - cellDmaWaitTagStatusAll(DMA_MASK(1)); - - //display the headers - int numBatch = subTrees.size(); - for (int i=0;idmaSubTreeHeaders ((ppu_address_t)(&subTrees[i]), nextBatch, 1); - cellDmaWaitTagStatusAll(DMA_MASK(1)); - - - // spu_printf("nextBatch = %d\n",nextBatch); - - for (int j=0;jm_subtreeHeaders[j]; - - unsigned int overlap = spuTestQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,subtree.m_quantizedAabbMin,subtree.m_quantizedAabbMax); - if (overlap) - { - btAssert(subtree.m_subtreeSize); - - //dma the actual nodes of this subtree - bvhShape->dmaSubTreeNodes (subtree, nodeArray, 2); - cellDmaWaitTagStatusAll(DMA_MASK(2)); - - /* Walk this subtree */ - spuWalkStacklessQuantizedTree(&nodeCallback, - quantizedQueryAabbMin, - quantizedQueryAabbMax, - &bvhShape->m_subtreeNodes[0], - 0,subtree.m_subtreeSize); - - } - // spu_printf("subtreeSize = %d\n",gSubtreeHeaders[j].m_subtreeSize); - } - i+=nextBatch; - } - //pre-fetch first tree, then loop and double buffer - } - -} void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTask_LocalStoreMemory& lsMem, SpuContactResult &spuContacts, - ppu_address_t collisionShape0Ptr, - ppu_address_t collisionShape1Ptr, bool dmaShapes = true) + ppu_address_t collisionShape0Ptr, void* collisionShape0Loc, + ppu_address_t collisionShape1Ptr, void* collisionShape1Loc, bool dmaShapes = true) { -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("handleCollisionPair ()\n"); -#endif + register int dmaSize; + register ppu_address_t dmaPpuAddress2; + if (btBroadphaseProxy::isConvex(collisionPairInput.m_shapeType0) && btBroadphaseProxy::isConvex(collisionPairInput.m_shapeType1)) { if (dmaShapes) { - /* Don't load the same shape twice. */ - if (collisionShape0Ptr != lsMem.gInternalShapes[0].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[0].dmaShapeData (collisionShape0Ptr, collisionPairInput.m_shapeType0, 1); - } - - /* Don't load the same shape twice. */ - if (collisionShape1Ptr != lsMem.gInternalShapes[1].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[1].dmaShapeData (collisionShape1Ptr, collisionPairInput.m_shapeType1, 2); - } - - if (collisionPairInput.m_shapeType0 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - btConvexHullShape* convexHull = (btConvexHullShape*)lsMem.gInternalShapes[0].m_convexShape; - cellDmaWaitTagStatusAll (DMA_MASK(1)); - /* Don't load the same verts twice */ - if ((ppu_address_t)convexHull->getPoints() != lsMem.gInternalConvexHull[0].m_ppuPointsPtr) - { - lsMem.gInternalConvexHull[0].dmaPointsData (lsMem.gInternalShapes[0], 1); - } - } - - if (collisionPairInput.m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - btConvexHullShape* convexHull = (btConvexHullShape*)lsMem.gInternalShapes[1].m_convexShape; - cellDmaWaitTagStatusAll (DMA_MASK(2)); - /* Don't load the same verts twice */ - if ((ppu_address_t)convexHull->getPoints() != lsMem.gInternalConvexHull[1].m_ppuPointsPtr) - { - lsMem.gInternalConvexHull[1].dmaPointsData (lsMem.gInternalShapes[1], 2); - } - } - + dmaCollisionShape (collisionShape0Loc, collisionShape0Ptr, 1, collisionPairInput.m_shapeType0); + dmaCollisionShape (collisionShape1Loc, collisionShape1Ptr, 2, collisionPairInput.m_shapeType1); cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); - -#if 0 - if (collisionPairInput.m_shapeType0 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - for (int i = 0; i < lsMem.gInternalConvexHull[0].m_numPoints; i++) - { - btVector3 vtx = lsMem.gInternalConvexHull[0].m_points[i]; - spu_printf("%d %f %f %f\n", i, vtx.getX(), vtx.getY(), vtx.getZ()); - } - } - - if (collisionPairInput.m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - for (int i = 0; i < lsMem.gInternalConvexHull[1].m_numPoints; i++) - { - btVector3 vtx = lsMem.gInternalConvexHull[1].m_points[i]; - spu_printf("%d %f %f %f\n", i, vtx.getX(), vtx.getY(), vtx.getZ()); - } - } -#endif } - SpuConvexConvexCollisionAlgorithm (collisionPairInput, lsMem, spuContacts, - &lsMem.gInternalShapes[0], - &lsMem.gInternalShapes[1], - &lsMem.gInternalConvexHull[0], - &lsMem.gInternalConvexHull[1]); + btConvexInternalShape* spuConvexShape0 = (btConvexInternalShape*)collisionShape0Loc; + btConvexInternalShape* spuConvexShape1 = (btConvexInternalShape*)collisionShape1Loc; + + btVector3 dim0 = spuConvexShape0->getImplicitShapeDimensions(); + btVector3 dim1 = spuConvexShape1->getImplicitShapeDimensions(); + + collisionPairInput.m_primitiveDimensions0 = dim0; + collisionPairInput.m_primitiveDimensions1 = dim1; + collisionPairInput.m_collisionShapes[0] = collisionShape0Ptr; + collisionPairInput.m_collisionShapes[1] = collisionShape1Ptr; + collisionPairInput.m_spuCollisionShapes[0] = spuConvexShape0; + collisionPairInput.m_spuCollisionShapes[1] = spuConvexShape1; + ProcessSpuConvexConvexCollision(&collisionPairInput,&lsMem,spuContacts); } else if (btBroadphaseProxy::isCompound(collisionPairInput.m_shapeType0) && btBroadphaseProxy::isCompound(collisionPairInput.m_shapeType1)) { //snPause(); - /* Don't load the same shape twice. */ - if (collisionShape0Ptr != lsMem.gInternalShapes[0].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[0].dmaShapeData (collisionShape0Ptr, collisionPairInput.m_shapeType0, 1); - } - - /* Don't load the same shape twice. */ - if (collisionShape1Ptr != lsMem.gInternalShapes[1].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[1].dmaShapeData (collisionShape1Ptr, collisionPairInput.m_shapeType1, 2); - } - + dmaCollisionShape (collisionShape0Loc, collisionShape0Ptr, 1, collisionPairInput.m_shapeType0); + dmaCollisionShape (collisionShape1Loc, collisionShape1Ptr, 2, collisionPairInput.m_shapeType1); cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); // Both are compounds, do N^2 CD for now // TODO: add some AABB-based pruning - btCompoundShape* spuCompoundShape0 = (btCompoundShape*)lsMem.gInternalShapes[0].m_collisionShape; - btCompoundShape* spuCompoundShape1 = (btCompoundShape*)lsMem.gInternalShapes[1].m_collisionShape; + btCompoundShape* spuCompoundShape0 = (btCompoundShape*)collisionShape0Loc; + btCompoundShape* spuCompoundShape1 = (btCompoundShape*)collisionShape1Loc; - lsMem.compoundShapeData[0].dmaChildShapeInfo (spuCompoundShape0, 1); - lsMem.compoundShapeData[1].dmaChildShapeInfo (spuCompoundShape1, 2); + dmaCompoundShapeInfo (&lsMem.compoundShapeData[0], spuCompoundShape0, 1); + dmaCompoundShapeInfo (&lsMem.compoundShapeData[1], spuCompoundShape1, 2); cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); + + + dmaCompoundSubShapes (&lsMem.compoundShapeData[0], spuCompoundShape0, 1); + cellDmaWaitTagStatusAll(DMA_MASK(1)); + dmaCompoundSubShapes (&lsMem.compoundShapeData[1], spuCompoundShape1, 1); + cellDmaWaitTagStatusAll(DMA_MASK(1)); int childShapeCount0 = spuCompoundShape0->getNumChildShapes(); int childShapeCount1 = spuCompoundShape1->getNumChildShapes(); @@ -794,13 +661,11 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas // Start the N^2 for (int i = 0; i < childShapeCount0; ++i) { - btCompoundShapeChild& childShape0 = lsMem.compoundShapeData[0].m_subshapes[i]; - // dma childshape0 into gInternalShapes 0 (this overwrites the original compound shape) - lsMem.compoundShapeData[0].dmaChildShape (i, &lsMem.gInternalShapes[0], &lsMem.gInternalConvexHull[0], 1); + btCompoundShapeChild& childShape0 = lsMem.compoundShapeData[0].gSubshapes[i]; + for (int j = 0; j < childShapeCount1; ++j) { - btCompoundShapeChild& childShape1 = lsMem.compoundShapeData[1].m_subshapes[j]; - lsMem.compoundShapeData[1].dmaChildShape (j, &lsMem.gInternalShapes[1], &lsMem.gInternalConvexHull[1], 2); + btCompoundShapeChild& childShape1 = lsMem.compoundShapeData[1].gSubshapes[j]; /* Create a new collision pair input struct using the two child shapes */ SpuCollisionPairInput cinput (collisionPairInput); @@ -812,121 +677,90 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas cinput.m_worldTransform1 = collisionPairInput.m_worldTransform1 * childShape1.m_transform; cinput.m_shapeType1 = childShape1.m_childShapeType; cinput.m_collisionMargin1 = childShape1.m_childMargin; - - cellDmaWaitTagStatusAll (DMA_MASK(1) | DMA_MASK(2)); - /* Recursively call handleCollisionPair () with new collision pair input */ handleCollisionPair(cinput, lsMem, spuContacts, - (ppu_address_t)childShape0.m_childShape, - (ppu_address_t)childShape1.m_childShape,false); // bug fix: changed index to j. + (ppu_address_t)childShape0.m_childShape, lsMem.compoundShapeData[0].gSubshapeShape[i], + (ppu_address_t)childShape1.m_childShape, lsMem.compoundShapeData[1].gSubshapeShape[j], false); // bug fix: changed index to j. } } } else if (btBroadphaseProxy::isCompound(collisionPairInput.m_shapeType0) ) { - /* Don't load the same shape twice. */ - if (collisionShape0Ptr != lsMem.gInternalShapes[0].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[0].dmaShapeData (collisionShape0Ptr, collisionPairInput.m_shapeType0, 1); - } - - /* Don't load the same shape twice. */ - if (collisionShape1Ptr != lsMem.gInternalShapes[1].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[1].dmaShapeData (collisionShape1Ptr, collisionPairInput.m_shapeType1, 2); - } - - if (collisionPairInput.m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - btConvexHullShape* convexHull = (btConvexHullShape*)lsMem.gInternalShapes[1].m_convexShape; - cellDmaWaitTagStatusAll (DMA_MASK(2)); - /* Don't load the same verts twice */ - if ((ppu_address_t)convexHull->getPoints() != lsMem.gInternalConvexHull[1].m_ppuPointsPtr) - { - lsMem.gInternalConvexHull[1].dmaPointsData (lsMem.gInternalShapes[1], 2); - } - } - - cellDmaWaitTagStatusAll (DMA_MASK(1)); - btCompoundShape* spuCompoundShape0 = (btCompoundShape*)lsMem.gInternalShapes[0].m_collisionShape; - lsMem.compoundShapeData[0].dmaChildShapeInfo (spuCompoundShape0, 1); + //snPause(); + + dmaCollisionShape (collisionShape0Loc, collisionShape0Ptr, 1, collisionPairInput.m_shapeType0); + dmaCollisionShape (collisionShape1Loc, collisionShape1Ptr, 2, collisionPairInput.m_shapeType1); cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); - int childShapeCount0 = spuCompoundShape0->getNumChildShapes(); - for (int i = 0; i < childShapeCount0; ++i) + // object 0 compound, object 1 non-compound + btCompoundShape* spuCompoundShape = (btCompoundShape*)collisionShape0Loc; + dmaCompoundShapeInfo (&lsMem.compoundShapeData[0], spuCompoundShape, 1); + cellDmaWaitTagStatusAll(DMA_MASK(1)); + + int childShapeCount = spuCompoundShape->getNumChildShapes(); + + for (int i = 0; i < childShapeCount; ++i) { - btCompoundShapeChild& childShape = lsMem.compoundShapeData[0].m_subshapes[i]; + btCompoundShapeChild& childShape = lsMem.compoundShapeData[0].gSubshapes[i]; - lsMem.compoundShapeData[0].dmaChildShape (i, &lsMem.gInternalShapes[0], &lsMem.gInternalConvexHull[0], 1); + // Dma the child shape + dmaCollisionShape (&lsMem.compoundShapeData[0].gSubshapeShape[i], (ppu_address_t)childShape.m_childShape, 1, childShape.m_childShapeType); + cellDmaWaitTagStatusAll(DMA_MASK(1)); + SpuCollisionPairInput cinput (collisionPairInput); cinput.m_worldTransform0 = collisionPairInput.m_worldTransform0 * childShape.m_transform; cinput.m_shapeType0 = childShape.m_childShapeType; cinput.m_collisionMargin0 = childShape.m_childMargin; - cellDmaWaitTagStatusAll(DMA_MASK(1)); - - handleCollisionPair(cinput, - lsMem, - spuContacts, - (ppu_address_t)childShape.m_childShape, - collisionShape1Ptr, false); + handleCollisionPair(cinput, lsMem, spuContacts, + (ppu_address_t)childShape.m_childShape, lsMem.compoundShapeData[0].gSubshapeShape[i], + collisionShape1Ptr, collisionShape1Loc, false); } } else if (btBroadphaseProxy::isCompound(collisionPairInput.m_shapeType1) ) { //snPause(); - - /* Don't load the same shape twice. */ - if (collisionShape0Ptr != lsMem.gInternalShapes[0].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[0].dmaShapeData (collisionShape0Ptr, collisionPairInput.m_shapeType0, 1); - } - - /* Don't load the same shape twice. */ - if (collisionShape1Ptr != lsMem.gInternalShapes[1].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[1].dmaShapeData (collisionShape1Ptr, collisionPairInput.m_shapeType1, 2); - } - + + dmaCollisionShape (collisionShape0Loc, collisionShape0Ptr, 1, collisionPairInput.m_shapeType0); + dmaCollisionShape (collisionShape1Loc, collisionShape1Ptr, 2, collisionPairInput.m_shapeType1); cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); - // object 0 non-compound, object 1 compound - btCompoundShape* spuCompoundShape = (btCompoundShape*)lsMem.gInternalShapes[1].m_collisionShape; - lsMem.compoundShapeData[1].dmaChildShapeInfo (spuCompoundShape, 1); + btCompoundShape* spuCompoundShape = (btCompoundShape*)collisionShape1Loc; + dmaCompoundShapeInfo (&lsMem.compoundShapeData[0], spuCompoundShape, 1); cellDmaWaitTagStatusAll(DMA_MASK(1)); int childShapeCount = spuCompoundShape->getNumChildShapes(); + for (int i = 0; i < childShapeCount; ++i) { - btCompoundShapeChild& childShape = lsMem.compoundShapeData[1].m_subshapes[i]; + btCompoundShapeChild& childShape = lsMem.compoundShapeData[0].gSubshapes[i]; // Dma the child shape - lsMem.compoundShapeData[1].dmaChildShape (i, &lsMem.gInternalShapes[1], &lsMem.gInternalConvexHull[1], 1); + dmaCollisionShape (&lsMem.compoundShapeData[0].gSubshapeShape[i], (ppu_address_t)childShape.m_childShape, 1, childShape.m_childShapeType); cellDmaWaitTagStatusAll(DMA_MASK(1)); SpuCollisionPairInput cinput (collisionPairInput); cinput.m_worldTransform1 = collisionPairInput.m_worldTransform1 * childShape.m_transform; cinput.m_shapeType1 = childShape.m_childShapeType; cinput.m_collisionMargin1 = childShape.m_childMargin; - handleCollisionPair(cinput, - lsMem, - spuContacts, - collisionShape0Ptr, - (ppu_address_t)childShape.m_childShape, false); + handleCollisionPair(cinput, lsMem, spuContacts, + collisionShape0Ptr, collisionShape0Loc, + (ppu_address_t)childShape.m_childShape, lsMem.compoundShapeData[0].gSubshapeShape[i], false); } + } else { - //we only support convex v. concave //a non-convex shape is involved bool handleConvexConcave = false; - //concave v. convex - //swap into convex v. concave + //snPause(); + if (btBroadphaseProxy::isConcave(collisionPairInput.m_shapeType0) && btBroadphaseProxy::isConvex(collisionPairInput.m_shapeType1)) { // Swap stuff DoSwap(collisionShape0Ptr, collisionShape1Ptr); + DoSwap(collisionShape0Loc, collisionShape1Loc); DoSwap(collisionPairInput.m_shapeType0, collisionPairInput.m_shapeType1); DoSwap(collisionPairInput.m_worldTransform0, collisionPairInput.m_worldTransform1); DoSwap(collisionPairInput.m_collisionMargin0, collisionPairInput.m_collisionMargin1); @@ -943,54 +777,24 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas { if (dmaShapes) { - /* Don't load the same shape twice. */ - if (collisionShape0Ptr != lsMem.gInternalShapes[0].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[0].dmaShapeData (collisionShape0Ptr, collisionPairInput.m_shapeType0, 1); - } - - /* Don't load the same shape twice. */ - if (collisionShape1Ptr != lsMem.gInternalShapes[1].m_ppuConvexShapePtr) - { - lsMem.gInternalShapes[1].dmaShapeData (collisionShape1Ptr, collisionPairInput.m_shapeType1, 2); - } - - if (collisionPairInput.m_shapeType0 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - btConvexHullShape* convexHull = (btConvexHullShape*)lsMem.gInternalShapes[0].m_convexShape; - cellDmaWaitTagStatusAll (DMA_MASK(1)); - /* Don't load the same verts twice */ - if ((ppu_address_t)convexHull->getPoints() != lsMem.gInternalConvexHull[0].m_ppuPointsPtr) - { - lsMem.gInternalConvexHull[0].dmaPointsData (lsMem.gInternalShapes[0], 1); - } - } - - /* This can't happen because shape1 is the optimized Bvh shape */ -#if 0 - if (collisionPairInput.m_shapeType1 == CONVEX_HULL_SHAPE_PROXYTYPE) - { - btConvexHullShape* convexHull = (btConvexHullShape*)lsMem.gInternalShapes[1].m_convexShape; - cellDmaWaitTagStatusAll (DMA_MASK(2)); - /* Don't load the same verts twice */ - if ((ppu_address_t)convexHull->getPoints() != lsMem.gInternalConvexHull[1].m_ppuPointsPtr) - { - lsMem.gInternalConvexHull[1].dmaPointsData (lsMem.gInternalShapes[1], 2); - } - } -#endif - + dmaCollisionShape (collisionShape0Loc, collisionShape0Ptr, 1, collisionPairInput.m_shapeType0); + dmaCollisionShape (collisionShape1Loc, collisionShape1Ptr, 2, collisionPairInput.m_shapeType1); cellDmaWaitTagStatusAll(DMA_MASK(1) | DMA_MASK(2)); } - SpuConvexConcaveCollisionAlgorithm (collisionPairInput, - lsMem, - spuContacts, - &lsMem.gInternalShapes[0], - &lsMem.gInternalShapes[1], - &lsMem.gInternalConvexHull[0], - &lsMem.gInternalConvexHull[1]); + btConvexInternalShape* spuConvexShape0 = (btConvexInternalShape*)collisionShape0Loc; + btBvhTriangleMeshShape* trimeshShape = (btBvhTriangleMeshShape*)collisionShape1Loc; + + btVector3 dim0 = spuConvexShape0->getImplicitShapeDimensions(); + collisionPairInput.m_primitiveDimensions0 = dim0; + collisionPairInput.m_collisionShapes[0] = collisionShape0Ptr; + collisionPairInput.m_collisionShapes[1] = collisionShape1Ptr; + collisionPairInput.m_spuCollisionShapes[0] = spuConvexShape0; + collisionPairInput.m_spuCollisionShapes[1] = trimeshShape; + + ProcessConvexConcaveSpuCollision(&collisionPairInput,&lsMem,spuContacts); } + } spuContacts.flush(); @@ -999,6 +803,7 @@ void handleCollisionPair(SpuCollisionPairInput& collisionPairInput, CollisionTas void processCollisionTask(void* userPtr, void* lsMemPtr) { + SpuGatherAndProcessPairsTaskDesc* taskDescPtr = (SpuGatherAndProcessPairsTaskDesc*)userPtr; SpuGatherAndProcessPairsTaskDesc& taskDesc = *taskDescPtr; CollisionTask_LocalStoreMemory* colMemPtr = (CollisionTask_LocalStoreMemory*)lsMemPtr; @@ -1039,10 +844,14 @@ void processCollisionTask(void* userPtr, void* lsMemPtr) for (unsigned int i = 0; btLikely(i < numPages); i++) { + // wait for back buffer dma and swap buffers inputPtr = lsMem.g_workUnitTaskBuffers.swapBuffers(); + // number on current page is number prefetched last iteration numOnPage = nextNumOnPage; + + // prefetch next set of inputs #if MIDPHASE_NUM_WORKUNIT_PAGES > 2 if ( btLikely( i < numPages-1 ) ) @@ -1056,26 +865,31 @@ void processCollisionTask(void* userPtr, void* lsMemPtr) } wuInputs = reinterpret_cast(inputPtr); + + for (j = 0; btLikely( j < numOnPage ); j++) { #ifdef DEBUG_SPU_COLLISION_DETECTION // printMidphaseInput(&wuInputs[j]); #endif //DEBUG_SPU_COLLISION_DETECTION + + numPairs = wuInputs[j].m_endIndex - wuInputs[j].m_startIndex; + if ( btLikely( numPairs ) ) { - // DMA: broadphase pairs - dmaSize = numPairs*sizeof(btBroadphasePair); - dmaPpuAddress = wuInputs[j].m_pairArrayPtr+wuInputs[j].m_startIndex * sizeof(btBroadphasePair); - cellDmaGet(&lsMem.gBroadphasePairs, dmaPpuAddress , dmaSize, DMA_TAG(1), 0, 0); - cellDmaWaitTagStatusAll(DMA_MASK(1)); + dmaSize = numPairs*sizeof(btBroadphasePair); + dmaPpuAddress = wuInputs[j].m_pairArrayPtr+wuInputs[j].m_startIndex * sizeof(btBroadphasePair); + cellDmaGet(&lsMem.gBroadphasePairs, dmaPpuAddress , dmaSize, DMA_TAG(1), 0, 0); + cellDmaWaitTagStatusAll(DMA_MASK(1)); + - //for each broadphase pair, do something for (p=0;pm_userInfo = %d\n",pair.m_userInfo); spu_printf("pair->m_algorithm = %d\n",pair.m_algorithm); @@ -1085,82 +899,102 @@ void processCollisionTask(void* userPtr, void* lsMemPtr) userInfo = int(pair.m_userInfo); - // skip pairs we don't support - if (!pair.m_algorithm || !pair.m_pProxy0 || - !pair.m_pProxy1 || userInfo != 2) - continue; - - - // DMA: SpuContactManifoldCollisionAlgorithm - // SpuContactManifoldCollisionAlgorithm: - // A dummy collision algorithm that gives us the - // collision types, and contact manifold pointers - dmaSize = sizeof(SpuContactManifoldCollisionAlgorithm); - dmaPpuAddress2 = (ppu_address_t)pair.m_algorithm; - cellDmaGet(&lsMem.gSpuContactManifoldAlgo, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); - //cellDmaWaitTagStatusAll(DMA_MASK(1)); - - //snPause(); - -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("SPU: manifoldPtr: %llx",collisionPairInput.m_persistentManifoldPtr); -#endif //DEBUG_SPU_COLLISION_DETECTION - - - // DMA: btBroadphaseProxy for object 0 - dmaSize = sizeof(btBroadphaseProxy); - dmaPpuAddress2 = (ppu_address_t)pair.m_pProxy0; - lsMem.gProxyPtr0 = (btBroadphaseProxy*) lsMem.bufferProxy0; - stallingUnalignedDmaSmallGet(lsMem.gProxyPtr0, dmaPpuAddress2 , dmaSize); - // NOTE: The DMA initiated for SpuContactManifoldCollisionAlgorithm is synced in - // stallingUnalignedDmaSmallGet - collisionPairInput.m_persistentManifoldPtr = (ppu_address_t) lsMem.gSpuContactManifoldAlgo.getContactManifoldPtr(); - collisionPairInput.m_isSwapped = false; - - // DMA: btPersistentManifold - dmaSize = sizeof(btPersistentManifold); - dmaPpuAddress2 = collisionPairInput.m_persistentManifoldPtr; - cellDmaGet(&lsMem.gPersistentManifold, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); - - // DMA: btBroadphaseProxy for object 0 - dmaSize = sizeof(btBroadphaseProxy); - dmaPpuAddress2 = (ppu_address_t)pair.m_pProxy1; - lsMem.gProxyPtr1 = (btBroadphaseProxy*) lsMem.bufferProxy1; - stallingUnalignedDmaSmallGet(lsMem.gProxyPtr1, dmaPpuAddress2 , dmaSize); - // NOTE: The DMA initiated for btPersistentManifold is synced in - // stallingUnalignedDmaSmallGet - -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("SPU collisionPairInput->m_shapeType0 = %d\n",collisionPairInput.m_shapeType0); - spu_printf("SPU collisionPairInput->m_shapeType1 = %d\n",collisionPairInput.m_shapeType1); -#endif //DEBUG_SPU_COLLISION_DETECTION - - // Construct the collision Pair - collisionPairInput.m_shapeType0 = lsMem.gSpuContactManifoldAlgo.getShapeType0(); - collisionPairInput.m_shapeType1 = lsMem.gSpuContactManifoldAlgo.getShapeType1(); - collisionPairInput.m_collisionMargin0 = lsMem.gSpuContactManifoldAlgo.getCollisionMargin0(); - collisionPairInput.m_collisionMargin1 = lsMem.gSpuContactManifoldAlgo.getCollisionMargin1(); - - cellDmaWaitTagStatusAll(DMA_MASK(1)); // might not be necessary - dmaAndSetupCollisionObjects(collisionPairInput, lsMem); - - if (lsMem.getColObj0()->isActive() || lsMem.getColObj1()->isActive()) + if (userInfo == 2 && pair.m_algorithm && pair.m_pProxy0 && pair.m_pProxy1) { - handleCollisionPair(collisionPairInput, - lsMem, - spuContacts, - (ppu_address_t)lsMem.getColObj0()->getCollisionShape(), - (ppu_address_t)lsMem.getColObj1()->getCollisionShape()); + + + dmaSize = sizeof(SpuContactManifoldCollisionAlgorithm); + + dmaPpuAddress2 = (ppu_address_t)pair.m_algorithm; + + cellDmaGet(&lsMem.gSpuContactManifoldAlgo, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); + //cellDmaWaitTagStatusAll(DMA_MASK(1)); + + + + + //snPause(); + +#ifdef DEBUG_SPU_COLLISION_DETECTION + //spu_printf("SPU: manifoldPtr: %llx",collisionPairInput->m_persistentManifoldPtr); +#endif //DEBUG_SPU_COLLISION_DETECTION + + + dmaSize = sizeof(btBroadphaseProxy); + + dmaPpuAddress2 = (ppu_address_t)pair.m_pProxy0; + + lsMem.gProxyPtr0 = (btBroadphaseProxy*) lsMem.bufferProxy0; + stallingUnalignedDmaSmallGet(lsMem.gProxyPtr0, dmaPpuAddress2 , dmaSize); + + collisionPairInput.m_persistentManifoldPtr = (ppu_address_t) lsMem.gSpuContactManifoldAlgo.getContactManifoldPtr(); + collisionPairInput.m_isSwapped = false; + + + dmaSize = sizeof(btBroadphaseProxy); + + dmaPpuAddress2 = (ppu_address_t)pair.m_pProxy1; + + lsMem.gProxyPtr1 = (btBroadphaseProxy*) lsMem.bufferProxy1; + stallingUnalignedDmaSmallGet(lsMem.gProxyPtr1, dmaPpuAddress2 , dmaSize); + + + //btCollisionObject* colObj0 = (btCollisionObject*)gProxy0.m_clientObject; + //btCollisionObject* colObj1 = (btCollisionObject*)gProxy1.m_clientObject; + + + if (1) + { + + ///can wait on the combined DMA_MASK, or dma on the same tag + + +#ifdef DEBUG_SPU_COLLISION_DETECTION + // spu_printf("SPU collisionPairInput->m_shapeType0 = %d\n",collisionPairInput->m_shapeType0); + // spu_printf("SPU collisionPairInput->m_shapeType1 = %d\n",collisionPairInput->m_shapeType1); +#endif //DEBUG_SPU_COLLISION_DETECTION + + + dmaSize = sizeof(btPersistentManifold); + + dmaPpuAddress2 = collisionPairInput.m_persistentManifoldPtr; + cellDmaGet(&lsMem.gPersistentManifold, dmaPpuAddress2 , dmaSize, DMA_TAG(1), 0, 0); + + collisionPairInput.m_shapeType0 = lsMem.gSpuContactManifoldAlgo.getShapeType0(); + collisionPairInput.m_shapeType1 = lsMem.gSpuContactManifoldAlgo.getShapeType1(); + collisionPairInput.m_collisionMargin0 = lsMem.gSpuContactManifoldAlgo.getCollisionMargin0(); + collisionPairInput.m_collisionMargin1 = lsMem.gSpuContactManifoldAlgo.getCollisionMargin1(); + + + + cellDmaWaitTagStatusAll(DMA_MASK(1)); + + + if (1) + { + //snPause(); + + // Get the collision objects + dmaAndSetupCollisionObjects(collisionPairInput, lsMem); + + if (lsMem.getColObj0()->isActive() || lsMem.getColObj1()->isActive()) + { + handleCollisionPair(collisionPairInput, lsMem, spuContacts, + (ppu_address_t)lsMem.getColObj0()->getCollisionShape(), &lsMem.gCollisionShapes[0].collisionShape, + (ppu_address_t)lsMem.getColObj1()->getCollisionShape(), &lsMem.gCollisionShapes[1].collisionShape); + } + + } + } + } } } } //end for (j = 0; j < numOnPage; j++) + }// for -#ifdef DEBUG_SPU_COLLISION_DETECTION - spu_printf("processCollisionTask %d / %d\n",numPages, numOnLastPage); -#endif //DEBUG_SPU_COLLISION_DETECTION return; } diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.cpp index fd52dc753..4d6d6d92e 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.cpp @@ -36,7 +36,7 @@ int gSpuNumGjkChecks = 0; -SpuGjkPairDetector::SpuGjkPairDetector(void* objectA,void* objectB,int shapeTypeA, int shapeTypeB, float marginA,float marginB,btVoronoiSimplexSolver* simplexSolver, const SpuConvexPenetrationDepthSolver* penetrationDepthSolver) +SpuGjkPairDetector::SpuGjkPairDetector(void* objectA,void* objectB,int shapeTypeA, int shapeTypeB, float marginA,float marginB,SpuVoronoiSimplexSolver* simplexSolver, const SpuConvexPenetrationDepthSolver* penetrationDepthSolver) :m_cachedSeparatingAxis(float(0.),float(0.),float(1.)), m_penetrationDepthSolver(penetrationDepthSolver), m_simplexSolver(simplexSolver), diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.h index 42b782306..449c13946 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGjkPairDetector.h @@ -24,15 +24,18 @@ subject to the following restrictions: #include "SpuContactResult.h" -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" + +#include "SpuVoronoiSimplexSolver.h" class SpuConvexPenetrationDepthSolver; /// btGjkPairDetector uses GJK to implement the btDiscreteCollisionDetectorInterface class SpuGjkPairDetector { + + btVector3 m_cachedSeparatingAxis; const SpuConvexPenetrationDepthSolver* m_penetrationDepthSolver; - btVoronoiSimplexSolver* m_simplexSolver; + SpuVoronoiSimplexSolver* m_simplexSolver; void* m_minkowskiA; void* m_minkowskiB; int m_shapeTypeA; @@ -51,7 +54,7 @@ public: int m_catchDegeneracies; - SpuGjkPairDetector(void* objectA,void* objectB,int m_shapeTypeA, int m_shapeTypeB, float marginA, float marginB, btVoronoiSimplexSolver* simplexSolver, const SpuConvexPenetrationDepthSolver* penetrationDepthSolver); + SpuGjkPairDetector(void* objectA,void* objectB,int m_shapeTypeA, int m_shapeTypeB, float marginA, float marginB, SpuVoronoiSimplexSolver* simplexSolver, const SpuConvexPenetrationDepthSolver* penetrationDepthSolver); virtual ~SpuGjkPairDetector() {}; virtual void getClosestPoints(const SpuClosestPointInput& input,SpuContactResult& output); diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.cpp b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.cpp index 13c39dc90..6ec94bdff 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.cpp +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.cpp @@ -13,15 +13,15 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" -#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" - -#include "SpuCollisionShapes.h" #include "SpuMinkowskiPenetrationDepthSolver.h" +#include "SpuVoronoiSimplexSolver.h" +#include "SpuGjkPairDetector.h" #include "SpuContactResult.h" #include "SpuPreferredPenetrationDirections.h" +#include "SpuCollisionShapes.h" + #define NUM_UNITSPHERE_POINTS 42 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = { @@ -69,7 +69,7 @@ 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, +bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( SpuVoronoiSimplexSolver& simplexSolver, void* convexA,void* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB, btTransform& transA,const btTransform& transB, btVector3& v, btPoint3& pa, btPoint3& pb, @@ -113,7 +113,7 @@ bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( btVoronoiSimplexSolver& s //just take fixed number of orientation, and sample the penetration depth in that direction btScalar minProj = btScalar(1e30); - btVector3 minNorm = btVector3(btScalar(0.0f), btScalar(0.0f), btScalar(0.0f)); + btVector3 minNorm; btVector3 minVertex; btVector3 minA,minB; btVector3 seperatingAxisInA,seperatingAxisInB; @@ -291,8 +291,7 @@ bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( btVoronoiSimplexSolver& s } #endif //DEBUG_DRAW - return false; -#if 0 //FIXME + SpuGjkPairDetector gjkdet(convexA,convexB,shapeTypeA,shapeTypeB,marginA,marginB,&simplexSolver,0); @@ -342,7 +341,6 @@ bool SpuMinkowskiPenetrationDepthSolver::calcPenDepth( btVoronoiSimplexSolver& s btAssert (false); } return res.m_hasResult; -#endif } diff --git a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.h b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.h index 331733c24..6193741ae 100644 --- a/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.h +++ b/Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuMinkowskiPenetrationDepthSolver.h @@ -22,7 +22,7 @@ subject to the following restrictions: class btStackAlloc; class btIDebugDraw; -class btVoronoiSimplexSolver; +class SpuVoronoiSimplexSolver; ///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. @@ -30,7 +30,7 @@ class SpuMinkowskiPenetrationDepthSolver : public SpuConvexPenetrationDepthSolve { public: - virtual bool calcPenDepth( btVoronoiSimplexSolver& simplexSolver, + virtual bool calcPenDepth( SpuVoronoiSimplexSolver& simplexSolver, void* convexA,void* convexB,int shapeTypeA, int shapeTypeB, float marginA, float marginB, btTransform& transA,const btTransform& transB, btVector3& v, btPoint3& pa, btPoint3& pb, diff --git a/Extras/BulletMultiThreaded/SpuRaycastTask/SpuRaycastTask.cpp b/Extras/BulletMultiThreaded/SpuRaycastTask/SpuRaycastTask.cpp index 7cdd1f2b5..49b8827a2 100644 --- a/Extras/BulletMultiThreaded/SpuRaycastTask/SpuRaycastTask.cpp +++ b/Extras/BulletMultiThreaded/SpuRaycastTask/SpuRaycastTask.cpp @@ -632,7 +632,7 @@ void performRaycastAgainstCompound (RaycastGatheredObjectData* gatheredObjectDat void performRaycastAgainstConvex (RaycastGatheredObjectData* gatheredObjectData, const SpuRaycastTaskWorkUnit& workUnit, SpuRaycastTaskWorkUnitOut* workUnitOut, RaycastTask_LocalStoreMemory* lsMemPtr) { - btVoronoiSimplexSolver simplexSolver; + SpuVoronoiSimplexSolver simplexSolver; btTransform rayFromTrans, rayToTrans; rayFromTrans.setIdentity (); diff --git a/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.cpp b/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.cpp index 1869f18d6..1cd2e983e 100644 --- a/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.cpp +++ b/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.cpp @@ -22,7 +22,7 @@ subject to the following restrictions: SpuSubsimplexRayCast::SpuSubsimplexRayCast (void* shapeB, SpuConvexPolyhedronVertexData* convexDataB, int shapeTypeB, float marginB, - btVoronoiSimplexSolver* simplexSolver) + SpuVoronoiSimplexSolver* simplexSolver) :m_simplexSolver(simplexSolver), m_shapeB(shapeB), m_convexDataB(convexDataB), m_shapeTypeB(shapeTypeB), m_marginB(marginB) { } diff --git a/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.h b/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.h index 9ceaef89b..23b6899b4 100644 --- a/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.h +++ b/Extras/BulletMultiThreaded/SpuRaycastTask/SpuSubSimplexConvexCast.h @@ -17,7 +17,7 @@ subject to the following restrictions: #ifndef SPU_SUBSIMPLEX_RAY_CAST_H #define SPU_SUBSIMPLEX_RAY_CAST_H -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" +#include "../SpuNarrowPhaseCollisionTask/SpuVoronoiSimplexSolver.h" #include "../SpuNarrowPhaseCollisionTask/SpuCollisionShapes.h" #include "SpuRaycastTask.h" @@ -35,7 +35,7 @@ struct SpuCastResult /// Objects should not start in overlap, otherwise results are not defined. class SpuSubsimplexRayCast { - btVoronoiSimplexSolver* m_simplexSolver; + SpuVoronoiSimplexSolver* m_simplexSolver; void* m_shapeB; SpuConvexPolyhedronVertexData* m_convexDataB; int m_shapeTypeB; @@ -43,7 +43,7 @@ class SpuSubsimplexRayCast public: SpuSubsimplexRayCast (void* shapeB, SpuConvexPolyhedronVertexData* convexDataB, int shapeTypeB, float marginB, - btVoronoiSimplexSolver* simplexSolver); + SpuVoronoiSimplexSolver* simplexSolver); //virtual ~btSubsimplexConvexCast();