From ff615888d27601b40acc4401f9ba991cd5958de9 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Tue, 5 Nov 2024 15:59:49 +0300 Subject: [PATCH] added fixes for frame timing disabled extra queues when not using hudfix --- OptiScaler/NVNGX_DLSS_Dx12.cpp | 15 +++------ OptiScaler/hooks/HooksDx.cpp | 45 ++++++++------------------ OptiScaler/hooks/HooksDx.h | 4 +++ OptiScaler/hooks/wrapped_swapchain.cpp | 4 +-- OptiScaler/resource.h | 2 +- 5 files changed, 24 insertions(+), 46 deletions(-) diff --git a/OptiScaler/NVNGX_DLSS_Dx12.cpp b/OptiScaler/NVNGX_DLSS_Dx12.cpp index e2b5728c..ae6e4c24 100644 --- a/OptiScaler/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/NVNGX_DLSS_Dx12.cpp @@ -26,14 +26,12 @@ //#define USE_COPY_QUEUE_FOR_FG // Use a dedicated Queue + CommandList for FG -#define USE_QUEUE_FOR_FG +//#define USE_QUEUE_FOR_FG -#ifndef USE_QUEUE_FOR_FG // Do not make copies of Depth + Velocity for FG //#define DONT_USE_DEPTH_MV_COPIES -#endif -#ifndef USE_MUTEX_FOR_FFX +#ifndef USE_PRESENT_FOR_FT static UINT64 fgLastFrameTime = 0; #endif static UINT64 fgLastFGFrame = 0; @@ -1343,7 +1341,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom { FrameGen_Dx12::upscaleRan = true; -#ifndef USE_MUTEX_FOR_FFX +#ifndef USE_PRESENT_FOR_FT float msDelta = 0.0; auto now = Util::MillisecondsNow(); @@ -1353,8 +1351,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom LOG_DEBUG("(FG) msDelta: {0}", msDelta); } - FrameGen_Dx12::fgFrameTime = msDelta; fgLastFrameTime = now; + FrameGen_Dx12::fgFrameTime = msDelta; #endif if (Config::Instance()->FGHUDFix.value_or(false)) @@ -1549,12 +1547,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom dfgPrepare.cameraFovAngleVertical = 1.0471975511966f; dfgPrepare.viewSpaceToMetersFactor = 1.0; - -#ifndef USE_MUTEX_FOR_FFX - dfgPrepare.frameTimeDelta = msDelta; -#else dfgPrepare.frameTimeDelta = FrameGen_Dx12::fgFrameTime; -#endif #ifdef USE_MUTEX_FOR_FFX FrameGen_Dx12::ffxMutex.lock(); diff --git a/OptiScaler/hooks/HooksDx.cpp b/OptiScaler/hooks/HooksDx.cpp index a2cf777a..34a54642 100644 --- a/OptiScaler/hooks/HooksDx.cpp +++ b/OptiScaler/hooks/HooksDx.cpp @@ -1507,26 +1507,33 @@ static void hkDispatch(ID3D12GraphicsCommandList* This, UINT ThreadGroupCountX, #ifdef USE_MUTEX_FOR_FFX static HRESULT hkFGPresent(void* This, UINT SyncInterval, UINT Flags) { - FrameGen_Dx12::upscaleRan = false; + // Skip calculations etc + if (Flags & DXGI_PRESENT_TEST) + return o_FGSCPresent(This, SyncInterval, Flags); FrameGen_Dx12::ffxMutex.lock(); + auto result = o_FGSCPresent(This, SyncInterval, Flags); + +#ifdef USE_PRESENT_FOR_FT float msDelta = 0.0; auto now = Util::MillisecondsNow(); if (fgLastFrameTime != 0) { msDelta = now - fgLastFrameTime; - LOG_DEBUG("(FG) msDelta: {0}", msDelta); + LOG_DEBUG("Frametime: {0}", msDelta); } - FrameGen_Dx12::fgFrameTime = msDelta; fgLastFrameTime = now; + FrameGen_Dx12::fgFrameTime = msDelta; +#else + LOG_DEBUG(""); +#endif - - LOG_DEBUG(""); - auto result = o_FGSCPresent(This, SyncInterval, Flags); + FrameGen_Dx12::upscaleRan = false; FrameGen_Dx12::ffxMutex.unlock(); + return result; } #endif @@ -1561,9 +1568,6 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags FrameGen_Dx12::gameCommandQueue = swInfo->gameCommandQueue; } - //if (Config::Instance()->CurrentFeature != nullptr) - // LOG_DEBUG("FrameCount: {}, fgHudlessFrame: {}", Config::Instance()->CurrentFeature->FrameCount(), fgHudlessFrame); - ID3D12CommandQueue* cq = nullptr; ID3D11Device* device = nullptr; ID3D12Device* device12 = nullptr; @@ -1622,17 +1626,6 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags fgStopAfterNextPresent = false; } -#ifndef USE_MUTEX_FOR_FFX - auto now = Util::MillisecondsNow(); - - if (fgLastFrameTime != 0) - { - fgLastDeltaTime = now - fgLastFrameTime; - LOG_DEBUG("fgLastDeltaTime: {0:.2f}, frameCounter: {1}", fgLastDeltaTime, frameCounter); - } - - fgLastFrameTime = now; -#endif return presentResult; } @@ -1727,18 +1720,6 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags if (device12 != nullptr) device12->Release(); -#ifndef USE_MUTEX_FOR_FFX - auto now = Util::MillisecondsNow(); - - if (fgLastFrameTime != 0) - { - fgLastDeltaTime = now - fgLastFrameTime; - LOG_DEBUG("fgLastDeltaTime: {0:.2f}, frameCounter: {1}", fgLastDeltaTime, frameCounter); - } - - fgLastFrameTime = now; -#endif - return presentResult; } diff --git a/OptiScaler/hooks/HooksDx.h b/OptiScaler/hooks/HooksDx.h index 923abc8c..03759417 100644 --- a/OptiScaler/hooks/HooksDx.h +++ b/OptiScaler/hooks/HooksDx.h @@ -12,6 +12,10 @@ // Will use mutex to prevent race condutions #define USE_MUTEX_FOR_FFX +#ifdef USE_MUTEX_FOR_FFX +#define USE_PRESENT_FOR_FT +#endif + // Enable D3D12 Debug Layers //#define ENABLE_DEBUG_LAYER diff --git a/OptiScaler/hooks/wrapped_swapchain.cpp b/OptiScaler/hooks/wrapped_swapchain.cpp index d96455cf..12c49035 100644 --- a/OptiScaler/hooks/wrapped_swapchain.cpp +++ b/OptiScaler/hooks/wrapped_swapchain.cpp @@ -233,7 +233,7 @@ HRESULT WrappedIDXGISwapChain4::Present(UINT SyncInterval, UINT Flags) HRESULT result; - if (!(Flags & DXGI_PRESENT_TEST) && !(Flags & DXGI_PRESENT_RESTART) && RenderTrig != nullptr) + if (!(Flags & DXGI_PRESENT_TEST) && RenderTrig != nullptr) result = RenderTrig(m_pReal, SyncInterval, Flags, nullptr, Device, Handle); else result = m_pReal->Present(SyncInterval, Flags); @@ -248,7 +248,7 @@ HRESULT WrappedIDXGISwapChain4::Present1(UINT SyncInterval, UINT Flags, const DX HRESULT result; - if (!(Flags & DXGI_PRESENT_TEST) && !(Flags & DXGI_PRESENT_RESTART) && RenderTrig != nullptr) + if (!(Flags & DXGI_PRESENT_TEST) && RenderTrig != nullptr) result = RenderTrig(m_pReal1, SyncInterval, Flags, pPresentParameters, Device, Handle); else result = m_pReal1->Present1(SyncInterval, Flags, pPresentParameters); diff --git a/OptiScaler/resource.h b/OptiScaler/resource.h index 8e70454d..925b08ea 100644 --- a/OptiScaler/resource.h +++ b/OptiScaler/resource.h @@ -21,7 +21,7 @@ #define VER_MAJOR_VERSION 0 #define VER_MINOR_VERSION 7 #define VER_HOTFIX_VERSION 0 -#define VER_BUILD_NUMBER 33 +#define VER_BUILD_NUMBER 36 #define VER_PRE_RELEASE