mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-29 21:13:14 +00:00
Fixes for hungs/crashes
This commit is contained in:
@@ -353,8 +353,6 @@ public:
|
||||
CustomOptional<bool> FGHudfixFullSync{ false };
|
||||
CustomOptional<bool> FGHudfixTrackRelease{ false };
|
||||
CustomOptional<int> FGHudfixCBVTrackMode{ 0 }; // 0 off, 1 after upscaler, 2 full
|
||||
//CustomOptional<bool> FGUseCommandQueue{ true };
|
||||
|
||||
|
||||
// DLSS Enabler
|
||||
std::optional<int> DE_FramerateLimit; // off - vsync - number
|
||||
|
||||
@@ -76,7 +76,8 @@ bool IFGFeature_Dx12::CopyResource(ID3D12GraphicsCommandList* cmdList, ID3D12Res
|
||||
void IFGFeature_Dx12::WaitForFenceValue(ID3D12Fence* fence, UINT64 targetValue, HANDLE fenceEvent)
|
||||
{
|
||||
// Check if the fence has already been reached
|
||||
if (fence->GetCompletedValue() < targetValue)
|
||||
auto fenceValue = fence->GetCompletedValue();
|
||||
if (fenceValue < targetValue)
|
||||
{
|
||||
// Instruct the fence to signal the event when the target value is reached
|
||||
HRESULT hr = fence->SetEventOnCompletion(targetValue, fenceEvent);
|
||||
@@ -254,7 +255,7 @@ void IFGFeature_Dx12::CreateObjects(ID3D12Device* InDevice)
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
queueDesc.NodeMask = 0;
|
||||
queueDesc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_HIGH;
|
||||
queueDesc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
|
||||
|
||||
HRESULT hr = InDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&queue));
|
||||
if (result != S_OK)
|
||||
|
||||
@@ -259,22 +259,27 @@ bool FSRFG_Dx12::DispatchHudless(bool useHudless, double frameTime)
|
||||
{
|
||||
LOG_DEBUG("useHudless: {}, frameTime: {}", useHudless, frameTime);
|
||||
|
||||
if (Config::Instance()->FGUseMutexForSwaphain.value_or_default() && Mutex.getOwner() != 2)
|
||||
{
|
||||
LOG_TRACE("Waiting FG->Mutex 1, current: {}", Mutex.getOwner());
|
||||
Mutex.lock(1);
|
||||
LOG_TRACE("Accuired FG->Mutex: {}", Mutex.getOwner());
|
||||
}
|
||||
|
||||
if (State::Instance().FSRFGFTPchanged)
|
||||
ConfigureFramePaceTuning();
|
||||
|
||||
//if (Config::Instance()->FGUseCommandQueue.value_or_default())
|
||||
//{
|
||||
if (_lastFgFenceValue > 0)
|
||||
WaitForFenceValue(_fgFence, _lastFgFenceValue, _fgFenceEvent);
|
||||
|
||||
if (_lastCopyFenceValue > 0)
|
||||
WaitForFenceValue(_copyFence, _lastCopyFenceValue, _copyFenceEvent);
|
||||
|
||||
if (_lastHudlessCopyFenceValue > 0)
|
||||
WaitForFenceValue(_hudlessCopyFence, _lastHudlessCopyFenceValue, _hudlessCopyFenceEvent);
|
||||
|
||||
if (useHudless)
|
||||
{
|
||||
if (_lastFgFenceValue > 0)
|
||||
WaitForFenceValue(_fgFence, _lastFgFenceValue, _fgFenceEvent);
|
||||
|
||||
if (_lastCopyFenceValue > 0)
|
||||
WaitForFenceValue(_copyFence, _lastCopyFenceValue, _copyFenceEvent);
|
||||
|
||||
if (_lastHudlessCopyFenceValue > 0)
|
||||
WaitForFenceValue(_hudlessCopyFence, _lastHudlessCopyFenceValue, _hudlessCopyFenceEvent);
|
||||
|
||||
// FG queue wait for copy operations
|
||||
LOG_DEBUG("FG Queue wait for copy, {}", _frameCount);
|
||||
_commandQueue->Wait(_copyFence, _frameCount);
|
||||
@@ -284,18 +289,12 @@ bool FSRFG_Dx12::DispatchHudless(bool useHudless, double frameTime)
|
||||
_commandQueue->Wait(_hudlessCopyFence, _frameCount);
|
||||
_lastHudlessCopyFenceValue = _frameCount;
|
||||
|
||||
LOG_DEBUG("Game Queue wait for FG, {}", _frameCount);
|
||||
_gameCommandQueue->Wait(_fgFence, _frameCount);
|
||||
_lastFgFenceValue = _frameCount;
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
if (Config::Instance()->FGUseMutexForSwaphain.value_or_default() && Mutex.getOwner() != 2)
|
||||
{
|
||||
LOG_TRACE("Waiting FG->Mutex 1, current: {}", Mutex.getOwner());
|
||||
Mutex.lock(1);
|
||||
LOG_TRACE("Accuired FG->Mutex: {}", Mutex.getOwner());
|
||||
if (State::Instance().currentCommandQueue != nullptr)
|
||||
{
|
||||
LOG_DEBUG("Game Queue wait for FG, {}", _frameCount);
|
||||
State::Instance().currentCommandQueue->Wait(_fgFence, _frameCount);
|
||||
_lastFgFenceValue = _frameCount;
|
||||
}
|
||||
}
|
||||
|
||||
// hudless captured for this frame
|
||||
@@ -361,15 +360,6 @@ bool FSRFG_Dx12::DispatchHudless(bool useHudless, double frameTime)
|
||||
return FFX_API_RETURN_ERROR;
|
||||
};
|
||||
|
||||
/*
|
||||
m_FrameGenerationConfig.presentCallbackUserContext = this;
|
||||
m_FrameGenerationConfig.presentCallback = [](ffxCallbackDescFrameGenerationPresent* params, void* pUserCtx)->ffxReturnCode_t
|
||||
{
|
||||
LOG_DEBUG("frameId: {}, isGenerated: {}", params->frameID, params->isGeneratedFrame);
|
||||
return FFX_API_RETURN_OK;
|
||||
};
|
||||
*/
|
||||
|
||||
m_FrameGenerationConfig.onlyPresentGenerated = State::Instance().FGonlyGenerated;
|
||||
m_FrameGenerationConfig.frameID = _frameCount;
|
||||
m_FrameGenerationConfig.swapChain = State::Instance().currentSwapchain;
|
||||
@@ -410,8 +400,6 @@ bool FSRFG_Dx12::DispatchHudless(bool useHudless, double frameTime)
|
||||
|
||||
retCode = FfxApiProxy::D3D12_Dispatch()(&_fgContext, &dfgPrepare.header);
|
||||
|
||||
//if (Config::Instance()->FGUseCommandQueue.value_or_default())
|
||||
//{
|
||||
auto result = _commandList[fIndex]->Close();
|
||||
LOG_DEBUG("_commandList[{}]->Close() result: {:X}", fIndex, (UINT)result);
|
||||
ID3D12CommandList* cl[] = { _commandList[fIndex] };
|
||||
@@ -423,31 +411,13 @@ bool FSRFG_Dx12::DispatchHudless(bool useHudless, double frameTime)
|
||||
_commandQueue->Signal(_fgFence, _frameCount);
|
||||
LOG_DEBUG("Execute and signal from FG Queue, {}", _frameCount);
|
||||
}
|
||||
else
|
||||
else if (State::Instance().currentCommandQueue != nullptr)
|
||||
{
|
||||
//Use game queue
|
||||
_gameCommandQueue->ExecuteCommandLists(1, cl);
|
||||
_gameCommandQueue->Signal(_fgFence, _frameCount);
|
||||
State::Instance().currentCommandQueue->ExecuteCommandLists(1, cl);
|
||||
State::Instance().currentCommandQueue->Signal(_fgFence, _frameCount);
|
||||
LOG_DEBUG("Execute from game queue!!");
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (!(useHudless && State::Instance().currentCommandQueue != nullptr) &&
|
||||
// !Config::Instance()->FGHudFixCloseAfterCallback.value_or_default())
|
||||
// {
|
||||
// auto result = _commandList[fIndex]->Close();
|
||||
// LOG_DEBUG("_commandList[{}]->Close() result: {:X}", fIndex, (UINT)result);
|
||||
|
||||
// if (result == S_OK)
|
||||
// {
|
||||
// ID3D12CommandList* cl[] = { _commandList[fIndex] };
|
||||
// // Use game queue
|
||||
// _gameCommandQueue->ExecuteCommandLists(1, cl);
|
||||
// LOG_DEBUG("Execute from game queue!!");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
LOG_DEBUG("D3D12_Dispatch result: {0}, frame: {1}, fIndex: {2}, commandList: {3:X}", retCode, _frameCount, fIndex, (size_t)dfgPrepare.commandList);
|
||||
}
|
||||
@@ -523,29 +493,6 @@ ffxReturnCode_t FSRFG_Dx12::HudlessDispatchCallback(ffxDispatchDescFrameGenerati
|
||||
|
||||
LOG_DEBUG("frameID: {}, commandList: {:X}, numGeneratedFrames: {}", params->frameID, (size_t)params->commandList, params->numGeneratedFrames);
|
||||
|
||||
//if (!Config::Instance()->FGUseCommandQueue.value_or_default() &&
|
||||
// params->frameID != _lastUpscaledFrameId && Config::Instance()->FGHudFixCloseAfterCallback.value_or_default())
|
||||
//{
|
||||
// result = _commandList[fIndex]->Close();
|
||||
// LOG_DEBUG("fgCommandList[{}]->Close() result: {:X}", fIndex, (UINT)result);
|
||||
|
||||
// // if there is command list error return ERROR
|
||||
// if (result == S_OK)
|
||||
// {
|
||||
// ID3D12CommandList* cl[1] = { nullptr };
|
||||
// cl[0] = _commandList[fIndex];
|
||||
// _gameCommandQueue->ExecuteCommandLists(1, cl);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return FFX_API_RETURN_ERROR;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// LOG_DEBUG("skipped close? frame id: {}", params->frameID);
|
||||
//}
|
||||
|
||||
// check for status
|
||||
if (!Config::Instance()->FGEnabled.value_or_default() || !Config::Instance()->FGHUDFix.value_or_default() ||
|
||||
_fgContext == nullptr || _commandQueue == nullptr || State::Instance().SCchanged)
|
||||
@@ -643,6 +590,10 @@ void FSRFG_Dx12::StopAndDestroyContext(bool destroy, bool shutDown, bool useMute
|
||||
WaitForFenceValue(_fgFence, _lastFgFenceValue, _fgFenceEvent);
|
||||
}
|
||||
|
||||
_lastCopyFenceValue = 0;
|
||||
_lastHudlessCopyFenceValue = 0;
|
||||
_lastFgFenceValue = 0;
|
||||
|
||||
if (!(shutDown || State::Instance().isShuttingDown) && _fgContext != nullptr)
|
||||
{
|
||||
ffxConfigureDescFrameGeneration m_FrameGenerationConfig = {};
|
||||
|
||||
@@ -706,6 +706,8 @@ void Hudfix_Dx12::ResetCounters()
|
||||
_upscaleEndTime = 0.0;
|
||||
_targetTime = 0.0;
|
||||
_frameTime = 0.0;
|
||||
|
||||
|
||||
_hudlessList.clear();
|
||||
|
||||
LOG_DEBUG("_hudlessList: {}", _hudlessList.size());
|
||||
}
|
||||
|
||||
@@ -1623,7 +1623,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom
|
||||
info.flags = desc.Flags;
|
||||
info.type = UAV;
|
||||
|
||||
Hudfix_Dx12::CheckForHudless(__FUNCTION__, InCmdList, &info, (D3D12_RESOURCE_STATES)Config::Instance()->OutputResourceBarrier.value_or(D3D12_RESOURCE_STATE_UNORDERED_ACCESS));
|
||||
if (Hudfix_Dx12::CheckForHudless(__FUNCTION__, InCmdList, &info, (D3D12_RESOURCE_STATES)Config::Instance()->OutputResourceBarrier.value_or(D3D12_RESOURCE_STATE_UNORDERED_ACCESS)))
|
||||
ResTrack_Dx12::SetHudlessCmdList(InCmdList);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -786,7 +786,7 @@ void ResTrack_Dx12::hkCreateRenderTargetView(ID3D12Device* This, ID3D12Resource*
|
||||
RemoveResourceHeap(temp->buffer, DestDescriptor.ptr);
|
||||
}
|
||||
#else
|
||||
pResource->SetPrivateData(GUID_Tracking, 4, &_trackMark);
|
||||
//pResource->SetPrivateData(GUID_Tracking, 4, &_trackMark);
|
||||
#endif
|
||||
|
||||
heap->SetByCpuHandle(DestDescriptor.ptr, resInfo);
|
||||
@@ -875,7 +875,7 @@ void ResTrack_Dx12::hkCreateShaderResourceView(ID3D12Device* This, ID3D12Resourc
|
||||
RemoveResourceHeap(temp->buffer, DestDescriptor.ptr);
|
||||
}
|
||||
#else
|
||||
pResource->SetPrivateData(GUID_Tracking, 4, &_trackMark);
|
||||
//pResource->SetPrivateData(GUID_Tracking, 4, &_trackMark);
|
||||
#endif
|
||||
|
||||
heap->SetByCpuHandle(DestDescriptor.ptr, resInfo);
|
||||
@@ -963,7 +963,7 @@ void ResTrack_Dx12::hkCreateUnorderedAccessView(ID3D12Device* This, ID3D12Resour
|
||||
RemoveResourceHeap(temp->buffer, DestDescriptor.ptr);
|
||||
}
|
||||
#else
|
||||
pResource->SetPrivateData(GUID_Tracking, 4, &_trackMark);
|
||||
//pResource->SetPrivateData(GUID_Tracking, 4, &_trackMark);
|
||||
#endif
|
||||
|
||||
heap->SetByCpuHandle(DestDescriptor.ptr, resInfo);
|
||||
@@ -2263,3 +2263,9 @@ void ResTrack_Dx12::SetUpscalerCmdList(ID3D12GraphicsCommandList* cmdList)
|
||||
_upscalerCommandList = cmdList;
|
||||
}
|
||||
|
||||
void ResTrack_Dx12::SetHudlessCmdList(ID3D12GraphicsCommandList* cmdList)
|
||||
{
|
||||
LOG_DEBUG("cmdList: {:X}", (size_t)cmdList);
|
||||
_commandList = cmdList;
|
||||
}
|
||||
|
||||
|
||||
@@ -355,4 +355,5 @@ public:
|
||||
static void ClearPossibleHudless();
|
||||
static void PresentDone();
|
||||
static void SetUpscalerCmdList(ID3D12GraphicsCommandList* cmdList);
|
||||
static void SetHudlessCmdList(ID3D12GraphicsCommandList* cmdList);
|
||||
};
|
||||
Reference in New Issue
Block a user