Re: [Mesa-dev] [PATCH 2/2] Add a new capabilities for drivers that can't share buffers

2014-04-28 Thread Emil Velikov
On 12/04/14 01:25, Giovanni Campagna wrote:
> From: Giovanni Campagna 
> 
Hi Giovanni,

> The kms-dri swrast driver cannot share buffers using the GEM,
> so it must tell the loader to disable extensions relying on
> that, without disabling the image DRI extension altogheter
> (which would prevent the loader from working at all).
> This requires a new gallium capability (which is queried on
> the pipe_screen and for swrast drivers it's forwared to the
> winsys), and requires a new version of the DRI image extension.
> ---
>  include/GL/internal/dri_interface.h| 15 +
>  src/egl/drivers/dri2/egl_dri2.c| 10 -
>  src/egl/drivers/dri2/platform_drm.c| 17 +++---
>  src/gallium/drivers/freedreno/freedreno_screen.c   |  1 +
>  src/gallium/drivers/i915/i915_screen.c |  1 +
>  src/gallium/drivers/ilo/ilo_screen.c   |  2 ++
>  src/gallium/drivers/llvmpipe/lp_screen.c   |  7 ++
>  src/gallium/drivers/nouveau/nv30/nv30_screen.c |  1 +
>  src/gallium/drivers/nouveau/nv50/nv50_screen.c |  2 ++
>  src/gallium/drivers/nouveau/nvc0/nvc0_screen.c |  2 ++
>  src/gallium/drivers/r300/r300_screen.c |  1 +
>  src/gallium/drivers/r600/r600_pipe.c   |  1 +
>  src/gallium/drivers/radeonsi/si_pipe.c |  1 +
>  src/gallium/drivers/softpipe/sp_screen.c   |  7 ++
>  src/gallium/drivers/svga/svga_screen.c |  2 ++
>  src/gallium/include/pipe/p_defines.h   |  1 +
>  src/gallium/include/state_tracker/sw_winsys.h  |  5 +
>  src/gallium/state_trackers/dri/common/dri_screen.h |  1 +
>  src/gallium/state_trackers/dri/drm/dri2.c  | 23 +--
>  src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c  | 26 
> +++---
>  20 files changed, 117 insertions(+), 9 deletions(-)
> 
> diff --git a/include/GL/internal/dri_interface.h 
> b/include/GL/internal/dri_interface.h
> index d028d05..85d4afa 100644
> --- a/include/GL/internal/dri_interface.h
> +++ b/include/GL/internal/dri_interface.h
> @@ -1133,6 +1133,13 @@ enum __DRIChromaSiting {
>  #define __DRI_IMAGE_ERROR_BAD_PARAMETER 3
>  /*@}*/
>  
> +/**
> + * \name Capabilities that might be returned by 
> __DRIimageExtensionRec::getCapabilities
> + */
> +/*@{*/
> +#define __DRI_IMAGE_CAP_GLOBAL_NAMES 1
> +/*@}*/
> +
>  typedef struct __DRIimageRec  __DRIimage;
>  typedef struct __DRIimageExtensionRec __DRIimageExtension;
>  struct __DRIimageExtensionRec {
> @@ -1239,6 +1246,14 @@ struct __DRIimageExtensionRec {
>   enum __DRIChromaSiting vert_siting,
>   unsigned *error,
>   void *loaderPrivate);
> +
> +   /**
> +* Query for general capabilities of the driver that concern
> +* buffer sharing and image importing.
> +*
> +* \since 9
> +*/
> +   int (*getCapabilities)(__DRIscreen *screen);
>  };
As you're updating the extension, can you bump __DRI_IMAGE_VERSION ?

[snip]
> diff --git a/src/gallium/include/pipe/p_defines.h 
> b/src/gallium/include/pipe/p_defines.h
> index a3a1ae1..1e1b47a 100644
> --- a/src/gallium/include/pipe/p_defines.h
> +++ b/src/gallium/include/pipe/p_defines.h
> @@ -556,6 +556,7 @@ enum pipe_cap {
> PIPE_CAP_TEXTURE_QUERY_LOD = 94,
> PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET = 95,
> PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET = 96,
> +   PIPE_CAP_BUFFER_SHARE = 97
>  };
Please document the new cap in gallium/docs/source/screen.rst

>  
>  #define PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 (1 << 0)
> diff --git a/src/gallium/include/state_tracker/sw_winsys.h 
> b/src/gallium/include/state_tracker/sw_winsys.h
> index a3479eb..21250ff 100644
> --- a/src/gallium/include/state_tracker/sw_winsys.h
> +++ b/src/gallium/include/state_tracker/sw_winsys.h
> @@ -37,6 +37,7 @@
>  
>  #include "pipe/p_compiler.h" /* for boolean */
>  #include "pipe/p_format.h"
> +#include "pipe/p_defines.h" /* for pipe_cap */
>  
>  
>  #ifdef __cplusplus
> @@ -135,6 +136,10 @@ struct sw_winsys
> void 
> (*displaytarget_destroy)( struct sw_winsys *ws, 
>   struct sw_displaytarget *dt );
> +
> +   int
> +   (*get_param)( struct sw_winsys *ws,
> + enum pipe_cap param );
>  };
>  
>  
> diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h 
> b/src/gallium/state_trackers/dri/common/dri_screen.h
> index 7c8e582..446dbcd 100644
> --- a/src/gallium/state_trackers/dri/common/dri_screen.h
> +++ b/src/gallium/state_trackers/dri/common/dri_screen.h
> @@ -69,6 +69,7 @@ struct dri_screen
>  
> /* drm */
> int fd;
> +   boolean can_share_buffer;
>  
> /* gallium */
> boolean d_depth_bits_last;
> diff --git a/src/gallium/state_trackers/dri/drm/dri2.c 
> b/src/gallium/state_trackers/dri/drm/dri2.c
> index 4f2a87e..30f92e3 100644
> --- a/src/gallium/state_trackers/dri/drm/dri2.c

