From ddd74ee4675c7d7d585cc332239adce46683e963 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Sat, 9 Nov 2024 22:23:55 +0300 Subject: [PATCH] stash 2 --- OptiScaler/Config.h | 4 + OptiScaler/OptiScaler.vcxproj | 32 +- OptiScaler/WorkingMode.cpp | 3 + OptiScaler/apis/NVNGX_DLSS_Dx12.cpp | 16 +- OptiScaler/apis/NVNGX_DLSS_Vk.cpp | 2 +- OptiScaler/dllmain.cpp | 104 ------ OptiScaler/hooks/LoadLibrary.cpp | 271 ++++++++------ OptiScaler/hooks/LoadLibrary.h | 6 +- OptiScaler/hooks/Vulkan.cpp | 132 ++++++- OptiScaler/menu/ImguiSpdLog.cpp | 353 ------------------ OptiScaler/menu/ImguiSpdLog.h | 4 - OptiScaler/menu/MenuBase.cpp | 72 ++++ .../menu/{imgui_overlay_base.h => MenuBase.h} | 5 +- .../menu/{imgui_common.cpp => MenuCommon.cpp} | 54 +-- .../menu/{imgui_common.h => MenuCommon.h} | 3 +- .../menu/{imgui_overlay_dx.cpp => MenuDx.cpp} | 85 ++--- .../menu/{imgui_overlay_dx.h => MenuDx.h} | 2 +- .../{imgui_overlay_vk.cpp => MenuVulkan.cpp} | 275 +++----------- OptiScaler/menu/MenuVulkan.h | 20 + .../{imgui_dx_base.cpp => OldMenuBase.cpp} | 32 +- .../menu/{imgui_dx_base.h => OldMenuBase.h} | 8 +- .../menu/{Imgui_Dx11.cpp => OldMenuDx11.cpp} | 14 +- .../menu/{Imgui_Dx11.h => OldMenuDx11.h} | 8 +- .../menu/{imgui_dx12.cpp => OldMenuDx12.cpp} | 14 +- .../menu/{Imgui_Dx12.h => OldMenuDx12.h} | 8 +- OptiScaler/menu/imgui_overlay_base.cpp | 72 ---- OptiScaler/menu/imgui_overlay_vk.h | 15 - OptiScaler/menu/wrapped_swapchain.h | 2 +- OptiScaler/nvapi/NvApiHooks.h | 125 +++++++ OptiScaler/nvapi/NvApiTypes.h | 26 ++ OptiScaler/nvapi/ReflexHooks.h | 141 +++++++ OptiScaler/nvapi/fakenvapi.h | 91 +++++ OptiScaler/upscalers/IFeature_Dx11.h | 4 +- OptiScaler/upscalers/IFeature_Dx11wDx12.h | 3 +- OptiScaler/upscalers/IFeature_Dx12.h | 4 +- .../upscalers/dlss/DLSSFeature_Dx11.cpp | 4 +- .../upscalers/dlss/DLSSFeature_Dx12.cpp | 4 +- .../upscalers/dlssd/DLSSDFeature_Dx11.cpp | 4 +- .../upscalers/dlssd/DLSSDFeature_Dx12.cpp | 4 +- .../upscalers/fsr2/FSR2Feature_Dx11.cpp | 4 +- .../upscalers/fsr2/FSR2Feature_Dx11On12.cpp | 6 +- .../upscalers/fsr2/FSR2Feature_Dx12.cpp | 4 +- .../fsr2_212/FSR2Feature_Dx11On12_212.cpp | 6 +- .../fsr2_212/FSR2Feature_Dx12_212.cpp | 4 +- .../upscalers/fsr31/FSR31Feature_Dx11.cpp | 4 +- .../upscalers/fsr31/FSR31Feature_Dx11On12.cpp | 6 +- .../upscalers/fsr31/FSR31Feature_Dx12.cpp | 4 +- .../upscalers/xess/XeSSFeature_Dx11.cpp | 6 +- .../upscalers/xess/XeSSFeature_Dx12.cpp | 4 +- 49 files changed, 991 insertions(+), 1083 deletions(-) delete mode 100644 OptiScaler/menu/ImguiSpdLog.cpp delete mode 100644 OptiScaler/menu/ImguiSpdLog.h create mode 100644 OptiScaler/menu/MenuBase.cpp rename OptiScaler/menu/{imgui_overlay_base.h => MenuBase.h} (93%) rename OptiScaler/menu/{imgui_common.cpp => MenuCommon.cpp} (98%) rename OptiScaler/menu/{imgui_common.h => MenuCommon.h} (99%) rename OptiScaler/menu/{imgui_overlay_dx.cpp => MenuDx.cpp} (94%) rename OptiScaler/menu/{imgui_overlay_dx.h => MenuDx.h} (96%) rename OptiScaler/menu/{imgui_overlay_vk.cpp => MenuVulkan.cpp} (68%) create mode 100644 OptiScaler/menu/MenuVulkan.h rename OptiScaler/menu/{imgui_dx_base.cpp => OldMenuBase.cpp} (50%) rename OptiScaler/menu/{imgui_dx_base.h => OldMenuBase.h} (93%) rename OptiScaler/menu/{Imgui_Dx11.cpp => OldMenuDx11.cpp} (89%) rename OptiScaler/menu/{Imgui_Dx11.h => OldMenuDx11.h} (72%) rename OptiScaler/menu/{imgui_dx12.cpp => OldMenuDx12.cpp} (95%) rename OptiScaler/menu/{Imgui_Dx12.h => OldMenuDx12.h} (79%) delete mode 100644 OptiScaler/menu/imgui_overlay_base.cpp delete mode 100644 OptiScaler/menu/imgui_overlay_vk.h create mode 100644 OptiScaler/nvapi/NvApiHooks.h create mode 100644 OptiScaler/nvapi/NvApiTypes.h create mode 100644 OptiScaler/nvapi/ReflexHooks.h create mode 100644 OptiScaler/nvapi/fakenvapi.h diff --git a/OptiScaler/Config.h b/OptiScaler/Config.h index f9630db1..4177be66 100644 --- a/OptiScaler/Config.h +++ b/OptiScaler/Config.h @@ -193,6 +193,10 @@ public: std::optional FN_LatencyFlexMode; // conservative - aggressive - reflex ids std::optional FN_ForceReflex; // in-game - force disable - force enable + // framerate + bool ReflexAvailable = false; + std::optional FramerateLimit; + // for realtime changes bool changeBackend = false; std::string newBackend = ""; diff --git a/OptiScaler/OptiScaler.vcxproj b/OptiScaler/OptiScaler.vcxproj index 1b4b9c85..25bcf297 100644 --- a/OptiScaler/OptiScaler.vcxproj +++ b/OptiScaler/OptiScaler.vcxproj @@ -194,6 +194,10 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\ + + + + @@ -251,13 +255,13 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\ - - - - - - - + + + + + + + @@ -318,13 +322,13 @@ copy $(SolutionDir)nvngx.ini $(SolutionDir)x64\Release\a\ - - - - - - - + + + + + + + diff --git a/OptiScaler/WorkingMode.cpp b/OptiScaler/WorkingMode.cpp index f4b5fae7..212d1071 100644 --- a/OptiScaler/WorkingMode.cpp +++ b/OptiScaler/WorkingMode.cpp @@ -341,7 +341,10 @@ bool WorkingMode::Check() } while (false); if (modeFound) + { + Config::Instance()->OverlayMenu = (!isNvngxMode || isWorkingWithEnabler) && Config::Instance()->OverlayMenu.value_or(true); return true; + } LOG_ERROR("Unsupported dll name: {0}", filename); return false; diff --git a/OptiScaler/apis/NVNGX_DLSS_Dx12.cpp b/OptiScaler/apis/NVNGX_DLSS_Dx12.cpp index 6eef9605..1c01f800 100644 --- a/OptiScaler/apis/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/apis/NVNGX_DLSS_Dx12.cpp @@ -2,7 +2,7 @@ #include "Config.h" #include "NVNGX_Parameter.h" #include "proxies/NVNGX_Proxy.h" -#include +#include #include "upscalers/dlss/DLSSFeature_Dx12.h" #include "upscalers/dlssd/DLSSDFeature_Dx12.h" #include "upscalers/fsr2/FSR2Feature_Dx12.h" @@ -272,13 +272,13 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp queryHeapDesc.Count = 2; // Start and End timestamps queryHeapDesc.NodeMask = 0; queryHeapDesc.Type = D3D12_QUERY_HEAP_TYPE_TIMESTAMP; - auto result = InDevice->CreateQueryHeap(&queryHeapDesc, IID_PPV_ARGS(&ImGuiOverlayDx::queryHeap)); + auto result = InDevice->CreateQueryHeap(&queryHeapDesc, IID_PPV_ARGS(&MenuDx::queryHeap)); // Create a readback buffer to retrieve timestamp data D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(2 * sizeof(UINT64)); D3D12_HEAP_PROPERTIES heapProps = {}; heapProps.Type = D3D12_HEAP_TYPE_READBACK; - result = InDevice->CreateCommittedResource(&heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&ImGuiOverlayDx::readbackBuffer)); + result = InDevice->CreateCommittedResource(&heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&MenuDx::readbackBuffer)); return NVSDK_NGX_Result_Success; } @@ -402,7 +402,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown(void) // Unhooking and cleaning stuff causing issues during shutdown. // Disabled for now to check if it cause any issues - //ImGuiOverlayDx::UnHookDx(); + //MenuDx::UnHookDx(); shutdown = false; @@ -1161,17 +1161,17 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_EvaluateFeature(ID3D12GraphicsCom } // Record the first timestamp (before FSR2 upscaling) - InCmdList->EndQuery(ImGuiOverlayDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0); + InCmdList->EndQuery(MenuDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0); bool evalResult = deviceContext->Evaluate(InCmdList, InParameters); // Record the second timestamp (after FSR2 upscaling) - InCmdList->EndQuery(ImGuiOverlayDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 1); + InCmdList->EndQuery(MenuDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 1); // Resolve the queries to the readback buffer - InCmdList->ResolveQueryData(ImGuiOverlayDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, ImGuiOverlayDx::readbackBuffer, 0); + InCmdList->ResolveQueryData(MenuDx::queryHeap, D3D12_QUERY_TYPE_TIMESTAMP, 0, 2, MenuDx::readbackBuffer, 0); - ImGuiOverlayDx::dx12UpscaleTrig = true; + MenuDx::dx12UpscaleTrig = true; if (deviceContext->Name() != "DLSSD" && (Config::Instance()->RestoreComputeSignature.value_or(false) || Config::Instance()->RestoreGraphicSignature.value_or(false))) { diff --git a/OptiScaler/apis/NVNGX_DLSS_Vk.cpp b/OptiScaler/apis/NVNGX_DLSS_Vk.cpp index ee7039e6..16afb85b 100644 --- a/OptiScaler/apis/NVNGX_DLSS_Vk.cpp +++ b/OptiScaler/apis/NVNGX_DLSS_Vk.cpp @@ -5,7 +5,7 @@ #include "resource.h" #include "NVNGX_Parameter.h" #include "proxies/NVNGX_Proxy.h" -#include "menu/imgui_overlay_vk.h" +#include "menu/MenuVulkan.h" #include "upscalers/fsr2/FSR2Feature_Vk.h" #include "upscalers/dlss/DLSSFeature_Vk.h" #include "upscalers/dlssd/DLSSDFeature_Vk.h" diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index 83dc6e2f..221f1d90 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -7,61 +7,6 @@ #include "proxies/NVNGX_Proxy.h" #include "proxies/FfxApi_Proxy.h" #include "proxies/XeSS_Proxy.h" -#include "menu/imgui_overlay_dx.h" -#include "menu/imgui_overlay_vk.h" - -#pragma warning (disable : 4996) - -inline std::vector upscalerNames = -{ - "nvngx.dll", - "nvngx", - "libxess.dll", - "libxess" -}; - -inline std::vector nvngxDlss = -{ - "nvngx_dlss.dll", - "nvngx_dlss", -}; - -inline std::vector nvapiNames = -{ - "nvapi64.dll", - "nvapi64", -}; - -inline std::vector dllNames; - -inline std::vector upscalerNamesW = -{ - L"nvngx.dll", - L"nvngx", - L"libxess.dll", - L"libxess" -}; - -inline std::vector nvngxDlssW = -{ - L"nvngx_dlss.dll", - L"nvngx_dlss", -}; - -inline std::vector nvapiNamesW = -{ - L"nvapi64.dll", - L"nvapi64", -}; - -inline std::vector dllNamesW; - -static int loadCount = 0; -static bool dontCount = false; - -static bool isNvngxMode = false; -static bool isWorkingWithEnabler = false; -static bool isNvngxAvailable = false; void AttachHooks(); void DetachHooks(); @@ -261,55 +206,6 @@ static void DetachHooks() } } -static void AttachHooks() -{ - LOG_FUNC(); - - if (o_LoadLibraryA == nullptr || o_LoadLibraryW == nullptr) - { - // Detour the functions - o_FreeLibrary = reinterpret_cast(DetourFindFunction("kernel32.dll", "FreeLibrary")); - o_LoadLibraryA = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryA")); - o_LoadLibraryW = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryW")); - o_LoadLibraryExA = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryExA")); - o_LoadLibraryExW = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryExW")); -#ifdef _DEBUG - o_GetProcAddress = reinterpret_cast(DetourFindFunction("kernel32.dll", "GetProcAddress")); -#endif // DEBUG - - if (o_LoadLibraryA != nullptr || o_LoadLibraryW != nullptr || o_LoadLibraryExA != nullptr || o_LoadLibraryExW != nullptr) - { - LOG_INFO("Attaching LoadLibrary hooks"); - - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - - if (o_FreeLibrary) - DetourAttach(&(PVOID&)o_FreeLibrary, hkFreeLibrary); - - if (o_LoadLibraryA) - DetourAttach(&(PVOID&)o_LoadLibraryA, hkLoadLibraryA); - - if (o_LoadLibraryW) - DetourAttach(&(PVOID&)o_LoadLibraryW, hkLoadLibraryW); - - if (o_LoadLibraryExA) - DetourAttach(&(PVOID&)o_LoadLibraryExA, hkLoadLibraryExA); - - if (o_LoadLibraryExW) - DetourAttach(&(PVOID&)o_LoadLibraryExW, hkLoadLibraryExW); - - if (o_GetProcAddress) - DetourAttach(&(PVOID&)o_GetProcAddress, hkGetProcAddress); - - DetourTransactionCommit(); - } - } - - - -} - BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) diff --git a/OptiScaler/hooks/LoadLibrary.cpp b/OptiScaler/hooks/LoadLibrary.cpp index 467b6b27..5066a7df 100644 --- a/OptiScaler/hooks/LoadLibrary.cpp +++ b/OptiScaler/hooks/LoadLibrary.cpp @@ -4,6 +4,7 @@ #include #include "Vulkan.h" #include +#include #include @@ -21,93 +22,20 @@ static PFN_LoadLibraryExA o_LoadLibraryExA = nullptr; static PFN_LoadLibraryExW o_LoadLibraryExW = nullptr; static PFN_GetProcAddress o_GetProcAddress = nullptr; -static std::vector upscalerNames = -{ - "nvngx.dll", - "nvngx", - "libxess.dll", - "libxess" -}; - -static std::vector nvngxDlss = -{ - "nvngx_dlss.dll", - "nvngx_dlss", -}; - -static std::vector nvapiNames = -{ - "nvapi64.dll", - "nvapi64", -}; - -static std::vector upscalerNamesW = -{ - L"nvngx.dll", - L"nvngx", - L"libxess.dll", - L"libxess" -}; - -static std::vector nvngxDlssW = -{ - L"nvngx_dlss.dll", - L"nvngx_dlss", -}; - -static std::vector nvapiNamesW = -{ - L"nvapi64.dll", - L"nvapi64", -}; - -static std::vector dx11NamesW = -{ - L"d3d11.dll", - L"d3d11", -}; - -static std::vector dx11Names = -{ - "d3d11.dll", - "d3d11", -}; - -static std::vector dx12NamesW = -{ - L"d3d12.dll", - L"d3d12", -}; - -static std::vector dx12Names = -{ - "d3d12.dll", - "d3d12", -}; - -inline std::vector dxgiNamesW = -{ - L"dxgi.dll", - L"dxgi", -}; - -static std::vector dxgiNames = -{ - "dxgi.dll", - "dxgi", -}; - -static std::vector vkNamesW = -{ - L"vulkan-1.dll", - L"vulkan-1", -}; - -static std::vector vkNames = -{ - "vulkan-1.dll", - "vulkan-1", -}; +static std::vector upscalerNames = { "nvngx.dll", "nvngx", "libxess.dll", "libxess" }; +static std::vector upscalerNamesW = { L"nvngx.dll", L"nvngx", L"libxess.dll", L"libxess" }; +static std::vector nvngxDlss = { "nvngx_dlss.dll", "nvngx_dlss", }; +static std::vector nvngxDlssW = { L"nvngx_dlss.dll", L"nvngx_dlss", }; +static std::vector nvapiNames = { "nvapi64.dll", "nvapi64", }; +static std::vector nvapiNamesW = { L"nvapi64.dll", L"nvapi64", }; +static std::vector dx11Names = { "d3d11.dll", "d3d11", }; +static std::vector dx11NamesW = { L"d3d11.dll", L"d3d11", }; +static std::vector dx12Names = { "d3d12.dll", "d3d12", }; +static std::vector dx12NamesW = { L"d3d12.dll", L"d3d12", }; +static std::vector dxgiNames = { "dxgi.dll", "dxgi", }; +static std::vector dxgiNamesW = { L"dxgi.dll", L"dxgi", }; +static std::vector vkNames = { "vulkan-1.dll", "vulkan-1", }; +static std::vector vkNamesW = { L"vulkan-1.dll", L"vulkan-1", }; static bool dontCount = false; static bool skipLoadChecks = false; @@ -228,14 +156,12 @@ inline static HMODULE LoadLibraryCheck(std::string lcaseLibName) { VulkanHooks::Hook(); VulkanHooks::HookExtension(); - - if (Config::Instance()->OverlayMenu.value_or(true)) - HooksVk::HookVk(); } skipLoadChecks = false; - if (!WorkingMode::IsNvngxMode() && CheckDllName(&lcaseLibName, &WorkingMode::DllNames())) + auto names = WorkingMode::DllNames(); + if (!WorkingMode::IsNvngxMode() && CheckDllName(&lcaseLibName, &names)) { LOG_INFO("{0} call returning this dll!", lcaseLibName); @@ -335,14 +261,12 @@ inline static HMODULE LoadLibraryCheckW(std::wstring lcaseLibName) { VulkanHooks::Hook(); VulkanHooks::HookExtension(); - - if (Config::Instance()->OverlayMenu.value_or(true)) - HooksVk::HookVk(); } skipLoadChecks = false; - if (!WorkingMode::IsNvngxMode() && CheckDllNameW(&lcaseLibName, &WorkingMode::DllNamesW())) + auto names = WorkingMode::DllNamesW(); + if (!WorkingMode::IsNvngxMode() && CheckDllNameW(&lcaseLibName, &names)) { LOG_INFO("{0} call returning this dll!", lcaseLibNameA); @@ -588,47 +512,146 @@ void LoadLibraryHooks::Hook() { LOG_FUNC(); - if (o_LoadLibraryA == nullptr || o_LoadLibraryW == nullptr) - { - // Detour the functions - o_FreeLibrary = reinterpret_cast(DetourFindFunction("kernel32.dll", "FreeLibrary")); + // Detour the functions + o_FreeLibrary = reinterpret_cast(DetourFindFunction("kernel32.dll", "FreeLibrary")); - o_LoadLibraryA = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryA")); - o_LoadLibraryW = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryW")); - o_LoadLibraryExA = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryExA")); - o_LoadLibraryExW = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryExW")); + o_LoadLibraryA = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryA")); + o_LoadLibraryW = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryW")); + o_LoadLibraryExA = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryExA")); + o_LoadLibraryExW = reinterpret_cast(DetourFindFunction("kernel32.dll", "LoadLibraryExW")); #ifdef _DEBUG - //o_GetProcAddress = reinterpret_cast(DetourFindFunction("kernel32.dll", "GetProcAddress")); + //o_GetProcAddress = reinterpret_cast(DetourFindFunction("kernel32.dll", "GetProcAddress")); #endif // DEBUG - if (o_LoadLibraryA != nullptr || o_LoadLibraryW != nullptr || o_LoadLibraryExA != nullptr || o_LoadLibraryExW != nullptr) - { - LOG_INFO("Attaching LoadLibrary hooks"); + if (o_LoadLibraryA != nullptr || o_LoadLibraryW != nullptr || o_LoadLibraryExA != nullptr || o_LoadLibraryExW != nullptr) + { + LOG_INFO("Attaching LoadLibrary hooks"); - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); - if (o_FreeLibrary) - DetourAttach(&(PVOID&)o_FreeLibrary, hkFreeLibrary); + if (o_FreeLibrary) + DetourAttach(&(PVOID&)o_FreeLibrary, hkFreeLibrary); - if (o_LoadLibraryA) - DetourAttach(&(PVOID&)o_LoadLibraryA, hkLoadLibraryA); + if (o_LoadLibraryA) + DetourAttach(&(PVOID&)o_LoadLibraryA, hkLoadLibraryA); - if (o_LoadLibraryW) - DetourAttach(&(PVOID&)o_LoadLibraryW, hkLoadLibraryW); + if (o_LoadLibraryW) + DetourAttach(&(PVOID&)o_LoadLibraryW, hkLoadLibraryW); - if (o_LoadLibraryExA) - DetourAttach(&(PVOID&)o_LoadLibraryExA, hkLoadLibraryExA); + if (o_LoadLibraryExA) + DetourAttach(&(PVOID&)o_LoadLibraryExA, hkLoadLibraryExA); - if (o_LoadLibraryExW) - DetourAttach(&(PVOID&)o_LoadLibraryExW, hkLoadLibraryExW); + if (o_LoadLibraryExW) + DetourAttach(&(PVOID&)o_LoadLibraryExW, hkLoadLibraryExW); - if (o_GetProcAddress) - DetourAttach(&(PVOID&)o_GetProcAddress, hkGetProcAddress); + if (o_GetProcAddress) + DetourAttach(&(PVOID&)o_GetProcAddress, hkGetProcAddress); - DetourTransactionCommit(); - } + DetourTransactionCommit(); } + + HMODULE dxgiModule = nullptr; + dxgiModule = GetModuleHandle(L"dxgi.dll"); + if (dxgiModule != nullptr) + { + LOG_DEBUG("dxgi.dll already in memory"); + HookForDxgiSpoofing(); + } + + HMODULE vulkanModule = nullptr; + vulkanModule = GetModuleHandle(L"vulkan-1.dll"); + if (vulkanModule != nullptr) + { + LOG_DEBUG("vulkan-1.dll already in memory"); + VulkanHooks::Hook(); + VulkanHooks::HookExtension(); + } + + HMODULE nvapi64 = nullptr; + nvapi64 = GetModuleHandle(L"nvapi64.dll"); + if (nvapi64 != nullptr) + { + LOG_DEBUG("nvapi64.dll already in memory"); + NvApiHooks::Hook(nvapi64); + } + + // dx menu hooks + HMODULE d3d11Module = nullptr; + d3d11Module = GetModuleHandle(L"d3d11.dll"); + if (Config::Instance()->OverlayMenu.value() && d3d11Module != nullptr) + { + LOG_DEBUG("d3d11.dll already in memory"); + HooksDx::HookDx11(); + } + + HMODULE d3d12Module = nullptr; + d3d12Module = GetModuleHandle(L"d3d12.dll"); + if (Config::Instance()->OverlayMenu.value() && d3d12Module != nullptr) + { + LOG_DEBUG("d3d12.dll already in memory"); + HooksDx::HookDx12(); + } + + if (Config::Instance()->OverlayMenu.value() && dxgiModule != nullptr) + HooksDx::HookDxgi(); +} + +void LoadLibraryHooks::Unhook() +{ + VulkanHooks::UnhookExtension(); + VulkanHooks::Unhook(); + + DetourTransactionBegin(); + + DetourUpdateThread(GetCurrentThread()); + + if (o_FreeLibrary) + { + DetourDetach(&(PVOID&)o_FreeLibrary, hkFreeLibrary); + o_FreeLibrary = nullptr; + } + + if (o_LoadLibraryA) + { + DetourDetach(&(PVOID&)o_LoadLibraryA, hkLoadLibraryA); + o_LoadLibraryA = nullptr; + } + + if (o_LoadLibraryW) + { + DetourDetach(&(PVOID&)o_LoadLibraryW, hkLoadLibraryW); + o_LoadLibraryW = nullptr; + } + + if (o_LoadLibraryExA) + { + DetourDetach(&(PVOID&)o_LoadLibraryExA, hkLoadLibraryExA); + o_LoadLibraryExA = nullptr; + } + + if (o_LoadLibraryExW) + { + DetourDetach(&(PVOID&)o_LoadLibraryExW, hkLoadLibraryExW); + o_LoadLibraryExW = nullptr; + } + + if (o_GetProcAddress) + { + DetourDetach(&(PVOID&)o_GetProcAddress, hkGetProcAddress); + o_GetProcAddress = nullptr; + } + + DetourTransactionCommit(); +} + +void LoadLibraryHooks::AddLoad() +{ + loadCount++; +} + +UINT LoadLibraryHooks::LoadCount() +{ + return loadCount; } - \ No newline at end of file diff --git a/OptiScaler/hooks/LoadLibrary.h b/OptiScaler/hooks/LoadLibrary.h index 6399615c..92c24ef9 100644 --- a/OptiScaler/hooks/LoadLibrary.h +++ b/OptiScaler/hooks/LoadLibrary.h @@ -5,6 +5,8 @@ class LoadLibraryHooks { private: public: - void Hook(); - void Unhook(); + static void Hook(); + static void Unhook(); + static void AddLoad(); + static UINT LoadCount(); }; diff --git a/OptiScaler/hooks/Vulkan.cpp b/OptiScaler/hooks/Vulkan.cpp index 5e5620bc..33c1591b 100644 --- a/OptiScaler/hooks/Vulkan.cpp +++ b/OptiScaler/hooks/Vulkan.cpp @@ -1,7 +1,9 @@ #include "Vulkan.h" +#include #include #include +#include #include #include @@ -12,6 +14,18 @@ typedef struct VkDummyProps void* pNext; } VkDummyProps; +typedef struct VkWin32SurfaceCreateInfoKHR { + VkStructureType sType; + const void* pNext; + VkFlags flags; + HINSTANCE hinstance; + HWND hwnd; +} VkWin32SurfaceCreateInfoKHR; + +typedef VkResult(*PFN_QueuePresentKHR)(VkQueue, const VkPresentInfoKHR*); +typedef VkResult(*PFN_CreateSwapchainKHR)(VkDevice, const VkSwapchainCreateInfoKHR*, const VkAllocationCallbacks*, VkSwapchainKHR*); +typedef VkResult(*PFN_vkCreateWin32SurfaceKHR)(VkInstance, const VkWin32SurfaceCreateInfoKHR*, const VkAllocationCallbacks*, VkSurfaceKHR*); + static PFN_vkGetPhysicalDeviceProperties o_vkGetPhysicalDeviceProperties = nullptr; static PFN_vkGetPhysicalDeviceProperties2 o_vkGetPhysicalDeviceProperties2 = nullptr; static PFN_vkGetPhysicalDeviceProperties2KHR o_vkGetPhysicalDeviceProperties2KHR = nullptr; @@ -21,9 +35,106 @@ static PFN_vkEnumerateDeviceExtensionProperties o_vkEnumerateDeviceExtensionProp static PFN_vkCreateDevice o_vkCreateDevice = nullptr; static PFN_vkCreateInstance o_vkCreateInstance = nullptr; +static PFN_QueuePresentKHR o_QueuePresentKHR = nullptr; +static PFN_CreateSwapchainKHR o_CreateSwapchainKHR = nullptr; +static PFN_vkCreateWin32SurfaceKHR o_vkCreateWin32SurfaceKHR = nullptr; + static uint32_t vkEnumerateInstanceExtensionPropertiesCount = 0; static uint32_t vkEnumerateDeviceExtensionPropertiesCount = 0; +static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo) +{ + LOG_FUNC(); + + if (Config::Instance()->OverlayMenu.value_or(true)) + { + auto menuResult = MenuVulkan::QueuePresent(queue, pPresentInfo); + + if (menuResult == VK_INCOMPLETE) + { + Config::Instance()->VulkanCreatingSC = true; + auto r0 = o_QueuePresentKHR(queue, pPresentInfo); + Config::Instance()->VulkanCreatingSC = false; + + if (r0 != VK_SUCCESS) + LOG_ERROR("o_QueuePresentKHR(queue, pPresentInfo): {0:X}", (UINT)r0); + + return r0; + } + + if (menuResult != VK_SUCCESS) + return menuResult; + } + + // original call + Config::Instance()->VulkanCreatingSC = true; + auto result = o_QueuePresentKHR(queue, pPresentInfo); + Config::Instance()->VulkanCreatingSC = false; + + LOG_FUNC_RESULT(result); + + return result; +} + +static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) +{ + LOG_FUNC(); + + Config::Instance()->VulkanCreatingSC = true; + auto result = o_CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); + Config::Instance()->VulkanCreatingSC = false; + + if (Config::Instance()->OverlayMenu.value_or(true) && result == VK_SUCCESS && + device != VK_NULL_HANDLE && pCreateInfo != nullptr && *pSwapchain != VK_NULL_HANDLE && !Config::Instance()->VulkanSkipHooks) + { + MenuVulkan::CreateSwapchain(device, pCreateInfo, pSwapchain); + } + + LOG_FUNC_RESULT(result); + return result; +} + +static void HookDevice(VkDevice InDevice) +{ + if (o_CreateSwapchainKHR != nullptr || Config::Instance()->VulkanSkipHooks) + return; + + LOG_FUNC(); + + o_QueuePresentKHR = (PFN_QueuePresentKHR)(vkGetDeviceProcAddr(InDevice, "vkQueuePresentKHR")); + o_CreateSwapchainKHR = (PFN_CreateSwapchainKHR)(vkGetDeviceProcAddr(InDevice, "vkCreateSwapchainKHR")); + + if (o_CreateSwapchainKHR) + { + LOG_DEBUG("Hooking VkDevice"); + + // Hook + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + + DetourAttach(&(PVOID&)o_QueuePresentKHR, hkvkQueuePresentKHR); + DetourAttach(&(PVOID&)o_CreateSwapchainKHR, hkvkCreateSwapchainKHR); + + DetourTransactionCommit(); + } +} + +static VkResult hkvkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) +{ + LOG_FUNC(); + + auto result = o_vkCreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); + + if (Config::Instance()->OverlayMenu.value_or(true) && result == VK_SUCCESS && !Config::Instance()->VulkanSkipHooks) + { + MenuVulkan::CreateSurface(instance, pCreateInfo->hwnd); + } + + LOG_FUNC_RESULT(result); + + return result; +} + static void hkvkGetPhysicalDeviceProperties(VkPhysicalDevice physical_device, VkPhysicalDeviceProperties* properties) { o_vkGetPhysicalDeviceProperties(physical_device, properties); @@ -127,12 +238,18 @@ static VkResult hkvkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, cons LOG_DEBUG("o_vkCreateInstance result: {0:X}", (INT)result); - auto head = (VkBaseInStructure*)pCreateInfo; - - while (head->pNext != nullptr) + if (result == VK_SUCCESS) { - head = (VkBaseInStructure*)head->pNext; - LOG_DEBUG("o_vkCreateInstance type: {0:X}", (UINT)head->sType); + auto head = (VkBaseInStructure*)pCreateInfo; + + while (head->pNext != nullptr) + { + head = (VkBaseInStructure*)head->pNext; + LOG_DEBUG("o_vkCreateInstance type: {0:X}", (UINT)head->sType); + } + + if (Config::Instance()->OverlayMenu.value_or(true)) + MenuVulkan::CreateInstance(pInstance); } return result; @@ -193,6 +310,11 @@ static VkResult hkvkCreateDevice(VkPhysicalDevice physicalDevice, VkDeviceCreate auto result = o_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); Config::Instance()->dxgiSkipSpoofing = false; + if (result == VK_SUCCESS && !Config::Instance()->VulkanSkipHooks) + { + HookDevice(*pDevice); + } + LOG_FUNC_RESULT(result); return result; diff --git a/OptiScaler/menu/ImguiSpdLog.cpp b/OptiScaler/menu/ImguiSpdLog.cpp deleted file mode 100644 index 0ab72ae0..00000000 --- a/OptiScaler/menu/ImguiSpdLog.cpp +++ /dev/null @@ -1,353 +0,0 @@ -#include "ImguiSpdLog.h" - -class SinkLineContent -{ -public: - spdlog::level::level_enum LogLevel; // If n_levels, the message pushed counts to the previous pushed line - - int32_t BeginIndex; // Base offset into the text buffer - - struct ColorDataRanges { - uint32_t SubStringBegin : 12; - uint32_t SubStringEnd : 12; - uint32_t FormatTag : 8; - }; - - ImVector FormattedStringRanges; -}; - - -// TODO: work on filters, they are really needed, did optimize the memory storage quite a bit tho -class ImGuiSpdLogAdaptor : public spdlog::sinks::base_sink { - - using sink_t = spdlog::sinks::base_sink; - -public: - void DrawLogWindow() { - - if (ImGui::Begin("CyberXeSS Log", &ShowWindow)) { - - // Options submenu menu - if (ImGui::BeginPopup("Options")) { - - ImGui::Checkbox("Auto-scroll", &EnableAutoScrolling); - ImGui::EndPopup(); - } - - if (ImGui::Button("Options")) - ImGui::OpenPopup("Options"); - - ImGui::SameLine(); - ImGui::SameLine(); - - if (ImGui::Button("Clear")) - ClearLogBuffers(); - - ImGui::SameLine(); - - ImGui::Text("%d messages logged, using %dmb memory", NumberOfLogEntries, (LoggedContent.size() + IndicesInBytes) / (1024 * 1024)); - - // Filter out physical messgaes through logger - static const char* LogLevels[] = SPDLOG_LEVEL_NAMES; - - static const auto LogSelectionWidth = []() -> float - { - float LongestTextWidth = 0; - for (auto LogLevelText : LogLevels) { - - auto TextWidth = ImGui::CalcTextSize(LogLevelText).x; - if (TextWidth > LongestTextWidth) - LongestTextWidth = TextWidth; - } - - return LongestTextWidth + - ImGui::GetStyle().FramePadding.x * 2 + - ImGui::GetFrameHeight(); - }(); - - auto ComboBoxRightAlignment = ImGui::GetWindowSize().x - (LogSelectionWidth + ImGui::GetStyle().WindowPadding.x); - auto ActiveLogLevel = spdlog::get_level(); - - ImGui::SetNextItemWidth(LogSelectionWidth); - ImGui::SameLine(ComboBoxRightAlignment); - - ImGui::Combo("##ActiveLogLevel", reinterpret_cast(&ActiveLogLevel), LogLevels, sizeof(LogLevels) / sizeof(LogLevels[0])); - spdlog::set_level(ActiveLogLevel); - - // Filter out messages on display - FilterTextMatch.Draw("##LogFilter", ImGui::GetWindowSize().x - (LogSelectionWidth + ImGui::GetStyle().WindowPadding.x * 2 + ImGui::GetStyle().FramePadding.x)); - - ImGui::SetNextItemWidth(LogSelectionWidth); - ImGui::SameLine(ComboBoxRightAlignment); - ImGui::Combo("##FilterLogLevel", &FilterLogLevel, LogLevels, sizeof(LogLevels) / sizeof(LogLevels[0])); - - // Draw main log window - ImGui::Separator(); - ImGui::BeginChild("LogTextView", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar); - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - const std::lock_guard LogLock(sink_t::mutex_); - - RebuildFilterWithPreviousStates(); - - ImGuiListClipper ViewClipper; - ViewClipper.Begin(FilteredView.size()); - - while (ViewClipper.Step()) - { - int32_t StylesPushedToStack = 0; - for (auto ClipperLineNumber = ViewClipper.DisplayStart; ClipperLineNumber < ViewClipper.DisplayEnd; ++ClipperLineNumber) - { - auto& LogMetaDataEntry = LogMetaData[FilteredView[ClipperLineNumber]]; - - if (LogMetaDataEntry.LogLevel == spdlog::level::n_levels) - ImGui::Indent(); - - for (auto i = 0; i < LogMetaDataEntry.FormattedStringRanges.size(); ++i) - { - static const ImVec4 BrightColorsToVec[]{ - { 0, 0, 0, 1 }, // COLOR_BRIGHTBLACK - { 1, 0, 0, 1 }, // COLOR_BRIGHTRED - { 0, 1, 0, 1 }, // COLOR_BRIGHTGREEN - { 1, 1, 0, 1 }, // COLOR_BRIGHTYELLOW - { 0, 0, 1, 1 }, // COLOR_BRIGHTBLUE - { 1, 0, 1, 1 }, // COLOR_BRIGHTMAGENTA - { 0, 1, 1, 1 }, // COLOR_BRIGHTCYAN - { 1, 1, 1, 1 } // COLOR_BRIGHTWHITE - }; - - ImGui::PushStyleColor(ImGuiCol_Text, BrightColorsToVec[LogMetaDataEntry.FormattedStringRanges[i].FormatTag]); - ++StylesPushedToStack; - - - auto FormatRangeBegin = LoggedContent.begin() + LogMetaDataEntry.BeginIndex + LogMetaDataEntry.FormattedStringRanges[i].SubStringBegin; - auto FormatRangeEnd = LoggedContent.begin() + LogMetaDataEntry.BeginIndex + LogMetaDataEntry.FormattedStringRanges[i].SubStringEnd; - ImGui::TextUnformatted(FormatRangeBegin, FormatRangeEnd); - - if (LogMetaDataEntry.FormattedStringRanges.size() - (i + 1)) - ImGui::SameLine(); - } - - if (LogMetaDataEntry.LogLevel == spdlog::level::n_levels) - ImGui::Unindent(); - } - - ImGui::PopStyleColor(StylesPushedToStack); - } - - ViewClipper.End(); - ImGui::PopStyleVar(); - - if (EnableAutoScrolling && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) - ImGui::SetScrollHereY(1.0f); - - ImGui::EndChild(); - } - - ImGui::End(); - } - - void ClearLogBuffers(IN bool DisableLock = false) - { - if (!DisableLock) - sink_t::mutex_.lock(); - - LoggedContent.clear(); - LogMetaData.clear(); - NumberOfLogEntries = 0; - IndicesInBytes = 0; - - if (!DisableLock) - sink_t::mutex_.unlock(); - } - -protected: - - // Writing version 2, this will accept ansi escape sequences for colors - void sink_it_(IN const spdlog::details::log_msg& LogMessage) final - { - // This is all protected by the base sink under a mutex - ++NumberOfLogEntries; - - // Format the logged message and push it into the text buffer - spdlog::memory_buf_t FormattedBuffer; - - sink_t::formatter_->format(LogMessage, FormattedBuffer); - - std::string FormattedText = FormattedBuffer; - - // Process string by converting the color range passed to an escape sequence first, - // yes may not be the nicest way of doing this but its way easier to process later. - const char* ColorToEscapeSequence[]{ ESC_BRIGHTMAGENTA, ESC_CYAN, ESC_BRIGHTGREEN, ESC_BRIGHTYELLOW, ESC_BRIGHTRED, ESC_RED }; - - FormattedText.insert(LogMessage.color_range_start, ColorToEscapeSequence[LogMessage.level]); - FormattedText.insert(LogMessage.color_range_end + 5, "\x1b[0m"); - - bool FilterPassing = LogMessage.level >= FilterLogLevel; - FilterPassing &= FilterTextMatch.PassFilter(FormattedText.c_str(), FormattedText.c_str() + FormattedText.size()); - - // Parse formatted logged string for ansi escape sequences - auto OldTextBufferSize = LoggedContent.size(); - SinkLineContent MessageData2{ LogMessage.level, OldTextBufferSize }; - - AnsiEscapeSequenceTag LastSequenceTagSinceBegin = FORMAT_RESET_COLORS; - - // Prematurely filter out immediately starting non default formats, - // and then enter the main processing loop - switch (FormattedText[0]) - { - case '\x1b': - case '\n': - break; - - default: - - SinkLineContent::ColorDataRanges FormatPush{ 0, 0, LastSequenceTagSinceBegin }; - MessageData2.FormattedStringRanges.push_back(FormatPush); - break; - } - - for (auto i = 0; i < FormattedText.size(); ++i) - { - switch (FormattedText[i]) { - case '\n': { - - // Handle new line bullshit, spdlog will terminate any logged message witha new line - // we can also assume this may not be the last line, so we continue the previous sequence into - // the next logically text line if necessary and reconfigure pushstate - if (MessageData2.FormattedStringRanges.size()) - MessageData2.FormattedStringRanges.back().SubStringEnd = i; - if (FilterPassing) - FilteredView.push_back(LogMetaData.size()); - LogMetaData.push_back(MessageData2); - - IndicesInBytes += MessageData2.FormattedStringRanges.size() * - sizeof(SinkLineContent::ColorDataRanges) + - sizeof(SinkLineContent); - MessageData2.LogLevel = spdlog::level::n_levels; - MessageData2.BeginIndex = OldTextBufferSize + i + 1; - MessageData2.FormattedStringRanges.clear(); - - // Continue previous escape sequences pushed in the previous line - SinkLineContent::ColorDataRanges FormatPush{ - i + 1, 0, LastSequenceTagSinceBegin - }; - MessageData2.FormattedStringRanges.push_back(FormatPush); - } break; - case '\x1b': { - - // Handle ansi escape sequence, convert textual to operand - if (FormattedText[i + 1] != '[') - throw std::runtime_error("Invalid ansi escape sequence passed"); - - size_t PositionProcessed = 0; - auto EscapeSequenceCode = static_cast( - std::stoi(&FormattedText[i + 2], - &PositionProcessed)); // this may throw, in which case we let it pass down - - if (FormattedText[i + 2 + PositionProcessed] != 'm') - throw std::runtime_error("Invalid ansi escape sequence operand was passed"); - ++PositionProcessed; - LastSequenceTagSinceBegin = EscapeSequenceCode; - - SinkLineContent::ColorDataRanges FormatPush{ - i, 0, EscapeSequenceCode - }; - if (MessageData2.FormattedStringRanges.size()) - MessageData2.FormattedStringRanges.back().SubStringEnd = FormatPush.SubStringBegin; - MessageData2.FormattedStringRanges.push_back(FormatPush); - - // Now the escape code has to be removed from the string, - // the iterator has to be kept stable, otherwise the next round could skip a char - FormattedText.erase(FormattedText.begin() + i--, - FormattedText.begin() + (i + 2 + PositionProcessed)); - } - } - } - - // Append processed string to log text buffer - LoggedContent.append(FormattedText.c_str(), FormattedText.c_str() + FormattedText.size()); - } - - void flush_() - { - } - -private: - - // TODO: Need to implement double buffering for the filter - void RebuildFilterWithPreviousStates() - { - int32_t RebuildType = PreviousFilterLevel != FilterLogLevel; - - RebuildType |= memcmp(PreviousFilterText, FilterTextMatch.InputBuf, sizeof(PreviousFilterText)); - - if (RebuildType) - { - // Filter was completely changed, have to rebuild array (very expensive, - // this may result in short freezes or stuttering on really large logs, - // one way to solve this could be to defer the calculation of the filter view - // to a thread pool and use a double buffering mechanism) - - auto NewLinePasses = false; - FilteredView.clear(); - - for (auto i = 0; i < LogMetaData.size(); ++i) - { - - if (LogMetaData[i].LogLevel == spdlog::level::n_levels&&) - { - FilteredView.push_back(i); - continue; - } - - if (LogMetaData[i].LogLevel < FilterLogLevel) - { - NewLinePasses = false; - continue; - } - - auto LineBegin = LoggedContent.begin() + LogMetaData[i].BeginIndex + LogMetaData[i].FormattedStringRanges.front().SubStringBegin; - auto LineEnd = LoggedContent.begin() + LogMetaData[i].BeginIndex + LogMetaData[i].FormattedStringRanges.back().SubStringEnd; - - if (!FilterTextMatch.PassFilter(LineBegin, LineEnd)) - { - NewLinePasses = false; - continue; - } - - NewLinePasses = true; - FilteredView.push_back(i); - } - } - - PreviousFilterLevel = FilterLogLevel; - memcpy(PreviousFilterText, FilterTextMatch.InputBuf, sizeof(PreviousFilterText)); - } - - // Using faster more efficient replacements of stl types for rendering - ImGuiTextBuffer LoggedContent; - - // Cannot use ImVetctor here as the type is not trivially copyable - std::vector LogMetaData; - - // the type has to be moved into, slightly more expensive - // but overall totally fine, at least no weird hacks - ImGuiTextFilter FilterTextMatch; - - // A filtered array of indexes into the LogMetaData vector - ImVector FilteredView; - - // this view is calculated once any filter changes - int32_t FilterLogLevel = spdlog::level::trace; - - // Counts the number of entries logged - uint32_t NumberOfLogEntries = 0; - - // Keeps track of the amount of memory allocated by indices - uint32_t IndicesInBytes = 0; - bool EnableAutoScrolling = true; - - // Previous Frame's filterdata, if any of these change to the new values the filter has to be recalculated - int32_t PreviousFilterLevel = spdlog::level::trace; - decltype(ImGuiTextFilter::InputBuf) PreviousFilterText{}; -}; diff --git a/OptiScaler/menu/ImguiSpdLog.h b/OptiScaler/menu/ImguiSpdLog.h deleted file mode 100644 index e0f46b92..00000000 --- a/OptiScaler/menu/ImguiSpdLog.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "../pch.h" -#include "spdlog/sinks/base_sink.h" -#include "imgui/imgui.h" diff --git a/OptiScaler/menu/MenuBase.cpp b/OptiScaler/menu/MenuBase.cpp new file mode 100644 index 00000000..4c9abc9c --- /dev/null +++ b/OptiScaler/menu/MenuBase.cpp @@ -0,0 +1,72 @@ +#include "MenuBase.h" + +#include +#include +#include +#include "MenuCommon.h" + +#include +#include + + +HWND MenuBase::Handle() +{ + return MenuCommon::Handle(); +} + +void MenuBase::Dx11Ready() +{ + MenuCommon::Dx11Inited(); +} + +void MenuBase::Dx12Ready() +{ + MenuCommon::Dx12Inited(); +} + +void MenuBase::VulkanReady() +{ + MenuCommon::VulkanInited(); +} + +bool MenuBase::IsInited() +{ + return MenuCommon::IsInited(); +} + +bool MenuBase::IsVisible() +{ + return MenuCommon::IsVisible(); +} + +bool MenuBase::IsResetRequested() +{ + return MenuCommon::IsResetRequested(); +} + +void MenuBase::Init(HWND InHandle) +{ + if (!Config::Instance()->OverlayMenu.value_or(true)) + return; + + LOG_FUNC(); + MenuCommon::Init(InHandle); +} + +void MenuBase::RenderMenu() +{ + if (!Config::Instance()->OverlayMenu.value_or(true)) + return; + + MenuCommon::RenderMenu(); +} + +void MenuBase::Shutdown() +{ + MenuCommon::Shutdown(); +} + +void MenuBase::HideMenu() +{ + MenuCommon::HideMenu(); +} diff --git a/OptiScaler/menu/imgui_overlay_base.h b/OptiScaler/menu/MenuBase.h similarity index 93% rename from OptiScaler/menu/imgui_overlay_base.h rename to OptiScaler/menu/MenuBase.h index 9d26d812..5622f096 100644 --- a/OptiScaler/menu/imgui_overlay_base.h +++ b/OptiScaler/menu/MenuBase.h @@ -5,9 +5,6 @@ #include #include - -// LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - typedef HRESULT(__fastcall* PFN_Present)(IDXGISwapChain*, UINT, UINT); typedef HRESULT(__fastcall* PFN_Present1)(IDXGISwapChain1*, UINT, UINT, const DXGI_PRESENT_PARAMETERS*); typedef HRESULT(__fastcall* PFN_ResizeBuffers)(IDXGISwapChain*, UINT, UINT, UINT, DXGI_FORMAT, UINT); @@ -17,7 +14,7 @@ typedef HRESULT(__fastcall* PFN_CreateSwapChainForHwnd)(IDXGIFactory*, IUnknown* typedef HRESULT(__fastcall* PFN_CreateSwapChainForCoreWindow)(IDXGIFactory*, IUnknown*, IUnknown*, const DXGI_SWAP_CHAIN_DESC1*, IDXGIOutput*, IDXGISwapChain1**); typedef HRESULT(__fastcall* PFN_CreateSwapChainForComposition)(IDXGIFactory*, IUnknown*, const DXGI_SWAP_CHAIN_DESC1*, IDXGIOutput*, IDXGISwapChain1**); -class ImGuiOverlayBase +class MenuBase { public: static HWND Handle(); diff --git a/OptiScaler/menu/imgui_common.cpp b/OptiScaler/menu/MenuCommon.cpp similarity index 98% rename from OptiScaler/menu/imgui_common.cpp rename to OptiScaler/menu/MenuCommon.cpp index c948b82d..94439bd3 100644 --- a/OptiScaler/menu/imgui_common.cpp +++ b/OptiScaler/menu/MenuCommon.cpp @@ -1,6 +1,6 @@ -#include "imgui_common.h" +#include "MenuCommon.h" -void ImGuiCommon::ShowTooltip(const char* tip) { +void MenuCommon::ShowTooltip(const char* tip) { if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); @@ -10,14 +10,14 @@ void ImGuiCommon::ShowTooltip(const char* tip) { } } -void ImGuiCommon::ShowHelpMarker(const char* tip) +void MenuCommon::ShowHelpMarker(const char* tip) { ImGui::SameLine(); ImGui::TextDisabled("(?)"); ShowTooltip(tip); } -LRESULT __stdcall ImGuiCommon::hkSendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +LRESULT __stdcall MenuCommon::hkSendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { if (_isVisible && Msg == 0x0020) return TRUE; @@ -25,7 +25,7 @@ LRESULT __stdcall ImGuiCommon::hkSendMessageW(HWND hWnd, UINT Msg, WPARAM wParam return pfn_SendMessageW(hWnd, Msg, wParam, lParam); } -BOOL __stdcall ImGuiCommon::hkSetPhysicalCursorPos(int x, int y) +BOOL __stdcall MenuCommon::hkSetPhysicalCursorPos(int x, int y) { if (_isVisible) return TRUE; @@ -33,7 +33,7 @@ BOOL __stdcall ImGuiCommon::hkSetPhysicalCursorPos(int x, int y) return pfn_SetPhysicalCursorPos(x, y); } -BOOL __stdcall ImGuiCommon::hkSetCursorPos(int x, int y) +BOOL __stdcall MenuCommon::hkSetCursorPos(int x, int y) { if (_isVisible) return TRUE; @@ -41,7 +41,7 @@ BOOL __stdcall ImGuiCommon::hkSetCursorPos(int x, int y) return pfn_SetCursorPos(x, y); } -BOOL __stdcall ImGuiCommon::hkClipCursor(RECT* lpRect) +BOOL __stdcall MenuCommon::hkClipCursor(RECT* lpRect) { if (_isVisible) return TRUE; @@ -52,7 +52,7 @@ BOOL __stdcall ImGuiCommon::hkClipCursor(RECT* lpRect) } } -void __stdcall ImGuiCommon::hkmouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo) +void __stdcall MenuCommon::hkmouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo) { if (_isVisible) return; @@ -60,7 +60,7 @@ void __stdcall ImGuiCommon::hkmouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWO pfn_mouse_event(dwFlags, dx, dy, dwData, dwExtraInfo); } -UINT __stdcall ImGuiCommon::hkSendInput(UINT cInputs, LPINPUT pInputs, int cbSize) +UINT __stdcall MenuCommon::hkSendInput(UINT cInputs, LPINPUT pInputs, int cbSize) { if (_isVisible) return TRUE; @@ -68,7 +68,7 @@ UINT __stdcall ImGuiCommon::hkSendInput(UINT cInputs, LPINPUT pInputs, int cbSiz return pfn_SendInput(cInputs, pInputs, cbSize); } -void ImGuiCommon::AttachHooks() +void MenuCommon::AttachHooks() { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); @@ -102,7 +102,7 @@ void ImGuiCommon::AttachHooks() DetourTransactionCommit(); } -void ImGuiCommon::DetachHooks() +void MenuCommon::DetachHooks() { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); @@ -140,7 +140,7 @@ void ImGuiCommon::DetachHooks() DetourTransactionCommit(); } -ImGuiKey ImGuiCommon::ImGui_ImplWin32_VirtualKeyToImGuiKey(WPARAM wParam) +ImGuiKey MenuCommon::ImGui_ImplWin32_VirtualKeyToImGuiKey(WPARAM wParam) { switch (wParam) { @@ -267,7 +267,7 @@ ImGuiKey ImGuiCommon::ImGui_ImplWin32_VirtualKeyToImGuiKey(WPARAM wParam) //Win32 message handler -LRESULT __stdcall ImGuiCommon::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +LRESULT __stdcall MenuCommon::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); (void)io; @@ -482,7 +482,7 @@ LRESULT __stdcall ImGuiCommon::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARA return CallWindowProc(_oWndProc, hWnd, msg, wParam, lParam); } -std::string ImGuiCommon::GetBackendName(std::string* code) +std::string MenuCommon::GetBackendName(std::string* code) { if (*code == "fsr21") return "FSR 2.1.2"; @@ -511,7 +511,7 @@ std::string ImGuiCommon::GetBackendName(std::string* code) return "????"; } -std::string ImGuiCommon::GetBackendCode(const NVNGX_Api api) +std::string MenuCommon::GetBackendCode(const NVNGX_Api api) { std::string code; @@ -525,13 +525,13 @@ std::string ImGuiCommon::GetBackendCode(const NVNGX_Api api) return code; } -void ImGuiCommon::GetCurrentBackendInfo(const NVNGX_Api api, std::string* code, std::string* name) +void MenuCommon::GetCurrentBackendInfo(const NVNGX_Api api, std::string* code, std::string* name) { *code = GetBackendCode(api); *name = GetBackendName(code); } -void ImGuiCommon::AddDx11Backends(std::string* code, std::string* name) +void MenuCommon::AddDx11Backends(std::string* code, std::string* name) { std::string selectedUpscalerName = ""; @@ -579,7 +579,7 @@ void ImGuiCommon::AddDx11Backends(std::string* code, std::string* name) } } -void ImGuiCommon::AddDx12Backends(std::string* code, std::string* name) +void MenuCommon::AddDx12Backends(std::string* code, std::string* name) { std::string selectedUpscalerName = ""; @@ -615,7 +615,7 @@ void ImGuiCommon::AddDx12Backends(std::string* code, std::string* name) } } -void ImGuiCommon::AddVulkanBackends(std::string* code, std::string* name) +void MenuCommon::AddVulkanBackends(std::string* code, std::string* name) { std::string selectedUpscalerName = ""; @@ -646,7 +646,7 @@ void ImGuiCommon::AddVulkanBackends(std::string* code, std::string* name) } } -void ImGuiCommon::AddResourceBarrier(std::string name, std::optional* value) +void MenuCommon::AddResourceBarrier(std::string name, std::optional* value) { const char* states[] = { "AUTO", "COMMON", "VERTEX_AND_CONSTANT_BUFFER", "INDEX_BUFFER", "RENDER_TARGET", "UNORDERED_ACCESS", "DEPTH_WRITE", "DEPTH_READ", "NON_PIXEL_SHADER_RESOURCE", "PIXEL_SHADER_RESOURCE", "STREAM_OUT", "INDIRECT_ARGUMENT", "COPY_DEST", "COPY_SOURCE", @@ -685,7 +685,7 @@ void ImGuiCommon::AddResourceBarrier(std::string name, std::optional* value } } -void ImGuiCommon::AddRenderPreset(std::string name, std::optional* value) +void MenuCommon::AddRenderPreset(std::string name, std::optional* value) { const char* presets[] = { "DEFAULT", "PRESET A", "PRESET B", "PRESET C", "PRESET D", "PRESET E", "PRESET F", "PRESET G" }; const char* presetsDesc[] = { "Whatever the game uses", @@ -701,7 +701,7 @@ void ImGuiCommon::AddRenderPreset(std::string name, std::optional* val PopulateCombo(name, value, presets, presetsDesc, 8); } -void ImGuiCommon::PopulateCombo(std::string name, std::optional* value, const char* names[], const char* desc[], int length) { +void MenuCommon::PopulateCombo(std::string name, std::optional* value, const char* names[], const char* desc[], int length) { int selected = value->value_or(0); const char* selectedName = ""; @@ -735,7 +735,7 @@ void ImGuiCommon::PopulateCombo(std::string name, std::optional* value } } -void ImGuiCommon::RenderMenu() +void MenuCommon::RenderMenu() { if (!_isInited || !_isVisible) return; @@ -2095,7 +2095,7 @@ void ImGuiCommon::RenderMenu() } } -void ImGuiCommon::Init(HWND InHwnd) +void MenuCommon::Init(HWND InHwnd) { _handle = InHwnd; _isVisible = false; @@ -2146,9 +2146,9 @@ void ImGuiCommon::Init(HWND InHwnd) } } -void ImGuiCommon::Shutdown() +void MenuCommon::Shutdown() { - if (!ImGuiCommon::_isInited) + if (!MenuCommon::_isInited) return; @@ -2169,7 +2169,7 @@ void ImGuiCommon::Shutdown() _isResetRequested = false; } -void ImGuiCommon::HideMenu() +void MenuCommon::HideMenu() { if (!_isVisible) return; diff --git a/OptiScaler/menu/imgui_common.h b/OptiScaler/menu/MenuCommon.h similarity index 99% rename from OptiScaler/menu/imgui_common.h rename to OptiScaler/menu/MenuCommon.h index 3890aa53..4fe3a96f 100644 --- a/OptiScaler/menu/imgui_common.h +++ b/OptiScaler/menu/MenuCommon.h @@ -1,6 +1,7 @@ #pragma once #include + #include #include #include @@ -11,7 +12,7 @@ extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -class ImGuiCommon +class MenuCommon { private: // internal values diff --git a/OptiScaler/menu/imgui_overlay_dx.cpp b/OptiScaler/menu/MenuDx.cpp similarity index 94% rename from OptiScaler/menu/imgui_overlay_dx.cpp rename to OptiScaler/menu/MenuDx.cpp index 582d10b1..cdd298d1 100644 --- a/OptiScaler/menu/imgui_overlay_dx.cpp +++ b/OptiScaler/menu/MenuDx.cpp @@ -1,10 +1,10 @@ -#include "imgui_overlay_dx.h" +#include "MenuDx.h" #include #include #include #include "wrapped_swapchain.h" -#include "imgui_overlay_base.h" +#include "MenuBase.h" #include #include @@ -13,9 +13,6 @@ #include #include - - - // dxgi stuff typedef HRESULT(*PFN_CreateDXGIFactory)(REFIID riid, IDXGIFactory** ppFactory); typedef HRESULT(*PFN_CreateDXGIFactory1)(REFIID riid, IDXGIFactory1** ppFactory); @@ -171,7 +168,7 @@ static void CleanupRenderTargetDx12(bool clearQueue) if (clearQueue) { - if (ImGuiOverlayBase::IsInited() && g_pd3dDeviceParam != nullptr && g_pd3dSrvDescHeap != nullptr && ImGui::GetIO().BackendRendererUserData) + if (MenuBase::IsInited() && g_pd3dDeviceParam != nullptr && g_pd3dSrvDescHeap != nullptr && ImGui::GetIO().BackendRendererUserData) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); ImGui_ImplDX12_Shutdown(); @@ -323,7 +320,7 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags LOG_DEBUG("D3D12CommandQueue captured"); currentSCCommandQueue = pDevice; - ImGuiOverlayDx::GameCommandQueue = (ID3D12CommandQueue*)pDevice; + MenuDx::GameCommandQueue = (ID3D12CommandQueue*)pDevice; if (cq->GetDevice(IID_PPV_ARGS(&device12)) == S_OK) { @@ -356,12 +353,12 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags } // Upscaler GPU time computation - if (ImGuiOverlayDx::dx12UpscaleTrig && ImGuiOverlayDx::readbackBuffer != nullptr && ImGuiOverlayDx::queryHeap != nullptr && cq != nullptr) + if (MenuDx::dx12UpscaleTrig && MenuDx::readbackBuffer != nullptr && MenuDx::queryHeap != nullptr && cq != nullptr) { - if (ImGuiOverlayBase::IsInited() && ImGuiOverlayBase::IsVisible()) + if (MenuBase::IsInited() && MenuBase::IsVisible()) { UINT64* timestampData; - ImGuiOverlayDx::readbackBuffer->Map(0, nullptr, reinterpret_cast(×tampData)); + MenuDx::readbackBuffer->Map(0, nullptr, reinterpret_cast(×tampData)); // Get the GPU timestamp frequency (ticks per second) UINT64 gpuFrequency; @@ -376,28 +373,28 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags Config::Instance()->upscaleTimes.pop_front(); // Unmap the buffer - ImGuiOverlayDx::readbackBuffer->Unmap(0, nullptr); + MenuDx::readbackBuffer->Unmap(0, nullptr); } - ImGuiOverlayDx::dx12UpscaleTrig = false; + MenuDx::dx12UpscaleTrig = false; } - else if (ImGuiOverlayDx::dx11UpscaleTrig[ImGuiOverlayDx::currentFrameIndex] && device != nullptr && ImGuiOverlayDx::disjointQueries[0] != nullptr && - ImGuiOverlayDx::startQueries[0] != nullptr && ImGuiOverlayDx::endQueries[0] != nullptr) + else if (MenuDx::dx11UpscaleTrig[MenuDx::currentFrameIndex] && device != nullptr && MenuDx::disjointQueries[0] != nullptr && + MenuDx::startQueries[0] != nullptr && MenuDx::endQueries[0] != nullptr) { if (g_pd3dDeviceContext == nullptr) device->GetImmediateContext(&g_pd3dDeviceContext); - if (ImGuiOverlayBase::IsInited() && ImGuiOverlayBase::IsVisible()) + if (MenuBase::IsInited() && MenuBase::IsVisible()) { // Retrieve the results from the previous frame D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointData; - if (g_pd3dDeviceContext->GetData(ImGuiOverlayDx::disjointQueries[ImGuiOverlayDx::previousFrameIndex], &disjointData, sizeof(disjointData), 0) == S_OK) + if (g_pd3dDeviceContext->GetData(MenuDx::disjointQueries[MenuDx::previousFrameIndex], &disjointData, sizeof(disjointData), 0) == S_OK) { if (!disjointData.Disjoint && disjointData.Frequency > 0) { UINT64 startTime = 0, endTime = 0; - if (g_pd3dDeviceContext->GetData(ImGuiOverlayDx::startQueries[ImGuiOverlayDx::previousFrameIndex], &startTime, sizeof(UINT64), 0) == S_OK && - g_pd3dDeviceContext->GetData(ImGuiOverlayDx::endQueries[ImGuiOverlayDx::previousFrameIndex], &endTime, sizeof(UINT64), 0) == S_OK) + if (g_pd3dDeviceContext->GetData(MenuDx::startQueries[MenuDx::previousFrameIndex], &startTime, sizeof(UINT64), 0) == S_OK && + g_pd3dDeviceContext->GetData(MenuDx::endQueries[MenuDx::previousFrameIndex], &endTime, sizeof(UINT64), 0) == S_OK) { double elapsedTimeMs = (endTime - startTime) / static_cast(disjointData.Frequency) * 1000.0; Config::Instance()->upscaleTimes.push_back(elapsedTimeMs); @@ -408,19 +405,19 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags } - ImGuiOverlayDx::dx11UpscaleTrig[ImGuiOverlayDx::currentFrameIndex] = false; - ImGuiOverlayDx::currentFrameIndex = (ImGuiOverlayDx::currentFrameIndex + 1) % ImGuiOverlayDx::QUERY_BUFFER_COUNT; + MenuDx::dx11UpscaleTrig[MenuDx::currentFrameIndex] = false; + MenuDx::currentFrameIndex = (MenuDx::currentFrameIndex + 1) % MenuDx::QUERY_BUFFER_COUNT; } // Process window handle changed, update base - if (ImGuiOverlayBase::Handle() != hWnd) + if (MenuBase::Handle() != hWnd) { LOG_DEBUG("Handle changed"); - if (ImGuiOverlayBase::IsInited()) - ImGuiOverlayBase::Shutdown(); + if (MenuBase::IsInited()) + MenuBase::Shutdown(); - ImGuiOverlayBase::Init(hWnd); + MenuBase::Init(hWnd); _isInited = false; } @@ -436,7 +433,7 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags g_pd3dDevice->AddRef(); CreateRenderTargetDx11(pSwapChain); - ImGuiOverlayBase::Dx11Ready(); + MenuBase::Dx11Ready(); _isInited = true; } else if (_dx12Device && (g_pd3dDeviceParam != nullptr || device12 != nullptr)) @@ -452,7 +449,7 @@ static HRESULT Present(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags g_pd3dCommandQueue->AddRef(); g_pd3dDeviceParam->AddRef(); - ImGuiOverlayBase::Dx12Ready(); + MenuBase::Dx12Ready(); _isInited = true; } } @@ -1230,11 +1227,11 @@ static void RenderImGui_DX11(IDXGISwapChain* pSwapChain) do { - if (!ImGuiOverlayBase::IsInited()) + if (!MenuBase::IsInited()) break; // Draw only when menu activated - if (!ImGuiOverlayBase::IsVisible()) + if (!MenuBase::IsVisible()) break; if (!_dx11Device || g_pd3dDevice == nullptr) @@ -1246,7 +1243,7 @@ static void RenderImGui_DX11(IDXGISwapChain* pSwapChain) if (!drawMenu) { - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); return; } @@ -1271,7 +1268,7 @@ static void RenderImGui_DX11(IDXGISwapChain* pSwapChain) ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); - ImGuiOverlayBase::RenderMenu(); + MenuBase::RenderMenu(); ImGui::Render(); @@ -1291,11 +1288,11 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (pSwapChainPlain->QueryInterface(IID_PPV_ARGS(&pSwapChain)) != S_OK || pSwapChain == nullptr) return; - if (!ImGuiOverlayBase::IsInited()) + if (!MenuBase::IsInited()) break; // Draw only when menu activated - if (!ImGuiOverlayBase::IsVisible()) + if (!MenuBase::IsVisible()) break; if (!_dx12Device || g_pd3dCommandQueue == nullptr || g_pd3dDeviceParam == nullptr) @@ -1307,7 +1304,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (!drawMenu) { - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); auto releaseResult = pSwapChain->Release(); return; } @@ -1335,7 +1332,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (result != S_OK) { LOG_ERROR("CreateDescriptorHeap(g_pd3dRtvDescHeap): {0:X}", (unsigned long)result); - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); CleanupRenderTargetDx12(true); pSwapChain->Release(); return; @@ -1361,7 +1358,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (result != S_OK) { LOG_ERROR("CreateDescriptorHeap(g_pd3dSrvDescHeap): {0:X}", (unsigned long)result); - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); CleanupRenderTargetDx12(true); pSwapChain->Release(); return; @@ -1375,7 +1372,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (result != S_OK) { LOG_ERROR("CreateCommandAllocator[{0}]: {1:X}", i, (unsigned long)result); - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); CleanupRenderTargetDx12(true); pSwapChain->Release(); return; @@ -1386,7 +1383,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (result != S_OK) { LOG_ERROR("CreateCommandList: {0:X}", (unsigned long)result); - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); CleanupRenderTargetDx12(true); pSwapChain->Release(); return; @@ -1396,7 +1393,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (result != S_OK) { LOG_ERROR("g_pd3dCommandList->Close: {0:X}", (unsigned long)result); - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); CleanupRenderTargetDx12(false); pSwapChain->Release(); return; @@ -1427,7 +1424,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) ImGui_ImplDX12_NewFrame(); ImGui_ImplWin32_NewFrame(); - ImGuiOverlayBase::RenderMenu(); + MenuBase::RenderMenu(); ImGui::Render(); @@ -1488,7 +1485,7 @@ static void RenderImGui_DX12(IDXGISwapChain* pSwapChainPlain) if (_showRenderImGuiDebugOnce) LOG_INFO("!(ImGui::GetCurrentContext() && g_pd3dCommandQueue && g_mainRenderTargetResource[0])"); - ImGuiOverlayBase::HideMenu(); + MenuBase::HideMenu(); _showRenderImGuiDebugOnce = false; } } @@ -1552,7 +1549,7 @@ void DeatachAllHooks() DetourTransactionCommit(); } -void ImGuiOverlayDx::HookDx() +void MenuDx::HookDx() { if (_isInited) return; @@ -1610,11 +1607,11 @@ void ImGuiOverlayDx::HookDx() } } -void ImGuiOverlayDx::UnHookDx() +void MenuDx::UnHookDx() { if (!Config::Instance()->IsRunningOnDXVK) { - if (_isInited && ImGuiOverlayBase::IsInited() && ImGui::GetIO().BackendRendererUserData) + if (_isInited && MenuBase::IsInited() && ImGui::GetIO().BackendRendererUserData) { if (_dx11Device) ImGui_ImplDX11_Shutdown(); @@ -1622,7 +1619,7 @@ void ImGuiOverlayDx::UnHookDx() ImGui_ImplDX12_Shutdown(); } - ImGuiOverlayBase::Shutdown(); + MenuBase::Shutdown(); if (_isInited) { diff --git a/OptiScaler/menu/imgui_overlay_dx.h b/OptiScaler/menu/MenuDx.h similarity index 96% rename from OptiScaler/menu/imgui_overlay_dx.h rename to OptiScaler/menu/MenuDx.h index 1400e087..76d93e32 100644 --- a/OptiScaler/menu/imgui_overlay_dx.h +++ b/OptiScaler/menu/MenuDx.h @@ -5,7 +5,7 @@ #include #include -namespace ImGuiOverlayDx +namespace MenuDx { inline ID3D12QueryHeap* queryHeap = nullptr; inline ID3D12Resource* readbackBuffer = nullptr; diff --git a/OptiScaler/menu/imgui_overlay_vk.cpp b/OptiScaler/menu/MenuVulkan.cpp similarity index 68% rename from OptiScaler/menu/imgui_overlay_vk.cpp rename to OptiScaler/menu/MenuVulkan.cpp index c72b7aff..7b8d9877 100644 --- a/OptiScaler/menu/imgui_overlay_vk.cpp +++ b/OptiScaler/menu/MenuVulkan.cpp @@ -1,14 +1,13 @@ -#include "imgui_overlay_vk.h" +#include "MenuVulkan.h" #include #include -#include "imgui_overlay_base.h" +#include "MenuBase.h" #include #include #include - // Vulkan overlay code adopted from here: // https://gist.github.com/mem99/0ec31ca302927457f86b1d6756aaa8c4 // Need to check resize & recreate fixes @@ -39,21 +38,6 @@ struct ImGui_ImplVulkanH_Frame* _ImVulkan_Frames = VK_NULL_HANDLE; static VkSemaphore* _ImVulkan_Semaphores = VK_NULL_HANDLE; static VkRenderPass _vkRenderPass = VK_NULL_HANDLE; -// hooking -typedef VkResult(*PFN_QueuePresentKHR)(VkQueue, const VkPresentInfoKHR*); -typedef VkResult(*PFN_CreateSwapchainKHR)(VkDevice, const VkSwapchainCreateInfoKHR*, const VkAllocationCallbacks*, VkSwapchainKHR*); -typedef VkResult(*PFN_vkCreateWin32SurfaceKHR)(VkInstance, const VkWin32SurfaceCreateInfoKHR*, const VkAllocationCallbacks*, VkSurfaceKHR*); - -PFN_vkCreateDevice o_vkCreateDevice = nullptr; -PFN_vkCreateInstance o_vkCreateInstance = nullptr; -PFN_vkCreateWin32SurfaceKHR o_vkCreateWin32SurfaceKHR = nullptr; -PFN_QueuePresentKHR o_QueuePresentKHR = nullptr; -PFN_CreateSwapchainKHR o_CreateSwapchainKHR = nullptr; - -static VkResult hkvkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice); -static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo); -static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain); - static void DestroyVulkanObjects(bool shutdown) { if (_ImVulkan_Info.Device == VK_NULL_HANDLE) @@ -146,13 +130,13 @@ static void CreateVulkanObjects(VkDevice device, const VkSwapchainCreateInfoKHR* } // Initialize ImGui - if (!ImGuiOverlayBase::IsInited() || ImGuiOverlayBase::Handle() != _hwnd) + if (!MenuBase::IsInited() || MenuBase::Handle() != _hwnd) { - if (ImGuiOverlayBase::IsInited()) - ImGuiOverlayBase::Shutdown(); + if (MenuBase::IsInited()) + MenuBase::Shutdown(); - LOG_DEBUG("ImGuiOverlayBase::Init"); - ImGuiOverlayBase::Init(_hwnd); + LOG_DEBUG("MenuBase::Init"); + MenuBase::Init(_hwnd); } ImGuiIO& io = ImGui::GetIO(); @@ -470,137 +454,59 @@ static void CreateVulkanObjects(VkDevice device, const VkSwapchainCreateInfoKHR* LOG_FUNC_RESULT(_vulkanObjectsCreated); } -static void HookDevice(VkDevice InDevice) +void MenuVulkan::CreateSurface(VkInstance instance, HWND hwnd) { - if (o_CreateSwapchainKHR != nullptr || Config::Instance()->VulkanSkipHooks) - return; + DestroyVulkanObjects(false); - LOG_FUNC(); - - o_QueuePresentKHR = (PFN_QueuePresentKHR)(vkGetDeviceProcAddr(InDevice, "vkQueuePresentKHR")); - o_CreateSwapchainKHR = (PFN_CreateSwapchainKHR)(vkGetDeviceProcAddr(InDevice, "vkCreateSwapchainKHR")); - - if (o_CreateSwapchainKHR) - { - LOG_DEBUG("Hooking VkDevice"); - - // Hook - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - - DetourAttach(&(PVOID&)o_QueuePresentKHR, hkvkQueuePresentKHR); - DetourAttach(&(PVOID&)o_CreateSwapchainKHR, hkvkCreateSwapchainKHR); - - DetourTransactionCommit(); - } + _instance = instance; + LOG_DEBUG("_instance captured: {0:X}", (UINT64)_instance); + _hwnd = hwnd; + LOG_DEBUG("_hwnd captured: {0:X}", (UINT64)_hwnd); } -static VkResult hkvkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) +void MenuVulkan::CreateInstance(VkInstance* pInstance) { - LOG_FUNC(); - - auto result = o_vkCreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); - - auto procHwnd = Util::GetProcessWindow(); - LOG_DEBUG("procHwnd: {0:X}, swapchain hwnd: {1:X}", (UINT64)procHwnd, (UINT64)pCreateInfo->hwnd); - - if (result == VK_SUCCESS && !Config::Instance()->VulkanSkipHooks && procHwnd == pCreateInfo->hwnd) - { - DestroyVulkanObjects(false); - - _instance = instance; - LOG_DEBUG("_instance captured: {0:X}", (UINT64)_instance); - _hwnd = pCreateInfo->hwnd; - LOG_DEBUG("_hwnd captured: {0:X}", (UINT64)_hwnd); - } - - LOG_FUNC_RESULT(result); - - return result; + DestroyVulkanObjects(false); + _instance = *pInstance; + LOG_DEBUG("_instance captured: {0:X}", (UINT64)_instance); } -static VkResult hkvkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) +void MenuVulkan::CreateDevice(VkPhysicalDevice physicalDevice, VkDevice* pDevice) { - LOG_FUNC(); + DestroyVulkanObjects(false); - auto result = o_vkCreateInstance(pCreateInfo, pAllocator, pInstance); - - if (result == VK_SUCCESS && !Config::Instance()->VulkanSkipHooks) - { - DestroyVulkanObjects(false); - - _instance = *pInstance; - LOG_DEBUG("_instance captured: {0:X}", (UINT64)_instance); - } - - LOG_FUNC_RESULT(result); - - return result; + _PD = physicalDevice; + LOG_DEBUG("_PD captured: {0:X}", (UINT64)_PD); + _device = *pDevice; + LOG_DEBUG("_device captured: {0:X}", (UINT64)_device); } -static VkResult hkvkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) -{ - LOG_FUNC(); - - auto result = o_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice); - - if (result == VK_SUCCESS && !Config::Instance()->VulkanSkipHooks) - { - DestroyVulkanObjects(false); - - _PD = physicalDevice; - LOG_DEBUG("_PD captured: {0:X}", (UINT64)_PD); - _device = *pDevice; - LOG_DEBUG("_device captured: {0:X}", (UINT64)_device); - HookDevice(_device); - } - - LOG_FUNC_RESULT(result); - - return result; -} - -static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo) +VkResult MenuVulkan::QueuePresent(VkQueue queue, VkPresentInfoKHR* pPresentInfo) { LOG_FUNC(); if (!_vulkanObjectsCreated) { LOG_TRACE("!_vulkanObjectsCreated return o_QueuePresentKHR"); - - Config::Instance()->VulkanCreatingSC = true; - auto r0 = o_QueuePresentKHR(queue, pPresentInfo); - Config::Instance()->VulkanCreatingSC = false; - - if (r0 != VK_SUCCESS) - LOG_ERROR("r0 = o_QueuePresentKHR(queue, pPresentInfo): {0:X}", (UINT)r0); - - return r0; + return VK_INCOMPLETE; } - if (!ImGuiOverlayBase::IsInited() || !ImGuiOverlayBase::IsVisible() || _ImVulkan_Info.Device == VK_NULL_HANDLE) + if (!MenuBase::IsInited() || !MenuBase::IsVisible() || _ImVulkan_Info.Device == VK_NULL_HANDLE) { - Config::Instance()->VulkanCreatingSC = true; - auto r1 = o_QueuePresentKHR(queue, pPresentInfo); - Config::Instance()->VulkanCreatingSC = false; - - if (r1 != VK_SUCCESS) - LOG_ERROR("r1 = o_QueuePresentKHR(queue, pPresentInfo): {0:X}", (UINT)r1); - - return r1; + return VK_INCOMPLETE; } _vkPresentMutex.lock(); - if (ImGuiOverlayVk::vkUpscaleTrig && ImGuiOverlayVk::queryPool != VK_NULL_HANDLE) + if (MenuVulkan::vkUpscaleTrig && MenuVulkan::queryPool != VK_NULL_HANDLE) { // Retrieve timestamps uint64_t timestamps[2]; - vkGetQueryPoolResults(_device, ImGuiOverlayVk::queryPool, 0, 2, sizeof(timestamps), timestamps, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT); + vkGetQueryPoolResults(_device, MenuVulkan::queryPool, 0, 2, sizeof(timestamps), timestamps, sizeof(uint64_t), VK_QUERY_RESULT_64_BIT); // Calculate elapsed time in milliseconds - double elapsedTimeMs = (timestamps[1] - timestamps[0]) * ImGuiOverlayVk::timeStampPeriod / 1e6; + double elapsedTimeMs = (timestamps[1] - timestamps[0]) * MenuVulkan::timeStampPeriod / 1e6; if (elapsedTimeMs > 0.0 && elapsedTimeMs < 5000.0) { @@ -608,7 +514,7 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInf Config::Instance()->upscaleTimes.pop_front(); } - ImGuiOverlayVk::vkUpscaleTrig = false; + MenuVulkan::vkUpscaleTrig = false; } LOG_DEBUG("rendering menu, swapchain count: {0}", pPresentInfo->swapchainCount); @@ -621,7 +527,7 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInf ImGui_ImplVulkan_NewFrame(); ImGui_ImplWin32_NewFrame(); - ImGuiOverlayBase::RenderMenu(); + MenuBase::RenderMenu(); uint32_t idx = pPresentInfo->pImageIndices[scIndex]; ImGui_ImplVulkanH_Frame* fd = &_ImVulkan_Frames[idx]; @@ -705,117 +611,40 @@ static VkResult hkvkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInf return VK_ERROR_OUT_OF_DATE_KHR; } - // original call - Config::Instance()->VulkanCreatingSC = true; - auto result = o_QueuePresentKHR(queue, pPresentInfo); - Config::Instance()->VulkanCreatingSC = false; - LOG_FUNC_RESULT(result); _vkPresentMutex.unlock(); - return result; + + return VK_SUCCESS; } -static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain) +void MenuVulkan::CreateSwapchain(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, VkSwapchainKHR* pSwapchain) { - LOG_FUNC(); + Config::Instance()->ScreenWidth = pCreateInfo->imageExtent.width; + Config::Instance()->ScreenHeight = pCreateInfo->imageExtent.height; - Config::Instance()->VulkanCreatingSC = true; - auto result = o_CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain); - Config::Instance()->VulkanCreatingSC = false; + LOG_DEBUG("if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr && pSwapchain != VK_NULL_HANDLE)"); - if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr && *pSwapchain != VK_NULL_HANDLE && !Config::Instance()->VulkanSkipHooks) + _device = device; + LOG_DEBUG("_device captured: {0:X}", (UINT64)_device); + + if (MenuBase::Handle() != _hwnd) { - Config::Instance()->ScreenWidth = pCreateInfo->imageExtent.width; - Config::Instance()->ScreenHeight = pCreateInfo->imageExtent.height; + LOG_DEBUG("MenuBase::Handle() != _hwnd"); - LOG_DEBUG("if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr && pSwapchain != VK_NULL_HANDLE)"); - - _device = device; - LOG_DEBUG("_device captured: {0:X}", (UINT64)_device); - - if (ImGuiOverlayBase::Handle() != _hwnd) + if (MenuBase::IsInited()) { - LOG_DEBUG("ImGuiOverlayBase::Handle() != _hwnd"); - - if (ImGuiOverlayBase::IsInited()) - { - LOG_DEBUG("ImGuiOverlayBase::Shutdown();"); - ImGuiOverlayBase::Shutdown(); - } - - LOG_DEBUG("ImGuiOverlayBase::Init({0:X})", (UINT64)_hwnd); - ImGuiOverlayBase::Init(_hwnd); + LOG_DEBUG("MenuBase::Shutdown();"); + MenuBase::Shutdown(); } - CreateVulkanObjects(_device, pCreateInfo, pSwapchain); - - if (_ImVulkan_Info.Device != VK_NULL_HANDLE) - { - _isInited = true; - ImGuiOverlayBase::VulkanReady(); - } + LOG_DEBUG("MenuBase::Init({0:X})", (UINT64)_hwnd); + MenuBase::Init(_hwnd); } - LOG_FUNC_RESULT(result); - return result; -} + CreateVulkanObjects(_device, pCreateInfo, pSwapchain); -void ImGuiOverlayVk::HookVk() -{ - if (o_vkCreateDevice != nullptr) - return; - - o_vkCreateDevice = (PFN_vkCreateDevice)DetourFindFunction("vulkan-1.dll", "vkCreateDevice"); - o_vkCreateInstance = (PFN_vkCreateInstance)DetourFindFunction("vulkan-1.dll", "vkCreateInstance"); - o_vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)DetourFindFunction("vulkan-1.dll", "vkCreateWin32SurfaceKHR"); - - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - - if (o_vkCreateDevice != nullptr) - DetourAttach(&(PVOID&)o_vkCreateDevice, hkvkCreateDevice); - - if (o_vkCreateInstance != nullptr) - DetourAttach(&(PVOID&)o_vkCreateInstance, hkvkCreateInstance); - - if (o_vkCreateWin32SurfaceKHR != nullptr) - DetourAttach(&(PVOID&)o_vkCreateWin32SurfaceKHR, hkvkCreateWin32SurfaceKHR); - - DetourTransactionCommit(); -} - -void ImGuiOverlayVk::UnHookVk() -{ - if (_isInited) - ImGui_ImplVulkan_Shutdown(); - - ImGuiOverlayBase::Shutdown(); - - if (_vulkanObjectsCreated) - DestroyVulkanObjects(true); - - if (_isInited) + if (_ImVulkan_Info.Device != VK_NULL_HANDLE) { - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - - if (o_QueuePresentKHR != nullptr) - DetourDetach(&(PVOID&)o_QueuePresentKHR, hkvkQueuePresentKHR); - - if (o_CreateSwapchainKHR != nullptr) - DetourDetach(&(PVOID&)o_CreateSwapchainKHR, hkvkCreateSwapchainKHR); - - if (o_vkCreateDevice != nullptr) - DetourDetach(&(PVOID&)o_vkCreateDevice, hkvkCreateDevice); - - if (o_vkCreateInstance != nullptr) - DetourDetach(&(PVOID&)o_vkCreateInstance, hkvkCreateInstance); - - if (o_vkCreateWin32SurfaceKHR != nullptr) - DetourDetach(&(PVOID&)o_vkCreateWin32SurfaceKHR, hkvkCreateWin32SurfaceKHR); - - DetourTransactionCommit(); + _isInited = true; + MenuBase::VulkanReady(); } - - _isInited = false; - _vulkanObjectsCreated = false; } diff --git a/OptiScaler/menu/MenuVulkan.h b/OptiScaler/menu/MenuVulkan.h new file mode 100644 index 00000000..2fbc7564 --- /dev/null +++ b/OptiScaler/menu/MenuVulkan.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include + +class MenuVulkan +{ +private: + inline static VkQueryPool queryPool = VK_NULL_HANDLE; + inline static double timeStampPeriod = 1.0; + inline static bool vkUpscaleTrig = false; + +public: + static void CreateSurface(VkInstance instance, HWND hwnd); + static void CreateInstance(VkInstance* pInstance); + static void CreateDevice(VkPhysicalDevice physicalDevice, VkDevice* pDevice); + static VkResult QueuePresent(VkQueue queue, VkPresentInfoKHR* pPresentInfo); + static void CreateSwapchain(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, VkSwapchainKHR* pSwapchain); +}; diff --git a/OptiScaler/menu/imgui_dx_base.cpp b/OptiScaler/menu/OldMenuBase.cpp similarity index 50% rename from OptiScaler/menu/imgui_dx_base.cpp rename to OptiScaler/menu/OldMenuBase.cpp index 0680d443..1c83df69 100644 --- a/OptiScaler/menu/imgui_dx_base.cpp +++ b/OptiScaler/menu/OldMenuBase.cpp @@ -1,23 +1,23 @@ -#include +#include "OldMenuBase.h" #include #include #include #include -#include +#include #include -void ImguiDxBase::RenderMenu() +void OldMenuBase::RenderMenu() { if (Config::Instance()->OverlayMenu.value_or(true)) return; - ImGuiCommon::RenderMenu(); + MenuCommon::RenderMenu(); ImGui::Render(); } -bool ImguiDxBase::IsHandleDifferent() +bool OldMenuBase::IsHandleDifferent() { if (Config::Instance()->OverlayMenu.value_or(true)) return false; @@ -32,35 +32,35 @@ bool ImguiDxBase::IsHandleDifferent() return true; } -void ImguiDxBase::Dx11Ready() +void OldMenuBase::Dx11Ready() { - ImGuiCommon::Dx11Inited(); + MenuCommon::Dx11Inited(); } -void ImguiDxBase::Dx12Ready() +void OldMenuBase::Dx12Ready() { - ImGuiCommon::Dx12Inited(); + MenuCommon::Dx12Inited(); } -ImguiDxBase::ImguiDxBase(HWND handle) : _handle(handle) +OldMenuBase::OldMenuBase(HWND handle) : _handle(handle) { if (Config::Instance()->OverlayMenu.value_or(true)) return; - ImGuiCommon::Init(handle); + MenuCommon::Init(handle); - _baseInit = ImGuiCommon::IsInited(); + _baseInit = MenuCommon::IsInited(); } -ImguiDxBase::~ImguiDxBase() +OldMenuBase::~OldMenuBase() { if (!_baseInit) return; - ImGuiCommon::Shutdown(); + MenuCommon::Shutdown(); } -bool ImguiDxBase::IsVisible() const +bool OldMenuBase::IsVisible() const { - return ImGuiCommon::IsVisible(); + return MenuCommon::IsVisible(); } diff --git a/OptiScaler/menu/imgui_dx_base.h b/OptiScaler/menu/OldMenuBase.h similarity index 93% rename from OptiScaler/menu/imgui_dx_base.h rename to OptiScaler/menu/OldMenuBase.h index 1f671f70..306e7236 100644 --- a/OptiScaler/menu/imgui_dx_base.h +++ b/OptiScaler/menu/OldMenuBase.h @@ -2,11 +2,11 @@ #include -#include "imgui_common.h" +#include "MenuCommon.h" #include -class ImguiDxBase +class OldMenuBase { private: HWND _handle = nullptr; @@ -56,7 +56,7 @@ public: void Dx11Ready(); void Dx12Ready(); - explicit ImguiDxBase(HWND handle); + explicit OldMenuBase(HWND handle); - ~ImguiDxBase(); + ~OldMenuBase(); }; \ No newline at end of file diff --git a/OptiScaler/menu/Imgui_Dx11.cpp b/OptiScaler/menu/OldMenuDx11.cpp similarity index 89% rename from OptiScaler/menu/Imgui_Dx11.cpp rename to OptiScaler/menu/OldMenuDx11.cpp index f37ecf65..a7fe1264 100644 --- a/OptiScaler/menu/Imgui_Dx11.cpp +++ b/OptiScaler/menu/OldMenuDx11.cpp @@ -1,9 +1,9 @@ -#include "Imgui_Dx11.h" +#include "OldMenuDx11.h" #include #include -void Imgui_Dx11::CreateRenderTarget(ID3D11Resource* out) +void OldMenuDx11::CreateRenderTarget(ID3D11Resource* out) { ID3D11Texture2D* outTexture2D = nullptr; @@ -67,7 +67,7 @@ void Imgui_Dx11::CreateRenderTarget(ID3D11Resource* out) } } -bool Imgui_Dx11::Render(ID3D11DeviceContext* pCmdList, ID3D11Resource* outTexture) +bool OldMenuDx11::Render(ID3D11DeviceContext* pCmdList, ID3D11Resource* outTexture) { if (Config::Instance()->OverlayMenu.value_or(true)) return false; @@ -93,7 +93,7 @@ bool Imgui_Dx11::Render(ID3D11DeviceContext* pCmdList, ID3D11Resource* outTextur ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); - ImguiDxBase::RenderMenu(); + OldMenuBase::RenderMenu(); // Create RTV for out pCmdList->OMSetRenderTargets(1, &_renderTargetView, nullptr); @@ -117,17 +117,17 @@ bool Imgui_Dx11::Render(ID3D11DeviceContext* pCmdList, ID3D11Resource* outTextur return true; } -Imgui_Dx11::Imgui_Dx11(HWND handle, ID3D11Device* pDevice) : ImguiDxBase(handle), _device(pDevice) +OldMenuDx11::OldMenuDx11(HWND handle, ID3D11Device* pDevice) : OldMenuBase(handle), _device(pDevice) { Dx11Ready(); } -Imgui_Dx11::~Imgui_Dx11() +OldMenuDx11::~OldMenuDx11() { if (!_dx11Init) return; - ImGuiCommon::Shutdown(); + MenuCommon::Shutdown(); // hackzor std::this_thread::sleep_for(std::chrono::milliseconds(250)); diff --git a/OptiScaler/menu/Imgui_Dx11.h b/OptiScaler/menu/OldMenuDx11.h similarity index 72% rename from OptiScaler/menu/Imgui_Dx11.h rename to OptiScaler/menu/OldMenuDx11.h index 676c7d92..90ab6e3c 100644 --- a/OptiScaler/menu/Imgui_Dx11.h +++ b/OptiScaler/menu/OldMenuDx11.h @@ -1,10 +1,10 @@ #pragma once -#include "imgui_dx_base.h" +#include "OldMenuBase.h" #include -class Imgui_Dx11 : public ImguiDxBase +class OldMenuDx11 : public OldMenuBase { private: bool _dx11Init = false; @@ -18,7 +18,7 @@ private: public: bool Render(ID3D11DeviceContext* pCmdList, ID3D11Resource* outTexture); - Imgui_Dx11(HWND handle, ID3D11Device* pDevice); + OldMenuDx11(HWND handle, ID3D11Device* pDevice); - ~Imgui_Dx11(); + ~OldMenuDx11(); }; \ No newline at end of file diff --git a/OptiScaler/menu/imgui_dx12.cpp b/OptiScaler/menu/OldMenuDx12.cpp similarity index 95% rename from OptiScaler/menu/imgui_dx12.cpp rename to OptiScaler/menu/OldMenuDx12.cpp index a7fb5c39..1bba3071 100644 --- a/OptiScaler/menu/imgui_dx12.cpp +++ b/OptiScaler/menu/OldMenuDx12.cpp @@ -1,4 +1,4 @@ -#include "Imgui_Dx12.h" +#include "OldMenuDx12.h" #include #include @@ -6,7 +6,7 @@ long frameCounter = 0; -bool Imgui_Dx12::Render(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* outTexture) +bool OldMenuDx12::Render(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* outTexture) { if (Config::Instance()->OverlayMenu.value_or(true)) return false; @@ -61,7 +61,7 @@ bool Imgui_Dx12::Render(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* out ImGui_ImplWin32_NewFrame(); // Render - ImguiDxBase::RenderMenu(); + OldMenuBase::RenderMenu(); ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), pCmdList); outBarrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; @@ -108,7 +108,7 @@ bool Imgui_Dx12::Render(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* out ImGui_ImplWin32_NewFrame(); // Render to buffer - ImguiDxBase::RenderMenu(); + OldMenuBase::RenderMenu(); ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), pCmdList); @@ -133,7 +133,7 @@ bool Imgui_Dx12::Render(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* out return true; } -Imgui_Dx12::Imgui_Dx12(HWND handle, ID3D12Device* pDevice) : ImguiDxBase(handle), _device(pDevice) +OldMenuDx12::OldMenuDx12(HWND handle, ID3D12Device* pDevice) : OldMenuBase(handle), _device(pDevice) { if (Config::Instance()->OverlayMenu.value_or(true)) return; @@ -170,7 +170,7 @@ Imgui_Dx12::Imgui_Dx12(HWND handle, ID3D12Device* pDevice) : ImguiDxBase(handle) _srvDescHeap->SetName(L"Imgui_Dx12_srvDescHeap"); } -Imgui_Dx12::~Imgui_Dx12() +OldMenuDx12::~OldMenuDx12() { if (!_dx12Init) return; @@ -216,7 +216,7 @@ Imgui_Dx12::~Imgui_Dx12() } } -void Imgui_Dx12::CreateRenderTarget(const D3D12_RESOURCE_DESC& InDesc) +void OldMenuDx12::CreateRenderTarget(const D3D12_RESOURCE_DESC& InDesc) { if (_renderTargetResource[0] != nullptr) { diff --git a/OptiScaler/menu/Imgui_Dx12.h b/OptiScaler/menu/OldMenuDx12.h similarity index 79% rename from OptiScaler/menu/Imgui_Dx12.h rename to OptiScaler/menu/OldMenuDx12.h index b5333432..831d2b42 100644 --- a/OptiScaler/menu/Imgui_Dx12.h +++ b/OptiScaler/menu/OldMenuDx12.h @@ -1,10 +1,10 @@ #pragma once -#include "imgui_dx_base.h" +#include "OldMenuBase.h" #include -class Imgui_Dx12 : public ImguiDxBase +class OldMenuDx12 : public OldMenuBase { private: bool _dx12Init = false; @@ -21,7 +21,7 @@ private: public: bool Render(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* outTexture); - Imgui_Dx12(HWND handle, ID3D12Device* pDevice); + OldMenuDx12(HWND handle, ID3D12Device* pDevice); - ~Imgui_Dx12(); + ~OldMenuDx12(); }; \ No newline at end of file diff --git a/OptiScaler/menu/imgui_overlay_base.cpp b/OptiScaler/menu/imgui_overlay_base.cpp deleted file mode 100644 index 3d8ee1f0..00000000 --- a/OptiScaler/menu/imgui_overlay_base.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "imgui_overlay_base.h" - -#include -#include -#include -#include "imgui_common.h" - -#include -#include - - -HWND ImGuiOverlayBase::Handle() -{ - return ImGuiCommon::Handle(); -} - -void ImGuiOverlayBase::Dx11Ready() -{ - ImGuiCommon::Dx11Inited(); -} - -void ImGuiOverlayBase::Dx12Ready() -{ - ImGuiCommon::Dx12Inited(); -} - -void ImGuiOverlayBase::VulkanReady() -{ - ImGuiCommon::VulkanInited(); -} - -bool ImGuiOverlayBase::IsInited() -{ - return ImGuiCommon::IsInited(); -} - -bool ImGuiOverlayBase::IsVisible() -{ - return ImGuiCommon::IsVisible(); -} - -bool ImGuiOverlayBase::IsResetRequested() -{ - return ImGuiCommon::IsResetRequested(); -} - -void ImGuiOverlayBase::Init(HWND InHandle) -{ - if (!Config::Instance()->OverlayMenu.value_or(true)) - return; - - LOG_FUNC(); - ImGuiCommon::Init(InHandle); -} - -void ImGuiOverlayBase::RenderMenu() -{ - if (!Config::Instance()->OverlayMenu.value_or(true)) - return; - - ImGuiCommon::RenderMenu(); -} - -void ImGuiOverlayBase::Shutdown() -{ - ImGuiCommon::Shutdown(); -} - -void ImGuiOverlayBase::HideMenu() -{ - ImGuiCommon::HideMenu(); -} diff --git a/OptiScaler/menu/imgui_overlay_vk.h b/OptiScaler/menu/imgui_overlay_vk.h deleted file mode 100644 index 2a2fac6e..00000000 --- a/OptiScaler/menu/imgui_overlay_vk.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -#include - -namespace ImGuiOverlayVk -{ - inline VkQueryPool queryPool = VK_NULL_HANDLE; - inline double timeStampPeriod = 1.0; - inline bool vkUpscaleTrig = false; - - void HookVk(); - void UnHookVk(); -} diff --git a/OptiScaler/menu/wrapped_swapchain.h b/OptiScaler/menu/wrapped_swapchain.h index 2fccc3f2..7eab6dcd 100644 --- a/OptiScaler/menu/wrapped_swapchain.h +++ b/OptiScaler/menu/wrapped_swapchain.h @@ -2,7 +2,7 @@ #include -#include "imgui_overlay_base.h" +#include "MenuBase.h" #include diff --git a/OptiScaler/nvapi/NvApiHooks.h b/OptiScaler/nvapi/NvApiHooks.h new file mode 100644 index 00000000..3ea4dd10 --- /dev/null +++ b/OptiScaler/nvapi/NvApiHooks.h @@ -0,0 +1,125 @@ +#pragma once + +#include + +#include "NvApiTypes.h" +#include "ReflexHooks.h" +#include "fakenvapi.h" + +class NvApiHooks { +public: + // NvAPI_GPU_GetArchInfo hooking based on Nukem's spoofing code here + // https://github.com/Nukem9/dlssg-to-fsr3/blob/89ddc8c1cce4593fb420e633a06605c3c4b9c3cf/source/wrapper_generic/nvapi.cpp#L50 + + inline static NvApiTypes::PFN_NvApi_QueryInterface OriginalNvAPI_QueryInterface = nullptr; + inline static NvApiTypes::PfnNvAPI_GPU_GetArchInfo OriginalNvAPI_GPU_GetArchInfo = nullptr; + + inline static uint32_t __stdcall HookedNvAPI_GPU_GetArchInfo(void* GPUHandle, NV_GPU_ARCH_INFO* ArchInfo) + { + if (OriginalNvAPI_GPU_GetArchInfo) + { + const auto status = OriginalNvAPI_GPU_GetArchInfo(GPUHandle, ArchInfo); + + if (status == 0 && ArchInfo) + { + LOG_DEBUG("From api arch: {0:X} impl: {1:X} rev: {2:X}!", ArchInfo->architecture, ArchInfo->implementation, ArchInfo->revision); + + // for 16xx cards + if (ArchInfo->architecture == NV_GPU_ARCHITECTURE_TU100 && ArchInfo->implementation > NV_GPU_ARCH_IMPLEMENTATION_TU106) + { + ArchInfo->implementation = NV_GPU_ARCH_IMPLEMENTATION_TU106; + ArchInfo->implementation_id = NV_GPU_ARCH_IMPLEMENTATION_TU106; + + LOG_INFO("Spoofed arch: {0:X} impl: {1:X} rev: {2:X}!", ArchInfo->architecture, ArchInfo->implementation, ArchInfo->revision); + } + //else if (ArchInfo->architecture < NV_GPU_ARCHITECTURE_TU100 && ArchInfo->architecture >= NV_GPU_ARCHITECTURE_GP100) + //{ + // LOG_INFO("Spoofing below 16xx arch: {0:X} impl: {1:X} rev: {2:X}!", ArchInfo->architecture, ArchInfo->implementation, ArchInfo->revision); + + // ArchInfo->architecture = NV_GPU_ARCHITECTURE_TU100; + // ArchInfo->architecture_id = NV_GPU_ARCHITECTURE_TU100; + // ArchInfo->implementation = NV_GPU_ARCH_IMPLEMENTATION_TU106; + // ArchInfo->implementation_id = NV_GPU_ARCH_IMPLEMENTATION_TU106; + + // LOG_INFO("Spoofed arch: {0:X} impl: {1:X} rev: {2:X}!", ArchInfo->architecture, ArchInfo->implementation, ArchInfo->revision); + //} + } + + return status; + } + + return 0xFFFFFFFF; + } + + inline static void* __stdcall HookedNvAPI_QueryInterface(NvApiTypes::NV_INTERFACE InterfaceId) + { + switch (InterfaceId) { + case NvApiTypes::NV_INTERFACE::D3D_SetSleepMode: + case NvApiTypes::NV_INTERFACE::D3D_Sleep: + case NvApiTypes::NV_INTERFACE::D3D_GetLatency: + case NvApiTypes::NV_INTERFACE::D3D_SetLatencyMarker: + case NvApiTypes::NV_INTERFACE::D3D12_SetAsyncFrameMarker: + return ReflexHooks::hookReflex(OriginalNvAPI_QueryInterface, InterfaceId); + default: + ReflexHooks::hookReflex(OriginalNvAPI_QueryInterface, InterfaceId); + } + + const auto functionPointer = OriginalNvAPI_QueryInterface(InterfaceId); + + if (functionPointer) + { + switch (InterfaceId) { + case NvApiTypes::NV_INTERFACE::GPU_GetArchInfo: + if (!Config::Instance()->DE_Available) { + OriginalNvAPI_GPU_GetArchInfo = static_cast(functionPointer); + return &HookedNvAPI_GPU_GetArchInfo; + } + break; + } + } + + return functionPointer; + } + + // Requires HMODULE to make sure nvapi is loaded before calling this function + inline static void Hook(HMODULE nvapiModule) + { + if (OriginalNvAPI_QueryInterface != nullptr) + return; + + if (nvapiModule == nullptr) { + LOG_ERROR("Hook called with a nullptr nvapi module"); + return; + } + + LOG_DEBUG("Trying to hook NvApi"); + + OriginalNvAPI_QueryInterface = (NvApiTypes::PFN_NvApi_QueryInterface)GetProcAddress(nvapiModule, "nvapi_QueryInterface"); + + LOG_DEBUG("OriginalNvAPI_QueryInterface = {0:X}", (unsigned long long)OriginalNvAPI_QueryInterface); + + if (OriginalNvAPI_QueryInterface != nullptr) + { + LOG_INFO("NvAPI_QueryInterface found, hooking!"); + fakenvapi::Init((fakenvapi::PFN_Fake_QueryInterface&)OriginalNvAPI_QueryInterface); + + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)OriginalNvAPI_QueryInterface, HookedNvAPI_QueryInterface); + DetourTransactionCommit(); + } + } + + inline static void Unhook() { + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + + if (OriginalNvAPI_QueryInterface != nullptr) + { + DetourDetach(&(PVOID&)OriginalNvAPI_QueryInterface, HookedNvAPI_QueryInterface); + OriginalNvAPI_QueryInterface = nullptr; + } + + DetourTransactionCommit(); + } +}; \ No newline at end of file diff --git a/OptiScaler/nvapi/NvApiTypes.h b/OptiScaler/nvapi/NvApiTypes.h new file mode 100644 index 00000000..af1d7215 --- /dev/null +++ b/OptiScaler/nvapi/NvApiTypes.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include +#include +#include + +// Separate to break up a circular dependency +class NvApiTypes { +public: + enum class NV_INTERFACE : uint32_t + { + GPU_GetArchInfo = 0xD8265D24, + D3D12_SetRawScgPriority = 0x5DB3048A, + D3D_SetSleepMode = 0xac1ca9e0, + D3D_Sleep = 0x852cd1d2, + D3D_GetLatency = 0x1a587f9c, + D3D_SetLatencyMarker = 0xd9984c05, + D3D12_SetAsyncFrameMarker = 0x13c98f73, + }; + + typedef void* (__stdcall* PFN_NvApi_QueryInterface)(NV_INTERFACE InterfaceId); + + using PfnNvAPI_GPU_GetArchInfo = uint32_t(__stdcall*)(void* GPUHandle, NV_GPU_ARCH_INFO* ArchInfo); +}; diff --git a/OptiScaler/nvapi/ReflexHooks.h b/OptiScaler/nvapi/ReflexHooks.h new file mode 100644 index 00000000..dc5537c2 --- /dev/null +++ b/OptiScaler/nvapi/ReflexHooks.h @@ -0,0 +1,141 @@ +#pragma once + +#include "NvApiTypes.h" + +#include + +class ReflexHooks { + inline static bool _inited = false; + inline static uint32_t _minimumIntervalUs = 0; + inline static NV_SET_SLEEP_MODE_PARAMS _lastSleepParams{}; + inline static IUnknown* _lastSleepDev = nullptr; + inline static bool _markersPresent = false; + + inline static decltype(&NvAPI_D3D_SetSleepMode) o_NvAPI_D3D_SetSleepMode = nullptr; + inline static decltype(&NvAPI_D3D_Sleep) o_NvAPI_D3D_Sleep = nullptr; + inline static decltype(&NvAPI_D3D_GetLatency) o_NvAPI_D3D_GetLatency = nullptr; + inline static decltype(&NvAPI_D3D_SetLatencyMarker) o_NvAPI_D3D_SetLatencyMarker = nullptr; + inline static decltype(&NvAPI_D3D12_SetAsyncFrameMarker) o_NvAPI_D3D12_SetAsyncFrameMarker = nullptr; + + inline static NvAPI_Status hNvAPI_D3D_SetSleepMode(IUnknown* pDev, NV_SET_SLEEP_MODE_PARAMS* pSetSleepModeParams) { +#ifdef _DEBUG + LOG_FUNC(); +#endif + // Store for later so we can adjust the fps whenever we want + memcpy(&_lastSleepParams, pSetSleepModeParams, sizeof(NV_SET_SLEEP_MODE_PARAMS)); + _lastSleepDev = pDev; + + if (_minimumIntervalUs != 0) + pSetSleepModeParams->minimumIntervalUs = _minimumIntervalUs; + + return o_NvAPI_D3D_SetSleepMode(pDev, pSetSleepModeParams); + } + + inline static NvAPI_Status hNvAPI_D3D_Sleep(IUnknown* pDev) { +#ifdef _DEBUG + LOG_FUNC(); +#endif + + return o_NvAPI_D3D_Sleep(pDev); + } + + inline static NvAPI_Status hNvAPI_D3D_GetLatency(IUnknown* pDev, NV_LATENCY_RESULT_PARAMS* pGetLatencyParams) { +#ifdef _DEBUG + LOG_FUNC(); +#endif + + return o_NvAPI_D3D_GetLatency(pDev, pGetLatencyParams); + } + + inline static NvAPI_Status hNvAPI_D3D_SetLatencyMarker(IUnknown* pDev, NV_LATENCY_MARKER_PARAMS* pSetLatencyMarkerParams) { +#ifdef _DEBUG + LOG_FUNC(); +#endif + + _markersPresent = true; + return o_NvAPI_D3D_SetLatencyMarker(pDev, pSetLatencyMarkerParams); + } + + inline static NvAPI_Status hNvAPI_D3D12_SetAsyncFrameMarker(ID3D12CommandQueue* pCommandQueue, NV_ASYNC_FRAME_MARKER_PARAMS* pSetAsyncFrameMarkerParams) { +#ifdef _DEBUG + LOG_FUNC(); +#endif + + return o_NvAPI_D3D12_SetAsyncFrameMarker(pCommandQueue, pSetAsyncFrameMarkerParams); + } + +public: + inline static void* hookReflex(NvApiTypes::PFN_NvApi_QueryInterface &queryInterface, NvApiTypes::NV_INTERFACE InterfaceId) { +#ifdef _DEBUG + LOG_FUNC(); +#endif + + if (o_NvAPI_D3D_SetSleepMode == nullptr || o_NvAPI_D3D_Sleep == nullptr || o_NvAPI_D3D_GetLatency == nullptr || o_NvAPI_D3D_SetLatencyMarker == nullptr || o_NvAPI_D3D12_SetAsyncFrameMarker == nullptr) { + o_NvAPI_D3D_SetSleepMode = static_cast(queryInterface(NvApiTypes::NV_INTERFACE::D3D_SetSleepMode)); + o_NvAPI_D3D_Sleep = static_cast(queryInterface(NvApiTypes::NV_INTERFACE::D3D_Sleep)); + o_NvAPI_D3D_GetLatency = static_cast(queryInterface(NvApiTypes::NV_INTERFACE::D3D_GetLatency)); + o_NvAPI_D3D_SetLatencyMarker = static_cast(queryInterface(NvApiTypes::NV_INTERFACE::D3D_SetLatencyMarker)); + o_NvAPI_D3D12_SetAsyncFrameMarker = static_cast(queryInterface(NvApiTypes::NV_INTERFACE::D3D12_SetAsyncFrameMarker)); + } + + switch (InterfaceId) { + case NvApiTypes::NV_INTERFACE::D3D_SetSleepMode: + if (o_NvAPI_D3D_SetSleepMode != nullptr) + return &hNvAPI_D3D_SetSleepMode; + break; + case NvApiTypes::NV_INTERFACE::D3D_Sleep: + if (o_NvAPI_D3D_Sleep != nullptr) + return &hNvAPI_D3D_Sleep; + break; + case NvApiTypes::NV_INTERFACE::D3D_GetLatency: + if (o_NvAPI_D3D_GetLatency != nullptr) + return &hNvAPI_D3D_GetLatency; + break; + case NvApiTypes::NV_INTERFACE::D3D_SetLatencyMarker: + if (o_NvAPI_D3D_SetLatencyMarker != nullptr) + return &hNvAPI_D3D_SetLatencyMarker; + break; + case NvApiTypes::NV_INTERFACE::D3D12_SetAsyncFrameMarker: + if (o_NvAPI_D3D12_SetAsyncFrameMarker != nullptr) + return &hNvAPI_D3D12_SetAsyncFrameMarker; + break; + } + + return nullptr; + } + + // For updating information about Reflex hooks + inline static void update(bool fgState) { + // Not a perfect check, doesn't confirm that Reflex is actually currently enabled + // This is intentional as fakenvapi might override what the game sends + Config::Instance()->ReflexAvailable = _markersPresent; + + static float lastFps = 0; + float currentFps = Config::Instance()->FramerateLimit.value_or(0); + + if (fgState) + currentFps = currentFps / 2; + + if (currentFps != lastFps) { + setFPSLimit(currentFps); + lastFps = currentFps; + } + } + + // 0 - disables the fps cap + inline static void setFPSLimit(float fps) { + LOG_INFO("Set FPS Limit to: {}", fps); + if (fps == 0.0) + _minimumIntervalUs = 0; + else + _minimumIntervalUs = 1'000'000 / fps; + + if (_lastSleepDev != nullptr) { + NV_SET_SLEEP_MODE_PARAMS temp{}; + memcpy(&temp, &_lastSleepParams, sizeof(NV_SET_SLEEP_MODE_PARAMS)); + temp.minimumIntervalUs = _minimumIntervalUs; + o_NvAPI_D3D_SetSleepMode(_lastSleepDev, &temp); + } + + } +}; \ No newline at end of file diff --git a/OptiScaler/nvapi/fakenvapi.h b/OptiScaler/nvapi/fakenvapi.h new file mode 100644 index 00000000..bb7006d3 --- /dev/null +++ b/OptiScaler/nvapi/fakenvapi.h @@ -0,0 +1,91 @@ +#pragma once + +#include + +#include + +enum class FN_INTERFACE : uint32_t +{ + Fake_InformFGState = 0x21382138, + Fake_InformPresentFG = 0x21392139, + Fake_GetAntiLagCtx = 0x21402140 +}; + +using PFN_Fake_InformFGState = uint32_t(__stdcall*)(bool fg_state); +using PFN_Fake_InformPresentFG = uint32_t(__stdcall*)(bool frame_interpolated, uint64_t reflex_frame_id); +using PFN_Fake_GetAntiLagCtx = uint32_t(__stdcall*)(void* al2_context); + +class fakenvapi +{ +private: + inline static struct AntiLag2Data + { + void* context; + bool enabled; + } antilag2_data; + + inline static PFN_Fake_InformFGState Fake_InformFGState = nullptr; + inline static PFN_Fake_InformPresentFG Fake_InformPresentFG = nullptr; + inline static PFN_Fake_GetAntiLagCtx Fake_GetAntiLagCtx = nullptr; + + inline static bool _inited = false; +public: + typedef void* (__stdcall* PFN_Fake_QueryInterface)(FN_INTERFACE InterfaceId); + + inline static const GUID IID_IFfxAntiLag2Data = { 0x5083ae5b, 0x8070, 0x4fca, {0x8e, 0xe5, 0x35, 0x82, 0xdd, 0x36, 0x7d, 0x13} }; + + inline static void Init(PFN_Fake_QueryInterface& queryInterface) { + if (_inited) return; + + LOG_INFO("Trying to get fakenvapi-specific functions"); + + Fake_InformFGState = static_cast(queryInterface(FN_INTERFACE::Fake_InformFGState)); + Fake_InformPresentFG = static_cast(queryInterface(FN_INTERFACE::Fake_InformPresentFG)); + Fake_GetAntiLagCtx = static_cast(queryInterface(FN_INTERFACE::Fake_GetAntiLagCtx)); + + if (Fake_InformFGState == nullptr) + LOG_INFO("Couldn't get InformFGState"); + if (Fake_InformPresentFG == nullptr) + LOG_INFO("Couldn't get InformPresentFG"); + if (Fake_GetAntiLagCtx == nullptr) + LOG_INFO("Couldn't get GetAntiLagCtx"); + + _inited = true; + } + + // Inform AntiLag 2 when present of interpolated frames starts + inline static void reportFGPresent(IDXGISwapChain* pSwapChain, bool fg_state, bool frame_interpolated) { + if (Fake_InformFGState == nullptr || Fake_InformPresentFG == nullptr || Fake_GetAntiLagCtx == nullptr) return; + + // Lets fakenvapi log and reset correctly + Fake_InformFGState(fg_state); + + if (fg_state) { + // Starting with FSR 3.1.1 we can provide an AntiLag 2 context to FSR FG + // and it will call SetFrameGenFrameType for us + auto static ffxApiVersion = FfxApiProxy::VersionDx12(); + constexpr feature_version requiredVersion = { 3, 1, 1 }; + if (isVersionOrBetter(ffxApiVersion, requiredVersion)) { + void* antilag2Context = nullptr; + Fake_GetAntiLagCtx(&antilag2Context); + + if (antilag2Context != nullptr) { + antilag2_data.context = antilag2Context; + antilag2_data.enabled = true; + + pSwapChain->SetPrivateData(IID_IFfxAntiLag2Data, sizeof(antilag2_data), &antilag2_data); + } + } + else + { + // Tell fakenvapi to call SetFrameGenFrameType by itself + // Reflex frame id might get used in the future + Fake_InformPresentFG(frame_interpolated, 0); + } + } + else { + // Remove it or other FG mods won't work with AL2 + pSwapChain->SetPrivateData(IID_IFfxAntiLag2Data, 0, nullptr); + } + } +}; \ No newline at end of file diff --git a/OptiScaler/upscalers/IFeature_Dx11.h b/OptiScaler/upscalers/IFeature_Dx11.h index 182dadba..0a187dc2 100644 --- a/OptiScaler/upscalers/IFeature_Dx11.h +++ b/OptiScaler/upscalers/IFeature_Dx11.h @@ -2,7 +2,7 @@ #include "IFeature.h" -#include +#include #include #include #include @@ -12,7 +12,7 @@ class IFeature_Dx11 : public virtual IFeature protected: ID3D11Device* Device = nullptr; ID3D11DeviceContext* DeviceContext = nullptr; - inline static std::unique_ptr Imgui = nullptr; + inline static std::unique_ptr Imgui = nullptr; std::unique_ptr OutputScaler = nullptr; std::unique_ptr RCAS = nullptr; std::unique_ptr Bias = nullptr; diff --git a/OptiScaler/upscalers/IFeature_Dx11wDx12.h b/OptiScaler/upscalers/IFeature_Dx11wDx12.h index cfabc064..15b7c780 100644 --- a/OptiScaler/upscalers/IFeature_Dx11wDx12.h +++ b/OptiScaler/upscalers/IFeature_Dx11wDx12.h @@ -2,7 +2,7 @@ #include "IFeature_Dx11.h" -#include +#include #include #include #include @@ -11,7 +11,6 @@ #include #include - class IFeature_Dx11wDx12 : public virtual IFeature_Dx11 { protected: diff --git a/OptiScaler/upscalers/IFeature_Dx12.h b/OptiScaler/upscalers/IFeature_Dx12.h index f866f6a3..7aa3b3d1 100644 --- a/OptiScaler/upscalers/IFeature_Dx12.h +++ b/OptiScaler/upscalers/IFeature_Dx12.h @@ -4,7 +4,7 @@ #include "IFeature.h" #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ class IFeature_Dx12 : public virtual IFeature { protected: ID3D12Device* Device = nullptr; - static inline std::unique_ptr Imgui = nullptr; + static inline std::unique_ptr Imgui = nullptr; std::unique_ptr OutputScaler = nullptr; std::unique_ptr RCAS = nullptr; std::unique_ptr Bias = nullptr; diff --git a/OptiScaler/upscalers/dlss/DLSSFeature_Dx11.cpp b/OptiScaler/upscalers/dlss/DLSSFeature_Dx11.cpp index 34eacc2f..fae0fdb6 100644 --- a/OptiScaler/upscalers/dlss/DLSSFeature_Dx11.cpp +++ b/OptiScaler/upscalers/dlss/DLSSFeature_Dx11.cpp @@ -68,7 +68,7 @@ bool DLSSFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex if (initResult) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(GetForegroundWindow(), InDevice); + Imgui = std::make_unique(GetForegroundWindow(), InDevice); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -209,7 +209,7 @@ bool DLSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_NGX_P else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(Util::GetProcessWindow(), Device); + Imgui = std::make_unique(Util::GetProcessWindow(), Device); } } diff --git a/OptiScaler/upscalers/dlss/DLSSFeature_Dx12.cpp b/OptiScaler/upscalers/dlss/DLSSFeature_Dx12.cpp index e9dfb413..a4f4ee25 100644 --- a/OptiScaler/upscalers/dlss/DLSSFeature_Dx12.cpp +++ b/OptiScaler/upscalers/dlss/DLSSFeature_Dx12.cpp @@ -76,7 +76,7 @@ bool DLSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In RCAS = std::make_unique("RCAS", InDevice); if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); + Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); OutputScaler = std::make_unique("OutputScaling", InDevice, (TargetWidth() < DisplayWidth())); } @@ -229,7 +229,7 @@ bool DLSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(Util::GetProcessWindow(), Device); + Imgui = std::make_unique(Util::GetProcessWindow(), Device); } } diff --git a/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx11.cpp b/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx11.cpp index 988ffa14..4c8aa70e 100644 --- a/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx11.cpp +++ b/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx11.cpp @@ -72,7 +72,7 @@ bool DLSSDFeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InConte if (initResult) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(GetForegroundWindow(), InDevice); + Imgui = std::make_unique(GetForegroundWindow(), InDevice); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -213,7 +213,7 @@ bool DLSSDFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_NGX_ else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(Util::GetProcessWindow(), Device); + Imgui = std::make_unique(Util::GetProcessWindow(), Device); } } diff --git a/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx12.cpp b/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx12.cpp index faf7cae6..be4b8cb3 100644 --- a/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx12.cpp +++ b/OptiScaler/upscalers/dlssd/DLSSDFeature_Dx12.cpp @@ -76,7 +76,7 @@ bool DLSSDFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* I RCAS = std::make_unique("RCAS", InDevice); if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); + Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); OutputScaler = std::make_unique("OutputScaling", InDevice, (TargetWidth() < DisplayWidth())); } @@ -231,7 +231,7 @@ bool DLSSDFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_ else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(Util::GetProcessWindow(), Device); + Imgui = std::make_unique(Util::GetProcessWindow(), Device); } } diff --git a/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11.cpp b/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11.cpp index 649b5b1c..312df02c 100644 --- a/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11.cpp +++ b/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11.cpp @@ -29,7 +29,7 @@ bool FSR2FeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InContex if (InitFSR2(InParameters)) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), Device); + Imgui = std::make_unique(Util::GetProcessWindow(), Device); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -604,7 +604,7 @@ bool FSR2FeatureDx11::Evaluate(ID3D11DeviceContext* InContext, NVSDK_NGX_Paramet else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } diff --git a/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11On12.cpp b/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11On12.cpp index 6d0905ca..7b811cb2 100644 --- a/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11On12.cpp +++ b/OptiScaler/upscalers/fsr2/FSR2Feature_Dx11On12.cpp @@ -103,7 +103,7 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_N } if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); if (Config::Instance()->Dx11DelayedInit.value_or(false)) { @@ -429,7 +429,7 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_N else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } @@ -474,7 +474,7 @@ bool FSR2FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_N else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } diff --git a/OptiScaler/upscalers/fsr2/FSR2Feature_Dx12.cpp b/OptiScaler/upscalers/fsr2/FSR2Feature_Dx12.cpp index 25484084..1683cbf2 100644 --- a/OptiScaler/upscalers/fsr2/FSR2Feature_Dx12.cpp +++ b/OptiScaler/upscalers/fsr2/FSR2Feature_Dx12.cpp @@ -16,7 +16,7 @@ bool FSR2FeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In if (InitFSR2(InParameters)) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); + Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -394,7 +394,7 @@ bool FSR2FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } diff --git a/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx11On12_212.cpp b/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx11On12_212.cpp index 1c38cc90..fe51de0b 100644 --- a/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx11On12_212.cpp +++ b/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx11On12_212.cpp @@ -106,7 +106,7 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, NVS } if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); if (Config::Instance()->Dx11DelayedInit.value_or(false)) { @@ -435,7 +435,7 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, NVS else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } @@ -480,7 +480,7 @@ bool FSR2FeatureDx11on12_212::Evaluate(ID3D11DeviceContext* InDeviceContext, NVS else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } diff --git a/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx12_212.cpp b/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx12_212.cpp index 008f5d96..473baf55 100644 --- a/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx12_212.cpp +++ b/OptiScaler/upscalers/fsr2_212/FSR2Feature_Dx12_212.cpp @@ -16,7 +16,7 @@ bool FSR2FeatureDx12_212::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList if (InitFSR2(InParameters)) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); + Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -401,7 +401,7 @@ bool FSR2FeatureDx12_212::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVS else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } diff --git a/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11.cpp b/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11.cpp index 92a0aec2..2d193c88 100644 --- a/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11.cpp +++ b/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11.cpp @@ -32,7 +32,7 @@ bool FSR31FeatureDx11::Init(ID3D11Device* InDevice, ID3D11DeviceContext* InConte if (InitFSR3(InParameters)) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), Device); + Imgui = std::make_unique(Util::GetProcessWindow(), Device); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -484,7 +484,7 @@ bool FSR31FeatureDx11::Evaluate(ID3D11DeviceContext* DeviceContext, NVSDK_NGX_Pa else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } diff --git a/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11On12.cpp b/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11On12.cpp index 3f1c8f85..58031391 100644 --- a/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11On12.cpp +++ b/OptiScaler/upscalers/fsr31/FSR31Feature_Dx11On12.cpp @@ -118,7 +118,7 @@ bool FSR31FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_ } if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); if (Config::Instance()->Dx11DelayedInit.value_or(false)) { @@ -464,7 +464,7 @@ bool FSR31FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_ else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } @@ -509,7 +509,7 @@ bool FSR31FeatureDx11on12::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_ else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } diff --git a/OptiScaler/upscalers/fsr31/FSR31Feature_Dx12.cpp b/OptiScaler/upscalers/fsr31/FSR31Feature_Dx12.cpp index 4be53ac0..2d63e25b 100644 --- a/OptiScaler/upscalers/fsr31/FSR31Feature_Dx12.cpp +++ b/OptiScaler/upscalers/fsr31/FSR31Feature_Dx12.cpp @@ -28,7 +28,7 @@ bool FSR31FeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* I if (InitFSR3(InParameters)) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); + Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -436,7 +436,7 @@ bool FSR31FeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_ else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } diff --git a/OptiScaler/upscalers/xess/XeSSFeature_Dx11.cpp b/OptiScaler/upscalers/xess/XeSSFeature_Dx11.cpp index 33b4f775..6f0ddb3d 100644 --- a/OptiScaler/upscalers/xess/XeSSFeature_Dx11.cpp +++ b/OptiScaler/upscalers/xess/XeSSFeature_Dx11.cpp @@ -118,7 +118,7 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_NGX_P if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) { LOG_DEBUG("Create Imgui!"); - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } if (Config::Instance()->Dx11DelayedInit.value_or(false)) @@ -435,7 +435,7 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_NGX_P else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } @@ -480,7 +480,7 @@ bool XeSSFeatureDx11::Evaluate(ID3D11DeviceContext* InDeviceContext, NVSDK_NGX_P else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } } } diff --git a/OptiScaler/upscalers/xess/XeSSFeature_Dx12.cpp b/OptiScaler/upscalers/xess/XeSSFeature_Dx12.cpp index 0ef37fe8..e43ff5e1 100644 --- a/OptiScaler/upscalers/xess/XeSSFeature_Dx12.cpp +++ b/OptiScaler/upscalers/xess/XeSSFeature_Dx12.cpp @@ -16,7 +16,7 @@ bool XeSSFeatureDx12::Init(ID3D12Device* InDevice, ID3D12GraphicsCommandList* In if (InitXeSS(InDevice, InParameters)) { if (!Config::Instance()->OverlayMenu.value_or(true) && (Imgui == nullptr || Imgui.get() == nullptr)) - Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); + Imgui = std::make_unique(Util::GetProcessWindow(), InDevice); OutputScaler = std::make_unique("Output Scaling", InDevice, (TargetWidth() < DisplayWidth())); RCAS = std::make_unique("RCAS", InDevice); @@ -373,7 +373,7 @@ bool XeSSFeatureDx12::Evaluate(ID3D12GraphicsCommandList* InCommandList, NVSDK_N else { if (Imgui == nullptr || Imgui.get() == nullptr) - Imgui = std::make_unique(GetForegroundWindow(), Device); + Imgui = std::make_unique(GetForegroundWindow(), Device); } }