Vsync messing with my job system

Started by
33 comments, last by Ryan_001 7 years, 1 month ago

Try off?

Same deal.

Advertisement

I didn't catch that your rate limiter used a busy wait, sorry. How is that implemented?

This is run at the start of every frame:

if(!mTimer.isStarted())
{
    mTimer.start();
}

mTimer.update();

Profiler::beginFrame();

double dt = mTimer.getTimeSinceLastUpdate();

// Spin if FPS gets too high.
if(RenderOptions::getBool(RenderOptions::OPTION_FRAMERATE_CAP) && mMaxFramerate > 0)
{
    double minDeltaTime = 1.0 / (double)mMaxFramerate;

    while(dt < minDeltaTime)
    {
        mTimer.update();
        dt += mTimer.getTimeSinceLastUpdate();
    }
}

This is bizarre so you're probably going to have to share some job system code to find the problem.

Well if you want to look at my ugly scribblings then here you go. http://www.sourcedrive.net/basis_job_system.zip
The engine is organized into sub categories, each in their own folder. I am giving you the jobsystem and threading folders. The jobsystem code depends on the threading code in this case. The code should be fairly self explanatory I hope. Feel free to point out any gnarly things you find.
As for the problematic case. This is how I update the particle systems in their own jobs and finally wait for the job group to be finished:

for(ParticleSystem* ps : mUpdateList)
{
    ps->updateInJob(time, mUpdateJobGroupHandle);
}

bool success = JobSystem::waitForJobGroup(mUpdateJobGroupHandle, 10000);
BASIS_ASSERTD(success, "The particle system update job(s) timed out.");

ParticleSystem::updateInJob() looks like this:


void ParticleSystem::updateInJob(const Time& time, JobGroupHandle jobGroupHandle)
{
    mCurrentDeltaTime = (float)time.deltaTime;

    updatePendingStateChange();

    if (mState == ParticleSystem::StatePlaying)
    {
        JobSystem::scheduleJob(Basis::MakeDelegate(this, &ParticleSystem::updateJob), jobGroupHandle);
    }
}

I have plans to support adding multiple jobs to the system in one go instead of having to do loops like that, locking/unlocking the job system internals on every iteration. But then again, the system performs really well as long as I don't use VSync, so who knows how big of a problem it is.

I appreciate the help!

One more thing. When the PS update jobs are run there are no other jobs running in the system. There are a few jobs that run each frame but they are started after the PS jobs have run and they are waited for too. Also, in the test case I don't use any job priorities other than JobPriorityDefault.

It seems like it might be something with the particles code. Can you replace that with something else simpler to test it?

Is all the particle memory on the CPU only? Your not doing any kind of lock or anything from the GPU before updating the particles?

Have you tried replacing WaitForSingleObject() with a simple atomic flag/spin loop? If it is truly the cause of the problem, removing it entirely should indicate that.

This topic is closed to new replies.

Advertisement