[Mesa-dev] [PATCH 2/2] Add a new capabilities for drivers that can't share buffers

2014-04-12 Thread Giovanni Campagna
From: Giovanni Campagna 

The kms-dri swrast driver cannot share buffers using the GEM,
so it must tell the loader to disable extensions relying on
that, without disabling the image DRI extension altogheter
(which would prevent the loader from working at all).
This requires a new gallium capability (which is queried on
the pipe_screen and for swrast drivers it's forwared to the
winsys), and requires a new version of the DRI image extension.
---
 include/GL/internal/dri_interface.h| 15 +
 src/egl/drivers/dri2/egl_dri2.c| 10 -
 src/egl/drivers/dri2/platform_drm.c| 17 +++---
 src/gallium/drivers/freedreno/freedreno_screen.c   |  1 +
 src/gallium/drivers/i915/i915_screen.c |  1 +
 src/gallium/drivers/ilo/ilo_screen.c   |  2 ++
 src/gallium/drivers/llvmpipe/lp_screen.c   |  7 ++
 src/gallium/drivers/nouveau/nv30/nv30_screen.c |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c |  2 ++
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c |  2 ++
 src/gallium/drivers/r300/r300_screen.c |  1 +
 src/gallium/drivers/r600/r600_pipe.c   |  1 +
 src/gallium/drivers/radeonsi/si_pipe.c |  1 +
 src/gallium/drivers/softpipe/sp_screen.c   |  7 ++
 src/gallium/drivers/svga/svga_screen.c |  2 ++
 src/gallium/include/pipe/p_defines.h   |  1 +
 src/gallium/include/state_tracker/sw_winsys.h  |  5 +
 src/gallium/state_trackers/dri/common/dri_screen.h |  1 +
 src/gallium/state_trackers/dri/drm/dri2.c  | 23 +--
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c  | 26 +++---
 20 files changed, 117 insertions(+), 9 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index d028d05..85d4afa 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1133,6 +1133,13 @@ enum __DRIChromaSiting {
 #define __DRI_IMAGE_ERROR_BAD_PARAMETER 3
 /*@}*/
 
+/**
+ * \name Capabilities that might be returned by 
__DRIimageExtensionRec::getCapabilities
+ */
+/*@{*/
+#define __DRI_IMAGE_CAP_GLOBAL_NAMES 1
+/*@}*/
+
 typedef struct __DRIimageRec  __DRIimage;
 typedef struct __DRIimageExtensionRec __DRIimageExtension;
 struct __DRIimageExtensionRec {
@@ -1239,6 +1246,14 @@ struct __DRIimageExtensionRec {
  enum __DRIChromaSiting vert_siting,
  unsigned *error,
  void *loaderPrivate);
+
+   /**
+* Query for general capabilities of the driver that concern
+* buffer sharing and image importing.
+*
+* \since 9
+*/
+   int (*getCapabilities)(__DRIscreen *screen);
 };
 
 
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index dc541ad..26f9fd4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -521,7 +521,15 @@ dri2_setup_screen(_EGLDisplay *disp)
}
 
if (dri2_dpy->image) {
-  disp->Extensions.MESA_drm_image = EGL_TRUE;
+  if (dri2_dpy->image->base.version >= 9 &&
+  dri2_dpy->image->getCapabilities != NULL) {
+ int capabilities;
+
+ capabilities = dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
+ disp->Extensions.MESA_drm_image = (capabilities & 
__DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
+  } else
+ disp->Extensions.MESA_drm_image = EGL_TRUE;
+
   disp->Extensions.KHR_image_base = EGL_TRUE;
   disp->Extensions.KHR_gl_renderbuffer_image = EGL_TRUE;
   if (dri2_dpy->image->base.version >= 5 &&
diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index 17b93db..2b79612 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -266,7 +266,10 @@ back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, 
__DRIbuffer *buffer)
 
bo = (struct gbm_dri_bo *) dri2_surf->back->bo;
 
-   dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);
+   if (dri2_surf->base.Resource.Display->Extensions.MESA_drm_image)
+  dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name);
+   else
+  dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE, &name);
dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &pitch);
 
buffer->attachment = __DRI_BUFFER_BACK_LEFT;
@@ -719,8 +722,16 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
   disp->Extensions.EXT_buffer_age = EGL_TRUE;
 
 #ifdef HAVE_WAYLAND_PLATFORM
-   if (dri2_dpy->image)
-  disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
+   if (dri2_dpy->image) {
+   if (dri2_dpy->image->base.version >= 9 &&
+   dri2_dpy->image->getCapabilities != NULL) {
+   int capabilities;
+
+   capabilities = 
dri2_dpy->image->getCapabilities(dri2_dpy->dr