From 6eee4520c72ce8a2e2815cd613d144a7054ea2c3 Mon Sep 17 00:00:00 2001 From: Evan Mezeske Date: Tue, 22 Oct 2024 22:01:58 -0700 Subject: [PATCH] vk: Add a workaround for a Windows NVIDIA Vulkan driver bug that causes swap chains to be created with incorrect dimensions for native windows created with thread-specific DPI-awareness context. (#8221) --- .../platform/VulkanPlatformAndroidLinuxWindows.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/filament/backend/src/vulkan/platform/VulkanPlatformAndroidLinuxWindows.cpp b/filament/backend/src/vulkan/platform/VulkanPlatformAndroidLinuxWindows.cpp index f12d9e7931..e7e12ac675 100644 --- a/filament/backend/src/vulkan/platform/VulkanPlatformAndroidLinuxWindows.cpp +++ b/filament/backend/src/vulkan/platform/VulkanPlatformAndroidLinuxWindows.cpp @@ -195,6 +195,15 @@ VulkanPlatform::SurfaceBundle VulkanPlatform::createVkSurfaceKHR(void* nativeWin } #endif #elif defined(WIN32) + // On (at least) NVIDIA drivers, the Vulkan implementation (specifically the call to + // vkGetPhysicalDeviceSurfaceCapabilitiesKHR()) does not correctly handle the fact that + // each native window has its own DPI_AWARENESS_CONTEXT, and erroneously uses the context + // of the calling thread. As a workaround, we set the current thread's DPI_AWARENESS_CONTEXT + // to that of the native window we've been given. This isn't a perfect solution, because an + // application could create swap chains on multiple native windows with varying DPI-awareness, + // but even then, at least one of the windows would be guaranteed to work correctly. + SetThreadDpiAwarenessContext(GetWindowDpiAwarenessContext((HWND) nativeWindow)); + VkWin32SurfaceCreateInfoKHR const createInfo = { .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, .hinstance = GetModuleHandle(nullptr),