mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-08-25 07:36:45 +00:00
Factor out DX12 shaders into common code
It now uses a pipeline system where shaders are added to the pipeline and are applied in order
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
#include <pch.h>
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "IFeature_Dx12.h"
|
||||
#include "State.h"
|
||||
|
||||
@@ -17,6 +21,214 @@ void IFeature_Dx12::ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID
|
||||
InCommandList->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
|
||||
bool IFeature_Dx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
Device = InDevice;
|
||||
|
||||
auto result = InitInternal(InCommandList, InParameters);
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("Output Scaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
Bias = std::make_unique<Bias_Dx12>("Bias", InDevice); // TODO: not needed on DLSS/DLSSD
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IFeature_Dx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (!IsInited())
|
||||
{
|
||||
LOG_ERROR("Not inited!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Config::Instance()->OverrideSharpness.value_or_default())
|
||||
_sharpness = Config::Instance()->Sharpness.value_or_default();
|
||||
else
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
if (_sharpness > 1.0f)
|
||||
_sharpness = 1.0f;
|
||||
|
||||
// Those upcalers don't have their own sharpness so always need to use RCAS when sharpness is set
|
||||
auto upscaler = GetUpscalerType();
|
||||
bool useRcas = upscaler == Upscaler::XeSS ||
|
||||
(upscaler == Upscaler::DLSS && Version() >= feature_version(2, 5, 1)) || upscaler == Upscaler::DLSSD;
|
||||
|
||||
if (!useRcas)
|
||||
useRcas = Config::Instance()->RcasEnabled.value_or_default();
|
||||
|
||||
if (_sharpness == 0.0f)
|
||||
useRcas = false;
|
||||
|
||||
// Need RCAS for MAS
|
||||
if (!useRcas && (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f))
|
||||
{
|
||||
useRcas = true;
|
||||
}
|
||||
|
||||
if (!RCAS->IsInit())
|
||||
useRcas = false;
|
||||
|
||||
bool useOutputScaling =
|
||||
Config::Instance()->OutputScalingEnabled.value_or_default() && (LowResMV() || RenderWidth() == DisplayWidth());
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
useOutputScaling = false;
|
||||
|
||||
ID3D12Resource* paramOutput = nullptr;
|
||||
ID3D12Resource* paramMotion = nullptr;
|
||||
ID3D12Resource* paramDepth = nullptr;
|
||||
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Output, ¶mOutput);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MotionVectors, ¶mMotion);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Depth, ¶mDepth);
|
||||
|
||||
// Order is important as that's the order of shader dispatch
|
||||
std::vector<ShaderPass> pipeline;
|
||||
|
||||
if (useOutputScaling)
|
||||
{
|
||||
pipeline.push_back(
|
||||
{ // Setup
|
||||
[&](ID3D12Resource* nextOutput) -> ID3D12Resource*
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, nextOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
return OutputScaler->Buffer();
|
||||
}
|
||||
return nullptr;
|
||||
},
|
||||
|
||||
// Dispatch
|
||||
[&](ID3D12Resource* input, ID3D12Resource* output) -> bool
|
||||
{
|
||||
LOG_DEBUG("Scaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, input, output))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
State::Instance().changeBackend[Handle()->Id] = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} });
|
||||
}
|
||||
|
||||
float localSharpness = _sharpness;
|
||||
if (useRcas)
|
||||
{
|
||||
pipeline.push_back(
|
||||
{ // Setup
|
||||
[&](ID3D12Resource* nextOutput) -> ID3D12Resource*
|
||||
{
|
||||
// Disable any built-in sharpness shaders
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Sharpness, 0.0f);
|
||||
_sharpness = 0.0f;
|
||||
|
||||
if (RCAS->CreateBufferResource(Device, nextOutput, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
return RCAS->Buffer();
|
||||
}
|
||||
return nullptr;
|
||||
},
|
||||
|
||||
// Dispatch
|
||||
[&](ID3D12Resource* input, ID3D12Resource* output) -> bool
|
||||
{
|
||||
if (!RCAS->CanRender() || !paramMotion || !paramOutput)
|
||||
return true;
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
rcasConstants.Sharpness = localSharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (!RCAS->Dispatch(Device, InCommandList, input, paramMotion, rcasConstants, output))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} });
|
||||
}
|
||||
|
||||
// Iterate BACKWARDS to establish where each shader needs to pull its input from
|
||||
ID3D12Resource* currentTarget = paramOutput;
|
||||
for (auto it = pipeline.rbegin(); it != pipeline.rend(); ++it)
|
||||
{
|
||||
ID3D12Resource* requiredInput = it->Setup(currentTarget);
|
||||
if (requiredInput)
|
||||
{
|
||||
it->outputBuffer = currentTarget;
|
||||
it->inputBuffer = requiredInput;
|
||||
currentTarget = requiredInput; // Shift the target back for the next previous stage
|
||||
}
|
||||
}
|
||||
|
||||
// Upscaler will write to the first active shader, or just output
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Output, currentTarget);
|
||||
|
||||
auto evalResult = EvaluateInternal(InCommandList, InParameters);
|
||||
|
||||
if (!evalResult)
|
||||
return false;
|
||||
|
||||
// Iterate FORWARDS to execute the shaders in the defined order
|
||||
for (auto& pass : pipeline)
|
||||
{
|
||||
if (pass.inputBuffer && pass.outputBuffer)
|
||||
{
|
||||
if (!pass.Dispatch(pass.inputBuffer, pass.outputBuffer))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(GetForegroundWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Output, paramOutput);
|
||||
|
||||
return evalResult;
|
||||
}
|
||||
|
||||
IFeature_Dx12::IFeature_Dx12(unsigned int InHandleId, NVSDK_NGX_Parameter* InParameters) {}
|
||||
|
||||
IFeature_Dx12::~IFeature_Dx12()
|
||||
|
||||
@@ -11,6 +11,20 @@
|
||||
|
||||
class IFeature_Dx12 : public virtual IFeature
|
||||
{
|
||||
private:
|
||||
struct ShaderPass
|
||||
{
|
||||
// Requests the target buffer it needs to write to. Returns the buffer the PREVIOUS stage must write to
|
||||
std::function<ID3D12Resource*(ID3D12Resource* nextOutput)> Setup;
|
||||
|
||||
// Runs the shader
|
||||
std::function<bool(ID3D12Resource* input, ID3D12Resource* output)> Dispatch;
|
||||
|
||||
// Internal state tracked by the pipeline setup loop
|
||||
ID3D12Resource* inputBuffer = nullptr;
|
||||
ID3D12Resource* outputBuffer = nullptr;
|
||||
};
|
||||
|
||||
protected:
|
||||
ID3D12Device* Device = nullptr;
|
||||
static inline std::unique_ptr<Menu_Dx12> Imgui = nullptr;
|
||||
@@ -21,10 +35,13 @@ class IFeature_Dx12 : public virtual IFeature
|
||||
void ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID3D12Resource* InResource,
|
||||
D3D12_RESOURCE_STATES InBeforeState, D3D12_RESOURCE_STATES InAfterState) const;
|
||||
|
||||
virtual bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) = 0;
|
||||
virtual bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) = 0;
|
||||
virtual Upscaler GetUpscalerType() = 0; // TODO: should be moved to IFeature in the future
|
||||
|
||||
public:
|
||||
virtual bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) = 0;
|
||||
virtual bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) = 0;
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters);
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters);
|
||||
|
||||
IFeature_Dx12(unsigned int InHandleId, NVSDK_NGX_Parameter* InParameters);
|
||||
|
||||
|
||||
@@ -1,96 +1,81 @@
|
||||
#include "pch.h"
|
||||
#include <pch.h>
|
||||
#include "DLSSFeature_Dx12.h"
|
||||
#include <dxgi1_4.h>
|
||||
#include <Config.h>
|
||||
|
||||
bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
bool DLSSFeatureDx12::InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
return InitDLSS(InCommandList, InParameters);
|
||||
}
|
||||
|
||||
bool DLSSFeatureDx12::InitDLSS(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (NVNGXProxy::NVNGXModule() == nullptr)
|
||||
{
|
||||
LOG_ERROR("nvngx.dll not loaded!");
|
||||
SetInit(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
NVSDK_NGX_Result nvResult;
|
||||
bool initResult = false;
|
||||
|
||||
Device = InDevice;
|
||||
|
||||
do
|
||||
if (!_dlssInited)
|
||||
{
|
||||
_dlssInited = NVNGXProxy::InitDx12(Device);
|
||||
|
||||
if (!_dlssInited)
|
||||
return false;
|
||||
|
||||
_moduleLoaded =
|
||||
(NVNGXProxy::D3D12_Init_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;
|
||||
|
||||
// delay between init and create feature
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
LOG_INFO("Creating DLSS feature");
|
||||
|
||||
if (NVNGXProxy::D3D12_CreateFeature() != nullptr)
|
||||
{
|
||||
ProcessInitParams(InParameters);
|
||||
|
||||
_p_dlssHandle = &_dlssHandle;
|
||||
|
||||
NVSDK_NGX_Result nvResult;
|
||||
{
|
||||
_dlssInited = NVNGXProxy::InitDx12(InDevice);
|
||||
ScopedSkipHeapCapture skipHeapCapture {};
|
||||
|
||||
if (!_dlssInited)
|
||||
return false;
|
||||
|
||||
_moduleLoaded =
|
||||
(NVNGXProxy::D3D12_Init_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;
|
||||
|
||||
// delay between init and create feature
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
nvResult = NVNGXProxy::D3D12_CreateFeature()(InCommandList, NVSDK_NGX_Feature_SuperSampling, InParameters,
|
||||
&_p_dlssHandle);
|
||||
}
|
||||
|
||||
LOG_INFO("Creating DLSS feature");
|
||||
|
||||
if (NVNGXProxy::D3D12_CreateFeature() != nullptr)
|
||||
if (nvResult != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
ProcessInitParams(InParameters);
|
||||
|
||||
_p_dlssHandle = &_dlssHandle;
|
||||
|
||||
{
|
||||
ScopedSkipHeapCapture skipHeapCapture {};
|
||||
|
||||
nvResult = NVNGXProxy::D3D12_CreateFeature()(InCommandList, NVSDK_NGX_Feature_SuperSampling,
|
||||
InParameters, &_p_dlssHandle);
|
||||
}
|
||||
|
||||
if (nvResult != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
LOG_ERROR("_CreateFeature result: {0:X}", (unsigned int) nvResult);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("_CreateFeature result: NVSDK_NGX_Result_Success");
|
||||
}
|
||||
LOG_ERROR("_CreateFeature result: {0:X}", (unsigned int) nvResult);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("_CreateFeature is nullptr");
|
||||
break;
|
||||
LOG_INFO("_CreateFeature result: NVSDK_NGX_Result_Success");
|
||||
}
|
||||
|
||||
ReadVersion();
|
||||
|
||||
initResult = true;
|
||||
|
||||
} while (false);
|
||||
|
||||
if (initResult)
|
||||
}
|
||||
else
|
||||
{
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("OutputScaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
LOG_ERROR("_CreateFeature is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
SetInit(initResult);
|
||||
ReadVersion();
|
||||
|
||||
return initResult;
|
||||
SetInit(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
bool DLSSFeatureDx12::EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (!_moduleLoaded)
|
||||
{
|
||||
@@ -98,80 +83,12 @@ bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsInited())
|
||||
{
|
||||
LOG_ERROR("Not inited!");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool rcasEnabled = Version() >= feature_version { 2, 5, 1 };
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or(rcasEnabled) &&
|
||||
(RCAS == nullptr || RCAS.get() == nullptr || !RCAS->IsInit()))
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
|
||||
NVSDK_NGX_Result nvResult;
|
||||
|
||||
if (NVNGXProxy::D3D12_EvaluateFeature() != nullptr)
|
||||
{
|
||||
ProcessEvaluateParams(InParameters);
|
||||
|
||||
ID3D12Resource* paramOutput = nullptr;
|
||||
ID3D12Resource* paramMotion = nullptr;
|
||||
ID3D12Resource* paramDepth = nullptr;
|
||||
ID3D12Resource* setBuffer = nullptr;
|
||||
|
||||
bool useSS = Config::Instance()->OutputScalingEnabled.value_or_default() &&
|
||||
(LowResMV() || RenderWidth() == DisplayWidth());
|
||||
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Output, ¶mOutput);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MotionVectors, ¶mMotion);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Depth, ¶mDepth);
|
||||
|
||||
if (paramDepth != nullptr)
|
||||
LOG_DEBUG("Depth exist, {:X}", (size_t) paramDepth);
|
||||
|
||||
if (paramMotion != nullptr)
|
||||
LOG_DEBUG("Velocity exist, {:X}", (size_t) paramMotion);
|
||||
|
||||
if (paramOutput != nullptr)
|
||||
LOG_DEBUG("Output exist, {:X}", (size_t) paramOutput);
|
||||
|
||||
// output scaling
|
||||
if (useSS)
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, paramOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
setBuffer = OutputScaler->Buffer();
|
||||
}
|
||||
else
|
||||
setBuffer = paramOutput;
|
||||
}
|
||||
else
|
||||
setBuffer = paramOutput;
|
||||
|
||||
// RCAS sharpness & preperation
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or(rcasEnabled) &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->IsInit() && RCAS->CreateBufferResource(Device, setBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
// Disable DLSS sharpness
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Sharpness, 0.0f);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
setBuffer = RCAS->Buffer();
|
||||
}
|
||||
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Output, setBuffer);
|
||||
|
||||
nvResult = NVNGXProxy::D3D12_EvaluateFeature()(InCommandList, _p_dlssHandle, InParameters, NULL);
|
||||
|
||||
if (nvResult != NVSDK_NGX_Result_Success)
|
||||
@@ -179,84 +96,6 @@ bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
LOG_ERROR("_EvaluateFeature result: {0:X}", (unsigned int) nvResult);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply CAS
|
||||
if (Config::Instance()->RcasEnabled.value_or(rcasEnabled) &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->CanRender())
|
||||
{
|
||||
if (setBuffer != RCAS->Buffer())
|
||||
ResourceBarrier(InCommandList, setBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
|
||||
rcasConstants.Sharpness = _sharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, setBuffer, paramMotion, rcasConstants,
|
||||
OutputScaler->Buffer()))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, setBuffer, paramMotion, rcasConstants, paramOutput))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Downsampling
|
||||
if (useSS)
|
||||
{
|
||||
LOG_DEBUG("downscaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, OutputScaler->Buffer(), paramOutput))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
State::Instance().changeBackend[Handle()->Id] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30 && paramOutput != nullptr)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
// set original output texture back
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Output, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,10 +8,12 @@ class DLSSFeatureDx12 : public DLSSFeature, public IFeature_Dx12
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
bool InitDLSS(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters);
|
||||
|
||||
public:
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
Upscaler GetUpscalerType() final { return Upscaler::DLSS; }
|
||||
|
||||
static void Shutdown(ID3D12Device* InDevice);
|
||||
|
||||
|
||||
@@ -3,94 +3,79 @@
|
||||
#include <dxgi1_4.h>
|
||||
#include <Config.h>
|
||||
|
||||
bool DLSSDFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
bool DLSSDFeatureDx12::InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
return InitDLSSD(InCommandList, InParameters);
|
||||
}
|
||||
|
||||
bool DLSSDFeatureDx12::InitDLSSD(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (NVNGXProxy::NVNGXModule() == nullptr)
|
||||
{
|
||||
LOG_ERROR("nvngx.dll not loaded!");
|
||||
SetInit(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
NVSDK_NGX_Result nvResult;
|
||||
bool initResult = false;
|
||||
|
||||
Device = InDevice;
|
||||
|
||||
do
|
||||
if (!_dlssdInited)
|
||||
{
|
||||
_dlssdInited = NVNGXProxy::InitDx12(Device);
|
||||
|
||||
if (!_dlssdInited)
|
||||
return false;
|
||||
|
||||
_moduleLoaded =
|
||||
(NVNGXProxy::D3D12_Init_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;
|
||||
|
||||
// delay between init and create feature
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
LOG_INFO("Creating DLSSD feature");
|
||||
|
||||
if (NVNGXProxy::D3D12_CreateFeature() != nullptr)
|
||||
{
|
||||
ProcessInitParams(InParameters);
|
||||
|
||||
_p_dlssdHandle = &_dlssdHandle;
|
||||
|
||||
NVSDK_NGX_Result nvResult;
|
||||
{
|
||||
_dlssdInited = NVNGXProxy::InitDx12(InDevice);
|
||||
ScopedSkipHeapCapture skipHeapCapture {};
|
||||
|
||||
if (!_dlssdInited)
|
||||
return false;
|
||||
|
||||
_moduleLoaded =
|
||||
(NVNGXProxy::D3D12_Init_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;
|
||||
|
||||
// delay between init and create feature
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
nvResult = NVNGXProxy::D3D12_CreateFeature()(InCommandList, NVSDK_NGX_Feature_RayReconstruction,
|
||||
InParameters, &_p_dlssdHandle);
|
||||
}
|
||||
|
||||
LOG_INFO("Creating DLSSD feature");
|
||||
|
||||
if (NVNGXProxy::D3D12_CreateFeature() != nullptr)
|
||||
if (nvResult != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
ProcessInitParams(InParameters);
|
||||
|
||||
_p_dlssdHandle = &_dlssdHandle;
|
||||
|
||||
{
|
||||
ScopedSkipHeapCapture skipHeapCapture {};
|
||||
|
||||
nvResult = NVNGXProxy::D3D12_CreateFeature()(InCommandList, NVSDK_NGX_Feature_RayReconstruction,
|
||||
InParameters, &_p_dlssdHandle);
|
||||
}
|
||||
|
||||
if (nvResult != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
LOG_ERROR("_CreateFeature result: {0:X}", (unsigned int) nvResult);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO("_CreateFeature result: NVSDK_NGX_Result_Success, HandleId: {0}", _p_dlssdHandle->Id);
|
||||
}
|
||||
LOG_ERROR("_CreateFeature result: {0:X}", (unsigned int) nvResult);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("_CreateFeature is nullptr");
|
||||
break;
|
||||
LOG_INFO("_CreateFeature result: NVSDK_NGX_Result_Success, HandleId: {0}", _p_dlssdHandle->Id);
|
||||
}
|
||||
|
||||
ReadVersion();
|
||||
|
||||
initResult = true;
|
||||
|
||||
} while (false);
|
||||
|
||||
if (initResult)
|
||||
}
|
||||
else
|
||||
{
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("OutputScaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
LOG_ERROR("_CreateFeature is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
SetInit(initResult);
|
||||
ReadVersion();
|
||||
|
||||
return initResult;
|
||||
SetInit(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DLSSDFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
bool DLSSDFeatureDx12::EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
if (!_moduleLoaded)
|
||||
{
|
||||
@@ -98,82 +83,12 @@ bool DLSSDFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsInited())
|
||||
{
|
||||
LOG_ERROR("Not inited!");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool rcasEnabled = true;
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or(rcasEnabled) &&
|
||||
(RCAS == nullptr || RCAS.get() == nullptr || !RCAS->IsInit()))
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
|
||||
NVSDK_NGX_Result nvResult;
|
||||
|
||||
if (NVNGXProxy::D3D12_EvaluateFeature() != nullptr)
|
||||
{
|
||||
ProcessEvaluateParams(InParameters);
|
||||
|
||||
ID3D12Resource* paramOutput = nullptr;
|
||||
ID3D12Resource* paramDepth = nullptr;
|
||||
ID3D12Resource* paramMotion = nullptr;
|
||||
ID3D12Resource* setBuffer = nullptr;
|
||||
|
||||
bool useSS = Config::Instance()->OutputScalingEnabled.value_or_default() &&
|
||||
(LowResMV() || RenderWidth() == DisplayWidth());
|
||||
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Output, ¶mOutput);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MotionVectors, ¶mMotion);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Depth, ¶mDepth);
|
||||
|
||||
if (paramDepth != nullptr)
|
||||
LOG_DEBUG("Depth exist, {:X}", (size_t) paramDepth);
|
||||
|
||||
if (paramMotion != nullptr)
|
||||
LOG_DEBUG("Velocity exist, {:X}", (size_t) paramMotion);
|
||||
|
||||
if (paramOutput != nullptr)
|
||||
LOG_DEBUG("Output exist, {:X}", (size_t) paramOutput);
|
||||
|
||||
// supersampling
|
||||
if (useSS)
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, paramOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
setBuffer = OutputScaler->Buffer();
|
||||
}
|
||||
else
|
||||
setBuffer = paramOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
setBuffer = paramOutput;
|
||||
}
|
||||
|
||||
// RCAS sharpness & preperation
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or(rcasEnabled) &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->IsInit() && RCAS->CreateBufferResource(Device, setBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
// Disable DLSS sharpness
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Sharpness, 0.0f);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
setBuffer = RCAS->Buffer();
|
||||
}
|
||||
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Output, setBuffer);
|
||||
|
||||
nvResult = NVNGXProxy::D3D12_EvaluateFeature()(InCommandList, _p_dlssdHandle, InParameters, NULL);
|
||||
|
||||
if (nvResult != NVSDK_NGX_Result_Success)
|
||||
@@ -181,84 +96,6 @@ bool DLSSDFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_
|
||||
LOG_ERROR("_EvaluateFeature result: {0:X}", (unsigned int) nvResult);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply CAS
|
||||
if (Config::Instance()->RcasEnabled.value_or(rcasEnabled) &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->CanRender())
|
||||
{
|
||||
if (setBuffer != RCAS->Buffer())
|
||||
ResourceBarrier(InCommandList, setBuffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
|
||||
rcasConstants.Sharpness = _sharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, setBuffer, paramMotion, rcasConstants,
|
||||
OutputScaler->Buffer()))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, setBuffer, paramMotion, rcasConstants, paramOutput))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Downsampling
|
||||
if (useSS)
|
||||
{
|
||||
LOG_DEBUG("downscaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, OutputScaler->Buffer(), paramOutput))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
State::Instance().changeBackend[Handle()->Id] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30 && paramOutput)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
// set original output texture back
|
||||
InParameters->Set(NVSDK_NGX_Parameter_Output, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,10 +8,12 @@ class DLSSDFeatureDx12 : public DLSSDFeature, public IFeature_Dx12
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
bool InitDLSSD(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters);
|
||||
|
||||
public:
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
Upscaler GetUpscalerType() final { return Upscaler::DLSSD; }
|
||||
|
||||
feature_version Version() override { return DLSSDFeature::Version(); }
|
||||
std::string Name() const override { return DLSSDFeature::Name(); }
|
||||
|
||||
@@ -5,71 +5,30 @@
|
||||
|
||||
using namespace OptiMath;
|
||||
|
||||
bool FSR2FeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
bool FSR2FeatureDx12::InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
Device = InDevice;
|
||||
|
||||
if (InitFSR2(InParameters))
|
||||
{
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("Output Scaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
Bias = std::make_unique<Bias_Dx12>("Bias", InDevice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return InitFSR2(InParameters);
|
||||
}
|
||||
|
||||
bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
bool FSR2FeatureDx12::EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (!IsInited())
|
||||
return false;
|
||||
|
||||
auto& state = State::Instance();
|
||||
auto& cfg = *Config::Instance();
|
||||
const auto& ngxParams = *InParameters;
|
||||
|
||||
if (!RCAS->IsInit())
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
|
||||
FfxFsr2DispatchDescription params {};
|
||||
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Jitter_Offset_X, ¶ms.jitterOffset.x);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Jitter_Offset_Y, ¶ms.jitterOffset.y);
|
||||
|
||||
if (Config::Instance()->OverrideSharpness.value_or_default())
|
||||
_sharpness = Config::Instance()->Sharpness.value_or_default();
|
||||
else
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or_default())
|
||||
{
|
||||
params.enableSharpening = false;
|
||||
params.sharpness = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_sharpness > 1.0f)
|
||||
_sharpness = 1.0f;
|
||||
|
||||
params.enableSharpening = _sharpness > 0.0f;
|
||||
params.sharpness = _sharpness;
|
||||
}
|
||||
params.enableSharpening = _sharpness > 0.0f;
|
||||
params.sharpness = _sharpness;
|
||||
|
||||
unsigned int reset;
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Reset, &reset);
|
||||
@@ -158,34 +117,8 @@ bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
(D3D12_RESOURCE_STATES) Config::Instance()->OutputResourceBarrier.value(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, paramOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.output = ffxGetResourceDX12(&_context, OutputScaler->Buffer(), (wchar_t*) L"FSR2_Output",
|
||||
FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
params.output = ffxGetResourceDX12(&_context, paramOutput, (wchar_t*) L"FSR2_Output",
|
||||
FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
params.output = ffxGetResourceDX12(&_context, paramOutput, (wchar_t*) L"FSR2_Output",
|
||||
FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or_default() &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS != nullptr && RCAS.get() != nullptr && RCAS->IsInit() &&
|
||||
RCAS->CreateBufferResource(Device, (ID3D12Resource*) params.output.resource,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.output = ffxGetResourceDX12(&_context, RCAS->Buffer(), (wchar_t*) L"FSR2_Output",
|
||||
FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
params.output =
|
||||
ffxGetResourceDX12(&_context, paramOutput, (wchar_t*) L"FSR2_Output", FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -347,7 +280,7 @@ bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
}
|
||||
|
||||
if (!cfg.FsrUseFsrInputValues.value_or_default() ||
|
||||
ngxParams.Get(OptiKeys::FSR_FarPlane, ¶ms.cameraFar) != NVSDK_NGX_Result_Success)
|
||||
InParameters->Get(OptiKeys::FSR_FarPlane, ¶ms.cameraFar) != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
if (DepthInverted())
|
||||
params.cameraNear = cfg.FsrCameraFar.value_or_default();
|
||||
@@ -356,7 +289,7 @@ bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
}
|
||||
|
||||
if (!cfg.FsrUseFsrInputValues.value_or_default() ||
|
||||
ngxParams.Get(OptiKeys::FSR_CameraFovVertical, ¶ms.cameraFovAngleVertical) != NVSDK_NGX_Result_Success)
|
||||
InParameters->Get(OptiKeys::FSR_CameraFovVertical, ¶ms.cameraFovAngleVertical) != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
if (cfg.FsrVerticalFov.has_value())
|
||||
params.cameraFovAngleVertical = GetRadiansFromDeg(cfg.FsrVerticalFov.value());
|
||||
@@ -391,81 +324,6 @@ bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
return false;
|
||||
}
|
||||
|
||||
// apply rcas
|
||||
if (Config::Instance()->RcasEnabled.value_or_default() &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS != nullptr && RCAS.get() != nullptr && RCAS->CanRender())
|
||||
{
|
||||
if (params.output.resource != RCAS->Buffer())
|
||||
ResourceBarrier(InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
|
||||
rcasConstants.Sharpness = _sharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
(ID3D12Resource*) params.motionVectors.resource, rcasConstants, OutputScaler->Buffer()))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
(ID3D12Resource*) params.motionVectors.resource, rcasConstants, paramOutput))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
LOG_DEBUG("scaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, OutputScaler->Buffer(), paramOutput))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
State::Instance().changeBackend[Handle()->Id] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(GetForegroundWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
// restore resource states
|
||||
if (paramColor && Config::Instance()->ColorResourceBarrier.has_value())
|
||||
ResourceBarrier(InCommandList, paramColor, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
|
||||
|
||||
@@ -18,9 +18,9 @@ class FSR2FeatureDx12 : public FSR2Feature, public IFeature_Dx12
|
||||
{
|
||||
}
|
||||
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
Upscaler GetUpscalerType() final { return Upscaler::FSR22; }
|
||||
|
||||
feature_version Version() override { return FSR2Feature::Version(); }
|
||||
std::string Name() const override { return FSR2Feature::Name(); }
|
||||
|
||||
@@ -5,71 +5,30 @@
|
||||
|
||||
using namespace OptiMath;
|
||||
|
||||
bool FSR2FeatureDx12_212::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
bool FSR2FeatureDx12_212::InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
Device = InDevice;
|
||||
|
||||
if (InitFSR2(InParameters))
|
||||
{
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("Output Scaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
Bias = std::make_unique<Bias_Dx12>("Bias", InDevice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return InitFSR2(InParameters);
|
||||
}
|
||||
|
||||
bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
bool FSR2FeatureDx12_212::EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (!IsInited())
|
||||
return false;
|
||||
|
||||
auto& state = State::Instance();
|
||||
auto& cfg = *Config::Instance();
|
||||
const auto& ngxParams = *InParameters;
|
||||
|
||||
if (!RCAS->IsInit())
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
|
||||
Fsr212::FfxFsr2DispatchDescription params {};
|
||||
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Jitter_Offset_X, ¶ms.jitterOffset.x);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Jitter_Offset_Y, ¶ms.jitterOffset.y);
|
||||
|
||||
if (Config::Instance()->OverrideSharpness.value_or_default())
|
||||
_sharpness = Config::Instance()->Sharpness.value_or_default();
|
||||
else
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or_default())
|
||||
{
|
||||
params.enableSharpening = false;
|
||||
params.sharpness = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_sharpness > 1.0f)
|
||||
_sharpness = 1.0f;
|
||||
|
||||
params.enableSharpening = _sharpness > 0.0f;
|
||||
params.sharpness = _sharpness;
|
||||
}
|
||||
params.enableSharpening = _sharpness > 0.0f;
|
||||
params.sharpness = _sharpness;
|
||||
|
||||
LOG_DEBUG("Jitter Offset: {0}x{1}", params.jitterOffset.x, params.jitterOffset.y);
|
||||
|
||||
@@ -159,35 +118,8 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVS
|
||||
(D3D12_RESOURCE_STATES) Config::Instance()->OutputResourceBarrier.value(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, paramOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.output =
|
||||
Fsr212::ffxGetResourceDX12_212(&_context, OutputScaler->Buffer(), (wchar_t*) L"FSR2_Output",
|
||||
Fsr212::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
params.output = Fsr212::ffxGetResourceDX12_212(&_context, paramOutput, (wchar_t*) L"FSR2_Output",
|
||||
Fsr212::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
params.output = Fsr212::ffxGetResourceDX12_212(&_context, paramOutput, (wchar_t*) L"FSR2_Output",
|
||||
Fsr212::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or_default() &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->IsInit() &&
|
||||
RCAS->CreateBufferResource(Device, (ID3D12Resource*) params.output.resource,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.output = Fsr212::ffxGetResourceDX12_212(&_context, RCAS->Buffer(), (wchar_t*) L"FSR2_Output",
|
||||
Fsr212::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
params.output = Fsr212::ffxGetResourceDX12_212(&_context, paramOutput, (wchar_t*) L"FSR2_Output",
|
||||
Fsr212::FFX_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -347,7 +279,7 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVS
|
||||
LOG_DEBUG("Sharpness: {0}", params.sharpness);
|
||||
|
||||
if (cfg.FsrCameraNear.has_value() || !cfg.FsrUseFsrInputValues.value_or_default() ||
|
||||
ngxParams.Get(OptiKeys::FSR_NearPlane, ¶ms.cameraNear) != NVSDK_NGX_Result_Success)
|
||||
InParameters->Get(OptiKeys::FSR_NearPlane, ¶ms.cameraNear) != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
if (DepthInverted())
|
||||
params.cameraFar = cfg.FsrCameraNear.value_or_default();
|
||||
@@ -356,7 +288,7 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVS
|
||||
}
|
||||
|
||||
if (!cfg.FsrUseFsrInputValues.value_or_default() ||
|
||||
ngxParams.Get(OptiKeys::FSR_FarPlane, ¶ms.cameraFar) != NVSDK_NGX_Result_Success)
|
||||
InParameters->Get(OptiKeys::FSR_FarPlane, ¶ms.cameraFar) != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
if (DepthInverted())
|
||||
params.cameraNear = cfg.FsrCameraFar.value_or_default();
|
||||
@@ -364,7 +296,7 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVS
|
||||
params.cameraFar = cfg.FsrCameraFar.value_or_default();
|
||||
}
|
||||
|
||||
if (ngxParams.Get(OptiKeys::FSR_CameraFovVertical, ¶ms.cameraFovAngleVertical) != NVSDK_NGX_Result_Success)
|
||||
if (InParameters->Get(OptiKeys::FSR_CameraFovVertical, ¶ms.cameraFovAngleVertical) != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
if (cfg.FsrVerticalFov.has_value())
|
||||
params.cameraFovAngleVertical = GetRadiansFromDeg(cfg.FsrVerticalFov.value());
|
||||
@@ -401,81 +333,6 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVS
|
||||
return false;
|
||||
}
|
||||
|
||||
// apply rcas
|
||||
if (Config::Instance()->RcasEnabled.value_or_default() &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->CanRender())
|
||||
{
|
||||
if (params.output.resource != RCAS->Buffer())
|
||||
ResourceBarrier(InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
|
||||
rcasConstants.Sharpness = _sharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
(ID3D12Resource*) params.motionVectors.resource, rcasConstants, OutputScaler->Buffer()))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
(ID3D12Resource*) params.motionVectors.resource, rcasConstants, paramOutput))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
LOG_DEBUG("scaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, OutputScaler->Buffer(), paramOutput))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
State::Instance().changeBackend[Handle()->Id] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(GetForegroundWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
// restore resource states
|
||||
if (paramColor && Config::Instance()->ColorResourceBarrier.has_value())
|
||||
ResourceBarrier(InCommandList, paramColor, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
|
||||
|
||||
@@ -18,9 +18,9 @@ class FSR2FeatureDx12_212 : public FSR2Feature212, public IFeature_Dx12
|
||||
{
|
||||
}
|
||||
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
Upscaler GetUpscalerType() final { return Upscaler::FSR21; }
|
||||
|
||||
feature_version Version() override { return FSR2Feature212::Version(); }
|
||||
std::string Name() const override { return FSR2Feature212::Name(); }
|
||||
|
||||
@@ -27,46 +27,21 @@ FSR31FeatureDx12::FSR31FeatureDx12(unsigned int InHandleId, NVSDK_NGX_Parameter*
|
||||
LOG_ERROR("can't load amd_fidelityfx_dx12.dll methods!");
|
||||
}
|
||||
|
||||
bool FSR31FeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
bool FSR31FeatureDx12::InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_DEBUG("FSR31FeatureDx12::Init");
|
||||
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
Device = InDevice;
|
||||
|
||||
if (InitFSR3(InParameters))
|
||||
{
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("Output Scaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
Bias = std::make_unique<Bias_Dx12>("Bias", InDevice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return InitFSR3(InParameters);
|
||||
}
|
||||
|
||||
bool FSR31FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
bool FSR31FeatureDx12::EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (!IsInited())
|
||||
return false;
|
||||
|
||||
auto& cfg = *Config::Instance();
|
||||
const auto& ngxParams = *InParameters;
|
||||
|
||||
if (!RCAS->IsInit())
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
|
||||
struct ffxDispatchDescUpscale params = { 0 };
|
||||
params.header.type = FFX_API_DISPATCH_DESC_TYPE_UPSCALE;
|
||||
@@ -87,24 +62,8 @@ bool FSR31FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Jitter_Offset_X, ¶ms.jitterOffset.x);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_Jitter_Offset_Y, ¶ms.jitterOffset.y);
|
||||
|
||||
if (Config::Instance()->OverrideSharpness.value_or_default())
|
||||
_sharpness = Config::Instance()->Sharpness.value_or_default();
|
||||
else
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or_default())
|
||||
{
|
||||
params.enableSharpening = false;
|
||||
params.sharpness = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_sharpness > 1.0f)
|
||||
_sharpness = 1.0f;
|
||||
|
||||
params.enableSharpening = _sharpness > 0.0f;
|
||||
params.sharpness = _sharpness;
|
||||
}
|
||||
params.enableSharpening = _sharpness > 0.0f;
|
||||
params.sharpness = _sharpness;
|
||||
|
||||
// Force enable RCAS when in FSR4 debug view mode
|
||||
// it crashes when sharpening is disabled
|
||||
@@ -202,30 +161,7 @@ bool FSR31FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_
|
||||
(D3D12_RESOURCE_STATES) Config::Instance()->OutputResourceBarrier.value(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, paramOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.output = ffxApiGetResourceDX12(OutputScaler->Buffer(), FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
params.output = ffxApiGetResourceDX12(paramOutput, FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
params.output = ffxApiGetResourceDX12(paramOutput, FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or_default() &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->IsInit() &&
|
||||
RCAS->CreateBufferResource(Device, (ID3D12Resource*) params.output.resource,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.output = ffxApiGetResourceDX12(RCAS->Buffer(), FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
params.output = ffxApiGetResourceDX12(paramOutput, FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -411,7 +347,7 @@ bool FSR31FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_
|
||||
}
|
||||
|
||||
if (!cfg.FsrUseFsrInputValues.value_or_default() ||
|
||||
ngxParams.Get(OptiKeys::FSR_CameraFovVertical, ¶ms.cameraFovAngleVertical) != NVSDK_NGX_Result_Success)
|
||||
InParameters->Get(OptiKeys::FSR_CameraFovVertical, ¶ms.cameraFovAngleVertical) != NVSDK_NGX_Result_Success)
|
||||
{
|
||||
if (cfg.FsrVerticalFov.has_value())
|
||||
params.cameraFovAngleVertical = GetRadiansFromDeg(cfg.FsrVerticalFov.value());
|
||||
@@ -551,81 +487,6 @@ bool FSR31FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_
|
||||
return false;
|
||||
}
|
||||
|
||||
// apply rcas
|
||||
if (Config::Instance()->RcasEnabled.value_or_default() &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or_default() &&
|
||||
Config::Instance()->MotionSharpness.value_or_default() > 0.0f)) &&
|
||||
RCAS->CanRender())
|
||||
{
|
||||
if (params.output.resource != RCAS->Buffer())
|
||||
ResourceBarrier(InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
|
||||
rcasConstants.Sharpness = _sharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
(ID3D12Resource*) params.motionVectors.resource, rcasConstants, OutputScaler->Buffer()))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, (ID3D12Resource*) params.output.resource,
|
||||
(ID3D12Resource*) params.motionVectors.resource, rcasConstants, paramOutput))
|
||||
{
|
||||
Config::Instance()->RcasEnabled.set_volatile_value(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
LOG_DEBUG("scaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, OutputScaler->Buffer(), paramOutput))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled.set_volatile_value(false);
|
||||
State::Instance().changeBackend[Handle()->Id] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(GetForegroundWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
// restore resource states
|
||||
if (paramColor && Config::Instance()->ColorResourceBarrier.has_value())
|
||||
ResourceBarrier(InCommandList, paramColor, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
|
||||
|
||||
@@ -16,9 +16,9 @@ class FSR31FeatureDx12 : public FSR31Feature, public IFeature_Dx12
|
||||
public:
|
||||
FSR31FeatureDx12(unsigned int InHandleId, NVSDK_NGX_Parameter* InParameters);
|
||||
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
Upscaler GetUpscalerType() final { return Upscaler::FSR31; }
|
||||
|
||||
feature_version Version() override { return FSR31Feature::Version(); }
|
||||
std::string Name() const override { return FSR31Feature::Name(); }
|
||||
|
||||
@@ -1,50 +1,28 @@
|
||||
#pragma once
|
||||
#include <pch.h>
|
||||
#include <Config.h>
|
||||
|
||||
#include "XeSSFeature_Dx12.h"
|
||||
|
||||
bool XeSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters)
|
||||
bool XeSSFeatureDx12::InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (IsInited())
|
||||
return true;
|
||||
|
||||
Device = InDevice;
|
||||
|
||||
if (InitXeSS(InDevice, InParameters))
|
||||
{
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && (Imgui == nullptr || Imgui.get() == nullptr))
|
||||
Imgui = std::make_unique<Menu_Dx12>(Util::GetProcessWindow(), InDevice);
|
||||
|
||||
OutputScaler = std::make_unique<OS_Dx12>("Output Scaling", InDevice, (TargetWidth() < DisplayWidth()));
|
||||
RCAS = std::make_unique<RCAS_Dx12>("RCAS", InDevice);
|
||||
Bias = std::make_unique<Bias_Dx12>("Bias", InDevice);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return InitXeSS(Device, InParameters);
|
||||
}
|
||||
|
||||
bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
bool XeSSFeatureDx12::EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
if (!IsInited() || !_xessContext || !ModuleLoaded())
|
||||
if (!_xessContext || !ModuleLoaded())
|
||||
{
|
||||
LOG_ERROR("Not inited!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!RCAS->IsInit())
|
||||
Config::Instance()->RcasEnabled = false;
|
||||
|
||||
if (!OutputScaler->IsInit())
|
||||
Config::Instance()->OutputScalingEnabled = false;
|
||||
|
||||
xess_result_t xessResult;
|
||||
|
||||
if (State::Instance().xessDebug)
|
||||
@@ -54,7 +32,8 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
xess_dump_parameters_t dumpParams {};
|
||||
dumpParams.frame_count = State::Instance().xessDebugFrames;
|
||||
dumpParams.frame_idx = dumpCount;
|
||||
dumpParams.path = wstring_to_string(Util::DllPath().wstring()).c_str();
|
||||
auto path = wstring_to_string(Util::DllPath().wstring());
|
||||
dumpParams.path = path.c_str();
|
||||
dumpParams.dump_elements_mask = XESS_DUMP_INPUT_COLOR | XESS_DUMP_INPUT_VELOCITY | XESS_DUMP_INPUT_DEPTH |
|
||||
XESS_DUMP_OUTPUT | XESS_DUMP_EXECUTION_PARAMETERS | XESS_DUMP_HISTORY;
|
||||
|
||||
@@ -80,8 +59,6 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
|
||||
GetRenderResolution(InParameters, ¶ms.inputWidth, ¶ms.inputHeight);
|
||||
|
||||
_sharpness = GetSharpness(InParameters);
|
||||
|
||||
float ssMulti = Config::Instance()->OutputScalingMultiplier.value_or(1.5f);
|
||||
|
||||
bool useSS =
|
||||
@@ -165,29 +142,7 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (OutputScaler->CreateBufferResource(Device, paramOutput, TargetWidth(), TargetHeight(),
|
||||
D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.pOutputTexture = OutputScaler->Buffer();
|
||||
}
|
||||
else
|
||||
params.pOutputTexture = paramOutput;
|
||||
}
|
||||
else
|
||||
params.pOutputTexture = paramOutput;
|
||||
|
||||
if (Config::Instance()->RcasEnabled.value_or(true) &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or(false) &&
|
||||
Config::Instance()->MotionSharpness.value_or(0.4) > 0.0f)) &&
|
||||
RCAS->IsInit() &&
|
||||
RCAS->CreateBufferResource(Device, params.pOutputTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS))
|
||||
{
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
params.pOutputTexture = RCAS->Buffer();
|
||||
}
|
||||
params.pOutputTexture = paramOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -356,81 +311,6 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply RCAS
|
||||
if (Config::Instance()->RcasEnabled.value_or(true) &&
|
||||
(_sharpness > 0.0f || (Config::Instance()->MotionSharpnessEnabled.value_or(false) &&
|
||||
Config::Instance()->MotionSharpness.value_or(0.4) > 0.0f)) &&
|
||||
RCAS->CanRender())
|
||||
{
|
||||
if (params.pOutputTexture != RCAS->Buffer())
|
||||
ResourceBarrier(InCommandList, params.pOutputTexture, D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RCAS->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
RcasConstants rcasConstants {};
|
||||
|
||||
rcasConstants.Sharpness = _sharpness;
|
||||
rcasConstants.DisplayWidth = TargetWidth();
|
||||
rcasConstants.DisplayHeight = TargetHeight();
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_X, &rcasConstants.MvScaleX);
|
||||
InParameters->Get(NVSDK_NGX_Parameter_MV_Scale_Y, &rcasConstants.MvScaleY);
|
||||
rcasConstants.DisplaySizeMV = !(GetFeatureFlags() & NVSDK_NGX_DLSS_Feature_Flags_MVLowRes);
|
||||
rcasConstants.RenderHeight = RenderHeight();
|
||||
rcasConstants.RenderWidth = RenderWidth();
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, params.pOutputTexture, params.pVelocityTexture, rcasConstants,
|
||||
OutputScaler->Buffer()))
|
||||
{
|
||||
Config::Instance()->RcasEnabled = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RCAS->Dispatch(Device, InCommandList, params.pOutputTexture, params.pVelocityTexture, rcasConstants,
|
||||
paramOutput))
|
||||
{
|
||||
Config::Instance()->RcasEnabled = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (useSS)
|
||||
{
|
||||
LOG_DEBUG("scaling output...");
|
||||
OutputScaler->SetBufferState(InCommandList, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
if (!OutputScaler->Dispatch(Device, InCommandList, OutputScaler->Buffer(), paramOutput))
|
||||
{
|
||||
Config::Instance()->OutputScalingEnabled = false;
|
||||
State::Instance().changeBackend[_handle->Id] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// imgui
|
||||
if (!Config::Instance()->OverlayMenu.value_or_default() && _frameCount > 30)
|
||||
{
|
||||
if (Imgui != nullptr && Imgui.get() != nullptr)
|
||||
{
|
||||
if (Imgui->IsHandleDifferent())
|
||||
{
|
||||
Imgui.reset();
|
||||
}
|
||||
else
|
||||
Imgui->Render(InCommandList, paramOutput);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Imgui == nullptr || Imgui.get() == nullptr)
|
||||
Imgui = std::make_unique<Menu_Dx12>(GetForegroundWindow(), Device);
|
||||
}
|
||||
}
|
||||
|
||||
// restore resource states
|
||||
if (params.pColorTexture && Config::Instance()->ColorResourceBarrier.has_value())
|
||||
ResourceBarrier(InCommandList, params.pColorTexture, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,
|
||||
|
||||
@@ -21,9 +21,9 @@ class XeSSFeatureDx12 : public XeSSFeature, public IFeature_Dx12
|
||||
_moduleLoaded = XeSSProxy::Module() != nullptr && XeSSProxy::D3D12CreateContext() != nullptr;
|
||||
}
|
||||
|
||||
bool Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* InCommandList,
|
||||
NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool InitInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
bool EvaluateInternal(ID3D12GraphicsCommandList* InCommandList, NVSDK_NGX_Parameter* InParameters) override;
|
||||
Upscaler GetUpscalerType() final { return Upscaler::XeSS; }
|
||||
|
||||
bool IsWithDx12() final { return false; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user