From ad0ab2f3961bf58135f24802dd37e0a217e7f738 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:09:30 +0300 Subject: [PATCH] [Windows] Improve OpenGL/ANGLE switching on ARM64. --- platform/windows/display_server_windows.cpp | 36 ++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 020ef0c31b3..fa6ed81793f 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -5984,13 +5984,32 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win // Init context and rendering device #if defined(GLES3_ENABLED) -#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) - // There's no native OpenGL drivers on Windows for ARM, switch to ANGLE over DX. - if (rendering_driver == "opengl3") { - rendering_driver = "opengl3_angle"; - } -#elif defined(EGL_STATIC) bool fallback = GLOBAL_GET("rendering/gl_compatibility/fallback_to_angle"); + bool show_warning = true; + + if (rendering_driver == "opengl3") { + // There's no native OpenGL drivers on Windows for ARM, always enable fallback. +#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) + fallback = true; + show_warning = false; +#else + typedef BOOL(WINAPI * IsWow64Process2Ptr)(HANDLE, USHORT *, USHORT *); + + IsWow64Process2Ptr IsWow64Process2 = (IsWow64Process2Ptr)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process2"); + if (IsWow64Process2) { + USHORT process_arch = 0; + USHORT machine_arch = 0; + if (!IsWow64Process2(GetCurrentProcess(), &process_arch, &machine_arch)) { + machine_arch = 0; + } + if (machine_arch == 0xAA64) { + fallback = true; + show_warning = false; + } + } +#endif + } + if (fallback && (rendering_driver == "opengl3")) { Dictionary gl_info = detect_wgl(); @@ -6016,11 +6035,12 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } if (force_angle || (gl_info["version"].operator int() < 30003)) { - WARN_PRINT("Your video card drivers seem not to support the required OpenGL 3.3 version, switching to ANGLE."); + if (show_warning) { + WARN_PRINT("Your video card drivers seem not to support the required OpenGL 3.3 version, switching to ANGLE."); + } rendering_driver = "opengl3_angle"; } } -#endif if (rendering_driver == "opengl3") { gl_manager_native = memnew(GLManagerNative_Windows);