egl/drm: Use IMAGE_DRIVER instead of DRI2_LOADER
authorDaniel Stone <daniels@collabora.com>
Thu, 27 Jul 2023 00:17:04 +0000 (01:17 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 28 Jul 2023 12:25:19 +0000 (12:25 +0000)
We always have this extension available to us, since we demand matching
Mesa builds, and it's much better. Just use it always when we're not on
swrast.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24347>

src/egl/drivers/dri2/platform_drm.c
src/gbm/backends/dri/gbm_dri.c
src/gbm/backends/dri/gbm_driint.h

index b792eb8..672ecdb 100644 (file)
@@ -56,7 +56,7 @@ lock_front_buffer(struct gbm_surface *_surf)
 
    bo = dri2_surf->current->bo;
 
-   if (device->dri2) {
+   if (!device->swrast) {
       dri2_surf->current->locked = true;
       dri2_surf->current = NULL;
    }
@@ -286,100 +286,6 @@ get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
    return 0;
 }
 
-static void
-back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
-{
-   struct dri2_egl_display *dri2_dpy =
-      dri2_egl_display(dri2_surf->base.Resource.Display);
-   struct gbm_dri_bo *bo;
-   int name, pitch;
-
-   bo = gbm_dri_bo(dri2_surf->back->bo);
-
-   dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);
-   dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &pitch);
-
-   buffer->attachment = __DRI_BUFFER_BACK_LEFT;
-   buffer->name = name;
-   buffer->pitch = pitch;
-   buffer->cpp = 4;
-   buffer->flags = 0;
-}
-
-static __DRIbuffer *
-dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
-                                 int *height, unsigned int *attachments,
-                                 int count, int *out_count, void *loaderPrivate)
-{
-   struct dri2_egl_surface *dri2_surf = loaderPrivate;
-   int i, j;
-
-   for (i = 0, j = 0; i < 2 * count; i += 2, j++) {
-      __DRIbuffer *local;
-
-      assert(attachments[i] < __DRI_BUFFER_COUNT);
-      assert(j < ARRAY_SIZE(dri2_surf->buffers));
-
-      switch (attachments[i]) {
-      case __DRI_BUFFER_BACK_LEFT:
-         if (get_back_bo(dri2_surf) < 0) {
-            _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer");
-            return NULL;
-         }
-         back_bo_to_dri_buffer(dri2_surf, &dri2_surf->buffers[j]);
-         break;
-      default:
-         local = dri2_egl_surface_alloc_local_buffer(dri2_surf, attachments[i],
-                                                     attachments[i + 1]);
-
-         if (!local) {
-            _eglError(EGL_BAD_ALLOC, "failed to allocate local buffer");
-            return NULL;
-         }
-         dri2_surf->buffers[j] = *local;
-         break;
-      }
-   }
-
-   *out_count = j;
-   if (j == 0)
-      return NULL;
-
-   *width = dri2_surf->base.Width;
-   *height = dri2_surf->base.Height;
-
-   return dri2_surf->buffers;
-}
-
-static __DRIbuffer *
-dri2_drm_get_buffers(__DRIdrawable *driDrawable, int *width, int *height,
-                     unsigned int *attachments, int count, int *out_count,
-                     void *loaderPrivate)
-{
-   unsigned int *attachments_with_format;
-   __DRIbuffer *buffer;
-   const unsigned int format = 32;
-
-   attachments_with_format = calloc(count, 2 * sizeof(unsigned int));
-   if (!attachments_with_format) {
-      *out_count = 0;
-      return NULL;
-   }
-
-   for (int i = 0; i < count; ++i) {
-      attachments_with_format[2 * i] = attachments[i];
-      attachments_with_format[2 * i + 1] = format;
-   }
-
-   buffer = dri2_drm_get_buffers_with_format(driDrawable, width, height,
-                                             attachments_with_format, count,
-                                             out_count, loaderPrivate);
-
-   free(attachments_with_format);
-
-   return buffer;
-}
-
 static int
 dri2_drm_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
                            uint32_t *stamp, void *loaderPrivate,
