Stuck with CullingThreadPool
The program got stuck when using CullingThreadPool, and going on with example code, I got the same problem after changing some code:
//FillrateTest.cpp line 424
for (int i = 0; i < numSizes; ++i)
{
int size = sizes[i];
//double t = BenchmarkTrianglesThreaded(verts[i], trisBtF[i], numTriangles[i], &ctp);
//change triangle count to 100
double t = BenchmarkTrianglesThreaded(verts[i], trisBtF[i], 100, &ctp);
double GPixelsPerSecond = (double)numTriangles[i] * size*size / (2.0 * 1e9 * t);
double MTrisPerSecond = (double)numTriangles[i] / (1e6 * t);
printf("Tri: %3dx%3d - Time: %7.2f ms, MTris/s: %6.2f GPixels/s: %5.2f \n", size, size, t * 1000.0f, MTrisPerSecond, GPixelsPerSecond);
}
//CullingThreadpool.cpp line 187
void CullingThreadpool::RenderJobQueue::Reset()
{
mWritePtr = 0;
mBinningPtr = 0;
for (unsigned int i = 0; i < mNumBins; ++i)
mRenderPtrs[i] = 0;
printf("checking..."); // just delay for a while using printf
for (unsigned int i = 0; i < mMaxJobs; ++i)
{
mJobs[i].mBinningJobCompletedIdx = -1;
mJobs[i].mBinningJobStartedIdx = -1;
}
}
run FillrateTest
same problem. stuck at flush, seem that Reset() work unexpectly where mWritePtr and mRenderPtrs are not reset at the same time.
I‘ve solved the problem by changing the order of some code
//CullingThreadpool.cpp line 187
void CullingThreadpool::RenderJobQueue::Reset()
{
mWritePtr = 0;
mBinningPtr = 0;
for (unsigned int i = 0; i < mNumBins; ++i)
mRenderPtrs[i] = 0;
for (unsigned int i = 0; i < mMaxJobs; ++i)
{
mJobs[i].mBinningJobCompletedIdx = -1;
mJobs[i].mBinningJobStartedIdx = -1;
}
}
//after fix
void CullingThreadpool::RenderJobQueue::Reset()
{
mWritePtr = 0;
mBinningPtr = 0;
for (unsigned int i = 0; i < mMaxJobs; ++i)
{
mJobs[i].mBinningJobCompletedIdx = -1;
mJobs[i].mBinningJobStartedIdx = -1;
}
//change the order
for (unsigned int i = 0; i < mNumBins; ++i)
mRenderPtrs[i] = 0;
}
There is another problem causing wrong culling result some object will be culled unexpected
//CullingThreadpool.cpp line 314
CullingThreadpool::CullingThreadpool(unsigned int numThreads, unsigned int binsW, unsigned int binsH, unsigned int maxJobs) :
mNumThreads(numThreads),
mMaxJobs(maxJobs),
mBinsW(binsW),
mBinsH(binsH),
mKillThreads(false),
mSuspendThreads(true),
mNumSuspendedThreads(0),
mModelToClipMatrices(maxJobs),
mVertexLayouts(maxJobs),
mMOC(nullptr)
{ ... }
//after fix
CullingThreadpool::CullingThreadpool(unsigned int numThreads, unsigned int binsW, unsigned int binsH, unsigned int maxJobs) :
mNumThreads(numThreads),
mMaxJobs(maxJobs),
mBinsW(binsW),
mBinsH(binsH),
mKillThreads(false),
mSuspendThreads(true),
mNumSuspendedThreads(0),
mModelToClipMatrices(maxJobs + 1),
mVertexLayouts(maxJobs + 1),
mMOC(nullptr)
{ ... }
finally,there are some threading problems can be found with turning on TSan on XCode I fixed these though they didn't cause perceptible problems
with fixing these problem, MOC with CullingThreadPool works fine in our engine
Thanks a lot!