experiment with first-level batching using object index instead of spatial hash in uniform grid (to avoid tuning average object size for uniform grid)

This commit is contained in:
erwin coumans
2013-05-03 01:14:34 -07:00
parent 6ee9eb9bb5
commit 1185de51d5
7 changed files with 211 additions and 15 deletions

View File

@@ -451,6 +451,34 @@ static const char* solverSetup2CL= \
" int m_nSplit;\n"
"} ConstBufferSSD;\n"
"\n"
"\n"
"static const int gridTable4x4[] = \n"
"{\n"
" 0,1,17,16,\n"
" 1,2,18,19,\n"
" 17,18,32,3,\n"
" 16,19,3,34\n"
"};\n"
"\n"
"static const int gridTable8x8[] = \n"
"{\n"
" 0, 2, 3, 16, 17, 18, 19, 1,\n"
" 66, 64, 80, 67, 82, 81, 65, 83,\n"
" 131,144,128,130,147,129,145,146,\n"
" 208,195,194,192,193,211,210,209,\n"
" 21, 22, 23, 5, 4, 6, 7, 20,\n"
" 86, 85, 69, 87, 70, 68, 84, 71,\n"
" 151,133,149,150,135,148,132,134,\n"
" 197,27,214,213,212,199,198,196\n"
" \n"
"};\n"
"\n"
"\n"
"\n"
"\n"
"#define USE_SPATIAL_BATCHING 1\n"
"#define USE_4x4_GRID 1\n"
"\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void SetSortDataKernel(__global Contact4* gContact, __global Body* gBodies, __global int2* gSortDataOut, \n"
@@ -462,18 +490,47 @@ static const char* solverSetup2CL= \
" if( gIdx < nContacts )\n"
" {\n"
" int aPtrAndSignBit = gContact[gIdx].m_bodyAPtrAndSignBit;\n"
" int bPtrAndSignBit = gContact[gIdx].m_bodyBPtrAndSignBit;\n"
"\n"
" int aIdx = abs(aPtrAndSignBit );\n"
" int bIdx = abs(gContact[gIdx].m_bodyBPtrAndSignBit);\n"
" int bIdx = abs(bPtrAndSignBit);\n"
"\n"
" bool aStatic = (aPtrAndSignBit<0) ||(aPtrAndSignBit==staticIdx);\n"
" \n"
" bool bStatic = (bPtrAndSignBit<0) ||(bPtrAndSignBit==staticIdx);\n"
"\n"
"#if USE_SPATIAL_BATCHING \n"
" int idx = (aStatic)? bIdx: aIdx;\n"
" float4 p = gBodies[idx].m_pos;\n"
" int xIdx = (int)((p.x-((p.x<0.f)?1.f:0.f))*scale) & (N_SPLIT-1);\n"
" int zIdx = (int)((p.z-((p.z<0.f)?1.f:0.f))*scale) & (N_SPLIT-1);\n"
" int newIndex = (xIdx+zIdx*N_SPLIT);\n"
" \n"
"#else//USE_SPATIAL_BATCHING\n"
" #if USE_4x4_GRID\n"
" int aa = aIdx&3;\n"
" int bb = bIdx&3;\n"
" if (aStatic)\n"
" aa = bb;\n"
" if (bStatic)\n"
" bb = aa;\n"
"\n"
" gSortDataOut[gIdx].x = (xIdx+zIdx*N_SPLIT);\n"
" int gridIndex = aa + bb*4;\n"
" int newIndex = gridTable4x4[gridIndex];\n"
" #else//USE_4x4_GRID\n"
" int aa = aIdx&7;\n"
" int bb = bIdx&7;\n"
" if (aStatic)\n"
" aa = bb;\n"
" if (bStatic)\n"
" bb = aa;\n"
"\n"
" int gridIndex = aa + bb*8;\n"
" int newIndex = gridTable8x8[gridIndex];\n"
" #endif//USE_4x4_GRID\n"
"#endif//USE_SPATIAL_BATCHING\n"
"\n"
"\n"
" gSortDataOut[gIdx].x = newIndex;\n"
" gSortDataOut[gIdx].y = gIdx;\n"
" }\n"
" else\n"