aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gospodnetich <me@kylegospodneti.ch>2022-06-15 17:44:26 -0700
committerGitHub <noreply@github.com>2022-06-15 20:44:26 -0400
commit4487becdb849125d0161b0269070de7f395f688d (patch)
tree17840b769d0cba22f94ece3bebf629157991a7e2
parent84ad1c2b2bd83e7f4448d7e3821c1062f566fa4d (diff)
downloadNorthstarLauncher-1.8.1-rc4.tar.gz
NorthstarLauncher-1.8.1-rc4.zip
LatencyFleX Implementation Update (#183)v1.8.1-rc4
Main entry point for LatencyFlex was recently changed from latencyflex_wine.dll to latencyflex_layer.dll to prepare library for eventual windows release/to be more generic. This updates our implementation to match, while still supporting the previous libraries for existing users. Co-authored-by: Kyle Gospodnetich <KyleGospo@users.noreply.github.com>
-rw-r--r--NorthstarDedicatedTest/latencyflex.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/NorthstarDedicatedTest/latencyflex.cpp b/NorthstarDedicatedTest/latencyflex.cpp
index 4ac1c760..3e2cecd7 100644
--- a/NorthstarDedicatedTest/latencyflex.cpp
+++ b/NorthstarDedicatedTest/latencyflex.cpp
@@ -9,13 +9,19 @@ OnRenderStartType OnRenderStart;
ConVar* Cvar_r_latencyflex;
HMODULE m_lfxModule {};
-typedef void (*PFN_winelfx_WaitAndBeginFrame)();
-PFN_winelfx_WaitAndBeginFrame m_winelfx_WaitAndBeginFrame {};
+typedef void (*PFN_lfx_WaitAndBeginFrame)();
+PFN_lfx_WaitAndBeginFrame m_lfx_WaitAndBeginFrame {};
void OnRenderStartHook()
{
+ // Sleep before next frame as needed to reduce latency.
if (Cvar_r_latencyflex->GetInt())
- m_winelfx_WaitAndBeginFrame();
+ {
+ if (m_lfx_WaitAndBeginFrame)
+ {
+ m_lfx_WaitAndBeginFrame();
+ }
+ }
OnRenderStart();
}
@@ -25,17 +31,43 @@ void InitialiseLatencyFleX(HMODULE baseAddress)
// Connect to the LatencyFleX service
// LatencyFleX is an open source vendor agnostic replacement for Nvidia Reflex input latency reduction technology.
// https://ishitatsuyuki.github.io/post/latencyflex/
- m_lfxModule = LoadLibraryA("latencyflex_wine.dll");
+ const auto lfxModuleName = "latencyflex_layer.dll";
+ const auto lfxModuleNameFallback = "latencyflex_wine.dll";
+ auto useFallbackEntrypoints = false;
+
+ // Load LatencyFleX library.
+ m_lfxModule = ::LoadLibraryA(lfxModuleName);
+ if (m_lfxModule == nullptr && ::GetLastError() == ERROR_MOD_NOT_FOUND)
+ {
+ spdlog::info("LFX: Primary LatencyFleX library not found, trying fallback.");
- if (m_lfxModule == nullptr)
+ m_lfxModule = ::LoadLibraryA(lfxModuleNameFallback);
+ if (m_lfxModule == nullptr)
+ {
+ if (::GetLastError() == ERROR_MOD_NOT_FOUND)
+ {
+ spdlog::info("LFX: Fallback LatencyFleX library not found.");
+ }
+ else
+ {
+ spdlog::info("LFX: Error loading fallback LatencyFleX library - Code: {}", ::GetLastError());
+ }
+
+ return;
+ }
+
+ useFallbackEntrypoints = true;
+ }
+ else if (m_lfxModule == nullptr)
{
- spdlog::info("Unable to load LatencyFleX library, LatencyFleX disabled.");
+ spdlog::info("LFX: Error loading primary LatencyFleX library - Code: {}", ::GetLastError());
return;
}
- m_winelfx_WaitAndBeginFrame =
- reinterpret_cast<PFN_winelfx_WaitAndBeginFrame>(reinterpret_cast<void*>(GetProcAddress(m_lfxModule, "winelfx_WaitAndBeginFrame")));
- spdlog::info("LatencyFleX initialized.");
+ m_lfx_WaitAndBeginFrame = reinterpret_cast<PFN_lfx_WaitAndBeginFrame>(reinterpret_cast<void*>(
+ GetProcAddress(m_lfxModule, !useFallbackEntrypoints ? "lfx_WaitAndBeginFrame" : "winelfx_WaitAndBeginFrame")));
+
+ spdlog::info("LFX: Initialized.");
Cvar_r_latencyflex = new ConVar("r_latencyflex", "1", FCVAR_ARCHIVE, "Whether or not to use LatencyFleX input latency reduction.");