diff --git a/OptiScaler/NVNGX_DLSS_Dx11.cpp b/OptiScaler/NVNGX_DLSS_Dx11.cpp index aaa1950a..6ed58e7a 100644 --- a/OptiScaler/NVNGX_DLSS_Dx11.cpp +++ b/OptiScaler/NVNGX_DLSS_Dx11.cpp @@ -26,11 +26,16 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_Ext(unsigned long long InApp std::string str(string.begin(), string.end()); spdlog::debug("NVSDK_NGX_D3D11_Init_Ext InApplicationDataPath {0}", str); + Config::Instance()->NVNGX_ApplicationId = InApplicationId; + Config::Instance()->NVNGX_ApplicationDataPath = InApplicationDataPath; + Config::Instance()->NVNGX_Version = InSDKVersion; + Config::Instance()->NVNGX_FeatureInfo = InFeatureInfo; + if (InDevice) D3D11Device = InDevice; if (InFeatureInfo) - Config::Instance()->NVSDK_Logger = InFeatureInfo->LoggingInfo; + Config::Instance()->NVNGX_Logger = InFeatureInfo->LoggingInfo; Config::Instance()->Api = NVNGX_DX11; @@ -51,6 +56,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_ProjectID(const char* InProj spdlog::debug("NVSDK_NGX_D3D11_Init_ProjectID InEngineType: {0}", (int)InEngineType); Config::Instance()->NVNGX_Engine = InEngineType; + Config::Instance()->NVNGX_EngineVersion = InEngineVersion; if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL && InEngineVersion) { @@ -68,6 +74,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_with_ProjectID(const char* I spdlog::debug("NVSDK_NGX_D3D11_Init_with_ProjectID InEngineType: {0}", (int)InEngineType); Config::Instance()->NVNGX_Engine = InEngineType; + Config::Instance()->NVNGX_EngineVersion = InEngineVersion; if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL && InEngineVersion) { @@ -206,10 +213,26 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_CreateFeature(ID3D11DeviceContext if (Config::Instance()->Dx11Upscaler.value_or("fsr22") == "xess") { - spdlog::info("NVSDK_NGX_D3D11_CreateFeature creating new XeSS with Dx12 feature"); Dx11Contexts[handleId] = std::make_unique(handleId, InParameters); + + + if (!Dx11Contexts[handleId]->IsInited()) + { + spdlog::error("NVSDK_NGX_D3D11_CreateFeature can't create new XeSS with Dx12 feature, Fallback to FSR2.2!"); + + Dx11Contexts[handleId].reset(); + auto it = std::find_if(Dx11Contexts.begin(), Dx11Contexts.end(), [&handleId](const auto& p) { return p.first == handleId; }); + Dx11Contexts.erase(it); + + Config::Instance()->Dx11Upscaler = "fsr22"; + } + else + { + spdlog::info("NVSDK_NGX_D3D11_CreateFeature creating new XeSS with Dx12 feature"); + } } - else if (Config::Instance()->Dx11Upscaler.value_or("fsr22") == "fsr22_12") + + if (Config::Instance()->Dx11Upscaler.value_or("fsr22") == "fsr22_12") { spdlog::info("NVSDK_NGX_D3D11_CreateFeature creating new FSR 2.2.1 with Dx12 feature"); Dx11Contexts[handleId] = std::make_unique(handleId, InParameters); diff --git a/OptiScaler/NVNGX_DLSS_Dx12.cpp b/OptiScaler/NVNGX_DLSS_Dx12.cpp index eaa61b55..ee530d83 100644 --- a/OptiScaler/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/NVNGX_DLSS_Dx12.cpp @@ -3,7 +3,6 @@ #include #include -#include "imgui/imgui/imgui_impl_dx12.h" #include "detours/detours.h" #include "Config.h" @@ -161,9 +160,14 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp std::string str(appDataPath.begin(), appDataPath.end()); spdlog::info("NVSDK_NGX_D3D12_Init_Ext InApplicationDataPath {0}", str); + Config::Instance()->NVNGX_ApplicationId = InApplicationId; + Config::Instance()->NVNGX_ApplicationDataPath = InApplicationDataPath; + Config::Instance()->NVNGX_Version = InSDKVersion; + Config::Instance()->NVNGX_FeatureInfo = InFeatureInfo; + if (InFeatureInfo != nullptr) { - Config::Instance()->NVSDK_Logger = InFeatureInfo->LoggingInfo; + Config::Instance()->NVNGX_Logger = InFeatureInfo->LoggingInfo; for (size_t i = 0; i < InFeatureInfo->PathListInfo.Length; i++) { @@ -207,6 +211,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_ProjectID(const char* InProj spdlog::info("NVSDK_NGX_D3D12_Init_ProjectID InEngineType: {0}", (int)InEngineType); Config::Instance()->NVNGX_Engine = InEngineType; + Config::Instance()->NVNGX_EngineVersion = InEngineVersion; if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL && InEngineVersion) { @@ -224,6 +229,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_with_ProjectID(const char* I spdlog::info("NVSDK_NGX_D3D12_Init_with_ProjectID InEngineType: {0}", (int)InEngineType); Config::Instance()->NVNGX_Engine = InEngineType; + Config::Instance()->NVNGX_EngineVersion = InEngineVersion; if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL && InEngineVersion) { @@ -368,8 +374,27 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_CreateFeature(ID3D12GraphicsComma upscalerChoice = 1; else if (Config::Instance()->Dx12Upscaler.value_or("xess") == "fsr21") upscalerChoice = 2; + } + + if (upscalerChoice == 0) + { + Dx12Contexts[handleId] = std::make_unique(handleId, InParameters); + + if (!Dx12Contexts[handleId]->IsInited()) + { + spdlog::error("NVSDK_NGX_D3D12_CreateFeature can't create new XeSS feature, Fallback to FSR2.1!"); + + Dx12Contexts[handleId].reset(); + auto it = std::find_if(Dx12Contexts.begin(), Dx12Contexts.end(), [&handleId](const auto& p) { return p.first == handleId; }); + Dx12Contexts.erase(it); + + upscalerChoice = 2; + } else + { Config::Instance()->Dx12Upscaler = "xess"; + spdlog::info("NVSDK_NGX_D3D12_CreateFeature creating new XeSS feature"); + } } if (upscalerChoice == 1) @@ -384,13 +409,6 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_CreateFeature(ID3D12GraphicsComma spdlog::info("NVSDK_NGX_D3D12_CreateFeature creating new FSR 2.1.2 feature"); Dx12Contexts[handleId] = std::make_unique(handleId, InParameters); } - else - { - Config::Instance()->Dx12Upscaler = "xess"; - spdlog::info("NVSDK_NGX_D3D12_CreateFeature creating new XeSS feature"); - - Dx12Contexts[handleId] = std::make_unique(handleId, InParameters); - } // nvsdk logging - ini first if (!Config::Instance()->LogToNGX.has_value()) diff --git a/OptiScaler/NVNGX_DLSS_Vk.cpp b/OptiScaler/NVNGX_DLSS_Vk.cpp index 296c4f04..21702c3f 100644 --- a/OptiScaler/NVNGX_DLSS_Vk.cpp +++ b/OptiScaler/NVNGX_DLSS_Vk.cpp @@ -28,6 +28,11 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init(unsigned long long InApplic spdlog::debug("NVSDK_NGX_VULKAN_Init InApplicationDataPath {0}", str); spdlog::info("NVSDK_NGX_VULKAN_Init InSDKVersion: {0:x}", (int)InSDKVersion); + Config::Instance()->NVNGX_ApplicationId = InApplicationId; + Config::Instance()->NVNGX_ApplicationDataPath = InApplicationDataPath; + Config::Instance()->NVNGX_Version = InSDKVersion; + Config::Instance()->NVNGX_FeatureInfo = InFeatureInfo; + if (InInstance) { spdlog::info("NVSDK_NGX_VULKAN_Init InInstance exist!"); @@ -59,7 +64,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init(unsigned long long InApplic } if (InFeatureInfo) - Config::Instance()->NVSDK_Logger = InFeatureInfo->LoggingInfo; + Config::Instance()->NVNGX_Logger = InFeatureInfo->LoggingInfo; Config::Instance()->Api = NVNGX_VULKAN; @@ -74,6 +79,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_ProjectID(const char* InPro spdlog::debug("NVSDK_NGX_VULKAN_Init_ProjectID InEngineType: {0}", (int)InEngineType); Config::Instance()->NVNGX_Engine = InEngineType; + Config::Instance()->NVNGX_EngineVersion = InEngineVersion; if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL && InEngineVersion) { @@ -92,6 +98,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_with_ProjectID(const char* spdlog::debug("NVSDK_NGX_VULKAN_Init_with_ProjectID InEngineType {0}", (int)InEngineType); Config::Instance()->NVNGX_Engine = InEngineType; + Config::Instance()->NVNGX_EngineVersion = InEngineVersion; if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL && InEngineVersion) { diff --git a/OptiScaler/backends/IFeature.h b/OptiScaler/backends/IFeature.h index ba4329e7..d0f214b9 100644 --- a/OptiScaler/backends/IFeature.h +++ b/OptiScaler/backends/IFeature.h @@ -7,17 +7,16 @@ inline static unsigned int handleCounter = 1000000; class IFeature { private: - NVSDK_NGX_Handle* _handle; - bool _initParameters = false; bool _isInited = false; int _featureFlags = 0; NVSDK_NGX_PerfQuality_Value _perfQualityValue; - void SetHandle(unsigned int InHandleId); protected: + NVSDK_NGX_Handle* _handle; + float _sharpness = 0; bool _hasColor = false; bool _hasDepth = false; @@ -35,8 +34,10 @@ protected: unsigned int _displayHeight = 0; long _frameCount = 0; + void SetHandle(unsigned int InHandleId); bool SetInitParameters(const NVSDK_NGX_Parameter* InParameters); void GetRenderResolution(const NVSDK_NGX_Parameter* InParameters, unsigned int* OutWidth, unsigned int* OutHeight); + virtual void SetInit(bool InValue) { _isInited = InValue; } public: diff --git a/OptiScaler/backends/xess/XeSSFeature.h b/OptiScaler/backends/xess/XeSSFeature.h index 028e31e4..d171b1ad 100644 --- a/OptiScaler/backends/xess/XeSSFeature.h +++ b/OptiScaler/backends/xess/XeSSFeature.h @@ -30,18 +30,18 @@ inline static std::string ResultToString(xess_result_t result) } } -typedef xess_result_t(XESS_API* PFN_xessD3D12CreateContext)(ID3D12Device* pDevice, xess_context_handle_t* phContext); -typedef xess_result_t(XESS_API* PFN_xessD3D12BuildPipelines)(xess_context_handle_t hContext, ID3D12PipelineLibrary* pPipelineLibrary, bool blocking, uint32_t initFlags); -typedef xess_result_t(XESS_API* PRN_xessD3D12Init)(xess_context_handle_t hContext, const xess_d3d12_init_params_t* pInitParams); -typedef xess_result_t(XESS_API* PFN_xessD3D12Execute)(xess_context_handle_t hContext, ID3D12GraphicsCommandList* pCommandList, const xess_d3d12_execute_params_t* pExecParams); -typedef xess_result_t(XESS_API* PFN_xessSelectNetworkModel)(xess_context_handle_t hContext, xess_network_model_t network); -typedef xess_result_t(XESS_API* PFN_xessStartDump)(xess_context_handle_t hContext, const xess_dump_parameters_t* dump_parameters); -typedef xess_result_t(XESS_API* PRN_xessGetVersion)(xess_version_t* pVersion); -typedef xess_result_t(XESS_API* PFN_xessIsOptimalDriver)(xess_context_handle_t hContext); -typedef xess_result_t(XESS_API* PFN_xessSetLoggingCallback)(xess_context_handle_t hContext, xess_logging_level_t loggingLevel, xess_app_log_callback_t loggingCallback); -typedef xess_result_t(XESS_API* PFN_xessGetProperties)(xess_context_handle_t hContext, const xess_2d_t* pOutputResolution, xess_properties_t* pBindingProperties); -typedef xess_result_t(XESS_API* PFN_xessDestroyContext)(xess_context_handle_t hContext); -typedef xess_result_t(XESS_API* PFN_xessSetVelocityScale)(xess_context_handle_t hContext, float x, float y); +typedef xess_result_t(*PFN_xessD3D12CreateContext)(ID3D12Device* pDevice, xess_context_handle_t* phContext); +typedef xess_result_t(*PFN_xessD3D12BuildPipelines)(xess_context_handle_t hContext, ID3D12PipelineLibrary* pPipelineLibrary, bool blocking, uint32_t initFlags); +typedef xess_result_t(*PRN_xessD3D12Init)(xess_context_handle_t hContext, const xess_d3d12_init_params_t* pInitParams); +typedef xess_result_t(*PFN_xessD3D12Execute)(xess_context_handle_t hContext, ID3D12GraphicsCommandList* pCommandList, const xess_d3d12_execute_params_t* pExecParams); +typedef xess_result_t(*PFN_xessSelectNetworkModel)(xess_context_handle_t hContext, xess_network_model_t network); +typedef xess_result_t(*PFN_xessStartDump)(xess_context_handle_t hContext, const xess_dump_parameters_t* dump_parameters); +typedef xess_result_t(*PRN_xessGetVersion)(xess_version_t* pVersion); +typedef xess_result_t(*PFN_xessIsOptimalDriver)(xess_context_handle_t hContext); +typedef xess_result_t(*PFN_xessSetLoggingCallback)(xess_context_handle_t hContext, xess_logging_level_t loggingLevel, xess_app_log_callback_t loggingCallback); +typedef xess_result_t(*PFN_xessGetProperties)(xess_context_handle_t hContext, const xess_2d_t* pOutputResolution, xess_properties_t* pBindingProperties); +typedef xess_result_t(*PFN_xessDestroyContext)(xess_context_handle_t hContext); +typedef xess_result_t(*PFN_xessSetVelocityScale)(xess_context_handle_t hContext, float x, float y); class XeSSFeature : public virtual IFeature { @@ -66,7 +66,6 @@ private: PFN_xessDestroyContext _xessDestroyContext = nullptr; PFN_xessSetVelocityScale _xessSetVelocityScale = nullptr; - HMODULE _libxess = nullptr; bool _moduleLoaded = false; @@ -79,20 +78,20 @@ protected: float GetSharpness(const NVSDK_NGX_Parameter* InParameters); bool CreateBufferResource(ID3D12Device* InDevice, ID3D12Resource* InSource, ID3D12Resource** OutDest, D3D12_RESOURCE_STATES InDestState); - bool ModuleLoaded() { return _moduleLoaded; } + bool ModuleLoaded() const { return _moduleLoaded; } - PFN_xessD3D12CreateContext D3D12CreateContext() { return _xessD3D12CreateContext; } - PFN_xessD3D12BuildPipelines D3D12BuildPipelines() { return _xessD3D12BuildPipelines; } - PRN_xessD3D12Init D3D12Init() { return _xessD3D12Init; } - PFN_xessD3D12Execute D3D12Execute() { return _xessD3D12Execute; } - PFN_xessSelectNetworkModel SelectNetworkModel() { return _xessSelectNetworkModel; } - PFN_xessStartDump StartDump() { return _xessStartDump; } - PRN_xessGetVersion GetVersion() { return _xessGetVersion; } - PFN_xessIsOptimalDriver IsOptimalDriver() { return _xessIsOptimalDriver; } - PFN_xessSetLoggingCallback SetLoggingCallback() { return _xessSetLoggingCallback; } - PFN_xessGetProperties GetProperties() { return _xessGetProperties; } - PFN_xessDestroyContext DestroyContext() { return _xessDestroyContext; } - PFN_xessSetVelocityScale SetVelocityScale() { return _xessSetVelocityScale; } + PFN_xessD3D12CreateContext D3D12CreateContext() const { return _xessD3D12CreateContext; } + PFN_xessD3D12BuildPipelines D3D12BuildPipelines() const { return _xessD3D12BuildPipelines; } + PRN_xessD3D12Init D3D12Init() const { return _xessD3D12Init; } + PFN_xessD3D12Execute D3D12Execute() const { return _xessD3D12Execute; } + PFN_xessSelectNetworkModel SelectNetworkModel() const { return _xessSelectNetworkModel; } + PFN_xessStartDump StartDump() const { return _xessStartDump; } + PRN_xessGetVersion GetVersion() const { return _xessGetVersion; } + PFN_xessIsOptimalDriver IsOptimalDriver() const { return _xessIsOptimalDriver; } + PFN_xessSetLoggingCallback SetLoggingCallback() const { return _xessSetLoggingCallback; } + PFN_xessGetProperties GetProperties() const { return _xessGetProperties; } + PFN_xessDestroyContext DestroyContext() const { return _xessDestroyContext; } + PFN_xessSetVelocityScale SetVelocityScale() const { return _xessSetVelocityScale; } public: feature_version Version() final { return feature_version{ _xessVersion.major, _xessVersion.minor, _xessVersion.patch }; }