Skip to content

Commit 3ef317b

Browse files
committed
perf: DX9Ex frame latency improvements
prioritize GPU thread and use DX9 driver to force frame sync if available
1 parent 2bbdda8 commit 3ef317b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/materialsystem/shaderapidx9/shaderdevicedx8.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,15 @@ bool CShaderDeviceDx8::CreateD3DDevice( void* pHWnd, int nAdapter, const ShaderD
24012401

24022402
g_pHardwareConfig->SetupHardwareCaps( info, g_ShaderDeviceMgrDx8.GetHardwareCaps( nAdapter ) );
24032403

2404+
#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9)
2405+
if ( g_ShaderDeviceUsingD3D9Ex )
2406+
{
2407+
Dx9ExDevice()->SetMaximumFrameLatency(1);
2408+
static ConVarRef mat_forcehardwaresync("mat_forcehardwaresync");
2409+
mat_forcehardwaresync.SetValue(0);
2410+
}
2411+
#endif
2412+
24042413
// FIXME: Bake this into hardware config
24052414
// What texture formats do we support?
24062415
if ( D3DSupportsCompressedTextures() )
@@ -3371,20 +3380,35 @@ void CShaderDeviceDx8::Present()
33713380
// if we're in queued mode, don't present if the device is already lost
33723381
bool bValidPresent = true;
33733382
bool bInMainThread = ThreadInMainThread();
3374-
if ( !bInMainThread )
3383+
static bool s_bSetPriority = true;
3384+
if ( bInMainThread )
3385+
{
3386+
s_bSetPriority = true;
3387+
}
3388+
else
33753389
{
33763390
// don't present if the device is in an invalid state and in queued mode
33773391
if ( m_DeviceState != DEVICE_STATE_OK )
33783392
{
3393+
s_bSetPriority = true;
33793394
bValidPresent = false;
33803395
}
33813396
// check for lost device early in threaded mode
33823397
CheckDeviceLost( m_bOtherAppInitializing );
33833398
if ( m_DeviceState != DEVICE_STATE_OK )
33843399
{
3400+
s_bSetPriority = true;
33853401
bValidPresent = false;
33863402
}
33873403
}
3404+
#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9)
3405+
if ( bValidPresent && s_bSetPriority && g_ShaderDeviceUsingD3D9Ex )
3406+
{
3407+
s_bSetPriority = false;
3408+
Dx9ExDevice()->SetGPUThreadPriority(7);
3409+
Dx9ExDevice()->SetMaximumFrameLatency(1);
3410+
}
3411+
#endif
33883412
// Copy the back buffer into the non-interactive temp buffer
33893413
if ( m_NonInteractiveRefresh.m_Mode == MATERIAL_NON_INTERACTIVE_MODE_LEVEL_LOAD )
33903414
{

src/materialsystem/shaderapidx9/shaderdevicedx8.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ class CShaderDeviceMgrDx8 : public CShaderDeviceMgrBase
128128
bool m_bObeyDxCommandlineOverride : 1;
129129
bool m_bAdapterInfoIntialized : 1;
130130
};
131-
131+
#if defined(IS_WINDOWS_PC) && defined(SHADERAPIDX9)
132+
FORCEINLINE IDirect3DDevice9Ex* Dx9ExDevice()
133+
{
134+
return (IDirect3DDevice9Ex*)g_pD3DDevice;
135+
}
136+
#endif
137+
`
132138
extern CShaderDeviceMgrDx8* g_pShaderDeviceMgrDx8;
133139

134140

0 commit comments

Comments
 (0)