From 0632c3356c57c97c4eeb09159134e4a1947f46f0 Mon Sep 17 00:00:00 2001
From: Stenzek <stenzek@gmail.com>
Date: Sat, 16 Dec 2023 21:04:40 +1000
Subject: [PATCH] OpenGLDevice: More Mali driver workarounds

---
 src/util/gl/context.cpp    | 7 ++++++-
 src/util/opengl_device.cpp | 4 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/util/gl/context.cpp b/src/util/gl/context.cpp
index 45b2e5ba6..33406d86f 100644
--- a/src/util/gl/context.cpp
+++ b/src/util/gl/context.cpp
@@ -65,7 +65,12 @@ static void DisableBrokenExtensions(const char* gl_vendor, const char* gl_render
          gl_major_version >= 3 && gl_minor_version >= 2 && major_version > 0))
     {
       // r32p0 and beyond seem okay.
-      Log_VerbosePrintf("Keeping copy_image for driver version '%s'", gl_version);
+      //Log_VerbosePrintf("Keeping copy_image for driver version '%s'", gl_version);
+
+      // Framebuffer blits still end up faster.
+      Log_VerbosePrintf("Newer Mali driver detected, disabling GL_{EXT,OES}_copy_image.");
+      GLAD_GL_EXT_copy_image = 0;
+      GLAD_GL_OES_copy_image = 0;
     }
     else
     {
diff --git a/src/util/opengl_device.cpp b/src/util/opengl_device.cpp
index d5c224513..845e90850 100644
--- a/src/util/opengl_device.cpp
+++ b/src/util/opengl_device.cpp
@@ -507,7 +507,9 @@ bool OpenGLDevice::CheckFeatures(bool* buggy_pbo, FeatureMask disabled_features)
   // noperspective is not supported in GLSL ES.
   m_features.noperspective_interpolation = !is_gles;
 
-  m_features.texture_copy_to_self = !(disabled_features & FEATURE_MASK_TEXTURE_COPY_TO_SELF);
+  // glBlitFramebufer with same source/destination should be legal, but on Mali (at least Bifrost) it breaks.
+  // So, blit from the shadow texture, like in the other renderers.
+  m_features.texture_copy_to_self = !vendor_id_arm && !(disabled_features & FEATURE_MASK_TEXTURE_COPY_TO_SELF);
 
   m_features.geometry_shaders =
     !(disabled_features & FEATURE_MASK_GEOMETRY_SHADERS) && (GLAD_GL_VERSION_3_2 || GLAD_GL_ES_VERSION_3_2);