[Mesa-dev,RFC] mesa: propose simple EGL_MESA_image_dma_buf_export

Submitted by Dave Airlie on March 3, 2014, 3:58 a.m.

Details

Message ID 1393819127-16826-1-git-send-email-airlied@gmail.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Dave Airlie March 3, 2014, 3:58 a.m.
From: Dave Airlie <airlied@redhat.com>

At the moment to get an EGL image to a dma-buf file descriptor,
you have to use EGL_MESA_drm_image, and then use libdrm to
convert this to a file descriptor.

This extension just provides an API modelled on EGL_MESA_drm_image,
to return a dma-buf file descriptor.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 docs/specs/MESA_image_dma_buf_export.txt | 74 ++++++++++++++++++++++++++++++++
 include/EGL/eglmesaext.h                 |  4 ++
 src/egl/drivers/dri2/egl_dri2.c          | 22 ++++++++++
 src/egl/main/eglapi.c                    | 25 +++++++++++
 src/egl/main/eglapi.h                    |  8 ++++
 src/egl/main/egldisplay.h                |  2 +
 src/egl/main/eglfallbacks.c              |  4 ++
 src/egl/main/eglmisc.c                   |  2 +
 8 files changed, 141 insertions(+)
 create mode 100644 docs/specs/MESA_image_dma_buf_export.txt

Patch hide | download patch | download mbox

diff --git a/docs/specs/MESA_image_dma_buf_export.txt b/docs/specs/MESA_image_dma_buf_export.txt
new file mode 100644
index 0000000..ca21ff9
--- /dev/null
+++ b/docs/specs/MESA_image_dma_buf_export.txt
@@ -0,0 +1,74 @@ 
+Name
+
+    MESA_image_dma_buf_export
+
+Name Strings
+
+    EGL_MESA_image_dma_buf_export
+
+Contact
+
+    Dave Airlie <airlied@redhat.com>
+
+Status
+
+    Proposal
+
+Version
+
+    Version 1
+
+Number
+
+ <unnumbered>
+
+Dependencies
+
+    Reguires EGL 1.4 or later.  This extension is written against the
+    wording of the EGL 1.4 specification.
+
+    EGL_KHR_base_image is required.
+
+Overview
+
+    This extension provides entry points for integrating EGLImage with the
+    dma-buf infrastructure.  The extension lets the application get a file descriptor
+    corresponding to an EGL image.
+
+    It is designed to provide the opposing functionality to EGL_EXT_image_dma_buf_import.
+
+IP Status
+
+    Open-source; freely implementable.
+
+New Procedures and Functions
+
+    EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy,
+                                        EGLImageKHR image,
+                                        int *fd,
+ 				        EGLint *stride);
+
+New Tokens
+
+
+Additions to the EGL 1.4 Specification:
+
+    To create a global passable file descriptior for a buffer, call
+
+        EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy,
+                                         EGLImageKHR image,
+					 int *fd,
+                                         EGLint *stride);
+
+    If <fd> is non-NULL, a global file descriptor is assigned to the image and
+    written to <fd>, and the stride (in bytes) is written to <stride>, if
+    non-NULL.
+
+Issues
+
+
+Revision History
+
+    Version 1, June 3, 201
+        Initial draft (Dave Airlie)
+
diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
index b3229e3..2614e18 100644
--- a/include/EGL/eglmesaext.h
+++ b/include/EGL/eglmesaext.h
@@ -165,6 +165,10 @@  typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
 #define EGL_NATIVE_BUFFER_ANDROID       0x3140  /* eglCreateImageKHR target */
 #endif
 
+#ifndef EGL_MESA_image_dma_buf_export
+#define EGL_MESA_image_dma_buf_export 1
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageMESA (EGLDisplay dpy, EGLImageKHR image, int *fd, EGLint *stride);
+#endif
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 892f1f4..bc5ae3f 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -518,6 +518,7 @@  dri2_setup_screen(_EGLDisplay *disp)
 
    if (dri2_dpy->image) {
       disp->Extensions.MESA_drm_image = EGL_TRUE;
+      disp->Extensions.MESA_image_dma_buf_export = EGL_TRUE;
       disp->Extensions.KHR_image_base = EGL_TRUE;
       disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
       if (dri2_dpy->image->base.version >= 5 &&
@@ -1802,6 +1803,26 @@  dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
 
    return EGL_TRUE;
 }
+
+static EGLBoolean
+dri2_export_dma_buf_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
+                               int *fd, EGLint *stride)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   struct dri2_egl_image *dri2_img = dri2_egl_image(img);
+
+   (void) drv;
+
+   if (fd)
+      dri2_dpy->image->queryImage(dri2_img->dri_image,
+				  __DRI_IMAGE_ATTRIB_FD, fd);
+
+   if (stride)
+      dri2_dpy->image->queryImage(dri2_img->dri_image,
+				  __DRI_IMAGE_ATTRIB_STRIDE, stride);
+
+   return EGL_TRUE;
+}
 #endif
 
 #ifdef HAVE_WAYLAND_PLATFORM
