Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck with CullingThreadPool #18

Open
nhy002 opened this issue Sep 11, 2019 · 3 comments
Open

Stuck with CullingThreadPool #18

nhy002 opened this issue Sep 11, 2019 · 3 comments

Comments

@nhy002
Copy link

nhy002 commented Sep 11, 2019

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

@lvvvmd
Copy link

lvvvmd commented Oct 10, 2020

same problem. stuck at flush, seem that Reset() work unexpectly where mWritePtr and mRenderPtrs are not reset at the same time.

@nhy002
Copy link
Author

nhy002 commented Oct 10, 2020

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

@lvvvmd
Copy link

lvvvmd commented Oct 13, 2020

Thanks a lot!

braxtons12 added a commit to braxtons12/MaskedOcclusionCulling that referenced this issue Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants