From 63a019b7493d83c62a55a106ca97bbe38f6b7676 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 21 Dec 2022 22:13:23 -0800 Subject: [PATCH] Qt: Start OpenGL bug list with glFlush cross-thread on Windows (fixes #2761) --- src/platform/qt/CMakeLists.txt | 1 + src/platform/qt/DisplayGL.cpp | 9 ++++++++- src/platform/qt/OpenGLBug.cpp | 34 ++++++++++++++++++++++++++++++++++ src/platform/qt/OpenGLBug.h | 17 +++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/platform/qt/OpenGLBug.cpp create mode 100644 src/platform/qt/OpenGLBug.h diff --git a/src/platform/qt/CMakeLists.txt b/src/platform/qt/CMakeLists.txt index 9b1f60288..204f8e89a 100644 --- a/src/platform/qt/CMakeLists.txt +++ b/src/platform/qt/CMakeLists.txt @@ -118,6 +118,7 @@ set(SOURCE_FILES MessagePainter.cpp MultiplayerController.cpp ObjView.cpp + OpenGLBug.cpp OverrideView.cpp PaletteView.cpp PlacementControl.cpp diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index 4b0fcdce3..0528922fb 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -44,6 +44,8 @@ using QOpenGLFunctions_Baseline = QOpenGLFunctions_3_2_Core; #define OVERHEAD_NSEC 300000 #endif +#include "OpenGLBug.h" + using namespace QGBA; QHash DisplayGL::s_supports; @@ -959,7 +961,12 @@ QOpenGLContext* PainterGL::shareContext() { void PainterGL::updateFramebufferHandle() { QOpenGLFunctions_Baseline* fn = m_gl->versionFunctions(); - fn->glFlush(); + // TODO: Figure out why glFlush doesn't work here on Intel/Windows + if (glContextHasBug(OpenGLBug::CROSS_THREAD_FLUSH)) { + fn->glFinish(); + } else { + fn->glFlush(); + } CoreController::Interrupter interrupter(m_context); if (!m_context->hardwareAccelerated()) { diff --git a/src/platform/qt/OpenGLBug.cpp b/src/platform/qt/OpenGLBug.cpp new file mode 100644 index 000000000..e00310c56 --- /dev/null +++ b/src/platform/qt/OpenGLBug.cpp @@ -0,0 +1,34 @@ +/* Copyright (c) 2013-2022 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "OpenGLBug.h" + +#include +#include + +namespace QGBA { + +bool glContextHasBug(OpenGLBug bug) { + QOpenGLContext* context = QOpenGLContext::currentContext(); + if (!context) { + abort(); + } + QOpenGLFunctions* fn = context->functions(); + QString vendor(reinterpret_cast(fn->glGetString(GL_VENDOR))); + QString renderer(reinterpret_cast(fn->glGetString(GL_RENDERER))); + + switch (bug) { + case OpenGLBug::CROSS_THREAD_FLUSH: +#ifndef Q_OS_WIN + return false; +#else + return vendor == "Intel"; +#endif + default: + return false; + } +} + +} diff --git a/src/platform/qt/OpenGLBug.h b/src/platform/qt/OpenGLBug.h new file mode 100644 index 000000000..fda0ed555 --- /dev/null +++ b/src/platform/qt/OpenGLBug.h @@ -0,0 +1,17 @@ +/* Copyright (c) 2013-2022 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#pragma once + +namespace QGBA { + +enum class OpenGLBug { + // mgba.io/i/2761 + CROSS_THREAD_FLUSH +}; + +bool glContextHasBug(OpenGLBug); + +}