mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-29 21:13:14 +00:00
Added FeatureProvider_Dx11
This commit is contained in:
@@ -370,6 +370,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
|
||||
<ClInclude Include="upscalers\dlss\DLSSFeature_Dx11.h" />
|
||||
<ClInclude Include="upscalers\dlss\DLSSFeature_Dx12.h" />
|
||||
<ClInclude Include="upscalers\dlss\DLSSFeature_Vk.h" />
|
||||
<ClInclude Include="upscalers\FeatureProvider_Dx11.h" />
|
||||
<ClInclude Include="upscalers\FeatureProvider_Dx12.h" />
|
||||
<ClInclude Include="upscalers\fsr31\FSR31Feature.h" />
|
||||
<ClInclude Include="upscalers\fsr31\FSR31Feature_Dx11.h" />
|
||||
@@ -511,6 +512,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
|
||||
<ClCompile Include="upscalers\dlss\DLSSFeature_Dx11.cpp" />
|
||||
<ClCompile Include="upscalers\dlss\DLSSFeature_Dx12.cpp" />
|
||||
<ClCompile Include="upscalers\dlss\DLSSFeature_Vk.cpp" />
|
||||
<ClCompile Include="upscalers\FeatureProvider_Dx11.cpp" />
|
||||
<ClCompile Include="upscalers\FeatureProvider_Dx12.cpp" />
|
||||
<ClCompile Include="upscalers\fsr2_212\FSR2Feature_212.cpp" />
|
||||
<ClCompile Include="upscalers\fsr2_212\FSR2Feature_Dx11On12_212.cpp" />
|
||||
|
||||
@@ -3,19 +3,12 @@
|
||||
#include "Config.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <upscalers/IFeature_Dx11.h>
|
||||
#include <upscalers/FeatureProvider_Dx11.h>
|
||||
|
||||
#include "NVNGX_DLSS.h"
|
||||
#include "NVNGX_Parameter.h"
|
||||
#include "proxies/NVNGX_Proxy.h"
|
||||
#include "NVNGX_DLSS.h"
|
||||
|
||||
#include "upscalers/dlss/DLSSFeature_Dx11.h"
|
||||
#include "upscalers/dlssd/DLSSDFeature_Dx11.h"
|
||||
#include "upscalers/fsr2/FSR2Feature_Dx11.h"
|
||||
#include "upscalers/fsr2/FSR2Feature_Dx11On12.h"
|
||||
#include "upscalers/fsr2_212/FSR2Feature_Dx11On12_212.h"
|
||||
#include "upscalers/fsr31/FSR31Feature_Dx11.h"
|
||||
#include "upscalers/fsr31/FSR31Feature_Dx11On12.h"
|
||||
#include "upscalers/xess/XeSSFeature_Dx11.h"
|
||||
#include "upscalers/xess/XeSSFeature_Dx11on12.h"
|
||||
|
||||
#include "hooks/HooksDx.h"
|
||||
|
||||
@@ -222,8 +215,6 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Shutdown()
|
||||
D3D11Device = nullptr;
|
||||
State::Instance().currentFeature = nullptr;
|
||||
|
||||
DLSSFeatureDx11::Shutdown(D3D11Device);
|
||||
|
||||
if (Config::Instance()->DLSSEnabled.value_or_default() && NVNGXProxy::IsDx11Inited() &&
|
||||
NVNGXProxy::D3D11_Shutdown() != nullptr)
|
||||
{
|
||||
@@ -407,129 +398,36 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_CreateFeature(ID3D11DeviceContext
|
||||
|
||||
if (InFeatureID == NVSDK_NGX_Feature_SuperSampling)
|
||||
{
|
||||
std::string defaultUpscaler = "fsr22";
|
||||
std::string upscalerChoice = "fsr22"; // Default FSR 2.2.1
|
||||
|
||||
// If original NVNGX available use DLSS as base upscaler
|
||||
if (NVNGXProxy::IsDx11Inited())
|
||||
defaultUpscaler = "dlss";
|
||||
if (Config::Instance()->DLSSEnabled.value_or_default() && NVNGXProxy::IsDx11Inited())
|
||||
upscalerChoice = "dlss";
|
||||
|
||||
if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "xess")
|
||||
if (Config::Instance()->Dx11Upscaler.has_value())
|
||||
upscalerChoice = Config::Instance()->Dx11Upscaler.value();
|
||||
|
||||
LOG_INFO("Creating new {} feature", upscalerChoice);
|
||||
|
||||
Dx11Contexts[handleId] = {};
|
||||
|
||||
if (!FeatureProvider_Dx11::GetFeature(upscalerChoice, handleId, InParameters, &Dx11Contexts[handleId].feature))
|
||||
{
|
||||
Dx11Contexts[handleId].feature = std::make_unique<XeSSFeature_Dx11>(handleId, InParameters);
|
||||
|
||||
if (!Dx11Contexts[handleId].feature->ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("can't create new XeSS feature, Fallback to FSR2.2!");
|
||||
|
||||
Dx11Contexts[handleId].feature.reset();
|
||||
Dx11Contexts[handleId].feature = nullptr;
|
||||
|
||||
Config::Instance()->Dx11Upscaler = "fsr22";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("creating new XeSS feature");
|
||||
}
|
||||
LOG_ERROR("Can't create {} feature", upscalerChoice);
|
||||
return NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
|
||||
if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "xess_12")
|
||||
{
|
||||
Dx11Contexts[handleId].feature = std::make_unique<XeSSFeatureDx11on12>(handleId, InParameters);
|
||||
|
||||
if (!Dx11Contexts[handleId].feature->ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("can't create new XeSS with Dx12 feature, Fallback to FSR2.2!");
|
||||
|
||||
Dx11Contexts[handleId].feature.reset();
|
||||
Dx11Contexts[handleId].feature = nullptr;
|
||||
|
||||
Config::Instance()->Dx11Upscaler = "fsr22";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("creating new XeSS with Dx12 feature");
|
||||
}
|
||||
}
|
||||
|
||||
if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "dlss")
|
||||
{
|
||||
if (Config::Instance()->DLSSEnabled.value_or_default())
|
||||
{
|
||||
Dx11Contexts[handleId].feature = std::make_unique<DLSSFeatureDx11>(handleId, InParameters);
|
||||
|
||||
if (!Dx11Contexts[handleId].feature->ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("can't create new DLSS feature, Fallback to FSR2.2!");
|
||||
|
||||
Dx11Contexts[handleId].feature.reset();
|
||||
Dx11Contexts[handleId].feature = nullptr;
|
||||
// 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
|
||||
{
|
||||
LOG_INFO("creating new DLSS feature");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "fsr31_12")
|
||||
{
|
||||
Dx11Contexts[handleId].feature = std::make_unique<FSR31FeatureDx11on12>(handleId, InParameters);
|
||||
|
||||
if (!Dx11Contexts[handleId].feature->ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("can't create new FSR 3.1 feature, Fallback to FSR2.2!");
|
||||
|
||||
Dx11Contexts[handleId].feature.reset();
|
||||
Dx11Contexts[handleId].feature = nullptr;
|
||||
// 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
|
||||
{
|
||||
LOG_INFO("creating new FSR 3.1 feature");
|
||||
}
|
||||
}
|
||||
|
||||
if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "fsr22_12")
|
||||
{
|
||||
LOG_INFO("creating new FSR 2.2.1 with Dx12 feature");
|
||||
Dx11Contexts[handleId].feature = std::make_unique<FSR2FeatureDx11on12>(handleId, InParameters);
|
||||
}
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "fsr21_12")
|
||||
{
|
||||
LOG_INFO("creating new FSR 2.1.2 with Dx12 feature");
|
||||
Dx11Contexts[handleId].feature = std::make_unique<FSR2FeatureDx11on12_212>(handleId, InParameters);
|
||||
}
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "fsr22")
|
||||
{
|
||||
LOG_INFO("creating new native FSR 2.2.1 feature");
|
||||
Dx11Contexts[handleId].feature = std::make_unique<FSR2FeatureDx11>(handleId, InParameters);
|
||||
}
|
||||
else if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "fsr31")
|
||||
{
|
||||
LOG_INFO("creating new native FSR 3.1.0 feature");
|
||||
Dx11Contexts[handleId].feature = std::make_unique<FSR31FeatureDx11>(handleId, InParameters);
|
||||
}
|
||||
// else if (Config::Instance()->Dx11Upscaler.value_or(defaultUpscaler) == "fsr304")
|
||||
//{
|
||||
// LOG_INFO("creating new native FSR 3.1.0 feature");
|
||||
// Dx11Contexts[handleId].feature = std::make_unique<FSR31FeatureDx11>(handleId, InParameters);
|
||||
// }
|
||||
}
|
||||
else
|
||||
else if (InFeatureID == NVSDK_NGX_Feature_RayReconstruction)
|
||||
{
|
||||
LOG_INFO("creating new DLSSD feature");
|
||||
Dx11Contexts[handleId].feature = std::make_unique<DLSSDFeatureDx11>(handleId, InParameters);
|
||||
LOG_INFO("Creating new DLSSD feature");
|
||||
|
||||
Dx11Contexts[handleId] = {};
|
||||
|
||||
if (!FeatureProvider_Dx11::GetFeature("dlssd", handleId, InParameters, &Dx11Contexts[handleId].feature))
|
||||
{
|
||||
LOG_ERROR("Can't create DLSSD feature");
|
||||
return NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
}
|
||||
|
||||
auto deviceContext = Dx11Contexts[handleId].feature.get();
|
||||
@@ -699,205 +597,18 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_EvaluateFeature(ID3D11DeviceConte
|
||||
LOG_INFO("callback exist");
|
||||
|
||||
IFeature_Dx11* deviceContext = nullptr;
|
||||
auto activeContext = &Dx11Contexts[handleId];
|
||||
|
||||
if (State::Instance().changeBackend[handleId])
|
||||
{
|
||||
if (State::Instance().newBackend == "" ||
|
||||
(!Config::Instance()->DLSSEnabled.value_or_default() && State::Instance().newBackend == "dlss"))
|
||||
State::Instance().newBackend = Config::Instance()->Dx11Upscaler.value_or_default();
|
||||
FeatureProvider_Dx11::ChangeFeature(State::Instance().newBackend, D3D11Device, InDevCtx, handleId, InParameters,
|
||||
activeContext);
|
||||
|
||||
Dx11Contexts[handleId].changeBackendCounter++;
|
||||
|
||||
// first release everything
|
||||
if (Dx11Contexts[handleId].changeBackendCounter == 1)
|
||||
{
|
||||
if (Dx11Contexts.contains(handleId) && Dx11Contexts[handleId].feature != nullptr)
|
||||
{
|
||||
LOG_INFO("changing backend to {0}", State::Instance().newBackend);
|
||||
|
||||
auto dc = Dx11Contexts[handleId].feature.get();
|
||||
|
||||
if (State::Instance().newBackend != "dlssd" && State::Instance().newBackend != "dlss")
|
||||
Dx11Contexts[handleId].createParams = GetNGXParameters("OptiDx11");
|
||||
else
|
||||
Dx11Contexts[handleId].createParams = InParameters;
|
||||
|
||||
Dx11Contexts[handleId].createParams->Set(NVSDK_NGX_Parameter_DLSS_Feature_Create_Flags,
|
||||
dc->GetFeatureFlags());
|
||||
Dx11Contexts[handleId].createParams->Set(NVSDK_NGX_Parameter_Width, dc->RenderWidth());
|
||||
Dx11Contexts[handleId].createParams->Set(NVSDK_NGX_Parameter_Height, dc->RenderHeight());
|
||||
Dx11Contexts[handleId].createParams->Set(NVSDK_NGX_Parameter_OutWidth, dc->DisplayWidth());
|
||||
Dx11Contexts[handleId].createParams->Set(NVSDK_NGX_Parameter_OutHeight, dc->DisplayHeight());
|
||||
Dx11Contexts[handleId].createParams->Set(NVSDK_NGX_Parameter_PerfQualityValue, dc->PerfQualityValue());
|
||||
|
||||
LOG_TRACE("sleeping before reset of current feature for 1000ms");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
|
||||
Dx11Contexts[handleId].feature.reset();
|
||||
Dx11Contexts[handleId].feature = nullptr;
|
||||
// auto it = std::find_if(Dx11Contexts.begin(), Dx11Contexts.end(), [&handleId](const auto& p) { return
|
||||
// p.first == handleId; }); Dx11Contexts.erase(it);
|
||||
|
||||
State::Instance().currentFeature = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("can't find handle {0} in Dx11Contexts!", handleId);
|
||||
|
||||
State::Instance().newBackend = "";
|
||||
State::Instance().changeBackend[handleId] = false;
|
||||
|
||||
if (Dx11Contexts[handleId].createParams != nullptr)
|
||||
{
|
||||
free(Dx11Contexts[handleId].createParams);
|
||||
Dx11Contexts[handleId].createParams = nullptr;
|
||||
}
|
||||
|
||||
Dx11Contexts[handleId].changeBackendCounter = 0;
|
||||
}
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
if (Dx11Contexts[handleId].changeBackendCounter == 2)
|
||||
{
|
||||
// next frame prepare stuff
|
||||
if (State::Instance().newBackend == "xess")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "xess";
|
||||
LOG_INFO("creating new XeSS feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<XeSSFeature_Dx11>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "xess_12")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "xess_12";
|
||||
LOG_INFO("creating new XeSS with Dx12 feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<XeSSFeatureDx11on12>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "dlss")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "dlss";
|
||||
LOG_INFO("creating new DLSS feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<DLSSFeatureDx11>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "dlssd")
|
||||
{
|
||||
LOG_INFO("creating new DLSSD feature");
|
||||
Dx11Contexts[handleId].feature = std::make_unique<DLSSDFeatureDx11>(handleId, InParameters);
|
||||
}
|
||||
else if (State::Instance().newBackend == "fsr21_12")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "fsr21_12";
|
||||
LOG_INFO("creating new FSR 2.1.2 with Dx12 feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<FSR2FeatureDx11on12_212>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "fsr31_12")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "fsr31_12";
|
||||
LOG_INFO("creating new FSR 3.1 with Dx12 feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<FSR31FeatureDx11on12>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "fsr22_12")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "fsr22_12";
|
||||
LOG_INFO("creating new FSR 2.2.1 with Dx12 feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<FSR2FeatureDx11on12>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "fsr22")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "fsr22";
|
||||
LOG_INFO("creating new native FSR 2.2.1 feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<FSR2FeatureDx11>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
else if (State::Instance().newBackend == "fsr31")
|
||||
{
|
||||
Config::Instance()->Dx11Upscaler = "fsr31";
|
||||
LOG_INFO("creating new native FSR 3.1.0 feature");
|
||||
Dx11Contexts[handleId].feature =
|
||||
std::make_unique<FSR31FeatureDx11>(handleId, Dx11Contexts[handleId].createParams);
|
||||
}
|
||||
// else if (State::Instance().newBackend == "fsr304")
|
||||
//{
|
||||
// Config::Instance()->Dx11Upscaler = "fsr31";
|
||||
// LOG_INFO("creating new native FSR 3.1.0 feature");
|
||||
// Dx11Contexts[handleId].feature = std::make_unique<FSR31FeatureDx11>(handleId,
|
||||
// Dx11Contexts[handleId].createParams);
|
||||
// }
|
||||
|
||||
if (Config::Instance()->Dx11DelayedInit.value_or_default() && State::Instance().newBackend != "fsr22" &&
|
||||
State::Instance().newBackend != "dlss" && State::Instance().newBackend != "dlssd")
|
||||
{
|
||||
LOG_TRACE("sleeping after new creation of new feature for 1000ms");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
if (Dx11Contexts[handleId].changeBackendCounter == 3)
|
||||
{
|
||||
// then init and continue
|
||||
auto initResult =
|
||||
Dx11Contexts[handleId].feature->Init(D3D11Device, InDevCtx, Dx11Contexts[handleId].createParams);
|
||||
|
||||
if (Config::Instance()->Dx11DelayedInit.value_or_default())
|
||||
{
|
||||
LOG_TRACE("sleeping after new Init of new feature for 1000ms");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
Dx11Contexts[handleId].changeBackendCounter = 0;
|
||||
|
||||
if (!initResult || !Dx11Contexts[handleId].feature->ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("init failed with {0} feature", State::Instance().newBackend);
|
||||
|
||||
if (State::Instance().newBackend != "dlssd")
|
||||
{
|
||||
State::Instance().newBackend = "fsr22";
|
||||
State::Instance().changeBackend[handleId] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
State::Instance().newBackend = "";
|
||||
State::Instance().changeBackend[handleId] = false;
|
||||
return NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("init successful for {0}, upscaler changed", State::Instance().newBackend);
|
||||
|
||||
State::Instance().newBackend = "";
|
||||
State::Instance().changeBackend[handleId] = false;
|
||||
evalCounter = 0;
|
||||
}
|
||||
|
||||
// if opti nvparam release it
|
||||
int optiParam = 0;
|
||||
if (Dx11Contexts[handleId].createParams->Get("OptiScaler", &optiParam) == NVSDK_NGX_Result_Success &&
|
||||
optiParam == 1)
|
||||
{
|
||||
free(Dx11Contexts[handleId].createParams);
|
||||
Dx11Contexts[handleId].createParams = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// if initial feature can't be inited
|
||||
State::Instance().currentFeature = Dx11Contexts[handleId].feature.get();
|
||||
evalCounter = 0;
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
auto activeContext = &Dx11Contexts[handleId];
|
||||
|
||||
if (activeContext->feature == nullptr) // prevent source api name flicker when dlssg is active
|
||||
{
|
||||
State::Instance().setInputApiName = State::Instance().currentInputApiName;
|
||||
|
||||
@@ -1012,6 +1012,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom
|
||||
FeatureProvider_Dx12::ChangeFeature(State::Instance().newBackend, D3D12Device, InCmdList, handleId,
|
||||
InParameters, deviceContext);
|
||||
|
||||
evalCounter = 0;
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
#include "FeatureProvider_Dx11.h"
|
||||
|
||||
#include "Util.h"
|
||||
#include "Config.h"
|
||||
|
||||
#include "NVNGX_Parameter.h"
|
||||
|
||||
#include "upscalers/dlss/DLSSFeature_Dx11.h"
|
||||
#include "upscalers/dlssd/DLSSDFeature_Dx11.h"
|
||||
#include "upscalers/fsr2/FSR2Feature_Dx11.h"
|
||||
#include "upscalers/fsr2/FSR2Feature_Dx11On12.h"
|
||||
#include "upscalers/fsr2_212/FSR2Feature_Dx11On12_212.h"
|
||||
#include "upscalers/fsr31/FSR31Feature_Dx11.h"
|
||||
#include "upscalers/fsr31/FSR31Feature_Dx11On12.h"
|
||||
#include "upscalers/xess/XeSSFeature_Dx11.h"
|
||||
#include "upscalers/xess/XeSSFeature_Dx11on12.h"
|
||||
|
||||
bool FeatureProvider_Dx11::GetFeature(std::string upscalerName, UINT handleId, NVSDK_NGX_Parameter* parameters,
|
||||
std::unique_ptr<IFeature_Dx11>* feature)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (upscalerName == "xess")
|
||||
{
|
||||
*feature = std::make_unique<XeSSFeature_Dx11>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "xess_12")
|
||||
{
|
||||
*feature = std::make_unique<XeSSFeatureDx11on12>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "fsr21_12")
|
||||
{
|
||||
*feature = std::make_unique<FSR2FeatureDx11on12_212>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "fsr22")
|
||||
{
|
||||
*feature = std::make_unique<FSR2FeatureDx11>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "fsr22_12")
|
||||
{
|
||||
*feature = std::make_unique<FSR2FeatureDx11on12>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "fsr31")
|
||||
{
|
||||
*feature = std::make_unique<FSR31FeatureDx11>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "fsr31_12")
|
||||
{
|
||||
*feature = std::make_unique<FSR31FeatureDx11on12>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
|
||||
if (Config::Instance()->DLSSEnabled.value_or_default())
|
||||
{
|
||||
if (upscalerName == "dlss")
|
||||
{
|
||||
*feature = std::make_unique<DLSSFeatureDx11>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
else if (upscalerName == "dlssd")
|
||||
{
|
||||
*feature = std::make_unique<DLSSDFeatureDx11>(handleId, parameters);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} while (false);
|
||||
|
||||
if (!(*feature)->ModuleLoaded())
|
||||
{
|
||||
(*feature).reset();
|
||||
*feature = std::make_unique<FSR2FeatureDx11>(handleId, parameters);
|
||||
upscalerName = "fsr22";
|
||||
}
|
||||
|
||||
auto result = (*feature)->ModuleLoaded();
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (upscalerName == "dlssd")
|
||||
upscalerName = "dlss";
|
||||
|
||||
Config::Instance()->Dx11Upscaler = upscalerName;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool FeatureProvider_Dx11::ChangeFeature(std::string upscalerName, ID3D11Device* device,
|
||||
ID3D11DeviceContext* devContext, UINT handleId,
|
||||
NVSDK_NGX_Parameter* parameters, ContextData<IFeature_Dx11>* contextData)
|
||||
{
|
||||
if (State::Instance().newBackend == "" ||
|
||||
(!Config::Instance()->DLSSEnabled.value_or_default() && State::Instance().newBackend == "dlss"))
|
||||
State::Instance().newBackend = Config::Instance()->Dx11Upscaler.value_or_default();
|
||||
|
||||
contextData->changeBackendCounter++;
|
||||
|
||||
// first release everything
|
||||
if (contextData->changeBackendCounter == 1)
|
||||
{
|
||||
if (contextData->feature != nullptr)
|
||||
{
|
||||
LOG_INFO("changing backend to {0}", State::Instance().newBackend);
|
||||
|
||||
auto dc = contextData->feature.get();
|
||||
|
||||
if (State::Instance().newBackend != "dlssd" && State::Instance().newBackend != "dlss")
|
||||
contextData->createParams = GetNGXParameters("OptiDx11");
|
||||
else
|
||||
contextData->createParams = parameters;
|
||||
|
||||
contextData->createParams->Set(NVSDK_NGX_Parameter_DLSS_Feature_Create_Flags, dc->GetFeatureFlags());
|
||||
contextData->createParams->Set(NVSDK_NGX_Parameter_Width, dc->RenderWidth());
|
||||
contextData->createParams->Set(NVSDK_NGX_Parameter_Height, dc->RenderHeight());
|
||||
contextData->createParams->Set(NVSDK_NGX_Parameter_OutWidth, dc->DisplayWidth());
|
||||
contextData->createParams->Set(NVSDK_NGX_Parameter_OutHeight, dc->DisplayHeight());
|
||||
contextData->createParams->Set(NVSDK_NGX_Parameter_PerfQualityValue, dc->PerfQualityValue());
|
||||
|
||||
LOG_TRACE("sleeping before reset of current feature for 1000ms");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
|
||||
contextData->feature.reset();
|
||||
contextData->feature = nullptr;
|
||||
|
||||
State::Instance().currentFeature = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("can't find handle {0} in Dx11Contexts!", handleId);
|
||||
|
||||
State::Instance().newBackend = "";
|
||||
State::Instance().changeBackend[handleId] = false;
|
||||
|
||||
if (contextData->createParams != nullptr)
|
||||
{
|
||||
free(contextData->createParams);
|
||||
contextData->createParams = nullptr;
|
||||
}
|
||||
|
||||
contextData->changeBackendCounter = 0;
|
||||
}
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
if (contextData->changeBackendCounter == 2)
|
||||
{
|
||||
LOG_INFO("Creating new {} upscaler", State::Instance().newBackend);
|
||||
|
||||
contextData->feature.reset();
|
||||
|
||||
if (!GetFeature(State::Instance().newBackend, handleId, parameters, &contextData->feature))
|
||||
{
|
||||
LOG_ERROR("Upscaler can't created");
|
||||
return NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
|
||||
return NVSDK_NGX_Result_Success;
|
||||
}
|
||||
|
||||
if (contextData->changeBackendCounter == 3)
|
||||
{
|
||||
// then init and continue
|
||||
auto initResult = contextData->feature->Init(device, devContext, contextData->createParams);
|
||||
|
||||
if (Config::Instance()->Dx11DelayedInit.value_or_default())
|
||||
{
|
||||
LOG_TRACE("sleeping after new Init of new feature for 1000ms");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
contextData->changeBackendCounter = 0;
|
||||
|
||||
if (!initResult || !contextData->feature->ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("init failed with {0} feature", State::Instance().newBackend);
|
||||
|
||||
if (State::Instance().newBackend != "dlssd")
|
||||
{
|
||||
State::Instance().newBackend = "fsr22";
|
||||
State::Instance().changeBackend[handleId] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
State::Instance().newBackend = "";
|
||||
State::Instance().changeBackend[handleId] = false;
|
||||
return NVSDK_NGX_Result_Fail;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("init successful for {0}, upscaler changed", State::Instance().newBackend);
|
||||
|
||||
State::Instance().newBackend = "";
|
||||
State::Instance().changeBackend[handleId] = false;
|
||||
}
|
||||
|
||||
// if opti nvparam release it
|
||||
int optiParam = 0;
|
||||
if (contextData->createParams->Get("OptiScaler", &optiParam) == NVSDK_NGX_Result_Success && optiParam == 1)
|
||||
{
|
||||
free(contextData->createParams);
|
||||
contextData->createParams = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// if initial feature can't be inited
|
||||
State::Instance().currentFeature = contextData->feature.get();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <pch.h>
|
||||
|
||||
#include "IFeature_Dx11.h"
|
||||
|
||||
#include <inputs/NVNGX_DLSS.h>
|
||||
|
||||
class FeatureProvider_Dx11
|
||||
{
|
||||
public:
|
||||
static bool GetFeature(std::string upscalerName, UINT handleId, NVSDK_NGX_Parameter* parameters,
|
||||
std::unique_ptr<IFeature_Dx11>* feature);
|
||||
|
||||
static bool ChangeFeature(std::string upscalerName, ID3D11Device* device, ID3D11DeviceContext* cmdList,
|
||||
UINT handleId, NVSDK_NGX_Parameter* parameters, ContextData<IFeature_Dx11>* contextData);
|
||||
};
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "upscalers/fsr2_212/FSR2Feature_Dx12_212.h"
|
||||
#include "upscalers/fsr31/FSR31Feature_Dx12.h"
|
||||
#include "upscalers/xess/XeSSFeature_Dx12.h"
|
||||
#include "FeatureProvider_Dx11.h"
|
||||
|
||||
bool FeatureProvider_Dx12::GetFeature(std::string upscalerName, UINT handleId, NVSDK_NGX_Parameter* parameters,
|
||||
std::unique_ptr<IFeature_Dx12>* feature)
|
||||
@@ -161,8 +162,7 @@ bool FeatureProvider_Dx12::ChangeFeature(std::string upscalerName, ID3D12Device*
|
||||
|
||||
contextData->feature.reset();
|
||||
|
||||
if (!FeatureProvider_Dx12::GetFeature(State::Instance().newBackend, handleId, parameters,
|
||||
&contextData->feature))
|
||||
if (!GetFeature(State::Instance().newBackend, handleId, parameters, &contextData->feature))
|
||||
{
|
||||
LOG_ERROR("Upscaler can't created");
|
||||
return NVSDK_NGX_Result_Fail;
|
||||
|
||||
Reference in New Issue
Block a user