Move NVIDIA Reflex implementation to library function

Improve code, there will be more NVIDIA GeForce related stuff soon.
This commit is contained in:
Kawe Mazidjatari 2023-09-12 00:08:46 +02:00
parent 85de096f98
commit 804f96625b
6 changed files with 61 additions and 16 deletions

View File

@ -15,6 +15,7 @@ add_subdirectory( vstdlib )
add_subdirectory( vphysics )
add_subdirectory( ebisusdk )
add_subdirectory( codecs )
add_subdirectory( geforce )
set( FOLDER_CONTEXT "Protocols" )
add_subdirectory( protoc )

View File

@ -76,6 +76,7 @@ target_link_libraries( ${PROJECT_NAME} PRIVATE
"filesystem"
"datacache"
"EbisuSDK"
"GFSDK"
"localize"

View File

@ -19,6 +19,7 @@
#include "engine/sys_mainwind.h"
#include "windows/id3dx.h"
#include "client/vengineclient_impl.h"
#include "geforce/reflex.h"
#endif // !DEDICATED
#include "rtech/rtech_utils.h"
#include "filesystem/filesystem.h"
@ -191,22 +192,7 @@ bool CEngineAPI::MainLoop()
fpsMax = 0.0f; // Don't let NVIDIA limit the frame rate.
}
NV_SET_SLEEP_MODE_PARAMS_V1 params = {};
params.version = NV_SET_SLEEP_MODE_PARAMS_VER1;
params.bLowLatencyMode = bUseLowLatencyMode;
params.bLowLatencyBoost = bUseLowLatencyMode && bUseLowLatencyBoost;
params.minimumIntervalUs = fpsMax > 0 ? (NvU32)((1000.0f / fpsMax) * 1000.0f) : 0;
params.bUseMarkersToOptimize = false;
ID3D11Device* pGameDevice = D3D11Device();
Assert(pGameDevice);
NvAPI_Status status = NvAPI_D3D_SetSleepMode(pGameDevice, &params);
if (status == NVAPI_OK)
NvAPI_D3D_Sleep(pGameDevice);
GFX_RunLowLatencySDK(D3D11Device(), bUseLowLatencyMode, bUseLowLatencyBoost, fpsMax);
CEngineAPI_PumpMessages();
#endif // !DEDICATED

View File

@ -0,0 +1,13 @@
cmake_minimum_required( VERSION 3.16 )
add_module( "lib" "GFSDK" "vpc" ${FOLDER_CONTEXT} TRUE TRUE )
start_sources()
add_sources( SOURCE_GROUP "Runtime"
"reflex.cpp"
"reflex.h"
)
end_sources()
target_include_directories( ${PROJECT_NAME} PRIVATE "${ENGINE_SOURCE_DIR}/tier0/" "${ENGINE_SOURCE_DIR}/tier1/" )

37
r5dev/geforce/reflex.cpp Normal file
View File

@ -0,0 +1,37 @@
//===========================================================================//
//
// Purpose: NVIDIA Reflex utilities
//
//===========================================================================//
#include "reflex.h"
#include "mathlib/mathlib.h"
//-----------------------------------------------------------------------------
// Purpose: runs the low latency sdk
// Input : device -
// useLowLatencyMode -
// useLowLatencyBoost -
// maxFramesPerSecond -
//-----------------------------------------------------------------------------
void GFX_RunLowLatencySDK(IUnknown* device, const bool useLowLatencyMode,
const bool useLowLatencyBoost, const float maxFramesPerSecond)
{
Assert(device);
Assert(IsFinite(maxFramesPerSecond));
NV_SET_SLEEP_MODE_PARAMS params = {};
params.version = NV_SET_SLEEP_MODE_PARAMS_VER1;
params.bLowLatencyMode = useLowLatencyMode;
params.bLowLatencyBoost = useLowLatencyMode && useLowLatencyBoost;
params.minimumIntervalUs = maxFramesPerSecond > 0
? (NvU32)((1000.0f / maxFramesPerSecond) * 1000.0f)
: 0;
params.bUseMarkersToOptimize = false;
NvAPI_Status status = NvAPI_D3D_SetSleepMode(device, &params);
if (status == NVAPI_OK)
NvAPI_D3D_Sleep(device);
}

7
r5dev/geforce/reflex.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef GFSDK_REFLEX_H
#define GFSDK_REFLEX_H
void GFX_RunLowLatencySDK(IUnknown* device, const bool useLowLatencyMode,
const bool useLowLatencyBoost, const float maxFramesPerSecond);
#endif // GFSDK_REFLEX_H