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

Emil Velikov emil.l.velikov at gmail.com
Wed May 14 17:54:52 PDT 2014


On 05/05/14 17:07, Giovanni Campagna wrote:
> From: Giovanni Campagna <gcampagna at 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)
Hi Giovanni,

A couple of nits that I have missed the previous time.

> ---
>  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"
dri-kms-swrast depends on DRM so it may be better to change the above to

if test "x$have_libdrm" = xyes; then
   GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-kms-swrast"
fi

>              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>
>  <li>GL_ARB_stencil_texturing on nv50, nvc0, r600, and radeonsi</li>
> +<li>A new software rasterizer driver that works with DRM drivers that
> +don't have a full-fledged GEM (such as qxl or simpledrm)</li>
>  </ul>

+<li>A new software rasterizer driver (kms_swrast_dri.so) that works
+with DRM drivers which are lacking a full-fledged GEM (such as qxl
+or simpledrm)</li>


>  
>  
> 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
Similar to before, build the new driver only when libdrm is present

if HAVE_LIBDRM
SUBDIRS += dri-kms-swrast
endif

>  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 0000000..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 = \
> +	$(EXPAT_CFLAGS) \
> +	$(GALLIUM_DRI_CFLAGS)
> +AM_CPPFLAGS = \
> +	-I$(top_srcdir)/src/gallium/winsys/sw/kms-dri \
> +	-I$(top_builddir)/src/mesa/drivers/dri/common \
> +	-DGALLIUM_RBUG \
> +	-DGALLIUM_TRACE \
> +	-DGALLIUM_SOFTPIPE \
> +	-D__NOT_HAVE_DRM_H
> +
> +dridir = $(DRI_DRIVER_INSTALL_DIR)
> +dri_LTLIBRARIES = kms_swrast_dri.la
> +
> +nodist_EXTRA_kms_swrast_dri_la_SOURCES = dummy.cpp
> +kms_swrast_dri_la_SOURCES = \
> +	kms_swrast_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
> +
> +kms_swrast_dri_la_LDFLAGS = $(GALLIUM_DRI_LINKER_FLAGS)
> +
> +kms_swrast_dri_la_LIBADD = \
> +	$(top_builddir)/src/gallium/state_trackers/dri/drm/libdridrm.la \
> +	$(top_builddir)/src/gallium/winsys/sw/kms-dri/libswkmsdri.la \
> +	$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
> +	$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
> +	$(top_builddir)/src/gallium/drivers/rbug/librbug.la \
> +	$(GALLIUM_DRI_LIB_DEPS)
> +
> +if HAVE_MESA_LLVM
> +AM_CPPFLAGS += -DGALLIUM_LLVMPIPE
> +kms_swrast_dri_la_LIBADD += $(top_builddir)/src/gallium/drivers/llvmpipe/libllvmpipe.la
> +endif
> +
> +include $(top_srcdir)/install-gallium-links.mk
> diff --git a/src/gallium/targets/dri-kms-swrast/kms_swrast_drm_api.c b/src/gallium/targets/dri-kms-swrast/kms_swrast_drm_api.c
> new file mode 100644
> index 0000000..10f891b
> --- /dev/null
> +++ b/src/gallium/targets/dri-kms-swrast/kms_swrast_drm_api.c
> @@ -0,0 +1,65 @@
> +/**************************************************************************
> + *
> + * Copyright 2009, VMware, Inc.
> + * All Rights Reserved.
> + * Copyright 2010 George Sapountzis <gsapountzis at gmail.com>
> + *
> + * 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, sub license, 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 NON-INFRINGEMENT.
> + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 "pipe/p_compiler.h"
> +#include "util/u_memory.h"
> +#include "kms_dri_sw_winsys.h"
> +
> +#include "target-helpers/inline_debug_helper.h"
> +#include "target-helpers/inline_sw_helper.h"
> +
> +#include "state_tracker/drm_driver.h"
> +
> +static struct pipe_screen *
> +drisw_create_dri2_screen(int fd)
> +{
> +   struct sw_winsys *winsys = NULL;
> +   struct pipe_screen *screen = NULL;
> +
> +   winsys = kms_dri_create_winsys(fd);
> +   if (winsys == NULL)
> +      return NULL;
> +
> +   screen = sw_screen_create(winsys);
> +   if (!screen)
> +      goto fail;
> +
> +   screen = debug_screen_wrap(screen);
> +
> +   return screen;
> +
> +fail:
> +   if (winsys)
> +      winsys->destroy(winsys);
> +
> +   return NULL;
> +}
> +
> +DRM_DRIVER_DESCRIPTOR("swrast", NULL, drisw_create_dri2_screen, NULL);
> +
> +/* vim: set sw=3 ts=8 sts=3 expandtab: */
> diff --git a/src/gallium/winsys/Makefile.am b/src/gallium/winsys/Makefile.am
> index ab1acc3..d2f50b3 100644
> --- a/src/gallium/winsys/Makefile.am
> +++ b/src/gallium/winsys/Makefile.am
> @@ -27,7 +27,7 @@ SUBDIRS += sw/xlib
>  endif
>  
>  if HAVE_DRI
> -SUBDIRS += sw/dri
> +SUBDIRS += sw/dri sw/kms-dri
if HAVE_LIBDRM
SUBDIRS += sw/kms-dri
endif