@@ -2040,6 +2061,7 @@  _eglBuiltInDriverDRI2(const char *args)
 #ifdef HAVE_DRM_PLATFORM
    dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa;
    dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
+   dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
    dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 59e214c..530ca42 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -980,6 +980,9 @@  eglGetProcAddress(const char *procname)
 #ifdef EGL_EXT_swap_buffers_with_damage
       { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
 #endif
+#ifdef EGL_MESA_drm_buf_image_export
+      { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
+#endif
       { NULL, NULL }
    };
    EGLint i;
@@ -1645,3 +1648,25 @@  eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
 
    RETURN_EGL_EVAL(disp, ret);
 }
+
+#ifdef EGL_MESA_image_dma_buf_export
+EGLBoolean EGLAPIENTRY
+eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImageKHR image,
+                         int *fd, EGLint *stride)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLImage *img = _eglLookupImage(image, disp);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+   assert(disp->Extensions.MESA_image_dma_buf_export);
+
+   if (!img)
+      RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
+
+   ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fd, stride);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+#endif
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 091c09c..e979567 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -139,6 +139,10 @@  typedef EGLint (*QueryBufferAge_t)(_EGLDriver *drv,
 typedef EGLBoolean (*SwapBuffersWithDamageEXT_t) (_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, const EGLint *rects, EGLint n_rects);
 #endif
 
+#ifdef EGL_MESA_image_dma_buf_export
+typedef EGLBoolean (*ExportDMABUFImageMESA_t)(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, int *fd, EGLint *stride);
+#endif
+
 /**
  * The API dispatcher jumps through these functions
  */
@@ -225,6 +229,10 @@  struct _egl_api
    PostSubBufferNV_t PostSubBufferNV;
 
    QueryBufferAge_t QueryBufferAge;
+
+#ifdef EGL_MESA_image_dma_buf_export
+   ExportDMABUFImageMESA_t ExportDMABUFImageMESA;
+#endif
 };
 
 #endif /* EGLAPI_INCLUDED */
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 66aaff5..b75a8d9 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -118,6 +118,8 @@  struct _egl_extensions
    EGLBoolean EXT_buffer_age;
    EGLBoolean EXT_swap_buffers_with_damage;
    EGLBoolean EXT_image_dma_buf_import;
+
+   EGLBoolean MESA_image_dma_buf_export;
 };
 
 
diff --git a/src/egl/main/eglfallbacks.c b/src/egl/main/eglfallbacks.c
index 0b70e92..f50ab07 100644
--- a/src/egl/main/eglfallbacks.c
+++ b/src/egl/main/eglfallbacks.c
@@ -120,4 +120,8 @@  _eglInitDriverFallbacks(_EGLDriver *drv)
 #ifdef EGL_NOK_swap_region
    drv->API.SwapBuffersRegionNOK = NULL;
 #endif
+
+#ifdef EGL_MESA_dma_buf_image_export
+   drv->API.ExportDMABUFImageMESA = NULL;
+#endif
 }
diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c
index 341a723..acfa1d9 100644
--- a/src/egl/main/eglmisc.c
+++ b/src/egl/main/eglmisc.c
@@ -122,6 +122,8 @@  _eglUpdateExtensionsString(_EGLDisplay *dpy)
    _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
 
    _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
+
+   _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
 #undef _EGL_CHECK_EXTENSION
 }
 

Comments

Hi,

