diff --git a/OptiScaler/NVNGX_DLSS_Vk.cpp b/OptiScaler/NVNGX_DLSS_Vk.cpp index d440d70b..65a7dfff 100644 --- a/OptiScaler/NVNGX_DLSS_Vk.cpp +++ b/OptiScaler/NVNGX_DLSS_Vk.cpp @@ -299,42 +299,40 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetFeatureInstanceExtensionRequi } } - if (FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_SuperSampling || FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_FrameGeneration) + if (FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_SuperSampling && OutExtensionCount != nullptr) // || FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_FrameGeneration) { - if (NVNGXProxy::NVNGXModule() != nullptr) + if ((FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_SuperSampling || FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_FrameGeneration) && OutExtensionCount != nullptr) { - LOG_INFO("returning no extensions are needed"); - *OutExtensionCount = 0; + if (OutExtensionProperties == nullptr) + { + if (Config::Instance()->VulkanExtensionSpoofing.value_or(false)) + { + LOG_INFO("returning 3 extensions are needed"); + *OutExtensionCount = 3; + } + else + { + LOG_INFO("returning no extensions are needed"); + *OutExtensionCount = 0; + } + } } + else if (*OutExtensionCount == 3 && Config::Instance()->VulkanExtensionSpoofing.value_or(false)) + { + LOG_INFO("returning extension infos"); - // Only Nvidia hardware should reach here, so in any case returning known extensions for DLSS - //if (OutExtensionProperties == nullptr) - //{ + std::memset((*OutExtensionProperties)[0].extensionName, 0, sizeof(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[0].extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + (*OutExtensionProperties)[0].specVersion = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION; - // if (NVNGXProxy::NVNGXModule() != nullptr) - // { - // LOG_INFO("returning 3 extensions are needed"); - // *OutExtensionCount = 3; - // } - // else - // { - // LOG_INFO("returning no extensions are needed"); - // *OutExtensionCount = 0; - // } - //} - //else if (*OutExtensionCount == 3) - //{ - // LOG_INFO("returning extension infos"); + std::memset((*OutExtensionProperties)[1].extensionName, 0, sizeof(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[1].extensionName, VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME); + (*OutExtensionProperties)[1].specVersion = VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION; - // strncpy_s(OutExtensionProperties[0]->extensionName, (VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME + '\0'), 39); - // OutExtensionProperties[0]->specVersion = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION; - - // strncpy_s(OutExtensionProperties[1]->extensionName, (VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME + '\0'), 36); - // OutExtensionProperties[1]->specVersion = VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION; - - // strncpy_s(OutExtensionProperties[2]->extensionName, (VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME + '\0'), 39); - // OutExtensionProperties[2]->specVersion = VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION; - //} + std::memset((*OutExtensionProperties)[2].extensionName, 0, sizeof(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[2].extensionName, VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME); + (*OutExtensionProperties)[2].specVersion = VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION; + } return NVSDK_NGX_Result_Success; } @@ -361,46 +359,41 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_GetFeatureDeviceExtensionRequire } } - if (FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_SuperSampling || FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_FrameGeneration) + if ((FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_SuperSampling || FeatureDiscoveryInfo->FeatureID == NVSDK_NGX_Feature_FrameGeneration) && OutExtensionCount != nullptr) { if (OutExtensionProperties == nullptr) { - LOG_INFO("returning no extensions are needed!"); - *OutExtensionCount = 0; + if (Config::Instance()->VulkanExtensionSpoofing.value_or(false)) + { + LOG_INFO("returning 4 extensions are needed!"); + *OutExtensionCount = 4; + } + else + { + LOG_INFO("returning no extensions are needed!"); + *OutExtensionCount = 0; + } } + else if (*OutExtensionCount == 4 && Config::Instance()->VulkanExtensionSpoofing.value_or(false)) + { + LOG_INFO("returning extension infos"); - // Only Nvidia hardware should reach here, so in any case returning known extensions for DLSS - //if (OutExtensionProperties == nullptr) - //{ + std::memset((*OutExtensionProperties)[0].extensionName, 0, sizeof(VK_NVX_BINARY_IMPORT_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[0].extensionName, VK_NVX_BINARY_IMPORT_EXTENSION_NAME); + (*OutExtensionProperties)[0].specVersion = VK_NVX_BINARY_IMPORT_SPEC_VERSION; - // if (NVNGXProxy::NVNGXModule() != nullptr) - // { + std::memset((*OutExtensionProperties)[1].extensionName, 0, sizeof(VK_NVX_IMAGE_VIEW_HANDLE_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[1].extensionName, VK_NVX_IMAGE_VIEW_HANDLE_EXTENSION_NAME); + (*OutExtensionProperties)[1].specVersion = VK_NVX_IMAGE_VIEW_HANDLE_SPEC_VERSION; - // LOG_INFO("returning 4 extensions are needed!"); - // *OutExtensionCount = 4; - // } - // else - // { - // LOG_INFO("returning no extensions are needed!"); - // *OutExtensionCount = 0; - // } - //} - //else if (*OutExtensionCount == 4) - //{ - // LOG_INFO("returning extension infos"); + std::memset((*OutExtensionProperties)[2].extensionName, 0, sizeof(VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[2].extensionName, VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME); + (*OutExtensionProperties)[2].specVersion = VK_EXT_BUFFER_DEVICE_ADDRESS_SPEC_VERSION; - // strncpy_s(OutExtensionProperties[0]->extensionName, (VK_NVX_BINARY_IMPORT_EXTENSION_NAME + '\0'), 21); - // OutExtensionProperties[0]->specVersion = VK_NVX_BINARY_IMPORT_SPEC_VERSION; - - // strncpy_s(OutExtensionProperties[1]->extensionName, (VK_NVX_IMAGE_VIEW_HANDLE_EXTENSION_NAME + '\0'), 25); - // OutExtensionProperties[1]->specVersion = VK_NVX_IMAGE_VIEW_HANDLE_SPEC_VERSION; - - // strncpy_s(OutExtensionProperties[2]->extensionName, (VK_EXT_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME + '\0'), 29); - // OutExtensionProperties[2]->specVersion = VK_EXT_BUFFER_DEVICE_ADDRESS_SPEC_VERSION; - - // strncpy_s(OutExtensionProperties[3]->extensionName, (VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME + '\0'), 23); - // OutExtensionProperties[3]->specVersion = VK_KHR_PUSH_DESCRIPTOR_SPEC_VERSION; - //} + std::memset((*OutExtensionProperties)[3].extensionName, 0, sizeof(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME)); + std::strcpy((*OutExtensionProperties)[3].extensionName, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); + (*OutExtensionProperties)[3].specVersion = VK_KHR_PUSH_DESCRIPTOR_SPEC_VERSION; + } return NVSDK_NGX_Result_Success; } diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index 9d56c129..7a48811c 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -1079,6 +1079,10 @@ static VkResult hkvkEnumerateDeviceExtensionProperties(VkPhysicalDevice physical LOG_FUNC(); auto count = *pPropertyCount; + + if (pProperties == nullptr) + count = 0; + auto result = o_vkEnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pPropertyCount, pProperties); if (result != VK_SUCCESS) @@ -1105,6 +1109,12 @@ static VkResult hkvkEnumerateDeviceExtensionProperties(VkPhysicalDevice physical VkExtensionProperties ivh{ VK_NVX_IMAGE_VIEW_HANDLE_EXTENSION_NAME, VK_NVX_IMAGE_VIEW_HANDLE_SPEC_VERSION }; memcpy(&pProperties[*pPropertyCount - 2], &ivh, sizeof(VkExtensionProperties)); + + LOG_DEBUG("Extensions returned:"); + for (size_t i = 0; i < *pPropertyCount; i++) + { + LOG_DEBUG(" {}", pProperties[i].extensionName); + } } LOG_FUNC_RESULT(result); @@ -1117,6 +1127,10 @@ static VkResult hkvkEnumerateInstanceExtensionProperties(const char* pLayerName, LOG_FUNC(); auto count = *pPropertyCount; + + if (pProperties == nullptr) + count = 0; + auto result = o_vkEnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties); if (result != VK_SUCCESS) @@ -1127,22 +1141,34 @@ static VkResult hkvkEnumerateInstanceExtensionProperties(const char* pLayerName, if (pLayerName == nullptr && pProperties == nullptr && count == 0) { - *pPropertyCount += 2; - vkEnumerateInstanceExtensionPropertiesCount = *pPropertyCount; - LOG_TRACE("hkvkEnumerateDeviceExtensionProperties({0}) count: {1}", pLayerName, vkEnumerateDeviceExtensionPropertiesCount); + //*pPropertyCount += 2; + //vkEnumerateInstanceExtensionPropertiesCount = *pPropertyCount; + //LOG_TRACE("hkvkEnumerateDeviceExtensionProperties({0}) count: {1}", pLayerName, vkEnumerateDeviceExtensionPropertiesCount); return result; } - if (pLayerName == nullptr && pProperties != nullptr && *pPropertyCount > 0) + //if (pLayerName == nullptr && pProperties != nullptr && *pPropertyCount > 0) + //{ + // if (vkEnumerateInstanceExtensionPropertiesCount == count) + // *pPropertyCount = count; + + // VkExtensionProperties bi{ VK_NVX_BINARY_IMPORT_EXTENSION_NAME, VK_NVX_BINARY_IMPORT_SPEC_VERSION }; + // memcpy(&pProperties[*pPropertyCount - 1], &bi, sizeof(VkExtensionProperties)); + + // VkExtensionProperties ivh{ VK_NVX_IMAGE_VIEW_HANDLE_EXTENSION_NAME, VK_NVX_IMAGE_VIEW_HANDLE_SPEC_VERSION }; + // memcpy(&pProperties[*pPropertyCount - 2], &ivh, sizeof(VkExtensionProperties)); + + // LOG_DEBUG("Extensions returned:"); + // for (size_t i = 0; i < *pPropertyCount; i++) + // { + // LOG_DEBUG(" {}", pProperties[i].extensionName); + // } + //} + + LOG_DEBUG("Extensions returned:"); + for (size_t i = 0; i < *pPropertyCount; i++) { - if (vkEnumerateInstanceExtensionPropertiesCount == count) - *pPropertyCount = count; - - VkExtensionProperties bi{ VK_NVX_BINARY_IMPORT_EXTENSION_NAME, VK_NVX_BINARY_IMPORT_SPEC_VERSION }; - memcpy(&pProperties[*pPropertyCount - 1], &bi, sizeof(VkExtensionProperties)); - - VkExtensionProperties ivh{ VK_NVX_IMAGE_VIEW_HANDLE_EXTENSION_NAME, VK_NVX_IMAGE_VIEW_HANDLE_SPEC_VERSION }; - memcpy(&pProperties[*pPropertyCount - 2], &ivh, sizeof(VkExtensionProperties)); + LOG_DEBUG(" {}", pProperties[i].extensionName); } LOG_FUNC_RESULT(result); diff --git a/OptiScaler/dllmain.h b/OptiScaler/dllmain.h index 3e6955f7..8712bb6a 100644 --- a/OptiScaler/dllmain.h +++ b/OptiScaler/dllmain.h @@ -1350,17 +1350,56 @@ bool SkipSpoofing() auto skip = !Config::Instance()->DxgiSpoofing.value_or(true) || Config::Instance()->dxgiSkipSpoofing; // || Config::Instance()->IsRunningOnLinux; if (skip) - LOG_TRACE("DxgiSpoofing: {}, dxgiSkipSpoofing: {}, skipping spoofing", + LOG_TRACE("DxgiSpoofing: {}, dxgiSkipSpoofing: {}, skipping spoofing", Config::Instance()->DxgiSpoofing.value_or(true), Config::Instance()->dxgiSkipSpoofing); - if (!skip && Config::Instance()->DxgiBlacklist.has_value()) + HANDLE process = GetCurrentProcess(); + + if (!skip && Config::Instance()->DxgiBlacklist.has_value() && process != nullptr) { skip = true; + /* + * File based spoofing + SymInitialize(process, NULL, TRUE); + + // Capture stack trace + const int maxFrames = 64; + void* stack[maxFrames]; + USHORT frames = CaptureStackBackTrace(0, maxFrames, stack, NULL); + + for (USHORT i = 0; i < frames; ++i) + { + DWORD64 address = (DWORD64)(stack[i]); + DWORD64 moduleBase = SymGetModuleBase64(process, address); + + if (moduleBase) + { + char moduleName[MAX_PATH]; + if (GetModuleFileNameA((HINSTANCE)moduleBase, moduleName, MAX_PATH)) + { + std::string module(moduleName); + LOG_TRACE("ModuleName: {}", module); + + auto pos = module.rfind("\\sl."); + + if (pos != std::string::npos) + { + LOG_INFO("spoofing for: {0}", module); + skip = false; + break; + } + } + } + } + + SymCleanup(process); + */ + // Walk the call stack to find the DLL that is calling the hooked function void* callers[100]; unsigned short frames = CaptureStackBackTrace(0, 100, callers, NULL); - HANDLE process = GetCurrentProcess(); + //HANDLE process = GetCurrentProcess(); if (SymInitialize(process, NULL, TRUE)) { @@ -1713,7 +1752,7 @@ void AttachToAdapter(IUnknown* unkAdapter) IDXGIAdapter* adapter = nullptr; bool adapterOk = unkAdapter->QueryInterface(__uuidof(IDXGIAdapter), (void**)&adapter) == S_OK; - + void* dxvkAdapter = nullptr; if (adapterOk && !Config::Instance()->IsRunningOnDXVK && adapter->QueryInterface(guid, &dxvkAdapter) == S_OK) { @@ -1721,7 +1760,7 @@ void AttachToAdapter(IUnknown* unkAdapter) ((IDXGIAdapter*)dxvkAdapter)->Release(); } - if(Config::Instance()->IsRunningOnDXVK != dxvkStatus) + if (Config::Instance()->IsRunningOnDXVK != dxvkStatus) LOG_INFO("IDXGIVkInteropDevice interface (DXVK) {0}", Config::Instance()->IsRunningOnDXVK ? "detected" : "not detected"); if (ptrGetDesc == nullptr && adapterOk) diff --git a/nvngx.ini b/nvngx.ini index 503899bc..cb22827c 100644 --- a/nvngx.ini +++ b/nvngx.ini @@ -582,7 +582,7 @@ SkipFirstFrames=auto ; Restore last used compute signature after upscaling ; true or false - Default (auto) is true -RestoreComputeSignature=true +RestoreComputeSignature=auto ; Restore last used graphics signature after upscaling ; true or false - Default (auto) is false