Re: [Mesa-dev] [PATCH] kms-swrast: Support Prime fd handling

2014-08-28 Thread Giovanni Campagna
On Thu, Aug 28, 2014 at 4:01 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 22/08/14 17:41, Andreas Pokorny wrote:
 Allows using prime fds as display target and from display target.
 Test for PRIME capability after initializing kms_swrast screen.

 Hi Andreas,

 I'm hoping that Giovanni will take a look. After all kms-dri is his creation.

I'm not sure I'm the right person to look at this code. After all I'm
not a mesa developer.

From a cursory review, the patches look good to me, but what I'm not
seeing are the necessary EGL changes to make use of prime fds with
kms-swrast, eg. EGL_WL_bind_wayland_display is still not exposed, even
though it could be implemented using prime fds.
Another thing is, you briefly mentioned the generic GEM ioctls. If
drivers really can use the generic GEM_FLINK/GEM_OPEN ioctl to give a
name to dumb buffers, then indeed the kms-swrast driver is capable of
buffer sharing (I always assumed that a somehow real GEM was
necessary, and that the simple one in qxl/cirrus/simpledrm was not
enough). I'd like to see that implemented first, which would allow to
remove a good amount of complexity and special casing in gallium and
egl (and would allow using kms-swrast for faster sw wayland too).

