Re: [Mesa-dev] [PATCH 3/3] egl: Implement EGL_EXT_device_{base, query, enumeration}

2017-05-04 Thread Eric Anholt
Adam Jackson  writes:

> On Wed, 2017-05-03 at 12:38 -0700, Eric Anholt wrote:
>> > Adam Jackson  writes:
>> > +#ifdef HAVE_LIBDRM
>> > +/* XXX kind of copypasta of drmCompareBusInfo */
>> > +static int
>> > +dri2_bus_info_equal(drmDevicePtr a, drmDevicePtr b)
>> > +{
>> > +if (a == NULL || b == NULL)
>> > +  return 0;
>> > +
>> > +if (a->bustype != b->bustype)
>> > +  return 0;
>> > +
>> > +if (a->bustype == DRM_BUS_PCI)
>> > +  return !memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo));
>> > +
>> > +return 0;
>> > +}
>> > +#endif
>> 
>> Yeah, this looks like a worse version of drmCompareBusInfo().  Would you
>> be willing to export it from libdrm, instead?  If not, please re-copy it
>> to get the usb/platform/host1x bits.
>
> Apologies, I copied this bit at a time when it only had the PCI case
> anyway. libdrm patch sent. I may need some guidance about which
> LIBDRM_REQUIRED in configure is the one to bump.

Thanks for doing that.  I think it would just be the top level
LIBDRM_REQUIRED.


signature.asc
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 3/3] egl: Implement EGL_EXT_device_{base, query, enumeration}

2017-05-04 Thread Adam Jackson
On Wed, 2017-05-03 at 12:38 -0700, Eric Anholt wrote:
> > Adam Jackson  writes:
> > +#ifdef HAVE_LIBDRM
> > +/* XXX kind of copypasta of drmCompareBusInfo */
> > +static int
> > +dri2_bus_info_equal(drmDevicePtr a, drmDevicePtr b)
> > +{
> > +if (a == NULL || b == NULL)
> > +   return 0;
> > +
> > +if (a->bustype != b->bustype)
> > +   return 0;
> > +
> > +if (a->bustype == DRM_BUS_PCI)
> > +   return !memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo));
> > +
> > +return 0;
> > +}
> > +#endif
> 
> Yeah, this looks like a worse version of drmCompareBusInfo().  Would you
> be willing to export it from libdrm, instead?  If not, please re-copy it
> to get the usb/platform/host1x bits.

Apologies, I copied this bit at a time when it only had the PCI case
anyway. libdrm patch sent. I may need some guidance about which
LIBDRM_REQUIRED in configure is the one to bump.

- ajax
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 3/3] egl: Implement EGL_EXT_device_{base, query, enumeration}

2017-05-03 Thread Eric Anholt
Adam Jackson  writes:

> From: Jonny Lamb 
>
> This is a rebase/squash/rewrite of a series Jonny had sent long ago. The
> major change is implementing this in terms of the drmDevice API. Both
> relevant piglits go from skip to pass on i965.

Just some style notes and one "why are we duplicating this code
badly?".  With those fixed, I think it's past time to merge, so you can
put my r-b on.

I anticipate that the second device type implementation will end up
doing some refactoring, but I'm fine with not building the
infrastructure until we need it.

> Signed-off-by: Adam Jackson 
> ---
>  src/egl/Makefile.sources|   2 +
>  src/egl/drivers/dri2/egl_dri2.c |  64 +
>  src/egl/main/eglapi.c   |  79 
>  src/egl/main/eglapi.h   |   4 +
>  src/egl/main/egldevice.c| 280 
> 
>  src/egl/main/egldevice.h|  74 +++
>  src/egl/main/eglentrypoint.h|  10 ++
>  src/egl/main/eglglobals.c   |  12 +-
>  src/egl/main/eglglobals.h   |   2 +
>  src/egl/main/egltypedefs.h  |   4 +
>  10 files changed, 529 insertions(+), 2 deletions(-)
>  create mode 100644 src/egl/main/egldevice.c
>  create mode 100644 src/egl/main/egldevice.h
>
> diff --git a/src/egl/Makefile.sources b/src/egl/Makefile.sources
> index e6fd3f114c..bd13bfc06a 100644
> --- a/src/egl/Makefile.sources
> +++ b/src/egl/Makefile.sources
> @@ -11,6 +11,8 @@ LIBEGL_C_FILES := \
>   main/eglcurrent.c \
>   main/eglcurrent.h \
>   main/egldefines.h \
> + main/egldevice.c \
> + main/egldevice.h \
>   main/egldisplay.c \
>   main/egldisplay.h \
>   main/egldriver.c \
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index 91456b025d..717ab0f860 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -57,6 +57,7 @@
>  
>  #include "egl_dri2.h"
>  #include "loader/loader.h"
> +#include "egldevice.h"
>  #include "util/u_atomic.h"
>  
>  /* The kernel header drm_fourcc.h defines the DRM formats below.  We 
> duplicate
> @@ -2861,6 +2862,67 @@ dri2_interop_export_object(_EGLDisplay *dpy, 
> _EGLContext *ctx,
> return dri2_dpy->interop->export_object(dri2_ctx->dri_context, in, out);
>  }
>  
> +#ifdef HAVE_LIBDRM
> +/* XXX kind of copypasta of drmCompareBusInfo */
> +static int
> +dri2_bus_info_equal(drmDevicePtr a, drmDevicePtr b)
> +{
> +if (a == NULL || b == NULL)
> + return 0;
> +
> +if (a->bustype != b->bustype)
> + return 0;
> +
> +if (a->bustype == DRM_BUS_PCI)
> + return !memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo));
> +
> +return 0;
> +}
> +#endif

