mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-05-04 08:41:43 +00:00
Hudfix improvements and fixes
This commit is contained in:
@@ -85,7 +85,7 @@ inline static bool CompareResourceFormats(DXGI_FORMAT sc, DXGI_FORMAT hudless)
|
||||
bool Hudfix_Dx12::CreateObjects()
|
||||
{
|
||||
if (_commandQueue != nullptr)
|
||||
return false;
|
||||
return true;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -154,7 +154,7 @@ bool Hudfix_Dx12::CreateObjects()
|
||||
bool Hudfix_Dx12::CreateBufferResource(ID3D12Device* InDevice, ResourceInfo* InSource, D3D12_RESOURCE_STATES InState,
|
||||
ID3D12Resource** OutResource)
|
||||
{
|
||||
if (InDevice == nullptr || InSource == nullptr)
|
||||
if (InDevice == nullptr || InSource == nullptr || InSource->buffer == nullptr)
|
||||
return false;
|
||||
|
||||
if (*OutResource != nullptr)
|
||||
@@ -271,22 +271,21 @@ bool Hudfix_Dx12::CheckCapture()
|
||||
{
|
||||
auto fIndex = GetIndex();
|
||||
|
||||
// early exit
|
||||
if (_captureCounter[fIndex] > 999)
|
||||
{
|
||||
LOG_DEBUG("_captureCounter[{}] > 999", fIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_counterMutex);
|
||||
|
||||
if (_captureCounter[fIndex] > 999)
|
||||
{
|
||||
LOG_DEBUG("_captureCounter[{}] > 999", fIndex);
|
||||
return false;
|
||||
}
|
||||
|
||||
_captureCounter[fIndex]++;
|
||||
|
||||
LOG_TRACE("frameCounter: {}, _captureCounter: {}, Limit: {}", State::Instance().currentFeature->FrameCount(),
|
||||
_captureCounter[fIndex], Config::Instance()->FGHUDLimit.value_or_default());
|
||||
|
||||
if (_captureCounter[fIndex] > 999 ||
|
||||
_captureCounter[fIndex] != Config::Instance()->FGHUDLimit.value_or_default())
|
||||
if (_captureCounter[fIndex] > Config::Instance()->FGHUDLimit.value_or_default())
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -342,7 +341,7 @@ bool Hudfix_Dx12::CheckResource(ResourceInfo* resource)
|
||||
if (State::Instance().FGonlyUseCapturedResources)
|
||||
{
|
||||
auto result = _captureList.find(resource->buffer) != _captureList.end();
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
|
||||
auto& s = State::Instance();
|
||||
@@ -421,19 +420,6 @@ bool Hudfix_Dx12::CheckResource(ResourceInfo* resource)
|
||||
return false;
|
||||
}
|
||||
|
||||
// resource format is one of supported formats
|
||||
// if (resDesc.Format == DXGI_FORMAT_R32G32B32A32_TYPELESS || resDesc.Format == DXGI_FORMAT_R32G32B32A32_FLOAT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R32G32B32A32_UINT || resDesc.Format == DXGI_FORMAT_R32G32B32A32_SINT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R32G32B32_TYPELESS || resDesc.Format == DXGI_FORMAT_R32G32B32_FLOAT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R32G32B32_UINT || resDesc.Format == DXGI_FORMAT_R32G32B32_SINT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R16G16B16A16_TYPELESS || resDesc.Format == DXGI_FORMAT_R16G16B16A16_FLOAT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R16G16B16A16_UNORM || resDesc.Format == DXGI_FORMAT_R16G16B16A16_UINT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R16G16B16A16_SNORM || resDesc.Format == DXGI_FORMAT_R16G16B16A16_SINT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R10G10B10A2_TYPELESS || resDesc.Format == DXGI_FORMAT_R10G10B10A2_UNORM ||
|
||||
// resDesc.Format == DXGI_FORMAT_R10G10B10A2_UINT || resDesc.Format == DXGI_FORMAT_R11G11B10_FLOAT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R8G8B8A8_TYPELESS || resDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM ||
|
||||
// resDesc.Format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB || resDesc.Format == DXGI_FORMAT_R8G8B8A8_UINT ||
|
||||
// resDesc.Format == DXGI_FORMAT_R8G8B8A8_SNORM || resDesc.Format == DXGI_FORMAT_R8G8B8A8_SINT)
|
||||
{
|
||||
LOG_DEBUG("{}->{} Width: {}/{}, Height: {}/{}, Format: {}/{}, Resource: {:X}, convertFormat: {} -> TRUE",
|
||||
GetSourceString(source), GetDispatchString(dispatcher), resDesc.Width, width, resDesc.Height, height,
|
||||
@@ -463,7 +449,7 @@ void Hudfix_Dx12::HudlessFound(ID3D12GraphicsCommandList* cmdList)
|
||||
if (_captureCounter[index] > 1000)
|
||||
return;
|
||||
|
||||
// Set it above 1000 to prvent capture
|
||||
// Set it above 1000 to prevent capture
|
||||
_captureCounter[index] = 9999;
|
||||
|
||||
// Increase counter
|
||||
@@ -503,7 +489,6 @@ void Hudfix_Dx12::UpscaleStart()
|
||||
std::lock_guard<std::mutex> lock(_captureMutex);
|
||||
_captureList.clear();
|
||||
LOG_DEBUG("FGResetCapturedResources");
|
||||
State::Instance().FGresetCapturedResources = false;
|
||||
State::Instance().FGcapturedResourceCount = 0;
|
||||
State::Instance().FGresetCapturedResources = false;
|
||||
}
|
||||
@@ -525,13 +510,10 @@ void Hudfix_Dx12::UpscaleEnd(UINT64 frameId, double lastFGFrameTime)
|
||||
// Get new index and clear resources
|
||||
auto index = GetIndex();
|
||||
_captureCounter[index] = 0;
|
||||
_skipHudlessChecks = false;
|
||||
}
|
||||
|
||||
void Hudfix_Dx12::PresentStart()
|
||||
{
|
||||
_fgCounter = _upscaleCounter;
|
||||
return;
|
||||
}
|
||||
void Hudfix_Dx12::PresentStart() { _fgCounter = _upscaleCounter; }
|
||||
|
||||
void Hudfix_Dx12::PresentEnd() { LOG_DEBUG(""); }
|
||||
|
||||
@@ -578,13 +560,6 @@ bool Hudfix_Dx12::IsResourceCheckActive()
|
||||
return false;
|
||||
}
|
||||
|
||||
auto fg = reinterpret_cast<IFGFeature_Dx12*>(State::Instance().currentFG);
|
||||
if (fg == nullptr)
|
||||
{
|
||||
// LOG_TRACK("fg == nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -609,7 +584,9 @@ bool Hudfix_Dx12::CheckForHudless(ID3D12GraphicsCommandList* cmdList, ResourceIn
|
||||
break;
|
||||
}
|
||||
|
||||
CapturedHudlessInfo* capturedHudlessInfo = &s.CapturedHudlesses[resource->buffer];
|
||||
auto hudlessIt = s.CapturedHudlesses.find(resource->buffer);
|
||||
CapturedHudlessInfo* capturedHudlessInfo =
|
||||
(hudlessIt != s.CapturedHudlesses.end()) ? &hudlessIt->second : nullptr;
|
||||
if (capturedHudlessInfo != nullptr && !capturedHudlessInfo->enabled)
|
||||
{
|
||||
LOG_DEBUG("Skipping {:X}, disabled from captured hudless list!", (size_t) resource->buffer);
|
||||
@@ -933,7 +910,9 @@ bool Hudfix_Dx12::CheckForHudless(ID3D12GraphicsCommandList* cmdList, ResourceIn
|
||||
HudlessFound(cmdList);
|
||||
|
||||
if (capturedHudlessInfo != nullptr)
|
||||
{
|
||||
capturedHudlessInfo->usageCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.CapturedHudlesses[resource->buffer] = {};
|
||||
|
||||
@@ -4101,7 +4101,6 @@ bool MenuCommon::RenderMenu()
|
||||
{
|
||||
state.FGresetCapturedResources = true;
|
||||
state.FGonlyUseCapturedResources = false;
|
||||
state.FGonlyUseCapturedResources = false;
|
||||
}
|
||||
|
||||
ImGui::EndDisabled();
|
||||
|
||||
@@ -203,7 +203,7 @@ bool ResTrack_Dx12::CheckForRealObject(const std::string functionName, IUnknown*
|
||||
bool ResTrack_Dx12::CreateBufferResource(ID3D12Device* InDevice, ResourceInfo* InSource, D3D12_RESOURCE_STATES InState,
|
||||
ID3D12Resource** OutResource)
|
||||
{
|
||||
if (InDevice == nullptr || InSource == nullptr)
|
||||
if (InDevice == nullptr || InSource == nullptr || InSource->buffer == nullptr)
|
||||
return false;
|
||||
|
||||
if (*OutResource != nullptr)
|
||||
@@ -249,6 +249,9 @@ bool ResTrack_Dx12::CreateBufferResource(ID3D12Device* InDevice, ResourceInfo* I
|
||||
void ResTrack_Dx12::ResourceBarrier(ID3D12GraphicsCommandList* InCommandList, ID3D12Resource* InResource,
|
||||
D3D12_RESOURCE_STATES InBeforeState, D3D12_RESOURCE_STATES InAfterState)
|
||||
{
|
||||
if (InBeforeState == InAfterState)
|
||||
return;
|
||||
|
||||
D3D12_RESOURCE_BARRIER barrier = {};
|
||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier.Transition.pResource = InResource;
|
||||
@@ -944,7 +947,7 @@ HRESULT ResTrack_Dx12::hkCreateDescriptorHeap(ID3D12Device* This, D3D12_DESCRIPT
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*ppvHeap != nullptr)
|
||||
if (ppvHeap != nullptr && *ppvHeap != nullptr)
|
||||
{
|
||||
auto heap = (ID3D12DescriptorHeap*) (*ppvHeap);
|
||||
LOG_TRACE("Skipping, Heap type: {}, Cpu: {}, Gpu: {}", (UINT) pDescriptorHeapDesc->Type,
|
||||
@@ -1267,7 +1270,6 @@ void ResTrack_Dx12::hkOMSetRenderTargets(ID3D12GraphicsCommandList* This, UINT N
|
||||
LOG_DEBUG_ONLY("NumRenderTargetDescriptors: {}", NumRenderTargetDescriptors);
|
||||
|
||||
auto fIndex = Hudfix_Dx12::ActivePresentFrame() % BUFFER_COUNT;
|
||||
bool anyResourceTracked = false;
|
||||
|
||||
// Process render targets
|
||||
for (size_t i = 0; i < NumRenderTargetDescriptors; i++)
|
||||
@@ -1334,7 +1336,6 @@ void ResTrack_Dx12::hkOMSetRenderTargets(ID3D12GraphicsCommandList* This, UINT N
|
||||
|
||||
LOG_TRACK("Tracking Resource: {:X}, Desc: {:X}", (size_t) capturedBuffer->buffer, handle.ptr);
|
||||
fgPossibleHudless[fIndex][This].insert_or_assign(capturedBuffer->buffer, *capturedBuffer);
|
||||
anyResourceTracked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1358,7 +1359,6 @@ void ResTrack_Dx12::hkOMSetRenderTargets(ID3D12GraphicsCommandList* This, UINT N
|
||||
(size_t) capturedBuffer->buffer, handle.ptr, (UINT) capturedBuffer->format);
|
||||
|
||||
shard.map[This].insert_or_assign(capturedBuffer->buffer, *capturedBuffer);
|
||||
anyResourceTracked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1494,14 +1494,11 @@ void ResTrack_Dx12::hkDrawInstanced(ID3D12GraphicsCommandList* This, UINT Vertex
|
||||
return;
|
||||
}
|
||||
|
||||
if (fgPossibleHudless[fIndex].size() == 0)
|
||||
return;
|
||||
|
||||
ankerl::unordered_dense::map<ID3D12Resource*, ResourceInfo> val0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_hudlessTrackMutex);
|
||||
|
||||
if (!fgPossibleHudless[fIndex].contains(This))
|
||||
if (fgPossibleHudless[fIndex].size() == 0 || !fgPossibleHudless[fIndex].contains(This))
|
||||
return;
|
||||
|
||||
val0 = std::move(fgPossibleHudless[fIndex][This]);
|
||||
@@ -1517,10 +1514,9 @@ void ResTrack_Dx12::hkDrawInstanced(ID3D12GraphicsCommandList* This, UINT Vertex
|
||||
if (Config::Instance()->FGHudfixDisableDI.value_or_default())
|
||||
break;
|
||||
|
||||
std::lock_guard<std::mutex> lock(_drawMutex);
|
||||
for (auto& [key, val] : val0)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_drawMutex);
|
||||
|
||||
val.captureInfo |= CaptureInfo::DrawInstanced;
|
||||
|
||||
if (Hudfix_Dx12::CheckForHudless(This, &val, val.state))
|
||||
@@ -1618,14 +1614,11 @@ void ResTrack_Dx12::hkDrawIndexedInstanced(ID3D12GraphicsCommandList* This, UINT
|
||||
return;
|
||||
}
|
||||
|
||||
if (fgPossibleHudless[fIndex].size() == 0)
|
||||
return;
|
||||
|
||||
ankerl::unordered_dense::map<ID3D12Resource*, ResourceInfo> val0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_hudlessTrackMutex);
|
||||
|
||||
if (!fgPossibleHudless[fIndex].contains(This))
|
||||
if (fgPossibleHudless[fIndex].size() == 0 || !fgPossibleHudless[fIndex].contains(This))
|
||||
return;
|
||||
|
||||
val0 = std::move(fgPossibleHudless[fIndex][This]);
|
||||
@@ -1641,11 +1634,9 @@ void ResTrack_Dx12::hkDrawIndexedInstanced(ID3D12GraphicsCommandList* This, UINT
|
||||
if (Config::Instance()->FGHudfixDisableDII.value_or_default())
|
||||
break;
|
||||
|
||||
std::lock_guard<std::mutex> lock(_drawMutex);
|
||||
for (auto& [key, val] : val0)
|
||||
{
|
||||
// LOG_DEBUG("Waiting _drawMutex {:X}", (size_t)val.buffer);
|
||||
std::lock_guard<std::mutex> lock(_drawMutex);
|
||||
|
||||
val.captureInfo |= CaptureInfo::DrawIndexedInstanced;
|
||||
|
||||
if (Hudfix_Dx12::CheckForHudless(This, &val, val.state))
|
||||
@@ -1733,7 +1724,7 @@ void ResTrack_Dx12::hkExecuteBundle(ID3D12GraphicsCommandList* This, ID3D12Graph
|
||||
if (_notFoundCmdLists.contains(pCommandList))
|
||||
LOG_WARN("Found last frames cmdList: {:X}", (size_t) This);
|
||||
|
||||
auto frameCmdList = _resourceCommandList[index];
|
||||
auto& frameCmdList = _resourceCommandList[index];
|
||||
for (std::unordered_map<FG_ResourceType, ID3D12GraphicsCommandList*>::iterator it = frameCmdList.begin();
|
||||
it != frameCmdList.end(); ++it)
|
||||
{
|
||||
@@ -1815,14 +1806,11 @@ void ResTrack_Dx12::hkDispatch(ID3D12GraphicsCommandList* This, UINT ThreadGroup
|
||||
return;
|
||||
}
|
||||
|
||||
if (fgPossibleHudless[fIndex].size() == 0)
|
||||
return;
|
||||
|
||||
ankerl::unordered_dense::map<ID3D12Resource*, ResourceInfo> val0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_hudlessTrackMutex);
|
||||
|
||||
if (!fgPossibleHudless[fIndex].contains(This))
|
||||
if (fgPossibleHudless[fIndex].size() == 0 || !fgPossibleHudless[fIndex].contains(This))
|
||||
return;
|
||||
|
||||
val0 = std::move(fgPossibleHudless[fIndex][This]);
|
||||
@@ -1838,16 +1826,13 @@ void ResTrack_Dx12::hkDispatch(ID3D12GraphicsCommandList* This, UINT ThreadGroup
|
||||
if (Config::Instance()->FGHudfixDisableDispatch.value_or_default())
|
||||
break;
|
||||
|
||||
std::lock_guard<std::mutex> lock(_drawMutex);
|
||||
for (auto& [key, val] : val0)
|
||||
{
|
||||
// LOG_DEBUG("Waiting _drawMutex {:X}", (size_t)val.buffer);
|
||||
std::lock_guard<std::mutex> lock(_drawMutex);
|
||||
|
||||
val.captureInfo |= CaptureInfo::Dispatch;
|
||||
|
||||
if (Hudfix_Dx12::CheckForHudless(This, &val, val.state))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
|
||||
@@ -132,10 +132,10 @@ struct HeapInfo
|
||||
// mutable std::shared_mutex mutex;
|
||||
|
||||
ID3D12DescriptorHeap* heap = nullptr;
|
||||
SIZE_T cpuStart = NULL;
|
||||
SIZE_T cpuEnd = NULL;
|
||||
SIZE_T gpuStart = NULL;
|
||||
SIZE_T gpuEnd = NULL;
|
||||
SIZE_T cpuStart = 0;
|
||||
SIZE_T cpuEnd = 0;
|
||||
SIZE_T gpuStart = 0;
|
||||
SIZE_T gpuEnd = 0;
|
||||
UINT numDescriptors = 0;
|
||||
UINT increment = 0;
|
||||
UINT type = 0;
|
||||
@@ -146,8 +146,8 @@ struct HeapInfo
|
||||
|
||||
HeapInfo(ID3D12DescriptorHeap* heap, SIZE_T cpuStart, SIZE_T cpuEnd, SIZE_T gpuStart, SIZE_T gpuEnd,
|
||||
UINT numResources, UINT increment, UINT type)
|
||||
: cpuStart(cpuStart), cpuEnd(cpuEnd), gpuStart(gpuStart), gpuEnd(gpuEnd), numDescriptors(numResources),
|
||||
increment(increment), info(new ResourceInfo[numResources]), type(type), heap(heap)
|
||||
: heap(heap), cpuStart(cpuStart), cpuEnd(cpuEnd), gpuStart(gpuStart), gpuEnd(gpuEnd),
|
||||
numDescriptors(numResources), increment(increment), type(type), info(new ResourceInfo[numResources])
|
||||
{
|
||||
static std::atomic<uint64_t> globalHeapVersion { 1 };
|
||||
version.store(globalHeapVersion.fetch_add(1, std::memory_order_relaxed), std::memory_order_relaxed);
|
||||
@@ -242,6 +242,10 @@ struct HeapInfo
|
||||
info[index] = setInfo;
|
||||
AttachToNewResource(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
info[index] = setInfo;
|
||||
}
|
||||
}
|
||||
|
||||
void SetByGpuHandle(SIZE_T gpuHandle, ResourceInfo setInfo) const
|
||||
@@ -263,6 +267,10 @@ struct HeapInfo
|
||||
info[index] = setInfo;
|
||||
AttachToNewResource(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
info[index] = setInfo;
|
||||
}
|
||||
}
|
||||
|
||||
void ClearByCpuHandle(SIZE_T cpuHandle) const
|
||||
@@ -323,7 +331,7 @@ struct alignas(CACHE_LINE_SIZE) CommandListShard
|
||||
ankerl::unordered_dense::map<ID3D12Resource*, ResourceInfo>>
|
||||
map;
|
||||
|
||||
char padding[CACHE_LINE_SIZE - (sizeof(SpinLock) + sizeof(void*) % CACHE_LINE_SIZE)] = {};
|
||||
char padding[CACHE_LINE_SIZE - ((sizeof(SpinLock) + sizeof(void*)) % CACHE_LINE_SIZE)] = {};
|
||||
};
|
||||
#else
|
||||
struct alignas(CACHE_LINE_SIZE) CommandListShard
|
||||
@@ -333,7 +341,7 @@ struct alignas(CACHE_LINE_SIZE) CommandListShard
|
||||
ankerl::unordered_dense::map<ID3D12Resource*, ResourceInfo>>
|
||||
map;
|
||||
|
||||
char padding[CACHE_LINE_SIZE - (sizeof(std::mutex) + sizeof(void*) % CACHE_LINE_SIZE)] = {};
|
||||
char padding[CACHE_LINE_SIZE - ((sizeof(std::mutex) + sizeof(void*)) % CACHE_LINE_SIZE)] = {};
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user