From 10efa56c58dd2aad821eb9ba53c6bd775c7e8ebf Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:27:02 +0200 Subject: [PATCH] Engine: don't run NVIDIA Reflex if -gfx_disableLowLatency was specified This command line argument should fully disable NVIDIA Reflex, AMD Anti-Lag 2 and PCL statistics. --- src/engine/sys_dll2.cpp | 2 +- src/geforce/reflex.cpp | 25 ++++++++++++++++++++++--- src/geforce/reflex.h | 5 ++++- src/materialsystem/cmaterialsystem.cpp | 5 ++++- src/radeon/antilag.cpp | 2 ++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/engine/sys_dll2.cpp b/src/engine/sys_dll2.cpp index 522ccb4d..ee99a5e5 100644 --- a/src/engine/sys_dll2.cpp +++ b/src/engine/sys_dll2.cpp @@ -234,7 +234,7 @@ void CEngineAPI::UpdateLowLatencyParameters() void CEngineAPI::RunLowLatencyFrame() { #ifndef DEDICATED - if (GeForce_IsLowLatencySDKEnabled()) + if (GeForce_IsLowLatencySDKAvailable()) { if (GeForce_HasPendingLowLatencyParameterUpdates()) { diff --git a/src/geforce/reflex.cpp b/src/geforce/reflex.cpp index f157be08..f6db3894 100644 --- a/src/geforce/reflex.cpp +++ b/src/geforce/reflex.cpp @@ -9,6 +9,8 @@ static bool s_LowLatencySDKEnabled = false; +static bool s_LowLatencyAvailable = false; + // If false, the system will call 'NvAPI_D3D_SetSleepMode' to update the parameters. static bool s_ReflexModeInfoUpToDate = false; @@ -31,9 +33,9 @@ void GeForce_EnableLowLatencySDK(const bool enable) //----------------------------------------------------------------------------- // Purpose: whether we should run the low latency SDK //----------------------------------------------------------------------------- -bool GeForce_IsLowLatencySDKEnabled(void) +bool GeForce_IsLowLatencySDKAvailable(void) { - if (!s_LowLatencySDKEnabled) + if (!s_LowLatencySDKEnabled || !s_LowLatencyAvailable) return false; const MaterialAdapterInfo_t& adapterInfo = g_pMaterialAdapterMgr->GetAdapterInfo(); @@ -42,6 +44,23 @@ bool GeForce_IsLowLatencySDKEnabled(void) return adapterInfo.m_VendorID == NVIDIA_VENDOR_ID; } +//----------------------------------------------------------------------------- +// Purpose: initialize the low latency SDK +//----------------------------------------------------------------------------- +bool GeForce_InitLowLatencySDK(void) +{ + s_LowLatencyAvailable = true; + return s_LowLatencyAvailable; +} + +//----------------------------------------------------------------------------- +// Purpose: shutdown the low latency SDK +//----------------------------------------------------------------------------- +void GeForce_ShutdownLowLatencySDK(void) +{ + s_LowLatencyAvailable = false; +} + //----------------------------------------------------------------------------- // Purpose: mark the parameters as out-of-date; force update next frame //----------------------------------------------------------------------------- @@ -126,7 +145,7 @@ void GeForce_SetLatencyMarker(IUnknown* const device, { Assert(device); - if (GeForce_ParameterUpdateWasSuccessful() && GeForce_IsLowLatencySDKEnabled()) + if (GeForce_ParameterUpdateWasSuccessful() && GeForce_IsLowLatencySDKAvailable()) { NV_LATENCY_MARKER_PARAMS params = {}; params.version = NV_LATENCY_MARKER_PARAMS_VER1; diff --git a/src/geforce/reflex.h b/src/geforce/reflex.h index 696f745d..07d8ae38 100644 --- a/src/geforce/reflex.h +++ b/src/geforce/reflex.h @@ -4,7 +4,10 @@ extern bool g_PCLStatsAvailable; void GeForce_EnableLowLatencySDK(const bool enable); -bool GeForce_IsLowLatencySDKEnabled(void); +bool GeForce_IsLowLatencySDKAvailable(void); + +bool GeForce_InitLowLatencySDK(void); +void GeForce_ShutdownLowLatencySDK(void); void GeForce_MarkLowLatencyParametersOutOfDate(void); bool GeForce_HasPendingLowLatencyParameterUpdates(void); diff --git a/src/materialsystem/cmaterialsystem.cpp b/src/materialsystem/cmaterialsystem.cpp index 158705f4..d0402221 100644 --- a/src/materialsystem/cmaterialsystem.cpp +++ b/src/materialsystem/cmaterialsystem.cpp @@ -11,6 +11,7 @@ #include "rtech/pak/pakstate.h" #include "engine/cmodel_bsp.h" #include "engine/sys_engine.h" +#include "engine/sys_dll2.h" #include "geforce/reflex.h" #include "radeon/antilag.h" #ifndef MATERIALSYSTEM_NODX @@ -61,9 +62,10 @@ InitReturnVal_t CMaterialSystem::Init(CMaterialSystem* thisptr) if (s_useLowLatency) { + GeForce_InitLowLatencySDK(); Radeon_InitLowLatencySDK(); - PCLSTATS_INIT(0); + PCLSTATS_INIT(0); g_PCLStatsAvailable = true; } @@ -83,6 +85,7 @@ int CMaterialSystem::Shutdown(CMaterialSystem* thisptr) PCLSTATS_SHUTDOWN(); Radeon_ShutdownLowLatencySDK(); + GeForce_ShutdownLowLatencySDK(); } #endif diff --git a/src/radeon/antilag.cpp b/src/radeon/antilag.cpp index 453cddff..907fa640 100644 --- a/src/radeon/antilag.cpp +++ b/src/radeon/antilag.cpp @@ -28,6 +28,8 @@ void Radeon_EnableLowLatencySDK(const bool enable) //----------------------------------------------------------------------------- bool Radeon_IsLowLatencySDKAvailable(void) { + // NOTE: don't check on s_LowLatencySDKEnabled here as this needs to be + // provided to the driver itself. if (!s_LowLatencyAvailable) return false;