SpuCollisionShapes.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef __SPU_COLLISION_SHAPES_H
  14. #define __SPU_COLLISION_SHAPES_H
  15. #include "../SpuDoubleBuffer.h"
  16. #include "bullet/BulletCollision//BroadphaseCollision/btBroadphaseProxy.h"
  17. #include "bullet/BulletCollision//CollisionShapes/btConvexInternalShape.h"
  18. #include "bullet/BulletCollision//CollisionShapes/btCylinderShape.h"
  19. #include "bullet/BulletCollision//CollisionShapes/btStaticPlaneShape.h"
  20. #include "bullet/BulletCollision//CollisionShapes/btOptimizedBvh.h"
  21. #include "bullet/BulletCollision//CollisionShapes/btTriangleIndexVertexArray.h"
  22. #include "bullet/BulletCollision//CollisionShapes/btSphereShape.h"
  23. #include "bullet/BulletCollision//CollisionShapes/btCapsuleShape.h"
  24. #include "bullet/BulletCollision//CollisionShapes/btConvexShape.h"
  25. #include "bullet/BulletCollision//CollisionShapes/btBvhTriangleMeshShape.h"
  26. #include "bullet/BulletCollision//CollisionShapes/btConvexHullShape.h"
  27. #include "bullet/BulletCollision//CollisionShapes/btCompoundShape.h"
  28. #define MAX_NUM_SPU_CONVEX_POINTS 128 //@fallback to PPU if a btConvexHullShape has more than MAX_NUM_SPU_CONVEX_POINTS points
  29. #define MAX_SPU_COMPOUND_SUBSHAPES 16 //@fallback on PPU if compound has more than MAX_SPU_COMPOUND_SUBSHAPES child shapes
  30. #define MAX_SHAPE_SIZE 256 //@todo: assert on this
  31. ATTRIBUTE_ALIGNED16(struct) SpuConvexPolyhedronVertexData
  32. {
  33. void* gSpuConvexShapePtr;
  34. btVector3* gConvexPoints;
  35. int gNumConvexPoints;
  36. int unused;
  37. ATTRIBUTE_ALIGNED16(btVector3 g_convexPointBuffer[MAX_NUM_SPU_CONVEX_POINTS]);
  38. };
  39. ATTRIBUTE_ALIGNED16(struct) CollisionShape_LocalStoreMemory
  40. {
  41. ATTRIBUTE_ALIGNED16(char collisionShape[MAX_SHAPE_SIZE]);
  42. };
  43. ATTRIBUTE_ALIGNED16(struct) CompoundShape_LocalStoreMemory
  44. {
  45. // Compound data
  46. ATTRIBUTE_ALIGNED16(btCompoundShapeChild gSubshapes[MAX_SPU_COMPOUND_SUBSHAPES]);
  47. ATTRIBUTE_ALIGNED16(char gSubshapeShape[MAX_SPU_COMPOUND_SUBSHAPES][MAX_SHAPE_SIZE]);
  48. };
  49. ATTRIBUTE_ALIGNED16(struct) bvhMeshShape_LocalStoreMemory
  50. {
  51. //ATTRIBUTE_ALIGNED16(btOptimizedBvh gOptimizedBvh);
  52. ATTRIBUTE_ALIGNED16(char gOptimizedBvh[sizeof(btOptimizedBvh)+16]);
  53. btOptimizedBvh* getOptimizedBvh()
  54. {
  55. return (btOptimizedBvh*) gOptimizedBvh;
  56. }
  57. ATTRIBUTE_ALIGNED16(btTriangleIndexVertexArray gTriangleMeshInterfaceStorage);
  58. btTriangleIndexVertexArray* gTriangleMeshInterfacePtr;
  59. ///only a single mesh part for now, we can add support for multiple parts, but quantized trees don't support this at the moment
  60. ATTRIBUTE_ALIGNED16(btIndexedMesh gIndexMesh);
  61. #define MAX_SPU_SUBTREE_HEADERS 32
  62. //1024
  63. ATTRIBUTE_ALIGNED16(btBvhSubtreeInfo gSubtreeHeaders[MAX_SPU_SUBTREE_HEADERS]);
  64. ATTRIBUTE_ALIGNED16(btQuantizedBvhNode gSubtreeNodes[MAX_SUBTREE_SIZE_IN_BYTES/sizeof(btQuantizedBvhNode)]);
  65. };
  66. void computeAabb (btVector3& aabbMin, btVector3& aabbMax, btConvexInternalShape* convexShape, ppu_address_t convexShapePtr, int shapeType, const btTransform& xform);
  67. void dmaBvhShapeData (bvhMeshShape_LocalStoreMemory* bvhMeshShape, btBvhTriangleMeshShape* triMeshShape);
  68. void dmaBvhIndexedMesh (btIndexedMesh* IndexMesh, IndexedMeshArray& indexArray, int index, uint32_t dmaTag);
  69. void dmaBvhSubTreeHeaders (btBvhSubtreeInfo* subTreeHeaders, ppu_address_t subTreePtr, int batchSize, uint32_t dmaTag);
  70. void dmaBvhSubTreeNodes (btQuantizedBvhNode* nodes, const btBvhSubtreeInfo& subtree, QuantizedNodeArray& nodeArray, int dmaTag);
  71. int getShapeTypeSize(int shapeType);
  72. void dmaConvexVertexData (SpuConvexPolyhedronVertexData* convexVertexData, btConvexHullShape* convexShapeSPU);
  73. void dmaCollisionShape (void* collisionShapeLocation, ppu_address_t collisionShapePtr, uint32_t dmaTag, int shapeType);
  74. void dmaCompoundShapeInfo (CompoundShape_LocalStoreMemory* compoundShapeLocation, btCompoundShape* spuCompoundShape, uint32_t dmaTag);
  75. void dmaCompoundSubShapes (CompoundShape_LocalStoreMemory* compoundShapeLocation, btCompoundShape* spuCompoundShape, uint32_t dmaTag);
  76. #define USE_BRANCHFREE_TEST 1
  77. #ifdef USE_BRANCHFREE_TEST
  78. SIMD_FORCE_INLINE unsigned int spuTestQuantizedAabbAgainstQuantizedAabb(unsigned short int* aabbMin1,unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
  79. {
  80. #if defined(__CELLOS_LV2__) && defined (__SPU__)
  81. vec_ushort8 vecMin = {aabbMin1[0],aabbMin2[0],aabbMin1[2],aabbMin2[2],aabbMin1[1],aabbMin2[1],0,0};
  82. vec_ushort8 vecMax = {aabbMax2[0],aabbMax1[0],aabbMax2[2],aabbMax1[2],aabbMax2[1],aabbMax1[1],0,0};
  83. vec_ushort8 isGt = spu_cmpgt(vecMin,vecMax);
  84. return spu_extract(spu_gather(isGt),0)==0;
  85. #else
  86. return btSelect((unsigned)((aabbMin1[0] <= aabbMax2[0]) & (aabbMax1[0] >= aabbMin2[0])
  87. & (aabbMin1[2] <= aabbMax2[2]) & (aabbMax1[2] >= aabbMin2[2])
  88. & (aabbMin1[1] <= aabbMax2[1]) & (aabbMax1[1] >= aabbMin2[1])),
  89. 1, 0);
  90. #endif
  91. }
  92. #else
  93. SIMD_FORCE_INLINE unsigned int spuTestQuantizedAabbAgainstQuantizedAabb(const unsigned short int* aabbMin1,const unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2)
  94. {
  95. unsigned int overlap = 1;
  96. overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? 0 : overlap;
  97. overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? 0 : overlap;
  98. overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? 0 : overlap;
  99. return overlap;
  100. }
  101. #endif
  102. void spuWalkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,const btQuantizedBvhNode* rootNode,int startNodeIndex,int endNodeIndex);
  103. #endif