>  endif
>  
>  if HAVE_EGL_PLATFORM_FBDEV
> diff --git a/src/gallium/winsys/sw/kms-dri/Makefile.am b/src/gallium/winsys/sw/kms-dri/Makefile.am
> new file mode 100644
> index 0000000..320e9dc
> --- /dev/null
> +++ b/src/gallium/winsys/sw/kms-dri/Makefile.am
> @@ -0,0 +1,33 @@
> +# Copyright © 2012 Intel Corporation
> +#             2013 Red Hat, Inc.
> +#
> +# 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_CPPFLAGS = \
> +	$(GALLIUM_CFLAGS) \
> +        $(LIBDRM_CFLAGS)
Indentation looks odd here.

> +
> +noinst_LTLIBRARIES = libswkmsdri.la
> +
> +libswkmsdri_la_SOURCES = kms_dri_sw_winsys.c
> +libswkmsdri_la_LIBADD = $(LIBDRM_LIBS)
> 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
> new file mode 100644
> index 0000000..745b857
> --- /dev/null
> +++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
> @@ -0,0 +1,310 @@
> +/**************************************************************************
> + *
> + * Copyright 2009, VMware, Inc.
> + * All Rights Reserved.
> + * Copyright 2010 George Sapountzis <gsapountzis at gmail.com>
> + *           2013 Red Hat, Inc.
> + *
> + * 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, sub license, 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 NON-INFRINGEMENT.
> + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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 <stdio.h>
> +#include <stdlib.h>
> +#include <stddef.h>
> +#include <stdint.h>
> +#include <string.h>
> +#include <limits.h>
> +
> +#include <sys/types.h>
> +#include <sys/mman.h>
> +#include <unistd.h>
> +#include <dlfcn.h>
> +#include <xf86drm.h>
> +
> +#include "pipe/p_compiler.h"
> +#include "pipe/p_format.h"
> +#include "util/u_inlines.h"
> +#include "util/u_format.h"
> +#include "util/u_math.h"
> +#include "util/u_memory.h"
> +#include "util/u_double_list.h"
> +
> +#include "state_tracker/sw_winsys.h"
> +#include "state_tracker/drm_driver.h"
> +
> +#if 0
> +#define DEBUG(msg, ...) fprintf(stderr, msg, __VA_ARGS__)
> +#else
> +#define DEBUG(msg, ...)
> +#endif
> +
> +struct sw_winsys;
> +
> +struct sw_winsys *kms_dri_create_winsys(int fd);
> +
> +struct kms_sw_displaytarget
> +{
> +   enum pipe_format format;
> +   unsigned width;
> +   unsigned height;
> +   unsigned stride;
> +   unsigned size;
> +
> +   uint32_t handle;
> +   void *mapped;
> +
> +   int ref_count;
> +   struct list_head link;
> +};
> +
> +struct kms_sw_winsys
> +{
> +   struct sw_winsys base;
> +
> +   int fd;
> +   struct list_head bo_list;
> +};
> +
> +static INLINE struct kms_sw_displaytarget *
> +kms_sw_displaytarget( struct sw_displaytarget *dt )
> +{
> +   return (struct kms_sw_displaytarget *)dt;
> +}
> +
> +static INLINE struct kms_sw_winsys *
> +kms_sw_winsys( struct sw_winsys *ws )
> +{
> +   return (struct kms_sw_winsys *)ws;
> +}
> +
> +
> +static boolean
> +kms_sw_is_displaytarget_format_supported( struct sw_winsys *ws,
> +                                          unsigned tex_usage,
> +                                          enum pipe_format format )
> +{
> +   /* TODO: check visuals or other sensible thing here */
> +   return TRUE;
> +}
> +
> +static struct sw_displaytarget *
> +kms_sw_displaytarget_create(struct sw_winsys *ws,
> +                            unsigned tex_usage,
> +                            enum pipe_format format,
> +                            unsigned width, unsigned height,
> +                            unsigned alignment,
> +                            unsigned *stride)
> +{
> +   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
> +   struct kms_sw_displaytarget *kms_sw_dt;
> +   struct drm_mode_create_dumb create_req;
> +   struct drm_mode_destroy_dumb destroy_req;
> +   int ret;
> +
> +   kms_sw_dt = CALLOC_STRUCT(kms_sw_displaytarget);
> +   if(!kms_sw_dt)
> +      goto no_dt;
> +
> +   kms_sw_dt->ref_count = 1;
> +
> +   kms_sw_dt->format = format;
> +   kms_sw_dt->width = width;
> +   kms_sw_dt->height = height;
> +
Zero out create_req.handle and/or the whole create_req ? Otherwise we'll be
feeding random junk to destroy_req.handle below.

> +   create_req.bpp = 32;
> +   create_req.width = width;
> +   create_req.height = height;
> +   ret = drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_req);
> +   if (ret)
> +      goto free_bo;
> +
> +   kms_sw_dt->stride = create_req.pitch;
> +   kms_sw_dt->size = create_req.size;
> +   kms_sw_dt->handle = create_req.handle;
> +
> +   list_add(&kms_sw_dt->link, &kms_sw->bo_list);
> +
> +   DEBUG("KMS-DEBUG: created 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;
> +
> + free_bo:
> +   memset(&destroy_req, 0, sizeof destroy_req);
> +   destroy_req.handle = create_req.handle;
> +   drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_req);
> +   FREE(kms_sw_dt);
> + no_dt:
> +   return NULL;
> +}
> +
> +static void
> +kms_sw_displaytarget_destroy(struct sw_winsys *ws,
> +                             struct sw_displaytarget *dt)
> +{
> +   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
> +   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
> +   struct drm_mode_destroy_dumb destroy_req;
> +
> +   kms_sw_dt->ref_count --;
> +   if (kms_sw_dt->ref_count > 0)
> +      return;
> +
> +   memset(&destroy_req, 0, sizeof destroy_req);
> +   destroy_req.handle = kms_sw_dt->handle;
> +   drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_req);
> +
> +   list_del(&kms_sw_dt->link);
> +
> +   DEBUG("KMS-DEBUG: destroyed buffer %u\n", kms_sw_dt->handle);
> +
> +   FREE(kms_sw_dt);
> +}
> +
> +static void *
> +kms_sw_displaytarget_map(struct sw_winsys *ws,
> +                         struct sw_displaytarget *dt,
> +                         unsigned flags)
> +{
> +   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
> +   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
> +   struct drm_mode_map_dumb map_req;
> +   int ret;
> +
> +   memset(&map_req, 0, sizeof map_req);
> +   map_req.handle = kms_sw_dt->handle;
> +   ret = drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_req);
> +   if (ret)
> +      return NULL;
> +
> +   if (flags == PIPE_TRANSFER_READ)
> +      kms_sw_dt->mapped = mmap(0, kms_sw_dt->size, PROT_READ, MAP_SHARED,
> +                               kms_sw->fd, map_req.offset);
> +   else
> +      kms_sw_dt->mapped = mmap(0, kms_sw_dt->size, PROT_READ | PROT_WRITE, MAP_SHARED,
> +                               kms_sw->fd, map_req.offset);
Maybe define prot as below and simplify things a bit.

