From 63513949189b501500961721b5186c90c9672df3 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 1 Aug 2022 12:45:38 +0600 Subject: [PATCH 1/4] qt: Fix compile on ARM64 with GLES2 headers --- src/qt/qt_openglrenderer.cpp | 14 ++++++++++++-- src/qt/qt_openglrenderer.hpp | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 7c7cd55fa..3a5f58846 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -26,6 +26,14 @@ #include "qt_opengloptionsdialog.hpp" #include "qt_openglrenderer.hpp" +#ifndef GL_MAP_PERSISTENT_BIT +#define GL_MAP_PERSISTENT_BIT 0x0040 +#endif + +#ifndef GL_MAP_COHERENT_BIT +#define GL_MAP_COHERENT_BIT 0x0080 +#endif + OpenGLRenderer::OpenGLRenderer(QWidget *parent) : QWindow(parent->windowHandle()) , renderTimer(new QTimer(this)) @@ -239,10 +247,12 @@ void OpenGLRenderer::initializeExtensions() { #ifndef NO_BUFFER_STORAGE - if (context->hasExtension("GL_ARB_buffer_storage")) { + if (context->hasExtension("GL_ARB_buffer_storage") || context->hasExtension("GL_EXT_buffer_storage")) { hasBufferStorage = true; - glBufferStorage = (PFNGLBUFFERSTORAGEPROC) context->getProcAddress("glBufferStorage"); + glBufferStorage = (PFNGLBUFFERSTORAGEEXTPROC_LOCAL) context->getProcAddress(context->hasExtension("GL_EXT_buffer_storage") ? "glBufferStorageEXT" : "glBufferStorage"); + if (!glBufferStorage) + glBufferStorage = glBufferStorage = (PFNGLBUFFERSTORAGEEXTPROC_LOCAL) context->getProcAddress("glBufferStorage"); } #endif } diff --git a/src/qt/qt_openglrenderer.hpp b/src/qt/qt_openglrenderer.hpp index a27e0fe21..da64ea79b 100644 --- a/src/qt/qt_openglrenderer.hpp +++ b/src/qt/qt_openglrenderer.hpp @@ -39,6 +39,8 @@ #include "qt_opengloptions.hpp" #include "qt_renderercommon.hpp" +typedef void (QOPENGLF_APIENTRYP PFNGLBUFFERSTORAGEEXTPROC_LOCAL) (GLenum target, GLsizeiptr size, const void *data, GLbitfield flags); + class OpenGLRenderer : public QWindow, protected QOpenGLExtraFunctions, public RendererCommon { Q_OBJECT @@ -103,7 +105,7 @@ private: /* GL_ARB_buffer_storage */ bool hasBufferStorage = false; #ifndef NO_BUFFER_STORAGE - PFNGLBUFFERSTORAGEPROC glBufferStorage = nullptr; + PFNGLBUFFERSTORAGEEXTPROC_LOCAL glBufferStorage = nullptr; #endif private slots: From ac12ad224391cadb868c6402fd84e9321d8c4223 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 1 Aug 2022 13:26:07 +0600 Subject: [PATCH 2/4] Revert "Fix crash at exit due to a unreleased mutex." This reverts commit 80e547000673b1f8f9804a3cacbe5dc934077493. std::unique_lock is incapable of recursively locking a mutex, which is needed for multi-monitor setups. As a result it will crash/show undefined behaviour when switching renderers. Switch to instead calling endblit() after pc_close to avoid crashes; at this point the CPU thread is now terminated so the mutex no longer remains held by it. --- src/qt/qt_main.cpp | 1 + src/qt/qt_platform.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index c30304eb8..a74958511 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -289,6 +289,7 @@ int main(int argc, char* argv[]) { cpu_thread_run = 0; main_thread->join(); pc_close(nullptr); + endblit(); socket.close(); return ret; diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index d1f5318ba..527b4e2ab 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -54,7 +54,6 @@ QElapsedTimer elapsed_timer; static std::atomic_int blitmx_contention = 0; static std::recursive_mutex blitmx; -static thread_local std::unique_lock blit_lock { blitmx, std::defer_lock }; class CharPointer { public: @@ -469,17 +468,17 @@ void dynld_close(void *handle) void startblit() { blitmx_contention++; - if (blit_lock.try_lock()) { + if (blitmx.try_lock()) { return; } - blit_lock.lock(); + blitmx.lock(); } void endblit() { blitmx_contention--; - blit_lock.unlock(); + blitmx.unlock(); if (blitmx_contention > 0) { // a deadlock has been observed on linux when toggling via video_toggle_option // because the mutex is typically unfair on linux From 8b99f9f3604242555c071ad4fbb4834a6084dd5c Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 1 Aug 2022 17:36:46 +0600 Subject: [PATCH 3/4] qt: avoid zero-sized main window --- src/qt/qt_mainwindow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 144c55d2d..63e876944 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -650,6 +650,11 @@ MainWindow::~MainWindow() { void MainWindow::showEvent(QShowEvent *event) { if (shownonce) return; shownonce = true; + if (window_remember) { + if (window_w < 320) window_w = 320; + if (window_h < 200) window_h = 200; + } + if (window_remember && !QApplication::platformName().contains("wayland")) { setGeometry(window_x, window_y, window_w, window_h + menuBar()->height() + (hide_status_bar ? 0 : statusBar()->height()) + (hide_tool_bar ? 0 : ui->toolBar->height())); } From af316716199207c786e032eaafc67e5242da2908 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Mon, 1 Aug 2022 18:06:45 +0600 Subject: [PATCH 4/4] Update qt_mainwindow.cpp --- src/qt/qt_mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 63e876944..ebccbe0cb 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -651,8 +651,8 @@ void MainWindow::showEvent(QShowEvent *event) { if (shownonce) return; shownonce = true; if (window_remember) { - if (window_w < 320) window_w = 320; - if (window_h < 200) window_h = 200; + if (window_w == 0) window_w = 320; + if (window_h == 0) window_h = 200; } if (window_remember && !QApplication::platformName().contains("wayland")) {