Re: [Mesa-dev] [PATCH 8/8] egldevice: implement eglQueryDisplayAttribEXT

2016-07-21 Thread Adam Jackson
On Thu, 2016-07-21 at 16:18 +0100, Daniel Stone wrote:
> On 21 July 2016 at 15:11, Emil Velikov  wrote:
> > I'd suggest opting for the drmDevice libdrm API. It can provide a list
> > of devices with all the nodes and other misc info. Thus we could use
> > the render/card/other node as any point as needed.
> 
> Indeed.
> 
> I don't believe Jonny is working on this anymore, and I'm pretty
> preoccupied, so it would be great if someone could pick this one up.

Happy to do so. glvnd's libEGL support gets a lot more useful if the
device enumeration API actually exists and works, so this is sort of
important to me.

drmDevice looks like a good start and we already require a libdrm that
has it. I might need to come up with a dummy implementation for
software (eg KHR_surfaceless_context) but that's easy enough. I'll
rework this series to target that instead of udev.

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


Re: [Mesa-dev] [PATCH 8/8] egldevice: implement eglQueryDisplayAttribEXT

2016-07-21 Thread Daniel Stone
Hi,

On 21 July 2016 at 15:11, Emil Velikov  wrote:
> On 21 July 2016 at 14:57, Adam Jackson  wrote:
>>> +   device_name = drv->QueryDeviceName(disp);
>>
>> This is /dev/dri/renderD128...
>>
>>> +   mtx_lock(_eglGlobal.Mutex);
>>> +
>>> +   assert(info->got_devices);
>>> +
>>> +   for (dev = info->devices; dev; dev = dev->Next) {
>>> +  const char *devname = udev_device_get_property_value(
>>> + dev->Info, "DEVNAME");
>>
>> And this is /dev/dri/card0, so querying the display will always fail.
>>
>> Obviously I can paper over this when there's only one device in the
>> list, but the whole reason I want this is to make multi-GPU work
>> better. Any ideas on a better approach here?
>>
> I'd suggest opting for the drmDevice libdrm API. It can provide a list
> of devices with all the nodes and other misc info. Thus we could use
> the render/card/other node as any point as needed.

Indeed.

I don't believe Jonny is working on this anymore, and I'm pretty
preoccupied, so it would be great if someone could pick this one up.

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


Re: [Mesa-dev] [PATCH 8/8] egldevice: implement eglQueryDisplayAttribEXT

2016-07-21 Thread Emil Velikov
On 21 July 2016 at 14:57, Adam Jackson  wrote:
> On Fri, 2015-07-24 at 16:20 +0200, Jonny Lamb wrote:
>> This adds a new vfunc to _EGLDriver, QueryDeviceName, which should
>> return a const string of the device name (usually in the format
>> '/dev/dri/cardN').
>>
>> The EGLDevice could perhaps be cached in the EGLDisplay but there
>> usually aren't loads of devices and this lookup isn't particularly
>> costly so leave it as is for now.
>>
>> Right now this only works with the egl_dri2 driver.
>
> Ancient thread I know, but this doesn't work, at least in my wayland
> session.
>
>>  static EGLBoolean
>> +_eglQueryDeviceFromDisplay(_EGLDeviceInfo *info,
>> +   _EGLDriver *drv,
>> +   _EGLDisplay *disp,
>> +   EGLAttrib *value)
>> +{
>> +#ifdef HAVE_LIBUDEV
>> +   const char *device_name = NULL;
>> +   _EGLDevice *dev;
>> +   UDEV_SYMBOL(const char *, udev_device_get_property_value,
>> +   (struct udev_device *, const char *));
>> +
>> +   if (dlsym_failed)
>> +  return EGL_FALSE;
>> +
>> +   if (!drv->QueryDeviceName)
>> +  return EGL_FALSE;
>> +
>> +   device_name = drv->QueryDeviceName(disp);
>
> This is /dev/dri/renderD128...
>
>> +   mtx_lock(_eglGlobal.Mutex);
>> +
>> +   assert(info->got_devices);
>> +
>> +   for (dev = info->devices; dev; dev = dev->Next) {
>> +  const char *devname = udev_device_get_property_value(
>> + dev->Info, "DEVNAME");
>
> And this is /dev/dri/card0, so querying the display will always fail.
>
> Obviously I can paper over this when there's only one device in the
> list, but the whole reason I want this is to make multi-GPU work
> better. Any ideas on a better approach here?
>
I'd suggest opting for the drmDevice libdrm API. It can provide a list
of devices with all the nodes and other misc info. Thus we could use
the render/card/other node as any point as needed.

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


Re: [Mesa-dev] [PATCH 8/8] egldevice: implement eglQueryDisplayAttribEXT

2016-07-21 Thread Adam Jackson
On Fri, 2015-07-24 at 16:20 +0200, Jonny Lamb wrote:
> This adds a new vfunc to _EGLDriver, QueryDeviceName, which should
> return a const string of the device name (usually in the format
> '/dev/dri/cardN').
> 
> The EGLDevice could perhaps be cached in the EGLDisplay but there
> usually aren't loads of devices and this lookup isn't particularly
> costly so leave it as is for now.
> 
> Right now this only works with the egl_dri2 driver.

Ancient thread I know, but this doesn't work, at least in my wayland
session.

>  static EGLBoolean
> +_eglQueryDeviceFromDisplay(_EGLDeviceInfo *info,
> +   _EGLDriver *drv,
> +   _EGLDisplay *disp,
> +   EGLAttrib *value)
> +{
> +#ifdef HAVE_LIBUDEV
> +   const char *device_name = NULL;
> +   _EGLDevice *dev;
> +   UDEV_SYMBOL(const char *, udev_device_get_property_value,
> +   (struct udev_device *, const char *));
> +
> +   if (dlsym_failed)
> +  return EGL_FALSE;
> +
> +   if (!drv->QueryDeviceName)
> +  return EGL_FALSE;
> +
> +   device_name = drv->QueryDeviceName(disp);

This is /dev/dri/renderD128...

> +   mtx_lock(_eglGlobal.Mutex);
> +
> +   assert(info->got_devices);
> +
> +   for (dev = info->devices; dev; dev = dev->Next) {
> +  const char *devname = udev_device_get_property_value(
> + dev->Info, "DEVNAME");

And this is /dev/dri/card0, so querying the display will always fail.

Obviously I can paper over this when there's only one device in the
list, but the whole reason I want this is to make multi-GPU work
better. Any ideas on a better approach here?

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


[Mesa-dev] [PATCH 8/8] egldevice: implement eglQueryDisplayAttribEXT

2015-07-24 Thread Jonny Lamb
This adds a new vfunc to _EGLDriver, QueryDeviceName, which should
return a const string of the device name (usually in the format
'/dev/dri/cardN').

The EGLDevice could perhaps be cached in the EGLDisplay but there
usually aren't loads of devices and this lookup isn't particularly
costly so leave it as is for now.

Right now this only works with the egl_dri2 driver.

Signed-off-by: Jonny Lamb 
---
 src/egl/drivers/dri2/egl_dri2.c |  9 ++
 src/egl/main/eglapi.c   | 13 +++-
 src/egl/main/egldevice.c| 72 +
 src/egl/main/egldevice.h|  5 +++
 src/egl/main/egldriver.h|  2 ++
 5 files changed, 100 insertions(+), 1 deletion(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 65194cb..d899cb9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2351,6 +2351,14 @@ dri2_server_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSync *sync)
return EGL_TRUE;
 }
 
+static const char *
+dri2_query_device_name(_EGLDisplay *disp)
+{
+   struct dri2_egl_display *dri2_dpy = disp->DriverData;
+
+   return dri2_dpy->device_name;
+}
+
 static void
 dri2_unload(_EGLDriver *drv)
 {
@@ -2472,6 +2480,7 @@ _eglBuiltInDriverDRI2(const char *args)
 
dri2_drv->base.Name = "DRI2";
dri2_drv->base.Unload = dri2_unload;
+   dri2_drv->base.QueryDeviceName = dri2_query_device_name;
 
return &dri2_drv->base;
 }
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index cc03fec..f9f216e 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -1861,7 +1861,18 @@ eglQueryDisplayAttribEXT(EGLDisplay dpy,
  EGLint attribute,
  EGLAttrib *value)
 {
-   RETURN_EGL_SUCCESS(NULL, EGL_TRUE);
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   if (!disp->Initialized)
+  RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
+
+   ret = _eglQueryDisplayAttribEXT(drv, disp, attribute, value);
+
+   RETURN_EGL_EVAL(disp, ret);
 }
 #endif
 
diff --git a/src/egl/main/egldevice.c b/src/egl/main/egldevice.c
index 596b891..15ea03c 100644
--- a/src/egl/main/egldevice.c
+++ b/src/egl/main/egldevice.c
@@ -31,8 +31,12 @@
 #include 
 #endif
 
+#include 
+#include 
+
 #include "eglcurrent.h"
 #include "egldevice.h"
+#include "egldriver.h"
 #include "eglglobals.h"
 #include "egllog.h"
 #include "egltypedefs.h"
@@ -254,6 +258,74 @@ _eglQueryDeviceStringEXT(_EGLDevice *device, EGLint name)
 }
 
 static EGLBoolean
+_eglQueryDeviceFromDisplay(_EGLDeviceInfo *info,
+   _EGLDriver *drv,
+   _EGLDisplay *disp,
+   EGLAttrib *value)
+{
+#ifdef HAVE_LIBUDEV
+   const char *device_name = NULL;
+   _EGLDevice *dev;
+   UDEV_SYMBOL(const char *, udev_device_get_property_value,
+   (struct udev_device *, const char *));
+
+   if (dlsym_failed)
+  return EGL_FALSE;
+
+   if (!drv->QueryDeviceName)
+  return EGL_FALSE;
+
+   device_name = drv->QueryDeviceName(disp);
+
+   mtx_lock(_eglGlobal.Mutex);
+
+   assert(info->got_devices);
+
+   for (dev = info->devices; dev; dev = dev->Next) {
+  const char *devname = udev_device_get_property_value(
+ dev->Info, "DEVNAME");
+
+  if (!devname)
+ continue;
+
+  if (!strcmp(devname, device_name))
+ break;
+   }
+
+   mtx_unlock(_eglGlobal.Mutex);
+
+   *value = (EGLAttrib) dev;
+
+   return (dev) ? EGL_TRUE : EGL_FALSE;
+#else
+   return EGL_FALSE;
+#endif
+}
+
+EGLBoolean
+_eglQueryDisplayAttribEXT(_EGLDriver *drv,
+  _EGLDisplay *disp,
+  EGLint attribute,
+  EGLAttrib *value)
+{
+   _EGLDeviceInfo *info;
+
+   info = _eglEnsureDeviceInfo(EGL_TRUE);
+   if (!info)
+  return _eglError(EGL_BAD_ALLOC, "eglQueryDisplayAttribEXT");
+
+   if (!value)
+  return _eglError(EGL_BAD_PARAMETER, "eglQueryDisplayAttribEXT");
+
+   switch (attribute) {
+   case EGL_DEVICE_EXT:
+  return _eglQueryDeviceFromDisplay(info, drv, disp, value);
+   default:
+  return _eglError(EGL_BAD_ATTRIBUTE, "eglQueryDisplayAttribEXT");
+   }
+}
+
+static EGLBoolean
 _eglFillDeviceList(_EGLDeviceInfo *info)
 {
 #ifdef HAVE_LIBUDEV
diff --git a/src/egl/main/egldevice.h b/src/egl/main/egldevice.h
index 14f0c1f..2c7986a 100644
--- a/src/egl/main/egldevice.h
+++ b/src/egl/main/egldevice.h
@@ -62,4 +62,9 @@ _eglQueryDevicesEXT(EGLint max_devices, _EGLDevice **devices,
 EGLint *num_devices);
 
 
+EGLBoolean
+_eglQueryDisplayAttribEXT(_EGLDriver *drv, _EGLDisplay *disp,
+  EGLint attribute, EGLAttrib *value);
+
+
 #endif /* EGLDEVICE_INCLUDED */
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 1cf6628..5e5c7b6 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -87,6