2014-03-03 4:58 GMT+01:00 Dave Airlie <airlied@gmail.com>:
> From: Dave Airlie <airlied@redhat.com>
>
> At the moment to get an EGL image to a dma-buf file descriptor,
> you have to use EGL_MESA_drm_image, and then use libdrm to
> convert this to a file descriptor.
>
> This extension just provides an API modelled on EGL_MESA_drm_image,
> to return a dma-buf file descriptor.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  docs/specs/MESA_image_dma_buf_export.txt | 74 ++++++++++++++++++++++++++++++++
>  include/EGL/eglmesaext.h                 |  4 ++
>  src/egl/drivers/dri2/egl_dri2.c          | 22 ++++++++++
>  src/egl/main/eglapi.c                    | 25 +++++++++++
>  src/egl/main/eglapi.h                    |  8 ++++
>  src/egl/main/egldisplay.h                |  2 +
>  src/egl/main/eglfallbacks.c              |  4 ++
>  src/egl/main/eglmisc.c                   |  2 +
>  8 files changed, 141 insertions(+)
>  create mode 100644 docs/specs/MESA_image_dma_buf_export.txt
>
> diff --git a/docs/specs/MESA_image_dma_buf_export.txt b/docs/specs/MESA_image_dma_buf_export.txt
> new file mode 100644
> index 0000000..ca21ff9
> --- /dev/null
> +++ b/docs/specs/MESA_image_dma_buf_export.txt
> @@ -0,0 +1,74 @@
> +Name
> +
> +    MESA_image_dma_buf_export
> +
> +Name Strings
> +
> +    EGL_MESA_image_dma_buf_export
> +
> +Contact
> +
> +    Dave Airlie <airlied@redhat.com>
> +
> +Status
> +
> +    Proposal
> +
> +Version
> +
> +    Version 1
> +
> +Number
> +
> + <unnumbered>
> +
> +Dependencies
> +
> +    Reguires EGL 1.4 or later.  This extension is written against the
> +    wording of the EGL 1.4 specification.
> +
> +    EGL_KHR_base_image is required.
> +
> +Overview
> +
> +    This extension provides entry points for integrating EGLImage with the
> +    dma-buf infrastructure.  The extension lets the application get a file descriptor
> +    corresponding to an EGL image.
> +
> +    It is designed to provide the opposing functionality to EGL_EXT_image_dma_buf_import.
> +
> +IP Status
> +
> +    Open-source; freely implementable.
> +
> +New Procedures and Functions
> +
> +    EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy,
> +                                        EGLImageKHR image,
> +                                        int *fd,
> +                                       EGLint *stride);
> +
> +New Tokens
> +
> +
> +Additions to the EGL 1.4 Specification:
> +
> +    To create a global passable file descriptior for a buffer, call
> +
> +        EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy,
> +                                         EGLImageKHR image,
> +                                        int *fd,
> +                                         EGLint *stride);
> +
> +    If <fd> is non-NULL, a global file descriptor is assigned to the image and
> +    written to <fd>, and the stride (in bytes) is written to <stride>, if
> +    non-NULL.
> +
> +Issues
> +
> +
> +Revision History
> +
> +    Version 1, June 3, 201
> +        Initial draft (Dave Airlie)
> +

Could you please describe in there the ownership model? I think the
implementation should own the fd, so the clients should dup() it if
ever necessary.

Do we have a Query API for EGLImage? I thought that was for EGLSurface
only. I mean, if not, that could be interesting to retrieve all the
necessary other attributes, or extend the eglExportDMABufImageMESA()
function to include the same level of information than what we have
for EXT_image_dma_buf_import. e.g. multi-plane stride information for
instance, up to including the actual format.

What happens if the EGLImage is not backing a 2D texture?

I believe for the last two questions, we might not need to care since
we can assume the client originally has all the required information,
since it created the EGLImage to begin with.

> diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
> index b3229e3..2614e18 100644
> --- a/include/EGL/eglmesaext.h
> +++ b/include/EGL/eglmesaext.h
> @@ -165,6 +165,10 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSREGIONNOK) (EGLDisplay dpy, EG
>  #define EGL_NATIVE_BUFFER_ANDROID       0x3140  /* eglCreateImageKHR target */
>  #endif
>
> +#ifndef EGL_MESA_image_dma_buf_export
> +#define EGL_MESA_image_dma_buf_export 1
> +EGLAPI EGLBoolean EGLAPIENTRY eglExportDMABUFImageMESA (EGLDisplay dpy, EGLImageKHR image, int *fd, EGLint *stride);
> +#endif
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index 892f1f4..bc5ae3f 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -518,6 +518,7 @@ dri2_setup_screen(_EGLDisplay *disp)
>
>     if (dri2_dpy->image) {
>        disp->Extensions.MESA_drm_image = EGL_TRUE;
> +      disp->Extensions.MESA_image_dma_buf_export = EGL_TRUE;
>        disp->Extensions.KHR_image_base = EGL_TRUE;
>        disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
>        if (dri2_dpy->image->base.version >= 5 &&
> @@ -1802,6 +1803,26 @@ dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
>
>     return EGL_TRUE;
>  }
> +
> +static EGLBoolean
> +dri2_export_dma_buf_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
> +                               int *fd, EGLint *stride)
> +{
> +   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> +   struct dri2_egl_image *dri2_img = dri2_egl_image(img);
> +
> +   (void) drv;
> +
> +   if (fd)
> +      dri2_dpy->image->queryImage(dri2_img->dri_image,
> +                                 __DRI_IMAGE_ATTRIB_FD, fd);
> +
> +   if (stride)
> +      dri2_dpy->image->queryImage(dri2_img->dri_image,
> +                                 __DRI_IMAGE_ATTRIB_STRIDE, stride);
> +
> +   return EGL_TRUE;
> +}
>  #endif
>
>  #ifdef HAVE_WAYLAND_PLATFORM
> @@ -2040,6 +2061,7 @@ _eglBuiltInDriverDRI2(const char *args)
>  #ifdef HAVE_DRM_PLATFORM
>     dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa;
>     dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
> +   dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
>  #endif
>  #ifdef HAVE_WAYLAND_PLATFORM
>     dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> index 59e214c..530ca42 100644
> --- a/src/egl/main/eglapi.c
> +++ b/src/egl/main/eglapi.c
> @@ -980,6 +980,9 @@ eglGetProcAddress(const char *procname)
>  #ifdef EGL_EXT_swap_buffers_with_damage
>        { "eglSwapBuffersWithDamageEXT", (_EGLProc) eglSwapBuffersWithDamageEXT },
>  #endif
> +#ifdef EGL_MESA_drm_buf_image_export
> +      { "eglExportDMABUFImageMESA", (_EGLProc) eglExportDMABUFImageMESA },
> +#endif
>        { NULL, NULL }
>     };
>     EGLint i;
> @@ -1645,3 +1648,25 @@ eglPostSubBufferNV(EGLDisplay dpy, EGLSurface surface,
>
>     RETURN_EGL_EVAL(disp, ret);
>  }
> +
> +#ifdef EGL_MESA_image_dma_buf_export
> +EGLBoolean EGLAPIENTRY
> +eglExportDMABUFImageMESA(EGLDisplay dpy, EGLImageKHR image,
> +                         int *fd, EGLint *stride)
> +{
> +   _EGLDisplay *disp = _eglLockDisplay(dpy);
> +   _EGLImage *img = _eglLookupImage(image, disp);
> +   _EGLDriver *drv;
> +   EGLBoolean ret;
> +
> +   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
> +   assert(disp->Extensions.MESA_image_dma_buf_export);
> +
> +   if (!img)
> +      RETURN_EGL_ERROR(disp, EGL_BAD_PARAMETER, EGL_FALSE);
> +
> +   ret = drv->API.ExportDMABUFImageMESA(drv, disp, img, fd, stride);
> +
> +   RETURN_EGL_EVAL(disp, ret);
> +}
> +#endif
> diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
> index 091c09c..e979567 100644
> --- a/src/egl/main/eglapi.h
> +++ b/src/egl/main/eglapi.h
> @@ -139,6 +139,10 @@ typedef EGLint (*QueryBufferAge_t)(_EGLDriver *drv,
>  typedef EGLBoolean (*SwapBuffersWithDamageEXT_t) (_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, const EGLint *rects, EGLint n_rects);
>  #endif
>
> +#ifdef EGL_MESA_image_dma_buf_export
> +typedef EGLBoolean (*ExportDMABUFImageMESA_t)(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img, int *fd, EGLint *stride);
> +#endif
> +
>  /**
>   * The API dispatcher jumps through these functions
>   */
> @@ -225,6 +229,10 @@ struct _egl_api
>     PostSubBufferNV_t PostSubBufferNV;
>
>     QueryBufferAge_t QueryBufferAge;
> +
> +#ifdef EGL_MESA_image_dma_buf_export
> +   ExportDMABUFImageMESA_t ExportDMABUFImageMESA;
> +#endif
>  };
>
>  #endif /* EGLAPI_INCLUDED */
> diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
> index 66aaff5..b75a8d9 100644
> --- a/src/egl/main/egldisplay.h
> +++ b/src/egl/main/egldisplay.h
> @@ -118,6 +118,8 @@ struct _egl_extensions
>     EGLBoolean EXT_buffer_age;
>     EGLBoolean EXT_swap_buffers_with_damage;
>     EGLBoolean EXT_image_dma_buf_import;
> +
> +   EGLBoolean MESA_image_dma_buf_export;
>  };
>
>
> diff --git a/src/egl/main/eglfallbacks.c b/src/egl/main/eglfallbacks.c
> index 0b70e92..f50ab07 100644
> --- a/src/egl/main/eglfallbacks.c
> +++ b/src/egl/main/eglfallbacks.c
> @@ -120,4 +120,8 @@ _eglInitDriverFallbacks(_EGLDriver *drv)
>  #ifdef EGL_NOK_swap_region
>     drv->API.SwapBuffersRegionNOK = NULL;
>  #endif
> +
> +#ifdef EGL_MESA_dma_buf_image_export
> +   drv->API.ExportDMABUFImageMESA = NULL;
> +#endif
>  }
> diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c
> index 341a723..acfa1d9 100644
> --- a/src/egl/main/eglmisc.c
> +++ b/src/egl/main/eglmisc.c
> @@ -122,6 +122,8 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
>     _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
>
>     _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
> +
> +   _EGL_CHECK_EXTENSION(MESA_image_dma_buf_export);
>  #undef _EGL_CHECK_EXTENSION
>  }
>
> --
> 1.8.5.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Thanks,
Hi,

