made the simulation deterministic
disable 'simdwidth' optimization for determinism (need to double-check) made the spatial batching 3D
This commit is contained in:
@@ -411,8 +411,8 @@ void BatchSolveKernelContact(__global Body* gBodies,
|
||||
__global int* gN,
|
||||
__global int* gOffsets,
|
||||
int maxBatch,
|
||||
int bIdx,
|
||||
int nSplit
|
||||
int cellBatch,
|
||||
int4 nSplit
|
||||
)
|
||||
{
|
||||
//__local int ldsBatchIdx[WG_SIZE+1];
|
||||
@@ -428,17 +428,29 @@ void BatchSolveKernelContact(__global Body* gBodies,
|
||||
//debugInfo[gIdx].m_valInt1 = GET_GROUP_SIZE;
|
||||
|
||||
|
||||
int xIdx = (wgIdx/(nSplit/2))*2 + (bIdx&1);
|
||||
int yIdx = (wgIdx%(nSplit/2))*2 + (bIdx>>1);
|
||||
int cellIdx = xIdx+yIdx*nSplit;
|
||||
int zIdx = (wgIdx/((nSplit.x*nSplit.y)/4))*2+((cellBatch&4)>>2);
|
||||
int remain= (wgIdx%((nSplit.x*nSplit.y)/4));
|
||||
int yIdx = (remain/(nSplit.x/2))*2 + ((cellBatch&2)>>1);
|
||||
int xIdx = (remain%(nSplit.x/2))*2 + (cellBatch&1);
|
||||
int cellIdx = xIdx+yIdx*nSplit.x+zIdx*(nSplit.x*nSplit.y);
|
||||
|
||||
//int xIdx = (wgIdx/(nSplit/2))*2 + (bIdx&1);
|
||||
//int yIdx = (wgIdx%(nSplit/2))*2 + (bIdx>>1);
|
||||
//int cellIdx = xIdx+yIdx*nSplit;
|
||||
|
||||
if( gN[cellIdx] == 0 )
|
||||
return;
|
||||
|
||||
|
||||
|
||||
const int start = gOffsets[cellIdx];
|
||||
const int end = start + gN[cellIdx];
|
||||
|
||||
|
||||
//if (lIdx==0)
|
||||
//printf("wgIdx = %d, start = %d, end=%d\n",wgIdx,start,end);
|
||||
|
||||
|
||||
if( lIdx == 0 )
|
||||
{
|
||||
ldsCurBatch = 0;
|
||||
@@ -456,6 +468,9 @@ void BatchSolveKernelContact(__global Body* gBodies,
|
||||
{
|
||||
if (gConstraints[idx].m_batchIdx == ldsCurBatch)
|
||||
{
|
||||
//if (wgIdx==0 && lIdx==0)
|
||||
//printf("solved wgIdx=%d, ldsCurBatch=%d idx=%d \n", wgIdx, ldsCurBatch,idx);
|
||||
|
||||
solveContactConstraint( gBodies, gShapes, &gConstraints[idx] );
|
||||
|
||||
idx+=64;
|
||||
@@ -465,6 +480,8 @@ void BatchSolveKernelContact(__global Body* gBodies,
|
||||
}
|
||||
}
|
||||
GROUP_LDS_BARRIER;
|
||||
// if (wgIdx==0 && lIdx==0)
|
||||
// printf("-----------------------\n");
|
||||
if( lIdx == 0 )
|
||||
{
|
||||
ldsCurBatch++;
|
||||
|
||||
@@ -413,8 +413,8 @@ static const char* solveContactCL= \
|
||||
" __global int* gN,\n"
|
||||
" __global int* gOffsets,\n"
|
||||
" int maxBatch,\n"
|
||||
" int bIdx,\n"
|
||||
" int nSplit\n"
|
||||
" int cellBatch,\n"
|
||||
" int4 nSplit\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
" //__local int ldsBatchIdx[WG_SIZE+1];\n"
|
||||
@@ -430,17 +430,29 @@ static const char* solveContactCL= \
|
||||
" //debugInfo[gIdx].m_valInt1 = GET_GROUP_SIZE;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" int xIdx = (wgIdx/(nSplit/2))*2 + (bIdx&1);\n"
|
||||
" int yIdx = (wgIdx%(nSplit/2))*2 + (bIdx>>1);\n"
|
||||
" int cellIdx = xIdx+yIdx*nSplit;\n"
|
||||
" int zIdx = (wgIdx/((nSplit.x*nSplit.y)/4))*2+((cellBatch&4)>>2);\n"
|
||||
" int remain= (wgIdx%((nSplit.x*nSplit.y)/4));\n"
|
||||
" int yIdx = (remain/(nSplit.x/2))*2 + ((cellBatch&2)>>1);\n"
|
||||
" int xIdx = (remain%(nSplit.x/2))*2 + (cellBatch&1);\n"
|
||||
" int cellIdx = xIdx+yIdx*nSplit.x+zIdx*(nSplit.x*nSplit.y);\n"
|
||||
"\n"
|
||||
" //int xIdx = (wgIdx/(nSplit/2))*2 + (bIdx&1);\n"
|
||||
" //int yIdx = (wgIdx%(nSplit/2))*2 + (bIdx>>1);\n"
|
||||
" //int cellIdx = xIdx+yIdx*nSplit;\n"
|
||||
" \n"
|
||||
" if( gN[cellIdx] == 0 ) \n"
|
||||
" return;\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" const int start = gOffsets[cellIdx];\n"
|
||||
" const int end = start + gN[cellIdx];\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" //if (lIdx==0)\n"
|
||||
" //printf(\"wgIdx = %d, start = %d, end=%d\n\",wgIdx,start,end);\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" if( lIdx == 0 )\n"
|
||||
" {\n"
|
||||
" ldsCurBatch = 0;\n"
|
||||
@@ -458,6 +470,9 @@ static const char* solveContactCL= \
|
||||
" {\n"
|
||||
" if (gConstraints[idx].m_batchIdx == ldsCurBatch)\n"
|
||||
" {\n"
|
||||
" //if (wgIdx==0 && lIdx==0)\n"
|
||||
" //printf(\"solved wgIdx=%d, ldsCurBatch=%d idx=%d \n\", wgIdx, ldsCurBatch,idx);\n"
|
||||
" \n"
|
||||
" solveContactConstraint( gBodies, gShapes, &gConstraints[idx] );\n"
|
||||
"\n"
|
||||
" idx+=64;\n"
|
||||
@@ -467,6 +482,8 @@ static const char* solveContactCL= \
|
||||
" }\n"
|
||||
" }\n"
|
||||
" GROUP_LDS_BARRIER;\n"
|
||||
" // if (wgIdx==0 && lIdx==0)\n"
|
||||
" // printf(\"-----------------------\n\");\n"
|
||||
" if( lIdx == 0 )\n"
|
||||
" {\n"
|
||||
" ldsCurBatch++;\n"
|
||||
|
||||
@@ -440,8 +440,8 @@ void BatchSolveKernelFriction(__global Body* gBodies,
|
||||
__global int* gN,
|
||||
__global int* gOffsets,
|
||||
int maxBatch,
|
||||
int bIdx,
|
||||
int nSplit
|
||||
int cellBatch,
|
||||
int4 nSplit
|
||||
)
|
||||
{
|
||||
//__local int ldsBatchIdx[WG_SIZE+1];
|
||||
@@ -457,9 +457,12 @@ void BatchSolveKernelFriction(__global Body* gBodies,
|
||||
//debugInfo[gIdx].m_valInt1 = GET_GROUP_SIZE;
|
||||
|
||||
|
||||
int xIdx = (wgIdx/(nSplit/2))*2 + (bIdx&1);
|
||||
int yIdx = (wgIdx%(nSplit/2))*2 + (bIdx>>1);
|
||||
int cellIdx = xIdx+yIdx*nSplit;
|
||||
int zIdx = (wgIdx/((nSplit.x*nSplit.y)/4))*2+((cellBatch&4)>>2);
|
||||
int remain= (wgIdx%((nSplit.x*nSplit.y)/4));
|
||||
int yIdx = (remain/(nSplit.x/2))*2 + ((cellBatch&2)>>1);
|
||||
int xIdx = (remain%(nSplit.x/2))*2 + (cellBatch&1);
|
||||
int cellIdx = xIdx+yIdx*nSplit.x+zIdx*(nSplit.x*nSplit.y);
|
||||
|
||||
|
||||
if( gN[cellIdx] == 0 )
|
||||
return;
|
||||
|
||||
@@ -442,8 +442,8 @@ static const char* solveFrictionCL= \
|
||||
" __global int* gN,\n"
|
||||
" __global int* gOffsets,\n"
|
||||
" int maxBatch,\n"
|
||||
" int bIdx,\n"
|
||||
" int nSplit\n"
|
||||
" int cellBatch,\n"
|
||||
" int4 nSplit\n"
|
||||
" )\n"
|
||||
"{\n"
|
||||
" //__local int ldsBatchIdx[WG_SIZE+1];\n"
|
||||
@@ -459,9 +459,12 @@ static const char* solveFrictionCL= \
|
||||
" //debugInfo[gIdx].m_valInt1 = GET_GROUP_SIZE;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" int xIdx = (wgIdx/(nSplit/2))*2 + (bIdx&1);\n"
|
||||
" int yIdx = (wgIdx%(nSplit/2))*2 + (bIdx>>1);\n"
|
||||
" int cellIdx = xIdx+yIdx*nSplit;\n"
|
||||
" int zIdx = (wgIdx/((nSplit.x*nSplit.y)/4))*2+((cellBatch&4)>>2);\n"
|
||||
" int remain= (wgIdx%((nSplit.x*nSplit.y)/4));\n"
|
||||
" int yIdx = (remain/(nSplit.x/2))*2 + ((cellBatch&2)>>1);\n"
|
||||
" int xIdx = (remain%(nSplit.x/2))*2 + (cellBatch&1);\n"
|
||||
" int cellIdx = xIdx+yIdx*nSplit.x+zIdx*(nSplit.x*nSplit.y);\n"
|
||||
"\n"
|
||||
" \n"
|
||||
" if( gN[cellIdx] == 0 ) \n"
|
||||
" return;\n"
|
||||
|
||||
@@ -441,6 +441,42 @@ void ReorderContactKernel(__global Contact4* in, __global Contact4* out, __globa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__kernel
|
||||
__attribute__((reqd_work_group_size(WG_SIZE,1,1)))
|
||||
void SetDeterminismSortDataBodyA(__global Contact4* contactsIn, __global int2* sortDataOut, int nContacts)
|
||||
{
|
||||
int gIdx = GET_GLOBAL_IDX;
|
||||
|
||||
if( gIdx < nContacts )
|
||||
{
|
||||
int2 sd;
|
||||
sd.x = contactsIn[gIdx].m_bodyAPtrAndSignBit;
|
||||
sd.y = gIdx;
|
||||
sortDataOut[gIdx] = sd;
|
||||
}
|
||||
}
|
||||
|
||||
__kernel
|
||||
__attribute__((reqd_work_group_size(WG_SIZE,1,1)))
|
||||
void SetDeterminismSortDataBodyB(__global Contact4* contactsIn, __global int2* sortDataInOut, int nContacts)
|
||||
{
|
||||
int gIdx = GET_GLOBAL_IDX;
|
||||
|
||||
if( gIdx < nContacts )
|
||||
{
|
||||
int2 sdIn;
|
||||
sdIn = sortDataInOut[gIdx];
|
||||
int2 sdOut;
|
||||
sdOut.x = contactsIn[sdIn.y].m_bodyBPtrAndSignBit;
|
||||
sdOut.y = sdIn.y;
|
||||
sortDataInOut[gIdx] = sdOut;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int m_nContacts;
|
||||
@@ -480,7 +516,7 @@ static __constant const int gridTable8x8[] =
|
||||
__kernel
|
||||
__attribute__((reqd_work_group_size(WG_SIZE,1,1)))
|
||||
void SetSortDataKernel(__global Contact4* gContact, __global Body* gBodies, __global int2* gSortDataOut,
|
||||
int nContacts,float scale,int N_SPLIT, int staticIdx)
|
||||
int nContacts,float scale,int4 nSplit,int staticIdx)
|
||||
|
||||
{
|
||||
int gIdx = GET_GLOBAL_IDX;
|
||||
@@ -499,9 +535,10 @@ int nContacts,float scale,int N_SPLIT, int staticIdx)
|
||||
#if USE_SPATIAL_BATCHING
|
||||
int idx = (aStatic)? bIdx: aIdx;
|
||||
float4 p = gBodies[idx].m_pos;
|
||||
int xIdx = (int)((p.x-((p.x<0.f)?1.f:0.f))*scale) & (N_SPLIT-1);
|
||||
int zIdx = (int)((p.z-((p.z<0.f)?1.f:0.f))*scale) & (N_SPLIT-1);
|
||||
int newIndex = (xIdx+zIdx*N_SPLIT);
|
||||
int xIdx = (int)((p.x-((p.x<0.f)?1.f:0.f))*scale) & (nSplit.x-1);
|
||||
int yIdx = (int)((p.y-((p.y<0.f)?1.f:0.f))*scale) & (nSplit.y-1);
|
||||
int zIdx = (int)((p.z-((p.z<0.f)?1.f:0.f))*scale) & (nSplit.z-1);
|
||||
int newIndex = (xIdx+yIdx*nSplit.x+zIdx*nSplit.x*nSplit.y);
|
||||
|
||||
#else//USE_SPATIAL_BATCHING
|
||||
#if USE_4x4_GRID
|
||||
|
||||
@@ -443,6 +443,42 @@ static const char* solverSetup2CL= \
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"__kernel\n"
|
||||
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
|
||||
"void SetDeterminismSortDataBodyA(__global Contact4* contactsIn, __global int2* sortDataOut, int nContacts)\n"
|
||||
"{\n"
|
||||
" int gIdx = GET_GLOBAL_IDX;\n"
|
||||
"\n"
|
||||
" if( gIdx < nContacts )\n"
|
||||
" {\n"
|
||||
" int2 sd;\n"
|
||||
" sd.x = contactsIn[gIdx].m_bodyAPtrAndSignBit;\n"
|
||||
" sd.y = gIdx;\n"
|
||||
" sortDataOut[gIdx] = sd;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"__kernel\n"
|
||||
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
|
||||
"void SetDeterminismSortDataBodyB(__global Contact4* contactsIn, __global int2* sortDataInOut, int nContacts)\n"
|
||||
"{\n"
|
||||
" int gIdx = GET_GLOBAL_IDX;\n"
|
||||
"\n"
|
||||
" if( gIdx < nContacts )\n"
|
||||
" {\n"
|
||||
" int2 sdIn;\n"
|
||||
" sdIn = sortDataInOut[gIdx];\n"
|
||||
" int2 sdOut;\n"
|
||||
" sdOut.x = contactsIn[sdIn.y].m_bodyBPtrAndSignBit;\n"
|
||||
" sdOut.y = sdIn.y;\n"
|
||||
" sortDataInOut[gIdx] = sdOut;\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"typedef struct\n"
|
||||
"{\n"
|
||||
" int m_nContacts;\n"
|
||||
@@ -482,7 +518,7 @@ static const char* solverSetup2CL= \
|
||||
"__kernel\n"
|
||||
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
|
||||
"void SetSortDataKernel(__global Contact4* gContact, __global Body* gBodies, __global int2* gSortDataOut, \n"
|
||||
"int nContacts,float scale,int N_SPLIT, int staticIdx)\n"
|
||||
"int nContacts,float scale,int4 nSplit,int staticIdx)\n"
|
||||
"\n"
|
||||
"{\n"
|
||||
" int gIdx = GET_GLOBAL_IDX;\n"
|
||||
@@ -501,9 +537,10 @@ static const char* solverSetup2CL= \
|
||||
"#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"
|
||||
" int xIdx = (int)((p.x-((p.x<0.f)?1.f:0.f))*scale) & (nSplit.x-1);\n"
|
||||
" int yIdx = (int)((p.y-((p.y<0.f)?1.f:0.f))*scale) & (nSplit.y-1);\n"
|
||||
" int zIdx = (int)((p.z-((p.z<0.f)?1.f:0.f))*scale) & (nSplit.z-1);\n"
|
||||
" int newIndex = (xIdx+yIdx*nSplit.x+zIdx*nSplit.x*nSplit.y);\n"
|
||||
" \n"
|
||||
"#else//USE_SPATIAL_BATCHING\n"
|
||||
" #if USE_4x4_GRID\n"
|
||||
|
||||
Reference in New Issue
Block a user