diff --git a/OptiScaler/framegen/IFGFeature.h b/OptiScaler/framegen/IFGFeature.h index 9968763a..f4b046f6 100644 --- a/OptiScaler/framegen/IFGFeature.h +++ b/OptiScaler/framegen/IFGFeature.h @@ -69,7 +69,9 @@ class IFGFeature virtual void SetUIReady() = 0; virtual void SetHudlessDispatchReady() = 0; - virtual bool UpscalerInputsReady() = 0; + virtual bool VelocityReady() = 0; + virtual bool DepthReady() = 0; + virtual bool UIReady() = 0; virtual bool HudlessReady() = 0; virtual bool ReadyForExecute() = 0; diff --git a/OptiScaler/framegen/IFGFeature_Dx12.cpp b/OptiScaler/framegen/IFGFeature_Dx12.cpp index e603cfc4..8d4dec47 100644 --- a/OptiScaler/framegen/IFGFeature_Dx12.cpp +++ b/OptiScaler/framegen/IFGFeature_Dx12.cpp @@ -421,7 +421,10 @@ void IFGFeature_Dx12::Present() _hudlessDispatchReady[fIndex] = false; } -bool IFGFeature_Dx12::UpscalerInputsReady() { return _velocityReady[GetIndex()] && _depthReady[GetIndex()]; } +bool IFGFeature_Dx12::VelocityReady() { return _velocityReady[GetIndex()]; } +bool IFGFeature_Dx12::DepthReady() { return _depthReady[GetIndex()]; } +bool IFGFeature_Dx12::UIReady() { return _uiReady[GetIndex()]; } + bool IFGFeature_Dx12::HudlessReady() { return _hudlessReady[GetIndex()]; } // Only makes sense for upscaler inputs because the list of buffers diff --git a/OptiScaler/framegen/IFGFeature_Dx12.h b/OptiScaler/framegen/IFGFeature_Dx12.h index 760c538a..60fa2f0c 100644 --- a/OptiScaler/framegen/IFGFeature_Dx12.h +++ b/OptiScaler/framegen/IFGFeature_Dx12.h @@ -131,7 +131,9 @@ class IFGFeature_Dx12 : public virtual IFGFeature void SetUIReady() override; void SetHudlessDispatchReady() override; void Present() override; - bool UpscalerInputsReady() override; + bool VelocityReady() override; + bool DepthReady() override; + bool UIReady() override; bool HudlessReady() override; bool ReadyForExecute() override; }; diff --git a/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp b/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp index 85611dae..1738f0fe 100644 --- a/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp +++ b/OptiScaler/framegen/Streamline_Inputs_Dx12.cpp @@ -143,7 +143,7 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo depthSent = true; - ResTrack_Dx12::SetInputsCmdList(cmdBuffer); + ResTrack_Dx12::SetDepthCmdList(cmdBuffer); auto depthResource = (ID3D12Resource*) tag.resource->native; @@ -158,7 +158,7 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo mvsSent = true; - ResTrack_Dx12::SetInputsCmdList(cmdBuffer); + ResTrack_Dx12::SetMVsCmdList(cmdBuffer); auto mvResource = (ID3D12Resource*) tag.resource->native; @@ -175,7 +175,7 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo uiSent = true; - ResTrack_Dx12::SetInputsCmdList(cmdBuffer); + ResTrack_Dx12::SetUICmdList(cmdBuffer); auto uiResource = (ID3D12Resource*) tag.resource->native; @@ -196,21 +196,19 @@ bool Sl_Inputs_Dx12::reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCo // Will trigger frame count update on the next call to reportResource allRequiredSent = hudlessSent && depthSent && mvsSent && (uiRequired && uiSent || !uiRequired); - if (allRequiredSent) - { - State::Instance().slFGInputs.dispatchFG((ID3D12GraphicsCommandList*) cmdBuffer); - - depthSent = false; - hudlessSent = false; - mvsSent = false; - uiSent = false; - } + // if (allRequiredSent) + // State::Instance().slFGInputs.dispatchFG((ID3D12GraphicsCommandList*) cmdBuffer); return true; } bool Sl_Inputs_Dx12::dispatchFG(ID3D12GraphicsCommandList* cmdBuffer) { + depthSent = false; + hudlessSent = false; + mvsSent = false; + uiSent = false; + auto fgOutput = reinterpret_cast(State::Instance().currentFG); if (fgOutput == nullptr) diff --git a/OptiScaler/framegen/Streamline_Inputs_Dx12.h b/OptiScaler/framegen/Streamline_Inputs_Dx12.h index ee2273e2..65b59a5a 100644 --- a/OptiScaler/framegen/Streamline_Inputs_Dx12.h +++ b/OptiScaler/framegen/Streamline_Inputs_Dx12.h @@ -18,13 +18,13 @@ class Sl_Inputs_Dx12 bool allRequiredSent = false; - bool dispatchFG(ID3D12GraphicsCommandList* cmdBuffer); - public: bool setConstants(const sl::Constants& constants); bool evaluateState(ID3D12Device* device); bool reportResource(const sl::ResourceTag& tag, ID3D12GraphicsCommandList* cmdBuffer); void reportEngineType(sl::EngineType type) { engineType = type; }; + bool dispatchFG(ID3D12GraphicsCommandList* cmdBuffer); + bool readyForDispatch() const { return allRequiredSent; }; // TODO: some shutdown and cleanup methods }; diff --git a/OptiScaler/hooks/HooksDx.cpp b/OptiScaler/hooks/HooksDx.cpp index 6a20f6da..fcbd7dcb 100644 --- a/OptiScaler/hooks/HooksDx.cpp +++ b/OptiScaler/hooks/HooksDx.cpp @@ -285,8 +285,8 @@ static HRESULT hkFGPresent(void* This, UINT SyncInterval, UINT Flags) if (willPresent && State::Instance().currentCommandQueue != nullptr && State::Instance().activeFgInput == FGInput::Upscaler && fg != nullptr && fg->IsActive() && - fg->TargetFrame() < fg->FrameCount() && fg->LastDispatchedFrame() != fg->FrameCount() && - fg->UpscalerInputsReady()) + fg->TargetFrame() < fg->FrameCount() && fg->LastDispatchedFrame() != fg->FrameCount() && fg->DepthReady() && + fg->VelocityReady()) { State::Instance().fgTrigSource = "Present"; fg->Present(); @@ -300,6 +300,12 @@ static HRESULT hkFGPresent(void* This, UINT SyncInterval, UINT Flags) } } + if (willPresent && State::Instance().activeFgInput == FGInput::DLSSG && + State::Instance().slFGInputs.readyForDispatch()) + { + State::Instance().slFGInputs.dispatchFG(nullptr); + } + // if (willPresent && State::Instance().currentCommandQueue != nullptr && // State::Instance().activeFgInput == FGInput::DLSSG && fg != nullptr) //{ diff --git a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp index 118d0744..fa19687b 100644 --- a/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/inputs/NVNGX_DLSS_Dx12.cpp @@ -1597,7 +1597,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom fg->Mutex.unlockThis(4); } - ResTrack_Dx12::SetInputsCmdList(InCmdList); + ResTrack_Dx12::SetDepthCmdList(InCmdList); + ResTrack_Dx12::SetMVsCmdList(InCmdList); bool allocatorReset = false; frameIndex = fg->GetIndex(); diff --git a/OptiScaler/resource_tracking/ResTrack_dx12.cpp b/OptiScaler/resource_tracking/ResTrack_dx12.cpp index a957bae5..7ab8452f 100644 --- a/OptiScaler/resource_tracking/ResTrack_dx12.cpp +++ b/OptiScaler/resource_tracking/ResTrack_dx12.cpp @@ -105,7 +105,9 @@ static std::unique_ptr fgHeaps[1000]; static UINT fgHeapIndex = 0; static void* _hudlessCmdList = nullptr; -static void* _inputsCmdList = nullptr; +static void* _depthCmdList = nullptr; +static void* _mvsCmdList = nullptr; +static void* _uiCmdList = nullptr; struct HeapCacheTLS { @@ -690,18 +692,33 @@ void ResTrack_Dx12::hkExecuteCommandLists(ID3D12CommandQueue* This, UINT NumComm auto index = fg == nullptr ? 0 : fg->GetIndex(); if ((State::Instance().activeFgInput == FGInput::Upscaler || State::Instance().activeFgInput == FGInput::DLSSG) && - (_hudlessCmdList != nullptr || _inputsCmdList != nullptr)) + (_hudlessCmdList != nullptr || _depthCmdList != nullptr || _mvsCmdList != nullptr || _uiCmdList != nullptr)) { int cmdListCount = 0; - int targetListCount = (_inputsCmdList == nullptr ? 0 : 1) + (fg->NoHudless() ? 0 : 1); + int targetListCount = (_depthCmdList == nullptr ? 0 : 1) + (_mvsCmdList == nullptr ? 0 : 1) + + (_uiCmdList == nullptr ? 0 : 1) + (fg->NoHudless() ? 0 : 1); for (size_t i = 0; i < NumCommandLists; i++) { - if (_inputsCmdList != nullptr && _inputsCmdList == ppCommandLists[i]) + if (_depthCmdList != nullptr && _depthCmdList == ppCommandLists[i]) { - LOG_DEBUG("_inputsCmdList: {:X}", (size_t) _inputsCmdList); + LOG_DEBUG("_depthCmdList: {:X}", (size_t) _depthCmdList); cmdListCount++; - _inputsCmdList = nullptr; + _depthCmdList = nullptr; + } + + if (_mvsCmdList != nullptr && _mvsCmdList == ppCommandLists[i]) + { + LOG_DEBUG("_mvsCmdList: {:X}", (size_t) _mvsCmdList); + cmdListCount++; + _mvsCmdList = nullptr; + } + + if (_uiCmdList != nullptr && _uiCmdList == ppCommandLists[i]) + { + LOG_DEBUG("_uiCmdList: {:X}", (size_t) _uiCmdList); + cmdListCount++; + _uiCmdList = nullptr; } if (_hudlessCmdList != nullptr && _hudlessCmdList == ppCommandLists[i]) @@ -1490,10 +1507,20 @@ void ResTrack_Dx12::hkExecuteBundle(ID3D12GraphicsCommandList* This, ID3D12Graph LOG_DEBUG("Hudless cmdlist[{}]: {:X}", index, (size_t) This); _hudlessCommandList[index] = This; } - else if (pCommandList == _inputsCommandList[index]) + else if (pCommandList == _mvsCommandList[index]) { - LOG_DEBUG("Upscaler cmdlist[{}]: {:X}", index, (size_t) This); - _inputsCommandList[index] = This; + LOG_DEBUG("Velocity cmdlist[{}]: {:X}", index, (size_t) This); + _mvsCommandList[index] = This; + } + else if (pCommandList == _depthCommandList[index]) + { + LOG_DEBUG("Depth cmdlist[{}]: {:X}", index, (size_t) This); + _depthCommandList[index] = This; + } + else if (pCommandList == _uiCommandList[index]) + { + LOG_DEBUG("UI cmdlist[{}]: {:X}", index, (size_t) This); + _uiCommandList[index] = This; } } @@ -1506,7 +1533,9 @@ void ResTrack_Dx12::hkClose(ID3D12GraphicsCommandList* This) auto index = fg != nullptr ? fg->GetIndex() : 0; if ((State::Instance().activeFgInput == FGInput::Upscaler || State::Instance().activeFgInput == FGInput::DLSSG) && - fg != nullptr && (_inputsCommandList[index] != nullptr || _hudlessCommandList[index] != nullptr)) + fg != nullptr && + (_depthCommandList[index] != nullptr || _mvsCommandList[index] != nullptr || _uiCommandList[index] != nullptr || + _hudlessCommandList[index] != nullptr)) { if (fg->IsActive() && fg->TargetFrame() < fg->FrameCount()) @@ -1524,20 +1553,42 @@ void ResTrack_Dx12::hkClose(ID3D12GraphicsCommandList* This) } } - if (!fg->UpscalerInputsReady()) + if (!fg->VelocityReady()) { - if (This == _inputsCommandList[index]) + if (This == _mvsCommandList[index]) { - LOG_DEBUG("Upscaler CmdList: {:X}", (size_t) This); + LOG_DEBUG("Velocity CmdList: {:X}", (size_t) This); fg->SetVelocityReady(); + + _mvsCmdList = _mvsCommandList[index]; + _mvsCommandList[index] = nullptr; + } + } + + if (!fg->DepthReady()) + { + if (This == _depthCommandList[index]) + { + LOG_DEBUG("Depth CmdList: {:X}", (size_t) This); + fg->SetDepthReady(); - // Technically we don't check if UI wasn't ready but it should be fine + _depthCmdList = _depthCommandList[index]; + _depthCommandList[index] = nullptr; + } + } + + if (!fg->UIReady()) + { + if (This == _uiCommandList[index]) + { + LOG_DEBUG("UI CmdList: {:X}", (size_t) This); + fg->SetUIReady(); - _inputsCmdList = _inputsCommandList[index]; - _inputsCommandList[index] = nullptr; + _uiCmdList = _uiCommandList[index]; + _uiCommandList[index] = nullptr; } } } @@ -1816,17 +1867,41 @@ void ResTrack_Dx12::ClearPossibleHudless() fgPossibleHudless[fIndex].clear(); _hudlessCmdList = nullptr; - _inputsCmdList = nullptr; + _depthCmdList = nullptr; + _mvsCmdList = nullptr; + _uiCmdList = nullptr; } -void ResTrack_Dx12::SetInputsCmdList(ID3D12GraphicsCommandList* cmdList) +void ResTrack_Dx12::SetDepthCmdList(ID3D12GraphicsCommandList* cmdList) { auto fg = State::Instance().currentFG; if (fg != nullptr && fg->IsActive()) { auto index = fg->FrameCount() % BUFFER_COUNT; LOG_DEBUG("cmdList[{}]: {:X}", index, (size_t) cmdList); - _inputsCommandList[index] = cmdList; + _depthCommandList[index] = cmdList; + } +} + +void ResTrack_Dx12::SetMVsCmdList(ID3D12GraphicsCommandList* cmdList) +{ + auto fg = State::Instance().currentFG; + if (fg != nullptr && fg->IsActive()) + { + auto index = fg->FrameCount() % BUFFER_COUNT; + LOG_DEBUG("cmdList[{}]: {:X}", index, (size_t) cmdList); + _mvsCommandList[index] = cmdList; + } +} + +void ResTrack_Dx12::SetUICmdList(ID3D12GraphicsCommandList* cmdList) +{ + auto fg = State::Instance().currentFG; + if (fg != nullptr && fg->IsActive()) + { + auto index = fg->FrameCount() % BUFFER_COUNT; + LOG_DEBUG("cmdList[{}]: {:X}", index, (size_t) cmdList); + _uiCommandList[index] = cmdList; } } diff --git a/OptiScaler/resource_tracking/ResTrack_dx12.h b/OptiScaler/resource_tracking/ResTrack_dx12.h index a4931455..58e2e1b4 100644 --- a/OptiScaler/resource_tracking/ResTrack_dx12.h +++ b/OptiScaler/resource_tracking/ResTrack_dx12.h @@ -238,7 +238,9 @@ class ResTrack_Dx12 inline static std::mutex _drawMutex; inline static ID3D12GraphicsCommandList* _hudlessCommandList[BUFFER_COUNT] = { nullptr, nullptr, nullptr, nullptr }; - inline static ID3D12GraphicsCommandList* _inputsCommandList[BUFFER_COUNT] = { nullptr, nullptr, nullptr, nullptr }; + inline static ID3D12GraphicsCommandList* _depthCommandList[BUFFER_COUNT] = { nullptr, nullptr, nullptr, nullptr }; + inline static ID3D12GraphicsCommandList* _mvsCommandList[BUFFER_COUNT] = { nullptr, nullptr, nullptr, nullptr }; + inline static ID3D12GraphicsCommandList* _uiCommandList[BUFFER_COUNT] = { nullptr, nullptr, nullptr, nullptr }; inline static ULONG64 _lastHudlessFrame = 0; inline static std::mutex _hudlessMutex; @@ -326,6 +328,8 @@ class ResTrack_Dx12 public: static void HookDevice(ID3D12Device* device); static void ClearPossibleHudless(); - static void SetInputsCmdList(ID3D12GraphicsCommandList* cmdList); + static void SetDepthCmdList(ID3D12GraphicsCommandList* cmdList); + static void SetMVsCmdList(ID3D12GraphicsCommandList* cmdList); + static void SetUICmdList(ID3D12GraphicsCommandList* cmdList); static void SetHudlessCmdList(ID3D12GraphicsCommandList* cmdList); };