On 29 August 2014 08:46, Gwenole Beauchesne <gb.devel@gmail.com> wrote:

> Could you please describe in there the ownership model? I think the
> implementation should own the fd, so the clients should dup() it if
> ever necessary.
>

So the fd can be destroyed at any time, particularly with threads? Meaning
that if you want to use it, then the first thing you need to do before all
others, is to dup() it, but in theory it could be destroyed by then too ...

Much better to hand the client back something that it unambiguously owns,
where there's no possibility for interference. Note how
EGL_EXT_image_dma_buf_import was revised from the same shared
'implementation owns fd so client should dup() model', to one where the
implementation internally dup()s.


> Do we have a Query API for EGLImage? I thought that was for EGLSurface
> only. I mean, if not, that could be interesting to retrieve all the
> necessary other attributes, or extend the eglExportDMABufImageMESA()
> function to include the same level of information than what we have
> for EXT_image_dma_buf_import. e.g. multi-plane stride information for
> instance, up to including the actual format.
>
> What happens if the EGLImage is not backing a 2D texture?
>

Or TEXTURE_EXTERNAL, surely? Anyway, isn't that restriction a bit too
harsh, that the image has to be bound (or have been bound once?) to
TEXTURE_{2D,EXTERNAL}? Given how EGLImage is used as a neutral interchange
type/format in places, I think supporting dma_buf_import -> EGLImage ->
dma_buf_export, with no need to ever bind it to GLES texture units, is a
useful thing to have.

Cheers,
Daniel
Hi,

2014-08-29 10:05 GMT+02:00 Daniel Stone <daniel@fooishbar.org>:
> Hi,
>
> On 29 August 2014 08:46, Gwenole Beauchesne <gb.devel@gmail.com> wrote:
>>
>> Could you please describe in there the ownership model? I think the
>> implementation should own the fd, so the clients should dup() it if
>> ever necessary.
>
>
> So the fd can be destroyed at any time, particularly with threads? Meaning
> that if you want to use it, then the first thing you need to do before all
> others, is to dup() it, but in theory it could be destroyed by then too ...
>
> Much better to hand the client back something that it unambiguously owns,
> where there's no possibility for interference. Note how
> EGL_EXT_image_dma_buf_import was revised from the same shared
> 'implementation owns fd so client should dup() model', to one where the
> implementation internally dup()s.

Yes, makes sense then. Either way, we need to be unambiguous.

>> Do we have a Query API for EGLImage? I thought that was for EGLSurface
>> only. I mean, if not, that could be interesting to retrieve all the
>> necessary other attributes, or extend the eglExportDMABufImageMESA()
>> function to include the same level of information than what we have
>> for EXT_image_dma_buf_import. e.g. multi-plane stride information for
>> instance, up to including the actual format.
>>
>> What happens if the EGLImage is not backing a 2D texture?
>
>
> Or TEXTURE_EXTERNAL, surely? Anyway, isn't that restriction a bit too harsh,
> that the image has to be bound (or have been bound once?) to
> TEXTURE_{2D,EXTERNAL}? Given how EGLImage is used as a neutral interchange
> type/format in places, I think supporting dma_buf_import -> EGLImage ->
> dma_buf_export, with no need to ever bind it to GLES texture units, is a
> useful thing to have.