Yeah, this looks like a worse version of drmCompareBusInfo().  Would you
be willing to export it from libdrm, instead?  If not, please re-copy it
to get the usb/platform/host1x bits.

> +static EGLBoolean
> +dri2_query_device_from_display(_EGLDisplay *disp, _EGLDeviceInfo *info,
> +EGLAttrib *value)
> +{
> +EGLBoolean ret = EGL_FALSE;
> +#ifdef HAVE_LIBDRM
> +struct dri2_egl_display *dri2_dpy = disp->DriverData;
> +drmDevicePtr dev;
> +int i;
> +
> +if (dri2_dpy->fd == -1) {
> + *value = (EGLAttrib) info; /* a dummy value is fine */
> + return EGL_TRUE;
> +}
> +
> +if (drmGetDevice(dri2_dpy->fd, ) < 0)
> + return ret;
> +
> +/* loop over _EGLDisplayInfo to find a match */
> +for (i = 0; i < info->num_drm_devices; i++) {
> + if (dri2_bus_info_equal(dev, info->drm_devices[i])) {
> + *value = (EGLAttrib) info->drm_devices[i];
> + ret = EGL_TRUE;
> + break;
> + }
> +}
> +
> +drmFreeDevice();
> +#endif
> +return ret;
> +}
> +
> +static const char *
> +dri2_query_device_name(_EGLDisplay *disp)
> +{
> +   struct dri2_egl_display *dri2_dpy = disp->DriverData;
> +
> +   if (dri2_dpy->fd == -1)
> +  return dri2_dpy->driver_name;
> +
> +   return loader_get_device_name_for_fd(dri2_dpy->fd);
> +}
> +
>  static void
>  dri2_unload(_EGLDriver *drv)
>  {
> @@ -2985,6 +3047,8 @@ _eglBuiltInDriverDRI2(const char *args)
> dri2_drv->base.API.GLInteropQueryDeviceInfo = 
> dri2_interop_query_device_info;
> dri2_drv->base.API.GLInteropExportObject = dri2_interop_export_object;
> dri2_drv->base.API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
> +   dri2_drv->base.API.QueryDeviceFromDisplay = 
> dri2_query_device_from_display;
> +   dri2_drv->base.API.QueryDeviceName = dri2_query_device_name;
>  
> dri2_drv->base.Name = "DRI2";
> dri2_drv->base.Unload = dri2_unload;
> diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
> index fc243a58e8..2f323e9fd4 100644
> --- a/src/egl/main/eglapi.c
> +++ b/src/egl/main/eglapi.c
> @@ -93,6 +93,7 @@
>  
>  #include "eglglobals.h"
>  #include "eglcontext.h"
> +#include "egldevice.h"
>  #include "egldisplay.h"
>  #include 

[Mesa-dev] [PATCH 3/3] egl: Implement EGL_EXT_device_{base, query, enumeration}

2017-05-03 Thread Adam Jackson
From: Jonny Lamb 

This is a rebase/squash/rewrite of a series Jonny had sent long ago. The
major change is implementing this in terms of the drmDevice API. Both
relevant piglits go from skip to pass on i965.

Signed-off-by: Adam Jackson 
---
 src/egl/Makefile.sources|   2 +
 src/egl/drivers/dri2/egl_dri2.c |  64 +
 src/egl/main/eglapi.c   |  79 
 src/egl/main/eglapi.h   |   4 +
 src/egl/main/egldevice.c| 280 
 src/egl/main/egldevice.h|  74 +++
 src/egl/main/eglentrypoint.h|  10 ++
 src/egl/main/eglglobals.c   |  12 +-
 src/egl/main/eglglobals.h   |   2 +
 src/egl/main/egltypedefs.h  |   4 +
 10 files changed, 529 insertions(+), 2 deletions(-)
 create mode 100644 src/egl/main/egldevice.c
 create mode 100644 src/egl/main/egldevice.h

diff --git a/src/egl/Makefile.sources b/src/egl/Makefile.sources
index e6fd3f114c..bd13bfc06a 100644
--- a/src/egl/Makefile.sources
+++ b/src/egl/Makefile.sources
@@ -11,6 +11,8 @@ LIBEGL_C_FILES := \
main/eglcurrent.c \
main/eglcurrent.h \
main/egldefines.h \
+   main/egldevice.c \
+   main/egldevice.h \
main/egldisplay.c \
main/egldisplay.h \
main/egldriver.c \
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 91456b025d..717ab0f860 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -57,6 +57,7 @@
 
 #include "egl_dri2.h"
 #include "loader/loader.h"
+#include "egldevice.h"
 #include "util/u_atomic.h"
 
 /* The kernel header drm_fourcc.h defines the DRM formats below.  We duplicate
@@ -2861,6 +2862,67 @@ dri2_interop_export_object(_EGLDisplay *dpy, _EGLContext 
*ctx,
return dri2_dpy->interop->export_object(dri2_ctx->dri_context, in, out);
 }
 
+#ifdef HAVE_LIBDRM
+/* XXX kind of copypasta of drmCompareBusInfo */
+static int
+dri2_bus_info_equal(drmDevicePtr a, drmDevicePtr b)
+{
+if (a == NULL || b == NULL)
+   return 0;
+
+if (a->bustype != b->bustype)
+   return 0;
+
+if (a->bustype == DRM_BUS_PCI)
+   return !memcmp(a->businfo.pci, b->businfo.pci, sizeof(drmPciBusInfo));
+
+return 0;
+}
+#endif
+
+static EGLBoolean
+dri2_query_device_from_display(_EGLDisplay *disp, _EGLDeviceInfo *info,
+  EGLAttrib *value)
+{
+EGLBoolean ret = EGL_FALSE;
+#ifdef HAVE_LIBDRM
+struct dri2_egl_display *dri2_dpy = disp->DriverData;
+drmDevicePtr dev;
+int i;
+
+if (dri2_dpy->fd == -1) {
+   *value = (EGLAttrib) info; /* a dummy value is fine */
+   return EGL_TRUE;
+}
+
+if (drmGetDevice(dri2_dpy->fd, ) < 0)
+   return ret;
+
+/* loop over _EGLDisplayInfo to find a match */
+for (i = 0; i < info->num_drm_devices; i++) {
+   if (dri2_bus_info_equal(dev, info->drm_devices[i])) {
+   *value = (EGLAttrib) info->drm_devices[i];
+   ret = EGL_TRUE;
+   break;
+   }
+}
+
+drmFreeDevice();
+#endif
+return ret;
+}
+
+static const char *
+dri2_query_device_name(_EGLDisplay *disp)
+{
+   struct dri2_egl_display *dri2_dpy = disp->DriverData;
+
+   if (dri2_dpy->fd == -1)
+  return dri2_dpy->driver_name;
+
+   return loader_get_device_name_for_fd(dri2_dpy->fd);
+}
+
 static void
 dri2_unload(_EGLDriver *drv)
 {
@@ -2985,6 +3047,8 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.GLInteropQueryDeviceInfo = 
dri2_interop_query_device_info;
dri2_drv->base.API.GLInteropExportObject = dri2_interop_export_object;
dri2_drv->base.API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
+   dri2_drv->base.API.QueryDeviceFromDisplay = dri2_query_device_from_display;
+   dri2_drv->base.API.QueryDeviceName = dri2_query_device_name;
 
dri2_drv->base.Name = "DRI2";
dri2_drv->base.Unload = dri2_unload;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index fc243a58e8..2f323e9fd4 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -93,6 +93,7 @@
 
 #include "eglglobals.h"
 #include "eglcontext.h"
+#include "egldevice.h"
 #include "egldisplay.h"
 #include "egltypedefs.h"
 #include "eglcurrent.h"
@@ -156,6 +157,12 @@
 #define _EGL_CHECK_SYNC(disp, s, ret, drv) \
_EGL_CHECK_OBJECT(disp, Sync, s, ret, drv)
 
+#define _EGL_CHECK_DEVICE(dev, ret, devptr) \
+   do { \
+  devptr = _eglLookupDevice(dev);   \
+  if (!devptr)  \
+ RETURN_EGL_ERROR(NULL, EGL_BAD_DEVICE_EXT, ret);   \
+   } while (0)
 
 struct _egl_entrypoint {
const char *name;
@@ -2368,6 +2375,78 @@ _eglFunctionCompare(const void *key, const void *elem)
return strcmp(procname, entrypoint->name);
 }
 
+#ifdef HAVE_LIBDRM
+#ifdef EGL_EXT_device_query
+static EGLBoolean EGLAPIENTRY