Better FG swapchain release

This commit is contained in:
cdozdil
2026-03-29 00:21:51 +03:00
parent 4f4b7b330f
commit b64da27a01
2 changed files with 75 additions and 0 deletions
+31
View File
@@ -379,6 +379,21 @@ static Fsr3::FfxErrorCode hkffxCreateFrameinterpolationSwapchainDX12(DXGI_SWAP_C
IDXGIFactory* dxgiFactory,
Fsr3::FfxSwapchain& outGameSwapChain)
{
if (State::Instance().currentSwapchain != nullptr &&
State::Instance().currentSwapchainDesc.OutputWindow == desc->OutputWindow)
{
auto refCount = State::Instance().currentSwapchain->Release();
while (refCount > 0)
{
refCount = State::Instance().currentSwapchain->Release();
}
State::Instance().currentSwapchain = nullptr;
State::Instance().currentFGSwapchain = nullptr;
State::Instance().currentSwapchainDesc = {};
}
auto result = dxgiFactory->CreateSwapChain(queue, desc, (IDXGISwapChain**) &outGameSwapChain);
return result == S_OK ? Fsr3::FFX_OK : Fsr3::FFX_ERROR_BACKEND_API_ERROR;
@@ -394,6 +409,22 @@ static Fsr3::FfxErrorCode hkffxCreateFrameinterpolationSwapchainForHwndDX12(
if (dxgiFactory->QueryInterface(IID_PPV_ARGS(&df)) == S_OK)
{
df->Release();
if (State::Instance().currentSwapchain != nullptr &&
State::Instance().currentSwapchainDesc.OutputWindow == hWnd)
{
auto refCount = State::Instance().currentSwapchain->Release();
while (refCount > 0)
{
refCount = State::Instance().currentSwapchain->Release();
}
State::Instance().currentSwapchain = nullptr;
State::Instance().currentFGSwapchain = nullptr;
State::Instance().currentSwapchainDesc = {};
}
result = df->CreateSwapChainForHwnd(queue, hWnd, desc1, fullscreenDesc, nullptr,
(IDXGISwapChain1**) &outGameSwapChain);
}
+44
View File
@@ -327,6 +327,22 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
else if (desc->type == FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_NEW_DX12)
{
auto cDesc = (ffxCreateContextDescFrameGenerationSwapChainNewDX12*) desc;
if (State::Instance().currentSwapchain != nullptr &&
State::Instance().currentSwapchainDesc.OutputWindow == cDesc->desc->OutputWindow)
{
auto refCount = State::Instance().currentSwapchain->Release();
while (refCount > 0)
{
refCount = State::Instance().currentSwapchain->Release();
}
State::Instance().currentSwapchain = nullptr;
State::Instance().currentFGSwapchain = nullptr;
State::Instance().currentSwapchainDesc = {};
}
auto result =
cDesc->dxgiFactory->CreateSwapChain(cDesc->gameQueue, cDesc->desc, (IDXGISwapChain**) cDesc->swapchain);
@@ -364,6 +380,21 @@ ffxReturnCode_t ffxCreateContext_Dx12FG(ffxContext* context, ffxCreateContextDes
factory->Release();
if (State::Instance().currentSwapchain != nullptr &&
State::Instance().currentSwapchainDesc.OutputWindow == cDesc->hwnd)
{
auto refCount = State::Instance().currentSwapchain->Release();
while (refCount > 0)
{
refCount = State::Instance().currentSwapchain->Release();
}
State::Instance().currentSwapchain = nullptr;
State::Instance().currentFGSwapchain = nullptr;
State::Instance().currentSwapchainDesc = {};
}
auto result = factory->CreateSwapChainForHwnd(cDesc->gameQueue, cDesc->hwnd, cDesc->desc, cDesc->fullscreenDesc,
nullptr, (IDXGISwapChain1**) cDesc->swapchain);
@@ -405,6 +436,19 @@ ffxReturnCode_t ffxDestroyContext_Dx12FG(ffxContext* context, const ffxAllocatio
{
LOG_INFO("Destroying Swapchain Context: {:X}", (size_t) State::Instance().currentFG);
State::Instance().currentFG->ReleaseSwapchain(State::Instance().currentFG->Hwnd());
if (State::Instance().currentSwapchain != nullptr)
{
auto refCount = State::Instance().currentSwapchain->Release();
while (refCount > 0)
{
refCount = State::Instance().currentSwapchain->Release();
}
State::Instance().currentSwapchain = nullptr;
}
return FFX_API_RETURN_OK;
}
else if (State::Instance().currentFG != nullptr && (void*) fgContext == *context)