Giovanni

 From my POV the patch is good and should be safe to go in 10.3 on the point
 that the driver/target was introduced with 10.3. There is a trivial nit-pick
 which I'll squash before committing later on this week.

 Btw in the future can you please include Cc: branch number mesa-stable...
 [1] in the commit message - it will ease things a bit :)

 Cheers,
 Emil

 [1] Marking a commit as a candidate for a stable branch
 http://mesa3d.org/devinfo.html

 Signed-off-by: Andreas Pokorny andreas.poko...@canonical.com
 ---
 [snip]
 diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c 
 b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
 index c9934bb..ba0660c 100644
 --- a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
 +++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
 [snip]
 @@ -231,17 +264,34 @@ kms_sw_displaytarget_from_handle(struct sw_winsys *ws,
 struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
 struct kms_sw_displaytarget *kms_sw_dt;

 -   assert(whandle-type == DRM_API_HANDLE_TYPE_KMS);
 +   assert(whandle-type == DRM_API_HANDLE_TYPE_KMS ||
 +  whandle-type == DRM_API_HANDLE_TYPE_FD);

 -   LIST_FOR_EACH_ENTRY(kms_sw_dt, kms_sw-bo_list, link) {
 -  if (kms_sw_dt-handle == whandle-handle) {
 +   switch(whandle-type) {
 +   case DRM_API_HANDLE_TYPE_FD:
 +  kms_sw_dt = kms_sw_displaytarget_add_from_prime(kms_sw, 
 whandle-handle);
 +  if (kms_sw_dt) {
   kms_sw_dt-ref_count++;
 + kms_sw_dt-width = templ-width0;
 + kms_sw_dt-height = templ-height0;
 + kms_sw_dt-stride = whandle-stride;
 + if (stride)
 Any objections on dropping the above conditional before committing?

 +*stride = kms_sw_dt-stride;
 +  }
 +  return (struct sw_displaytarget *)kms_sw_dt;
 +   case DRM_API_HANDLE_TYPE_KMS:
 +  LIST_FOR_EACH_ENTRY(kms_sw_dt, kms_sw-bo_list, link) {
 + if (kms_sw_dt-handle == whandle-handle) {
 +kms_sw_dt-ref_count++;

 - DEBUG(KMS-DEBUG: imported buffer %u (size %u)\n, 
 kms_sw_dt-handle, kms_sw_dt-size);
 +DEBUG(KMS-DEBUG: imported buffer %u (size %u)\n, 
 kms_sw_dt-handle, kms_sw_dt-size);

 - *stride = kms_sw_dt-stride;
 - return (struct sw_displaytarget *)kms_sw_dt;
 +*stride = kms_sw_dt-stride;
 +return (struct sw_displaytarget *)kms_sw_dt;
 + }
}
 +   default:
 +   break;
 }
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 6/6] gallium: remove PIPE_CAP_BUFFER_SHARE cap and get_param sw_winsys hook

2014-07-30 Thread Giovanni Campagna
On Jul 29, 2014 7:42 PM, Emil Velikov emil.l.veli...@gmail.com wrote:

 On 24/07/14 01:43, Emil Velikov wrote:
  The kms_swrast driver has a separate InitScreen hook for its DriverAPI
  from the rest of the DRI2 drivers, all of which capable of buffer
  sharing. As such we no longer need to dive through the pipe-driver and
  winsys layers in order to determine if the driver can share buffers or
  not and we can explicitly set screen-can_share_buffer in InitScreen.
 
  XXX: Squash with the original commit ?
 
 Hi Giovanni,

 With the current implementation of kms_dri + megadrivers the PIPE_CAP is
no
 longer required. Are you OK if we drop it ?

Yes, it's an implementation detail and I don't particularly care about it,
as long as we have a way not to expose the image egl extensions.
I did not answer immediately because I wanted to test this again and did
not find time yet, but this is now in use for gnome-continuous through the
egl-drm branch and it works, so it's good to go, I believe.

Giovanni

 -Emil

  Cc: Giovanni Campagna gcampa...@src.gnome.org
  Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
  ---
   src/gallium/docs/source/screen.rst|  4 
   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|  1 -
   src/gallium/drivers/nouveau/nvc0/nvc0_screen.c|  1 -
   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|  3 ---
   src/gallium/include/pipe/p_defines.h  |  1 -
   src/gallium/include/state_tracker/sw_winsys.h |  5 -
   src/gallium/state_trackers/dri/dri2.c |  3 ++-
   src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c | 14 --
   17 files changed, 2 insertions(+), 52 deletions(-)
 
  diff --git a/src/gallium/docs/source/screen.rst
b/src/gallium/docs/source/screen.rst
  index b09f18bd..ba583fe 100644
  --- a/src/gallium/docs/source/screen.rst
  +++ b/src/gallium/docs/source/screen.rst
  @@ -213,10 +213,6 @@ The integer capabilities:
   * ``PIPE_CAP_DRAW_INDIRECT``: Whether the driver supports taking draw
arguments
 { count, instance_count, start, index_bias } from a PIPE_BUFFER
resource.
 See pipe_draw_info.
  -* ``PIPE_CAP_BUFFER_SHARE``: Whether it is possible to share buffers
between
  -  processes using the native window system. If this is 0, the buffers
and
  -  display targets available are only valid for in-process rendering and
  -  scanout. This will be 1 for most HW drivers.
 
 
   .. _pipe_capf:
  diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c
b/src/gallium/drivers/freedreno/freedreno_screen.c
  index 05426dc..c574cb8 100644
  --- a/src/gallium/drivers/freedreno/freedreno_screen.c
  +++ b/src/gallium/drivers/freedreno/freedreno_screen.c
  @@ -175,7 +175,6 @@ fd_screen_get_param(struct pipe_screen *pscreen,
enum pipe_cap param)
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
case PIPE_CAP_USER_CONSTANT_BUFFERS:
case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
  - case PIPE_CAP_BUFFER_SHARE:
return 1;
 
case PIPE_CAP_SHADER_STENCIL_EXPORT:
  diff --git a/src/gallium/drivers/i915/i915_screen.c
b/src/gallium/drivers/i915/i915_screen.c
  index 437f4bd..86a7a67 100644
  --- a/src/gallium/drivers/i915/i915_screen.c
  +++ b/src/gallium/drivers/i915/i915_screen.c
  @@ -186,7 +186,6 @@ i915_get_param(struct pipe_screen *screen, enum
pipe_cap cap)
  case PIPE_CAP_USER_VERTEX_BUFFERS:
  case PIPE_CAP_USER_INDEX_BUFFERS:
  case PIPE_CAP_USER_CONSTANT_BUFFERS:
  -   case PIPE_CAP_BUFFER_SHARE:
 return 1;
 
  /* Unsupported features (boolean caps). */
  diff --git a/src/gallium/drivers/ilo/ilo_screen.c
b/src/gallium/drivers/ilo/ilo_screen.c
  index 6b96e5b..e2a0e23 100644
  --- a/src/gallium/drivers/ilo/ilo_screen.c
  +++ b/src/gallium/drivers/ilo/ilo_screen.c
  @@ -433,8 +433,6 @@ ilo_get_param(struct pipe_screen *screen, enum
pipe_cap param)
  case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
  case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
 return 0;
  -   case PIPE_CAP_BUFFER_SHARE:
  -  return 1;
 
  default:
 return 0;
  diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c
b/src/gallium/drivers/llvmpipe/lp_screen.c
  index a7659c7..e25d14e 100644
  --- a/src/gallium/drivers/llvmpipe/lp_screen.c
  +++ b/src/gallium/drivers/llvmpipe/lp_screen.c
  @@ -105,8 +105,6 @@ llvmpipe_get_name(struct pipe_screen *screen)
   static int
   llvmpipe_get_param(struct pipe_screen *screen

Re: [Mesa-dev] [PATCH v4 0/3] Software rendering in EGL-DRM

2014-07-22 Thread Giovanni Campagna
On Mon, Jul 21, 2014 at 9:54 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 On 21/07/14 17:02, Giovanni Campagna wrote:
 On Mon, Jul 21, 2014 at 12:47 PM, Emil Velikov emil.l.veli...@gmail.com 
 wrote:
 Giovanni can you test the series that I've not butchered anything else 
 during
 the rebase ?

 Oh hey, sorry I missed the bit that I was expected to test the patches.
 Unfortunately, something indeed got lost: the logic to choose the
 kms_swrast driver in preference to the swrast one.

 In my patches, I had:

 static int
 dri_screen_create_sw(struct gbm_dri_device *dri)
 {
int ret;

ret = dri_screen_create_dri2(dri, kms_swrast);
if (ret == 0)
   return ret;

return dri_screen_create_swrast(dri);
 }

 That would take the place of dri_screen_create_swrast in the
 dri_device_create() call site.
 With your patches, the kms_swrast driver is effectively never loaded.

 Am I day-dreaming, or is this the same as your initial concern as stated here
 [0] ? If so I believe that this should be fully addressed with the follow-up
 revision of patches 1 [1]  2 [2].

 Perhaps the updated patches never made it to your inbox :'(

My bad, I was testing the old patch.
Nevertheless, the new patch is not working either: after the
megadrivers work, the new kms_swrast_dri is trying to load ilo when
run on an intel card with GBM_ALWAYS_SOFTWARE, because
loader_get_pci_from_fd() returns i965. This fails because ilo is not
compiled in (and even if ilo was compiled, it would fail because ilo
does not support my GM45).
Then weston crashes using the swrast driver, because at that point the
kms_swrast driver was already partially loaded and extensions bound
(so it takes a mixture of swrast and dri2 paths).

On intel, this problem can be worked around by removing the
LOADER_GALLIUM from the i965 entry in the pci_id_driver_map table, but
on nouveau/r600g/radeonsi it would result on a working GBM, HW
accelerated despite the environment variable. I believe the
_getDriverExtension_kms_swrast() function should return a different
extension table for kms_swrast (one that references a InitScreen that
always initializes a kms_swrast screen).
Additionally, it's probably a bad idea to fallback to kms_swrast
unconditionally, because kms_swrast will fail spectacularly on x11 or
wayland.

OTOH, once loaded the driver works fine.

Giovanni
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v4 0/3] Software rendering in EGL-DRM

2014-07-21 Thread Giovanni Campagna
On Mon, Jul 21, 2014 at 12:47 PM, Emil Velikov emil.l.veli...@gmail.com wrote:
 Giovanni can you test the series that I've not butchered anything else during
 the rebase ?

Oh hey, sorry I missed the bit that I was expected to test the patches.
Unfortunately, something indeed got lost: the logic to choose the
kms_swrast driver in preference to the swrast one.

In my patches, I had:

static int
dri_screen_create_sw(struct gbm_dri_device *dri)
{
   int ret;

   ret = dri_screen_create_dri2(dri, kms_swrast);
   if (ret == 0)
  return ret;

   return dri_screen_create_swrast(dri);
}

That would take the place of dri_screen_create_swrast in the
dri_device_create() call site.
With your patches, the kms_swrast driver is effectively never loaded.

Giovanni

 Thanks
 Emil

 On 11/07/14 18:19, Emil Velikov wrote:
 Hello all,

 Here is hopefully the last iteration of Giovanni's patches, rebased
 on top of the buildsystem mayhem that I've caused recently.

 I've a few small changes in patch 1, most significant of which is
 s/LIBGL_ALWAYS_SOFTWARE/GBM_ALWAYS_SOFTWARE, as I think that having an
 LIBGL envvar to control gbm is ambiguous and may cause some unexpected
 issues.

 Giovanni can you please test that I haven't broken the series with
 megadrivers and/or during rebase.

 Thanks,
 Emil



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


Re: [Mesa-dev] [PATCH 1/3] Add support for swrast to the DRM EGL platform

2014-07-13 Thread Giovanni Campagna
2014-07-11 19:19 GMT+02:00 Emil Velikov emil.l.veli...@gmail.com:
 From: Giovanni Campagna gcampa...@src.gnome.org

 Turn GBM into a swrast loader (providing putimage/getimage backed
 by a dumb KMS buffer). This allows to run KMS+DRM GL applications
 (such as weston or mutter-wayland) unmodified on cards that don't
 have any client side HW acceleration component but that can do
 modeset (examples include simpledrm and qxl)

 v2: [Emil Velikov]
  - Fix make check.
  - Split dri_open_driver() from dri_load_driver().
  - Don't try to bind the swrast extensions when using dri.
  - Handle swrast-CreateNewScreen() failure.
  - strdup the driver_name, as it's free'd at destruction.
  - Fallback to kms_swrast when seeking swrast+dumbbuffer.
  - s/LIBGL_ALWAYS_SOFTWARE/GBM_ALWAYS_SOFTWARE/
  - Move gbm_dri_bo_map/unmap to gbm_driiint.h.

 Signed-off-by: Emil Velikov emil.l.veli...@gmail.com
 ---
  src/egl/drivers/dri2/platform_drm.c | 153 +++
  src/gbm/backends/dri/gbm_dri.c  | 203 
 +++-
  src/gbm/backends/dri/gbm_driint.h   |  57 +-
  src/gbm/gbm-symbols-check   |   1 +
  src/gbm/main/gbm.h  |   3 +
  5 files changed, 369 insertions(+), 48 deletions(-)

 diff --git a/src/egl/drivers/dri2/platform_drm.c 
 b/src/egl/drivers/dri2/platform_drm.c
 index 6227bc9..23a8d27 100644
 --- a/src/egl/drivers/dri2/platform_drm.c
 +++ b/src/egl/drivers/dri2/platform_drm.c
 @@ -44,6 +44,7 @@ lock_front_buffer(struct gbm_surface *_surf)
  {
 struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf;
 struct dri2_egl_surface *dri2_surf = surf-dri_private;
 +   struct gbm_dri_device *device = (struct gbm_dri_device *) _surf-gbm;
 struct gbm_bo *bo;

 if (dri2_surf-current == NULL) {
 @@ -52,8 +53,11 @@ lock_front_buffer(struct gbm_surface *_surf)
 }

 bo = dri2_surf-current-bo;
 -   dri2_surf-current-locked = 1;
 -   dri2_surf-current = NULL;
 +
 +   if (device-dri2) {
 +  dri2_surf-current-locked = 1;
 +  dri2_surf-current = NULL;
 +   }

 return bo;
  }
 @@ -122,13 +126,22 @@ dri2_drm_create_surface(_EGLDriver *drv, _EGLDisplay 
 *disp, EGLint type,
goto cleanup_surf;
 }

 -   dri2_surf-dri_drawable =
 -  (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
 -   dri2_conf-dri_double_config,
 -   dri2_surf-gbm_surf);
 +   if (dri2_dpy-dri2) {
 +  dri2_surf-dri_drawable =
 + (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
 +   dri2_conf-dri_double_config,
 +   dri2_surf-gbm_surf);
 +
 +   } else {
 +  assert(dri2_dpy-swrast != NULL);
 +  dri2_surf-dri_drawable =
 + (*dri2_dpy-swrast-createNewDrawable) (dri2_dpy-dri_screen,
 + 
 dri2_conf-dri_double_config,
 + dri2_surf-gbm_surf);

 +   }
 if (dri2_surf-dri_drawable == NULL) {
 -  _eglError(EGL_BAD_ALLOC, dri2-createNewDrawable);
 +  _eglError(EGL_BAD_ALLOC, createNewDrawable());
goto cleanup_surf;
 }

 @@ -221,6 +234,28 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
 return 0;
  }

 +static int
 +get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
 +{
 +   struct dri2_egl_display *dri2_dpy =
 +  dri2_egl_display(dri2_surf-base.Resource.Display);
 +   struct gbm_dri_surface *surf = dri2_surf-gbm_surf;
 +
 +   if (dri2_surf-current == NULL) {
 +  assert(!dri2_surf-color_buffers[0].locked);
 +  dri2_surf-current = dri2_surf-color_buffers[0];
 +   }
 +
 +   if (dri2_surf-current-bo == NULL)
 +  dri2_surf-current-bo = gbm_bo_create(dri2_dpy-gbm_dri-base.base,
 + surf-base.width, 
 surf-base.height,
 + surf-base.format, 
 surf-base.flags);
 +   if (dri2_surf-current-bo == NULL)
 +  return -1;
 +
 +   return 0;
 +}
 +
  static void
  back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer 
 *buffer)
  {
 @@ -374,19 +409,23 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay 
 *disp, _EGLSurface *draw)
 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
 int i;

 -   if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
 -  if (dri2_surf-current)
 -_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
 -  for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
 - if (dri2_surf-color_buffers[i].age  0)
 -dri2_surf-color_buffers[i].age++;
 -  dri2_surf-current = dri2_surf-back;
 -  dri2_surf-current-age = 1;
 -  dri2_surf-back = NULL;
 -   }
 +   if (dri2_dpy-swrast) {
 +  (*dri2_dpy-core-swapBuffers)(dri2_surf-dri_drawable);
 +   } else {
 +  if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
 + if (dri2_surf-current

Re: [Mesa-dev] [PATCH v3 0/3] Software rendering in EGL-DRM

2014-07-03 Thread Giovanni Campagna
2014-07-03 10:48 GMT+02:00 Boris BREZILLON boris.brezil...@free-electrons.com:
 Hello Giovanni,

 I have recently been working on a DRM/KMS driver which does not support
 OpenGL rendering (it only provides plane composition functionalities):
 [1].

 If I understand correctly you patch series might solve some of the
 issues I am facing.

It might get your working EGL, but it's not a complete solution,
because buffer management is limited to linear CPU-addressable dumb
buffers, which is probably not the most efficient choice (altough how
much slower it gets depends on the driver and on the HWl).

 I'm trying to get wayland working with HW cursor and several planes,
 the problem is that it depends on GBM to provides drm plane and drm
 cursor support.

 I tried to get EGL working with my DRM device and it always ask for an
 atmel-hlcdc_dri.so module (I have applied this patch [2] to get to this
 point).

 First of all, am I mistaken in thinking this series could solve my
 issue ?

Indeed, using my patch stack (patches 2 and 3) you will have a working
GBM device that will allocate GPU memory using the dumb interface.
If your driver is then able to upload this buffers to the plane HW (or
directly capable of allocating in GPU memory), that may be good enough
for you.
OTOH, this will not provide the wayland clients with the ability to
render directly to the plane buffers, because the dumb interface
does not provide global names that can be shared between processes,
therefore clients will have to render into a shared memory location,
that then the wayland compositor (weston, I assume) will have to
memcpy into a GBM allocated buffer.
If you want to avoid that, you will need to design an ioctl interface
for your driver to allocate buffers, then write a winsys for the
userspace side that uses those ioctls (directly or through libdrm) -
first it allocates the buffer with your driver specific ioctl and then
calls GEM_FLINK to get the global name, which can be passed to weston
and in there to gbm_bo_import().
If your HW is uncapable of GL rendering (and thus you want to use SW
rendering always) is quite likely that your driver will not be that
different from
dri_kms_swrast, except that will be able to share buffers (patch 3)
using GEM names.

 If not, could you tell me on which branch (or which tag) you based
 your work ?

 I'm asking this because I tried to apply your patches on top of the
 master branch (a few days ago), and after fixing some conflict I got a
 segfault (sorry, I don't have the backtrace anymore :-(, but this was
 related to negative stride value which was implying faulty memory
 access).

The patches were made against an old version of mesa, and the build
system was updated meanwhile. Emil said he will rebase them, and that
will happen in a couple days. You should just wait until they land.

Giovanni
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2014-06-19 Thread Giovanni Campagna
2014-06-19 16:16 GMT+02:00 Axel Davy axel.d...@ens.fr:
 On 15/06/2014 07:49, Giovanni Campagna wrote :

 From: Giovanni Campagna gcampa...@src.gnome.org

 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.

 Why does this require a new version of the DRI image extension ?
 Could you just set createImageFromName and CreateImageFromNames to NULL, and
 add checks for that (instead of checking the capability ?
 It's what is done to check if we can import dma-bufs (check if
 createImageFromFds is not NULL).

Yes, but in my opinion a generic getCapabilities() that returns a
bitmask is more flexible, and will allow avoiding version increases
and new vfuncs, should negotiation for new features be needed in the
future.

Giovanni
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


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

2014-06-16 Thread Giovanni Campagna
2014-06-16 14:47 GMT+02:00 Marek Olšák mar...@gmail.com:
 Does the new CAP cover resource_from_handle or resource_get_handle or both?

It covers both.

Giovanni

 Marek

 On Sun, Jun 15, 2014 at 1:49 PM, Giovanni Campagna
 scampa.giova...@gmail.com wrote:
 From: Giovanni Campagna gcampa...@src.gnome.org

 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| 17 +-
  src/egl/drivers/dri2/egl_dri2.c| 10 -
  src/egl/drivers/dri2/platform_drm.c| 17 +++---
  src/gallium/docs/source/screen.rst |  5 -
  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   |  3 ++-
  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 
 +++---
  21 files changed, 121 insertions(+), 14 deletions(-)

 diff --git a/include/GL/internal/dri_interface.h 
 b/include/GL/internal/dri_interface.h
 index 4d57d0b..fba1cac 100644
 --- a/include/GL/internal/dri_interface.h
 +++ b/include/GL/internal/dri_interface.h
 @@ -1005,7 +1005,7 @@ struct __DRIdri2ExtensionRec {
   * extensions.
   */
  #define __DRI_IMAGE DRI_IMAGE
 -#define __DRI_IMAGE_VERSION 8
 +#define __DRI_IMAGE_VERSION 9

  /**
   * These formats correspond to the similarly named MESA_FORMAT_*
 @@ -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 eb6abfd..132ebff 100644
 --- a/src/egl/drivers/dri2/egl_dri2.c
 +++ b/src/egl/drivers/dri2/egl_dri2.c
 @@ -520,7 +520,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 6a0dcd3..633b2ab 100644
 --- a/src/egl/drivers/dri2/platform_drm.c
 +++ b/src/egl/drivers/dri2/platform_drm.c
 @@ -270,7 +270,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

Re: [Mesa-dev] [PATCH v3 0/3] Software rendering in EGL-DRM

2014-06-16 Thread Giovanni Campagna
2014-06-16 7:47 GMT+02:00 Pekka Paalanen ppaala...@gmail.com:
 On Sun, 15 Jun 2014 13:49:48 +0200
 Giovanni Campagna scampa.giova...@gmail.com wrote:

 Hello all,

 This is the third attempt at swrast/llvmpipe support for DRM
 drivers that don't have userspace support (qxl, cirrus, simpledrm, etc.)

 I hope I addressed all of Emil's comments.

 Hi,

 this sounds cool work to me, sorry I can't really review it.

 Does this work also help in getting llvmpipe working with the egl_dri2
 loader?

If you mean in wayland, unfortunately no. Each egl platform has to
implement buffer uploading differently, so the code paths are
different. This patchset only tackles the DRM platform, which means
mutter, weston and other wayland compositors can run with llvmpipe,
but their clients will not have working egl.

 AFAIU, currently on EGL-Wayland the only way to use llvmpipe is to use
 egl_gallium.so as the loader, and I don't really know what it would
 take to make egl_dri2 work there, apart from the Wayland-specific bits,
 so I was kind of hoping your work would make that easier to implement.

In the end, the simple way is to implement swrastGetImage and
swrastPutImage for the wayland platform, using an shm backed buffer.
It would look similar to the platform_drm side (because the way drm
and wayland do double buffering is quite similar, and because both are
incapable of front-buffer rendering, single-buffer rendering or
rendering to foreign windows), but no real code sharing.
OTOH, in wayland buffer sharing exists, so it would be hugely
inefficient to implement swrast support this way (it incures one extra
copy, from the malloc backbuffer to the shm fake frontbuffer). It
should be possible to design an swrast2 interface in terms of shm
FDs, similar to prime/dma-buf FDs, and with similar semantics, just
nobody is working on it right now.

Giovanni
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3 1/3] Add support for swrast to the DRM EGL platform

2014-06-15 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

Turn GBM into a swrast loader (providing putimage/getimage backed
by a dumb KMS buffer). This allows to run KMS+DRM GL applications
(such as weston or mutter-wayland) unmodified on cards that don't
have any client side HW acceleration component but that can do
modeset (examples include simpledrm and qxl)
---
 src/egl/drivers/dri2/platform_drm.c | 162 +
 src/gbm/backends/dri/gbm_dri.c  | 202 +++-
 src/gbm/backends/dri/gbm_driint.h   |  35 ++-
 src/gbm/main/gbm.h  |   3 +
 4 files changed, 354 insertions(+), 48 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index 6227bc9..6a0dcd3 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -44,6 +44,7 @@ lock_front_buffer(struct gbm_surface *_surf)
 {
struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf;
struct dri2_egl_surface *dri2_surf = surf-dri_private;
+   struct gbm_dri_device *device = (struct gbm_dri_device *) _surf-gbm;
struct gbm_bo *bo;
 
if (dri2_surf-current == NULL) {
@@ -52,8 +53,11 @@ lock_front_buffer(struct gbm_surface *_surf)
}
 
bo = dri2_surf-current-bo;
-   dri2_surf-current-locked = 1;
-   dri2_surf-current = NULL;
+
+   if (device-dri2) {
+  dri2_surf-current-locked = 1;
+  dri2_surf-current = NULL;
+   }
 
return bo;
 }
@@ -122,14 +126,27 @@ dri2_drm_create_surface(_EGLDriver *drv, _EGLDisplay 
*disp, EGLint type,
   goto cleanup_surf;
}
 
-   dri2_surf-dri_drawable =
-  (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
-   dri2_conf-dri_double_config,
-   dri2_surf-gbm_surf);
+   if (dri2_dpy-dri2) {
+  dri2_surf-dri_drawable =
+ (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
+   dri2_conf-dri_double_config,
+   dri2_surf-gbm_surf);
 
-   if (dri2_surf-dri_drawable == NULL) {
-  _eglError(EGL_BAD_ALLOC, dri2-createNewDrawable);
-  goto cleanup_surf;
+  if (dri2_surf-dri_drawable == NULL) {
+ _eglError(EGL_BAD_ALLOC, dri2-createNewDrawable);
+ goto cleanup_surf;
+  }
+   } else {
+  assert (dri2_dpy-swrast != NULL);
+  dri2_surf-dri_drawable =
+ (*dri2_dpy-swrast-createNewDrawable) (dri2_dpy-dri_screen,
+ dri2_conf-dri_double_config,
+ dri2_surf-gbm_surf);
+
+  if (dri2_surf-dri_drawable == NULL) {
+ _eglError(EGL_BAD_ALLOC, swrast-createNewDrawable);
+ goto cleanup_surf;
+  }
}
 
return dri2_surf-base;
@@ -221,6 +238,28 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf-base.Resource.Display);
+   struct gbm_dri_surface *surf = dri2_surf-gbm_surf;
+
+   if (dri2_surf-current == NULL) {
+  assert (!dri2_surf-color_buffers[0].locked);
+  dri2_surf-current = dri2_surf-color_buffers[0];
+   }
+
+   if (dri2_surf-current-bo == NULL)
+  dri2_surf-current-bo = gbm_bo_create(dri2_dpy-gbm_dri-base.base,
+ surf-base.width, 
surf-base.height,
+ surf-base.format, 
surf-base.flags);
+   if (dri2_surf-current-bo == NULL)
+  return -1;
+
+   return 0;
+}
+
 static void
 back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
 {
@@ -374,19 +413,23 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
int i;
 
-   if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
-  if (dri2_surf-current)
-_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
-  for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
- if (dri2_surf-color_buffers[i].age  0)
-dri2_surf-color_buffers[i].age++;
-  dri2_surf-current = dri2_surf-back;
-  dri2_surf-current-age = 1;
-  dri2_surf-back = NULL;
-   }
+   if (dri2_dpy-swrast) {
+  (*dri2_dpy-core-swapBuffers)(dri2_surf-dri_drawable);
+   } else {
+  if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
+ if (dri2_surf-current)
+_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
+ for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
+if (dri2_surf-color_buffers[i].age  0)
+   dri2_surf-color_buffers[i].age++;
+ dri2_surf-current = dri2_surf-back;
+ dri2_surf-current-age = 1;
+ dri2_surf-back = NULL;
+  }
 
-   (*dri2_dpy-flush-flush)(dri2_surf-dri_drawable);
-   (*dri2_dpy-flush-invalidate

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

2014-06-15 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

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| 17 +-
 src/egl/drivers/dri2/egl_dri2.c| 10 -
 src/egl/drivers/dri2/platform_drm.c| 17 +++---
 src/gallium/docs/source/screen.rst |  5 -
 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   |  3 ++-
 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 +++---
 21 files changed, 121 insertions(+), 14 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 4d57d0b..fba1cac 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1005,7 +1005,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE DRI_IMAGE
-#define __DRI_IMAGE_VERSION 8
+#define __DRI_IMAGE_VERSION 9
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -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 eb6abfd..132ebff 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -520,7 +520,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 6a0dcd3..633b2ab 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -270,7 +270,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;
@@ -690,8 +693,16 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
   disp-Extensions.EXT_buffer_age = EGL_TRUE;
 
 #ifdef HAVE_WAYLAND_PLATFORM
-   if (dri2_dpy-image)
-  disp

[Mesa-dev] [PATCH v3 2/3] Add a dumb drm/kms winsys for software rendering

2014-06-15 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

Add a new winsys and target that can be used with a dri2 state tracker and
loader instead of drisw. This allows to use gbm as a dri2/image loader
and avoid the extra copy from the backbuffer to the shadow frontbuffer.

The new driver is called kms_swrast, and is only loaded by gbm
as a fallback, because it is only useful with the gbm platform
(as no buffer sharing is possible)
---
 configure.ac   |   5 +
 docs/relnotes/10.3.html|   2 +
 src/gallium/targets/Makefile.am|   3 +
 src/gallium/targets/dri-kms-swrast/Makefile.am |  61 
 .../targets/dri-kms-swrast/kms_swrast_drm_api.c|  65 +
 src/gallium/winsys/Makefile.am |   5 +
 src/gallium/winsys/sw/kms-dri/Makefile.am  |  33 +++
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c  | 312 +
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h  |  37 +++
 src/gbm/backends/dri/gbm_dri.c |  31 +-
 10 files changed, 549 insertions(+), 5 deletions(-)
 create mode 100644 src/gallium/targets/dri-kms-swrast/Makefile.am
 create mode 100644 src/gallium/targets/dri-kms-swrast/kms_swrast_drm_api.c
 create mode 100644 src/gallium/winsys/sw/kms-dri/Makefile.am
 create mode 100644 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
 create mode 100644 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h

diff --git a/configure.ac b/configure.ac
index 390adaa..07e4648 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1993,6 +1993,9 @@ if test -n $with_gallium_drivers; then
 if test x$enable_dri = xyes; then
 GALLIUM_TARGET_DIRS=$GALLIUM_TARGET_DIRS dri-swrast
 fi
+if text x$have_libdrm = xyes; then
+GALLIUM_TARGET_DIRS=$GALLIUM_TARGET_DIRS dri-kms-swrast
+fi
 ;;
 *)
 AC_MSG_ERROR([Unknown Gallium driver: $driver])
@@ -2206,6 +2209,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/state_trackers/xvmc/Makefile
src/gallium/targets/Makefile
src/gallium/targets/dri-freedreno/Makefile
+   src/gallium/targets/dri-kms-swrast/Makefile
src/gallium/targets/dri-i915/Makefile
src/gallium/targets/dri-ilo/Makefile
src/gallium/targets/dri-nouveau/Makefile
@@ -2243,6 +2247,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/winsys/svga/drm/Makefile
src/gallium/winsys/sw/dri/Makefile
src/gallium/winsys/sw/fbdev/Makefile
+   src/gallium/winsys/sw/kms-dri/Makefile
src/gallium/winsys/sw/null/Makefile
src/gallium/winsys/sw/wayland/Makefile
src/gallium/winsys/sw/wrapper/Makefile
diff --git a/docs/relnotes/10.3.html b/docs/relnotes/10.3.html
index 7ceaca4..6c47c19 100644
--- a/docs/relnotes/10.3.html
+++ b/docs/relnotes/10.3.html
@@ -48,6 +48,8 @@ Note: some of the new features are only available with 
certain drivers.
 liGL_ARB_stencil_texturing on nv50, nvc0, r600, and radeonsi/li
 liGL_ARB_texture_cube_map_array on radeonsi/li
 liGL_ARB_compressed_texture_pixel_storage on all drivers/li
+liA new software rasterizer driver (kms_swrast_dri.so) that works with
+DRM drivers that don't have a full-fledged GEM (such as qxl or simpledrm)/li
 /ul
 
 
diff --git a/src/gallium/targets/Makefile.am b/src/gallium/targets/Makefile.am
index 36d359c..16f88ba 100644
--- a/src/gallium/targets/Makefile.am
+++ b/src/gallium/targets/Makefile.am
@@ -126,6 +126,9 @@ if HAVE_GALLIUM_SOFTPIPE
 if HAVE_DRISW
 SUBDIRS += dri-swrast
 endif
+if HAVE_DRI2
+SUBDIRS += dri-kms-swrast
+endif
 endif
 
 if NEED_GALLIUM_LOADER
diff --git a/src/gallium/targets/dri-kms-swrast/Makefile.am 
b/src/gallium/targets/dri-kms-swrast/Makefile.am
new file mode 100644
index 000..09a8d17
--- /dev/null
+++ b/src/gallium/targets/dri-kms-swrast/Makefile.am
@@ -0,0 +1,61 @@
+# Copyright © 2012 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the Software),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

[Mesa-dev] [PATCH v3 0/3] Software rendering in EGL-DRM

2014-06-15 Thread Giovanni Campagna
Hello all,

This is the third attempt at swrast/llvmpipe support for DRM
drivers that don't have userspace support (qxl, cirrus, simpledrm, etc.)

I hope I addressed all of Emil's comments.

Giovanni

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


Re: [Mesa-dev] [PATCH v2 1/3] Add support for swrast to the DRM EGL platform

2014-05-18 Thread Giovanni Campagna
2014-05-15 2:47 GMT+02:00 Emil Velikov emil.l.veli...@gmail.com:
 On 05/05/14 17:07, Giovanni Campagna wrote:
 From: Giovanni Campagna gcampa...@src.gnome.org

 Turn GBM into a swrast loader (providing putimage/getimage backed
 by a dumb KMS buffer). This allows to run KMS+DRM GL applications
 (such as weston or mutter-wayland) unmodified on cards that don't
 have any client side HW acceleration component but that can do
 modeset (examples include simpledrm and qxl)
 ---
  src/egl/drivers/dri2/platform_drm.c | 186 
  src/gbm/backends/dri/gbm_dri.c  | 210 
 +---
  src/gbm/backends/dri/gbm_driint.h   |  19 +++-
  src/gbm/main/gbm.h  |   3 +
  src/loader/loader.c |   6 ++
  5 files changed, 363 insertions(+), 61 deletions(-)

 diff --git a/src/egl/drivers/dri2/platform_drm.c 
 b/src/egl/drivers/dri2/platform_drm.c
 index 9a7633a..17b93db 100644
 --- a/src/egl/drivers/dri2/platform_drm.c
 +++ b/src/egl/drivers/dri2/platform_drm.c
 @@ -32,6 +32,7 @@
  #include dlfcn.h
  #include sys/types.h
  #include sys/stat.h
 +#include sys/mman.h
  #include fcntl.h
  #include unistd.h

 @@ -44,6 +45,7 @@ lock_front_buffer(struct gbm_surface *_surf)
  {
 struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf;
 struct dri2_egl_surface *dri2_surf = surf-dri_private;
 +   struct gbm_dri_device *device = (struct gbm_dri_device *) _surf-gbm;
 struct gbm_bo *bo;

 if (dri2_surf-current == NULL) {
 @@ -52,8 +54,11 @@ lock_front_buffer(struct gbm_surface *_surf)
 }

 bo = dri2_surf-current-bo;
 -   dri2_surf-current-locked = 1;
 -   dri2_surf-current = NULL;
 +
 +   if (device-dri2) {
 +  dri2_surf-current-locked = 1;
 +  dri2_surf-current = NULL;
 +   }

 return bo;
  }
 @@ -122,10 +127,18 @@ dri2_drm_create_surface(_EGLDriver *drv, _EGLDisplay 
 *disp, EGLint type,
goto cleanup_surf;
 }

 -   dri2_surf-dri_drawable =
 -  (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
 - dri2_conf-dri_double_config,
 - dri2_surf-gbm_surf);
 +   if (dri2_dpy-dri2) {
 +  dri2_surf-dri_drawable =
 + (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
 +   dri2_conf-dri_double_config,
 +   dri2_surf-gbm_surf);
 +   } else {
 +  assert (dri2_dpy-swrast != NULL);
 +  dri2_surf-dri_drawable =
 + (*dri2_dpy-swrast-createNewDrawable) (dri2_dpy-dri_screen,
 + 
 dri2_conf-dri_double_config,
 + dri2_surf-gbm_surf);
 +   }

 if (dri2_surf-dri_drawable == NULL) {
_eglError(EGL_BAD_ALLOC, dri2-createNewDrawable);
 Can you update the above message ?

 @@ -221,6 +234,28 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
 return 0;
  }

 +static int
 +get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
 +{
 +   struct dri2_egl_display *dri2_dpy =
 +  dri2_egl_display(dri2_surf-base.Resource.Display);
 +   struct gbm_dri_surface *surf = dri2_surf-gbm_surf;
 +
 +   if (dri2_surf-current == NULL) {
 +  assert (!dri2_surf-color_buffers[0].locked);
 +  dri2_surf-current = dri2_surf-color_buffers[0];
 +   }
 +
 +   if (dri2_surf-current-bo == NULL)
 +  dri2_surf-current-bo = gbm_bo_create(dri2_dpy-gbm_dri-base.base,
 + surf-base.width, 
 surf-base.height,
 + surf-base.format, 
 surf-base.flags);
 +   if (dri2_surf-current-bo == NULL)
 +  return -1;
 +
 +   return 0;
 +}
 +
  static void
  back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer 
 *buffer)
  {
 @@ -374,19 +409,23 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay 
 *disp, _EGLSurface *draw)
 struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
 int i;

 -   if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
 -  if (dri2_surf-current)
 -  _eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
 -  for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
 - if (dri2_surf-color_buffers[i].age  0)
 -dri2_surf-color_buffers[i].age++;
 -  dri2_surf-current = dri2_surf-back;
 -  dri2_surf-current-age = 1;
 -  dri2_surf-back = NULL;
 -   }
 +   if (dri2_dpy-swrast) {
 +  (*dri2_dpy-core-swapBuffers)(dri2_surf-dri_drawable);
 +   } else {
 +  if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
 + if (dri2_surf-current)
 +_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
 + for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
 +if (dri2_surf-color_buffers[i].age  0)
 +   dri2_surf-color_buffers[i].age++;
 + dri2_surf-current = dri2_surf-back;
 + dri2_surf-current-age = 1;
 + dri2_surf-back

[Mesa-dev] [PATCH v2 0/3] Software rasterizer in the DRM EGL platform

2014-05-05 Thread Giovanni Campagna
This is my second attempt to bring swrast to the DRM EGL platform.
It includes both the legacy loader, which will work with any
swrast driver, and the new gallium winsys which works with the
DRI2 loader and softpipe/llvmpipe.

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


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

2014-05-05 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

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| 17 +-
 src/egl/drivers/dri2/egl_dri2.c| 10 -
 src/egl/drivers/dri2/platform_drm.c| 17 +++---
 src/gallium/docs/source/screen.rst |  5 -
 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 +++---
 21 files changed, 120 insertions(+), 13 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 4d57d0b..fba1cac 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1005,7 +1005,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE DRI_IMAGE
-#define __DRI_IMAGE_VERSION 8
+#define __DRI_IMAGE_VERSION 9
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -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 380bd7b..178a6f7 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -522,7 +522,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

[Mesa-dev] [PATCH v2 2/3] Add a dumb drm/kms winsys for software rendering

2014-05-05 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

Add a new winsys and target that can be used with a dri2 state tracker and
loader instead of drisw. This allows to use gbm as a dri2/image loader
and avoid the extra copy from the backbuffer to the shadow frontbuffer.

The new driver is called kms_swrast, and is only loaded by gbm
as a fallback, because it is only useful with the gbm platform
(as no buffer sharing is possible)
---
 configure.ac   |   4 +-
 docs/relnotes/10.3.html|   2 +
 src/gallium/targets/Makefile.am|   2 +-
 src/gallium/targets/dri-kms-swrast/Makefile.am |  61 
 .../targets/dri-kms-swrast/kms_swrast_drm_api.c|  65 +
 src/gallium/winsys/Makefile.am |   2 +-
 src/gallium/winsys/sw/kms-dri/Makefile.am  |  33 +++
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c  | 310 +
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h  |  37 +++
 src/gbm/backends/dri/gbm_dri.c |   6 +-
 10 files changed, 516 insertions(+), 6 deletions(-)
 create mode 100644 src/gallium/targets/dri-kms-swrast/Makefile.am
 create mode 100644 src/gallium/targets/dri-kms-swrast/kms_swrast_drm_api.c
 create mode 100644 src/gallium/winsys/sw/kms-dri/Makefile.am
 create mode 100644 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
 create mode 100644 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h

diff --git a/configure.ac b/configure.ac
index e77ed77..958e03e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1863,7 +1863,7 @@ if test -n $with_gallium_drivers; then
 fi
 
 if test x$enable_dri = xyes; then
-GALLIUM_TARGET_DIRS=$GALLIUM_TARGET_DIRS dri-swrast
+GALLIUM_TARGET_DIRS=$GALLIUM_TARGET_DIRS dri-swrast 
dri-kms-swrast
 fi
 ;;
 *)
@@ -2080,6 +2080,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/targets/dri-ilo/Makefile
src/gallium/targets/dri-nouveau/Makefile
src/gallium/targets/dri-swrast/Makefile
+   src/gallium/targets/dri-kms-swrast/Makefile
src/gallium/targets/dri-vmwgfx/Makefile
src/gallium/targets/egl-static/Makefile
src/gallium/targets/gbm/Makefile
@@ -2111,6 +2112,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/winsys/nouveau/drm/Makefile
src/gallium/winsys/radeon/drm/Makefile
src/gallium/winsys/svga/drm/Makefile
+   src/gallium/winsys/sw/kms-dri/Makefile
src/gallium/winsys/sw/dri/Makefile
src/gallium/winsys/sw/fbdev/Makefile
src/gallium/winsys/sw/null/Makefile
diff --git a/docs/relnotes/10.3.html b/docs/relnotes/10.3.html
index aebc3ff..92b2cc0 100644
--- a/docs/relnotes/10.3.html
+++ b/docs/relnotes/10.3.html
@@ -45,6 +45,8 @@ Note: some of the new features are only available with 
certain drivers.
 
 ul
 liGL_ARB_stencil_texturing on nv50, nvc0, r600, and radeonsi/li
+liA new software rasterizer driver that works with DRM drivers that
+don't have a full-fledged GEM (such as qxl or simpledrm)/li
 /ul
 
 
diff --git a/src/gallium/targets/Makefile.am b/src/gallium/targets/Makefile.am
index 5023dbc..95b644e 100644
--- a/src/gallium/targets/Makefile.am
+++ b/src/gallium/targets/Makefile.am
@@ -124,7 +124,7 @@ endif
 
 if HAVE_GALLIUM_SOFTPIPE
 if HAVE_DRI
-SUBDIRS += dri-swrast
+SUBDIRS += dri-swrast dri-kms-swrast
 endif
 endif
 
diff --git a/src/gallium/targets/dri-kms-swrast/Makefile.am 
b/src/gallium/targets/dri-kms-swrast/Makefile.am
new file mode 100644
index 000..09a8d17
--- /dev/null
+++ b/src/gallium/targets/dri-kms-swrast/Makefile.am
@@ -0,0 +1,61 @@
+# Copyright © 2012 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the Software),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS

[Mesa-dev] [PATCH v2 1/3] Add support for swrast to the DRM EGL platform

2014-05-05 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

Turn GBM into a swrast loader (providing putimage/getimage backed
by a dumb KMS buffer). This allows to run KMS+DRM GL applications
(such as weston or mutter-wayland) unmodified on cards that don't
have any client side HW acceleration component but that can do
modeset (examples include simpledrm and qxl)
---
 src/egl/drivers/dri2/platform_drm.c | 186 
 src/gbm/backends/dri/gbm_dri.c  | 210 +---
 src/gbm/backends/dri/gbm_driint.h   |  19 +++-
 src/gbm/main/gbm.h  |   3 +
 src/loader/loader.c |   6 ++
 5 files changed, 363 insertions(+), 61 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index 9a7633a..17b93db 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -32,6 +32,7 @@
 #include dlfcn.h
 #include sys/types.h
 #include sys/stat.h
+#include sys/mman.h
 #include fcntl.h
 #include unistd.h
 
@@ -44,6 +45,7 @@ lock_front_buffer(struct gbm_surface *_surf)
 {
struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf;
struct dri2_egl_surface *dri2_surf = surf-dri_private;
+   struct gbm_dri_device *device = (struct gbm_dri_device *) _surf-gbm;
struct gbm_bo *bo;
 
if (dri2_surf-current == NULL) {
@@ -52,8 +54,11 @@ lock_front_buffer(struct gbm_surface *_surf)
}
 
bo = dri2_surf-current-bo;
-   dri2_surf-current-locked = 1;
-   dri2_surf-current = NULL;
+
+   if (device-dri2) {
+  dri2_surf-current-locked = 1;
+  dri2_surf-current = NULL;
+   }
 
return bo;
 }
@@ -122,10 +127,18 @@ dri2_drm_create_surface(_EGLDriver *drv, _EGLDisplay 
*disp, EGLint type,
   goto cleanup_surf;
}
 
-   dri2_surf-dri_drawable =
-  (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
-   dri2_conf-dri_double_config,
-   dri2_surf-gbm_surf);
+   if (dri2_dpy-dri2) {
+  dri2_surf-dri_drawable =
+ (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
+   dri2_conf-dri_double_config,
+   dri2_surf-gbm_surf);
+   } else {
+  assert (dri2_dpy-swrast != NULL);
+  dri2_surf-dri_drawable =
+ (*dri2_dpy-swrast-createNewDrawable) (dri2_dpy-dri_screen,
+ dri2_conf-dri_double_config,
+ dri2_surf-gbm_surf);
+   }
 
if (dri2_surf-dri_drawable == NULL) {
   _eglError(EGL_BAD_ALLOC, dri2-createNewDrawable);
@@ -221,6 +234,28 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf-base.Resource.Display);
+   struct gbm_dri_surface *surf = dri2_surf-gbm_surf;
+
+   if (dri2_surf-current == NULL) {
+  assert (!dri2_surf-color_buffers[0].locked);
+  dri2_surf-current = dri2_surf-color_buffers[0];
+   }
+
+   if (dri2_surf-current-bo == NULL)
+  dri2_surf-current-bo = gbm_bo_create(dri2_dpy-gbm_dri-base.base,
+ surf-base.width, 
surf-base.height,
+ surf-base.format, 
surf-base.flags);
+   if (dri2_surf-current-bo == NULL)
+  return -1;
+
+   return 0;
+}
+
 static void
 back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
 {
@@ -374,19 +409,23 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
int i;
 
-   if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
-  if (dri2_surf-current)
-_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
-  for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
- if (dri2_surf-color_buffers[i].age  0)
-dri2_surf-color_buffers[i].age++;
-  dri2_surf-current = dri2_surf-back;
-  dri2_surf-current-age = 1;
-  dri2_surf-back = NULL;
-   }
+   if (dri2_dpy-swrast) {
+  (*dri2_dpy-core-swapBuffers)(dri2_surf-dri_drawable);
+   } else {
+  if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
+ if (dri2_surf-current)
+_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
+ for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
+if (dri2_surf-color_buffers[i].age  0)
+   dri2_surf-color_buffers[i].age++;
+ dri2_surf-current = dri2_surf-back;
+ dri2_surf-current-age = 1;
+ dri2_surf-back = NULL;
+  }
 
-   (*dri2_dpy-flush-flush)(dri2_surf-dri_drawable);
-   (*dri2_dpy-flush-invalidate)(dri2_surf-dri_drawable);
+  (*dri2_dpy-flush-flush)(dri2_surf-dri_drawable);
+  (*dri2_dpy-flush-invalidate)(dri2_surf-dri_drawable);
+   }
 
return

Re: [Mesa-dev] [PATCH 0/2] Turning swrast into DRI2 drivers

2014-04-21 Thread Giovanni Campagna
2014-04-14 22:37 GMT+02:00 Dave Airlie airl...@gmail.com:
 On Sat, Apr 12, 2014 at 10:25 AM, Giovanni Campagna
 scampa.giova...@gmail.com wrote:
 Hi everyone,

 Some time ago I sent patches to enable the swrast driver on
 GBM/DRM, and I did them in the dumbest way possible (that is,
 having GBM implement the dri-swrast interface), to make sure
 it would work without kernel support.
 This patch series is a little smarter, in that it creates
 more than one KMS buffer and has llvmpipe render directly
 into the KMS buffer, so we don't need to copy from the back
 to the shadow (before the kernel copies from the shadow to
 the front).

 For background, this is necessary to get mutter-wayland running
 inside VMs such as gnome-continuous, which has a qxl DRM driver.
 mutter-wayland only has a KMS/EGL rendering backend, and we
 have no intention to add pixman or fbdev.
 GNOME bug: https://bugzilla.gnome.org/show_bug.cgi?id=728059

 The older patches were 
 http://lists.freedesktop.org/archives/mesa-dev/2014-March/055113.html
 I can rebase if so is desired.

 I actually did something similiar that was qxl specific before,
 (qxl-dri2-driver in my repo, though it had some problems I can barely
 remember now), the only question I have is what does this produce?
 another swrast_dri.so? and will it have any affect on current
 scenarios?

The first patch (the one in the previous mail) only affects the
loader, not the driver, so it works with the current swrast_dri. This
set produces a swrast_dri2_dri.so, which is loaded only under the
drm+gbm+dri backend, so it does not affect drisw+x11 and
drisw+wayland.
Also, it's not qxl specific, as far i'm told, because it uses the dumb
ioctls, not the qxl gem. A qxl userspace driver with proper gem
buffersharing would allow us to use it for accelerating composition on
x11 too, but I'm not sure it's a real benefit, with wayland around the
corner.

Giovanni
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 0/2] Turning swrast into DRI2 drivers

2014-04-21 Thread Giovanni Campagna
2014-04-15 19:19 GMT+02:00 Adam Jackson a...@redhat.com:
 On Sat, 2014-04-12 at 02:25 +0200, Giovanni Campagna wrote:
 Hi everyone,

 Some time ago I sent patches to enable the swrast driver on
 GBM/DRM, and I did them in the dumbest way possible (that is,
 having GBM implement the dri-swrast interface), to make sure
 it would work without kernel support.
 This patch series is a little smarter, in that it creates
 more than one KMS buffer and has llvmpipe render directly
 into the KMS buffer, so we don't need to copy from the back
 to the shadow (before the kernel copies from the shadow to
 the front).

 Have you looked into making this work with -modesetting as the ddx
 driver, not just qxl?

This works on the DRM platform, not X11, so there is no DDX involved.
It was tested with the qxl and i915 (through LIBGL_ALWAYS_SOFTWARE)
kernel drivers (some time ago...)

Giovanni
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 0/2] Turning swrast into DRI2 drivers

2014-04-12 Thread Giovanni Campagna
Hi everyone,

Some time ago I sent patches to enable the swrast driver on
GBM/DRM, and I did them in the dumbest way possible (that is,
having GBM implement the dri-swrast interface), to make sure
it would work without kernel support.
This patch series is a little smarter, in that it creates
more than one KMS buffer and has llvmpipe render directly
into the KMS buffer, so we don't need to copy from the back
to the shadow (before the kernel copies from the shadow to
the front).

For background, this is necessary to get mutter-wayland running
inside VMs such as gnome-continuous, which has a qxl DRM driver.
mutter-wayland only has a KMS/EGL rendering backend, and we
have no intention to add pixman or fbdev.
GNOME bug: https://bugzilla.gnome.org/show_bug.cgi?id=728059

The older patches were 
http://lists.freedesktop.org/archives/mesa-dev/2014-March/055113.html
I can rebase if so is desired.

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


[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 gcampa...@src.gnome.org

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-dri_screen);
+   disp

[Mesa-dev] [PATCH 1/2] Add a dumb drm/kms winsys for software rendering

2014-04-12 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

Add a new winsys and target that can be used with a dri2 state tracker and
loader instead of drisw. This allows to use gbm as a dri2/image loader
and avoid the extra copy from the backbuffer to the shadow frontbuffer.
---
 configure.ac  |   4 +-
 src/gallium/targets/Makefile.am   |   2 +-
 src/gallium/targets/dri-swrast2/Makefile.am   |  72 +
 src/gallium/targets/dri-swrast2/swrast2_drm_api.c |  65 +
 src/gallium/winsys/Makefile.am|   2 +-
 src/gallium/winsys/sw/kms-dri/Makefile.am |  33 +++
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c | 310 ++
 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h |  37 +++
 8 files changed, 522 insertions(+), 3 deletions(-)
 create mode 100644 src/gallium/targets/dri-swrast2/Makefile.am
 create mode 100644 src/gallium/targets/dri-swrast2/swrast2_drm_api.c
 create mode 100644 src/gallium/winsys/sw/kms-dri/Makefile.am
 create mode 100644 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
 create mode 100644 src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h

diff --git a/configure.ac b/configure.ac
index c71fa26..7179abd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1857,7 +1857,7 @@ if test -n $with_gallium_drivers; then
 fi
 
 if test x$enable_dri = xyes; then
-GALLIUM_TARGET_DIRS=$GALLIUM_TARGET_DIRS dri-swrast
+GALLIUM_TARGET_DIRS=$GALLIUM_TARGET_DIRS dri-swrast 
dri-swrast2
 fi
 ;;
 *)
@@ -2073,6 +2073,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/targets/dri-ilo/Makefile
src/gallium/targets/dri-nouveau/Makefile
src/gallium/targets/dri-swrast/Makefile
+   src/gallium/targets/dri-swrast2/Makefile
src/gallium/targets/dri-vmwgfx/Makefile
src/gallium/targets/egl-static/Makefile
src/gallium/targets/gbm/Makefile
@@ -2103,6 +2104,7 @@ AC_CONFIG_FILES([Makefile
src/gallium/winsys/nouveau/drm/Makefile
src/gallium/winsys/radeon/drm/Makefile
src/gallium/winsys/svga/drm/Makefile
+   src/gallium/winsys/sw/kms-dri/Makefile
src/gallium/winsys/sw/dri/Makefile
src/gallium/winsys/sw/fbdev/Makefile
src/gallium/winsys/sw/null/Makefile
diff --git a/src/gallium/targets/Makefile.am b/src/gallium/targets/Makefile.am
index 871b31d..475962b 100644
--- a/src/gallium/targets/Makefile.am
+++ b/src/gallium/targets/Makefile.am
@@ -120,7 +120,7 @@ endif
 
 if HAVE_GALLIUM_SOFTPIPE
 if HAVE_DRI
-SUBDIRS += dri-swrast
+SUBDIRS += dri-swrast dri-swrast2
 endif
 endif
 
diff --git a/src/gallium/targets/dri-swrast2/Makefile.am 
b/src/gallium/targets/dri-swrast2/Makefile.am
new file mode 100644
index 000..d22ec82
--- /dev/null
+++ b/src/gallium/targets/dri-swrast2/Makefile.am
@@ -0,0 +1,72 @@
+# Copyright © 2012 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the Software),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = \
+   $(GALLIUM_CFLAGS) \
+   $(PTHREAD_CFLAGS) \
+   $(LIBDRM_CFLAGS)
+AM_CPPFLAGS = \
+   -I$(top_srcdir)/src/gallium/winsys/sw/kms-dri \
+   -I$(top_srcdir)/src/gallium/drivers \
+   -I$(top_srcdir)/src/gallium/winsys \
+   -I$(top_srcdir)/src/mesa \
+   -I$(top_srcdir)/src/mapi \
+   -DGALLIUM_RBUG \
+   -DGALLIUM_TRACE \
+   -DGALLIUM_SOFTPIPE
+
+dridir = $(DRI_DRIVER_INSTALL_DIR)
+dri_LTLIBRARIES = swrast_dri2_dri.la
+
+swrast_dri2_dri_la_SOURCES = \
+   swrast2_drm_api.c \
+   $(top_srcdir)/src/mesa/drivers/dri/common/utils.c \
+   $(top_srcdir)/src/mesa/drivers/dri/common/dri_util.c \
+   $(top_srcdir)/src/mesa/drivers/dri/common/xmlconfig.c
+
+swrast_dri2_dri_la_LDFLAGS = -module -avoid-version

[Mesa-dev] [PATCH] Add support for swrast to the DRM EGL platform

2014-03-01 Thread Giovanni Campagna
From: Giovanni Campagna gcampa...@src.gnome.org

Turn GBM into a swrast loader (providing putimage/getimage backed
by a dumb KMS buffer). This allows to run KMS+DRM GL applications
(such as weston or mutter-wayland) unmodified on cards that don't
have any client side HW acceleration component but that can do
modeset (examples include simpledrm and qxl)
---
 src/egl/drivers/dri2/platform_drm.c | 186 
 src/gbm/backends/dri/gbm_dri.c  | 208 +---
 src/gbm/backends/dri/gbm_driint.h   |  21 +++-
 src/gbm/main/gbm.h  |   3 +
 src/loader/loader.c |   6 ++
 5 files changed, 363 insertions(+), 61 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_drm.c 
b/src/egl/drivers/dri2/platform_drm.c
index a2b387d..265c935 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -32,6 +32,7 @@
 #include dlfcn.h
 #include sys/types.h
 #include sys/stat.h
+#include sys/mman.h
 #include fcntl.h
 #include unistd.h
 
@@ -43,6 +44,7 @@ lock_front_buffer(struct gbm_surface *_surf)
 {
struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf;
struct dri2_egl_surface *dri2_surf = surf-dri_private;
+   struct gbm_dri_device *device = (struct gbm_dri_device *) _surf-gbm;
struct gbm_bo *bo;
 
if (dri2_surf-current == NULL) {
@@ -51,8 +53,11 @@ lock_front_buffer(struct gbm_surface *_surf)
}
 
bo = dri2_surf-current-bo;
-   dri2_surf-current-locked = 1;
-   dri2_surf-current = NULL;
+
+   if (device-dri2) {
+  dri2_surf-current-locked = 1;
+  dri2_surf-current = NULL;
+   }
 
return bo;
 }
@@ -120,10 +125,18 @@ dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, 
EGLint type,
   goto cleanup_surf;
}
 
-   dri2_surf-dri_drawable =
-  (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
-   dri2_conf-dri_double_config,
-   dri2_surf-gbm_surf);
+   if (dri2_dpy-dri2) {
+  dri2_surf-dri_drawable =
+ (*dri2_dpy-dri2-createNewDrawable) (dri2_dpy-dri_screen,
+   dri2_conf-dri_double_config,
+   dri2_surf-gbm_surf);
+   } else {
+  assert (dri2_dpy-swrast != NULL);
+  dri2_surf-dri_drawable =
+ (*dri2_dpy-swrast-createNewDrawable) (dri2_dpy-dri_screen,
+ dri2_conf-dri_double_config,
+ dri2_surf-gbm_surf);
+   }
 
if (dri2_surf-dri_drawable == NULL) {
   _eglError(EGL_BAD_ALLOC, dri2-createNewDrawable);
@@ -204,6 +217,28 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
return 0;
 }
 
+static int
+get_swrast_front_bo(struct dri2_egl_surface *dri2_surf)
+{
+   struct dri2_egl_display *dri2_dpy =
+  dri2_egl_display(dri2_surf-base.Resource.Display);
+   struct gbm_dri_surface *surf = dri2_surf-gbm_surf;
+
+   if (dri2_surf-current == NULL) {
+  assert (!dri2_surf-color_buffers[0].locked);
+  dri2_surf-current = dri2_surf-color_buffers[0];
+   }
+
+   if (dri2_surf-current-bo == NULL)
+  dri2_surf-current-bo = gbm_bo_create(dri2_dpy-gbm_dri-base.base,
+ surf-base.width, 
surf-base.height,
+ surf-base.format, 
surf-base.flags);
+   if (dri2_surf-current-bo == NULL)
+  return -1;
+
+   return 0;
+}
+
 static void
 back_bo_to_dri_buffer(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer)
 {
@@ -357,19 +392,23 @@ dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *draw)
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
int i;
 
-   if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
-  if (dri2_surf-current)
-_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
-  for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
- if (dri2_surf-color_buffers[i].age  0)
-dri2_surf-color_buffers[i].age++;
-  dri2_surf-current = dri2_surf-back;
-  dri2_surf-current-age = 1;
-  dri2_surf-back = NULL;
-   }
+   if (dri2_dpy-swrast) {
+  (*dri2_dpy-core-swapBuffers)(dri2_surf-dri_drawable);
+   } else {
+  if (dri2_surf-base.Type == EGL_WINDOW_BIT) {
+ if (dri2_surf-current)
+_eglError(EGL_BAD_SURFACE, dri2_swap_buffers);
+ for (i = 0; i  ARRAY_SIZE(dri2_surf-color_buffers); i++)
+if (dri2_surf-color_buffers[i].age  0)
+   dri2_surf-color_buffers[i].age++;
+ dri2_surf-current = dri2_surf-back;
+ dri2_surf-current-age = 1;
+ dri2_surf-back = NULL;
+  }
 
-   (*dri2_dpy-flush-flush)(dri2_surf-dri_drawable);
-   (*dri2_dpy-flush-invalidate)(dri2_surf-dri_drawable);
+  (*dri2_dpy-flush-flush)(dri2_surf-dri_drawable);
+  (*dri2_dpy-flush-invalidate)(dri2_surf-dri_drawable);
+   }
 
return