driconfig: add a new engine name/version parameter
[mesa.git] / src / mesa / drivers / dri / common / dri_util.c
index 8506f5356ebba9fe68f90cb74213c1862250beb8..45f614bf720eb2520f3bcf2396141ecc5cc17244 100644 (file)
 
 
 #include <stdbool.h>
-#ifndef __NOT_HAVE_DRM_H
-#include <xf86drm.h>
-#endif
 #include "dri_util.h"
 #include "utils.h"
-#include "xmlpool.h"
-#include "../glsl/glsl_parser_extras.h"
+#include "util/xmlpool.h"
 #include "main/mtypes.h"
+#include "main/framebuffer.h"
 #include "main/version.h"
+#include "main/debug_output.h"
 #include "main/errors.h"
 #include "main/macros.h"
 
@@ -77,10 +75,14 @@ setupLoaderExtensions(__DRIscreen *psp,
            psp->dri2.image = (__DRIimageLookupExtension *) extensions[i];
        if (strcmp(extensions[i]->name, __DRI_USE_INVALIDATE) == 0)
            psp->dri2.useInvalidate = (__DRIuseInvalidateExtension *) extensions[i];
+        if (strcmp(extensions[i]->name, __DRI_BACKGROUND_CALLABLE) == 0)
+            psp->dri2.backgroundCallable = (__DRIbackgroundCallableExtension *) extensions[i];
        if (strcmp(extensions[i]->name, __DRI_SWRAST_LOADER) == 0)
            psp->swrast_loader = (__DRIswrastLoaderExtension *) extensions[i];
         if (strcmp(extensions[i]->name, __DRI_IMAGE_LOADER) == 0)
            psp->image.loader = (__DRIimageLoaderExtension *) extensions[i];
+        if (strcmp(extensions[i]->name, __DRI_MUTABLE_RENDER_BUFFER_LOADER) == 0)
+           psp->mutableRenderBuffer.loader = (__DRImutableRenderBufferLoaderExtension *) extensions[i];
     }
 }
 
@@ -138,40 +140,41 @@ driCreateNewScreen2(int scrn, int fd,
 
     setupLoaderExtensions(psp, extensions);
 
-#ifndef __NOT_HAVE_DRM_H
-    if (fd != -1) {
-       drmVersionPtr version = drmGetVersion(fd);
-       if (version) {
-          psp->drm_version.major = version->version_major;
-          psp->drm_version.minor = version->version_minor;
-          psp->drm_version.patch = version->version_patchlevel;
-          drmFreeVersion(version);
-       }
-    }
-#endif
-
     psp->loaderPrivate = data;
 
     psp->extensions = emptyExtensionList;
     psp->fd = fd;
     psp->myNum = scrn;
 
+    /* Option parsing before ->InitScreen(), as some options apply there. */
+    driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
+    driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum,
+                        "dri2", NULL, NULL, 0);
+
     *driver_configs = psp->driver->InitScreen(psp);
     if (*driver_configs == NULL) {
        free(psp);
        return NULL;
     }
 
-    int gl_version_override = _mesa_get_gl_version_override();
-    if (gl_version_override >= 31) {
-       psp->max_gl_core_version = MAX2(psp->max_gl_core_version,
-                                       gl_version_override);
-    } else {
-       psp->max_gl_compat_version = MAX2(psp->max_gl_compat_version,
-                                         gl_version_override);
+    struct gl_constants consts = { 0 };
+    gl_api api;
+    unsigned version;
+
+    api = API_OPENGLES2;
+    if (_mesa_override_gl_version_contextless(&consts, &api, &version))
+       psp->max_gl_es2_version = version;
+
+    api = API_OPENGL_COMPAT;
+    if (_mesa_override_gl_version_contextless(&consts, &api, &version)) {
+       psp->max_gl_core_version = version;
+       if (api == API_OPENGL_COMPAT)
+          psp->max_gl_compat_version = version;
     }
 
-    psp->api_mask = (1 << __DRI_API_OPENGL);
+    psp->api_mask = 0;
+    if (psp->max_gl_compat_version > 0)
+       psp->api_mask |= (1 << __DRI_API_OPENGL);
     if (psp->max_gl_core_version > 0)
        psp->api_mask |= (1 << __DRI_API_OPENGL_CORE);
     if (psp->max_gl_es1_version > 0)
@@ -181,10 +184,6 @@ driCreateNewScreen2(int scrn, int fd,
     if (psp->max_gl_es2_version >= 30)
        psp->api_mask |= (1 << __DRI_API_GLES3);
 
-    driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions);
-    driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2");
-
-
     return psp;
 }
 
