Fix PLBVH symmetry optimization for calculateOverlappingPairs().
This commit is contained in:
@@ -211,12 +211,12 @@ __kernel void plbvhCalculateOverlappingPairs(__global b3AabbCL* rigidAabbs,
|
||||
int isLeaf = isLeafNode(internalOrLeafNodeIndex); //Internal node if false
|
||||
int bvhNodeIndex = getIndexWithInternalNodeMarkerRemoved(internalOrLeafNodeIndex);
|
||||
|
||||
//Optimization - if the node is not a leaf, check whether the highest leaf index of that node
|
||||
//is less than the queried node's index to avoid testing each pair twice.
|
||||
//Optimization - if the BVH is structured as a binary radix tree, then
|
||||
//each internal node corresponds to a contiguous range of leaf nodes(internalNodeLeafIndexRanges[]).
|
||||
//This can be used to avoid testing each AABB-AABB pair twice.
|
||||
{
|
||||
// fix: produces duplicate pairs
|
||||
// int highestLeafIndex = (isLeaf) ? numQueryAabbs : internalNodeLeafIndexRanges[bvhNodeIndex].y;
|
||||
// if(highestLeafIndex < queryBvhNodeIndex) continue;
|
||||
int highestLeafIndex = (isLeaf) ? bvhNodeIndex : internalNodeLeafIndexRanges[bvhNodeIndex].y;
|
||||
if(highestLeafIndex < queryBvhNodeIndex) continue;
|
||||
}
|
||||
|
||||
//bvhRigidIndex is not used if internal node
|
||||
@@ -225,7 +225,7 @@ __kernel void plbvhCalculateOverlappingPairs(__global b3AabbCL* rigidAabbs,
|
||||
b3AabbCL bvhNodeAabb = (isLeaf) ? rigidAabbs[bvhRigidIndex] : internalNodeAabbs[bvhNodeIndex];
|
||||
if( queryRigidIndex != bvhRigidIndex && TestAabbAgainstAabb2(&queryAabb, &bvhNodeAabb) )
|
||||
{
|
||||
if(isLeaf && rigidAabbs[queryRigidIndex].m_minIndices[3] < rigidAabbs[bvhRigidIndex].m_minIndices[3])
|
||||
if(isLeaf)
|
||||
{
|
||||
int4 pair;
|
||||
pair.x = rigidAabbs[queryRigidIndex].m_minIndices[3];
|
||||
@@ -741,3 +741,32 @@ __kernel void buildBinaryRadixTreeAabbsRecursive(__global int* distanceFromRoot,
|
||||
internalNodeAabbs[internalNodeIndex] = mergedAabb;
|
||||
}
|
||||
}
|
||||
|
||||
__kernel void findLeafIndexRanges(__global int2* internalNodeChildNodes, __global int2* out_leafIndexRanges, int numInternalNodes)
|
||||
{
|
||||
int internalNodeIndex = get_global_id(0);
|
||||
if(internalNodeIndex >= numInternalNodes) return;
|
||||
|
||||
int numLeafNodes = numInternalNodes + 1;
|
||||
|
||||
int2 childNodes = internalNodeChildNodes[internalNodeIndex];
|
||||
|
||||
int2 leafIndexRange; //x == min leaf index, y == max leaf index
|
||||
|
||||
//Find lowest leaf index covered by this internal node
|
||||
{
|
||||
int lowestIndex = childNodes.x; //childNodes.x == Left child
|
||||
while( !isLeafNode(lowestIndex) ) lowestIndex = internalNodeChildNodes[ getIndexWithInternalNodeMarkerRemoved(lowestIndex) ].x;
|
||||
leafIndexRange.x = lowestIndex;
|
||||
}
|
||||
|
||||
//Find highest leaf index covered by this internal node
|
||||
{
|
||||
int highestIndex = childNodes.y; //childNodes.y == Right child
|
||||
while( !isLeafNode(highestIndex) ) highestIndex = internalNodeChildNodes[ getIndexWithInternalNodeMarkerRemoved(highestIndex) ].y;
|
||||
leafIndexRange.y = highestIndex;
|
||||
}
|
||||
|
||||
//
|
||||
out_leafIndexRanges[internalNodeIndex] = leafIndexRange;
|
||||
}
|
||||
|
||||
@@ -196,12 +196,12 @@ static const char* parallelLinearBvhCL= \
|
||||
" int isLeaf = isLeafNode(internalOrLeafNodeIndex); //Internal node if false\n"
|
||||
" int bvhNodeIndex = getIndexWithInternalNodeMarkerRemoved(internalOrLeafNodeIndex);\n"
|
||||
" \n"
|
||||
" //Optimization - if the node is not a leaf, check whether the highest leaf index of that node\n"
|
||||
" //is less than the queried node's index to avoid testing each pair twice.\n"
|
||||
" //Optimization - if the BVH is structured as a binary radix tree, then\n"
|
||||
" //each internal node corresponds to a contiguous range of leaf nodes(internalNodeLeafIndexRanges[]).\n"
|
||||
" //This can be used to avoid testing each AABB-AABB pair twice.\n"
|
||||
" {\n"
|
||||
" // fix: produces duplicate pairs\n"
|
||||
" // int highestLeafIndex = (isLeaf) ? numQueryAabbs : internalNodeLeafIndexRanges[bvhNodeIndex].y;\n"
|
||||
" // if(highestLeafIndex < queryBvhNodeIndex) continue;\n"
|
||||
" int highestLeafIndex = (isLeaf) ? bvhNodeIndex : internalNodeLeafIndexRanges[bvhNodeIndex].y;\n"
|
||||
" if(highestLeafIndex < queryBvhNodeIndex) continue;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" //bvhRigidIndex is not used if internal node\n"
|
||||
@@ -210,7 +210,7 @@ static const char* parallelLinearBvhCL= \
|
||||
" b3AabbCL bvhNodeAabb = (isLeaf) ? rigidAabbs[bvhRigidIndex] : internalNodeAabbs[bvhNodeIndex];\n"
|
||||
" if( queryRigidIndex != bvhRigidIndex && TestAabbAgainstAabb2(&queryAabb, &bvhNodeAabb) )\n"
|
||||
" {\n"
|
||||
" if(isLeaf && rigidAabbs[queryRigidIndex].m_minIndices[3] < rigidAabbs[bvhRigidIndex].m_minIndices[3])\n"
|
||||
" if(isLeaf)\n"
|
||||
" {\n"
|
||||
" int4 pair;\n"
|
||||
" pair.x = rigidAabbs[queryRigidIndex].m_minIndices[3];\n"
|
||||
@@ -702,4 +702,32 @@ static const char* parallelLinearBvhCL= \
|
||||
" internalNodeAabbs[internalNodeIndex] = mergedAabb;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"__kernel void findLeafIndexRanges(__global int2* internalNodeChildNodes, __global int2* out_leafIndexRanges, int numInternalNodes)\n"
|
||||
"{\n"
|
||||
" int internalNodeIndex = get_global_id(0);\n"
|
||||
" if(internalNodeIndex >= numInternalNodes) return;\n"
|
||||
" \n"
|
||||
" int numLeafNodes = numInternalNodes + 1;\n"
|
||||
" \n"
|
||||
" int2 childNodes = internalNodeChildNodes[internalNodeIndex];\n"
|
||||
" \n"
|
||||
" int2 leafIndexRange; //x == min leaf index, y == max leaf index\n"
|
||||
" \n"
|
||||
" //Find lowest leaf index covered by this internal node\n"
|
||||
" {\n"
|
||||
" int lowestIndex = childNodes.x; //childNodes.x == Left child\n"
|
||||
" while( !isLeafNode(lowestIndex) ) lowestIndex = internalNodeChildNodes[ getIndexWithInternalNodeMarkerRemoved(lowestIndex) ].x;\n"
|
||||
" leafIndexRange.x = lowestIndex;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" //Find highest leaf index covered by this internal node\n"
|
||||
" {\n"
|
||||
" int highestIndex = childNodes.y; //childNodes.y == Right child\n"
|
||||
" while( !isLeafNode(highestIndex) ) highestIndex = internalNodeChildNodes[ getIndexWithInternalNodeMarkerRemoved(highestIndex) ].y;\n"
|
||||
" leafIndexRange.y = highestIndex;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" //\n"
|
||||
" out_leafIndexRanges[internalNodeIndex] = leafIndexRange;\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user