From bd331db5bb76bf342182f080995d83ab0b77b50c Mon Sep 17 00:00:00 2001 From: cdozdil Date: Sat, 30 Aug 2025 11:47:40 +0300 Subject: [PATCH] Try to improve FG Feature lifetime & context management --- OptiScaler/framegen/ffx/FSRFG_Dx12.cpp | 10 ++++------ OptiScaler/framegen/ffx/FSRFG_Dx12.h | 2 ++ OptiScaler/framegen/xefg/XeFG_Dx12.cpp | 11 ++++++----- OptiScaler/framegen/xefg/XeFG_Dx12.h | 2 ++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp b/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp index e0144af6..ec569e49 100644 --- a/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp +++ b/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp @@ -378,6 +378,8 @@ ffxReturnCode_t FSRFG_Dx12::DispatchCallback(ffxDispatchDescFrameGeneration* par return dispatchResult; } +FSRFG_Dx12::~FSRFG_Dx12() { Shutdown(); } + void* FSRFG_Dx12::FrameGenerationContext() { LOG_DEBUG(""); @@ -418,9 +420,6 @@ bool FSRFG_Dx12::Shutdown() { Deactivate(); - if (_fgContext != nullptr) - DestroyFGContext(); - if (_swapChainContext != nullptr) ReleaseSwapchain(_hwnd); @@ -529,8 +528,6 @@ bool FSRFG_Dx12::ReleaseSwapchain(HWND hwnd) _swapChainContext = nullptr; } - ReleaseObjects(); - if (Config::Instance()->FGUseMutexForSwapchain.value_or_default()) { LOG_TRACE("Releasing Mutex: {}", Mutex.getOwner()); @@ -544,6 +541,8 @@ void FSRFG_Dx12::CreateContext(ID3D12Device* device, FG_Constants& fgConstants) { LOG_DEBUG(""); + CreateObjects(device); + _constants = fgConstants; // Changing the format of the hudless resource requires a new context @@ -738,7 +737,6 @@ void FSRFG_Dx12::EvaluateState(ID3D12Device* device, FG_Constants& fgConstants) if (_fgContext == nullptr) { // Create it again - CreateObjects(device); CreateContext(device, fgConstants); // Pause for 10 frames diff --git a/OptiScaler/framegen/ffx/FSRFG_Dx12.h b/OptiScaler/framegen/ffx/FSRFG_Dx12.h index 7057fa30..f122562f 100644 --- a/OptiScaler/framegen/ffx/FSRFG_Dx12.h +++ b/OptiScaler/framegen/ffx/FSRFG_Dx12.h @@ -97,4 +97,6 @@ class FSRFG_Dx12 : public virtual IFGFeature_Dx12 { // } + + ~FSRFG_Dx12(); }; diff --git a/OptiScaler/framegen/xefg/XeFG_Dx12.cpp b/OptiScaler/framegen/xefg/XeFG_Dx12.cpp index fed2a031..825871bd 100644 --- a/OptiScaler/framegen/xefg/XeFG_Dx12.cpp +++ b/OptiScaler/framegen/xefg/XeFG_Dx12.cpp @@ -383,11 +383,11 @@ void XeFG_Dx12::CreateContext(ID3D12Device* device, FG_Constants& fgConstants) LOG_DEBUG(""); _device = device; + CreateObjects(device); if (_fgContext == nullptr && _swapChainContext != nullptr) { _fgContext = _swapChainContext; - CreateObjects(device); } } @@ -602,6 +602,8 @@ void* XeFG_Dx12::FrameGenerationContext() { return _fgContext; } void* XeFG_Dx12::SwapchainContext() { return _swapChainContext; } +XeFG_Dx12::~XeFG_Dx12() { Shutdown(); } + void XeFG_Dx12::EvaluateState(ID3D12Device* device, FG_Constants& fgConstants) { LOG_FUNC(); @@ -626,7 +628,6 @@ void XeFG_Dx12::EvaluateState(ID3D12Device* device, FG_Constants& fgConstants) if (_fgContext == nullptr) { // Create it again - CreateObjects(device); CreateContext(device, fgConstants); // Pause for 10 frames @@ -912,10 +913,10 @@ bool XeFG_Dx12::ReleaseSwapchain(HWND hwnd) if (_fgContext != nullptr) DestroyFGContext(); - if (_swapChainContext != nullptr) - DestroySwapchainContext(); + // if (_swapChainContext != nullptr) + // DestroySwapchainContext(); - ReleaseObjects(); + // ReleaseObjects(); if (Config::Instance()->FGUseMutexForSwapchain.value_or_default()) { diff --git a/OptiScaler/framegen/xefg/XeFG_Dx12.h b/OptiScaler/framegen/xefg/XeFG_Dx12.h index 02c6c842..f3879c00 100644 --- a/OptiScaler/framegen/xefg/XeFG_Dx12.h +++ b/OptiScaler/framegen/xefg/XeFG_Dx12.h @@ -72,4 +72,6 @@ class XeFG_Dx12 : public virtual IFGFeature_Dx12 if (XeFGProxy::Module() == nullptr) XeFGProxy::InitXeFG(); } + + ~XeFG_Dx12(); };