Experimenting with GUI in PairBench, still preliminary. Goal is to make it easier to add variables that can be tuned using GUI/gwen
Pre-compile PairBench OpenCL kernel
This commit is contained in:
@@ -103,11 +103,10 @@ void findPairsInCell( int numObjects,
|
||||
__global int2* pHash,
|
||||
__global int* pCellStart,
|
||||
__global float4* pAABB,
|
||||
__global int* pPairBuff,
|
||||
__global int2* pPairBuffStartCurr,
|
||||
__global float4* pParams,
|
||||
volatile __global int* pairCount,
|
||||
__global int4* pPairBuff2
|
||||
__global int4* pPairBuff2,
|
||||
int maxPairs
|
||||
)
|
||||
{
|
||||
int4 pGridDim = *((__global int4*)(pParams + 1));
|
||||
@@ -125,11 +124,7 @@ void findPairsInCell( int numObjects,
|
||||
float4 min0 = pAABB[unsorted_indx*2 + 0];
|
||||
float4 max0 = pAABB[unsorted_indx*2 + 1];
|
||||
int handleIndex = as_int(min0.w);
|
||||
int2 start_curr = pPairBuffStartCurr[handleIndex];
|
||||
int start = start_curr.x;
|
||||
int curr = start_curr.y;
|
||||
int2 start_curr_next = pPairBuffStartCurr[handleIndex+1];
|
||||
int curr_max = start_curr_next.x - start - 1;
|
||||
|
||||
int bucketEnd = bucketStart + maxBodiesPerCell;
|
||||
bucketEnd = (bucketEnd > numObjects) ? numObjects : bucketEnd;
|
||||
for(int index2 = bucketStart; index2 < bucketEnd; index2++)
|
||||
@@ -153,59 +148,31 @@ void findPairsInCell( int numObjects,
|
||||
if (handleIndex<handleIndex2)
|
||||
{
|
||||
int curPair = atomic_add(pairCount,1);
|
||||
int4 newpair;
|
||||
newpair.x = handleIndex;
|
||||
newpair.y = handleIndex2;
|
||||
newpair.z = -1;
|
||||
newpair.w = -1;
|
||||
pPairBuff2[curPair] = newpair;
|
||||
if (curPair<maxPairs)
|
||||
{
|
||||
int4 newpair;
|
||||
newpair.x = handleIndex;
|
||||
newpair.y = handleIndex2;
|
||||
newpair.z = -1;
|
||||
newpair.w = -1;
|
||||
pPairBuff2[curPair] = newpair;
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
int handleIndex2 = as_int(min1.w);
|
||||
int k;
|
||||
for(k = 0; k < curr; k++)
|
||||
{
|
||||
int old_pair = pPairBuff[start+k] & (~0x60000000);
|
||||
if(old_pair == handleIndex2)
|
||||
{
|
||||
pPairBuff[start+k] |= 0x40000000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(k == curr)
|
||||
{
|
||||
if(curr >= curr_max)
|
||||
{ // not a good solution, but let's avoid crash
|
||||
break;
|
||||
}
|
||||
pPairBuff[start+curr] = handleIndex2 | 0x20000000;
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pairCount)
|
||||
{
|
||||
int2 newStartCurr;
|
||||
newStartCurr.x = start;
|
||||
newStartCurr.y = curr;
|
||||
pPairBuffStartCurr[handleIndex] = newStartCurr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
__kernel void kFindOverlappingPairs( int numObjects,
|
||||
__global float4* pAABB,
|
||||
__global int2* pHash,
|
||||
__global int* pCellStart,
|
||||
__global int* pPairBuff,
|
||||
__global int2* pPairBuffStartCurr,
|
||||
__global float4* pParams ,
|
||||
volatile __global int* pairCount,
|
||||
__global int4* pPairBuff2
|
||||
__global int4* pPairBuff2,
|
||||
int maxPairs
|
||||
)
|
||||
|
||||
{
|
||||
@@ -235,140 +202,13 @@ __kernel void kFindOverlappingPairs( int numObjects,
|
||||
for(int x=-1; x<=1; x++)
|
||||
{
|
||||
gridPosB.x = gridPosA.x + x;
|
||||
findPairsInCell(numObjects, gridPosB, index, pHash, pCellStart, pAABB, pPairBuff, pPairBuffStartCurr, pParams, pairCount,pPairBuff2);
|
||||
findPairsInCell(numObjects, gridPosB, index, pHash, pCellStart, pAABB, pParams, pairCount,pPairBuff2, maxPairs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__kernel void kFindPairsLarge( int numObjects,
|
||||
__global float4* pAABB,
|
||||
__global int2* pHash,
|
||||
__global int* pCellStart,
|
||||
__global int* pPairBuff,
|
||||
__global int2* pPairBuffStartCurr,
|
||||
uint numLarge )
|
||||
{
|
||||
int index = get_global_id(0);
|
||||
if(index >= numObjects)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int2 sortedData = pHash[index];
|
||||
int unsorted_indx = sortedData.y;
|
||||
float4 min0 = pAABB[unsorted_indx*2 + 0];
|
||||
float4 max0 = pAABB[unsorted_indx*2 + 1];
|
||||
int handleIndex = as_int(min0.w);
|
||||
int2 start_curr = pPairBuffStartCurr[handleIndex];
|
||||
int start = start_curr.x;
|
||||
int curr = start_curr.y;
|
||||
int2 start_curr_next = pPairBuffStartCurr[handleIndex+1];
|
||||
int curr_max = start_curr_next.x - start - 1;
|
||||
for(uint i = 0; i < numLarge; i++)
|
||||
{
|
||||
int indx2 = numObjects + i;
|
||||
float4 min1 = pAABB[indx2*2 + 0];
|
||||
float4 max1 = pAABB[indx2*2 + 1];
|
||||
if(testAABBOverlap(min0, max0, min1, max1))
|
||||
{
|
||||
int k;
|
||||
int handleIndex2 = as_int(min1.w);
|
||||
for(k = 0; k < curr; k++)
|
||||
{
|
||||
int old_pair = pPairBuff[start+k] & (~0x60000000);
|
||||
if(old_pair == handleIndex2)
|
||||
{
|
||||
pPairBuff[start+k] |= 0x40000000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(k == curr)
|
||||
{
|
||||
pPairBuff[start+curr] = handleIndex2 | 0x20000000;
|
||||
if(curr >= curr_max)
|
||||
{ // not a good solution, but let's avoid crash
|
||||
break;
|
||||
}
|
||||
curr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
int2 newStartCurr;
|
||||
newStartCurr.x = start;
|
||||
newStartCurr.y = curr;
|
||||
pPairBuffStartCurr[handleIndex] = newStartCurr;
|
||||
return;
|
||||
}
|
||||
|
||||
__kernel void kComputePairCacheChanges( int numObjects,
|
||||
__global int* pPairBuff,
|
||||
__global int2* pPairBuffStartCurr,
|
||||
__global int* pPairScan,
|
||||
__global float4* pAABB )
|
||||
{
|
||||
int index = get_global_id(0);
|
||||
if(index >= numObjects)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float4 bbMin = pAABB[index * 2];
|
||||
int handleIndex = as_int(bbMin.w);
|
||||
int2 start_curr = pPairBuffStartCurr[handleIndex];
|
||||
int start = start_curr.x;
|
||||
int curr = start_curr.y;
|
||||
__global int *pInp = pPairBuff + start;
|
||||
int num_changes = 0;
|
||||
for(int k = 0; k < curr; k++, pInp++)
|
||||
{
|
||||
if(!((*pInp) & 0x40000000))
|
||||
{
|
||||
num_changes++;
|
||||
}
|
||||
}
|
||||
pPairScan[index+1] = num_changes;
|
||||
}
|
||||
|
||||
__kernel void kSqueezeOverlappingPairBuff( int numObjects,
|
||||
__global int* pPairBuff,
|
||||
__global int2* pPairBuffStartCurr,
|
||||
__global int* pPairScan,
|
||||
__global int* pPairOut,
|
||||
__global float4* pAABB )
|
||||
{
|
||||
int index = get_global_id(0);
|
||||
if(index >= numObjects)
|
||||
{
|
||||
return;
|
||||
}
|
||||
float4 bbMin = pAABB[index * 2];
|
||||
int handleIndex = as_int(bbMin.w);
|
||||
int2 start_curr = pPairBuffStartCurr[handleIndex];
|
||||
int start = start_curr.x;
|
||||
int curr = start_curr.y;
|
||||
__global int* pInp = pPairBuff + start;
|
||||
__global int* pOut = pPairOut + pPairScan[index+1];
|
||||
__global int* pOut2 = pInp;
|
||||
int num = 0;
|
||||
for(int k = 0; k < curr; k++, pInp++)
|
||||
{
|
||||
if(!((*pInp) & 0x40000000))
|
||||
{
|
||||
*pOut = *pInp;
|
||||
pOut++;
|
||||
}
|
||||
if((*pInp) & 0x60000000)
|
||||
{
|
||||
*pOut2 = (*pInp) & (~0x60000000);
|
||||
pOut2++;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
int2 newStartCurr;
|
||||
newStartCurr.x = start;
|
||||
newStartCurr.y = num;
|
||||
pPairBuffStartCurr[handleIndex] = newStartCurr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -92,11 +92,10 @@ static const char* gridBroadphaseCL= \
|
||||
" __global int2* pHash,\n"
|
||||
" __global int* pCellStart,\n"
|
||||
" __global float4* pAABB, \n"
|
||||
" __global int* pPairBuff,\n"
|
||||
" __global int2* pPairBuffStartCurr,\n"
|
||||
" __global float4* pParams,\n"
|
||||
" volatile __global int* pairCount,\n"
|
||||
" __global int4* pPairBuff2\n"
|
||||
" __global int4* pPairBuff2,\n"
|
||||
" int maxPairs\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
" int4 pGridDim = *((__global int4*)(pParams + 1));\n"
|
||||
@@ -114,11 +113,7 @@ static const char* gridBroadphaseCL= \
|
||||
" float4 min0 = pAABB[unsorted_indx*2 + 0]; \n"
|
||||
" float4 max0 = pAABB[unsorted_indx*2 + 1];\n"
|
||||
" int handleIndex = as_int(min0.w);\n"
|
||||
" int2 start_curr = pPairBuffStartCurr[handleIndex];\n"
|
||||
" int start = start_curr.x;\n"
|
||||
" int curr = start_curr.y;\n"
|
||||
" int2 start_curr_next = pPairBuffStartCurr[handleIndex+1];\n"
|
||||
" int curr_max = start_curr_next.x - start - 1;\n"
|
||||
" \n"
|
||||
" int bucketEnd = bucketStart + maxBodiesPerCell;\n"
|
||||
" bucketEnd = (bucketEnd > numObjects) ? numObjects : bucketEnd;\n"
|
||||
" for(int index2 = bucketStart; index2 < bucketEnd; index2++) \n"
|
||||
@@ -142,58 +137,30 @@ static const char* gridBroadphaseCL= \
|
||||
" if (handleIndex<handleIndex2)\n"
|
||||
" {\n"
|
||||
" int curPair = atomic_add(pairCount,1);\n"
|
||||
" int4 newpair;\n"
|
||||
" newpair.x = handleIndex;\n"
|
||||
" newpair.y = handleIndex2;\n"
|
||||
" newpair.z = -1;\n"
|
||||
" newpair.w = -1;\n"
|
||||
" pPairBuff2[curPair] = newpair;\n"
|
||||
" if (curPair<maxPairs)\n"
|
||||
" {\n"
|
||||
" int4 newpair;\n"
|
||||
" newpair.x = handleIndex;\n"
|
||||
" newpair.y = handleIndex2;\n"
|
||||
" newpair.z = -1;\n"
|
||||
" newpair.w = -1;\n"
|
||||
" pPairBuff2[curPair] = newpair;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" } else\n"
|
||||
" {\n"
|
||||
" int handleIndex2 = as_int(min1.w);\n"
|
||||
" int k;\n"
|
||||
" for(k = 0; k < curr; k++)\n"
|
||||
" {\n"
|
||||
" int old_pair = pPairBuff[start+k] & (~0x60000000);\n"
|
||||
" if(old_pair == handleIndex2)\n"
|
||||
" {\n"
|
||||
" pPairBuff[start+k] |= 0x40000000;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" if(k == curr)\n"
|
||||
" {\n"
|
||||
" if(curr >= curr_max) \n"
|
||||
" { // not a good solution, but let's avoid crash\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" pPairBuff[start+curr] = handleIndex2 | 0x20000000;\n"
|
||||
" curr++;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" if (!pairCount)\n"
|
||||
" {\n"
|
||||
" int2 newStartCurr;\n"
|
||||
" newStartCurr.x = start;\n"
|
||||
" newStartCurr.y = curr;\n"
|
||||
" pPairBuffStartCurr[handleIndex] = newStartCurr;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
"}\n"
|
||||
"__kernel void kFindOverlappingPairs( int numObjects,\n"
|
||||
" __global float4* pAABB, \n"
|
||||
" __global int2* pHash, \n"
|
||||
" __global int* pCellStart, \n"
|
||||
" __global int* pPairBuff, \n"
|
||||
" __global int2* pPairBuffStartCurr, \n"
|
||||
" __global float4* pParams ,\n"
|
||||
" volatile __global int* pairCount,\n"
|
||||
" __global int4* pPairBuff2\n"
|
||||
" __global int4* pPairBuff2,\n"
|
||||
" int maxPairs\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
" int index = get_global_id(0);\n"
|
||||
@@ -222,134 +189,9 @@ static const char* gridBroadphaseCL= \
|
||||
" for(int x=-1; x<=1; x++) \n"
|
||||
" {\n"
|
||||
" gridPosB.x = gridPosA.x + x;\n"
|
||||
" findPairsInCell(numObjects, gridPosB, index, pHash, pCellStart, pAABB, pPairBuff, pPairBuffStartCurr, pParams, pairCount,pPairBuff2);\n"
|
||||
" findPairsInCell(numObjects, gridPosB, index, pHash, pCellStart, pAABB, pParams, pairCount,pPairBuff2, maxPairs);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"__kernel void kFindPairsLarge( int numObjects, \n"
|
||||
" __global float4* pAABB, \n"
|
||||
" __global int2* pHash, \n"
|
||||
" __global int* pCellStart, \n"
|
||||
" __global int* pPairBuff, \n"
|
||||
" __global int2* pPairBuffStartCurr, \n"
|
||||
" uint numLarge )\n"
|
||||
"{\n"
|
||||
" int index = get_global_id(0);\n"
|
||||
" if(index >= numObjects)\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" int2 sortedData = pHash[index];\n"
|
||||
" int unsorted_indx = sortedData.y;\n"
|
||||
" float4 min0 = pAABB[unsorted_indx*2 + 0];\n"
|
||||
" float4 max0 = pAABB[unsorted_indx*2 + 1];\n"
|
||||
" int handleIndex = as_int(min0.w);\n"
|
||||
" int2 start_curr = pPairBuffStartCurr[handleIndex];\n"
|
||||
" int start = start_curr.x;\n"
|
||||
" int curr = start_curr.y;\n"
|
||||
" int2 start_curr_next = pPairBuffStartCurr[handleIndex+1];\n"
|
||||
" int curr_max = start_curr_next.x - start - 1;\n"
|
||||
" for(uint i = 0; i < numLarge; i++)\n"
|
||||
" {\n"
|
||||
" int indx2 = numObjects + i;\n"
|
||||
" float4 min1 = pAABB[indx2*2 + 0];\n"
|
||||
" float4 max1 = pAABB[indx2*2 + 1];\n"
|
||||
" if(testAABBOverlap(min0, max0, min1, max1))\n"
|
||||
" {\n"
|
||||
" int k;\n"
|
||||
" int handleIndex2 = as_int(min1.w);\n"
|
||||
" for(k = 0; k < curr; k++)\n"
|
||||
" {\n"
|
||||
" int old_pair = pPairBuff[start+k] & (~0x60000000);\n"
|
||||
" if(old_pair == handleIndex2)\n"
|
||||
" {\n"
|
||||
" pPairBuff[start+k] |= 0x40000000;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" if(k == curr)\n"
|
||||
" {\n"
|
||||
" pPairBuff[start+curr] = handleIndex2 | 0x20000000;\n"
|
||||
" if(curr >= curr_max) \n"
|
||||
" { // not a good solution, but let's avoid crash\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" curr++;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" int2 newStartCurr;\n"
|
||||
" newStartCurr.x = start;\n"
|
||||
" newStartCurr.y = curr;\n"
|
||||
" pPairBuffStartCurr[handleIndex] = newStartCurr;\n"
|
||||
" return;\n"
|
||||
"}\n"
|
||||
"__kernel void kComputePairCacheChanges( int numObjects,\n"
|
||||
" __global int* pPairBuff, \n"
|
||||
" __global int2* pPairBuffStartCurr, \n"
|
||||
" __global int* pPairScan, \n"
|
||||
" __global float4* pAABB )\n"
|
||||
"{\n"
|
||||
" int index = get_global_id(0);\n"
|
||||
" if(index >= numObjects)\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" float4 bbMin = pAABB[index * 2];\n"
|
||||
" int handleIndex = as_int(bbMin.w);\n"
|
||||
" int2 start_curr = pPairBuffStartCurr[handleIndex];\n"
|
||||
" int start = start_curr.x;\n"
|
||||
" int curr = start_curr.y;\n"
|
||||
" __global int *pInp = pPairBuff + start;\n"
|
||||
" int num_changes = 0;\n"
|
||||
" for(int k = 0; k < curr; k++, pInp++)\n"
|
||||
" {\n"
|
||||
" if(!((*pInp) & 0x40000000))\n"
|
||||
" {\n"
|
||||
" num_changes++;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" pPairScan[index+1] = num_changes;\n"
|
||||
"} \n"
|
||||
"__kernel void kSqueezeOverlappingPairBuff( int numObjects,\n"
|
||||
" __global int* pPairBuff, \n"
|
||||
" __global int2* pPairBuffStartCurr, \n"
|
||||
" __global int* pPairScan,\n"
|
||||
" __global int* pPairOut, \n"
|
||||
" __global float4* pAABB )\n"
|
||||
"{\n"
|
||||
" int index = get_global_id(0);\n"
|
||||
" if(index >= numObjects)\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" float4 bbMin = pAABB[index * 2];\n"
|
||||
" int handleIndex = as_int(bbMin.w);\n"
|
||||
" int2 start_curr = pPairBuffStartCurr[handleIndex];\n"
|
||||
" int start = start_curr.x;\n"
|
||||
" int curr = start_curr.y;\n"
|
||||
" __global int* pInp = pPairBuff + start;\n"
|
||||
" __global int* pOut = pPairOut + pPairScan[index+1];\n"
|
||||
" __global int* pOut2 = pInp;\n"
|
||||
" int num = 0; \n"
|
||||
" for(int k = 0; k < curr; k++, pInp++)\n"
|
||||
" {\n"
|
||||
" if(!((*pInp) & 0x40000000))\n"
|
||||
" {\n"
|
||||
" *pOut = *pInp;\n"
|
||||
" pOut++;\n"
|
||||
" }\n"
|
||||
" if((*pInp) & 0x60000000)\n"
|
||||
" {\n"
|
||||
" *pOut2 = (*pInp) & (~0x60000000);\n"
|
||||
" pOut2++;\n"
|
||||
" num++;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" int2 newStartCurr;\n"
|
||||
" newStartCurr.x = start;\n"
|
||||
" newStartCurr.y = num;\n"
|
||||
" pPairBuffStartCurr[handleIndex] = newStartCurr;\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user