Better handling of UI Commandlist

This commit is contained in:
cdozdil
2025-09-24 23:36:10 +03:00
parent 3af32a20b6
commit 18bd2dfbab
7 changed files with 81 additions and 154 deletions
+6 -6
View File
@@ -379,11 +379,6 @@ class Config
// OptiFG
CustomOptional<bool> FGEnabled { false };
CustomOptional<bool> FGDebugView { false };
CustomOptional<bool> FGDebugResetLines { false };
CustomOptional<bool> FGDebugTearLines { false };
CustomOptional<bool> FGDebugPacingLines { false };
CustomOptional<bool> FGAsync { false };
CustomOptional<bool> FGUseMutexForSwapchain { true };
CustomOptional<bool> FGMakeMVCopy { true };
CustomOptional<bool> FGMakeDepthCopy { true };
@@ -411,7 +406,12 @@ class Config
CustomOptional<bool> FGEnableDepthScale { false };
CustomOptional<float> FGDepthScaleMax { 10000.0f };
// OptiFG - FSR-FG FPT
// FSR-FG
CustomOptional<bool> FGDebugView { false };
CustomOptional<bool> FGDebugResetLines { false };
CustomOptional<bool> FGDebugTearLines { false };
CustomOptional<bool> FGDebugPacingLines { false };
CustomOptional<bool> FGAsync { false };
CustomOptional<bool> FGFramePacingTuning { true };
CustomOptional<float> FGFPTSafetyMarginInMs { 0.01f };
CustomOptional<float> FGFPTVarianceFactor { 0.3f };
+53
View File
@@ -38,6 +38,59 @@ bool IFGFeature_Dx12::GetResourceCopy(FG_ResourceType type, D3D12_RESOURCE_STATE
ID3D12CommandQueue* IFGFeature_Dx12::GetCommandQueue() { return _gameCommandQueue; }
ID3D12GraphicsCommandList* IFGFeature_Dx12::GetUICommandList(int index)
{
if (index < 0)
index = GetIndex();
LOG_DEBUG("index: {}", index);
if (_uiCommandAllocator[0] == nullptr)
{
if (_device != nullptr)
CreateObjects(_device);
else if (State::Instance().currentD3D12Device != nullptr)
CreateObjects(State::Instance().currentD3D12Device);
else
return nullptr;
}
for (size_t i = 0; i < BUFFER_COUNT; i++)
{
if (i != index && _uiCommandListResetted[i])
{
LOG_DEBUG("Executing _uiCommandList[{}]: {:X}", i, (size_t) _uiCommandList[i]);
auto closeResult = _uiCommandList[i]->Close();
if (closeResult != S_OK)
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", i, (UINT) closeResult);
_uiCommandListResetted[i] = false;
}
}
if (!_uiCommandListResetted[index])
{
auto result = _uiCommandAllocator[index]->Reset();
if (result == S_OK)
{
result = _uiCommandList[index]->Reset(_uiCommandAllocator[index], nullptr);
if (result == S_OK)
_uiCommandListResetted[index] = true;
else
LOG_ERROR("_uiCommandList[{}]->Reset() error: {:X}", index, (UINT) result);
}
else
{
LOG_ERROR("_uiCommandAllocator[{}]->Reset() error: {:X}", index, (UINT) result);
}
}
return _uiCommandList[index];
}
Dx12Resource* IFGFeature_Dx12::GetResource(FG_ResourceType type, int index)
{
std::lock_guard<std::mutex> lock(_frMutex);
+2 -1
View File
@@ -90,7 +90,8 @@ class IFGFeature_Dx12 : public virtual IFGFeature
virtual void SetResource(Dx12Resource* inputResource) = 0;
virtual void SetCommandQueue(FG_ResourceType type, ID3D12CommandQueue* queue) = 0;
virtual ID3D12GraphicsCommandList* GetUICommandList(int index = -1) = 0;
ID3D12GraphicsCommandList* GetUICommandList(int index = -1);
Dx12Resource* GetResource(FG_ResourceType type, int index = -1);
bool GetResourceCopy(FG_ResourceType type, D3D12_RESOURCE_STATES bufferState, ID3D12Resource* output);
+9 -72
View File
@@ -916,66 +916,6 @@ void FSRFG_Dx12::SetResourceReady(FG_ResourceType type) { _resourceReady[GetInde
void FSRFG_Dx12::SetCommandQueue(FG_ResourceType type, ID3D12CommandQueue* queue) { _gameCommandQueue = queue; }
ID3D12GraphicsCommandList* FSRFG_Dx12::GetUICommandList(int index)
{
if (index < 0)
index = GetIndex();
LOG_DEBUG("index: {}", index);
if (_uiCommandAllocator[0] == nullptr)
{
if (_device != nullptr)
CreateObjects(_device);
else if (State::Instance().currentD3D12Device != nullptr)
CreateObjects(State::Instance().currentD3D12Device);
else
return nullptr;
}
if (Config::Instance()->FGEnabled.value_or_default())
{
for (size_t i = 0; i < BUFFER_COUNT; i++)
{
if (i != index && _uiCommandListResetted[i])
{
LOG_DEBUG("Executing _uiCommandList[{}]: {:X}", i, (size_t) _uiCommandList[i]);
auto closeResult = _uiCommandList[i]->Close();
if (closeResult == S_OK)
_gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[i]);
else
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", i, (UINT) closeResult);
_uiCommandListResetted[i] = false;
}
}
if (!_uiCommandListResetted[index])
{
_uiCommandListResetted[index] = true;
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);
}
LOG_DEBUG("_uiCommandList[{}]->Reset()", index);
}
}
return _uiCommandList[index];
}
void FSRFG_Dx12::CreateObjects(ID3D12Device* InDevice)
{
_device = InDevice;
@@ -1081,21 +1021,18 @@ bool FSRFG_Dx12::Present()
}
}
if (Config::Instance()->FGEnabled.value_or_default())
auto fIndex = GetIndex();
if (_uiCommandListResetted[fIndex])
{
auto fIndex = GetIndex();
if (_uiCommandListResetted[fIndex])
{
LOG_DEBUG("Executing _uiCommandList[fIndex][{}]: {:X}", fIndex, (size_t) _uiCommandList[fIndex]);
auto closeResult = _uiCommandList[fIndex]->Close();
LOG_DEBUG("Executing _uiCommandList[fIndex][{}]: {:X}", fIndex, (size_t) _uiCommandList[fIndex]);
auto closeResult = _uiCommandList[fIndex]->Close();
if (closeResult == S_OK)
_gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[fIndex]);
else
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", fIndex, (UINT) closeResult);
if (closeResult == S_OK)
_gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[fIndex]);
else
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", fIndex, (UINT) closeResult);
_uiCommandListResetted[fIndex] = false;
}
_uiCommandListResetted[fIndex] = false;
}
if (_lastDispatchedFrame == _frameCount)
-2
View File
@@ -90,8 +90,6 @@ class FSRFG_Dx12 : public virtual IFGFeature_Dx12
void SetResourceReady(FG_ResourceType type) override final;
void SetCommandQueue(FG_ResourceType type, ID3D12CommandQueue* queue) override final;
ID3D12GraphicsCommandList* GetUICommandList(int index = -1) override final;
ffxReturnCode_t DispatchCallback(ffxDispatchDescFrameGeneration* params);
FSRFG_Dx12() : IFGFeature_Dx12(), IFGFeature()
{
+11 -71
View File
@@ -649,6 +649,7 @@ void XeFG_Dx12::EvaluateState(ID3D12Device* device, FG_Constants& fgConstants)
// If there is a change deactivate it
else if (State::Instance().FGchanged)
{
LOG_DEBUG("FGChanged");
Deactivate();
// Pause for 10 frames
@@ -664,6 +665,7 @@ void XeFG_Dx12::EvaluateState(ID3D12Device* device, FG_Constants& fgConstants)
}
else
{
LOG_DEBUG("!FGEnabled");
Deactivate();
State::Instance().ClearCapturedHudlesses = true;
@@ -768,22 +770,18 @@ bool XeFG_Dx12::Present()
}
}
if (Config::Instance()->FGEnabled.value_or_default())
auto fIndex = GetIndex();
if (_uiCommandListResetted[fIndex])
{
auto fIndex = GetIndex();
if (_uiCommandListResetted[fIndex])
{
LOG_DEBUG("Executing _uiCommandList[{}]: {:X}", fIndex, (size_t) _uiCommandList[fIndex]);
auto closeResult = _uiCommandList[fIndex]->Close();
LOG_DEBUG("Executing _uiCommandList[{}]: {:X}", fIndex, (size_t) _uiCommandList[fIndex]);
auto closeResult = _uiCommandList[fIndex]->Close();
if (closeResult == S_OK)
_gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[fIndex]);
else
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", fIndex, (UINT) closeResult);
if (closeResult != S_OK)
_gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[fIndex]);
else
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", fIndex, (UINT) closeResult);
_uiCommandListResetted[fIndex] = false;
}
_uiCommandListResetted[fIndex] = false;
}
if (_lastDispatchedFrame == _frameCount)
@@ -955,64 +953,6 @@ void XeFG_Dx12::SetResourceReady(FG_ResourceType type) { _resourceReady[GetIndex
void XeFG_Dx12::SetCommandQueue(FG_ResourceType type, ID3D12CommandQueue* queue) { _gameCommandQueue = queue; }
ID3D12GraphicsCommandList* XeFG_Dx12::GetUICommandList(int index)
{
if (index < 0)
index = GetIndex();
LOG_DEBUG("index: {}", index);
if (_uiCommandAllocator[0] == nullptr)
{
if (_device != nullptr)
CreateObjects(_device);
else if (State::Instance().currentD3D12Device != nullptr)
CreateObjects(State::Instance().currentD3D12Device);
else
return nullptr;
}
if (Config::Instance()->FGEnabled.value_or_default())
{
for (size_t i = 0; i < BUFFER_COUNT; i++)
{
if (i != index && _uiCommandListResetted[i])
{
LOG_DEBUG("Executing _uiCommandList[{}]: {:X}", i, (size_t) _uiCommandList[i]);
auto closeResult = _uiCommandList[i]->Close();
if (closeResult == S_OK)
_gameCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList**) &_uiCommandList[i]);
else
LOG_ERROR("_uiCommandList[{}]->Close() error: {:X}", i, (UINT) closeResult);
_uiCommandListResetted[i] = false;
}
}
if (!_uiCommandListResetted[index])
{
_uiCommandListResetted[index] = true;
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];
}
bool XeFG_Dx12::ReleaseSwapchain(HWND hwnd)
{
if (hwnd != _hwnd || _hwnd == NULL)
-2
View File
@@ -63,8 +63,6 @@ class XeFG_Dx12 : public virtual IFGFeature_Dx12
void SetResourceReady(FG_ResourceType type) override final;
void SetCommandQueue(FG_ResourceType type, ID3D12CommandQueue* queue) override final;
ID3D12GraphicsCommandList* GetUICommandList(int index = -1) override final;
void* FrameGenerationContext() override final;
void* SwapchainContext() override final;