@@ -230,8 +229,6 @@ static void driDestroyScreen(__DRIscreen *psp)
         * stream open to the X-server anymore.
         */
 
-       _mesa_destroy_shader_compiler();
-
        psp->driver->DestroyScreen(psp);
 
        driDestroyOptionCache(&psp->optionCache);
@@ -306,10 +303,13 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
     const struct gl_config *modes = (config != NULL) ? &config->modes : NULL;
     void *shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
     gl_api mesa_api;
-    unsigned major_version = 1;
-    unsigned minor_version = 0;
-    uint32_t flags = 0;
-    bool notify_reset = false;
+    struct __DriverContextConfig ctx_config;
+
+    ctx_config.major_version = 1;
+    ctx_config.minor_version = 0;
+    ctx_config.flags = 0;
+    ctx_config.attribute_mask = 0;
+    ctx_config.priority = __DRI_CTX_PRIORITY_MEDIUM;
 
     assert((num_attribs == 0) || (attribs != NULL));
 
@@ -340,17 +340,37 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
     for (unsigned i = 0; i < num_attribs; i++) {
        switch (attribs[i * 2]) {
        case __DRI_CTX_ATTRIB_MAJOR_VERSION:
-           major_version = attribs[i * 2 + 1];
+            ctx_config.major_version = attribs[i * 2 + 1];
            break;
        case __DRI_CTX_ATTRIB_MINOR_VERSION:
-           minor_version = attribs[i * 2 + 1];
+           ctx_config.minor_version = attribs[i * 2 + 1];
            break;
        case __DRI_CTX_ATTRIB_FLAGS:
-           flags = attribs[i * 2 + 1];
+           ctx_config.flags = attribs[i * 2 + 1];
            break;
         case __DRI_CTX_ATTRIB_RESET_STRATEGY:
-            notify_reset = (attribs[i * 2 + 1]
-                            != __DRI_CTX_RESET_NO_NOTIFICATION);
+            if (attribs[i * 2 + 1] != __DRI_CTX_RESET_NO_NOTIFICATION) {
+                ctx_config.attribute_mask |=
+                    __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY;
+                ctx_config.reset_strategy = attribs[i * 2 + 1];
+            } else {
+                ctx_config.attribute_mask &=
+                    ~__DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY;
+            }
+            break;
+       case __DRI_CTX_ATTRIB_PRIORITY:
+            ctx_config.attribute_mask |= __DRIVER_CONTEXT_ATTRIB_PRIORITY;
+           ctx_config.priority = attribs[i * 2 + 1];
+           break;
+        case __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR:
+            if (attribs[i * 2 + 1] != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+                ctx_config.attribute_mask |=
+                    __DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR;
+                ctx_config.release_behavior = attribs[i * 2 + 1];
+            } else {
+                ctx_config.attribute_mask &=
+                    ~__DRIVER_CONTEXT_ATTRIB_RELEASE_BEHAVIOR;
+            }
             break;
        default:
            /* We can't create a context that satisfies the requirements of an
@@ -362,33 +382,49 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
        }
     }
 
-    /* Mesa does not support the GL_ARB_compatibilty extension or the
-     * compatibility profile.  This means that we treat a API_OPENGL_COMPAT 3.1 as
-     * API_OPENGL_CORE and reject API_OPENGL_COMPAT 3.2+.
+    /* The specific Mesa driver may not support the GL_ARB_compatibilty
+     * extension or the compatibility profile.  In that case, we treat an
+     * API_OPENGL_COMPAT 3.1 as API_OPENGL_CORE. We reject API_OPENGL_COMPAT
+     * 3.2+ in any case.
      */
-    if (mesa_api == API_OPENGL_COMPAT && major_version == 3 && minor_version == 1)
+    if (mesa_api == API_OPENGL_COMPAT &&
+        ctx_config.major_version == 3 && ctx_config.minor_version == 1 &&
+        screen->max_gl_compat_version < 31)
        mesa_api = API_OPENGL_CORE;
 
-    if (mesa_api == API_OPENGL_COMPAT
-        && ((major_version > 3)
-            || (major_version == 3 && minor_version >= 2))) {
-       *error = __DRI_CTX_ERROR_BAD_API;
-       return NULL;
-    }
-
-    /* The EGL_KHR_create_context spec says:
+    /* The latest version of EGL_KHR_create_context spec says:
+     *
+     *     "If the EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR flag bit is set in
+     *     EGL_CONTEXT_FLAGS_KHR, then a <debug context> will be created.
+     *     [...] This bit is supported for OpenGL and OpenGL ES contexts.
      *
-     *     "Flags are only defined for OpenGL context creation, and specifying
-     *     a flags value other than zero for other types of contexts,
-     *     including OpenGL ES contexts, will generate an error."
+     * No other EGL_CONTEXT_OPENGL_*_BIT is legal for an ES context.
      *
-     * The GLX_EXT_create_context_es2_profile specification doesn't say
-     * anything specific about this case.  However, none of the known flags
-     * have any meaning in an ES context, so this seems safe.
+     * However, Mesa's EGL layer translates the context attribute
+     * EGL_CONTEXT_OPENGL_ROBUST_ACCESS into the context flag
+     * __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS.  That attribute is legal for ES
+     * (with EGL 1.5 or EGL_EXT_create_context_robustness) and GL (only with
+     * EGL 1.5).
+     *
+     * From the EGL_EXT_create_context_robustness spec:
+     *
+     *     This extension is written against the OpenGL ES 2.0 Specification
+     *     but can apply to OpenGL ES 1.1 and up.
+     *
+     * From the EGL 1.5 (2014.08.27) spec, p55:
+     *
+     *     If the EGL_CONTEXT_OPENGL_ROBUST_ACCESS attribute is set to
+     *     EGL_TRUE, a context supporting robust buffer access will be created.
+     *     OpenGL contexts must support the GL_ARB_robustness extension, or
+     *     equivalent core API functional- ity. OpenGL ES contexts must support
+     *     the GL_EXT_robustness extension, or equivalent core API
+     *     functionality.
      */
     if (mesa_api != API_OPENGL_COMPAT
         && mesa_api != API_OPENGL_CORE
-        && flags != 0) {
+        && (ctx_config.flags & ~(__DRI_CTX_FLAG_DEBUG |
+                                 __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS |
+                                 __DRI_CTX_FLAG_NO_ERROR))) {
        *error = __DRI_CTX_ERROR_BAD_FLAG;
        return NULL;
     }
@@ -404,20 +440,23 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
      *
      * In Mesa, a debug context is the same as a regular context.
      */
-    if ((flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
+    if ((ctx_config.flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
        mesa_api = API_OPENGL_CORE;
     }
 
     const uint32_t allowed_flags = (__DRI_CTX_FLAG_DEBUG
                                     | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
-                                    | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS);
-    if (flags & ~allowed_flags) {
+                                    | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
+                                    | __DRI_CTX_FLAG_NO_ERROR);
+    if (ctx_config.flags & ~allowed_flags) {
        *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
        return NULL;
     }
 
     if (!validate_context_version(screen, mesa_api,
-                                  major_version, minor_version, error))
+                                  ctx_config.major_version,
+                                  ctx_config.minor_version,
+                                  error))
        return NULL;
 
     context = calloc(1, sizeof *context);
@@ -433,8 +472,7 @@ driCreateContextAttribs(__DRIscreen *screen, int api,
     context->driReadablePriv = NULL;
 
     if (!screen->driver->CreateContext(mesa_api, modes, context,
-                                       major_version, minor_version,
-                                       flags, notify_reset, error, shareCtx)) {
+                                       &ctx_config, error, shareCtx)) {
         free(context);
         return NULL;
     }
@@ -452,6 +490,8 @@ driContextSetFlags(struct gl_context *ctx, uint32_t flags)
        _mesa_set_debug_state_int(ctx, GL_DEBUG_OUTPUT, GL_TRUE);
         ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
     }
+    if ((flags & __DRI_CTX_FLAG_NO_ERROR) != 0)
+        ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
 }
 
 static __DRIcontext *
@@ -569,6 +609,12 @@ static int driUnbindContext(__DRIcontext *pcp)
     if (pcp == NULL)
        return GL_FALSE;
 
+    /*
+    ** Call driUnbindContext before checking for valid drawables
+    ** to handle surfaceless contexts properly.
+    */
+    pcp->driScreenPriv->driver->UnbindContext(pcp);
+
     pdp = pcp->driDrawablePriv;
     prp = pcp->driReadablePriv;
 
@@ -576,8 +622,6 @@ static int driUnbindContext(__DRIcontext *pcp)
     if (!pdp && !prp)
        return GL_TRUE;
 
-    pcp->driScreenPriv->driver->UnbindContext(pcp);
-
     assert(pdp);
     if (pdp->refcount == 0) {
        /* ERROR!!! */
@@ -628,6 +672,8 @@ driCreateNewDrawable(__DRIscreen *screen,
 {
     __DRIdrawable *pdraw;
 
+    assert(data != NULL);
+
     pdraw = malloc(sizeof *pdraw);
     if (!pdraw)
        return NULL;
@@ -657,6 +703,16 @@ driCreateNewDrawable(__DRIscreen *screen,
 static void
 driDestroyDrawable(__DRIdrawable *pdp)
 {
+    /*
+     * The loader's data structures are going away, even if pdp itself stays
+     * around for the time being because it is currently bound. This happens
+     * when a currently bound GLX pixmap is destroyed.
+     *
+     * Clear out the pointer back into the loader's data structures to avoid
+     * accessing an outdated pointer.
+     */
+    pdp->loaderPrivate = NULL;
+
     dri_put_drawable(pdp);
 }
 
@@ -677,7 +733,7 @@ dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
 
 
 static int
-dri2ConfigQueryb(__DRIscreen *screen, const char *var, bool *val)
+dri2ConfigQueryb(__DRIscreen *screen, const char *var, unsigned char *val)
 {
    if (!driCheckOption(&screen->optionCache, var, DRI_BOOL))
       return -1;
@@ -732,7 +788,7 @@ driSwapBuffers(__DRIdrawable *pdp)
 
 /** Core interface */
 const __DRIcoreExtension driCoreExtension = {
-    .base = { __DRI_CORE, 1 },
+    .base = { __DRI_CORE, 2 },
 
     .createNewScreen            = NULL,
     .destroyScreen              = driDestroyScreen,
@@ -782,6 +838,10 @@ const __DRI2configQueryExtension dri2ConfigQueryExtension = {
    .configQueryf        = dri2ConfigQueryf,
 };
 
+const __DRI2flushControlExtension dri2FlushControlExtension = {
+   .base = { __DRI2_FLUSH_CONTROL, 1 }
+};
+
 void
 dri2InvalidateDrawable(__DRIdrawable *drawable)
 {
@@ -799,7 +859,7 @@ driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv)
 {
    struct gl_framebuffer *fb = (struct gl_framebuffer *) dPriv->driverPrivate;
    if (fb && (dPriv->w != fb->Width || dPriv->h != fb->Height)) {
-      ctx->Driver.ResizeBuffers(ctx, fb, dPriv->w, dPriv->h);
+      _mesa_resize_framebuffer(ctx, fb, dPriv->w, dPriv->h);
       /* if the driver needs the hw lock for ResizeBuffers, the drawable
          might have changed again by now */
       assert(fb->Width == dPriv->w);
@@ -807,66 +867,122 @@ driUpdateFramebufferSize(struct gl_context *ctx, const __DRIdrawable *dPriv)
    }
 }
 
+/*
+ * Note: the first match is returned, which is important for formats like
+ * __DRI_IMAGE_FORMAT_R8 which maps to both MESA_FORMAT_{R,L}_UNORM8
+ */
+static const struct {
+   uint32_t    image_format;
+   mesa_format mesa_format;
+} format_mapping[] = {
+   {
+      .image_format = __DRI_IMAGE_FORMAT_RGB565,
+      .mesa_format  =        MESA_FORMAT_B5G6R5_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_ARGB1555,
+      .mesa_format  =        MESA_FORMAT_B5G5R5A1_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_XRGB8888,
+      .mesa_format  =        MESA_FORMAT_B8G8R8X8_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_ABGR16161616F,
+      .mesa_format  =        MESA_FORMAT_RGBA_FLOAT16,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_XBGR16161616F,
+      .mesa_format  =        MESA_FORMAT_RGBX_FLOAT16,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_ARGB2101010,
+      .mesa_format  =        MESA_FORMAT_B10G10R10A2_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_XRGB2101010,
+      .mesa_format  =        MESA_FORMAT_B10G10R10X2_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_ABGR2101010,
+      .mesa_format  =        MESA_FORMAT_R10G10B10A2_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_XBGR2101010,
+      .mesa_format  =        MESA_FORMAT_R10G10B10X2_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_ARGB8888,
+      .mesa_format  =        MESA_FORMAT_B8G8R8A8_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_ABGR8888,
+      .mesa_format  =        MESA_FORMAT_R8G8B8A8_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_XBGR8888,
+      .mesa_format  =        MESA_FORMAT_R8G8B8X8_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_R8,
+      .mesa_format  =        MESA_FORMAT_R_UNORM8,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_R8,
+      .mesa_format  =        MESA_FORMAT_L_UNORM8,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_GR88,
+      .mesa_format  =        MESA_FORMAT_R8G8_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_GR88,
+      .mesa_format  =        MESA_FORMAT_L8A8_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_SABGR8,
+      .mesa_format  =        MESA_FORMAT_R8G8B8A8_SRGB,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_SARGB8,
+      .mesa_format  =        MESA_FORMAT_B8G8R8A8_SRGB,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_R16,
+      .mesa_format  =        MESA_FORMAT_R_UNORM16,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_R16,
+      .mesa_format  =        MESA_FORMAT_L_UNORM16,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_GR1616,
+      .mesa_format  =        MESA_FORMAT_R16G16_UNORM,
+   },
+   {
+      .image_format = __DRI_IMAGE_FORMAT_GR1616,
+      .mesa_format  =        MESA_FORMAT_L16A16_UNORM,
+   },
+};
+
 uint32_t
 driGLFormatToImageFormat(mesa_format format)
 {
-   switch (format) {
-   case MESA_FORMAT_B5G6R5_UNORM:
-      return __DRI_IMAGE_FORMAT_RGB565;
-   case MESA_FORMAT_B8G8R8X8_UNORM:
-      return __DRI_IMAGE_FORMAT_XRGB8888;
-   case MESA_FORMAT_B10G10R10A2_UNORM:
-      return __DRI_IMAGE_FORMAT_ARGB2101010;
-   case MESA_FORMAT_B10G10R10X2_UNORM:
-      return __DRI_IMAGE_FORMAT_XRGB2101010;
-   case MESA_FORMAT_B8G8R8A8_UNORM:
-      return __DRI_IMAGE_FORMAT_ARGB8888;
-   case MESA_FORMAT_R8G8B8A8_UNORM:
-      return __DRI_IMAGE_FORMAT_ABGR8888;
-   case MESA_FORMAT_R8G8B8X8_UNORM:
-      return __DRI_IMAGE_FORMAT_XBGR8888;
-   case MESA_FORMAT_R_UNORM8:
-      return __DRI_IMAGE_FORMAT_R8;
-   case MESA_FORMAT_R8G8_UNORM:
-      return __DRI_IMAGE_FORMAT_GR88;
-   case MESA_FORMAT_NONE:
-      return __DRI_IMAGE_FORMAT_NONE;
-   case MESA_FORMAT_B8G8R8A8_SRGB:
-      return __DRI_IMAGE_FORMAT_SARGB8;
-   default:
-      return 0;
-   }
+   for (size_t i = 0; i < ARRAY_SIZE(format_mapping); i++)
+      if (format_mapping[i].mesa_format == format)
+         return format_mapping[i].image_format;
+
+   return __DRI_IMAGE_FORMAT_NONE;
 }
 
 mesa_format
 driImageFormatToGLFormat(uint32_t image_format)
 {
-   switch (image_format) {
-   case __DRI_IMAGE_FORMAT_RGB565:
-      return MESA_FORMAT_B5G6R5_UNORM;
-   case __DRI_IMAGE_FORMAT_XRGB8888:
-      return MESA_FORMAT_B8G8R8X8_UNORM;
-   case __DRI_IMAGE_FORMAT_ARGB2101010:
-      return MESA_FORMAT_B10G10R10A2_UNORM;
-   case __DRI_IMAGE_FORMAT_XRGB2101010:
-      return MESA_FORMAT_B10G10R10X2_UNORM;
-   case __DRI_IMAGE_FORMAT_ARGB8888:
-      return MESA_FORMAT_B8G8R8A8_UNORM;
-   case __DRI_IMAGE_FORMAT_ABGR8888:
-      return MESA_FORMAT_R8G8B8A8_UNORM;
-   case __DRI_IMAGE_FORMAT_XBGR8888:
-      return MESA_FORMAT_R8G8B8X8_UNORM;
-   case __DRI_IMAGE_FORMAT_R8:
-      return MESA_FORMAT_R_UNORM8;
-   case __DRI_IMAGE_FORMAT_GR88:
-      return MESA_FORMAT_R8G8_UNORM;
-   case __DRI_IMAGE_FORMAT_SARGB8:
-      return MESA_FORMAT_B8G8R8A8_SRGB;
-   case __DRI_IMAGE_FORMAT_NONE:
-      return MESA_FORMAT_NONE;
-   default:
-      return MESA_FORMAT_NONE;
-   }
+   for (size_t i = 0; i < ARRAY_SIZE(format_mapping); i++)
+      if (format_mapping[i].image_format == image_format)
+         return format_mapping[i].mesa_format;
+
+   return MESA_FORMAT_NONE;
 }
 
 /** Image driver interface */
@@ -894,3 +1010,7 @@ const __DRIcopySubBufferExtension driCopySubBufferExtension = {
 
    .copySubBuffer               = driCopySubBuffer,
 };
+
+const __DRInoErrorExtension dri2NoErrorExtension = {
+   .base = { __DRI2_NO_ERROR, 1 },
+};