That's what I was wondering about too. Though, this proposal could
immediately fit my needs. I was curious about the non-2D texture
cases. A Query API for images might be useful to have. That way,
EGL_MESA_image_dma_buf_export would remain the unique and future proof
interface to get the dma_buf fd, and only that. And the Query API be
useful to extract any side information that would be needed depending
on the original <target>. WDYT?

Regards,
Gwenole.
>>
>> On 29 August 2014 08:46, Gwenole Beauchesne <gb.devel@gmail.com> wrote:
>>>
>>> Could you please describe in there the ownership model? I think the
>>> implementation should own the fd, so the clients should dup() it if
>>> ever necessary.
>>
>>
>> So the fd can be destroyed at any time, particularly with threads? Meaning
>> that if you want to use it, then the first thing you need to do before all
>> others, is to dup() it, but in theory it could be destroyed by then too ...
>>
>> Much better to hand the client back something that it unambiguously owns,
>> where there's no possibility for interference. Note how
>> EGL_EXT_image_dma_buf_import was revised from the same shared
>> 'implementation owns fd so client should dup() model', to one where the
>> implementation internally dup()s.
>
> Yes, makes sense then. Either way, we need to be unambiguous.

6 months later I get back to this, not bad!

Okay I can change the fd ownership issue to one where we internally
dup and hand it back.

>
>>> Do we have a Query API for EGLImage? I thought that was for EGLSurface
>>> only. I mean, if not, that could be interesting to retrieve all the
>>> necessary other attributes, or extend the eglExportDMABufImageMESA()
>>> function to include the same level of information than what we have
>>> for EXT_image_dma_buf_import. e.g. multi-plane stride information for
>>> instance, up to including the actual format.
>>>
>>> What happens if the EGLImage is not backing a 2D texture?
>>
>>
>> Or TEXTURE_EXTERNAL, surely? Anyway, isn't that restriction a bit too harsh,
>> that the image has to be bound (or have been bound once?) to
>> TEXTURE_{2D,EXTERNAL}? Given how EGLImage is used as a neutral interchange
>> type/format in places, I think supporting dma_buf_import -> EGLImage ->
>> dma_buf_export, with no need to ever bind it to GLES texture units, is a
>> useful thing to have.
>
> That's what I was wondering about too. Though, this proposal could
> immediately fit my needs. I was curious about the non-2D texture
> cases. A Query API for images might be useful to have. That way,
> EGL_MESA_image_dma_buf_export would remain the unique and future proof
> interface to get the dma_buf fd, and only that. And the Query API be
> useful to extract any side information that would be needed depending
> on the original <target>. WDYT?

So there is resistance to a query API upstream in the KHR area, at
least according
to https://www.khronos.org/registry/egl/extensions/MESA/EGL_MESA_drm_image.txt
which I based this on.

So I'm wondering how would this API look if we are going to pass back
multiple fd, pitches, offsets etc to mirror the other API.

eglExportImageQueryMesa(EGLDisplay dpy, EGLImageKHR image, int
*num_planes, int *fourcc);
then the original interface can return 3 fds, 3 planes and 3 offsets

 EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy,
                                        EGLImageKHR image,
                                        int *fd,
                                        EGLint *stride,);
(oops pushed send too quick)
> So there is resistance to a query API upstream in the KHR area, at
> least according
> to https://www.khronos.org/registry/egl/extensions/MESA/EGL_MESA_drm_image.txt
> which I based this on.
>
> So I'm wondering how would this API look if we are going to pass back
> multiple fd, pitches, offsets etc to mirror the other API.
>
> eglExportImageQueryMesa(EGLDisplay dpy, EGLImageKHR image, int
> *num_planes, int *fourcc);
> then the original interface can return 3 fds, 3 planes and 3 offsets
>

EGLBoolean eglExportDMABUFImageMESA(EGLDisplay dpy,
                                       EGLImageKHR image,
                                       int *fds,
                                       EGLint *strides, EGLInt *offsets);

I guess it needs to be in two passes or we need to return structs
and have the user free them, which doesn't seem like an EGL API to me.

This way we do the query, allocate things if more planes, then gets
the values back.

Any opinions, sorry for dropping the ball for so long.

Dave.