From a9915579a0ea5d850bddee9af1276c07a4e35a05 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 22 Jun 2024 22:58:45 +0200 Subject: [PATCH] impr: Better detection of Intel GPUs with really bad driver bugs --- lib/libimhex/include/hex/api/imhex_api.hpp | 7 +++ lib/libimhex/source/api/imhex_api.cpp | 9 ++++ main/gui/source/init/splash_window.cpp | 1 + .../source/content/settings_entries.cpp | 46 ++++++++++++++----- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 258395422..d98a0175a 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -434,6 +434,7 @@ namespace hex { void setInitialWindowProperties(InitialWindowProperties properties); void setGPUVendor(const std::string &vendor); + void setGLRenderer(const std::string &renderer); void addInitArgument(const std::string &key, const std::string &value = { }); @@ -573,6 +574,12 @@ namespace hex { */ const std::string& getGPUVendor(); + /** + * @brief Gets the current GPU vendor + * @return The current GPU vendor + */ + const std::string& getGLRenderer(); + /** * @brief Checks if ImHex is running in portable mode * @return Whether ImHex is running in portable mode diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index eec325353..46a6f8d2e 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -532,6 +532,11 @@ namespace hex { s_gpuVendor = vendor; } + static AutoReset s_glRenderer; + void setGLRenderer(const std::string &renderer) { + s_glRenderer = renderer; + } + static AutoReset> s_initArguments; void addInitArgument(const std::string &key, const std::string &value) { static std::mutex initArgumentsMutex; @@ -676,6 +681,10 @@ namespace hex { return impl::s_gpuVendor; } + const std::string &getGLRenderer() { + return impl::s_glRenderer; + } + bool isPortableVersion() { static std::optional portable; if (portable.has_value()) diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index c79d6f470..5cb2d3960 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -56,6 +56,7 @@ namespace hex::init { log::debug("OpenGL Shading Language Version: '{}'", glShadingLanguageVersion); ImHexApi::System::impl::setGPUVendor(glVendor); + ImHexApi::System::impl::setGLRenderer(glRenderer); } RequestAddInitTask::subscribe([this](const std::string& name, bool async, const TaskFunction &function){ diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 5a0fdb8ee..7ac93fa89 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -656,22 +656,46 @@ namespace hex::plugin::builtin { bool getDefaultBorderlessWindowMode() { - bool result = false; + bool result; - #if defined (OS_WINDOWS) || defined(OS_MACOS) + #if defined (OS_WINDOWS) result = true; - #endif - // Intel's OpenGL driver has weird bugs that cause the drawn window to be offset to the bottom right. - // This can be fixed by either using Mesa3D's OpenGL Software renderer or by simply disabling it. - // If you want to try if it works anyways on your GPU, set the hex.builtin.setting.interface.force_borderless_window_mode setting to 1 - if (ImHexApi::System::isBorderlessWindowModeEnabled()) { + // Intel's OpenGL driver is extremely buggy. Its issues can manifest in lots of different ways + // such as "colorful snow" appearing on the screen or, the most annoying issue, + // it might draw the window content slightly offset to the bottom right as seen in issue #1625 + + // The latter issue can be circumvented by using the native OS decorations or by using the software renderer. + // This code here tries to detect if the user has a problematic Intel GPU and if so, it will default to the native OS decorations. + // This doesn't actually solve the issue at all but at least it makes ImHex usable on these GPUs. const bool isIntelGPU = hex::containsIgnoreCase(ImHexApi::System::getGPUVendor(), "Intel"); + if (isIntelGPU) { + log::warn("Intel GPU detected! Intel's OpenGL GPU drivers are extremely buggy and can cause issues when using ImHex. If you experience any rendering bugs, please enable the Native OS Decoration setting or try the software rendererd -NoGPU release."); - result = !isIntelGPU; - if (isIntelGPU) - log::warn("Intel GPU detected! Intel's OpenGL driver has bugs that can cause issues when using ImHex. If you experience any rendering bugs, please enable the Native OS Decoration setting or try the software rendererd -NoGPU release."); - } + // Non-exhaustive list of bad GPUs. + // If more GPUs are found to be problematic, they can be added here. + constexpr static std::array BadGPUs = { + // Sandy Bridge Series, Second Gen HD Graphics + "HD Graphics 2000", + "HD Graphics 3000" + }; + + const auto &glRenderer = ImHexApi::System::getGLRenderer(); + for (const auto &badGPU : BadGPUs) { + if (hex::containsIgnoreCase(glRenderer, badGPU)) { + result = false; + break; + } + } + } + + #elif defined(OS_MACOS) + result = true; + #elif defined(OS_LINUX) + // On Linux, things like Window snapping and moving is hard to implement + // without hacking e.g. libdecor, therefor we default to the native window decorations. + result = false; + #endif return result; }