-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nvapi: Reflex support through LatencyFleX
- Loading branch information
1 parent
50c5957
commit dd26cbd
Showing
23 changed files
with
329 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "lfx.h" | ||
|
||
#include <windows.h> | ||
#include "../util/util_string.h" | ||
#include "../util/util_log.h" | ||
|
||
namespace dxvk { | ||
Lfx::Lfx() { | ||
const auto lfxModuleName = "latencyflex_wine.dll"; | ||
m_lfxModule = ::LoadLibraryA(lfxModuleName); | ||
if (m_lfxModule == nullptr) { | ||
auto lastError = ::GetLastError(); | ||
if (lastError != ERROR_MOD_NOT_FOUND) // Ignore library not found | ||
log::write(str::format("Loading ", lfxModuleName, " failed with error code: ", lastError)); | ||
|
||
return; | ||
} | ||
|
||
m_winelfx_WaitAndBeginFrame = reinterpret_cast<PFN_winelfx_WaitAndBeginFrame>(reinterpret_cast<void*>(GetProcAddress(m_lfxModule,"winelfx_WaitAndBeginFrame"))); | ||
m_winelfx_SetTargetFrameTime = reinterpret_cast<PFN_winelfx_SetTargetFrameTime>(reinterpret_cast<void*>(GetProcAddress(m_lfxModule,"winelfx_SetTargetFrameTime"))); | ||
} | ||
|
||
Lfx::~Lfx() { | ||
if (m_lfxModule == nullptr) return; | ||
::FreeLibrary(m_lfxModule); | ||
m_lfxModule = nullptr; | ||
} | ||
|
||
bool Lfx::IsAvailable() const { | ||
return m_lfxModule != nullptr; | ||
} | ||
|
||
void Lfx::WaitAndBeginFrame() { | ||
if (m_winelfx_WaitAndBeginFrame) | ||
m_winelfx_WaitAndBeginFrame(); | ||
} | ||
|
||
void Lfx::SetTargetFrameTime(uint64_t frame_time_ns) { | ||
if (m_winelfx_SetTargetFrameTime) | ||
m_winelfx_SetTargetFrameTime(static_cast<__int64>(frame_time_ns)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <minwindef.h> | ||
#include <cstdint> | ||
|
||
namespace dxvk { | ||
class Lfx { | ||
public: | ||
Lfx(); | ||
virtual ~Lfx(); | ||
|
||
[[nodiscard]] virtual bool IsAvailable() const; | ||
virtual void WaitAndBeginFrame(); | ||
virtual void SetTargetFrameTime(uint64_t frame_time_ns); | ||
|
||
private: | ||
HMODULE m_lfxModule{}; | ||
bool m_enabled = false; | ||
|
||
typedef void (*PFN_winelfx_WaitAndBeginFrame)(); | ||
typedef void (*PFN_winelfx_SetTargetFrameTime)(__int64); | ||
|
||
PFN_winelfx_WaitAndBeginFrame m_winelfx_WaitAndBeginFrame{}; | ||
PFN_winelfx_SetTargetFrameTime m_winelfx_SetTargetFrameTime{}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "nvapi_d3d_instance.h" | ||
|
||
namespace dxvk { | ||
NvapiD3dInstance::NvapiD3dInstance(ResourceFactory &resourceFactory): m_resourceFactory(resourceFactory) { | ||
|
||
} | ||
|
||
NvapiD3dInstance::~NvapiD3dInstance() { | ||
|
||
} | ||
|
||
bool NvapiD3dInstance::Initialize() { | ||
m_lfx = m_resourceFactory.CreateLfx(); | ||
return true; | ||
} | ||
|
||
bool NvapiD3dInstance::IsReflexAvailable() { | ||
return m_lfx->IsAvailable(); | ||
} | ||
|
||
bool NvapiD3dInstance::IsReflexEnabled() { | ||
return m_isLfxEnabled; | ||
} | ||
|
||
void NvapiD3dInstance::SetReflexEnabled(bool value) { | ||
m_isLfxEnabled = value; | ||
} | ||
|
||
void NvapiD3dInstance::Sleep() { | ||
if(IsReflexAvailable() && m_isLfxEnabled) | ||
m_lfx->WaitAndBeginFrame(); | ||
} | ||
|
||
void NvapiD3dInstance::SetTargetFrameTime(uint64_t frameTimeNs) { | ||
m_lfx->SetTargetFrameTime(frameTimeNs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "../resource_factory.h" | ||
|
||
namespace dxvk { | ||
class NvapiD3dInstance { | ||
public: | ||
explicit NvapiD3dInstance(ResourceFactory &resourceFactory); | ||
virtual ~NvapiD3dInstance(); | ||
|
||
virtual bool Initialize(); | ||
virtual bool IsReflexAvailable(); | ||
virtual bool IsReflexEnabled(); | ||
virtual void SetReflexEnabled(bool value); | ||
virtual void Sleep(); | ||
virtual void SetTargetFrameTime(uint64_t frameTimeNs); | ||
|
||
private: | ||
ResourceFactory m_resourceFactory; | ||
std::unique_ptr<Lfx> m_lfx; | ||
bool m_isLfxEnabled = false; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
#pragma once | ||
|
||
#include "sysinfo/resource_factory.h" | ||
#include "resource_factory.h" | ||
#include "sysinfo/nvapi_adapter_registry.h" | ||
#include "d3d/nvapi_d3d_instance.h" | ||
|
||
static std::unique_ptr<dxvk::ResourceFactory> resourceFactory; | ||
static std::unique_ptr<dxvk::NvapiAdapterRegistry> nvapiAdapterRegistry; | ||
static std::unique_ptr<dxvk::NvapiD3dInstance> nvapiD3dInstance; | ||
|
||
static auto initializationMutex = std::mutex{}; | ||
static auto initializationCount = 0ULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.