gbm: Add support for __DRIimage based getBuffers when available
authorKristian Høgsberg <krh@bitplanet.net>
Sat, 9 Nov 2013 06:06:51 +0000 (22:06 -0800)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 13 Nov 2013 00:01:40 +0000 (16:01 -0800)
This lets us allocate color buffers as __DRIimages and pass them into
the driver instead of having to create a __DRIbuffer with the flink
that requires.

With this patch, we can now run gbm on render-nodes.  A render-node is a
drm device that doesn't support modesetting and all the legacy DRI ioctls.
flink is also not supported, but now that gbm doesn't need flink, we can
run piglit on head-less gbm or head-less GPGPU.

Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Tested-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: "10.0" <mesa-stable@lists.freedesktop.org>
src/egl/drivers/dri2/platform_drm.c
src/gbm/backends/dri/gbm_dri.c
src/gbm/backends/dri/gbm_driint.h

index 7b1e3a1779725cd0e0358d15ec580840c1f5d2c5..181b29d3f7adf294432c83e409a22349cfa4d948 100644 (file)
@@ -175,13 +175,12 @@ dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
 }
 
 static int
-get_back_bo(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
+get_back_bo(struct dri2_egl_surface *dri2_surf)
 {
    struct dri2_egl_display *dri2_dpy =
       dri2_egl_display(dri2_surf->base.Resource.Display);
-   struct gbm_dri_bo *bo;
    struct gbm_dri_surface *surf = dri2_surf->gbm_surf;
-   int i, name, pitch;
+   int i;
 
    if (dri2_surf->back == NULL) {
       for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
@@ -201,6 +200,17 @@ get_back_bo(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
    if (dri2_surf->back->bo == NULL)
       return -1;
 
+   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 = (struct gbm_dri_bo *) dri2_surf->back->bo;
 
    dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);
@@ -211,8 +221,6 @@ get_back_bo(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
    buffer->pitch = pitch;
    buffer->cpp = 4;
    buffer->flags = 0;
-
-   return 0;
 }
 
 static int
@@ -254,10 +262,11 @@ dri2_get_buffers_with_format(__DRIdrawable *driDrawable,
 
       switch (attachments[i]) {
       case __DRI_BUFFER_BACK_LEFT:
-        if (get_back_bo(dri2_surf, &dri2_surf->buffers[j]) < 0) {
+        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:
         if (get_aux_bo(dri2_surf, attachments[i], attachments[i + 1],
@@ -312,6 +321,27 @@ dri2_get_buffers(__DRIdrawable * driDrawable,
    return buffer;
 }
 
+static int
+dri_image_get_buffers(__DRIdrawable *driDrawable,
+                      unsigned int format,
+                      uint32_t *stamp,
+                      void *loaderPrivate,
+                      uint32_t buffer_mask,
+                      struct __DRIimageList *buffers)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+   struct gbm_dri_bo *bo;
+
+   if (get_back_bo(dri2_surf) < 0)
+      return 0;
+
+   bo = (struct gbm_dri_bo *) dri2_surf->back->bo;
+   buffers->image_mask = __DRI_IMAGE_BUFFER_BACK;
+   buffers->back = bo->image;
+
+   return 1;
+}
+
 static void
 dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
 {
@@ -348,9 +378,8 @@ dri2_query_buffer_age(_EGLDriver *drv,
                       _EGLDisplay *disp, _EGLSurface *surface)
 {
    struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface);
-   __DRIbuffer buffer;
 
-   if (get_back_bo(dri2_surf, &buffer) < 0) {
+   if (get_back_bo(dri2_surf) < 0) {
       _eglError(EGL_BAD_ALLOC, "dri2_query_buffer_age");
       return 0;
    }
@@ -469,6 +498,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
    dri2_dpy->gbm_dri->get_buffers = dri2_get_buffers;
    dri2_dpy->gbm_dri->flush_front_buffer = dri2_flush_front_buffer;
    dri2_dpy->gbm_dri->get_buffers_with_format = dri2_get_buffers_with_format;
+   dri2_dpy->gbm_dri->image_get_buffers = dri_image_get_buffers;
 
    dri2_dpy->gbm_dri->base.base.surface_lock_front_buffer = lock_front_buffer;
    dri2_dpy->gbm_dri->base.base.surface_release_buffer = release_buffer;
index e95fcc7b23cffad463a11809f655ee3a14d684e6..6c63c75e92d36e88ffa87c6eb13699acecf40a73 100644 (file)
@@ -104,6 +104,24 @@ dri_get_buffers_with_format(__DRIdrawable * driDrawable,
                                    count, out_count, surf->dri_private);
 }
 
+static int
+image_get_buffers(__DRIdrawable *driDrawable,
+                  unsigned int format,
+                  uint32_t *stamp,
+                  void *loaderPrivate,
+                  uint32_t buffer_mask,
+                  struct __DRIimageList *buffers)
+{
+   struct gbm_dri_surface *surf = loaderPrivate;
+   struct gbm_dri_device *dri = gbm_dri_device(surf->base.gbm);
+
+   if (dri->image_get_buffers == NULL)
+      return 0;
+
+   return dri->image_get_buffers(driDrawable, format, stamp,
+                                 surf->dri_private, buffer_mask, buffers);
+}
+
 static const __DRIuseInvalidateExtension use_invalidate = {
    { __DRI_USE_INVALIDATE, 1 }
 };
@@ -120,6 +138,13 @@ const __DRIdri2LoaderExtension dri2_loader_extension = {
    dri_get_buffers_with_format,
 };
 
+const __DRIimageLoaderExtension image_loader_extension = {
+   { __DRI_IMAGE_LOADER, 1 },
+   image_get_buffers,
+   dri_flush_front_buffer,
+};
+
+
 struct dri_extension_match {
    const char *name;
    int version;
@@ -258,7 +283,8 @@ dri_screen_create(struct gbm_dri_device *dri)
    dri->extensions[0] = &image_lookup_extension.base;
    dri->extensions[1] = &use_invalidate.base;
    dri->extensions[2] = &dri2_loader_extension.base;
-   dri->extensions[3] = NULL;
+   dri->extensions[3] = &image_loader_extension.base;
+   dri->extensions[4] = NULL;
 
    if (dri->dri2 == NULL)
       return -1;
index cb4e477abf4733867843e8c1b18a869737620727..fb303a3be550bd18d4732757c2970cddd2345142 100644 (file)
@@ -52,7 +52,7 @@ struct gbm_dri_device {
    __DRIdri2LoaderExtension *loader;
 
    const __DRIconfig   **driver_configs;
-   const __DRIextension *extensions[4];
+   const __DRIextension *extensions[5];
    const __DRIextension **driver_extensions;
 
    __DRIimage *(*lookup_image)(__DRIscreen *screen, void *image, void *data);
@@ -67,6 +67,12 @@ struct gbm_dri_device {
                             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,
+                            void *loaderPrivate,
+                            uint32_t buffer_mask,
+                            struct __DRIimageList *buffers);
 
    struct wl_drm *wl_drm;
 };