Skip to content

Commit

Permalink
thread scheduling BOOST
Browse files Browse the repository at this point in the history
dont constantly set gpu thread priority
fix fps limiter
  • Loading branch information
mastercoms committed Oct 8, 2020
1 parent 553015a commit 17a1425
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion engine/sys_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void CEngine::Frame( void )
// If we are meeting our frame rate then go idle for a while
// to avoid wasting power and to let other threads/processes run.
// Calculate how long we need to wait.
unsigned nSleepMS = (unsigned)((m_flMinFrameTime - m_flFrameTime) * 1000 - fBusyWaitMS);
int nSleepMS = (int)((m_flMinFrameTime - m_flFrameTime) * 1000 - fBusyWaitMS);
if ( nSleepMS > fBusyWaitMS )
{
ThreadSleep(nSleepMS);
Expand Down
21 changes: 12 additions & 9 deletions materialsystem/shaderapidx9/shaderdevicedx8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3369,7 +3369,6 @@ void CShaderDeviceDx8::RefreshFrontBufferNonInteractive()
#endif
}


//-----------------------------------------------------------------------------
// Page flip
//-----------------------------------------------------------------------------
Expand All @@ -3390,22 +3389,30 @@ void CShaderDeviceDx8::Present()
// if we're in queued mode, don't present if the device is already lost
bool bValidPresent = true;
bool bInMainThread = ThreadInMainThread();
if ( !bInMainThread )
static bool s_bSetPriority = true;
if ( bInMainThread )
{
s_bSetPriority = true;
}
else
{
// don't present if the device is in an invalid state and in queued mode
if ( m_DeviceState != DEVICE_STATE_OK )
{
s_bSetPriority = true;
bValidPresent = false;
}
// check for lost device early in threaded mode
CheckDeviceLost( m_bOtherAppInitializing );
if ( m_DeviceState != DEVICE_STATE_OK )
{
s_bSetPriority = true;
bValidPresent = false;
}
#ifndef DX_TO_GL_ABSTRACTION
if (bValidPresent && g_ShaderDeviceUsingD3D9Ex)
if (s_bSetPriority && g_ShaderDeviceUsingD3D9Ex)
{
s_bSetPriority = false;
Dx9ExDevice()->SetGPUThreadPriority(7);
}
#endif
Expand Down Expand Up @@ -3447,13 +3454,9 @@ void CShaderDeviceDx8::Present()
{
g_pShaderAPI->OwnGPUResources( false );
#ifndef DX_TO_GL_ABSTRACTION
if (g_ShaderDeviceUsingD3D9Ex)
if (g_ShaderDeviceUsingD3D9Ex && m_PresentParameters.PresentationInterval != D3DPRESENT_INTERVAL_IMMEDIATE)
{
int flags = 0;
if (m_PresentParameters.PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE)
{
flags |= D3DPRESENT_DONOTWAIT;
}
int flags = D3DPRESENT_DONOTWAIT;
hr = Dx9ExDevice()->PresentEx(0, 0, 0, 0, flags);
}
else
Expand Down
4 changes: 1 addition & 3 deletions tier0/threadtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2580,9 +2580,7 @@ unsigned CWorkerThread::GetCallParam( CFunctor **ppParamFunctor ) const
int CWorkerThread::BoostPriority()
{
int iInitialPriority = GetPriority();
const int iNewPriority = ThreadGetPriority( (ThreadHandle_t)GetThreadID() );
if (iNewPriority > iInitialPriority)
ThreadSetPriority( (ThreadHandle_t)GetThreadID(), iNewPriority);
SetPriority(iInitialPriority + 1);
return iInitialPriority;
}

Expand Down
5 changes: 5 additions & 0 deletions vstdlib/jobthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ class CJobThread : public CWorkerThread
case TPM_RUNFUNCTOR:
if( pFunctor )
{
int iInitialPriority = BoostPriority();
( *pFunctor )();
Reply( true );
SetPriority(iInitialPriority);
}
else
{
Expand All @@ -436,6 +438,7 @@ class CJobThread : public CWorkerThread

CJob *pJob;
bool bTookJob = false;
int iInitialPriority;
do
{
if ( !m_DirectQueue.Pop( &pJob) )
Expand All @@ -448,6 +451,7 @@ class CJobThread : public CWorkerThread
}
if ( !bTookJob )
{
iInitialPriority = BoostPriority();
m_IdleEvent.Reset();
m_pOwner->m_nIdleThreads--;
bTookJob = true;
Expand All @@ -460,6 +464,7 @@ class CJobThread : public CWorkerThread
{
m_pOwner->m_nIdleThreads++;
m_IdleEvent.Set();
SetPriority(iInitialPriority);
}
}
}
Expand Down

0 comments on commit 17a1425

Please sign in to comment.