Skip to content

Commit 17a1425

Browse files
committed
thread scheduling BOOST
dont constantly set gpu thread priority fix fps limiter
1 parent 553015a commit 17a1425

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

engine/sys_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ void CEngine::Frame( void )
357357
// If we are meeting our frame rate then go idle for a while
358358
// to avoid wasting power and to let other threads/processes run.
359359
// Calculate how long we need to wait.
360-
unsigned nSleepMS = (unsigned)((m_flMinFrameTime - m_flFrameTime) * 1000 - fBusyWaitMS);
360+
int nSleepMS = (int)((m_flMinFrameTime - m_flFrameTime) * 1000 - fBusyWaitMS);
361361
if ( nSleepMS > fBusyWaitMS )
362362
{
363363
ThreadSleep(nSleepMS);

materialsystem/shaderapidx9/shaderdevicedx8.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,7 +3369,6 @@ void CShaderDeviceDx8::RefreshFrontBufferNonInteractive()
33693369
#endif
33703370
}
33713371

3372-
33733372
//-----------------------------------------------------------------------------
33743373
// Page flip
33753374
//-----------------------------------------------------------------------------
@@ -3390,22 +3389,30 @@ void CShaderDeviceDx8::Present()
33903389
// if we're in queued mode, don't present if the device is already lost
33913390
bool bValidPresent = true;
33923391
bool bInMainThread = ThreadInMainThread();
3393-
if ( !bInMainThread )
3392+
static bool s_bSetPriority = true;
3393+
if ( bInMainThread )
3394+
{
3395+
s_bSetPriority = true;
3396+
}
3397+
else
33943398
{
33953399
// don't present if the device is in an invalid state and in queued mode
33963400
if ( m_DeviceState != DEVICE_STATE_OK )
33973401
{
3402+
s_bSetPriority = true;
33983403
bValidPresent = false;
33993404
}
34003405
// check for lost device early in threaded mode
34013406
CheckDeviceLost( m_bOtherAppInitializing );
34023407
if ( m_DeviceState != DEVICE_STATE_OK )
34033408
{
3409+
s_bSetPriority = true;
34043410
bValidPresent = false;
34053411
}
34063412
#ifndef DX_TO_GL_ABSTRACTION
3407-
if (bValidPresent && g_ShaderDeviceUsingD3D9Ex)
3413+
if (s_bSetPriority && g_ShaderDeviceUsingD3D9Ex)
34083414
{
3415+
s_bSetPriority = false;
34093416
Dx9ExDevice()->SetGPUThreadPriority(7);
34103417
}
34113418
#endif
@@ -3447,13 +3454,9 @@ void CShaderDeviceDx8::Present()
34473454
{
34483455
g_pShaderAPI->OwnGPUResources( false );
34493456
#ifndef DX_TO_GL_ABSTRACTION
3450-
if (g_ShaderDeviceUsingD3D9Ex)
3457+
if (g_ShaderDeviceUsingD3D9Ex && m_PresentParameters.PresentationInterval != D3DPRESENT_INTERVAL_IMMEDIATE)
34513458
{
3452-
int flags = 0;
3453-
if (m_PresentParameters.PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE)
3454-
{
3455-
flags |= D3DPRESENT_DONOTWAIT;
3456-
}
3459+
int flags = D3DPRESENT_DONOTWAIT;
34573460
hr = Dx9ExDevice()->PresentEx(0, 0, 0, 0, flags);
34583461
}
34593462
else

tier0/threadtools.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,9 +2580,7 @@ unsigned CWorkerThread::GetCallParam( CFunctor **ppParamFunctor ) const
25802580
int CWorkerThread::BoostPriority()
25812581
{
25822582
int iInitialPriority = GetPriority();
2583-
const int iNewPriority = ThreadGetPriority( (ThreadHandle_t)GetThreadID() );
2584-
if (iNewPriority > iInitialPriority)
2585-
ThreadSetPriority( (ThreadHandle_t)GetThreadID(), iNewPriority);
2583+
SetPriority(iInitialPriority + 1);
25862584
return iInitialPriority;
25872585
}
25882586

vstdlib/jobthread.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,10 @@ class CJobThread : public CWorkerThread
414414
case TPM_RUNFUNCTOR:
415415
if( pFunctor )
416416
{
417+
int iInitialPriority = BoostPriority();
417418
( *pFunctor )();
418419
Reply( true );
420+
SetPriority(iInitialPriority);
419421
}
420422
else
421423
{
@@ -436,6 +438,7 @@ class CJobThread : public CWorkerThread
436438

437439
CJob *pJob;
438440
bool bTookJob = false;
441+
int iInitialPriority;
439442
do
440443
{
441444
if ( !m_DirectQueue.Pop( &pJob) )
@@ -448,6 +451,7 @@ class CJobThread : public CWorkerThread
448451
}
449452
if ( !bTookJob )
450453
{
454+
iInitialPriority = BoostPriority();
451455
m_IdleEvent.Reset();
452456
m_pOwner->m_nIdleThreads--;
453457
bTookJob = true;
@@ -460,6 +464,7 @@ class CJobThread : public CWorkerThread
460464
{
461465
m_pOwner->m_nIdleThreads++;
462466
m_IdleEvent.Set();
467+
SetPriority(iInitialPriority);
463468
}
464469
}
465470
}

0 commit comments

Comments
 (0)