From 51676fbe74e59ad0fd87f1bf59c2f67de11361c3 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Thu, 11 Apr 2024 02:22:26 +0300 Subject: [PATCH] fix for arc dx11 this time automatic motion vector size configuration --- CyberXeSS/backends/fsr2/FSR2Feature_Dx11.cpp | 22 ++++- .../backends/fsr2/FSR2Feature_Dx11On12.cpp | 80 +++++++++++------ .../backends/fsr2/FSR2Feature_Dx11On12.h | 1 + CyberXeSS/backends/fsr2/FSR2Feature_Dx12.cpp | 29 ++++++- CyberXeSS/backends/fsr2/FSR2Feature_Vk.cpp | 2 - .../fsr2_212/FSR2Feature_Dx11On12_212.cpp | 80 +++++++++++------ .../fsr2_212/FSR2Feature_Dx11On12_212.h | 1 + .../fsr2_212/FSR2Feature_Dx12_212.cpp | 35 ++++++-- .../backends/fsr2_212/FSR2Feature_Vk_212.cpp | 2 - CyberXeSS/backends/xess/XeSSFeature.cpp | 2 - CyberXeSS/backends/xess/XeSSFeature_Dx11.cpp | 87 ++++++++++++------- CyberXeSS/backends/xess/XeSSFeature_Dx11.h | 1 + CyberXeSS/backends/xess/XeSSFeature_Dx12.cpp | 19 ++++ 13 files changed, 263 insertions(+), 98 deletions(-) diff --git a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11.cpp b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11.cpp index 68537371..66b9c9ed 100644 --- a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11.cpp +++ b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11.cpp @@ -188,13 +188,11 @@ bool FSR2FeatureDx11::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureDx11::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureDx11::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } @@ -277,6 +275,26 @@ bool FSR2FeatureDx11::Evaluate(ID3D11DeviceContext* InContext, const NVSDK_NGX_P { spdlog::debug("FSR2FeatureDx11::Evaluate MotionVectors exist.."); params.motionVectors = ffxGetResourceDX11(&_context, paramVelocity, (wchar_t*)L"FSR2_MotionVectors"); + + if (!Config::Instance()->DisplayResolution.has_value()) + { + D3D11_TEXTURE2D_DESC desc; + ((ID3D11Texture2D*)paramVelocity)->GetDesc(&desc); + bool lowResMV = desc.Width == params.renderSize.width; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("FSR2FeatureDx11::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("FSR2FeatureDx11::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } } else { diff --git a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp index 798bc0a9..61f5c56d 100644 --- a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp +++ b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.cpp @@ -11,30 +11,10 @@ bool FSR2FeatureDx11on12::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InCo if (IsInited()) return true; - if (!BaseInit(InDevice, InContext, InParameters)) - { - spdlog::debug("FSR2FeatureDx11on12::Init BaseInit failed!"); - return false; - } + Device = InDevice; + DeviceContext = InContext; - spdlog::debug("FSR2FeatureDx11on12::Init calling InitFSR2"); - - if (Dx12on11Device == nullptr) - { - spdlog::error("FSR2FeatureDx11on12::Init Dx12on11Device is null!"); - return false; - } - - if (!InitFSR2(InParameters)) - { - spdlog::error("FSR2FeatureDx11on12::Init InitFSR2 fail!"); - return false; - } - - if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); - - OUT_DS = std::make_unique("Output Downsample", Dx12on11Device); + _baseInit = false; return true; } @@ -43,6 +23,39 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N { spdlog::debug("FSR2FeatureDx11on12::Evaluate"); + if (!_baseInit) + { + if (!BaseInit(Device, InDeviceContext, InParameters)) + { + spdlog::debug("FSR2FeatureDx11on12::Evaluate BaseInit failed!"); + return false; + } + + _baseInit = true; + + spdlog::debug("FSR2FeatureDx11on12::Evaluate calling InitFSR2"); + + if (Dx12on11Device == nullptr) + { + spdlog::error("FSR2FeatureDx11on12::Evaluate Dx12on11Device is null!"); + return false; + } + + if (!InitFSR2(InParameters)) + { + spdlog::error("FSR2FeatureDx11on12::Evaluate InitFSR2 fail!"); + return false; + } + + if (Imgui == nullptr || Imgui.get() == nullptr) + Imgui = std::make_unique(GetForegroundWindow(), Device); + + spdlog::trace("FSR2FeatureDx11on12::Evaluate sleeping after FSRContext creation for 1500ms"); + std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + + OUT_DS = std::make_unique("Output Downsample", Dx12on11Device); + } + if (!IsInited()) return false; @@ -117,6 +130,25 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, const N _hasTM = params.reactive.resource != nullptr; _hasOutput = params.output.resource != nullptr; + if (_hasMV && !Config::Instance()->DisplayResolution.has_value()) + { + auto desc = dx11Mv.Dx12Resource->GetDesc(); + bool lowResMV = desc.Width == params.renderSize.width; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("FSR2FeatureDx11on12::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("FSR2FeatureDx11on12::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } + #pragma endregion float MVScaleX = 1.0f; @@ -347,13 +379,11 @@ bool FSR2FeatureDx11on12::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureDx11on12::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureDx11on12::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } diff --git a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.h b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.h index 48ec7994..c1123dc5 100644 --- a/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.h +++ b/CyberXeSS/backends/fsr2/FSR2Feature_Dx11On12.h @@ -8,6 +8,7 @@ class FSR2FeatureDx11on12 : public FSR2Feature, public IFeature_Dx11wDx12 { private: + bool _baseInit = false; protected: bool InitFSR2(const NVSDK_NGX_Parameter* InParameters); diff --git a/CyberXeSS/backends/fsr2/FSR2Feature_Dx12.cpp b/CyberXeSS/backends/fsr2/FSR2Feature_Dx12.cpp index 62792e67..5901c7bc 100644 --- a/CyberXeSS/backends/fsr2/FSR2Feature_Dx12.cpp +++ b/CyberXeSS/backends/fsr2/FSR2Feature_Dx12.cpp @@ -95,6 +95,33 @@ bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N ResourceBarrier(InCommandList, paramVelocity, (D3D12_RESOURCE_STATES)Config::Instance()->MVResourceBarrier.value(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + else if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL) + { + Config::Instance()->MVResourceBarrier = (int)D3D12_RESOURCE_STATE_UNORDERED_ACCESS; + + ResourceBarrier(InCommandList, paramVelocity, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, + D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + } + + if (!Config::Instance()->DisplayResolution.has_value()) + { + auto desc = paramVelocity->GetDesc(); + bool lowResMV = desc.Width == params.renderSize.width; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("FSR2FeatureDx12::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("FSR2FeatureDx12::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } params.motionVectors = ffxGetResourceDX12(&_context, paramVelocity, (wchar_t*)L"FSR2_MotionVectors", FFX_RESOURCE_STATE_COMPUTE_READ); } @@ -444,13 +471,11 @@ bool FSR2FeatureDx12::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureDx12::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureDx12::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } diff --git a/CyberXeSS/backends/fsr2/FSR2Feature_Vk.cpp b/CyberXeSS/backends/fsr2/FSR2Feature_Vk.cpp index 100fbe94..61fe0b35 100644 --- a/CyberXeSS/backends/fsr2/FSR2Feature_Vk.cpp +++ b/CyberXeSS/backends/fsr2/FSR2Feature_Vk.cpp @@ -96,13 +96,11 @@ bool FSR2FeatureVk::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureVk::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureVk::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp index 6f3b56a5..48cc3570 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.cpp @@ -11,30 +11,10 @@ bool FSR2FeatureDx11on12_212::Init(ID3D11Device* InDevice, ID3D11DeviceContext* if (IsInited()) return true; - if (!BaseInit(InDevice, InContext, InParameters)) - { - spdlog::debug("FSR2FeatureDx11on12_212::Init BaseInit failed!"); - return false; - } + Device = InDevice; + DeviceContext = InContext; - spdlog::debug("FSR2FeatureDx11on12_212::Init calling InitFSR2"); - - if (Dx12on11Device == nullptr) - { - spdlog::error("FSR2FeatureDx11on12_212::Init Dx12on11Device is null!"); - return false; - } - - if (!InitFSR2(InParameters)) - { - spdlog::error("FSR2FeatureDx11on12_212::Init InitFSR2 fail!"); - return false; - } - - if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); - - OUT_DS = std::make_unique("Output Downsample", Dx12on11Device); + _baseInit = false; return true; } @@ -43,6 +23,39 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, con { spdlog::debug("FSR2FeatureDx11on12_212::Evaluate"); + if (!_baseInit) + { + if (!BaseInit(Device, InDeviceContext, InParameters)) + { + spdlog::debug("FSR2FeatureDx11on12_212::Init BaseInit failed!"); + return false; + } + + _baseInit = true; + + spdlog::debug("FSR2FeatureDx11on12_212::Init calling InitFSR2"); + + if (Dx12on11Device == nullptr) + { + spdlog::error("FSR2FeatureDx11on12_212::Init Dx12on11Device is null!"); + return false; + } + + if (!InitFSR2(InParameters)) + { + spdlog::error("FSR2FeatureDx11on12_212::Init InitFSR2 fail!"); + return false; + } + + if (Imgui == nullptr || Imgui.get() == nullptr) + Imgui = std::make_unique(GetForegroundWindow(), Device); + + spdlog::trace("FSR2FeatureDx11on12_212::Evaluate sleeping after FSRContext creation for 1500ms"); + std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + + OUT_DS = std::make_unique("Output Downsample", Dx12on11Device); + } + if (!IsInited()) return false; @@ -115,6 +128,25 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, con _hasTM = params.reactive.resource != nullptr; _hasOutput = params.output.resource != nullptr; + if (_hasMV && !Config::Instance()->DisplayResolution.has_value()) + { + auto desc = dx11Mv.Dx12Resource->GetDesc(); + bool lowResMV = desc.Width == params.renderSize.width; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("FSR2FeatureDx11on12_212::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("FSR2FeatureDx11on12_212::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } + #pragma endregion float MVScaleX = 1.0f; @@ -343,13 +375,11 @@ bool FSR2FeatureDx11on12_212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= Fsr212::FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureDx11on12_212::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureDx11on12_212::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.h b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.h index c57bbb6e..51686fe4 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.h +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx11On12_212.h @@ -8,6 +8,7 @@ class FSR2FeatureDx11on12_212 : public FSR2Feature212, public IFeature_Dx11wDx12 { private: + bool _baseInit = false; protected: bool InitFSR2(const NVSDK_NGX_Parameter* InParameters); diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp index 7d50f4f1..c5593bf6 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Dx12_212.cpp @@ -71,10 +71,7 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, con else if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL) { Config::Instance()->ColorResourceBarrier = (int)D3D12_RESOURCE_STATE_RENDER_TARGET; - - ResourceBarrier(InCommandList, paramColor, - D3D12_RESOURCE_STATE_RENDER_TARGET, - D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + ResourceBarrier(InCommandList, paramColor, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); } params.color = Fsr212::ffxGetResourceDX12_212(&_context, paramColor, (wchar_t*)L"FSR2_Color", Fsr212::FFX_RESOURCE_STATE_COMPUTE_READ); @@ -94,9 +91,31 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, con spdlog::debug("FSR2FeatureDx12_212::Evaluate MotionVectors exist.."); if (Config::Instance()->MVResourceBarrier.has_value()) - ResourceBarrier(InCommandList, paramVelocity, - (D3D12_RESOURCE_STATES)Config::Instance()->MVResourceBarrier.value(), - D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + ResourceBarrier(InCommandList, paramVelocity, (D3D12_RESOURCE_STATES)Config::Instance()->MVResourceBarrier.value(), D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + else if (Config::Instance()->NVNGX_Engine == NVSDK_NGX_ENGINE_TYPE_UNREAL) + { + Config::Instance()->MVResourceBarrier = (int)D3D12_RESOURCE_STATE_UNORDERED_ACCESS; + ResourceBarrier(InCommandList, paramVelocity, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + } + + if (!Config::Instance()->DisplayResolution.has_value()) + { + auto desc = paramVelocity->GetDesc(); + bool lowResMV = desc.Width == params.renderSize.width; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("FSR2FeatureDx12_212::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("FSR2FeatureDx12_212::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } params.motionVectors = Fsr212::ffxGetResourceDX12_212(&_context, paramVelocity, (wchar_t*)L"FSR2_MotionVectors", Fsr212::FFX_RESOURCE_STATE_COMPUTE_READ); } @@ -452,13 +471,11 @@ bool FSR2FeatureDx12_212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= Fsr212::FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureDx12_212::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureDx12_212::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } diff --git a/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp b/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp index 744cbc9f..75445f09 100644 --- a/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp +++ b/CyberXeSS/backends/fsr2_212/FSR2Feature_Vk_212.cpp @@ -96,13 +96,11 @@ bool FSR2FeatureVk212::InitFSR2(const NVSDK_NGX_Parameter* InParameters) if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; _contextDesc.flags |= Fsr212::FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS; spdlog::info("FSR2FeatureVk212::InitFSR2 xessParams.initFlags (!LowResMV) {0:b}", _contextDesc.flags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("FSR2FeatureVk212::InitFSR2 xessParams.initFlags (LowResMV) {0:b}", _contextDesc.flags); } diff --git a/CyberXeSS/backends/xess/XeSSFeature.cpp b/CyberXeSS/backends/xess/XeSSFeature.cpp index 5501d6c0..e3848550 100644 --- a/CyberXeSS/backends/xess/XeSSFeature.cpp +++ b/CyberXeSS/backends/xess/XeSSFeature.cpp @@ -103,13 +103,11 @@ bool XeSSFeature::InitXeSS(ID3D12Device* device, const NVSDK_NGX_Parameter* InPa if (Config::Instance()->DisplayResolution.value_or(!LowRes)) { - Config::Instance()->DisplayResolution = true; xessParams.initFlags |= XESS_INIT_FLAG_HIGH_RES_MV; spdlog::info("XeSSFeature::InitXeSS xessParams.initFlags (!LowResMV) {0:b}", xessParams.initFlags); } else { - Config::Instance()->DisplayResolution = false; spdlog::info("XeSSFeature::InitXeSS xessParams.initFlags (LowResMV) {0:b}", xessParams.initFlags); } diff --git a/CyberXeSS/backends/xess/XeSSFeature_Dx11.cpp b/CyberXeSS/backends/xess/XeSSFeature_Dx11.cpp index f9a4243c..a79dd27e 100644 --- a/CyberXeSS/backends/xess/XeSSFeature_Dx11.cpp +++ b/CyberXeSS/backends/xess/XeSSFeature_Dx11.cpp @@ -19,36 +19,10 @@ bool XeSSFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex if (IsInited()) return true; - if (!BaseInit(InDevice, InContext, InParameters)) - { - spdlog::error("XeSSFeatureDx11::Init BaseInit failed!"); - return false; - } + Device = InDevice; + DeviceContext = InContext; - if (Dx12on11Device == nullptr) - { - spdlog::error("XeSSFeatureDx11::Init Dx12on11Device is null!"); - return false; - } - - spdlog::debug("XeSSFeatureDx11::Init calling InitXeSS"); - - if (!InitXeSS(Dx12on11Device, InParameters)) - { - spdlog::error("XeSSFeatureDx11::Init InitXeSS fail!"); - return false; - } - - if (Imgui == nullptr || Imgui.get() == nullptr) - { - spdlog::debug("XeSSFeatureDx11::Init Create Imgui!"); - Imgui = std::make_unique(GetForegroundWindow(), Device); - } - - spdlog::trace("XeSSFeatureDx11::Init sleeping after XeSSContext creation for 500ms"); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - - OUT_DS = std::make_unique("Output Downsample", Dx12on11Device); + _baseInit = false; return true; } @@ -57,6 +31,42 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK { spdlog::debug("XeSSFeatureDx11::Evaluate"); + if (!_baseInit) + { + if (!BaseInit(Device, InDeviceContext, InParameters)) + { + spdlog::error("XeSSFeatureDx11::Evaluate BaseInit failed!"); + return false; + } + + _baseInit = true; + + if (Dx12on11Device == nullptr) + { + spdlog::error("XeSSFeatureDx11::Evaluate Dx12on11Device is null!"); + return false; + } + + spdlog::debug("XeSSFeatureDx11::Evaluate calling InitXeSS"); + + if (!InitXeSS(Dx12on11Device, InParameters)) + { + spdlog::error("XeSSFeatureDx11::Evaluate InitXeSS fail!"); + return false; + } + + if (Imgui == nullptr || Imgui.get() == nullptr) + { + spdlog::debug("XeSSFeatureDx11::Evaluate Create Imgui!"); + Imgui = std::make_unique(GetForegroundWindow(), Device); + } + + spdlog::trace("XeSSFeatureDx11::Evaluate sleeping after XeSSContext creation for 1500ms"); + std::this_thread::sleep_for(std::chrono::milliseconds(1500)); + + OUT_DS = std::make_unique("Output Downsample", Dx12on11Device); + } + if (!IsInited() || !_xessContext) return false; @@ -185,6 +195,25 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, const NVSDK params.pResponsivePixelMaskTexture = dx11Tm.Dx12Resource; _hasTM = params.pResponsivePixelMaskTexture != nullptr; + if (_hasMV && !Config::Instance()->DisplayResolution.has_value()) + { + auto desc = dx11Mv.Dx12Resource->GetDesc(); + bool lowResMV = desc.Width == params.inputWidth; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("XeSSFeatureDx11::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("XeSSFeatureDx11::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } + spdlog::debug("XeSSFeatureDx11::Evaluate Textures -> params complete!"); float MVScaleX; diff --git a/CyberXeSS/backends/xess/XeSSFeature_Dx11.h b/CyberXeSS/backends/xess/XeSSFeature_Dx11.h index cee7b4f5..fa70e2b5 100644 --- a/CyberXeSS/backends/xess/XeSSFeature_Dx11.h +++ b/CyberXeSS/backends/xess/XeSSFeature_Dx11.h @@ -7,6 +7,7 @@ class XeSSFeatureDx11 : public XeSSFeature, public IFeature_Dx11wDx12 { private: ID3D12Resource* _outBuffer; + bool _baseInit = false; protected: diff --git a/CyberXeSS/backends/xess/XeSSFeature_Dx12.cpp b/CyberXeSS/backends/xess/XeSSFeature_Dx12.cpp index e2d37df1..cc5d0a11 100644 --- a/CyberXeSS/backends/xess/XeSSFeature_Dx12.cpp +++ b/CyberXeSS/backends/xess/XeSSFeature_Dx12.cpp @@ -142,6 +142,25 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, const N D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); } + + if (_hasMV && !Config::Instance()->DisplayResolution.has_value()) + { + auto desc = params.pVelocityTexture->GetDesc(); + bool lowResMV = desc.Width == params.inputWidth; + + if (Config::Instance()->DisplayResolution.value_or(false) && lowResMV) + { + spdlog::warn("XeSSFeatureDx12::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = false; + Config::Instance()->changeBackend = true; + } + else if (!Config::Instance()->DisplayResolution.value_or(false) && !lowResMV) + { + spdlog::warn("XeSSFeatureDx12::Evaluate MotionVectors size and feature init config not matching!!"); + Config::Instance()->DisplayResolution = true; + Config::Instance()->changeBackend = true; + } + } } else {