@@ -710,23 +616,14 @@ dri2_initialize_drm(_EGLDisplay *disp)
    dri2_dpy->is_render_node =
       drmGetNodeTypeFromFd(dri2_dpy->fd_render_gpu) == DRM_NODE_RENDER;
 
-   /* render nodes cannot use Gem names, and thus do not support
-    * the __DRI_DRI2_LOADER extension */
-   if (!dri2_dpy->is_render_node) {
-      if (!dri2_load_driver(disp)) {
-         err = "DRI2: failed to load driver";
-         goto cleanup;
-      }
-   } else {
-      if (!dri2_load_driver_dri3(disp)) {
-         err = "DRI3: failed to load driver";
-         goto cleanup;
-      }
+   if (!dri2_load_driver_dri3(disp)) {
+      err = "DRI3: failed to load driver";
+      goto cleanup;
    }
 
    dri2_dpy->dri_screen_render_gpu = dri2_dpy->gbm_dri->screen;
    dri2_dpy->core = dri2_dpy->gbm_dri->core;
-   dri2_dpy->dri2 = dri2_dpy->gbm_dri->dri2;
+   dri2_dpy->image_driver = dri2_dpy->gbm_dri->image_driver;
    dri2_dpy->swrast = dri2_dpy->gbm_dri->swrast;
    dri2_dpy->kopper = dri2_dpy->gbm_dri->kopper;
    dri2_dpy->driver_configs = dri2_dpy->gbm_dri->driver_configs;
@@ -736,10 +633,7 @@ dri2_initialize_drm(_EGLDisplay *disp)
    dri2_dpy->gbm_dri->lookup_image_validated = dri2_lookup_egl_image_validated;
    dri2_dpy->gbm_dri->lookup_user_data = disp;
 
-   dri2_dpy->gbm_dri->get_buffers = dri2_drm_get_buffers;
    dri2_dpy->gbm_dri->flush_front_buffer = dri2_drm_flush_front_buffer;
-   dri2_dpy->gbm_dri->get_buffers_with_format =
-      dri2_drm_get_buffers_with_format;
    dri2_dpy->gbm_dri->image_get_buffers = dri2_drm_image_get_buffers;
    dri2_dpy->gbm_dri->swrast_put_image2 = swrast_put_image2;
    dri2_dpy->gbm_dri->swrast_get_image = swrast_get_image;
index ed76087..03d3f00 100644 (file)
@@ -91,22 +91,6 @@ dri_lookup_egl_image_validated(void *image, void *data)
    return dri->lookup_image_validated(image, dri->lookup_user_data);
 }
 
-static __DRIbuffer *
-dri_get_buffers(__DRIdrawable * driDrawable,
-                int *width, int *height,
-                unsigned int *attachments, int count,
-                int *out_count, void *data)
-{
-   struct gbm_dri_surface *surf = data;
-   struct gbm_dri_device *dri = gbm_dri_device(surf->base.gbm);
-
-   if (dri->get_buffers == NULL)
-      return NULL;
-
-   return dri->get_buffers(driDrawable, width, height, attachments,
-                           count, out_count, surf->dri_private);
-}
-
 static void
 dri_flush_front_buffer(__DRIdrawable * driDrawable, void *data)
 {
@@ -117,23 +101,6 @@ dri_flush_front_buffer(__DRIdrawable * driDrawable, void *data)
       dri->flush_front_buffer(driDrawable, surf->dri_private);
 }
 
