2017-08-01 12:30:58 +00:00
|
|
|
#ifndef B3_GPU_GRID_BROADPHASE_H
|
|
|
|
#define B3_GPU_GRID_BROADPHASE_H
|
|
|
|
|
|
|
|
#include "b3GpuBroadphaseInterface.h"
|
|
|
|
#include "Bullet3OpenCL/ParallelPrimitives/b3RadixSort32CL.h"
|
|
|
|
|
|
|
|
struct b3ParamsGridBroadphaseCL
|
|
|
|
{
|
|
|
|
float m_invCellSize[4];
|
2019-01-03 13:26:51 +00:00
|
|
|
int m_gridSize[4];
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
int getMaxBodiesPerCell() const
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return m_gridSize[3];
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void setMaxBodiesPerCell(int maxOverlap)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_gridSize[3] = maxOverlap;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class b3GpuGridBroadphase : public b3GpuBroadphaseInterface
|
|
|
|
{
|
|
|
|
protected:
|
2019-01-03 13:26:51 +00:00
|
|
|
cl_context m_context;
|
|
|
|
cl_device_id m_device;
|
|
|
|
cl_command_queue m_queue;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3OpenCLArray<b3SapAabb> m_allAabbsGPU1;
|
|
|
|
b3AlignedObjectArray<b3SapAabb> m_allAabbsCPU1;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3OpenCLArray<int> m_smallAabbsMappingGPU;
|
2017-08-01 12:30:58 +00:00
|
|
|
b3AlignedObjectArray<int> m_smallAabbsMappingCPU;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3OpenCLArray<int> m_largeAabbsMappingGPU;
|
2017-08-01 12:30:58 +00:00
|
|
|
b3AlignedObjectArray<int> m_largeAabbsMappingCPU;
|
|
|
|
|
|
|
|
b3AlignedObjectArray<b3Int4> m_hostPairs;
|
2019-01-03 13:26:51 +00:00
|
|
|
b3OpenCLArray<b3Int4> m_gpuPairs;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3OpenCLArray<b3SortData> m_hashGpu;
|
|
|
|
b3OpenCLArray<int> m_cellStartGpu;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3ParamsGridBroadphaseCL m_paramsCPU;
|
|
|
|
b3OpenCLArray<b3ParamsGridBroadphaseCL> m_paramsGPU;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
class b3RadixSort32CL* m_sorter;
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
public:
|
2019-01-03 13:26:51 +00:00
|
|
|
b3GpuGridBroadphase(cl_context ctx, cl_device_id device, cl_command_queue q);
|
2017-08-01 12:30:58 +00:00
|
|
|
virtual ~b3GpuGridBroadphase();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
static b3GpuBroadphaseInterface* CreateFunc(cl_context ctx, cl_device_id device, cl_command_queue q)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
return new b3GpuGridBroadphase(ctx, device, q);
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void createProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr, int collisionFilterGroup, int collisionFilterMask);
|
|
|
|
virtual void createLargeProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr, int collisionFilterGroup, int collisionFilterMask);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual void calculateOverlappingPairs(int maxPairs);
|
|
|
|
virtual void calculateOverlappingPairsHost(int maxPairs);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
//call writeAabbsToGpu after done making all changes (createProxy etc)
|
|
|
|
virtual void writeAabbsToGpu();
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
virtual cl_mem getAabbBufferWS();
|
|
|
|
virtual int getNumOverlap();
|
|
|
|
virtual cl_mem getOverlappingPairBuffer();
|
|
|
|
|
|
|
|
virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU();
|
|
|
|
virtual b3AlignedObjectArray<b3SapAabb>& getAllAabbsCPU();
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
virtual b3OpenCLArray<b3Int4>& getOverlappingPairsGPU();
|
|
|
|
virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU();
|
|
|
|
virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU();
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
#endif //B3_GPU_GRID_BROADPHASE_H
|