From caf89400af8287d148a46e67cea2e9e97ae5a38e Mon Sep 17 00:00:00 2001 From: cdozdil Date: Mon, 25 Nov 2024 12:18:32 +0300 Subject: [PATCH] added mutexes for FG context destroy --- OptiScaler/hooks/HooksDx.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/OptiScaler/hooks/HooksDx.cpp b/OptiScaler/hooks/HooksDx.cpp index 2874b373..e7d561a8 100644 --- a/OptiScaler/hooks/HooksDx.cpp +++ b/OptiScaler/hooks/HooksDx.cpp @@ -3553,6 +3553,15 @@ void FrameGen_Dx12::ReleaseFGSwapchain(HWND hWnd) ImGuiOverlayDx::CleanupRenderTarget(true, hWnd); + if (FrameGen_Dx12::fgContext != nullptr) + { + FrameGen_Dx12::StopAndDestroyFGContext(true, false, false); + +#ifndef USE_MUTEX_FOR_FFX + std::this_thread::sleep_for(std::chrono::milliseconds(250)); +#endif + } + #ifndef USE_MUTEX_FOR_FFX std::this_thread::sleep_for(std::chrono::milliseconds(250)); #endif @@ -3868,14 +3877,18 @@ void FrameGen_Dx12::CreateFGContext(ID3D12Device* InDevice, IFeature* deviceCont LOG_DEBUG("Create"); } -void FrameGen_Dx12::StopAndDestroyFGContext(bool destroy, bool shutDown) +void FrameGen_Dx12::StopAndDestroyFGContext(bool destroy, bool shutDown, bool useMutex) { FrameGen_Dx12::fgSkipHudlessChecks = false; + + if (useMutex) + FrameGen_Dx12::ffxMutex.lock(); + //Config::Instance()->dxgiSkipSpoofing = true; if (!(shutDown || Config::Instance()->IsShuttingDown) && FrameGen_Dx12::fgContext != nullptr) { - std::this_thread::sleep_for(std::chrono::milliseconds(250)); + //std::this_thread::sleep_for(std::chrono::milliseconds(250)); ffxConfigureDescFrameGeneration m_FrameGenerationConfig = {}; m_FrameGenerationConfig.header.type = FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATION; @@ -3906,6 +3919,9 @@ void FrameGen_Dx12::StopAndDestroyFGContext(bool destroy, bool shutDown) if ((shutDown || Config::Instance()->IsShuttingDown) || destroy) ReleaseFGObjects(); + + if (useMutex) + FrameGen_Dx12::ffxMutex.unlock(); } void FrameGen_Dx12::CheckUpscaledFrame(ID3D12GraphicsCommandList* InCmdList, ID3D12Resource* InUpscaled)