Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CUDA / btCudaBroadphase.h
1 /*
2 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
3 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. 
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose, 
8 including commercial applications, and to alter it and redistribute it freely, 
9 subject to the following restrictions:
10
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16
17
18 #ifndef CUDA_BROADPHASE_H
19 #define CUDA_BROADPHASE_H
20
21
22
23 #include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
24
25 #include "../../src/BulletMultiThreaded/btGpu3DGridBroadphaseSharedTypes.h"
26 #include "../../src/BulletMultiThreaded/btGpu3DGridBroadphase.h"
27
28
29
30 ///The btCudaBroadphase uses CUDA-capable GPU to compute overlapping pairs
31
32 class btCudaBroadphase : public btGpu3DGridBroadphase
33 {
34 protected:
35     // GPU data
36     unsigned int*       m_dBodiesHash[2];
37     unsigned int*       m_dCellStart;
38         unsigned int*   m_dPairBuff; 
39         unsigned int*   m_dPairBuffStartCurr;
40         bt3DGrid3F1U*           m_dAABB;
41         unsigned int*   m_dPairScan;
42         unsigned int*   m_dPairOut;
43 public:
44         btCudaBroadphase(       btOverlappingPairCache* overlappingPairCache,
45                                                 const btVector3& worldAabbMin,const btVector3& worldAabbMax, 
46                                                 int gridSizeX, int gridSizeY, int gridSizeZ, 
47                                                 int maxSmallProxies, int maxLargeProxies, int maxPairsPerSmallProxies,
48                                                 int maxSmallProxiesPerCell = 8);
49         virtual ~btCudaBroadphase();
50 protected:
51         void _initialize();
52         void _finalize();
53         void allocateArray(void** devPtr, unsigned int size);
54         void freeArray(void* devPtr);
55 // overrides for CUDA version
56         virtual void setParameters(bt3DGridBroadphaseParams* hostParams);
57         virtual void prepareAABB();
58         virtual void calcHashAABB();
59         virtual void sortHash();        
60         virtual void findCellStart();
61         virtual void findOverlappingPairs();
62         virtual void findPairsLarge();
63         virtual void computePairCacheChanges();
64         virtual void scanOverlappingPairBuff();
65         virtual void squeezeOverlappingPairBuff();
66         virtual void resetPool(btDispatcher* dispatcher);
67 };
68
69 #endif //CUDA_BROADPHASE_H