From 024032cab13ef9ccf93f2a2e298084f55cf8775e Mon Sep 17 00:00:00 2001 From: cdozdil Date: Thu, 13 Jun 2024 23:20:06 +0300 Subject: [PATCH] use NVNGXProxy for upscaler too --- OptiScaler/backends/dlss/DLSSFeature.cpp | 145 +--------------- OptiScaler/backends/dlss/DLSSFeature.h | 8 +- OptiScaler/backends/dlss/DLSSFeature_Dx11.cpp | 161 +++-------------- OptiScaler/backends/dlss/DLSSFeature_Dx11.h | 22 --- OptiScaler/backends/dlss/DLSSFeature_Dx12.cpp | 163 +++--------------- OptiScaler/backends/dlss/DLSSFeature_Dx12.h | 22 --- OptiScaler/backends/dlss/DLSSFeature_Vk.cpp | 109 ++++-------- OptiScaler/backends/dlss/DLSSFeature_Vk.h | 21 --- 8 files changed, 91 insertions(+), 560 deletions(-) diff --git a/OptiScaler/backends/dlss/DLSSFeature.cpp b/OptiScaler/backends/dlss/DLSSFeature.cpp index 1d18adb2..2c8ad7c4 100644 --- a/OptiScaler/backends/dlss/DLSSFeature.cpp +++ b/OptiScaler/backends/dlss/DLSSFeature.cpp @@ -774,26 +774,6 @@ void DLSSFeature::ProcessInitParams(const NVSDK_NGX_Parameter* InParameters) Parameters->Set(NVSDK_NGX_Parameter_DLSS_Hint_Render_Preset_UltraPerformance, RenderPresetUltraPerformance); } -void DLSSFeature::GetFeatureCommonInfo(NVSDK_NGX_FeatureCommonInfo* fcInfo) -{ - // Allocate memory for the array of const wchar_t* - wchar_t const** paths = new const wchar_t* [Config::Instance()->NVNGX_FeatureInfo_Paths.size()]; - - // Copy the strings from the vector to the array - for (size_t i = 0; i < Config::Instance()->NVNGX_FeatureInfo_Paths.size(); ++i) - { - paths[i] = Config::Instance()->NVNGX_FeatureInfo_Paths[i].c_str(); - - std::string str(Config::Instance()->NVNGX_FeatureInfo_Paths[i].length(), 0); - std::transform(Config::Instance()->NVNGX_FeatureInfo_Paths[i].begin(), Config::Instance()->NVNGX_FeatureInfo_Paths[i].end(), str.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::debug("DLSSFeature::GetFeatureCommonInfo paths[{0}]: {1}", i, str); - } - - fcInfo->PathListInfo.Path = paths; - fcInfo->PathListInfo.Length = static_cast(Config::Instance()->NVNGX_FeatureInfo_Paths.size()); -} - void DLSSFeature::ReadVersion() { PFN_NVSDK_NGX_GetSnippetVersion _GetSnippetVersion = nullptr; @@ -819,124 +799,16 @@ void DLSSFeature::ReadVersion() DLSSFeature::DLSSFeature(unsigned int handleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(handleId, InParameters) { - if (_nvngx == nullptr) - { - Config::Instance()->dlssDisableHook = true; + if (NVNGXProxy::NVNGXModule() == nullptr) + NVNGXProxy::InitNVNGX(); - do - { - // check dlss enabler - spdlog::info("DLSSFeature::DLSSFeature Trying to load dlss-enabler-ngx.dll"); - - _nvngx = LoadLibraryW(L"dlss-enabler-ngx.dll"); - - if (_nvngx) - { - Config::Instance()->DE_Available = true; - spdlog::info("DLSSFeature::DLSSFeature dlss-enabler-ngx.dll loaded from DLSS Enabler, ptr: {0:X}", (ULONG64)_nvngx); - _moduleLoaded = true; - break; - } - else - { - spdlog::error("DLSSFeature::DLSSFeature dlss-enabler-ngx.dll could not be loaded from DLSS Enabler!"); - } - - // path from ini - if (Config::Instance()->DLSSLibrary.has_value()) - { - spdlog::info("DLSSFeature::DLSSFeature trying to load nvngx from ini path!"); - - std::filesystem::path cfgPath(Config::Instance()->DLSSLibrary.value().c_str()); - auto path = cfgPath / L"_nvngx.dll"; - - spdlog::info("DLSSFeature::DLSSFeature trying to load _nvngx.dll path: {0}", path.string()); - _nvngx = LoadLibraryW(path.c_str()); - - if (_nvngx) - { - spdlog::info("DLSSFeature::DLSSFeature _nvngx.dll loaded from {0}, ptr: {1:X}", path.string(), (ULONG64)_nvngx); - _moduleLoaded = true; - break; - } - - path = cfgPath / L"nvngx.dll"; - spdlog::info("DLSSFeature::DLSSFeature trying to load nvngx.dll path: {0}", path.string()); - _nvngx = LoadLibraryW(path.c_str()); - - if (_nvngx) - { - spdlog::info("DLSSFeature::DLSSFeature nvngx.dll loaded from {0}, ptr: {1:X}", path.string(), (ULONG64)_nvngx); - _moduleLoaded = true; - break; - } - } - - spdlog::info("DLSSFeature::DLSSFeature trying to load nvngx from registry path!"); - - // path from registry - auto regNGXCorePath = Util::NvngxPath(); - - if (regNGXCorePath.has_value()) - { - auto nvngxPath = regNGXCorePath.value() / "_nvngx.dll"; - spdlog::info("DLSSFeature::DLSSFeature trying to load _nvngx.dll path: {0}", nvngxPath.string()); - - _nvngx = LoadLibraryW(nvngxPath.wstring().c_str()); - - if (_nvngx) - { - spdlog::info("DLSSFeature::DLSSFeature _nvngx.dll loaded from {0}, ptr: {1:X}", nvngxPath.string(), (ULONG64)_nvngx); - _moduleLoaded = true; - break; - } - - nvngxPath = regNGXCorePath.value() / "nvngx.dll"; - spdlog::info("DLSSFeature::DLSSFeature trying to load nvngx.dll path: {0}", nvngxPath.string()); - - _nvngx = LoadLibraryW(nvngxPath.wstring().c_str()); - - if (_nvngx) - { - spdlog::info("DLSSFeature::DLSSFeature nvngx.dll loaded from {0}, ptr: {1:X}", nvngxPath.string(), (ULONG64)_nvngx); - _moduleLoaded = true; - break; - } - } - else - { - spdlog::warn("DLSSFeature::DLSSFeature can't load NGXPath value!"); - } - - - // dll path - spdlog::info("DLSSFeature::DLSSFeature trying to load nvngx from dll path!"); - - auto nvngxPath = Util::DllPath().parent_path() / L"_nvngx.dll"; - spdlog::info("DLSSFeature::DLSSFeature trying to load _nvngx.dll path: {0}", nvngxPath.string()); - - _nvngx = LoadLibraryW(nvngxPath.wstring().c_str()); - - if (_nvngx) - { - spdlog::info("DLSSFeature::DLSSFeature _nvngx.dll loaded from {0}, ptr: {1:X}", nvngxPath.string(), (ULONG64)_nvngx); - _moduleLoaded = true; - } - - } while (false); - - Config::Instance()->dlssDisableHook = false; - } - else - { - _moduleLoaded = true; - } - - if (_moduleLoaded && !Config::Instance()->DE_Available) + if (NVNGXProxy::NVNGXModule() != nullptr && !Config::Instance()->DE_Available) { HookNvApi(); - HookNgxApi(_nvngx); + HookNgxApi(NVNGXProxy::NVNGXModule()); } + + _moduleLoaded = NVNGXProxy::NVNGXModule() != nullptr; } DLSSFeature::~DLSSFeature() @@ -945,9 +817,6 @@ DLSSFeature::~DLSSFeature() void DLSSFeature::Shutdown() { - if (_nvngx != nullptr) - { + if (NVNGXProxy::NVNGXModule() != nullptr) UnhookApis(); - FreeLibrary(_nvngx); - } } \ No newline at end of file diff --git a/OptiScaler/backends/dlss/DLSSFeature.h b/OptiScaler/backends/dlss/DLSSFeature.h index 8e5d33c0..b6500ae1 100644 --- a/OptiScaler/backends/dlss/DLSSFeature.h +++ b/OptiScaler/backends/dlss/DLSSFeature.h @@ -1,8 +1,8 @@ #pragma once -#include "../IFeature.h" #include "../../pch.h" -#include +#include "../../NVNGX_Proxy.h" +#include "../IFeature.h" typedef uint32_t(*PFN_NVSDK_NGX_GetSnippetVersion)(void); @@ -10,7 +10,6 @@ class DLSSFeature : public virtual IFeature { private: feature_version _version = { 0, 0, 0 }; - inline static HMODULE _nvngx = nullptr; protected: NVSDK_NGX_Parameter* Parameters = nullptr; @@ -18,11 +17,8 @@ protected: NVSDK_NGX_Handle* _p_dlssHandle = nullptr; inline static bool _dlssInited = false; - HMODULE NVNGX() { return _nvngx; } - void ProcessEvaluateParams(const NVSDK_NGX_Parameter* InParameters); void ProcessInitParams(const NVSDK_NGX_Parameter* InParameters); - void GetFeatureCommonInfo(NVSDK_NGX_FeatureCommonInfo* fcInfo); static void Shutdown(); diff --git a/OptiScaler/backends/dlss/DLSSFeature_Dx11.cpp b/OptiScaler/backends/dlss/DLSSFeature_Dx11.cpp index b4a98552..b0b1cecd 100644 --- a/OptiScaler/backends/dlss/DLSSFeature_Dx11.cpp +++ b/OptiScaler/backends/dlss/DLSSFeature_Dx11.cpp @@ -23,46 +23,20 @@ bool DLSSFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex { if (!_dlssInited) { - NVSDK_NGX_FeatureCommonInfo fcInfo{}; + _dlssInited = NVNGXProxy::InitDx11(InDevice); - GetFeatureCommonInfo(&fcInfo); - - if (Config::Instance()->NVNGX_ProjectId != "" && _Init_with_ProjectID != nullptr) - { - spdlog::debug("DLSSFeatureDx11::Init _Init_with_ProjectID!"); - - nvResult = _Init_with_ProjectID(Config::Instance()->NVNGX_ProjectId.c_str(), Config::Instance()->NVNGX_Engine, Config::Instance()->NVNGX_EngineVersion.c_str(), - Config::Instance()->NVNGX_ApplicationDataPath.c_str(), InDevice, Config::Instance()->NVNGX_Version, &fcInfo); - } - else if (_Init_Ext != nullptr) - { - spdlog::debug("DLSSFeatureDx11::Init _Init_Ext!"); - - nvResult = _Init_Ext(Config::Instance()->NVNGX_ApplicationId, Config::Instance()->NVNGX_ApplicationDataPath.c_str(), InDevice, Config::Instance()->NVNGX_Version, &fcInfo); - } - else - { - spdlog::error("DLSSFeatureDx11::Init _Init_with_ProjectID and is null"); - break; - } - - if (nvResult != NVSDK_NGX_Result_Success) - { - spdlog::error("DLSSFeatureDx11::Init _Init_with_ProjectID result: {0:X}", (unsigned int)nvResult); - break; - } - - _dlssInited = true; + if (!_dlssInited) + return false; //delay between init and create feature std::this_thread::sleep_for(std::chrono::milliseconds(500)); } - if (_AllocateParameters != nullptr) + if (NVNGXProxy::D3D11_AllocateParameters() != nullptr) { spdlog::debug("DLSSFeatureDx11::Init _AllocateParameters will be used"); - nvResult = _AllocateParameters(&Parameters); + nvResult = NVNGXProxy::D3D11_AllocateParameters()(&Parameters); if (nvResult != NVSDK_NGX_Result_Success) { @@ -74,11 +48,11 @@ bool DLSSFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex DumpNvParams(Parameters); #endif } - else if (_GetParameters != nullptr) + else if (NVNGXProxy::D3D11_GetParameters() != nullptr) { spdlog::debug("DLSSFeatureDx11::Init _GetParameters will be used"); - nvResult = _GetParameters(&Parameters); + nvResult = NVNGXProxy::D3D11_GetParameters()(&Parameters); if (nvResult != NVSDK_NGX_Result_Success) { @@ -98,12 +72,12 @@ bool DLSSFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex spdlog::info("DLSSFeatureDx12::Evaluate Creating DLSS feature"); - if (_CreateFeature != nullptr) + if (NVNGXProxy::D3D11_CreateFeature() != nullptr) { ProcessInitParams(InParameters); _p_dlssHandle = &_dlssHandle; - nvResult = _CreateFeature(InContext, NVSDK_NGX_Feature_SuperSampling, Parameters, &_p_dlssHandle); + nvResult = NVNGXProxy::D3D11_CreateFeature()(InContext, NVSDK_NGX_Feature_SuperSampling, Parameters, &_p_dlssHandle); if (nvResult != NVSDK_NGX_Result_Success) { @@ -145,11 +119,11 @@ bool DLSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK NVSDK_NGX_Result nvResult; ID3D11Resource* paramOutput; - if (_EvaluateFeature != nullptr) + if (NVNGXProxy::D3D11_EvaluateFeature() != nullptr) { ProcessEvaluateParams(InParameters); - nvResult = _EvaluateFeature(InDeviceContext, _p_dlssHandle, Parameters, NULL); + nvResult = NVNGXProxy::D3D11_EvaluateFeature()(InDeviceContext, _p_dlssHandle, Parameters, NULL); if (nvResult != NVSDK_NGX_Result_Success) { @@ -174,9 +148,7 @@ bool DLSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK if (Imgui != nullptr && Imgui.get() != nullptr) { if (Imgui->IsHandleDifferent()) - { Imgui.reset(); - } else Imgui->Render(InDeviceContext, paramOutput); } @@ -196,10 +168,10 @@ void DLSSFeatureDx11::Shutdown(ID3D11Device* InDevice) { if (_dlssInited) { - if (_Shutdown != nullptr) - _Shutdown(); - else if (_Shutdown1 != nullptr) - _Shutdown1(InDevice); + if (NVNGXProxy::D3D11_Shutdown() != nullptr) + NVNGXProxy::D3D11_Shutdown()(); + else if (NVNGXProxy::D3D11_Shutdown1() != nullptr) + NVNGXProxy::D3D11_Shutdown1()(InDevice); } DLSSFeature::Shutdown(); @@ -207,106 +179,25 @@ void DLSSFeatureDx11::Shutdown(ID3D11Device* InDevice) DLSSFeatureDx11::DLSSFeatureDx11(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(InHandleId, InParameters), IFeature_Dx11(InHandleId, InParameters), DLSSFeature(InHandleId, InParameters) { - if (!ModuleLoaded()) + if (NVNGXProxy::NVNGXModule() == nullptr) { - spdlog::error("DLSSFeatureDx11::DLSSFeatureDx11 nvngx.dll not loaded!"); - return; + spdlog::info("DLSSFeatureDx11::DLSSFeatureDx11 nvngx.dll not loaded, now loading"); + NVNGXProxy::InitNVNGX(); } - spdlog::info("DLSSFeatureDx11::DLSSFeatureDx11 binding methods!"); - - if (_Shutdown == nullptr) - _Shutdown = (PFN_NVSDK_NGX_D3D11_Shutdown)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_Shutdown"); - - if (_Shutdown1 == nullptr) - _Shutdown1 = (PFN_NVSDK_NGX_D3D11_Shutdown1)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_Shutdown1"); - - if (_Init_Ext == nullptr) - _Init_Ext = (PFN_NVSDK_NGX_D3D11_Init_Ext)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_Init_Ext"); - - if (_Init_with_ProjectID == nullptr) - _Init_with_ProjectID = (PFN_NVSDK_NGX_D3D11_Init_ProjectID)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_Init_ProjectID"); - - if (_GetParameters == nullptr) - _GetParameters = (PFN_NVSDK_NGX_D3D11_GetParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_GetParameters"); - - if (_AllocateParameters == nullptr) - _AllocateParameters = (PFN_NVSDK_NGX_D3D11_AllocateParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_AllocateParameters"); - - if (_DestroyParameters == nullptr) - _DestroyParameters = (PFN_NVSDK_NGX_D3D11_DestroyParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_DestroyParameters"); - - if (_CreateFeature == nullptr) - _CreateFeature = (PFN_NVSDK_NGX_D3D11_CreateFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_CreateFeature"); - - if (_ReleaseFeature == nullptr) - _ReleaseFeature = (PFN_NVSDK_NGX_D3D11_ReleaseFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_ReleaseFeature"); - - if (_EvaluateFeature == nullptr) - _EvaluateFeature = (PFN_NVSDK_NGX_D3D11_EvaluateFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D11_EvaluateFeature"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _Init_with_ProjectID ptr: {0:X}", (ULONG64)_Init_with_ProjectID); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _Init_with_ProjectID ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _Init_Ext ptr: {0:X}", (ULONG64)_Init_Ext); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _Init_Ext ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _Shutdown ptr: {0:X}", (ULONG64)_Shutdown); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _Shutdown ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _Shutdown1 ptr: {0:X}", (ULONG64)_Shutdown1); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _Shutdown1 ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _GetParameters ptr: {0:X}", (ULONG64)_GetParameters); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _GetParameters ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _AllocateParameters ptr: {0:X}", (ULONG64)_AllocateParameters); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _AllocateParameters ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _DestroyParameters ptr: {0:X}", (ULONG64)_DestroyParameters); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _DestroyParameters ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _CreateFeature ptr: {0:X}", (ULONG64)_CreateFeature); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _CreateFeature ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _ReleaseFeature ptr: {0:X}", (ULONG64)_ReleaseFeature); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _ReleaseFeature ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx11::DLSSFeatureDx11 _EvaluateFeature ptr: {0:X}", (ULONG64)_EvaluateFeature); - else - spdlog::warn("DLSSFeatureDx11::DLSSFeatureDx11 _EvaluateFeature ptr: nullptr"); - - _moduleLoaded = (_Init_with_ProjectID != nullptr || _Init_Ext != nullptr) && (_Shutdown != nullptr || _Shutdown1 != nullptr) && - (_GetParameters != nullptr || _AllocateParameters != nullptr) && _DestroyParameters != nullptr && _CreateFeature != nullptr && - _ReleaseFeature != nullptr && _EvaluateFeature != nullptr; + _moduleLoaded = (NVNGXProxy::D3D11_Init_with_ProjectID() != nullptr || NVNGXProxy::D3D11_Init_Ext() != nullptr) && + (NVNGXProxy::D3D11_Shutdown() != nullptr || NVNGXProxy::D3D11_Shutdown1() != nullptr) && + (NVNGXProxy::D3D11_GetParameters() != nullptr || NVNGXProxy::D3D11_AllocateParameters() != nullptr) && NVNGXProxy::D3D11_DestroyParameters() != nullptr && + NVNGXProxy::D3D11_CreateFeature() != nullptr && NVNGXProxy::D3D11_ReleaseFeature() != nullptr && NVNGXProxy::D3D11_EvaluateFeature() != nullptr; spdlog::info("DLSSFeatureDx11::DLSSFeatureDx11 binding complete!"); } DLSSFeatureDx11::~DLSSFeatureDx11() { - if (Parameters != nullptr && _DestroyParameters != nullptr) - _DestroyParameters(Parameters); + if (Parameters != nullptr && NVNGXProxy::D3D11_DestroyParameters() != nullptr) + NVNGXProxy::D3D11_DestroyParameters()(Parameters); - if (_ReleaseFeature != nullptr && _p_dlssHandle != nullptr) - _ReleaseFeature(_p_dlssHandle); + if (NVNGXProxy::D3D11_ReleaseFeature() != nullptr && _p_dlssHandle != nullptr) + NVNGXProxy::D3D11_ReleaseFeature()(_p_dlssHandle); } diff --git a/OptiScaler/backends/dlss/DLSSFeature_Dx11.h b/OptiScaler/backends/dlss/DLSSFeature_Dx11.h index f6c73ad4..d0b1ab25 100644 --- a/OptiScaler/backends/dlss/DLSSFeature_Dx11.h +++ b/OptiScaler/backends/dlss/DLSSFeature_Dx11.h @@ -3,34 +3,12 @@ #include "DLSSFeature.h" #include -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_Init_Ext)(unsigned long long InApplicationId, const wchar_t* InApplicationDataPath, ID3D11Device* InDevice, NVSDK_NGX_Version InSDKVersion, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_Init_ProjectID)(const char* InProjectId, NVSDK_NGX_EngineType InEngineType, const char* InEngineVersion, const wchar_t* InApplicationDataPath, ID3D11Device* InDevice, NVSDK_NGX_Version InSDKVersion, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_Shutdown)(void); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_Shutdown1)(ID3D11Device* InDevice); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_GetParameters)(NVSDK_NGX_Parameter** OutParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_AllocateParameters)(NVSDK_NGX_Parameter** OutParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_DestroyParameters)(NVSDK_NGX_Parameter* InParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_CreateFeature)(ID3D11DeviceContext * InDevCtx, NVSDK_NGX_Feature InFeatureID, NVSDK_NGX_Parameter* InParameters, NVSDK_NGX_Handle** OutHandle); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_ReleaseFeature)(NVSDK_NGX_Handle* InHandle); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D11_EvaluateFeature)(ID3D11DeviceContext* InDevCtx, const NVSDK_NGX_Handle* InFeatureHandle, const NVSDK_NGX_Parameter* InParameters, PFN_NVSDK_NGX_ProgressCallback InCallback); - class DLSSFeatureDx11 : public DLSSFeature, public IFeature_Dx11 { private: - inline static PFN_NVSDK_NGX_D3D11_Shutdown _Shutdown = nullptr; - inline static PFN_NVSDK_NGX_D3D11_Shutdown1 _Shutdown1 = nullptr; - inline static PFN_NVSDK_NGX_D3D11_Init_Ext _Init_Ext = nullptr; - inline static PFN_NVSDK_NGX_D3D11_Init_ProjectID _Init_with_ProjectID = nullptr; - inline static PFN_NVSDK_NGX_D3D11_GetParameters _GetParameters = nullptr; - inline static PFN_NVSDK_NGX_D3D11_AllocateParameters _AllocateParameters = nullptr; - inline static PFN_NVSDK_NGX_D3D11_DestroyParameters _DestroyParameters = nullptr; - inline static PFN_NVSDK_NGX_D3D11_CreateFeature _CreateFeature = nullptr; - inline static PFN_NVSDK_NGX_D3D11_ReleaseFeature _ReleaseFeature = nullptr; - inline static PFN_NVSDK_NGX_D3D11_EvaluateFeature _EvaluateFeature = nullptr; protected: - public: bool Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContext, const NVSDK_NGX_Parameter* InParameters) override; bool Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK_NGX_Parameter* InParameters) override; diff --git a/OptiScaler/backends/dlss/DLSSFeature_Dx12.cpp b/OptiScaler/backends/dlss/DLSSFeature_Dx12.cpp index b92136f9..b7cf3634 100644 --- a/OptiScaler/backends/dlss/DLSSFeature_Dx12.cpp +++ b/OptiScaler/backends/dlss/DLSSFeature_Dx12.cpp @@ -8,7 +8,6 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In if (!_moduleLoaded) { spdlog::error("DLSSFeatureDx12::Init nvngx.dll not loaded!"); - SetInit(false); return false; } @@ -22,48 +21,20 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In { if (!_dlssInited) { - NVSDK_NGX_FeatureCommonInfo fcInfo{}; + _dlssInited = NVNGXProxy::InitDx12(InDevice); - GetFeatureCommonInfo(&fcInfo); - - if (Config::Instance()->NVNGX_ProjectId != "" && _Init_with_ProjectID != nullptr) - { - spdlog::debug("DLSSFeatureDx12::Init _Init_with_ProjectID!"); - - nvResult = _Init_with_ProjectID(Config::Instance()->NVNGX_ProjectId.c_str(), Config::Instance()->NVNGX_Engine, Config::Instance()->NVNGX_EngineVersion.c_str(), - Config::Instance()->NVNGX_ApplicationDataPath.c_str(), InDevice, Config::Instance()->NVNGX_Version, &fcInfo); - } - else if (_Init_Ext != nullptr) - { - spdlog::debug("DLSSFeatureDx12::Init _Init_Ext!"); - - nvResult = _Init_Ext(Config::Instance()->NVNGX_ApplicationId, Config::Instance()->NVNGX_ApplicationDataPath.c_str(), InDevice, Config::Instance()->NVNGX_Version, &fcInfo); - } - else - { - spdlog::error("DLSSFeatureDx12::Init _Init_with_ProjectID and is null"); - break; - } - - if (nvResult != NVSDK_NGX_Result_Success) - { - spdlog::error("DLSSFeatureDx12::Init _Init_with_ProjectID result: {0:X}", (unsigned int)nvResult); - break; - } - - _dlssInited = true; + if (!_dlssInited) + return false; //delay between init and create feature std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - } - if (_AllocateParameters != nullptr) + if (NVNGXProxy::D3D12_AllocateParameters() != nullptr) { spdlog::debug("DLSSFeatureDx12::Init _AllocateParameters will be used"); - nvResult = _AllocateParameters(&Parameters); + nvResult = NVNGXProxy::D3D12_AllocateParameters()(&Parameters); if (nvResult != NVSDK_NGX_Result_Success) { @@ -75,11 +46,11 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In DumpNvParams(Parameters); #endif } - else if (_GetParameters != nullptr) + else if (NVNGXProxy::D3D12_GetParameters() != nullptr) { spdlog::debug("DLSSFeatureDx12::Init _GetParameters will be used"); - nvResult = _GetParameters(&Parameters); + nvResult = NVNGXProxy::D3D12_GetParameters()(&Parameters); if (nvResult != NVSDK_NGX_Result_Success) { @@ -99,12 +70,12 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In spdlog::info("DLSSFeatureDx12::Evaluate Creating DLSS feature"); - if (_CreateFeature != nullptr) + if (NVNGXProxy::D3D12_CreateFeature() != nullptr) { ProcessInitParams(InParameters); _p_dlssHandle = &_dlssHandle; - nvResult = _CreateFeature(InCommandList, NVSDK_NGX_Feature_SuperSampling, Parameters, &_p_dlssHandle); + nvResult = NVNGXProxy::D3D12_CreateFeature()(InCommandList, NVSDK_NGX_Feature_SuperSampling, Parameters, &_p_dlssHandle); if (nvResult != NVSDK_NGX_Result_Success) { @@ -167,7 +138,7 @@ bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N NVSDK_NGX_Result nvResult; - if (_EvaluateFeature != nullptr) + if (NVNGXProxy::D3D12_EvaluateFeature() != nullptr) { ProcessEvaluateParams(InParameters); @@ -217,7 +188,7 @@ bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N Parameters->Set(NVSDK_NGX_Parameter_Output, setBuffer); - nvResult = _EvaluateFeature(InCommandList, _p_dlssHandle, Parameters, NULL); + nvResult = NVNGXProxy::D3D12_EvaluateFeature()(InCommandList, _p_dlssHandle, Parameters, NULL); if (nvResult != NVSDK_NGX_Result_Success) { @@ -312,10 +283,10 @@ void DLSSFeatureDx12::Shutdown(ID3D12Device* InDevice) { if (_dlssInited) { - if (_Shutdown != nullptr) - _Shutdown(); - else if (_Shutdown1 != nullptr) - _Shutdown1(InDevice); + if (NVNGXProxy::D3D12_Shutdown() != nullptr) + NVNGXProxy::D3D12_Shutdown()(); + else if (NVNGXProxy::D3D12_Shutdown1() != nullptr) + NVNGXProxy::D3D12_Shutdown1()(InDevice); } DLSSFeature::Shutdown(); @@ -323,108 +294,28 @@ void DLSSFeatureDx12::Shutdown(ID3D12Device* InDevice) DLSSFeatureDx12::DLSSFeatureDx12(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(InHandleId, InParameters), IFeature_Dx12(InHandleId, InParameters), DLSSFeature(InHandleId, InParameters) { - if (!_moduleLoaded) + if (NVNGXProxy::NVNGXModule() == nullptr) { - spdlog::error("DLSSFeatureDx12::DLSSFeatureDx12 nvngx.dll not loaded!"); - return; + spdlog::info("DLSSFeatureDx12::DLSSFeatureDx12 nvngx.dll not loaded, now loading"); + NVNGXProxy::InitNVNGX(); } - spdlog::info("DLSSFeatureDx12::DLSSFeatureDx12 binding methods!"); - - if (_Init_with_ProjectID == nullptr) - _Init_with_ProjectID = (PFN_NVSDK_NGX_D3D12_Init_ProjectID)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_Init_ProjectID"); - - if (_Init_Ext == nullptr) - _Init_Ext = (PFN_NVSDK_NGX_D3D12_Init_Ext)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_Init_Ext"); - - if (_Shutdown == nullptr) - _Shutdown = (PFN_NVSDK_NGX_D3D12_Shutdown)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_Shutdown"); - - if (_Shutdown1 == nullptr) - _Shutdown1 = (PFN_NVSDK_NGX_D3D12_Shutdown1)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_Shutdown1"); - - if (_GetParameters == nullptr) - _GetParameters = (PFN_NVSDK_NGX_D3D12_GetParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_GetParameters"); - - if (_AllocateParameters == nullptr) - _AllocateParameters = (PFN_NVSDK_NGX_D3D12_AllocateParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_AllocateParameters"); - - if (_DestroyParameters == nullptr) - _DestroyParameters = (PFN_NVSDK_NGX_D3D12_DestroyParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_DestroyParameters"); - - if (_CreateFeature == nullptr) - _CreateFeature = (PFN_NVSDK_NGX_D3D12_CreateFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_CreateFeature"); - - if (_ReleaseFeature == nullptr) - _ReleaseFeature = (PFN_NVSDK_NGX_D3D12_ReleaseFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_ReleaseFeature"); - - if (_EvaluateFeature == nullptr) - _EvaluateFeature = (PFN_NVSDK_NGX_D3D12_EvaluateFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_D3D12_EvaluateFeature"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _Init_with_ProjectID ptr: {0:X}", (ULONG64)_Init_with_ProjectID); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _Init_with_ProjectID ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _Init_Ext ptr: {0:X}", (ULONG64)_Init_Ext); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _Init_Ext ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _Shutdown ptr: {0:X}", (ULONG64)_Shutdown); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _Shutdown ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _Shutdown1 ptr: {0:X}", (ULONG64)_Shutdown1); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _Shutdown1 ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _GetParameters ptr: {0:X}", (ULONG64)_GetParameters); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _GetParameters ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _AllocateParameters ptr: {0:X}", (ULONG64)_AllocateParameters); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _AllocateParameters ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _DestroyParameters ptr: {0:X}", (ULONG64)_DestroyParameters); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _DestroyParameters ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _CreateFeature ptr: {0:X}", (ULONG64)_CreateFeature); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _CreateFeature ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _ReleaseFeature ptr: {0:X}", (ULONG64)_ReleaseFeature); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _ReleaseFeature ptr: nullptr"); - - if (_Init_with_ProjectID) - spdlog::trace("DLSSFeatureDx12::DLSSFeatureDx12 _EvaluateFeature ptr: {0:X}", (ULONG64)_EvaluateFeature); - else - spdlog::warn("DLSSFeatureDx12::DLSSFeatureDx12 _EvaluateFeature ptr: nullptr"); - - _moduleLoaded = (_Init_with_ProjectID != nullptr || _Init_Ext != nullptr) && (_Shutdown != nullptr || _Shutdown1 != nullptr) && - (_GetParameters != nullptr || _AllocateParameters != nullptr) && _DestroyParameters != nullptr && _CreateFeature != nullptr && - _ReleaseFeature != nullptr && _EvaluateFeature != nullptr; + _moduleLoaded = (NVNGXProxy::D3D12_Init_with_ProjectID() != nullptr || NVNGXProxy::D3D12_Init_Ext() != nullptr) && + (NVNGXProxy::D3D12_Shutdown() != nullptr || NVNGXProxy::D3D12_Shutdown1() != nullptr) && + (NVNGXProxy::D3D12_GetParameters() != nullptr || NVNGXProxy::D3D12_AllocateParameters() != nullptr) && + NVNGXProxy::D3D12_DestroyParameters() != nullptr && NVNGXProxy::D3D12_CreateFeature() != nullptr && + NVNGXProxy::D3D12_ReleaseFeature() != nullptr && NVNGXProxy::D3D12_EvaluateFeature() != nullptr; spdlog::info("DLSSFeatureDx12::DLSSFeatureDx12 binding complete!"); } DLSSFeatureDx12::~DLSSFeatureDx12() { - if (Parameters != nullptr && _DestroyParameters != nullptr) - _DestroyParameters(Parameters); + if (Parameters != nullptr && NVNGXProxy::D3D12_DestroyParameters() != nullptr) + NVNGXProxy::D3D12_DestroyParameters()(Parameters); - if (_ReleaseFeature != nullptr && _p_dlssHandle != nullptr) - _ReleaseFeature(_p_dlssHandle); + if (NVNGXProxy::D3D12_ReleaseFeature() != nullptr && _p_dlssHandle != nullptr) + NVNGXProxy::D3D12_ReleaseFeature()(_p_dlssHandle); if (RCAS != nullptr && RCAS.get() != nullptr) RCAS.reset(); diff --git a/OptiScaler/backends/dlss/DLSSFeature_Dx12.h b/OptiScaler/backends/dlss/DLSSFeature_Dx12.h index 78477299..c95e660e 100644 --- a/OptiScaler/backends/dlss/DLSSFeature_Dx12.h +++ b/OptiScaler/backends/dlss/DLSSFeature_Dx12.h @@ -4,31 +4,9 @@ #include "../../rcas/RCAS_Dx12.h" #include -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_Init_Ext)(unsigned long long InApplicationId, const wchar_t* InApplicationDataPath, ID3D12Device* InDevice, NVSDK_NGX_Version InSDKVersion, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_Init_ProjectID)(const char* InProjectId, NVSDK_NGX_EngineType InEngineType, const char* InEngineVersion, const wchar_t* InApplicationDataPath, ID3D12Device* InDevice, NVSDK_NGX_Version InSDKVersion, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_Shutdown)(void); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_Shutdown1)(ID3D12Device* InDevice); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_GetParameters)(NVSDK_NGX_Parameter** OutParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_AllocateParameters)(NVSDK_NGX_Parameter** OutParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_DestroyParameters)(NVSDK_NGX_Parameter* InParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_CreateFeature)(ID3D12GraphicsCommandList* InCmdList, NVSDK_NGX_Feature InFeatureID, NVSDK_NGX_Parameter* InParameters, NVSDK_NGX_Handle** OutHandle); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_ReleaseFeature)(NVSDK_NGX_Handle* InHandle); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_D3D12_EvaluateFeature)(ID3D12GraphicsCommandList* InCmdList, const NVSDK_NGX_Handle* InFeatureHandle, const NVSDK_NGX_Parameter* InParameters, PFN_NVSDK_NGX_ProgressCallback InCallback); - class DLSSFeatureDx12 : public DLSSFeature, public IFeature_Dx12 { private: - inline static PFN_NVSDK_NGX_D3D12_Init_ProjectID _Init_with_ProjectID = nullptr; - inline static PFN_NVSDK_NGX_D3D12_Init_Ext _Init_Ext = nullptr; - inline static PFN_NVSDK_NGX_D3D12_Shutdown _Shutdown = nullptr; - inline static PFN_NVSDK_NGX_D3D12_Shutdown1 _Shutdown1 = nullptr; - inline static PFN_NVSDK_NGX_D3D12_GetParameters _GetParameters = nullptr; - inline static PFN_NVSDK_NGX_D3D12_AllocateParameters _AllocateParameters = nullptr; - inline static PFN_NVSDK_NGX_D3D12_DestroyParameters _DestroyParameters = nullptr; - inline static PFN_NVSDK_NGX_D3D12_CreateFeature _CreateFeature = nullptr; - inline static PFN_NVSDK_NGX_D3D12_ReleaseFeature _ReleaseFeature = nullptr; - inline static PFN_NVSDK_NGX_D3D12_EvaluateFeature _EvaluateFeature = nullptr; - float GetSharpness(const NVSDK_NGX_Parameter* InParameters); protected: diff --git a/OptiScaler/backends/dlss/DLSSFeature_Vk.cpp b/OptiScaler/backends/dlss/DLSSFeature_Vk.cpp index d78d5e9d..ed3b8fee 100644 --- a/OptiScaler/backends/dlss/DLSSFeature_Vk.cpp +++ b/OptiScaler/backends/dlss/DLSSFeature_Vk.cpp @@ -26,47 +26,21 @@ bool DLSSFeatureVk::Init(VkInstance InInstance, VkPhysicalDevice InPD, VkDevice { if (!_dlssInited) { - NVSDK_NGX_FeatureCommonInfo fcInfo{}; + _dlssInited = NVNGXProxy::InitVulkan(InInstance, InPD, InDevice, InGIPA, InGDPA); - GetFeatureCommonInfo(&fcInfo); + if (!_dlssInited) + return false; - if (Config::Instance()->NVNGX_ProjectId != "" && _Init_with_ProjectID != nullptr) - { - spdlog::debug("DLSSFeatureVk::Init _Init_with_ProjectID!"); - - nvResult = _Init_with_ProjectID(Config::Instance()->NVNGX_ProjectId.c_str(), Config::Instance()->NVNGX_Engine, Config::Instance()->NVNGX_EngineVersion.c_str(), - Config::Instance()->NVNGX_ApplicationDataPath.c_str(), InInstance, InPD, InDevice, InGIPA, InGDPA, Config::Instance()->NVNGX_Version, &fcInfo); - } - else if (_Init_Ext != nullptr) - { - spdlog::debug("DLSSFeatureVk::Init _Init_Ext!"); - - nvResult = _Init_Ext(Config::Instance()->NVNGX_ApplicationId, Config::Instance()->NVNGX_ApplicationDataPath.c_str(), - InInstance, InPD, InDevice, InGIPA, InGDPA, Config::Instance()->NVNGX_Version, &fcInfo); - } - else - { - spdlog::error("DLSSFeatureVk::Init _Init_with_ProjectID and is null"); - break; - } - - if (nvResult != NVSDK_NGX_Result_Success) - { - spdlog::error("DLSSFeatureVk::Init _Init_with_ProjectID result: {0:X}", (unsigned int)nvResult); - break; - } - - _dlssInited = true; //delay between init and create feature std::this_thread::sleep_for(std::chrono::milliseconds(500)); } - if (_AllocateParameters != nullptr) + if (NVNGXProxy::VULKAN_AllocateParameters() != nullptr) { spdlog::debug("DLSSFeatureVk::Init _AllocateParameters will be used"); - nvResult = _AllocateParameters(&Parameters); + nvResult = NVNGXProxy::VULKAN_AllocateParameters()(&Parameters); if (nvResult != NVSDK_NGX_Result_Success) { @@ -78,11 +52,11 @@ bool DLSSFeatureVk::Init(VkInstance InInstance, VkPhysicalDevice InPD, VkDevice DumpNvParams(Parameters); #endif } - else if (_GetParameters != nullptr) + else if (NVNGXProxy::VULKAN_GetParameters() != nullptr) { spdlog::debug("DLSSFeatureVk::Init _GetParameters will be used"); - nvResult = _GetParameters(&Parameters); + nvResult = NVNGXProxy::VULKAN_GetParameters()(&Parameters); if (nvResult != NVSDK_NGX_Result_Success) { @@ -102,12 +76,12 @@ bool DLSSFeatureVk::Init(VkInstance InInstance, VkPhysicalDevice InPD, VkDevice spdlog::info("DLSSFeatureVk::Evaluate Creating DLSS feature"); - if (_CreateFeature != nullptr) + if (NVNGXProxy::VULKAN_CreateFeature() != nullptr) { ProcessInitParams(InParameters); _p_dlssHandle = &_dlssHandle; - nvResult = _CreateFeature(InCmdList, NVSDK_NGX_Feature_SuperSampling, Parameters, &_p_dlssHandle); + nvResult = NVNGXProxy::VULKAN_CreateFeature()(InCmdList, NVSDK_NGX_Feature_SuperSampling, Parameters, &_p_dlssHandle); if (nvResult != NVSDK_NGX_Result_Success) { @@ -142,11 +116,11 @@ bool DLSSFeatureVk::Evaluate(VkCommandBuffer InCmdBuffer, const NVSDK_NGX_Parame NVSDK_NGX_Result nvResult; - if (_EvaluateFeature != nullptr) + if (NVNGXProxy::VULKAN_EvaluateFeature() != nullptr) { ProcessEvaluateParams(InParameters); - nvResult = _EvaluateFeature(InCmdBuffer, _p_dlssHandle, Parameters, NULL); + nvResult = NVNGXProxy::VULKAN_EvaluateFeature()(InCmdBuffer, _p_dlssHandle, Parameters, NULL); if (nvResult != NVSDK_NGX_Result_Success) { @@ -169,10 +143,10 @@ void DLSSFeatureVk::Shutdown(VkDevice InDevice) { if (_dlssInited) { - if (_Shutdown != nullptr) - _Shutdown(); - else if (_Shutdown1 != nullptr) - _Shutdown1(InDevice); + if (NVNGXProxy::VULKAN_Shutdown() != nullptr) + NVNGXProxy::VULKAN_Shutdown()(); + else if (NVNGXProxy::VULKAN_Shutdown1() != nullptr) + NVNGXProxy::VULKAN_Shutdown1()(InDevice); } DLSSFeature::Shutdown(); @@ -180,51 +154,26 @@ void DLSSFeatureVk::Shutdown(VkDevice InDevice) DLSSFeatureVk::DLSSFeatureVk(unsigned int InHandleId, const NVSDK_NGX_Parameter* InParameters) : IFeature(InHandleId, InParameters), IFeature_Vk(InHandleId, InParameters), DLSSFeature(InHandleId, InParameters) { - if (!_moduleLoaded) - return; + if (NVNGXProxy::NVNGXModule() == nullptr) + { + spdlog::info("DLSSFeatureVk::DLSSFeatureVk nvngx.dll not loaded, now loading"); + NVNGXProxy::InitNVNGX(); + } - if (_Init_with_ProjectID == nullptr) - _Init_with_ProjectID = (PFN_NVSDK_NGX_VULKAN_Init_ProjectID)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_Init_ProjectID"); - - if (_Init_Ext == nullptr) - _Init_Ext = (PFN_NVSDK_NGX_VULKAN_Init)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_Init"); - - if (_Shutdown == nullptr) - _Shutdown = (PFN_NVSDK_NGX_VULKAN_Shutdown)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_Shutdown"); - - if (_Shutdown1 == nullptr) - _Shutdown1 = (PFN_NVSDK_NGX_VULKAN_Shutdown1)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_Shutdown1"); - - if (_GetParameters == nullptr) - _GetParameters = (PFN_NVSDK_NGX_VULKAN_GetParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_GetParameters"); - - if (_AllocateParameters == nullptr) - _AllocateParameters = (PFN_NVSDK_NGX_VULKAN_AllocateParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_AllocateParameters"); - - if (_DestroyParameters == nullptr) - _DestroyParameters = (PFN_NVSDK_NGX_VULKAN_DestroyParameters)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_DestroyParameters"); - - if (_CreateFeature == nullptr) - _CreateFeature = (PFN_NVSDK_NGX_VULKAN_CreateFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_CreateFeature"); - - if (_ReleaseFeature == nullptr) - _ReleaseFeature = (PFN_NVSDK_NGX_VULKAN_ReleaseFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_ReleaseFeature"); - - if (_EvaluateFeature == nullptr) - _EvaluateFeature = (PFN_NVSDK_NGX_VULKAN_EvaluateFeature)GetProcAddress(NVNGX(), "NVSDK_NGX_VULKAN_EvaluateFeature"); - - _moduleLoaded = (_Init_with_ProjectID != nullptr || _Init_Ext != nullptr) && (_Shutdown != nullptr || _Shutdown1 != nullptr) && - (_GetParameters != nullptr || _AllocateParameters != nullptr) && _DestroyParameters != nullptr && _CreateFeature != nullptr && - _ReleaseFeature != nullptr && _EvaluateFeature != nullptr; + _moduleLoaded = (NVNGXProxy::VULKAN_Init_with_ProjectID() != nullptr || NVNGXProxy::VULKAN_Init_Ext() != nullptr) && + (NVNGXProxy::VULKAN_Shutdown() != nullptr || NVNGXProxy::VULKAN_Shutdown1() != nullptr) && + (NVNGXProxy::VULKAN_GetParameters() != nullptr || NVNGXProxy::VULKAN_AllocateParameters() != nullptr) && + NVNGXProxy::VULKAN_DestroyParameters() != nullptr && NVNGXProxy::VULKAN_CreateFeature() != nullptr && + NVNGXProxy::VULKAN_ReleaseFeature() != nullptr && NVNGXProxy::VULKAN_EvaluateFeature() != nullptr; spdlog::info("DLSSFeatureVk::DLSSFeatureVk binding complete!"); } DLSSFeatureVk::~DLSSFeatureVk() { - if (Parameters != nullptr && _DestroyParameters != nullptr) - _DestroyParameters(Parameters); + if (Parameters != nullptr && NVNGXProxy::VULKAN_DestroyParameters() != nullptr) + NVNGXProxy::VULKAN_DestroyParameters()(Parameters); - if (_ReleaseFeature != nullptr && _p_dlssHandle != nullptr) - _ReleaseFeature(_p_dlssHandle); + if (NVNGXProxy::VULKAN_ReleaseFeature() != nullptr && _p_dlssHandle != nullptr) + NVNGXProxy::VULKAN_ReleaseFeature()(_p_dlssHandle); } diff --git a/OptiScaler/backends/dlss/DLSSFeature_Vk.h b/OptiScaler/backends/dlss/DLSSFeature_Vk.h index 17d11f02..0234315d 100644 --- a/OptiScaler/backends/dlss/DLSSFeature_Vk.h +++ b/OptiScaler/backends/dlss/DLSSFeature_Vk.h @@ -4,30 +4,9 @@ #include #include "nvsdk_ngx_vk.h" -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_Init)(unsigned long long InApplicationId, const wchar_t* InApplicationDataPath, VkInstance InInstance, VkPhysicalDevice InPD, VkDevice InDevice, PFN_vkGetInstanceProcAddr InGIPA, PFN_vkGetDeviceProcAddr InGDPA, NVSDK_NGX_Version InSDKVersion, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_Init_ProjectID)(const char* InProjectId, NVSDK_NGX_EngineType InEngineType, const char* InEngineVersion, const wchar_t* InApplicationDataPath, VkInstance InInstance, VkPhysicalDevice InPD, VkDevice InDevice, PFN_vkGetInstanceProcAddr InGIPA, PFN_vkGetDeviceProcAddr InGDPA, NVSDK_NGX_Version InSDKVersion, const NVSDK_NGX_FeatureCommonInfo* InFeatureInfo); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_Shutdown)(void); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_Shutdown1)(VkDevice InDevice); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_GetParameters)(NVSDK_NGX_Parameter** OutParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_AllocateParameters)(NVSDK_NGX_Parameter** OutParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_DestroyParameters)(NVSDK_NGX_Parameter* InParameters); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_CreateFeature)(VkCommandBuffer InCmdBuffer, NVSDK_NGX_Feature InFeatureID, NVSDK_NGX_Parameter* InParameters, NVSDK_NGX_Handle** OutHandle); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_ReleaseFeature)(NVSDK_NGX_Handle* InHandle); -typedef NVSDK_NGX_Result(*PFN_NVSDK_NGX_VULKAN_EvaluateFeature)(VkCommandBuffer InCmdList, const NVSDK_NGX_Handle* InFeatureHandle, const NVSDK_NGX_Parameter* InParameters, PFN_NVSDK_NGX_ProgressCallback InCallback); - class DLSSFeatureVk : public DLSSFeature, public IFeature_Vk { private: - inline static PFN_NVSDK_NGX_VULKAN_Init_ProjectID _Init_with_ProjectID = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_Init _Init_Ext = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_Shutdown _Shutdown = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_Shutdown1 _Shutdown1 = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_GetParameters _GetParameters = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_AllocateParameters _AllocateParameters = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_DestroyParameters _DestroyParameters = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_CreateFeature _CreateFeature = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_ReleaseFeature _ReleaseFeature = nullptr; - inline static PFN_NVSDK_NGX_VULKAN_EvaluateFeature _EvaluateFeature = nullptr; protected: