From 3e5a69e289251b45e18319c78b92046d3fc390d5 Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Mon, 24 Nov 2025 22:39:03 +0100 Subject: [PATCH 1/4] Fix FFX type check --- OptiScaler/proxies/FfxApi_Proxy.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OptiScaler/proxies/FfxApi_Proxy.h b/OptiScaler/proxies/FfxApi_Proxy.h index a487552e..bb11327e 100644 --- a/OptiScaler/proxies/FfxApi_Proxy.h +++ b/OptiScaler/proxies/FfxApi_Proxy.h @@ -80,6 +80,21 @@ class FfxApiProxy static bool IsFGType(ffxStructType_t type) { return type >= 0x00020001u && type <= 0x00030009u; } + // Can't directly check for type when query is used + // might apply to FFX_API_DESC_TYPE_OVERRIDE_VERSION as well + static bool IsFGType(ffxQueryDescHeader* header) + { + ffxStructType_t type = header->type; + + if (header->type == FFX_API_QUERY_DESC_TYPE_GET_VERSIONS || + header->type == FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION) + { + type = header[1].type; + } + + return IsFGType(type); + } + static bool IsLoader(const std::wstring& filePath) { auto size = std::filesystem::file_size(filePath); @@ -651,7 +666,7 @@ class FfxApiProxy static ffxReturnCode_t D3D12_Query(ffxContext* context, ffxQueryDescHeader* desc) { - auto isFg = IsFGType(desc->type); + auto isFg = IsFGType(desc); if (isFg && _dllDx12_FG != nullptr) return _D3D12_Query_FG(context, desc); From bde135ad07c374e998463f632151d7a972423e97 Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Tue, 25 Nov 2025 13:35:16 +0100 Subject: [PATCH 2/4] Generalize FFX type check for no particular reason :) --- OptiScaler/proxies/FfxApi_Proxy.h | 52 ++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/OptiScaler/proxies/FfxApi_Proxy.h b/OptiScaler/proxies/FfxApi_Proxy.h index bb11327e..cdd13e05 100644 --- a/OptiScaler/proxies/FfxApi_Proxy.h +++ b/OptiScaler/proxies/FfxApi_Proxy.h @@ -13,6 +13,8 @@ #include "ffx_api.h" #include +#include +#include class FfxApiProxy { @@ -78,11 +80,43 @@ class FfxApiProxy LOG_WARN("can't parse {0}", version_str); } - static bool IsFGType(ffxStructType_t type) { return type >= 0x00020001u && type <= 0x00030009u; } + enum class FFXStructType + { + General, + Upscaling, + Swapchain, + FG, + VulkanSwapchain, + Unknown + }; + + static FFXStructType GetType(ffxStructType_t type) + { + switch (type & FFX_API_EFFECT_MASK) // type without the specific effect + { + case FFX_API_EFFECT_ID_GENERAL: + return FFXStructType::General; + + case FFX_API_EFFECT_ID_UPSCALE: + return FFXStructType::Upscaling; + + case FFX_API_EFFECT_ID_FRAMEGENERATION: + return FFXStructType::FG; + + case 0x00030000u: // don't want to include ffx_api_dx12.h because of enum name pollution + return FFXStructType::Swapchain; + + case 0x00040000u: // don't want to include ffx_api_vk.h because of enum name pollution + return FFXStructType::VulkanSwapchain; + + default: + return FFXStructType::Unknown; + } + } // Can't directly check for type when query is used // might apply to FFX_API_DESC_TYPE_OVERRIDE_VERSION as well - static bool IsFGType(ffxQueryDescHeader* header) + static FFXStructType GetType(ffxQueryDescHeader* header) { ffxStructType_t type = header->type; @@ -92,7 +126,7 @@ class FfxApiProxy type = header[1].type; } - return IsFGType(type); + return GetType(type); } static bool IsLoader(const std::wstring& filePath) @@ -579,7 +613,8 @@ class FfxApiProxy static ffxReturnCode_t D3D12_CreateContext(ffxContext* context, ffxCreateContextDescHeader* desc, const ffxAllocationCallbacks* memCb) { - auto isFg = IsFGType(desc->type); + auto type = GetType(desc->type); + auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; if (isFg && _dllDx12_FG != nullptr) return _D3D12_CreateContext_FG(context, desc, memCb); @@ -637,7 +672,8 @@ class FfxApiProxy static ffxReturnCode_t D3D12_Configure(ffxContext* context, const ffxConfigureDescHeader* desc) { - auto isFg = IsFGType(desc->type); + auto type = GetType(desc->type); + auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; if (isFg && _dllDx12_FG != nullptr) return _D3D12_Configure_FG(context, desc); @@ -666,7 +702,8 @@ class FfxApiProxy static ffxReturnCode_t D3D12_Query(ffxContext* context, ffxQueryDescHeader* desc) { - auto isFg = IsFGType(desc); + auto type = GetType(desc); + auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; if (isFg && _dllDx12_FG != nullptr) return _D3D12_Query_FG(context, desc); @@ -695,7 +732,8 @@ class FfxApiProxy static ffxReturnCode_t D3D12_Dispatch(ffxContext* context, const ffxDispatchDescHeader* desc) { - auto isFg = IsFGType(desc->type); + auto type = GetType(desc->type); + auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; if (isFg && _dllDx12_FG != nullptr) return _D3D12_Dispatch_FG(context, desc); From 0df2927f7857d18ad9de36400076c62045a57069 Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Tue, 25 Nov 2025 14:11:05 +0100 Subject: [PATCH 3/4] Generalize FFX modules also for no particular reason :) --- OptiScaler/proxies/FfxApi_Proxy.h | 528 +++++++++++++++--------------- 1 file changed, 259 insertions(+), 269 deletions(-) diff --git a/OptiScaler/proxies/FfxApi_Proxy.h b/OptiScaler/proxies/FfxApi_Proxy.h index cdd13e05..edacee1b 100644 --- a/OptiScaler/proxies/FfxApi_Proxy.h +++ b/OptiScaler/proxies/FfxApi_Proxy.h @@ -16,51 +16,35 @@ #include #include +struct FfxModule +{ + HMODULE dll = nullptr; + feature_version version { 0, 0, 0 }; + + bool skipCreateCalls = false; + bool skipConfigureCalls = false; + bool skipQueryCalls = false; + bool skipDispatchCalls = false; + + bool isLoader = false; + + PfnFfxCreateContext CreateContext = nullptr; + PfnFfxDestroyContext DestroyContext = nullptr; + PfnFfxConfigure Configure = nullptr; + PfnFfxQuery Query = nullptr; + PfnFfxDispatch Dispatch = nullptr; +}; + class FfxApiProxy { private: - inline static HMODULE _dllDx12 = nullptr; - inline static HMODULE _dllDx12_SR = nullptr; - inline static HMODULE _dllDx12_FG = nullptr; - inline static feature_version _versionDx12 { 0, 0, 0 }; - inline static feature_version _versionDx12_SR { 0, 0, 0 }; - inline static feature_version _versionDx12_FG { 0, 0, 0 }; - inline static bool _dx12Loader = false; - inline static bool _skipSRCreateCalls = false; - inline static bool _skipFGCreateCalls = false; + inline static FfxModule main_dx12; + inline static FfxModule upscaling_dx12; + inline static FfxModule fg_dx12; + + inline static FfxModule main_vk; + inline static bool _skipDestroyCalls = false; - inline static bool _skipSRConfigureCalls = false; - inline static bool _skipFGConfigureCalls = false; - inline static bool _skipSRQueryCalls = false; - inline static bool _skipFGQueryCalls = false; - inline static bool _skipSRDispatchCalls = false; - inline static bool _skipFGDispatchCalls = false; - - inline static PfnFfxCreateContext _D3D12_CreateContext = nullptr; - inline static PfnFfxDestroyContext _D3D12_DestroyContext = nullptr; - inline static PfnFfxConfigure _D3D12_Configure = nullptr; - inline static PfnFfxQuery _D3D12_Query = nullptr; - inline static PfnFfxDispatch _D3D12_Dispatch = nullptr; - - inline static PfnFfxCreateContext _D3D12_CreateContext_SR = nullptr; - inline static PfnFfxDestroyContext _D3D12_DestroyContext_SR = nullptr; - inline static PfnFfxConfigure _D3D12_Configure_SR = nullptr; - inline static PfnFfxQuery _D3D12_Query_SR = nullptr; - inline static PfnFfxDispatch _D3D12_Dispatch_SR = nullptr; - - inline static PfnFfxCreateContext _D3D12_CreateContext_FG = nullptr; - inline static PfnFfxDestroyContext _D3D12_DestroyContext_FG = nullptr; - inline static PfnFfxConfigure _D3D12_Configure_FG = nullptr; - inline static PfnFfxQuery _D3D12_Query_FG = nullptr; - inline static PfnFfxDispatch _D3D12_Dispatch_FG = nullptr; - - inline static HMODULE _dllVk = nullptr; - inline static feature_version _versionVk { 0, 0, 0 }; - inline static PfnFfxCreateContext _VULKAN_CreateContext = nullptr; - inline static PfnFfxDestroyContext _VULKAN_DestroyContext = nullptr; - inline static PfnFfxConfigure _VULKAN_Configure = nullptr; - inline static PfnFfxQuery _VULKAN_Query = nullptr; - inline static PfnFfxDispatch _VULKAN_Dispatch = nullptr; static inline void parse_version(const char* version_str, feature_version* _version) { @@ -138,32 +122,32 @@ class FfxApiProxy } public: - static HMODULE Dx12Module() { return _dllDx12; } - static HMODULE Dx12Module_SR() { return _dllDx12_SR; } - static HMODULE Dx12Module_FG() { return _dllDx12_FG; } + static HMODULE Dx12Module() { return main_dx12.dll; } + static HMODULE Dx12Module_SR() { return upscaling_dx12.dll; } + static HMODULE Dx12Module_FG() { return fg_dx12.dll; } - static bool IsFGReady() { return (_dllDx12 && !_dx12Loader) || _dllDx12_FG != nullptr; } - static bool IsSRReady() { return (_dllDx12 && !_dx12Loader) || _dllDx12_SR != nullptr; } + static bool IsFGReady() { return (main_dx12.dll && !main_dx12.isLoader) || fg_dx12.dll != nullptr; } + static bool IsSRReady() { return (main_dx12.dll && !main_dx12.isLoader) || upscaling_dx12.dll != nullptr; } static bool InitFfxDx12(HMODULE module = nullptr) { // if dll already loaded - if (_dllDx12 != nullptr && _D3D12_CreateContext != nullptr) + if (main_dx12.dll != nullptr && main_dx12.CreateContext != nullptr) return true; spdlog::info(""); if (module != nullptr) { - _dllDx12 = module; + main_dx12.dll = module; wchar_t path[MAX_PATH]; DWORD len = GetModuleFileNameW(module, path, MAX_PATH); std::wstring fileName(path); - _dx12Loader = IsLoader(fileName); + main_dx12.isLoader = IsLoader(fileName); } - if (_dllDx12 == nullptr) + if (main_dx12.dll == nullptr) { // Try new api first std::vector dllNames = { L"amd_fidelityfx_loader_dx12.dll", L"amd_fidelityfx_dx12.dll" }; @@ -172,7 +156,7 @@ class FfxApiProxy { LOG_DEBUG("Trying to load {}", wstring_to_string(dllNames[i])); - if (_dllDx12 == nullptr && Config::Instance()->FfxDx12Path.has_value()) + if (main_dx12.dll == nullptr && Config::Instance()->FfxDx12Path.has_value()) { std::filesystem::path libPath(Config::Instance()->FfxDx12Path.value().c_str()); std::wstring fileName; @@ -182,65 +166,65 @@ class FfxApiProxy else fileName = (libPath / dllNames[i]).c_str(); - _dllDx12 = NtdllProxy::LoadLibraryExW_Ldr(fileName.c_str(), NULL, 0); + main_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr(fileName.c_str(), NULL, 0); - if (_dllDx12 != nullptr) + if (main_dx12.dll != nullptr) { LOG_INFO("{} loaded from {}", wstring_to_string(dllNames[i]), wstring_to_string(Config::Instance()->FfxDx12Path.value())); // hacky but works for now - _dx12Loader = IsLoader(fileName); + main_dx12.isLoader = IsLoader(fileName); break; } } - if (_dllDx12 == nullptr) + if (main_dx12.dll == nullptr) { auto filePath = (Util::DllPath().parent_path() / dllNames[i]); - _dllDx12 = NtdllProxy::LoadLibraryExW_Ldr(filePath.c_str(), NULL, 0); + main_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr(filePath.c_str(), NULL, 0); - if (_dllDx12 != nullptr) + if (main_dx12.dll != nullptr) { LOG_INFO("{} loaded from exe folder", wstring_to_string(dllNames[i])); // hacky but works for now - _dx12Loader = IsLoader(filePath.c_str()); + main_dx12.isLoader = IsLoader(filePath.c_str()); break; } } } } - if (_dllDx12 != nullptr && _D3D12_Configure == nullptr) + if (main_dx12.dll != nullptr && main_dx12.Configure == nullptr) { - _D3D12_Configure = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(_dllDx12, "ffxConfigure"); - _D3D12_CreateContext = - (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(_dllDx12, "ffxCreateContext"); - _D3D12_DestroyContext = - (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(_dllDx12, "ffxDestroyContext"); - _D3D12_Dispatch = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(_dllDx12, "ffxDispatch"); - _D3D12_Query = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(_dllDx12, "ffxQuery"); + main_dx12.Configure = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(main_dx12.dll, "ffxConfigure"); + main_dx12.CreateContext = + (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(main_dx12.dll, "ffxCreateContext"); + main_dx12.DestroyContext = + (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(main_dx12.dll, "ffxDestroyContext"); + main_dx12.Dispatch = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(main_dx12.dll, "ffxDispatch"); + main_dx12.Query = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(main_dx12.dll, "ffxQuery"); - if (Config::Instance()->EnableFfxInputs.value_or_default() && _D3D12_CreateContext != nullptr) + if (Config::Instance()->EnableFfxInputs.value_or_default() && main_dx12.CreateContext != nullptr) { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - if (_D3D12_Configure != nullptr) - DetourAttach(&(PVOID&) _D3D12_Configure, ffxConfigure_Dx12); + if (main_dx12.Configure != nullptr) + DetourAttach(&(PVOID&) main_dx12.Configure, ffxConfigure_Dx12); - if (_D3D12_CreateContext != nullptr) - DetourAttach(&(PVOID&) _D3D12_CreateContext, ffxCreateContext_Dx12); + if (main_dx12.CreateContext != nullptr) + DetourAttach(&(PVOID&) main_dx12.CreateContext, ffxCreateContext_Dx12); - if (_D3D12_DestroyContext != nullptr) - DetourAttach(&(PVOID&) _D3D12_DestroyContext, ffxDestroyContext_Dx12); + if (main_dx12.DestroyContext != nullptr) + DetourAttach(&(PVOID&) main_dx12.DestroyContext, ffxDestroyContext_Dx12); - if (_D3D12_Dispatch != nullptr) - DetourAttach(&(PVOID&) _D3D12_Dispatch, ffxDispatch_Dx12); + if (main_dx12.Dispatch != nullptr) + DetourAttach(&(PVOID&) main_dx12.Dispatch, ffxDispatch_Dx12); - if (_D3D12_Query != nullptr) - DetourAttach(&(PVOID&) _D3D12_Query, ffxQuery_Dx12); + if (main_dx12.Query != nullptr) + DetourAttach(&(PVOID&) main_dx12.Query, ffxQuery_Dx12); State::Instance().fsrHooks = true; @@ -251,15 +235,15 @@ class FfxApiProxy InitFfxDx12_SR(); InitFfxDx12_FG(); - bool loadResult = - _D3D12_CreateContext != nullptr || _D3D12_CreateContext_SR != nullptr || _D3D12_CreateContext_FG != nullptr; + bool loadResult = main_dx12.CreateContext != nullptr || upscaling_dx12.CreateContext != nullptr || + fg_dx12.CreateContext != nullptr; LOG_INFO("LoadResult: {}", loadResult); if (loadResult) VersionDx12(); else - _dllDx12 = nullptr; + main_dx12.dll = nullptr; return loadResult; } @@ -267,15 +251,15 @@ class FfxApiProxy static bool InitFfxDx12_SR(HMODULE module = nullptr) { // if dll already loaded - if (_dllDx12_SR != nullptr && _D3D12_CreateContext_SR != nullptr) + if (upscaling_dx12.dll != nullptr && upscaling_dx12.CreateContext != nullptr) return true; spdlog::info(""); if (module != nullptr) - _dllDx12_SR = module; + upscaling_dx12.dll = module; - if (_dllDx12_SR == nullptr) + if (upscaling_dx12.dll == nullptr) { // Try new api first std::vector dllNames = { L"amd_fidelityfx_upscaler_dx12.dll" }; @@ -284,16 +268,16 @@ class FfxApiProxy { LOG_DEBUG("Trying to load {}", wstring_to_string(dllNames[i])); - if (_dllDx12_SR == nullptr && Config::Instance()->FfxDx12Path.has_value()) + if (upscaling_dx12.dll == nullptr && Config::Instance()->FfxDx12Path.has_value()) { std::filesystem::path libPath(Config::Instance()->FfxDx12Path.value().c_str()); if (libPath.has_filename()) - _dllDx12_SR = NtdllProxy::LoadLibraryExW_Ldr(libPath.c_str(), NULL, 0); + upscaling_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr(libPath.c_str(), NULL, 0); else - _dllDx12_SR = NtdllProxy::LoadLibraryExW_Ldr((libPath / dllNames[i]).c_str(), NULL, 0); + upscaling_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr((libPath / dllNames[i]).c_str(), NULL, 0); - if (_dllDx12_SR != nullptr) + if (upscaling_dx12.dll != nullptr) { LOG_INFO("{} loaded from {}", wstring_to_string(dllNames[i]), wstring_to_string(Config::Instance()->FfxDx12Path.value())); @@ -301,11 +285,11 @@ class FfxApiProxy } } - if (_dllDx12_SR == nullptr) + if (upscaling_dx12.dll == nullptr) { - _dllDx12_SR = NtdllProxy::LoadLibraryExW_Ldr(dllNames[i].c_str(), NULL, 0); + upscaling_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr(dllNames[i].c_str(), NULL, 0); - if (_dllDx12_SR != nullptr) + if (upscaling_dx12.dll != nullptr) { LOG_INFO("{} loaded from exe folder", wstring_to_string(dllNames[i])); break; @@ -314,35 +298,37 @@ class FfxApiProxy } } - if (_dllDx12_SR != nullptr && _D3D12_Configure_SR == nullptr) + if (upscaling_dx12.dll != nullptr && upscaling_dx12.Configure == nullptr) { - _D3D12_Configure_SR = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(_dllDx12_SR, "ffxConfigure"); - _D3D12_CreateContext_SR = - (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(_dllDx12_SR, "ffxCreateContext"); - _D3D12_DestroyContext_SR = - (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(_dllDx12_SR, "ffxDestroyContext"); - _D3D12_Dispatch_SR = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(_dllDx12_SR, "ffxDispatch"); - _D3D12_Query_SR = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(_dllDx12_SR, "ffxQuery"); + upscaling_dx12.Configure = + (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(upscaling_dx12.dll, "ffxConfigure"); + upscaling_dx12.CreateContext = + (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(upscaling_dx12.dll, "ffxCreateContext"); + upscaling_dx12.DestroyContext = + (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(upscaling_dx12.dll, "ffxDestroyContext"); + upscaling_dx12.Dispatch = + (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(upscaling_dx12.dll, "ffxDispatch"); + upscaling_dx12.Query = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(upscaling_dx12.dll, "ffxQuery"); - if (Config::Instance()->EnableFfxInputs.value_or_default() && _D3D12_CreateContext_SR != nullptr) + if (Config::Instance()->EnableFfxInputs.value_or_default() && upscaling_dx12.CreateContext != nullptr) { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - if (_D3D12_Configure_SR != nullptr) - DetourAttach(&(PVOID&) _D3D12_Configure_SR, ffxConfigure_Dx12); + if (upscaling_dx12.Configure != nullptr) + DetourAttach(&(PVOID&) upscaling_dx12.Configure, ffxConfigure_Dx12); - if (_D3D12_CreateContext_SR != nullptr) - DetourAttach(&(PVOID&) _D3D12_CreateContext_SR, ffxCreateContext_Dx12); + if (upscaling_dx12.CreateContext != nullptr) + DetourAttach(&(PVOID&) upscaling_dx12.CreateContext, ffxCreateContext_Dx12); - if (_D3D12_DestroyContext_SR != nullptr) - DetourAttach(&(PVOID&) _D3D12_DestroyContext_SR, ffxDestroyContext_Dx12); + if (upscaling_dx12.DestroyContext != nullptr) + DetourAttach(&(PVOID&) upscaling_dx12.DestroyContext, ffxDestroyContext_Dx12); - if (_D3D12_Dispatch_SR != nullptr) - DetourAttach(&(PVOID&) _D3D12_Dispatch_SR, ffxDispatch_Dx12); + if (upscaling_dx12.Dispatch != nullptr) + DetourAttach(&(PVOID&) upscaling_dx12.Dispatch, ffxDispatch_Dx12); - if (_D3D12_Query_SR != nullptr) - DetourAttach(&(PVOID&) _D3D12_Query_SR, ffxQuery_Dx12); + if (upscaling_dx12.Query != nullptr) + DetourAttach(&(PVOID&) upscaling_dx12.Query, ffxQuery_Dx12); State::Instance().fsrHooks = true; @@ -350,14 +336,14 @@ class FfxApiProxy } } - bool loadResult = _D3D12_CreateContext_SR != nullptr; + bool loadResult = upscaling_dx12.CreateContext != nullptr; LOG_INFO("LoadResult: {}", loadResult); if (loadResult) VersionDx12_SR(); else - _dllDx12_SR = nullptr; + upscaling_dx12.dll = nullptr; return loadResult; } @@ -365,15 +351,15 @@ class FfxApiProxy static bool InitFfxDx12_FG(HMODULE module = nullptr) { // if dll already loaded - if (_dllDx12_FG != nullptr && _D3D12_CreateContext_FG != nullptr) + if (fg_dx12.dll != nullptr && fg_dx12.CreateContext != nullptr) return true; spdlog::info(""); if (module != nullptr) - _dllDx12_FG = module; + fg_dx12.dll = module; - if (_dllDx12_FG == nullptr) + if (fg_dx12.dll == nullptr) { // Try new api first std::vector dllNames = { L"amd_fidelityfx_framegeneration_dx12.dll" }; @@ -382,16 +368,16 @@ class FfxApiProxy { LOG_DEBUG("Trying to load {}", wstring_to_string(dllNames[i])); - if (_dllDx12_FG == nullptr && Config::Instance()->FfxDx12Path.has_value()) + if (fg_dx12.dll == nullptr && Config::Instance()->FfxDx12Path.has_value()) { std::filesystem::path libPath(Config::Instance()->FfxDx12Path.value().c_str()); if (libPath.has_filename()) - _dllDx12_FG = NtdllProxy::LoadLibraryExW_Ldr(libPath.c_str(), NULL, 0); + fg_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr(libPath.c_str(), NULL, 0); else - _dllDx12_FG = NtdllProxy::LoadLibraryExW_Ldr((libPath / dllNames[i]).c_str(), NULL, 0); + fg_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr((libPath / dllNames[i]).c_str(), NULL, 0); - if (_dllDx12_FG != nullptr) + if (fg_dx12.dll != nullptr) { LOG_INFO("{} loaded from {}", wstring_to_string(dllNames[i]), wstring_to_string(Config::Instance()->FfxDx12Path.value())); @@ -399,11 +385,11 @@ class FfxApiProxy } } - if (_dllDx12_FG == nullptr) + if (fg_dx12.dll == nullptr) { - _dllDx12_FG = NtdllProxy::LoadLibraryExW_Ldr(dllNames[i].c_str(), NULL, 0); + fg_dx12.dll = NtdllProxy::LoadLibraryExW_Ldr(dllNames[i].c_str(), NULL, 0); - if (_dllDx12_FG != nullptr) + if (fg_dx12.dll != nullptr) { LOG_INFO("{} loaded from exe folder", wstring_to_string(dllNames[i])); break; @@ -412,35 +398,35 @@ class FfxApiProxy } } - if (_dllDx12_FG != nullptr && _D3D12_Configure_FG == nullptr) + if (fg_dx12.dll != nullptr && fg_dx12.Configure == nullptr) { - _D3D12_Configure_FG = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(_dllDx12_FG, "ffxConfigure"); - _D3D12_CreateContext_FG = - (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(_dllDx12_FG, "ffxCreateContext"); - _D3D12_DestroyContext_FG = - (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(_dllDx12_FG, "ffxDestroyContext"); - _D3D12_Dispatch_FG = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(_dllDx12_FG, "ffxDispatch"); - _D3D12_Query_FG = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(_dllDx12_FG, "ffxQuery"); + fg_dx12.Configure = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(fg_dx12.dll, "ffxConfigure"); + fg_dx12.CreateContext = + (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(fg_dx12.dll, "ffxCreateContext"); + fg_dx12.DestroyContext = + (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(fg_dx12.dll, "ffxDestroyContext"); + fg_dx12.Dispatch = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(fg_dx12.dll, "ffxDispatch"); + fg_dx12.Query = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(fg_dx12.dll, "ffxQuery"); - if (Config::Instance()->EnableFfxInputs.value_or_default() && _D3D12_CreateContext_FG != nullptr) + if (Config::Instance()->EnableFfxInputs.value_or_default() && fg_dx12.CreateContext != nullptr) { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - if (_D3D12_Configure_FG != nullptr) - DetourAttach(&(PVOID&) _D3D12_Configure_FG, ffxConfigure_Dx12); + if (fg_dx12.Configure != nullptr) + DetourAttach(&(PVOID&) fg_dx12.Configure, ffxConfigure_Dx12); - if (_D3D12_CreateContext_FG != nullptr) - DetourAttach(&(PVOID&) _D3D12_CreateContext_FG, ffxCreateContext_Dx12); + if (fg_dx12.CreateContext != nullptr) + DetourAttach(&(PVOID&) fg_dx12.CreateContext, ffxCreateContext_Dx12); - if (_D3D12_DestroyContext_FG != nullptr) - DetourAttach(&(PVOID&) _D3D12_DestroyContext_FG, ffxDestroyContext_Dx12); + if (fg_dx12.DestroyContext != nullptr) + DetourAttach(&(PVOID&) fg_dx12.DestroyContext, ffxDestroyContext_Dx12); - if (_D3D12_Dispatch_FG != nullptr) - DetourAttach(&(PVOID&) _D3D12_Dispatch_FG, ffxDispatch_Dx12); + if (fg_dx12.Dispatch != nullptr) + DetourAttach(&(PVOID&) fg_dx12.Dispatch, ffxDispatch_Dx12); - if (_D3D12_Query_FG != nullptr) - DetourAttach(&(PVOID&) _D3D12_Query_FG, ffxQuery_Dx12); + if (fg_dx12.Query != nullptr) + DetourAttach(&(PVOID&) fg_dx12.Query, ffxQuery_Dx12); State::Instance().fsrHooks = true; @@ -448,29 +434,29 @@ class FfxApiProxy } } - bool loadResult = _D3D12_CreateContext_FG != nullptr; + bool loadResult = fg_dx12.CreateContext != nullptr; LOG_INFO("LoadResult: {}", loadResult); if (loadResult) VersionDx12_FG(); else - _dllDx12_FG = nullptr; + fg_dx12.dll = nullptr; return loadResult; } static feature_version VersionDx12() { - if (_versionDx12.major == 0 && _D3D12_Query != nullptr /* && device != nullptr*/) + if (main_dx12.version.major == 0 && main_dx12.Query != nullptr /* && device != nullptr*/) { ffxQueryDescGetVersions versionQuery {}; versionQuery.header.type = FFX_API_QUERY_DESC_TYPE_GET_VERSIONS; - versionQuery.createDescType = 0x00010000u; // FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE + versionQuery.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE; uint64_t versionCount = 0; versionQuery.outputCount = &versionCount; - auto queryResult = _D3D12_Query(nullptr, &versionQuery.header); + auto queryResult = main_dx12.Query(nullptr, &versionQuery.header); // get number of versions for allocation if (versionCount > 0 && queryResult == FFX_API_RETURN_OK) @@ -484,48 +470,48 @@ class FfxApiProxy versionQuery.versionNames = versionNames.data(); // fill version ids and names arrays. - queryResult = _D3D12_Query(nullptr, &versionQuery.header); + queryResult = main_dx12.Query(nullptr, &versionQuery.header); if (queryResult == FFX_API_RETURN_OK) { - parse_version(versionNames[0], &_versionDx12); - LOG_INFO("FfxApi Dx12 version: {}.{}.{}", _versionDx12.major, _versionDx12.minor, - _versionDx12.patch); + parse_version(versionNames[0], &main_dx12.version); + LOG_INFO("FfxApi Dx12 version: {}.{}.{}", main_dx12.version.major, main_dx12.version.minor, + main_dx12.version.patch); } else { - LOG_WARN("_D3D12_Query 2 result: {}", (UINT) queryResult); + LOG_WARN("main_dx12.Query 2 result: {}", (UINT) queryResult); } } else { - LOG_WARN("_D3D12_Query result: {}", (UINT) queryResult); + LOG_WARN("main_dx12.Query result: {}", (UINT) queryResult); } } - if (_versionDx12.major == 0 && _D3D12_Query_SR != nullptr) - _versionDx12 = VersionDx12_SR(); + if (main_dx12.version.major == 0 && upscaling_dx12.Query != nullptr) + main_dx12.version = VersionDx12_SR(); - if (_versionDx12.major == 0 && _D3D12_Query_FG != nullptr) - _versionDx12 = VersionDx12_FG(); + if (main_dx12.version.major == 0 && fg_dx12.Query != nullptr) + main_dx12.version = VersionDx12_FG(); - return _versionDx12; + return main_dx12.version; } static feature_version VersionDx12_SR() { - if (_D3D12_Query_SR == nullptr) + if (upscaling_dx12.Query == nullptr) return VersionDx12(); - if (_versionDx12_SR.major == 0) + if (upscaling_dx12.version.major == 0) { ffxQueryDescGetVersions versionQuery {}; versionQuery.header.type = FFX_API_QUERY_DESC_TYPE_GET_VERSIONS; - versionQuery.createDescType = 0x00010000u; // FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE + versionQuery.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE; uint64_t versionCount = 0; versionQuery.outputCount = &versionCount; - auto queryResult = _D3D12_Query_SR(nullptr, &versionQuery.header); + auto queryResult = upscaling_dx12.Query(nullptr, &versionQuery.header); // get number of versions for allocation if (versionCount > 0 && queryResult == FFX_API_RETURN_OK) @@ -539,42 +525,42 @@ class FfxApiProxy versionQuery.versionNames = versionNames.data(); // fill version ids and names arrays. - queryResult = _D3D12_Query_SR(nullptr, &versionQuery.header); + queryResult = upscaling_dx12.Query(nullptr, &versionQuery.header); if (queryResult == FFX_API_RETURN_OK) { - parse_version(versionNames[0], &_versionDx12_SR); - LOG_INFO("FfxApi Dx12 SR version: {}.{}.{}", _versionDx12_SR.major, _versionDx12_SR.minor, - _versionDx12_SR.patch); + parse_version(versionNames[0], &upscaling_dx12.version); + LOG_INFO("FfxApi Dx12 SR version: {}.{}.{}", upscaling_dx12.version.major, + upscaling_dx12.version.minor, upscaling_dx12.version.patch); } else { - LOG_WARN("_D3D12_Query 2 result: {}", (UINT) queryResult); + LOG_WARN("main_dx12.Query 2 result: {}", (UINT) queryResult); } } else { - LOG_WARN("_D3D12_Query result: {}", (UINT) queryResult); + LOG_WARN("main_dx12.Query result: {}", (UINT) queryResult); } } - return _versionDx12_SR; + return upscaling_dx12.version; } static feature_version VersionDx12_FG() { - if (_D3D12_Query_FG == nullptr) + if (fg_dx12.Query == nullptr) return VersionDx12(); - if (_versionDx12_FG.major == 0) + if (fg_dx12.version.major == 0) { ffxQueryDescGetVersions versionQuery {}; versionQuery.header.type = FFX_API_QUERY_DESC_TYPE_GET_VERSIONS; - versionQuery.createDescType = 0x00020001u; // FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION + versionQuery.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION; uint64_t versionCount = 0; versionQuery.outputCount = &versionCount; - auto queryResult = _D3D12_Query_FG(nullptr, &versionQuery.header); + auto queryResult = fg_dx12.Query(nullptr, &versionQuery.header); // get number of versions for allocation if (versionCount > 0 && queryResult == FFX_API_RETURN_OK) @@ -588,26 +574,26 @@ class FfxApiProxy versionQuery.versionNames = versionNames.data(); // fill version ids and names arrays. - queryResult = _D3D12_Query_FG(nullptr, &versionQuery.header); + queryResult = fg_dx12.Query(nullptr, &versionQuery.header); if (queryResult == FFX_API_RETURN_OK) { - parse_version(versionNames[0], &_versionDx12_FG); - LOG_INFO("FfxApi Dx12 FG version: {}.{}.{}", _versionDx12_FG.major, _versionDx12_FG.minor, - _versionDx12_FG.patch); + parse_version(versionNames[0], &fg_dx12.version); + LOG_INFO("FfxApi Dx12 FG version: {}.{}.{}", fg_dx12.version.major, fg_dx12.version.minor, + fg_dx12.version.patch); } else { - LOG_WARN("_D3D12_Query 2 result: {}", (UINT) queryResult); + LOG_WARN("main_dx12.Query 2 result: {}", (UINT) queryResult); } } else { - LOG_WARN("_D3D12_Query result: {}", (UINT) queryResult); + LOG_WARN("main_dx12.Query result: {}", (UINT) queryResult); } } - return _versionDx12_FG; + return fg_dx12.version; } static ffxReturnCode_t D3D12_CreateContext(ffxContext* context, ffxCreateContextDescHeader* desc, @@ -616,24 +602,25 @@ class FfxApiProxy auto type = GetType(desc->type); auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; - if (isFg && _dllDx12_FG != nullptr) - return _D3D12_CreateContext_FG(context, desc, memCb); - else if (!isFg && _dllDx12_SR != nullptr) - return _D3D12_CreateContext_SR(context, desc, memCb); + if (isFg && fg_dx12.dll != nullptr) + return fg_dx12.CreateContext(context, desc, memCb); + else if (!isFg && upscaling_dx12.dll != nullptr) + return upscaling_dx12.CreateContext(context, desc, memCb); - if (_dllDx12 != nullptr && !(isFg && _skipFGCreateCalls) && !(!isFg && _skipSRCreateCalls)) + if (main_dx12.dll != nullptr && !(isFg && fg_dx12.skipCreateCalls) && + !(!isFg && upscaling_dx12.skipCreateCalls)) { if (isFg) - _skipFGCreateCalls = true; + fg_dx12.skipCreateCalls = true; else - _skipSRCreateCalls = true; + upscaling_dx12.skipCreateCalls = true; - auto result = _D3D12_CreateContext(context, desc, memCb); + auto result = main_dx12.CreateContext(context, desc, memCb); if (isFg) - _skipFGCreateCalls = false; + fg_dx12.skipCreateCalls = false; else - _skipSRCreateCalls = false; + upscaling_dx12.skipCreateCalls = false; return result; } @@ -645,24 +632,24 @@ class FfxApiProxy { ffxReturnCode_t result = FFX_API_RETURN_ERROR; - if (_dllDx12 != nullptr && !_skipDestroyCalls) + if (main_dx12.dll != nullptr && !_skipDestroyCalls) { _skipDestroyCalls = true; - result = _D3D12_DestroyContext(context, memCb); + result = main_dx12.DestroyContext(context, memCb); _skipDestroyCalls = false; } if (result == FFX_API_RETURN_OK) return result; - if (_dllDx12_SR != nullptr) - result = _D3D12_DestroyContext_SR(context, memCb); + if (upscaling_dx12.dll != nullptr) + result = upscaling_dx12.DestroyContext(context, memCb); if (result == FFX_API_RETURN_OK) return result; - if (_dllDx12_FG != nullptr) - result = _D3D12_DestroyContext_FG(context, memCb); + if (fg_dx12.dll != nullptr) + result = fg_dx12.DestroyContext(context, memCb); if (result == FFX_API_RETURN_OK) return result; @@ -675,24 +662,25 @@ class FfxApiProxy auto type = GetType(desc->type); auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; - if (isFg && _dllDx12_FG != nullptr) - return _D3D12_Configure_FG(context, desc); - else if (!isFg && _dllDx12_SR != nullptr) - return _D3D12_Configure_SR(context, desc); + if (isFg && fg_dx12.dll != nullptr) + return fg_dx12.Configure(context, desc); + else if (!isFg && upscaling_dx12.dll != nullptr) + return upscaling_dx12.Configure(context, desc); - if (_dllDx12 != nullptr && !(isFg && _skipFGConfigureCalls) && !(!isFg && _skipSRConfigureCalls)) + if (main_dx12.dll != nullptr && !(isFg && fg_dx12.skipConfigureCalls) && + !(!isFg && upscaling_dx12.skipConfigureCalls)) { if (isFg) - _skipFGConfigureCalls = true; + fg_dx12.skipConfigureCalls = true; else - _skipSRConfigureCalls = true; + upscaling_dx12.skipConfigureCalls = true; - auto result = _D3D12_Configure(context, desc); + auto result = main_dx12.Configure(context, desc); if (isFg) - _skipFGConfigureCalls = false; + fg_dx12.skipConfigureCalls = false; else - _skipSRConfigureCalls = false; + upscaling_dx12.skipConfigureCalls = false; return result; } @@ -705,24 +693,24 @@ class FfxApiProxy auto type = GetType(desc); auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; - if (isFg && _dllDx12_FG != nullptr) - return _D3D12_Query_FG(context, desc); - else if (!isFg && _dllDx12_SR != nullptr) - return _D3D12_Query_SR(context, desc); + if (isFg && fg_dx12.dll != nullptr) + return fg_dx12.Query(context, desc); + else if (!isFg && upscaling_dx12.dll != nullptr) + return upscaling_dx12.Query(context, desc); - if (_dllDx12 != nullptr && !(isFg && _skipFGQueryCalls) && !(!isFg && _skipSRQueryCalls)) + if (main_dx12.dll != nullptr && !(isFg && fg_dx12.skipQueryCalls) && !(!isFg && upscaling_dx12.skipQueryCalls)) { if (isFg) - _skipFGQueryCalls = true; + fg_dx12.skipQueryCalls = true; else - _skipSRQueryCalls = true; + upscaling_dx12.skipQueryCalls = true; - auto result = _D3D12_Query(context, desc); + auto result = main_dx12.Query(context, desc); if (isFg) - _skipFGQueryCalls = false; + fg_dx12.skipQueryCalls = false; else - _skipSRQueryCalls = false; + upscaling_dx12.skipQueryCalls = false; return result; } @@ -735,24 +723,25 @@ class FfxApiProxy auto type = GetType(desc->type); auto isFg = type == FFXStructType::FG || type == FFXStructType::Swapchain; - if (isFg && _dllDx12_FG != nullptr) - return _D3D12_Dispatch_FG(context, desc); - else if (!isFg && _dllDx12_SR != nullptr) - return _D3D12_Dispatch_SR(context, desc); + if (isFg && fg_dx12.dll != nullptr) + return fg_dx12.Dispatch(context, desc); + else if (!isFg && upscaling_dx12.dll != nullptr) + return upscaling_dx12.Dispatch(context, desc); - if (_dllDx12 != nullptr && !(isFg && _skipFGDispatchCalls) && !(!isFg && _skipSRDispatchCalls)) + if (main_dx12.dll != nullptr && !(isFg && fg_dx12.skipDispatchCalls) && + !(!isFg && upscaling_dx12.skipDispatchCalls)) { if (isFg) - _skipFGDispatchCalls = true; + fg_dx12.skipDispatchCalls = true; else - _skipSRDispatchCalls = true; + upscaling_dx12.skipDispatchCalls = true; - auto result = _D3D12_Dispatch(context, desc); + auto result = main_dx12.Dispatch(context, desc); if (isFg) - _skipFGDispatchCalls = false; + fg_dx12.skipDispatchCalls = false; else - _skipSRDispatchCalls = false; + upscaling_dx12.skipDispatchCalls = false; return result; } @@ -760,12 +749,12 @@ class FfxApiProxy return FFX_API_RETURN_NO_PROVIDER; } - static HMODULE VkModule() { return _dllVk; } + static HMODULE VkModule() { return main_vk.dll; } static bool InitFfxVk(HMODULE module = nullptr) { // if dll already loaded - if (_dllVk != nullptr && _VULKAN_CreateContext != nullptr) + if (main_vk.dll != nullptr && main_vk.CreateContext != nullptr) return true; spdlog::info(""); @@ -773,61 +762,61 @@ class FfxApiProxy LOG_DEBUG("Loading amd_fidelityfx_vk.dll methods"); if (module != nullptr) - _dllVk = module; + main_vk.dll = module; - if (_dllVk == nullptr && Config::Instance()->FfxVkPath.has_value()) + if (main_vk.dll == nullptr && Config::Instance()->FfxVkPath.has_value()) { std::filesystem::path libPath(Config::Instance()->FfxVkPath.value().c_str()); if (libPath.has_filename()) - _dllVk = NtdllProxy::LoadLibraryExW_Ldr(libPath.c_str(), NULL, 0); + main_vk.dll = NtdllProxy::LoadLibraryExW_Ldr(libPath.c_str(), NULL, 0); else - _dllVk = NtdllProxy::LoadLibraryExW_Ldr((libPath / L"amd_fidelityfx_vk.dll").c_str(), NULL, 0); + main_vk.dll = NtdllProxy::LoadLibraryExW_Ldr((libPath / L"amd_fidelityfx_vk.dll").c_str(), NULL, 0); - if (_dllVk != nullptr) + if (main_vk.dll != nullptr) { LOG_INFO("amd_fidelityfx_vk.dll loaded from {0}", wstring_to_string(Config::Instance()->FfxVkPath.value())); } } - if (_dllVk == nullptr) + if (main_vk.dll == nullptr) { - _dllVk = NtdllProxy::LoadLibraryExW_Ldr(L"amd_fidelityfx_vk.dll", NULL, 0); + main_vk.dll = NtdllProxy::LoadLibraryExW_Ldr(L"amd_fidelityfx_vk.dll", NULL, 0); - if (_dllVk != nullptr) + if (main_vk.dll != nullptr) LOG_INFO("amd_fidelityfx_vk.dll loaded from exe folder"); } - if (_dllVk != nullptr && _VULKAN_CreateContext == nullptr) + if (main_vk.dll != nullptr && main_vk.CreateContext == nullptr) { - _VULKAN_Configure = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(_dllVk, "ffxConfigure"); - _VULKAN_CreateContext = - (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(_dllVk, "ffxCreateContext"); - _VULKAN_DestroyContext = - (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(_dllVk, "ffxDestroyContext"); - _VULKAN_Dispatch = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(_dllVk, "ffxDispatch"); - _VULKAN_Query = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(_dllVk, "ffxQuery"); + main_vk.Configure = (PfnFfxConfigure) KernelBaseProxy::GetProcAddress_()(main_vk.dll, "ffxConfigure"); + main_vk.CreateContext = + (PfnFfxCreateContext) KernelBaseProxy::GetProcAddress_()(main_vk.dll, "ffxCreateContext"); + main_vk.DestroyContext = + (PfnFfxDestroyContext) KernelBaseProxy::GetProcAddress_()(main_vk.dll, "ffxDestroyContext"); + main_vk.Dispatch = (PfnFfxDispatch) KernelBaseProxy::GetProcAddress_()(main_vk.dll, "ffxDispatch"); + main_vk.Query = (PfnFfxQuery) KernelBaseProxy::GetProcAddress_()(main_vk.dll, "ffxQuery"); - if (Config::Instance()->EnableFfxInputs.value_or_default() && _VULKAN_CreateContext != nullptr) + if (Config::Instance()->EnableFfxInputs.value_or_default() && main_vk.CreateContext != nullptr) { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); - if (_VULKAN_Configure != nullptr) - DetourAttach(&(PVOID&) _VULKAN_Configure, ffxConfigure_Vk); + if (main_vk.Configure != nullptr) + DetourAttach(&(PVOID&) main_vk.Configure, ffxConfigure_Vk); - if (_VULKAN_CreateContext != nullptr) - DetourAttach(&(PVOID&) _VULKAN_CreateContext, ffxCreateContext_Vk); + if (main_vk.CreateContext != nullptr) + DetourAttach(&(PVOID&) main_vk.CreateContext, ffxCreateContext_Vk); - if (_VULKAN_DestroyContext != nullptr) - DetourAttach(&(PVOID&) _VULKAN_DestroyContext, ffxDestroyContext_Vk); + if (main_vk.DestroyContext != nullptr) + DetourAttach(&(PVOID&) main_vk.DestroyContext, ffxDestroyContext_Vk); - if (_VULKAN_Dispatch != nullptr) - DetourAttach(&(PVOID&) _VULKAN_Dispatch, ffxDispatch_Vk); + if (main_vk.Dispatch != nullptr) + DetourAttach(&(PVOID&) main_vk.Dispatch, ffxDispatch_Vk); - if (_VULKAN_Query != nullptr) - DetourAttach(&(PVOID&) _VULKAN_Query, ffxQuery_Vk); + if (main_vk.Query != nullptr) + DetourAttach(&(PVOID&) main_vk.Query, ffxQuery_Vk); State::Instance().fsrHooks = true; @@ -835,29 +824,29 @@ class FfxApiProxy } } - bool loadResult = _VULKAN_CreateContext != nullptr; + bool loadResult = main_vk.CreateContext != nullptr; LOG_INFO("LoadResult: {}", loadResult); if (loadResult) VersionVk(); else - _dllVk = nullptr; + main_vk.dll = nullptr; return loadResult; } static feature_version VersionVk() { - if (_versionVk.major == 0 && _VULKAN_Query != nullptr) + if (main_vk.version.major == 0 && main_vk.Query != nullptr) { ffxQueryDescGetVersions versionQuery {}; versionQuery.header.type = FFX_API_QUERY_DESC_TYPE_GET_VERSIONS; - versionQuery.createDescType = 0x00010000u; // FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE + versionQuery.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE; uint64_t versionCount = 0; versionQuery.outputCount = &versionCount; - auto queryResult = _VULKAN_Query(nullptr, &versionQuery.header); + auto queryResult = main_vk.Query(nullptr, &versionQuery.header); // get number of versions for allocation if (versionCount > 0 && queryResult == FFX_API_RETURN_OK) @@ -870,32 +859,33 @@ class FfxApiProxy versionQuery.versionIds = versionIds.data(); versionQuery.versionNames = versionNames.data(); - queryResult = _VULKAN_Query(nullptr, &versionQuery.header); + queryResult = main_vk.Query(nullptr, &versionQuery.header); if (queryResult == FFX_API_RETURN_OK) { - parse_version(versionNames[0], &_versionVk); - LOG_INFO("FfxApi Vulkan version: {}.{}.{}", _versionVk.major, _versionVk.minor, _versionVk.patch); + parse_version(versionNames[0], &main_vk.version); + LOG_INFO("FfxApi Vulkan version: {}.{}.{}", main_vk.version.major, main_vk.version.minor, + main_vk.version.patch); } else { - LOG_WARN("_VULKAN_Query 2 result: {}", (UINT) queryResult); + LOG_WARN("main_vk.Query 2 result: {}", (UINT) queryResult); } } else { - LOG_WARN("_VULKAN_Query result: {}", (UINT) queryResult); + LOG_WARN("main_vk.Query result: {}", (UINT) queryResult); } } - return _versionVk; + return main_vk.version; } - static PfnFfxCreateContext VULKAN_CreateContext() { return _VULKAN_CreateContext; } - static PfnFfxDestroyContext VULKAN_DestroyContext() { return _VULKAN_DestroyContext; } - static PfnFfxConfigure VULKAN_Configure() { return _VULKAN_Configure; } - static PfnFfxQuery VULKAN_Query() { return _VULKAN_Query; } - static PfnFfxDispatch VULKAN_Dispatch() { return _VULKAN_Dispatch; } + static PfnFfxCreateContext VULKAN_CreateContext() { return main_vk.CreateContext; } + static PfnFfxDestroyContext VULKAN_DestroyContext() { return main_vk.DestroyContext; } + static PfnFfxConfigure VULKAN_Configure() { return main_vk.Configure; } + static PfnFfxQuery VULKAN_Query() { return main_vk.Query; } + static PfnFfxDispatch VULKAN_Dispatch() { return main_vk.Dispatch; } static std::string ReturnCodeToString(ffxReturnCode_t result) { From 877b1d6a14f25539fb6c25f4f52178a62685e6af Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:21:52 +0100 Subject: [PATCH 4/4] Use decltype whenever possible --- OptiScaler/Util.cpp | 6 +- OptiScaler/hooks/Advapi32_Hooks.h | 7 +- OptiScaler/hooks/Crypt32_Hooks.h | 6 +- OptiScaler/hooks/Wintrust_Hooks.h | 2 +- OptiScaler/menu/menu_common.h | 12 +-- OptiScaler/proxies/Kernel32_Proxy.h | 26 +++---- OptiScaler/proxies/KernelBase_Proxy.h | 20 ++--- OptiScaler/proxies/Ntdll_Proxy.h | 4 +- OptiScaler/proxies/XeFG_Proxy.h | 61 +++++---------- OptiScaler/proxies/XeLL_Proxy.h | 18 ++--- OptiScaler/proxies/XeSS_Proxy.h | 108 ++++++++++---------------- 11 files changed, 108 insertions(+), 162 deletions(-) diff --git a/OptiScaler/Util.cpp b/OptiScaler/Util.cpp index 08e38fb4..b1d96e58 100644 --- a/OptiScaler/Util.cpp +++ b/OptiScaler/Util.cpp @@ -6,9 +6,9 @@ #include typedef LONG(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); -typedef DWORD (*PFN_GetFileVersionInfoSizeW)(LPCWSTR lptstrFilename, LPDWORD lpdwHandle); -typedef BOOL (*PFN_GetFileVersionInfoW)(LPCWSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData); -typedef BOOL (*PFN_VerQueryValueW)(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID* lplpBuffer, PUINT puLen); +typedef decltype(&GetFileVersionInfoSizeW) PFN_GetFileVersionInfoSizeW; +typedef decltype(&GetFileVersionInfoW) PFN_GetFileVersionInfoW; +typedef decltype(&VerQueryValueW) PFN_VerQueryValueW; static IID streamlineRiid {}; diff --git a/OptiScaler/hooks/Advapi32_Hooks.h b/OptiScaler/hooks/Advapi32_Hooks.h index 42e9c520..591f90ae 100644 --- a/OptiScaler/hooks/Advapi32_Hooks.h +++ b/OptiScaler/hooks/Advapi32_Hooks.h @@ -8,10 +8,9 @@ const HKEY signatureMark = (HKEY) 0xFFFFFFFF13372137; -typedef LSTATUS (*PFN_RegOpenKeyExW)(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult); -typedef LSTATUS (*PFN_RegEnumValueW)(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName, - LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData); -typedef LSTATUS (*PFN_RegCloseKey)(HKEY hKey); +typedef decltype(&RegOpenKeyExW) PFN_RegOpenKeyExW; +typedef decltype(&RegEnumValueW) PFN_RegEnumValueW; +typedef decltype(&RegCloseKey) PFN_RegCloseKey; static PFN_RegOpenKeyExW o_RegOpenKeyExW = nullptr; static PFN_RegEnumValueW o_RegEnumValueW = nullptr; diff --git a/OptiScaler/hooks/Crypt32_Hooks.h b/OptiScaler/hooks/Crypt32_Hooks.h index 465f521e..7d7dc00b 100644 --- a/OptiScaler/hooks/Crypt32_Hooks.h +++ b/OptiScaler/hooks/Crypt32_Hooks.h @@ -7,10 +7,8 @@ #include "detours/detours.h" #include -typedef BOOL (*PFN_CryptQueryObject)(DWORD dwObjectType, const void* pvObject, DWORD dwExpectedContentTypeFlags, - DWORD dwExpectedFormatTypeFlags, DWORD dwFlags, DWORD* pdwMsgAndCertEncodingType, - DWORD* pdwContentType, DWORD* pdwFormatType, HCERTSTORE* phCertStore, - HCRYPTMSG* phMsg, const void** ppvContext); +typedef decltype(&CryptQueryObject) PFN_CryptQueryObject; + static PFN_CryptQueryObject o_CryptQueryObject = nullptr; static BOOL hkCryptQueryObject(DWORD dwObjectType, const void* pvObject, DWORD dwExpectedContentTypeFlags, diff --git a/OptiScaler/hooks/Wintrust_Hooks.h b/OptiScaler/hooks/Wintrust_Hooks.h index 19b38f6c..f57efde8 100644 --- a/OptiScaler/hooks/Wintrust_Hooks.h +++ b/OptiScaler/hooks/Wintrust_Hooks.h @@ -8,7 +8,7 @@ #include #include -typedef LONG (*PFN_WinVerifyTrust)(HWND hwnd, GUID* pgActionID, LPVOID pWVTData); +typedef decltype(&WinVerifyTrust) PFN_WinVerifyTrust; static PFN_WinVerifyTrust o_WinVerifyTrust = nullptr; static LONG hkWinVerifyTrust(HWND hwnd, GUID* pgActionID, LPVOID pWVTData) diff --git a/OptiScaler/menu/menu_common.h b/OptiScaler/menu/menu_common.h index fd2dea15..a24f5562 100644 --- a/OptiScaler/menu/menu_common.h +++ b/OptiScaler/menu/menu_common.h @@ -83,12 +83,12 @@ class MenuCommon #pragma region "Hooks & WndProc" // for hooking - typedef BOOL (*PFN_SetCursorPos)(int x, int y); - typedef BOOL (*PFN_ClipCursor)(const RECT* lpRect); - typedef UINT (*PFN_SendInput)(UINT cInputs, LPINPUT pInputs, int cbSize); - typedef void (*PFN_mouse_event)(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo); - typedef BOOL (*PFN_GetCursorPos)(LPPOINT lpPoint); - typedef LRESULT (*PFN_SendMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); + typedef decltype(&SetCursorPos) PFN_SetCursorPos; + typedef decltype(&ClipCursor) PFN_ClipCursor; + typedef decltype(&SendInput) PFN_SendInput; + typedef decltype(&mouse_event) PFN_mouse_event; + typedef decltype(&GetCursorPos) PFN_GetCursorPos; + typedef decltype(&SendMessageW) PFN_SendMessageW; inline static PFN_SetCursorPos pfn_SetPhysicalCursorPos = nullptr; inline static PFN_SetCursorPos pfn_SetCursorPos = nullptr; diff --git a/OptiScaler/proxies/Kernel32_Proxy.h b/OptiScaler/proxies/Kernel32_Proxy.h index 51998c3f..c0307a13 100644 --- a/OptiScaler/proxies/Kernel32_Proxy.h +++ b/OptiScaler/proxies/Kernel32_Proxy.h @@ -13,20 +13,18 @@ class Kernel32Proxy { public: - typedef BOOL(WINAPI* PFN_FreeLibrary)(HMODULE lpLibrary); - typedef HMODULE(WINAPI* PFN_LoadLibraryA)(LPCSTR lpLibFileName); - typedef HMODULE(WINAPI* PFN_LoadLibraryW)(LPCWSTR lpLibFileName); - typedef HMODULE(WINAPI* PFN_LoadLibraryExA)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); - typedef HMODULE(WINAPI* PFN_LoadLibraryExW)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); - typedef FARPROC(WINAPI* PFN_GetProcAddress)(HMODULE hModule, LPCSTR lpProcName); - typedef HMODULE(WINAPI* PFN_GetModuleHandleA)(LPCSTR lpModuleName); - typedef HMODULE(WINAPI* PFN_GetModuleHandleW)(LPCWSTR lpModuleName); - typedef BOOL(WINAPI* PFN_GetModuleHandleExA)(DWORD dwFlags, LPCSTR lpModuleName, HMODULE* phModule); - typedef BOOL(WINAPI* PFN_GetModuleHandleExW)(DWORD dwFlags, LPCWSTR lpModuleName, HMODULE* phModule); - typedef DWORD(WINAPI* PFN_GetFileAttributesW)(LPCWSTR lpFileName); - typedef HANDLE(WINAPI* PFN_CreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, HANDLE hTemplateFile); + typedef decltype(&FreeLibrary) PFN_FreeLibrary; + typedef decltype(&LoadLibraryA) PFN_LoadLibraryA; + typedef decltype(&LoadLibraryW) PFN_LoadLibraryW; + typedef decltype(&LoadLibraryExA) PFN_LoadLibraryExA; + typedef decltype(&LoadLibraryExW) PFN_LoadLibraryExW; + typedef decltype(&GetProcAddress) PFN_GetProcAddress; + typedef decltype(&GetModuleHandleA) PFN_GetModuleHandleA; + typedef decltype(&GetModuleHandleW) PFN_GetModuleHandleW; + typedef decltype(&GetModuleHandleExA) PFN_GetModuleHandleExA; + typedef decltype(&GetModuleHandleExW) PFN_GetModuleHandleExW; + typedef decltype(&GetFileAttributesW) PFN_GetFileAttributesW; + typedef decltype(&CreateFileW) PFN_CreateFileW; static void Init() { diff --git a/OptiScaler/proxies/KernelBase_Proxy.h b/OptiScaler/proxies/KernelBase_Proxy.h index 8849e283..a3c47952 100644 --- a/OptiScaler/proxies/KernelBase_Proxy.h +++ b/OptiScaler/proxies/KernelBase_Proxy.h @@ -7,16 +7,16 @@ class KernelBaseProxy { public: - typedef BOOL(WINAPI* PFN_FreeLibrary)(HMODULE lpLibrary); - typedef HMODULE(WINAPI* PFN_LoadLibraryA)(LPCSTR lpLibFileName); - typedef HMODULE(WINAPI* PFN_LoadLibraryW)(LPCWSTR lpLibFileName); - typedef HMODULE(WINAPI* PFN_LoadLibraryExA)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); - typedef HMODULE(WINAPI* PFN_LoadLibraryExW)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); - typedef FARPROC(WINAPI* PFN_GetProcAddress)(HMODULE hModule, LPCSTR lpProcName); - typedef HMODULE(WINAPI* PFN_GetModuleHandleA)(LPCSTR lpModuleName); - typedef HMODULE(WINAPI* PFN_GetModuleHandleW)(LPCWSTR lpModuleName); - typedef BOOL(WINAPI* PFN_GetModuleHandleExA)(DWORD dwFlags, LPCSTR lpModuleName, HMODULE* phModule); - typedef BOOL(WINAPI* PFN_GetModuleHandleExW)(DWORD dwFlags, LPCWSTR lpModuleName, HMODULE* phModule); + typedef decltype(&FreeLibrary) PFN_FreeLibrary; + typedef decltype(&LoadLibraryA) PFN_LoadLibraryA; + typedef decltype(&LoadLibraryW) PFN_LoadLibraryW; + typedef decltype(&LoadLibraryExA) PFN_LoadLibraryExA; + typedef decltype(&LoadLibraryExW) PFN_LoadLibraryExW; + typedef decltype(&GetProcAddress) PFN_GetProcAddress; + typedef decltype(&GetModuleHandleA) PFN_GetModuleHandleA; + typedef decltype(&GetModuleHandleW) PFN_GetModuleHandleW; + typedef decltype(&GetModuleHandleExA) PFN_GetModuleHandleExA; + typedef decltype(&GetModuleHandleExW) PFN_GetModuleHandleExW; static void Init() { diff --git a/OptiScaler/proxies/Ntdll_Proxy.h b/OptiScaler/proxies/Ntdll_Proxy.h index ee29f580..f01ba6d8 100644 --- a/OptiScaler/proxies/Ntdll_Proxy.h +++ b/OptiScaler/proxies/Ntdll_Proxy.h @@ -107,8 +107,8 @@ class NtdllProxy } private: - typedef VOID(NTAPI* PFN_RtlInitUnicodeString)(PUNICODE_STRING DestinationString, PCWSTR SourceString); - typedef ULONG(NTAPI* PFN_RtlNtStatusToDosError)(NTSTATUS Status); + typedef decltype(&RtlInitUnicodeString) PFN_RtlInitUnicodeString; + typedef decltype(&RtlNtStatusToDosError) PFN_RtlNtStatusToDosError; inline static HMODULE _dll = nullptr; diff --git a/OptiScaler/proxies/XeFG_Proxy.h b/OptiScaler/proxies/XeFG_Proxy.h index 0f6ab783..c7a1e7f8 100644 --- a/OptiScaler/proxies/XeFG_Proxy.h +++ b/OptiScaler/proxies/XeFG_Proxy.h @@ -15,52 +15,29 @@ #pragma comment(lib, "Version.lib") // Common -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainGetVersion)(xefg_swapchain_version_t* pVersion); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainGetProperties)(xefg_swapchain_handle_t hSwapChain, - xefg_swapchain_properties_t* pProperties); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainTagFrameConstants)( - xefg_swapchain_handle_t hSwapChain, uint32_t presentId, const xefg_swapchain_frame_constant_data_t* pConstants); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainSetEnabled)(xefg_swapchain_handle_t hSwapChain, uint32_t enable); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainSetPresentId)(xefg_swapchain_handle_t hSwapChain, - uint32_t presentId); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainGetLastPresentStatus)( - xefg_swapchain_handle_t hSwapChain, xefg_swapchain_present_status_t* pPresentStatus); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainSetLoggingCallback)( - xefg_swapchain_handle_t hSwapChain, xefg_swapchain_logging_level_t loggingLevel, - xefg_swapchain_app_log_callback_t loggingCallback, void* userData); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainDestroy)(xefg_swapchain_handle_t hSwapChain); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainSetLatencyReduction)(xefg_swapchain_handle_t hSwapChain, - void* hXeLLContext); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainSetSceneChangeThreshold)(xefg_swapchain_handle_t hSwapChain, - float threshold); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainGetPipelineBuildStatus)(xefg_swapchain_handle_t hSwapChain); +typedef decltype(&xefgSwapChainGetVersion) PFN_xefgSwapChainGetVersion; +typedef decltype(&xefgSwapChainGetProperties) PFN_xefgSwapChainGetProperties; +typedef decltype(&xefgSwapChainTagFrameConstants) PFN_xefgSwapChainTagFrameConstants; +typedef decltype(&xefgSwapChainSetEnabled) PFN_xefgSwapChainSetEnabled; +typedef decltype(&xefgSwapChainSetPresentId) PFN_xefgSwapChainSetPresentId; +typedef decltype(&xefgSwapChainGetLastPresentStatus) PFN_xefgSwapChainGetLastPresentStatus; +typedef decltype(&xefgSwapChainSetLoggingCallback) PFN_xefgSwapChainSetLoggingCallback; +typedef decltype(&xefgSwapChainDestroy) PFN_xefgSwapChainDestroy; +typedef decltype(&xefgSwapChainSetLatencyReduction) PFN_xefgSwapChainSetLatencyReduction; +typedef decltype(&xefgSwapChainSetSceneChangeThreshold) PFN_xefgSwapChainSetSceneChangeThreshold; +typedef decltype(&xefgSwapChainGetPipelineBuildStatus) PFN_xefgSwapChainGetPipelineBuildStatus; // Dx12 -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12CreateContext)(ID3D12Device* pDevice, - xefg_swapchain_handle_t* phSwapChain); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12BuildPipelines)(xefg_swapchain_handle_t hSwapChain, - ID3D12PipelineLibrary* pPipelineLibrary, - bool blocking, uint32_t initFlags); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12InitFromSwapChain)( - xefg_swapchain_handle_t hSwapChain, ID3D12CommandQueue* pCmdQueue, - const xefg_swapchain_d3d12_init_params_t* pInitParams); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12InitFromSwapChainDesc)( - xefg_swapchain_handle_t hSwapChain, HWND hWnd, const DXGI_SWAP_CHAIN_DESC1* pSwapChainDesc, - const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullscreenDesc, ID3D12CommandQueue* pCmdQueue, IDXGIFactory2* pDxgiFactory, - const xefg_swapchain_d3d12_init_params_t* pInitParams); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12GetSwapChainPtr)(xefg_swapchain_handle_t hSwapChain, - REFIID riid, void** ppSwapChain); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12TagFrameResource)( - xefg_swapchain_handle_t hSwapChain, ID3D12CommandList* pCmdList, uint32_t presentId, - const xefg_swapchain_d3d12_resource_data_t* pResData); -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainD3D12SetDescriptorHeap)(xefg_swapchain_handle_t hSwapChain, - ID3D12DescriptorHeap* pDescriptorHeap, - uint32_t descriptorHeapOffsetInBytes); +typedef decltype(&xefgSwapChainD3D12CreateContext) PFN_xefgSwapChainD3D12CreateContext; +typedef decltype(&xefgSwapChainD3D12BuildPipelines) PFN_xefgSwapChainD3D12BuildPipelines; +typedef decltype(&xefgSwapChainD3D12InitFromSwapChain) PFN_xefgSwapChainD3D12InitFromSwapChain; +typedef decltype(&xefgSwapChainD3D12InitFromSwapChainDesc) PFN_xefgSwapChainD3D12InitFromSwapChainDesc; +typedef decltype(&xefgSwapChainD3D12GetSwapChainPtr) PFN_xefgSwapChainD3D12GetSwapChainPtr; +typedef decltype(&xefgSwapChainD3D12TagFrameResource) PFN_xefgSwapChainD3D12TagFrameResource; +typedef decltype(&xefgSwapChainD3D12SetDescriptorHeap) PFN_xefgSwapChainD3D12SetDescriptorHeap; // Debug -typedef xefg_swapchain_result_t (*PFN_xefgSwapChainEnableDebugFeature)(xefg_swapchain_handle_t hSwapChain, - xefg_swapchain_debug_feature_t featureId, - uint32_t enable, void* pArgument); +typedef decltype(&xefgSwapChainEnableDebugFeature) PFN_xefgSwapChainEnableDebugFeature; class XeFGProxy { diff --git a/OptiScaler/proxies/XeLL_Proxy.h b/OptiScaler/proxies/XeLL_Proxy.h index 2a79b4c4..64d88df5 100644 --- a/OptiScaler/proxies/XeLL_Proxy.h +++ b/OptiScaler/proxies/XeLL_Proxy.h @@ -16,18 +16,16 @@ #pragma comment(lib, "Version.lib") // Common -typedef xell_result_t (*PFN_xellDestroyContext)(xell_context_handle_t context); -typedef xell_result_t (*PFN_xellSetSleepMode)(xell_context_handle_t context, const xell_sleep_params_t* param); -typedef xell_result_t (*PFN_xellGetSleepMode)(xell_context_handle_t context, xell_sleep_params_t* param); -typedef xell_result_t (*PFN_xellSleep)(xell_context_handle_t context, uint32_t frame_id); -typedef xell_result_t (*PFN_xellAddMarkerData)(xell_context_handle_t context, uint32_t frame_id, - xell_latency_marker_type_t marker); -typedef xell_result_t (*PFN_xellGetVersion)(xell_version_t* pVersion); -typedef xell_result_t (*PFN_xellSetLoggingCallback)(xell_context_handle_t hContext, xell_logging_level_t loggingLevel, - xell_app_log_callback_t loggingCallback); +typedef decltype(&xellDestroyContext) PFN_xellDestroyContext; +typedef decltype(&xellSetSleepMode) PFN_xellSetSleepMode; +typedef decltype(&xellGetSleepMode) PFN_xellGetSleepMode; +typedef decltype(&xellSleep) PFN_xellSleep; +typedef decltype(&xellAddMarkerData) PFN_xellAddMarkerData; +typedef decltype(&xellGetVersion) PFN_xellGetVersion; +typedef decltype(&xellSetLoggingCallback) PFN_xellSetLoggingCallback; // Dx12 -typedef xell_result_t (*PFN_xellD3D12CreateContext)(ID3D12Device* device, xell_context_handle_t* out_context); +typedef decltype(&xellD3D12CreateContext) PFN_xellD3D12CreateContext; class XeLLProxy { diff --git a/OptiScaler/proxies/XeSS_Proxy.h b/OptiScaler/proxies/XeSS_Proxy.h index b76540dd..8cb4ef4b 100644 --- a/OptiScaler/proxies/XeSS_Proxy.h +++ b/OptiScaler/proxies/XeSS_Proxy.h @@ -24,75 +24,51 @@ #pragma comment(lib, "Version.lib") -typedef xess_result_t (*PFN_xessD3D12CreateContext)(ID3D12Device* pDevice, xess_context_handle_t* phContext); -typedef xess_result_t (*PFN_xessD3D12BuildPipelines)(xess_context_handle_t hContext, - ID3D12PipelineLibrary* pPipelineLibrary, bool blocking, - uint32_t initFlags); -typedef xess_result_t (*PRN_xessD3D12Init)(xess_context_handle_t hContext, const xess_d3d12_init_params_t* pInitParams); -typedef xess_result_t (*PFN_xessD3D12Execute)(xess_context_handle_t hContext, ID3D12GraphicsCommandList* pCommandList, - const xess_d3d12_execute_params_t* pExecParams); -typedef xess_result_t (*PFN_xessSelectNetworkModel)(xess_context_handle_t hContext, xess_network_model_t network); -typedef xess_result_t (*PFN_xessStartDump)(xess_context_handle_t hContext, - const xess_dump_parameters_t* dump_parameters); -typedef xess_result_t (*PFN_xessGetVersion)(xess_version_t* pVersion); -typedef xess_result_t (*PFN_xessIsOptimalDriver)(xess_context_handle_t hContext); -typedef xess_result_t (*PFN_xessSetLoggingCallback)(xess_context_handle_t hContext, xess_logging_level_t loggingLevel, - xess_app_log_callback_t loggingCallback); -typedef xess_result_t (*PFN_xessGetProperties)(xess_context_handle_t hContext, const xess_2d_t* pOutputResolution, - xess_properties_t* pBindingProperties); -typedef xess_result_t (*PFN_xessDestroyContext)(xess_context_handle_t hContext); -typedef xess_result_t (*PFN_xessSetVelocityScale)(xess_context_handle_t hContext, float x, float y); +typedef decltype(&xessD3D12CreateContext) PFN_xessD3D12CreateContext; +typedef decltype(&xessD3D12BuildPipelines) PFN_xessD3D12BuildPipelines; +typedef decltype(&xessD3D12Init) PFN_xessD3D12Init; +typedef decltype(&xessD3D12Execute) PFN_xessD3D12Execute; +typedef decltype(&xessSelectNetworkModel) PFN_xessSelectNetworkModel; +typedef decltype(&xessStartDump) PFN_xessStartDump; +typedef decltype(&xessGetVersion) PFN_xessGetVersion; +typedef decltype(&xessIsOptimalDriver) PFN_xessIsOptimalDriver; +typedef decltype(&xessSetLoggingCallback) PFN_xessSetLoggingCallback; +typedef decltype(&xessGetProperties) PFN_xessGetProperties; +typedef decltype(&xessDestroyContext) PFN_xessDestroyContext; +typedef decltype(&xessSetVelocityScale) PFN_xessSetVelocityScale; -typedef xess_result_t (*PFN_xessD3D12GetInitParams)(xess_context_handle_t hContext, - xess_d3d12_init_params_t* pInitParams); -typedef xess_result_t (*PFN_xessForceLegacyScaleFactors)(xess_context_handle_t hContext, bool force); -typedef xess_result_t (*PFN_xessGetExposureMultiplier)(xess_context_handle_t hContext, float* pScale); -typedef xess_result_t (*PFN_xessGetInputResolution)(xess_context_handle_t hContext, const xess_2d_t* pOutputResolution, - xess_quality_settings_t qualitySettings, - xess_2d_t* pInputResolution); -typedef xess_result_t (*PFN_xessGetIntelXeFXVersion)(xess_context_handle_t hContext, xess_version_t* pVersion); -typedef xess_result_t (*PFN_xessGetJitterScale)(xess_context_handle_t hContext, float* pX, float* pY); -typedef xess_result_t (*PFN_xessGetOptimalInputResolution)( - xess_context_handle_t hContext, const xess_2d_t* pOutputResolution, xess_quality_settings_t qualitySettings, - xess_2d_t* pInputResolutionOptimal, xess_2d_t* pInputResolutionMin, xess_2d_t* pInputResolutionMax); -typedef xess_result_t (*PFN_xessSetExposureMultiplier)(xess_context_handle_t hContext, float scale); -typedef xess_result_t (*PFN_xessSetJitterScale)(xess_context_handle_t hContext, float x, float y); +typedef decltype(&xessD3D12GetInitParams) PFN_xessD3D12GetInitParams; +typedef decltype(&xessForceLegacyScaleFactors) PFN_xessForceLegacyScaleFactors; +typedef decltype(&xessGetExposureMultiplier) PFN_xessGetExposureMultiplier; +typedef decltype(&xessGetInputResolution) PFN_xessGetInputResolution; +typedef decltype(&xessGetIntelXeFXVersion) PFN_xessGetIntelXeFXVersion; +typedef decltype(&xessGetJitterScale) PFN_xessGetJitterScale; +typedef decltype(&xessGetOptimalInputResolution) PFN_xessGetOptimalInputResolution; +typedef decltype(&xessSetExposureMultiplier) PFN_xessSetExposureMultiplier; +typedef decltype(&xessSetJitterScale) PFN_xessSetJitterScale; -typedef xess_result_t (*PFN_xessD3D12GetResourcesToDump)(xess_context_handle_t hContext, - xess_resources_to_dump_t** pResourcesToDump); -typedef xess_result_t (*PFN_xessD3D12GetProfilingData)(xess_context_handle_t hContext, - xess_profiling_data_t** pProfilingData); +typedef decltype(&xessD3D12GetResourcesToDump) PFN_xessD3D12GetResourcesToDump; +typedef decltype(&xessD3D12GetProfilingData) PFN_xessD3D12GetProfilingData; -typedef xess_result_t (*PFN_xessSetContextParameterF)(); -typedef xess_result_t (*PFN_xessGetPipelineBuildStatus)(xess_context_handle_t hContext); +typedef xess_result_t (*PFN_xessSetContextParameterF)(); // XeSS' headers don't export this +typedef decltype(&xessGetPipelineBuildStatus) PFN_xessGetPipelineBuildStatus; // Vulkan?!? -typedef xess_result_t (*PFN_xessVKGetRequiredInstanceExtensions)(uint32_t* instanceExtensionsCount, - const char* const** instanceExtensions, - uint32_t* minVkApiVersion); -typedef xess_result_t (*PFN_xessVKGetRequiredDeviceExtensions)(VkInstance instance, VkPhysicalDevice physicalDevice, - uint32_t* deviceExtensionsCount, - const char* const** deviceExtensions); -typedef xess_result_t (*PFN_xessVKGetRequiredDeviceFeatures)(VkInstance instance, VkPhysicalDevice physicalDevice, - void** features); -typedef xess_result_t (*PFN_xessVKCreateContext)(VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - xess_context_handle_t* phContext); -typedef xess_result_t (*PFN_xessVKBuildPipelines)(xess_context_handle_t hContext, VkPipelineCache pipelineCache, - bool blocking, uint32_t initFlags); -typedef xess_result_t (*PFN_xessVKInit)(xess_context_handle_t hContext, const xess_vk_init_params_t* pInitParams); -typedef xess_result_t (*PFN_xessVKGetInitParams)(xess_context_handle_t hContext, xess_vk_init_params_t* pInitParams); -typedef xess_result_t (*PFN_xessVKExecute)(xess_context_handle_t hContext, VkCommandBuffer commandBuffer, - const xess_vk_execute_params_t* pExecParams); -typedef xess_result_t (*PFN_xessVKGetResourcesToDump)(xess_context_handle_t hContext, - xess_vk_resources_to_dump_t** pResourcesToDump); +typedef decltype(&xessVKGetRequiredInstanceExtensions) PFN_xessVKGetRequiredInstanceExtensions; +typedef decltype(&xessVKGetRequiredDeviceExtensions) PFN_xessVKGetRequiredDeviceExtensions; +typedef decltype(&xessVKGetRequiredDeviceFeatures) PFN_xessVKGetRequiredDeviceFeatures; +typedef decltype(&xessVKCreateContext) PFN_xessVKCreateContext; +typedef decltype(&xessVKBuildPipelines) PFN_xessVKBuildPipelines; +typedef decltype(&xessVKInit) PFN_xessVKInit; +typedef decltype(&xessVKGetInitParams) PFN_xessVKGetInitParams; +typedef decltype(&xessVKExecute) PFN_xessVKExecute; +typedef decltype(&xessVKGetResourcesToDump) PFN_xessVKGetResourcesToDump; // Dx11 -typedef xess_result_t (*PFN_xessD3D11CreateContext)(ID3D11Device* device, xess_context_handle_t* phContext); -typedef xess_result_t (*PFN_xessD3D11Init)(xess_context_handle_t hContext, const xess_d3d11_init_params_t* pInitParams); -typedef xess_result_t (*PFN_xessD3D11GetInitParams)(xess_context_handle_t hContext, - xess_d3d11_init_params_t* pInitParams); -typedef xess_result_t (*PFN_xessD3D11Execute)(xess_context_handle_t hContext, - const xess_d3d11_execute_params_t* pExecParams); +typedef decltype(&xessD3D11CreateContext) PFN_xessD3D11CreateContext; +typedef decltype(&xessD3D11Init) PFN_xessD3D11Init; +typedef decltype(&xessD3D11GetInitParams) PFN_xessD3D11GetInitParams; +typedef decltype(&xessD3D11Execute) PFN_xessD3D11Execute; class XeSSProxy { @@ -105,7 +81,7 @@ class XeSSProxy inline static PFN_xessD3D12CreateContext _xessD3D12CreateContext = nullptr; inline static PFN_xessD3D12BuildPipelines _xessD3D12BuildPipelines = nullptr; - inline static PRN_xessD3D12Init _xessD3D12Init = nullptr; + inline static PFN_xessD3D12Init _xessD3D12Init = nullptr; inline static PFN_xessD3D12Execute _xessD3D12Execute = nullptr; inline static PFN_xessSelectNetworkModel _xessSelectNetworkModel = nullptr; inline static PFN_xessStartDump _xessStartDump = nullptr; @@ -361,7 +337,7 @@ class XeSSProxy (PFN_xessD3D12CreateContext) KernelBaseProxy::GetProcAddress_()(_dll, "xessD3D12CreateContext"); _xessD3D12BuildPipelines = (PFN_xessD3D12BuildPipelines) KernelBaseProxy::GetProcAddress_()(_dll, "xessD3D12BuildPipelines"); - _xessD3D12Init = (PRN_xessD3D12Init) KernelBaseProxy::GetProcAddress_()(_dll, "xessD3D12Init"); + _xessD3D12Init = (PFN_xessD3D12Init) KernelBaseProxy::GetProcAddress_()(_dll, "xessD3D12Init"); _xessD3D12Execute = (PFN_xessD3D12Execute) KernelBaseProxy::GetProcAddress_()(_dll, "xessD3D12Execute"); _xessSelectNetworkModel = (PFN_xessSelectNetworkModel) KernelBaseProxy::GetProcAddress_()(_dll, "xessSelectNetworkModel"); @@ -432,7 +408,7 @@ class XeSSProxy (PFN_xessD3D12CreateContext) DetourFindFunction("libxess.dll", "xessD3D12CreateContext"); _xessD3D12BuildPipelines = (PFN_xessD3D12BuildPipelines) DetourFindFunction("libxess.dll", "xessD3D12BuildPipelines"); - _xessD3D12Init = (PRN_xessD3D12Init) DetourFindFunction("libxess.dll", "xessD3D12Init"); + _xessD3D12Init = (PFN_xessD3D12Init) DetourFindFunction("libxess.dll", "xessD3D12Init"); _xessGetVersion = (PFN_xessGetVersion) DetourFindFunction("libxess.dll", "xessGetVersion"); _xessD3D12Execute = (PFN_xessD3D12Execute) DetourFindFunction("libxess.dll", "xessD3D12Execute"); _xessSelectNetworkModel = @@ -888,7 +864,7 @@ class XeSSProxy static PFN_xessD3D12CreateContext D3D12CreateContext() { return _xessD3D12CreateContext; } static PFN_xessD3D12BuildPipelines D3D12BuildPipelines() { return _xessD3D12BuildPipelines; } - static PRN_xessD3D12Init D3D12Init() { return _xessD3D12Init; } + static PFN_xessD3D12Init D3D12Init() { return _xessD3D12Init; } static PFN_xessD3D12Execute D3D12Execute() { return _xessD3D12Execute; } static PFN_xessSelectNetworkModel SelectNetworkModel() { return _xessSelectNetworkModel; } static PFN_xessStartDump StartDump() { return _xessStartDump; }