Add access to overlapping pairs b3OpenCLArray.

This commit is contained in:
Jackson Lee
2014-03-13 21:27:15 -07:00
parent 19b194e8fe
commit f324e66f86
9 changed files with 29 additions and 18 deletions

View File

@@ -35,6 +35,7 @@ public:
virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU()=0; virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU()=0;
virtual b3AlignedObjectArray<b3SapAabb>& getAllAabbsCPU()=0; virtual b3AlignedObjectArray<b3SapAabb>& getAllAabbsCPU()=0;
virtual b3OpenCLArray<b3Int4>& getOverlappingPairsGPU() = 0;
virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU() = 0; virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU() = 0;
virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU() = 0; virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU() = 0;

View File

@@ -368,6 +368,10 @@ b3AlignedObjectArray<b3SapAabb>& b3GpuGridBroadphase::getAllAabbsCPU()
return m_allAabbsCPU1; return m_allAabbsCPU1;
} }
b3OpenCLArray<b3Int4>& b3GpuGridBroadphase::getOverlappingPairsGPU()
{
return m_gpuPairs;
}
b3OpenCLArray<int>& b3GpuGridBroadphase::getSmallAabbIndicesGPU() b3OpenCLArray<int>& b3GpuGridBroadphase::getSmallAabbIndicesGPU()
{ {
return m_smallAabbsMappingGPU; return m_smallAabbsMappingGPU;

View File

@@ -79,6 +79,7 @@ public:
virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU(); virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU();
virtual b3AlignedObjectArray<b3SapAabb>& getAllAabbsCPU(); virtual b3AlignedObjectArray<b3SapAabb>& getAllAabbsCPU();
virtual b3OpenCLArray<b3Int4>& getOverlappingPairsGPU();
virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU(); virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU();
virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU(); virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU();

View File

@@ -22,6 +22,7 @@ b3GpuParallelLinearBvh::b3GpuParallelLinearBvh(cl_context context, cl_device_id
m_rootNodeIndex(context, queue), m_rootNodeIndex(context, queue),
m_maxDistanceFromRoot(context, queue), m_maxDistanceFromRoot(context, queue),
m_temp(context, queue),
m_internalNodeAabbs(context, queue), m_internalNodeAabbs(context, queue),
m_internalNodeLeafIndexRanges(context, queue), m_internalNodeLeafIndexRanges(context, queue),
@@ -41,6 +42,7 @@ b3GpuParallelLinearBvh::b3GpuParallelLinearBvh(cl_context context, cl_device_id
{ {
m_rootNodeIndex.resize(1); m_rootNodeIndex.resize(1);
m_maxDistanceFromRoot.resize(1); m_maxDistanceFromRoot.resize(1);
m_temp.resize(1);
// //
const char CL_PROGRAM_PATH[] = "src/Bullet3OpenCL/BroadphaseCollision/kernels/parallelLinearBvh.cl"; const char CL_PROGRAM_PATH[] = "src/Bullet3OpenCL/BroadphaseCollision/kernels/parallelLinearBvh.cl";
@@ -287,14 +289,13 @@ void b3GpuParallelLinearBvh::build(const b3OpenCLArray<b3SapAabb>& worldSpaceAab
} }
} }
void b3GpuParallelLinearBvh::calculateOverlappingPairs(b3OpenCLArray<int>& out_numPairs, b3OpenCLArray<b3Int4>& out_overlappingPairs) void b3GpuParallelLinearBvh::calculateOverlappingPairs(b3OpenCLArray<b3Int4>& out_overlappingPairs)
{ {
b3Assert( out_numPairs.size() == 1 );
int maxPairs = out_overlappingPairs.size(); int maxPairs = out_overlappingPairs.size();
b3OpenCLArray<int>& numPairsGpu = m_temp;
int reset = 0; int reset = 0;
out_numPairs.copyFromHostPointer(&reset, 1); numPairsGpu.copyFromHostPointer(&reset, 1);
// //
if( m_leafNodeAabbs.size() > 1 ) if( m_leafNodeAabbs.size() > 1 )
@@ -313,7 +314,7 @@ void b3GpuParallelLinearBvh::calculateOverlappingPairs(b3OpenCLArray<int>& out_n
b3BufferInfoCL( m_internalNodeLeafIndexRanges.getBufferCL() ), b3BufferInfoCL( m_internalNodeLeafIndexRanges.getBufferCL() ),
b3BufferInfoCL( m_mortonCodesAndAabbIndicies.getBufferCL() ), b3BufferInfoCL( m_mortonCodesAndAabbIndicies.getBufferCL() ),
b3BufferInfoCL( out_numPairs.getBufferCL() ), b3BufferInfoCL( numPairsGpu.getBufferCL() ),
b3BufferInfoCL( out_overlappingPairs.getBufferCL() ) b3BufferInfoCL( out_overlappingPairs.getBufferCL() )
}; };
@@ -338,7 +339,7 @@ void b3GpuParallelLinearBvh::calculateOverlappingPairs(b3OpenCLArray<int>& out_n
b3BufferInfoCL( m_leafNodeAabbs.getBufferCL() ), b3BufferInfoCL( m_leafNodeAabbs.getBufferCL() ),
b3BufferInfoCL( m_largeAabbs.getBufferCL() ), b3BufferInfoCL( m_largeAabbs.getBufferCL() ),
b3BufferInfoCL( out_numPairs.getBufferCL() ), b3BufferInfoCL( numPairsGpu.getBufferCL() ),
b3BufferInfoCL( out_overlappingPairs.getBufferCL() ) b3BufferInfoCL( out_overlappingPairs.getBufferCL() )
}; };
@@ -355,12 +356,12 @@ void b3GpuParallelLinearBvh::calculateOverlappingPairs(b3OpenCLArray<int>& out_n
// //
int numPairs = -1; int numPairs = -1;
out_numPairs.copyToHostPointer(&numPairs, 1); numPairsGpu.copyToHostPointer(&numPairs, 1);
if(numPairs > maxPairs) if(numPairs > maxPairs)
{ {
b3Error("Error running out of pairs: numPairs = %d, maxPairs = %d.\n", numPairs, maxPairs); b3Error("Error running out of pairs: numPairs = %d, maxPairs = %d.\n", numPairs, maxPairs);
numPairs = maxPairs; numPairs = maxPairs;
out_numPairs.copyFromHostPointer(&maxPairs, 1); numPairsGpu.copyFromHostPointer(&maxPairs, 1);
} }
out_overlappingPairs.resize(numPairs); out_overlappingPairs.resize(numPairs);

View File

@@ -76,6 +76,7 @@ class b3GpuParallelLinearBvh
//1 element //1 element
b3OpenCLArray<int> m_rootNodeIndex; //Most significant bit(0x80000000) is set to indicate internal node b3OpenCLArray<int> m_rootNodeIndex; //Most significant bit(0x80000000) is set to indicate internal node
b3OpenCLArray<int> m_maxDistanceFromRoot; //Max number of internal nodes between an internal node and the root node b3OpenCLArray<int> m_maxDistanceFromRoot; //Max number of internal nodes between an internal node and the root node
b3OpenCLArray<int> m_temp; //Used to hold the number of pairs in calculateOverlappingPairs()
//1 element per internal node (number_of_internal_nodes == number_of_leaves - 1) //1 element per internal node (number_of_internal_nodes == number_of_leaves - 1)
b3OpenCLArray<b3SapAabb> m_internalNodeAabbs; b3OpenCLArray<b3SapAabb> m_internalNodeAabbs;
@@ -101,15 +102,14 @@ public:
b3GpuParallelLinearBvh(cl_context context, cl_device_id device, cl_command_queue queue); b3GpuParallelLinearBvh(cl_context context, cl_device_id device, cl_command_queue queue);
virtual ~b3GpuParallelLinearBvh(); virtual ~b3GpuParallelLinearBvh();
///Must be called before any other function
void build(const b3OpenCLArray<b3SapAabb>& worldSpaceAabbs, const b3OpenCLArray<int>& smallAabbIndices, void build(const b3OpenCLArray<b3SapAabb>& worldSpaceAabbs, const b3OpenCLArray<int>& smallAabbIndices,
const b3OpenCLArray<int>& largeAabbIndices); const b3OpenCLArray<int>& largeAabbIndices);
///b3GpuParallelLinearBvh::build() must be called before this function. calculateOverlappingPairs() uses ///calculateOverlappingPairs() uses the worldSpaceAabbs parameter of b3GpuParallelLinearBvh::build() as the query AABBs.
///the worldSpaceAabbs parameter of b3GpuParallelLinearBvh::build() as the query AABBs.
///@param out_numPairs If number of pairs exceeds the max number of pairs, this is clamped to the max number.
///@param out_overlappingPairs The size() of this array is used to determine the max number of pairs. ///@param out_overlappingPairs The size() of this array is used to determine the max number of pairs.
///If the number of overlapping pairs is < out_overlappingPairs.size(), out_overlappingPairs is resized. ///If the number of overlapping pairs is < out_overlappingPairs.size(), out_overlappingPairs is resized.
void calculateOverlappingPairs(b3OpenCLArray<int>& out_numPairs, b3OpenCLArray<b3Int4>& out_overlappingPairs); void calculateOverlappingPairs(b3OpenCLArray<b3Int4>& out_overlappingPairs);
///@param out_numRigidRayPairs Array of length 1; contains the number of detected ray-rigid AABB intersections; ///@param out_numRigidRayPairs Array of length 1; contains the number of detected ray-rigid AABB intersections;
///this value may be greater than out_rayRigidPairs.size() if out_rayRigidPairs is not large enough. ///this value may be greater than out_rayRigidPairs.size() if out_rayRigidPairs is not large enough.

View File

@@ -16,14 +16,12 @@ subject to the following restrictions:
b3GpuParallelLinearBvhBroadphase::b3GpuParallelLinearBvhBroadphase(cl_context context, cl_device_id device, cl_command_queue queue) : b3GpuParallelLinearBvhBroadphase::b3GpuParallelLinearBvhBroadphase(cl_context context, cl_device_id device, cl_command_queue queue) :
m_plbvh(context, device, queue), m_plbvh(context, device, queue),
m_numOverlappingPairs(context, queue),
m_overlappingPairsGpu(context, queue), m_overlappingPairsGpu(context, queue),
m_aabbsGpu(context, queue), m_aabbsGpu(context, queue),
m_smallAabbsMappingGpu(context, queue), m_smallAabbsMappingGpu(context, queue),
m_largeAabbsMappingGpu(context, queue) m_largeAabbsMappingGpu(context, queue)
{ {
m_numOverlappingPairs.resize(1);
} }
void b3GpuParallelLinearBvhBroadphase::createProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr, short int collisionFilterGroup, short int collisionFilterMask) void b3GpuParallelLinearBvhBroadphase::createProxy(const b3Vector3& aabbMin, const b3Vector3& aabbMax, int userPtr, short int collisionFilterGroup, short int collisionFilterMask)
@@ -64,7 +62,7 @@ void b3GpuParallelLinearBvhBroadphase::calculateOverlappingPairs(int maxPairs)
// //
m_overlappingPairsGpu.resize(maxPairs); m_overlappingPairsGpu.resize(maxPairs);
m_plbvh.calculateOverlappingPairs(m_numOverlappingPairs, m_overlappingPairsGpu); m_plbvh.calculateOverlappingPairs(m_overlappingPairsGpu);
} }
void b3GpuParallelLinearBvhBroadphase::calculateOverlappingPairsHost(int maxPairs) void b3GpuParallelLinearBvhBroadphase::calculateOverlappingPairsHost(int maxPairs)
{ {

View File

@@ -22,7 +22,6 @@ class b3GpuParallelLinearBvhBroadphase : public b3GpuBroadphaseInterface
{ {
b3GpuParallelLinearBvh m_plbvh; b3GpuParallelLinearBvh m_plbvh;
b3OpenCLArray<int> m_numOverlappingPairs;
b3OpenCLArray<b3Int4> m_overlappingPairsGpu; b3OpenCLArray<b3Int4> m_overlappingPairsGpu;
b3OpenCLArray<b3SapAabb> m_aabbsGpu; b3OpenCLArray<b3SapAabb> m_aabbsGpu;
@@ -51,6 +50,8 @@ public:
virtual cl_mem getAabbBufferWS() { return m_aabbsGpu.getBufferCL(); } virtual cl_mem getAabbBufferWS() { return m_aabbsGpu.getBufferCL(); }
virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU() { return m_aabbsGpu; } virtual b3OpenCLArray<b3SapAabb>& getAllAabbsGPU() { return m_aabbsGpu; }
virtual b3OpenCLArray<b3Int4>& getOverlappingPairsGPU() { return m_overlappingPairsGpu; }
virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU() { return m_smallAabbsMappingGpu; } virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU() { return m_smallAabbsMappingGpu; }
virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU() { return m_largeAabbsMappingGpu; } virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU() { return m_largeAabbsMappingGpu; }

View File

@@ -1308,6 +1308,10 @@ cl_mem b3GpuSapBroadphase::getOverlappingPairBuffer()
return m_overlappingPairs.getBufferCL(); return m_overlappingPairs.getBufferCL();
} }
b3OpenCLArray<b3Int4>& b3GpuSapBroadphase::getOverlappingPairsGPU()
{
return m_overlappingPairs;
}
b3OpenCLArray<int>& b3GpuSapBroadphase::getSmallAabbIndicesGPU() b3OpenCLArray<int>& b3GpuSapBroadphase::getSmallAabbIndicesGPU()
{ {
return m_smallAabbsMappingGPU; return m_smallAabbsMappingGPU;

View File

@@ -143,6 +143,7 @@ public:
virtual int getNumOverlap(); virtual int getNumOverlap();
virtual cl_mem getOverlappingPairBuffer(); virtual cl_mem getOverlappingPairBuffer();
virtual b3OpenCLArray<b3Int4>& getOverlappingPairsGPU();
virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU(); virtual b3OpenCLArray<int>& getSmallAabbIndicesGPU();
virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU(); virtual b3OpenCLArray<int>& getLargeAabbIndicesGPU();
}; };