more work towards hybrid of GPU grid and sap broadphase, separating small, large (moving) and static objects
re-enable 'useNewBatchingKernel', it is slower but more robust
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* gridBroadphaseCL= \
|
||||
"#pragma OPENCL EXTENSION cl_amd_printf : enable\n"
|
||||
"int getPosHash(int4 gridPos, __global float4* pParams)\n"
|
||||
"{\n"
|
||||
" int4 gridDim = *((__global int4*)(pParams + 1));\n"
|
||||
@@ -47,7 +46,6 @@ static const char* gridBroadphaseCL= \
|
||||
" __global int* pCellStart )\n"
|
||||
"{\n"
|
||||
" int index = get_global_id(0);\n"
|
||||
" \n"
|
||||
" if(index >= numCells)\n"
|
||||
" {\n"
|
||||
" return;\n"
|
||||
@@ -68,7 +66,6 @@ static const char* gridBroadphaseCL= \
|
||||
" sharedHash[get_local_id(0) + 1] = sortedData.x;\n"
|
||||
" if((index > 0) && (get_local_id(0) == 0))\n"
|
||||
" {\n"
|
||||
" printf(\"%d sharedHash!\\n\", index);\n"
|
||||
" // first thread in block must load neighbor body hash\n"
|
||||
" sharedHash[0] = pHash[index-1].x;\n"
|
||||
" }\n"
|
||||
@@ -78,7 +75,6 @@ static const char* gridBroadphaseCL= \
|
||||
" {\n"
|
||||
" if((index == 0) || (sortedData.x != sharedHash[get_local_id(0)]))\n"
|
||||
" {\n"
|
||||
" printf(\"%d cellStart!\\n\", index);\n"
|
||||
" cellStart[sortedData.x] = index;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
@@ -89,6 +85,7 @@ static const char* gridBroadphaseCL= \
|
||||
" (min0.y <= max1.y)&& (min1.y <= max0.y) && \n"
|
||||
" (min0.z <= max1.z)&& (min1.z <= max0.z); \n"
|
||||
"}\n"
|
||||
"//search for AABB 'index' against other AABBs' in this cell\n"
|
||||
"void findPairsInCell( int numObjects,\n"
|
||||
" int4 gridPos,\n"
|
||||
" int index,\n"
|
||||
@@ -97,7 +94,10 @@ static const char* gridBroadphaseCL= \
|
||||
" __global float4* pAABB, \n"
|
||||
" __global int* pPairBuff,\n"
|
||||
" __global int2* pPairBuffStartCurr,\n"
|
||||
" __global float4* pParams)\n"
|
||||
" __global float4* pParams,\n"
|
||||
" volatile __global int* pairCount,\n"
|
||||
" __global int4* pPairBuff2\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
" int4 pGridDim = *((__global int4*)(pParams + 1));\n"
|
||||
" int maxBodiesPerCell = pGridDim.w;\n"
|
||||
@@ -129,40 +129,61 @@ static const char* gridBroadphaseCL= \
|
||||
" break; // no longer in same bucket\n"
|
||||
" }\n"
|
||||
" int unsorted_indx2 = cellData.y;\n"
|
||||
" if (unsorted_indx2 < unsorted_indx) // check not colliding with self\n"
|
||||
" //if (unsorted_indx2 < unsorted_indx) // check not colliding with self\n"
|
||||
" if (unsorted_indx2 != unsorted_indx) // check not colliding with self\n"
|
||||
" { \n"
|
||||
" float4 min1 = pAABB[unsorted_indx2*2 + 0];\n"
|
||||
" float4 max1 = pAABB[unsorted_indx2*2 + 1];\n"
|
||||
" if(testAABBOverlap(min0, max0, min1, max1))\n"
|
||||
" {\n"
|
||||
" int handleIndex2 = as_int(min1.w);\n"
|
||||
" int k;\n"
|
||||
" for(k = 0; k < curr; k++)\n"
|
||||
" if (pairCount)\n"
|
||||
" {\n"
|
||||
" int old_pair = pPairBuff[start+k] & (~0x60000000);\n"
|
||||
" if(old_pair == handleIndex2)\n"
|
||||
" int handleIndex2 = as_int(min1.w);\n"
|
||||
" if (handleIndex<handleIndex2)\n"
|
||||
" {\n"
|
||||
" pPairBuff[start+k] |= 0x40000000;\n"
|
||||
" break;\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"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" if(k == curr)\n"
|
||||
" \n"
|
||||
" } else\n"
|
||||
" {\n"
|
||||
" if(curr >= curr_max) \n"
|
||||
" { // not a good solution, but let's avoid crash\n"
|
||||
" break;\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"
|
||||
" pPairBuff[start+curr] = handleIndex2 | 0x20000000;\n"
|
||||
" curr++;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" int2 newStartCurr;\n"
|
||||
" newStartCurr.x = start;\n"
|
||||
" newStartCurr.y = curr;\n"
|
||||
" pPairBuffStartCurr[handleIndex] = newStartCurr;\n"
|
||||
" return;\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"
|
||||
@@ -170,7 +191,10 @@ static const char* gridBroadphaseCL= \
|
||||
" __global int* pCellStart, \n"
|
||||
" __global int* pPairBuff, \n"
|
||||
" __global int2* pPairBuffStartCurr, \n"
|
||||
" __global float4* pParams )\n"
|
||||
" __global float4* pParams ,\n"
|
||||
" volatile __global int* pairCount,\n"
|
||||
" __global int4* pPairBuff2\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
" int index = get_global_id(0);\n"
|
||||
" if(index >= numObjects)\n"
|
||||
@@ -198,7 +222,7 @@ 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);\n"
|
||||
" findPairsInCell(numObjects, gridPosB, index, pHash, pCellStart, pAABB, pPairBuff, pPairBuffStartCurr, pParams, pairCount,pPairBuff2);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
|
||||
Reference in New Issue
Block a user