diff --git a/OptiScaler/framegen/IFGFeature_Dx12.cpp b/OptiScaler/framegen/IFGFeature_Dx12.cpp index bf8e44fb..ec2ce43f 100644 --- a/OptiScaler/framegen/IFGFeature_Dx12.cpp +++ b/OptiScaler/framegen/IFGFeature_Dx12.cpp @@ -20,20 +20,19 @@ bool IFGFeature_Dx12::GetResourceCopy(FG_ResourceType type, D3D12_RESOURCE_STATE auto fIndex = GetIndex(); - auto result = _copyCommandAllocator[fIndex]->Reset(); - if (result != S_OK) - return false; + if (!_uiCommandListResetted[fIndex]) + { + auto result = _copyCommandAllocator[fIndex]->Reset(); + if (result != S_OK) + return false; - result = _copyCommandList[fIndex]->Reset(_copyCommandAllocator[fIndex], nullptr); - if (result != S_OK) - return false; + result = _copyCommandList[fIndex]->Reset(_copyCommandAllocator[fIndex], nullptr); + if (result != S_OK) + return false; + } _copyCommandList[fIndex]->CopyResource(output, resource->GetResource()); - _copyCommandList[fIndex]->Close(); - ID3D12CommandList* commandList = _copyCommandList[fIndex]; - _gameCommandQueue->ExecuteCommandLists(1, &commandList); - return true; } @@ -62,6 +61,7 @@ void IFGFeature_Dx12::NewFrame() LOG_DEBUG("_frameCount: {}, fIndex: {}", _frameCount, fIndex); _frameResources[fIndex].clear(); + _uiCommandListResetted[fIndex] = false; } void IFGFeature_Dx12::FlipResource(Dx12Resource* resource) diff --git a/OptiScaler/framegen/IFGFeature_Dx12.h b/OptiScaler/framegen/IFGFeature_Dx12.h index 4912fa38..d4f1e794 100644 --- a/OptiScaler/framegen/IFGFeature_Dx12.h +++ b/OptiScaler/framegen/IFGFeature_Dx12.h @@ -48,6 +48,7 @@ class IFGFeature_Dx12 : public virtual IFGFeature ID3D12GraphicsCommandList* _uiCommandList[BUFFER_COUNT] {}; ID3D12CommandAllocator* _uiCommandAllocator[BUFFER_COUNT] {}; + bool _uiCommandListResetted[BUFFER_COUNT] {}; std::unordered_map _frameResources[BUFFER_COUNT] {}; std::unordered_map _resourceCopy[BUFFER_COUNT] {}; diff --git a/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp b/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp index ec569e49..39625f24 100644 --- a/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp +++ b/OptiScaler/framegen/ffx/FSRFG_Dx12.cpp @@ -822,12 +822,25 @@ bool FSRFG_Dx12::ExecuteCommandList(int index) { LOG_DEBUG(); + std::vector lists; + + if (_uiCommandListResetted[index]) + { + LOG_DEBUG("Executing UI cmdList: {:X}", (size_t) _uiCommandList[index]); + lists.push_back(_uiCommandList[index]); + _uiCommandListResetted[index] = false; + } + if (WaitingExecution(index)) { - LOG_DEBUG("Executing FG cmdList: {:X} with queue: {:X}", (size_t) _fgCommandList[index], - (size_t) _gameCommandQueue); - _gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_fgCommandList[index]); + LOG_DEBUG("Executing FG cmdList: {:X}", (size_t) _fgCommandList[index]); + lists.push_back(_fgCommandList[index]); SetExecuted(); + } + + if (lists.size() > 0) + { + _gameCommandQueue->ExecuteCommandLists(lists.size(), lists.data()); return true; } @@ -930,18 +943,21 @@ ID3D12GraphicsCommandList* FSRFG_Dx12::GetUICommandList(int index) if (index < 0) index = GetIndex(); - auto result = _uiCommandAllocator[index]->Reset(); - - if (result == S_OK) + if (!_uiCommandListResetted[index]) { - result = _uiCommandList[index]->Reset(_uiCommandAllocator[index], nullptr); + auto result = _uiCommandAllocator[index]->Reset(); - if (result != S_OK) - LOG_ERROR("_uiCommandList[{}]->Reset() error: {:X}", index, (UINT) result); - } - else - { - LOG_ERROR("_uiCommandAllocator[{}]->Reset() error: {:X}", index, (UINT) result); + if (result == S_OK) + { + result = _uiCommandList[index]->Reset(_uiCommandAllocator[index], nullptr); + + if (result != S_OK) + LOG_ERROR("_uiCommandList[{}]->Reset() error: {:X}", index, (UINT) result); + } + else + { + LOG_ERROR("_uiCommandAllocator[{}]->Reset() error: {:X}", index, (UINT) result); + } } return _uiCommandList[index]; diff --git a/OptiScaler/framegen/xefg/XeFG_Dx12.cpp b/OptiScaler/framegen/xefg/XeFG_Dx12.cpp index 88ec7c49..3c4da211 100644 --- a/OptiScaler/framegen/xefg/XeFG_Dx12.cpp +++ b/OptiScaler/framegen/xefg/XeFG_Dx12.cpp @@ -775,6 +775,14 @@ bool XeFG_Dx12::Present() } } + auto fIndex = GetIndex(); + if (_uiCommandListResetted[fIndex]) + { + LOG_DEBUG("Executing UI cmdList: {:X}", (size_t) _uiCommandList[fIndex]); + _gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[fIndex]); + _uiCommandListResetted[fIndex] = false; + } + return Dispatch(); } @@ -893,8 +901,22 @@ ID3D12GraphicsCommandList* XeFG_Dx12::GetUICommandList(int index) if (index < 0) index = GetIndex(); - _uiCommandAllocator[index]->Reset(); - _uiCommandList[index]->Reset(_uiCommandAllocator[index], nullptr); + if (!_uiCommandListResetted[index]) + { + auto result = _uiCommandAllocator[index]->Reset(); + + if (result == S_OK) + { + result = _uiCommandList[index]->Reset(_uiCommandAllocator[index], nullptr); + + if (result != S_OK) + LOG_ERROR("_uiCommandList[{}]->Reset() error: {:X}", index, (UINT) result); + } + else + { + LOG_ERROR("_uiCommandAllocator[{}]->Reset() error: {:X}", index, (UINT) result); + } + } return _uiCommandList[index]; } diff --git a/OptiScaler/inputs/FG/FfxApi_Dx12_FG.cpp b/OptiScaler/inputs/FG/FfxApi_Dx12_FG.cpp index d670f7e8..a9edfb6e 100644 --- a/OptiScaler/inputs/FG/FfxApi_Dx12_FG.cpp +++ b/OptiScaler/inputs/FG/FfxApi_Dx12_FG.cpp @@ -483,48 +483,6 @@ ffxReturnCode_t ffxConfigure_Dx12FG(ffxContext* context, ffxConfigureDescHeader* _presentCallback = cDesc->presentCallback; _presentCallbackUserContext = cDesc->presentCallbackUserContext; _presentCallbackFrameId = cDesc->frameID; - - // Probably because of queue can't capture at correct state - // if (fg->GetResource(FG_ResourceType::HudlessColor) == nullptr) - //{ - // LOG_DEBUG("Trying to copy current swapchain buffer as hudless"); - - // IDXGISwapChain3* sc = (IDXGISwapChain3*) State::Instance().currentFGSwapchain; - // auto scIndex = sc->GetCurrentBackBufferIndex(); - - // ID3D12Resource* currentBuffer = nullptr; - // auto hr = sc->GetBuffer(scIndex, IID_PPV_ARGS(¤tBuffer)); - // if (hr != S_OK) - // { - // LOG_ERROR("sc->GetBuffer error: {:X}", (UINT) hr); - // } - - // auto cmdList = fg->GetUICommandList(); - - // auto hDesc = currentBuffer->GetDesc(); - // Dx12Resource hudless {}; - // hudless.cmdList = cmdList; - // hudless.height = hDesc.Height; - // hudless.resource = currentBuffer; - // hudless.state = D3D12_RESOURCE_STATE_PRESENT; - // hudless.type = FG_ResourceType::HudlessColor; - // hudless.validity = FG_ResourceValidity::ValidNow; - // hudless.width = hDesc.Width; - // fg->SetResource(&hudless); - - // hr = cmdList->Close(); - // if (hr == S_OK) - // { - // ID3D12CommandList* cmdLists[1] = { cmdList }; - // fg->GetCommandQueue()->ExecuteCommandLists(1, cmdLists); - // } - // else - // { - // LOG_ERROR("cmdList->Close() error: {:X}", (UINT) hr); - // } - - // currentBuffer->Release(); - //} } if (cDesc->allowAsyncWorkloads || cDesc->onlyPresentGenerated) @@ -735,14 +693,14 @@ ffxReturnCode_t ffxQuery_Dx12FG(ffxContext* context, ffxQueryDescHeader* desc) } else if (desc->type == FFX_API_QUERY_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_INTERPOLATIONCOMMANDLIST_DX12) { - // auto cDesc = (ffxQueryDescFrameGenerationSwapChainInterpolationCommandListDX12*) desc; - // auto fg = State::Instance().currentFG; + auto cDesc = (ffxQueryDescFrameGenerationSwapChainInterpolationCommandListDX12*) desc; + auto fg = State::Instance().currentFG; - // if (fg != nullptr) - //{ - // *cDesc->pOutCommandList = fg->GetUICommandList(); - // LOG_DEBUG("Returning cmdList: {:X}", (size_t) *cDesc->pOutCommandList); - // } + if (fg != nullptr) + { + *cDesc->pOutCommandList = fg->GetUICommandList(); + LOG_DEBUG("Returning cmdList: {:X}", (size_t) *cDesc->pOutCommandList); + } return FFX_API_RETURN_OK; }