int prot = (flags == PIPE_TRANSFER_READ) ? PROT_READ : PROT_READ | PROT_WRITE;
kms_sw_dt->mapped = mmap(0, kms_sw_dt->size, prot, MAP_SHARED,
                               kms_sw->fd, map_req.offset);

if (kms_sw_dt->mapped == MAP_FAILED)
   return NULL;

> +
> +   DEBUG("KMS-DEBUG: mapped buffer %u (size %u) at %p\n",
> +         kms_sw_dt->handle, kms_sw_dt->size, kms_sw_dt->mapped);
> +
> +   return kms_sw_dt->mapped;
> +}
> +
> +static void
> +kms_sw_displaytarget_unmap(struct sw_winsys *ws,
> +                           struct sw_displaytarget *dt)
> +{
> +   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
> +
> +   DEBUG("KMS-DEBUG: unmapped buffer %u (was %p)\n", kms_sw_dt->handle, kms_sw_dt->mapped);
> +
> +   munmap(kms_sw_dt->mapped, kms_sw_dt->size);
> +   kms_sw_dt->mapped = NULL;
> +}
> +
> +static struct sw_displaytarget *
> +kms_sw_displaytarget_from_handle(struct sw_winsys *ws,
> +                                 const struct pipe_resource *templ,
> +                                 struct winsys_handle *whandle,
> +                                 unsigned *stride)
> +{
> +   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
> +   struct kms_sw_displaytarget *kms_sw_dt;
> +
> +   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);
> +
> +         *stride = kms_sw_dt->stride;
> +         return (struct sw_displaytarget *)kms_sw_dt;
> +      }
> +   }
> +
> +   assert(0);
> +   return NULL;
> +}
> +
> +static boolean
> +kms_sw_displaytarget_get_handle(struct sw_winsys *winsys,
> +                                struct sw_displaytarget *dt,
> +                                struct winsys_handle *whandle)
> +{
> +   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
> +
> +   assert(whandle->type == DRM_API_HANDLE_TYPE_SHARED);
> +   whandle->handle = kms_sw_dt->handle;
> +   whandle->stride = kms_sw_dt->stride;
> +   return TRUE;
> +}
> +
> +static void
> +kms_sw_displaytarget_display(struct sw_winsys *ws,
> +                             struct sw_displaytarget *dt,
> +                             void *context_private)
> +{
> +   /* This function should not be called, instead the dri2 loader should
> +      handle swap buffers internally.
> +   */
> +   assert(0);
> +}
> +
> +
> +static void
> +kms_destroy_sw_winsys(struct sw_winsys *winsys)
> +{
> +   FREE(winsys);
> +}
> +
> +struct sw_winsys *
> +kms_dri_create_winsys(int fd)
> +{
> +   struct kms_sw_winsys *ws;
> +
> +   ws = CALLOC_STRUCT(kms_sw_winsys);
> +   if (!ws)
> +      return NULL;
> +
> +   ws->fd = fd;
> +   list_inithead(&ws->bo_list);
> +
> +   ws->base.destroy = kms_destroy_sw_winsys;
> +
> +   ws->base.is_displaytarget_format_supported = kms_sw_is_displaytarget_format_supported;
> +
> +   /* screen texture functions */
> +   ws->base.displaytarget_create = kms_sw_displaytarget_create;
> +   ws->base.displaytarget_destroy = kms_sw_displaytarget_destroy;
> +   ws->base.displaytarget_from_handle = kms_sw_displaytarget_from_handle;
> +   ws->base.displaytarget_get_handle = kms_sw_displaytarget_get_handle;
> +
> +   /* texture functions */
> +   ws->base.displaytarget_map = kms_sw_displaytarget_map;
> +   ws->base.displaytarget_unmap = kms_sw_displaytarget_unmap;
> +
> +   ws->base.displaytarget_display = kms_sw_displaytarget_display;
> +
> +   return &ws->base;
> +}
> +
> +/* vim: set sw=3 ts=8 sts=3 expandtab: */
> diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h
> new file mode 100644
> index 0000000..e276a72
> --- /dev/null
> +++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h
> @@ -0,0 +1,37 @@
> +/**************************************************************************
> + *
> + * Copyright 2009, VMware, Inc.
> + * All Rights Reserved.
> + * Copyright 2010 George Sapountzis <gsapountzis at gmail.com>
> + *           2013 Red Hat, Inc.
> + *
> + * 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, sub license, 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 NON-INFRINGEMENT.
> + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
> + *
> + **************************************************************************/
> +
> +#ifndef KMS_DRI_SW_WINSYS
> +#define KMS_DRI_SW_WINSYS
> +
> +struct sw_winsys;
> +
> +struct sw_winsys *kms_dri_create_winsys(int fd);
> +
> +#endif
> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
> index 53d0bf3..8a26524 100644
> --- a/src/gbm/backends/dri/gbm_dri.c
> +++ b/src/gbm/backends/dri/gbm_dri.c
> @@ -371,13 +371,13 @@ dri_screen_create(struct gbm_dri_device *dri)
>  
>     dri->base.driver_name = loader_get_driver_for_fd(dri->base.base.fd, 0);
>     if (dri->base.driver_name == NULL)
> -      return -1;
> +      dri->base.driver_name = "kms_swrast";
>  
>     ret = dri_load_driver(dri);
>     if (ret) {
>        fprintf(stderr, "failed to load driver: %s\n", dri->base.driver_name);
>  
> -      dri->base.driver_name = "swrast";
> +      dri->base.driver_name = "kms_swrast";
>        ret = dri_load_driver(dri);
>        if (ret) {
>           fprintf(stderr, "failed to fallback to software rendering\n");
> @@ -578,7 +578,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
>     int gbm_format;
>  
>     /* Required for query image WIDTH & HEIGHT */
> -   if (dri->image == NULL || dri->image->base.version < 4)
> +   if (dri->image == NULL || dri->image->base.version < 4) {
Can you sneak this in the previous patch ?

-Emil

>        errno = ENOSYS;
>        return NULL;
>     }
> 



More information about the mesa-dev mailing list