From f1d7ccfa7943dbe1157a331d1cfce4440c7e2af2 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Tue, 6 Sep 2022 09:29:26 +0000 Subject: [PATCH] cogl: Add a quirk on Mali to glFlush before glGenerateMipmap But only when the texture in question has associated framebuffers that actually need flushing. Workaround for: https://github.com/Xilinx/mali-userspace-binaries/issues/3 Related to: https://gitlab.gnome.org/GNOME/mutter/-/issues/2354 Part-of: --- cogl/cogl/cogl-private.h | 3 +++ cogl/cogl/cogl-texture-2d.c | 4 ++++ cogl/cogl/driver/gl/gles/cogl-driver-gles.c | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/cogl/cogl/cogl-private.h b/cogl/cogl/cogl-private.h index 2878a1640..5a714fc1a 100644 --- a/cogl/cogl/cogl-private.h +++ b/cogl/cogl/cogl-private.h @@ -67,6 +67,9 @@ typedef enum */ COGL_PRIVATE_FEATURE_ANY_GL, + /* This is a Mali bug/quirk: */ + COGL_PRIVATE_QUIRK_GENERATE_MIPMAP_NEEDS_FLUSH, + COGL_N_PRIVATE_FEATURES } CoglPrivateFeature; diff --git a/cogl/cogl/cogl-texture-2d.c b/cogl/cogl/cogl-texture-2d.c index 07ab82074..88978abb3 100644 --- a/cogl/cogl/cogl-texture-2d.c +++ b/cogl/cogl/cogl-texture-2d.c @@ -403,6 +403,10 @@ _cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags) */ _cogl_texture_flush_journal_rendering (tex); + if (_cogl_has_private_feature (ctx, COGL_PRIVATE_QUIRK_GENERATE_MIPMAP_NEEDS_FLUSH) && + _cogl_texture_get_associated_framebuffers (tex)) + ctx->glFlush (); + ctx->driver_vtable->texture_2d_generate_mipmap (tex_2d); tex_2d->mipmaps_dirty = FALSE; diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index 00f72fbab..de080a99d 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -440,6 +440,13 @@ _cogl_driver_update_features (CoglContext *context, if (context->glGenQueries && context->glQueryCounter && context->glGetInteger64v) COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_TIMESTAMP_QUERY, TRUE); + if (!g_strcmp0 ((char *) context->glGetString (GL_RENDERER), "Mali-400 MP")) + { + COGL_FLAGS_SET (private_features, + COGL_PRIVATE_QUIRK_GENERATE_MIPMAP_NEEDS_FLUSH, + TRUE); + } + /* Cache features */ for (i = 0; i < G_N_ELEMENTS (private_features); i++) context->private_features[i] |= private_features[i];