mirror of
https://github.com/optiscaler/OptiScaler.git
synced 2026-09-24 14:25:42 +00:00
Fix build issues
This commit is contained in:
@@ -26,6 +26,7 @@ inline static UINT64 resizeFenceValue = 0;
|
||||
inline static HANDLE resizeFenceEvent = nullptr;
|
||||
inline static IUnknown* oldSwapChain = nullptr;
|
||||
inline static ID3D12CommandQueue* currentCommandQueue = nullptr;
|
||||
inline static bool _forcedHdrForXeFG = false;
|
||||
|
||||
#if (XEFG_RESOURCE_REF_LIMIT == 0)
|
||||
inline static std::vector<void*> oldBackBuffers;
|
||||
|
||||
+188
-187
@@ -169,224 +169,225 @@ static VkResult hkvkCreateDevice(VkPhysicalDevice physicalDevice, const VkDevice
|
||||
if (szName.size() > 0)
|
||||
State::Instance().DeviceAdapterNames[*pDevice] = szName;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_QUEUE_SUBMIT_2_KHR
|
||||
if (result == VK_SUCCESS)
|
||||
hkvkGetDeviceProcAddr(*pDevice, "vkQueueSubmit2KHR");
|
||||
if (result == VK_SUCCESS)
|
||||
hkvkGetDeviceProcAddr(*pDevice, "vkQueueSubmit2KHR");
|
||||
#endif
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
LOG_FUNC_RESULT(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static VkResult hkvkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
// get upscaler time
|
||||
UpscalerTimeVk::ReadUpscalingTime(_device);
|
||||
|
||||
if (!State::Instance().isRunningOnDXVK)
|
||||
State::Instance().swapchainApi = Vulkan;
|
||||
|
||||
// Tick feature to let it know if it's frozen
|
||||
if (auto currentFeature = State::Instance().currentFeature; currentFeature != nullptr)
|
||||
currentFeature->TickFrozenCheck();
|
||||
|
||||
VkPresentInfoKHR localPresentInfo {};
|
||||
memcpy(&localPresentInfo, pPresentInfo, sizeof(VkPresentInfoKHR));
|
||||
|
||||
// render menu if needed
|
||||
if (!MenuOverlayVk::QueuePresent(queue, &localPresentInfo))
|
||||
{
|
||||
LOG_ERROR("QueuePresent: false!");
|
||||
return VK_ERROR_OUT_OF_DATE_KHR;
|
||||
}
|
||||
|
||||
ReflexHooks::update(false, true);
|
||||
|
||||
// original call
|
||||
ScopedVulkanCreatingSC scopedVulkanCreatingSC {};
|
||||
auto result = o_QueuePresentKHR(queue, &localPresentInfo);
|
||||
|
||||
// Unsure about Vulkan Reflex fps limit and if that could be causing an issue here
|
||||
if (!State::Instance().reflexLimitsFps)
|
||||
FrameLimit::sleep(false);
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||
VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
ScopedVulkanCreatingSC scopedVulkanCreatingSC {};
|
||||
VkResult result = VK_SUCCESS;
|
||||
{
|
||||
ScopedSkipSpoofing skipSpoofing {};
|
||||
result = o_CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
|
||||
}
|
||||
|
||||
if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr && *pSwapchain != VK_NULL_HANDLE &&
|
||||
!State::Instance().vulkanSkipHooks)
|
||||
{
|
||||
State::Instance().screenWidth = static_cast<float>(pCreateInfo->imageExtent.width);
|
||||
State::Instance().screenHeight = static_cast<float>(pCreateInfo->imageExtent.height);
|
||||
|
||||
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);
|
||||
|
||||
MenuOverlayVk::CreateSwapchain(device, _PD, _instance, _hwnd, pCreateInfo, pAllocator, pSwapchain);
|
||||
}
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction hkvkGetInstanceProcAddr(VkInstance instance, const char* pName)
|
||||
{
|
||||
auto orgFunc = o_vkGetInstanceProcAddr(instance, pName);
|
||||
|
||||
if (orgFunc == VK_NULL_HANDLE)
|
||||
return VK_NULL_HANDLE;
|
||||
|
||||
auto procName = std::string(pName);
|
||||
|
||||
if (procName == std::string("vkCreateInstance"))
|
||||
{
|
||||
if (o_vkCreateInstance == nullptr)
|
||||
o_vkCreateInstance = (PFN_vkCreateInstance) orgFunc;
|
||||
|
||||
LOG_DEBUG("vkCreateInstance");
|
||||
return (PFN_vkVoidFunction) hkvkCreateInstance;
|
||||
}
|
||||
else if (procName == std::string("vkCreateDevice"))
|
||||
{
|
||||
if (o_vkCreateDevice == nullptr)
|
||||
o_vkCreateDevice = (PFN_vkCreateDevice) orgFunc;
|
||||
|
||||
LOG_DEBUG("vkCreateDevice");
|
||||
return (PFN_vkVoidFunction) hkvkCreateDevice;
|
||||
}
|
||||
|
||||
auto result = VulkanSpoofing::hkvkGetInstanceProcAddr(orgFunc, pName);
|
||||
if (result != VK_NULL_HANDLE)
|
||||
return result;
|
||||
|
||||
return orgFunc;
|
||||
}
|
||||
|
||||
PFN_vkVoidFunction hkvkGetDeviceProcAddr(VkDevice device, const char* pName)
|
||||
{
|
||||
auto orgFunc = o_vkGetDeviceProcAddr(device, pName);
|
||||
|
||||
if (orgFunc == VK_NULL_HANDLE)
|
||||
return VK_NULL_HANDLE;
|
||||
|
||||
auto procName = std::string(pName);
|
||||
|
||||
if (procName == std::string("vkCreateInstance"))
|
||||
{
|
||||
if (o_vkCreateInstance == nullptr)
|
||||
o_vkCreateInstance = (PFN_vkCreateInstance) orgFunc;
|
||||
|
||||
LOG_DEBUG("vkCreateInstance");
|
||||
return (PFN_vkVoidFunction) hkvkCreateInstance;
|
||||
}
|
||||
else if (procName == std::string("vkCreateDevice"))
|
||||
{
|
||||
if (o_vkCreateDevice == nullptr)
|
||||
o_vkCreateDevice = (PFN_vkCreateDevice) orgFunc;
|
||||
|
||||
LOG_DEBUG("vkCreateDevice");
|
||||
return (PFN_vkVoidFunction) hkvkCreateDevice;
|
||||
}
|
||||
|
||||
static VkResult hkvkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo)
|
||||
{
|
||||
LOG_FUNC();
|
||||
|
||||
// get upscaler time
|
||||
UpscalerTimeVk::ReadUpscalingTime(_device);
|
||||
|
||||
if (!State::Instance().isRunningOnDXVK)
|
||||
State::Instance().swapchainApi = Vulkan;
|
||||
|
||||
// Tick feature to let it know if it's frozen
|
||||
if (auto currentFeature = State::Instance().currentFeature; currentFeature != nullptr)
|
||||
currentFeature->TickFrozenCheck();
|
||||
|
||||
VkPresentInfoKHR localPresentInfo {};
|
||||
memcpy(&localPresentInfo, pPresentInfo, sizeof(VkPresentInfoKHR));
|
||||
|
||||
// render menu if needed
|
||||
if (!MenuOverlayVk::QueuePresent(queue, &localPresentInfo))
|
||||
{
|
||||
LOG_ERROR("QueuePresent: false!");
|
||||
return VK_ERROR_OUT_OF_DATE_KHR;
|
||||
}
|
||||
|
||||
ReflexHooks::update(false, true);
|
||||
|
||||
// original call
|
||||
ScopedVulkanCreatingSC scopedVulkanCreatingSC {};
|
||||
auto result = o_QueuePresentKHR(queue, &localPresentInfo);
|
||||
|
||||
// Unsure about Vulkan Reflex fps limit and if that could be causing an issue here
|
||||
if (!State::Instance().reflexLimitsFps)
|
||||
FrameLimit::sleep(false);
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
auto result = VulkanSpoofing::hkvkGetDeviceProcAddr(orgFunc, pName);
|
||||
if (result != VK_NULL_HANDLE)
|
||||
return result;
|
||||
}
|
||||
|
||||
static VkResult hkvkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo,
|
||||
VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain)
|
||||
{
|
||||
LOG_FUNC();
|
||||
return orgFunc;
|
||||
}
|
||||
|
||||
ScopedVulkanCreatingSC scopedVulkanCreatingSC {};
|
||||
VkResult result = VK_SUCCESS;
|
||||
{
|
||||
ScopedSkipSpoofing skipSpoofing {};
|
||||
result = o_CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
|
||||
}
|
||||
void VulkanHooks::Hook(HMODULE vulkan1)
|
||||
{
|
||||
VulkanSpoofing::HookForVulkanSpoofing(vulkan1);
|
||||
VulkanSpoofing::HookForVulkanExtensionSpoofing(vulkan1);
|
||||
VulkanSpoofing::HookForVulkanVRAMSpoofing(vulkan1);
|
||||
|
||||
if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr &&
|
||||
*pSwapchain != VK_NULL_HANDLE && !State::Instance().vulkanSkipHooks)
|
||||
{
|
||||
State::Instance().screenWidth = static_cast<float>(pCreateInfo->imageExtent.width);
|
||||
State::Instance().screenHeight = static_cast<float>(pCreateInfo->imageExtent.height);
|
||||
if (o_vkCreateDevice != nullptr)
|
||||
return;
|
||||
|
||||
LOG_DEBUG("if (result == VK_SUCCESS && device != VK_NULL_HANDLE && pCreateInfo != nullptr && pSwapchain != "
|
||||
"VK_NULL_HANDLE)");
|
||||
FARPROC address = nullptr;
|
||||
|
||||
_device = device;
|
||||
LOG_DEBUG("_device captured: {0:X}", (UINT64) _device);
|
||||
o_vkCreateDevice = (PFN_vkCreateDevice) KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCreateDevice");
|
||||
o_vkCreateInstance = (PFN_vkCreateInstance) KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCreateInstance");
|
||||
|
||||
MenuOverlayVk::CreateSwapchain(device, _PD, _instance, _hwnd, pCreateInfo, pAllocator, pSwapchain);
|
||||
}
|
||||
address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkGetInstanceProcAddr");
|
||||
o_vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) address;
|
||||
|
||||
LOG_FUNC_RESULT(result);
|
||||
return result;
|
||||
}
|
||||
address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkGetDeviceProcAddr");
|
||||
o_vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr) address;
|
||||
|
||||
PFN_vkVoidFunction hkvkGetInstanceProcAddr(VkInstance instance, const char* pName)
|
||||
{
|
||||
auto orgFunc = o_vkGetInstanceProcAddr(instance, pName);
|
||||
address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCreateWin32SurfaceKHR");
|
||||
o_vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) address;
|
||||
|
||||
if (orgFunc == VK_NULL_HANDLE)
|
||||
return VK_NULL_HANDLE;
|
||||
// address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCmdPipelineBarrier");
|
||||
// o_vkCmdPipelineBarrier = (PFN_vkCmdPipelineBarrier) address;
|
||||
|
||||
auto procName = std::string(pName);
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
if (procName == std::string("vkCreateInstance"))
|
||||
{
|
||||
if (o_vkCreateInstance == nullptr)
|
||||
o_vkCreateInstance = (PFN_vkCreateInstance) orgFunc;
|
||||
if (o_vkCreateDevice != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkCreateDevice, hkvkCreateDevice);
|
||||
|
||||
LOG_DEBUG("vkCreateInstance");
|
||||
return (PFN_vkVoidFunction) hkvkCreateInstance;
|
||||
}
|
||||
else if (procName == std::string("vkCreateDevice"))
|
||||
{
|
||||
if (o_vkCreateDevice == nullptr)
|
||||
o_vkCreateDevice = (PFN_vkCreateDevice) orgFunc;
|
||||
if (o_vkGetInstanceProcAddr != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkGetInstanceProcAddr, hkvkGetInstanceProcAddr);
|
||||
|
||||
LOG_DEBUG("vkCreateDevice");
|
||||
return (PFN_vkVoidFunction) hkvkCreateDevice;
|
||||
}
|
||||
if (o_vkGetDeviceProcAddr != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkGetDeviceProcAddr, hkvkGetDeviceProcAddr);
|
||||
|
||||
auto result = VulkanSpoofing::hkvkGetInstanceProcAddr(orgFunc, pName);
|
||||
if (result != VK_NULL_HANDLE)
|
||||
return result;
|
||||
if (o_vkCreateInstance != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkCreateInstance, hkvkCreateInstance);
|
||||
|
||||
return orgFunc;
|
||||
}
|
||||
if (o_vkCreateWin32SurfaceKHR != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkCreateWin32SurfaceKHR, hkvkCreateWin32SurfaceKHR);
|
||||
|
||||
PFN_vkVoidFunction hkvkGetDeviceProcAddr(VkDevice device, const char* pName)
|
||||
{
|
||||
auto orgFunc = o_vkGetDeviceProcAddr(device, pName);
|
||||
// if (o_vkCmdPipelineBarrier != nullptr)
|
||||
// DetourAttach(&(PVOID&) o_vkCmdPipelineBarrier, hkvkCmdPipelineBarrier);
|
||||
|
||||
if (orgFunc == VK_NULL_HANDLE)
|
||||
return VK_NULL_HANDLE;
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
auto procName = std::string(pName);
|
||||
void VulkanHooks::Unhook()
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
if (procName == std::string("vkCreateInstance"))
|
||||
{
|
||||
if (o_vkCreateInstance == nullptr)
|
||||
o_vkCreateInstance = (PFN_vkCreateInstance) orgFunc;
|
||||
if (o_QueuePresentKHR != nullptr)
|
||||
DetourDetach(&(PVOID&) o_QueuePresentKHR, hkvkQueuePresentKHR);
|
||||
|
||||
LOG_DEBUG("vkCreateInstance");
|
||||
return (PFN_vkVoidFunction) hkvkCreateInstance;
|
||||
}
|
||||
else if (procName == std::string("vkCreateDevice"))
|
||||
{
|
||||
if (o_vkCreateDevice == nullptr)
|
||||
o_vkCreateDevice = (PFN_vkCreateDevice) orgFunc;
|
||||
if (o_CreateSwapchainKHR != nullptr)
|
||||
DetourDetach(&(PVOID&) o_CreateSwapchainKHR, hkvkCreateSwapchainKHR);
|
||||
|
||||
LOG_DEBUG("vkCreateDevice");
|
||||
return (PFN_vkVoidFunction) hkvkCreateDevice;
|
||||
}
|
||||
if (o_vkCreateDevice != nullptr)
|
||||
DetourDetach(&(PVOID&) o_vkCreateDevice, hkvkCreateDevice);
|
||||
|
||||
auto result = VulkanSpoofing::hkvkGetDeviceProcAddr(orgFunc, pName);
|
||||
if (result != VK_NULL_HANDLE)
|
||||
return result;
|
||||
if (o_vkCreateInstance != nullptr)
|
||||
DetourDetach(&(PVOID&) o_vkCreateInstance, hkvkCreateInstance);
|
||||
|
||||
return orgFunc;
|
||||
}
|
||||
if (o_vkCreateWin32SurfaceKHR != nullptr)
|
||||
DetourDetach(&(PVOID&) o_vkCreateWin32SurfaceKHR, hkvkCreateWin32SurfaceKHR);
|
||||
|
||||
void VulkanHooks::Hook(HMODULE vulkan1)
|
||||
{
|
||||
VulkanSpoofing::HookForVulkanSpoofing(vulkan1);
|
||||
VulkanSpoofing::HookForVulkanExtensionSpoofing(vulkan1);
|
||||
VulkanSpoofing::HookForVulkanVRAMSpoofing(vulkan1);
|
||||
// if (o_vkCmdPipelineBarrier != nullptr)
|
||||
// DetourDetach(&(PVOID&) o_vkCmdPipelineBarrier, hkvkCmdPipelineBarrier);
|
||||
|
||||
if (o_vkCreateDevice != nullptr)
|
||||
return;
|
||||
|
||||
FARPROC address = nullptr;
|
||||
|
||||
o_vkCreateDevice = (PFN_vkCreateDevice) KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCreateDevice");
|
||||
o_vkCreateInstance = (PFN_vkCreateInstance) KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCreateInstance");
|
||||
|
||||
address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkGetInstanceProcAddr");
|
||||
o_vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) address;
|
||||
|
||||
address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkGetDeviceProcAddr");
|
||||
o_vkGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr) address;
|
||||
|
||||
address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCreateWin32SurfaceKHR");
|
||||
o_vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) address;
|
||||
|
||||
// address = KernelBaseProxy::GetProcAddress_()(vulkan1, "vkCmdPipelineBarrier");
|
||||
// o_vkCmdPipelineBarrier = (PFN_vkCmdPipelineBarrier) address;
|
||||
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
if (o_vkCreateDevice != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkCreateDevice, hkvkCreateDevice);
|
||||
|
||||
if (o_vkGetInstanceProcAddr != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkGetInstanceProcAddr, hkvkGetInstanceProcAddr);
|
||||
|
||||
if (o_vkGetDeviceProcAddr != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkGetDeviceProcAddr, hkvkGetDeviceProcAddr);
|
||||
|
||||
if (o_vkCreateInstance != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkCreateInstance, hkvkCreateInstance);
|
||||
|
||||
if (o_vkCreateWin32SurfaceKHR != nullptr)
|
||||
DetourAttach(&(PVOID&) o_vkCreateWin32SurfaceKHR, hkvkCreateWin32SurfaceKHR);
|
||||
|
||||
// if (o_vkCmdPipelineBarrier != nullptr)
|
||||
// DetourAttach(&(PVOID&) o_vkCmdPipelineBarrier, hkvkCmdPipelineBarrier);
|
||||
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
void VulkanHooks::Unhook()
|
||||
{
|
||||
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);
|
||||
|
||||
// if (o_vkCmdPipelineBarrier != nullptr)
|
||||
// DetourDetach(&(PVOID&) o_vkCmdPipelineBarrier, hkvkCmdPipelineBarrier);
|
||||
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user