1 #ifndef B3_GPU_GRID_BROADPHASE_H 2 #define B3_GPU_GRID_BROADPHASE_H 3 4 #include "b3GpuBroadphaseInterface.h" 5 #include "Bullet3OpenCL/ParallelPrimitives/b3RadixSort32CL.h" 6 7 struct b3ParamsGridBroadphaseCL 8 { 9 float m_invCellSize[4]; 10 int m_gridSize[4]; 11 getMaxBodiesPerCellb3ParamsGridBroadphaseCL12 int getMaxBodiesPerCell() const 13 { 14 return m_gridSize[3]; 15 } 16 setMaxBodiesPerCellb3ParamsGridBroadphaseCL17 void setMaxBodiesPerCell(int maxOverlap) 18 { 19 m_gridSize[3] = maxOverlap; 20 } 21 }; 22 23 class b3GpuGridBroadphase : public b3GpuBroadphaseInterface 24 { 25 protected: 26 cl_context m_context; 27 cl_device_id m_device; 28 cl_command_queue m_queue; 29 30 b3OpenCLArray<b3SapAabb> m_allAabbsGPU1; 31 b3AlignedObjectArray<b3SapAabb> m_allAabbsCPU1; 32 33 b3OpenCLArray<int> m_smallAabbsMappingGPU; 34 b3AlignedObjectArray<int> m_smallAabbsMappingCPU; 35 36 b3OpenCLArray<int> m_largeAabbsMappingGPU; 37 b3AlignedObjectArray<int> m_largeAabbsMappingCPU; 38 39 b3AlignedObjectArray<b3Int4> m_hostPairs; 40 b3OpenCLArray<b3Int4> m_gpuPairs; 41 42 b3OpenCLArray<b3SortData> m_hashGpu; 43 b3OpenCLArray<int> m_cellStartGpu; 44 45 b3ParamsGridBroadphaseCL m_paramsCPU; 46 b3OpenCLArray<b3ParamsGridBroadphaseCL> m_paramsGPU; 47 48 class b3RadixSort32CL* m_sorter; 49 50 public: 51 b3GpuGridBroadphase(cl_context ctx, cl_device_id device, cl_command_queue q); 52 virtual ~b3GpuGridBroadphase(); 53 CreateFunc(cl_context ctx,cl_device_id device,cl_command_queue q)54 static b3GpuBroadphaseInterface* CreateFunc(cl_context ctx, cl_device_id device, cl_command_queue q) 55 { 56 return new b3GpuGridBroadphase(ctx, device, q); 57 } 58 59 virtual void createProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr, int collisionFilterGroup, int collisionFilterMask); 60 virtual void createLargeProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr, int collisionFilterGroup, int collisionFilterMask); 61 62 virtual void calculateOverlappingPairs(int maxPairs); 63 virtual void calculateOverlappingPairsHost(int maxPairs); 64 65 //call writeAabbsToGpu after done making all changes (createProxy etc) 66 virtual void writeAabbsToGpu(); 67 68 virtual cl_mem getAabbBufferWS(); 69 virtual int getNumOverlap(); 70 virtual cl_mem getOverlappingPairBuffer(); 71 72 virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU(); 73 virtual b3AlignedObjectArray<b3SapAabb>& getAllAabbsCPU(); 74 75 virtual b3OpenCLArray<b3Int4>& getOverlappingPairsGPU(); 76 virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU(); 77 virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU(); 78 }; 79 80 #endif //B3_GPU_GRID_BROADPHASE_H