-static __DRIbuffer *
-dri_get_buffers_with_format(__DRIdrawable * driDrawable,
-                            int *width, int *height,
-                            unsigned int *attachments, int count,
-                            int *out_count, void *data)
-{
-   struct gbm_dri_surface *surf = data;
-   struct gbm_dri_device *dri = gbm_dri_device(surf->base.gbm);
-
-   if (dri->get_buffers_with_format == NULL)
-      return NULL;
-
-   return
-      dri->get_buffers_with_format(driDrawable, width, height, attachments,
-                                   count, out_count, surf->dri_private);
-}
-
 static unsigned
 dri_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
 {
@@ -244,15 +211,6 @@ static const __DRIimageLookupExtension image_lookup_extension = {
    .lookupEGLImageValidated = dri_lookup_egl_image_validated,
 };
 
-static const __DRIdri2LoaderExtension dri2_loader_extension = {
-   .base = { __DRI_DRI2_LOADER, 4 },
-
-   .getBuffers              = dri_get_buffers,
-   .flushFrontBuffer        = dri_flush_front_buffer,
-   .getBuffersWithFormat    = dri_get_buffers_with_format,
-   .getCapability           = dri_get_capability,
-};
-
 static const __DRIimageLoaderExtension image_loader_extension = {
    .base = { __DRI_IMAGE_LOADER, 2 },
 
@@ -279,7 +237,6 @@ static const __DRIkopperLoaderExtension kopper_loader_extension = {
 static const __DRIextension *gbm_dri_screen_extensions[] = {
    &image_lookup_extension.base,
    &use_invalidate.base,
-   &dri2_loader_extension.base,
    &image_loader_extension.base,
    &swrast_loader_extension.base,
    &kopper_loader_extension.base,
@@ -294,7 +251,7 @@ static struct dri_extension_match dri_core_extensions[] = {
 static struct dri_extension_match gbm_dri_device_extensions[] = {
    { __DRI_CORE, 1, offsetof(struct gbm_dri_device, core), false },
    { __DRI_MESA, 1, offsetof(struct gbm_dri_device, mesa), false },
-   { __DRI_DRI2, 4, offsetof(struct gbm_dri_device, dri2), false },
+   { __DRI_IMAGE_DRIVER, 1, offsetof(struct gbm_dri_device, image_driver), false },
 };
 
 static struct dri_extension_match gbm_swrast_device_extensions[] = {
@@ -1188,9 +1145,15 @@ gbm_dri_bo_map(struct gbm_bo *_bo,
    }
 
    mtx_lock(&dri->mutex);
-   if (!dri->context)
-      dri->context = dri->dri2->createNewContext(dri->screen, NULL,
-                                                 NULL, NULL);
+   if (!dri->context) {
+      unsigned error;
+
+      dri->context =
+         dri->image_driver->createContextAttribs(dri->screen,
+                                                 __DRI_API_OPENGL,
+                                                 NULL, NULL, 0, NULL,
+                                                 &error, NULL);
+   }
    assert(dri->context);
    mtx_unlock(&dri->mutex);
 
index def6deb..76f6194 100644 (file)
@@ -73,8 +73,8 @@ struct gbm_dri_device {
 
    const __DRIcoreExtension   *core;
    const __DRImesaCoreExtension   *mesa;
-   const __DRIdri2Extension   *dri2;
    const __DRIimageExtension  *image;
+   const __DRIimageDriverExtension  *image_driver;
    const __DRIswrastExtension *swrast;
    const __DRIkopperExtension *kopper;
    const __DRI2flushExtension *flush;
@@ -88,15 +88,7 @@ struct gbm_dri_device {
    __DRIimage *(*lookup_image_validated)(void *image, void *data);
    void *lookup_user_data;
 
-   __DRIbuffer *(*get_buffers)(__DRIdrawable * driDrawable,
-                               int *width, int *height,
-                               unsigned int *attachments, int count,
-                               int *out_count, void *data);
    void (*flush_front_buffer)(__DRIdrawable * driDrawable, void *data);
-   __DRIbuffer *(*get_buffers_with_format)(__DRIdrawable * driDrawable,
-                            int *width, int *height,
-                            unsigned int *attachments, int count,
-                            int *out_count, void *data);
    int (*image_get_buffers)(__DRIdrawable *driDrawable,
                             unsigned int format,
                             uint32_t *stamp,