pipe-loader: rework the sw backend
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 17 Oct 2015 20:51:24 +0000 (21:51 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Sat, 21 Nov 2015 12:52:18 +0000 (12:52 +0000)
Move the winsys into the pipe-target, similar to the hardware
pipe-driver.

v2:
 - move int declaration outside of loop (Brian)
 - fold the teardown into a goto + separate function.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Rob Clark <robclark@freedesktop.org>
14 files changed:
src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c
src/gallium/include/state_tracker/sw_driver.h [new file with mode: 0644]
src/gallium/targets/d3dadapter9/Makefile.am
src/gallium/targets/dri/Makefile.am
src/gallium/targets/omx/Makefile.am
src/gallium/targets/opencl/Makefile.am
src/gallium/targets/pipe-loader/Makefile.am
src/gallium/targets/pipe-loader/pipe.sym
src/gallium/targets/pipe-loader/pipe_swrast.c
src/gallium/targets/va/Makefile.am
src/gallium/targets/vdpau/Makefile.am
src/gallium/targets/xa/Makefile.am
src/gallium/targets/xvmc/Makefile.am
src/gallium/tests/trivial/Makefile.am

index c61f2b8882c4bb5036caea77baa1d7113b5934ed..816ff1c85d3042b04491f61814ac059bc0bd90b8 100644 (file)
 #include "sw/wrapper/wrapper_sw_winsys.h"
 #include "target-helpers/inline_sw_helper.h"
 #include "state_tracker/drisw_api.h"
+#include "state_tracker/sw_driver.h"
 
 struct pipe_loader_sw_device {
    struct pipe_loader_device base;
+   const struct sw_driver_descriptor *dd;
    struct util_dl_library *lib;
    struct sw_winsys *ws;
 };
@@ -49,33 +51,62 @@ static struct pipe_loader_ops pipe_loader_sw_ops;
 static bool
 pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device *sdev)
 {
-   if (!sdev->ws)
-      return false;
-
    sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
    sdev->base.driver_name = "swrast";
    sdev->base.ops = &pipe_loader_sw_ops;
 
+   sdev->lib = pipe_loader_find_module(&sdev->base, PIPE_SEARCH_DIR);
+   if (!sdev->lib)
+      return false;
+
+   sdev->dd = (const struct sw_driver_descriptor *)
+      util_dl_get_proc_address(sdev->lib, "swrast_driver_descriptor");
+
+   if (!sdev->dd){
+      util_dl_close(sdev->lib);
+      sdev->lib = NULL;
+      return false;
+   }
+
    return true;
 }
 
+static void
+pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device *sdev)
+{
+   if (sdev->lib)
+      util_dl_close(sdev->lib);
+}
+
 #ifdef HAVE_PIPE_LOADER_DRI
 bool
 pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
 {
    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+   int i;
 
    if (!sdev)
       return false;
 
-   sdev->ws = dri_create_sw_winsys(drisw_lf);
-   if (!pipe_loader_sw_probe_init_common(sdev)) {
-      FREE(sdev);
-      return false;
+   if (!pipe_loader_sw_probe_init_common(sdev))
+      goto fail;
+
+   for (i = 0; sdev->dd->winsys; i++) {
+      if (strcmp(sdev->dd->winsys[i].name, "dri") == 0) {
+         sdev->ws = sdev->dd->winsys[i].create_winsys(drisw_lf);
+         break;
+      }
    }
-   *devs = &sdev->base;
+   if (!sdev->ws)
+      goto fail;
 
+   *devs = &sdev->base;
    return true;
+
+fail:
+   pipe_loader_sw_probe_teardown_common(sdev);
+   FREE(sdev);
+   return false;
 }
 #endif
 
@@ -84,18 +115,30 @@ bool
 pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
 {
    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+   int i;
 
    if (!sdev)
       return false;
 
-   sdev->ws = kms_dri_create_winsys(fd);
-   if (!pipe_loader_sw_probe_init_common(sdev)) {
-      FREE(sdev);
-      return false;
+   if (!pipe_loader_sw_probe_init_common(sdev))
+      goto fail;
+
+   for (i = 0; sdev->dd->winsys; i++) {
+      if (strcmp(sdev->dd->winsys[i].name, "kms_dri") == 0) {
+         sdev->ws = sdev->dd->winsys[i].create_winsys(fd);
+         break;
+      }
    }
-   *devs = &sdev->base;
+   if (!sdev->ws)
+      goto fail;
 
+   *devs = &sdev->base;
    return true;
+
+fail:
+   pipe_loader_sw_probe_teardown_common(sdev);
+   FREE(sdev);
+   return false;
 }
 #endif
 
@@ -103,18 +146,30 @@ bool
 pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
 {
    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+   int i;
 
    if (!sdev)
       return false;
 
-   sdev->ws = null_sw_create();
-   if (!pipe_loader_sw_probe_init_common(sdev)) {
-      FREE(sdev);
-      return false;
+   if (!pipe_loader_sw_probe_init_common(sdev))
+      goto fail;
+
+   for (i = 0; sdev->dd->winsys; i++) {
+      if (strcmp(sdev->dd->winsys[i].name, "null") == 0) {
+         sdev->ws = sdev->dd->winsys[i].create_winsys();
+         break;
+      }
    }
-   *devs = &sdev->base;
+   if (!sdev->ws)
+      goto fail;
 
+   *devs = &sdev->base;
    return true;
+
+fail:
+   pipe_loader_sw_probe_teardown_common(sdev);
+   FREE(sdev);
+   return false;
 }
 
 int
@@ -136,17 +191,30 @@ pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
                              struct pipe_screen *screen)
 {
    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+   int i;
 
    if (!sdev)
       return false;
 
-   sdev->ws = wrapper_sw_winsys_wrap_pipe_screen(screen);
-   if (!pipe_loader_sw_probe_init_common(sdev)) {
-      FREE(sdev);
-      return false;
+   if (!pipe_loader_sw_probe_init_common(sdev))
+      goto fail;
+
+   for (i = 0; sdev->dd->winsys; i++) {
+      if (strcmp(sdev->dd->winsys[i].name, "wrapped") == 0) {
+         sdev->ws = sdev->dd->winsys[i].create_winsys(screen);
+         break;
+      }
    }
+   if (!sdev->ws)
+      goto fail;
+
    *dev = &sdev->base;
    return true;
+
+fail:
+   pipe_loader_sw_probe_teardown_common(sdev);
+   FREE(sdev);
+   return false;
 }
 
 static void
@@ -172,21 +240,8 @@ static struct pipe_screen *
 pipe_loader_sw_create_screen(struct pipe_loader_device *dev)
 {
    struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
-   struct pipe_screen *(*init)(struct sw_winsys *);
-
-   if (!sdev->lib)
-      sdev->lib = pipe_loader_find_module(&sdev->base, PIPE_SEARCH_DIR);
-   if (!sdev->lib)
-      return NULL;
-
-   init = (void *)util_dl_get_proc_address(sdev->lib, "swrast_create_screen");
-   if (!init){
-      util_dl_close(sdev->lib);
-      sdev->lib = NULL;
-      return NULL;
-   }
 
-   return init(sdev->ws);
+   return sdev->dd->create_screen(sdev->ws);
 }
 
 static struct pipe_loader_ops pipe_loader_sw_ops = {
diff --git a/src/gallium/include/state_tracker/sw_driver.h b/src/gallium/include/state_tracker/sw_driver.h
new file mode 100644 (file)
index 0000000..0eb2b44
--- /dev/null
@@ -0,0 +1,21 @@
+
+#ifndef _SW_DRIVER_H_
+#define _SW_DRIVER_H_
+
+#include "pipe/p_compiler.h"
+
+struct pipe_screen;
+struct sw_winsys;
+
+struct sw_driver_descriptor
+{
+   struct pipe_screen *(*create_screen)(struct sw_winsys *ws);
+   struct {
+       const char * const name;
+       struct sw_winsys *(*create_winsys)();
+   } winsys[];
+};
+
+extern struct sw_driver_descriptor swrast_driver_descriptor;
+
+#endif
index bd6d620e8196edb3423bb46a9920bccebd3cabfc..d125ba8918d46711449443d3641d2d68c7bc02d0 100644 (file)
@@ -110,8 +110,7 @@ d3dadapter9_la_LIBADD += $(TARGET_LIB_DEPS) \
 else # HAVE_GALLIUM_STATIC_TARGETS
 
 d3dadapter9_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index 95efdd4451c559ea97a6131ca1b59c23783e9f73..038a12bfdfebc4df56c387e03dfa872be0b1aba0 100644 (file)
@@ -98,8 +98,7 @@ gallium_dri_la_LIBADD += $(TARGET_LIB_DEPS) \
 else # HAVE_GALLIUM_STATIC_TARGETS
 
 gallium_dri_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index a4dff487dd85d9d9d8f94df3d5e316f805a636b4..2454cbe424aa05d6c192cdc6c81a8c5fd534743a 100644 (file)
@@ -56,8 +56,7 @@ libomx_mesa_la_LIBADD += $(TARGET_LIB_DEPS) \
 else # HAVE_GALLIUM_STATIC_TARGETS
 
 libomx_mesa_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index c78b26832ff0bc2535e12cef1004e62d50193f4d..004d6d786dff552169feaa12ccc36f9b868382c9 100644 (file)
@@ -19,7 +19,6 @@ lib@OPENCL_LIBNAME@_la_LIBADD = \
        $(top_builddir)/src/gallium/state_trackers/clover/libclover.la \
        $(top_builddir)/src/gallium/auxiliary/libgallium.la \
        $(top_builddir)/src/util/libmesautil.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS) \
        $(ELF_LIB) \
        -ldl \
        -lclangCodeGen \
index 4f25b4f60737d9a3bca74838547f451bdcee080a..4bc3b55f26b22d0afaef0cb8c9df343d28d65c7f 100644 (file)
@@ -27,6 +27,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/include \
        -I$(top_srcdir)/src/gallium/drivers \
        -I$(top_srcdir)/src/gallium/winsys \
+       $(GALLIUM_PIPE_LOADER_DEFINES) \
        $(LIBDRM_CFLAGS) \
        $(VISIBILITY_CFLAGS) \
        -DGALLIUM_RBUG \
@@ -208,6 +209,10 @@ AM_CPPFLAGS += -DGALLIUM_LLVMPIPE
 pipe_swrast_la_LIBADD += \
        $(top_builddir)/src/gallium/drivers/llvmpipe/libllvmpipe.la
 endif
+
+pipe_swrast_la_LIBADD += \
+       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+
 endif
 
 EXTRA_DIST = pipe.sym
index 19b1d77b0405dcff280de2508e1418e839b3303b..b2fa619f7dee79848612bc4b4fd1b6a6240e1a0b 100644 (file)
@@ -1,7 +1,7 @@
 {
        global:
                driver_descriptor;
-               swrast_create_screen;
+               swrast_driver_descriptor;
        local:
                *;
 };
index f7f354acf3fe7dc36e755d96c08c85b4aca3c1c8..cf617f37e20f151275c386ef6675c221af62021c 100644 (file)
@@ -1,7 +1,11 @@
 
 #include "target-helpers/inline_sw_helper.h"
 #include "target-helpers/inline_debug_helper.h"
-#include "state_tracker/drm_driver.h"
+#include "state_tracker/sw_driver.h"
+#include "sw/dri/dri_sw_winsys.h"
+#include "sw/kms-dri/kms_dri_sw_winsys.h"
+#include "sw/null/null_sw_winsys.h"
+#include "sw/wrapper/wrapper_sw_winsys.h"
 
 PUBLIC struct pipe_screen *
 swrast_create_screen(struct sw_winsys *ws);
@@ -17,3 +21,31 @@ swrast_create_screen(struct sw_winsys *ws)
 
    return screen;
 }
+
+PUBLIC
+struct sw_driver_descriptor swrast_driver_descriptor = {
+   .create_screen = swrast_create_screen,
+   .winsys = {
+#ifdef HAVE_PIPE_LOADER_DRI
+      {
+         .name = "dri",
+         .create_winsys = dri_create_sw_winsys,
+      },
+#endif
+#ifdef HAVE_PIPE_LOADER_KMS
+      {
+         .name = "kms_dri",
+         .create_winsys = kms_dri_create_winsys,
+      },
+#endif
+      {
+         .name = "null",
+         .create_winsys = null_sw_create,
+      },
+      {
+         .name = "wrapped",
+         .create_winsys = wrapper_sw_winsys_wrap_pipe_screen,
+      },
+      { 0 },
+   }
+};
index 9613f041b5844c1c81d3eeb7631477eedabd0d70..2fd24a8bdd9927acbde14801dbe026721fb7ba7b 100644 (file)
@@ -53,8 +53,7 @@ gallium_drv_video_la_LIBADD += $(TARGET_LIB_DEPS) \
 else # HAVE_GALLIUM_STATIC_TARGETS
 
 gallium_drv_video_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index 7eb62c1cc7815b14d8a47e59284d738a0c78f644..34b7ef40b2032418aa27e609a9c8e64c6fc65995 100644 (file)
@@ -65,8 +65,7 @@ libvdpau_gallium_la_LIBADD += $(TARGET_LIB_DEPS) \
 else # HAVE_GALLIUM_STATIC_TARGETS
 
 libvdpau_gallium_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index 02c42c665edc320d69390ec5dcc348c125d27509..0fba3b2f3a1c209deee32b3586c0ee49834df60c 100644 (file)
@@ -79,8 +79,7 @@ libxatracker_la_LIBADD += $(TARGET_LIB_DEPS)
 else # HAVE_GALLIUM_STATIC_TARGETS
 
 libxatracker_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index b328589082234e171aa25896a27865f90da2240e..f1045d4f745fe82d644124725c2eef67d579b927 100644 (file)
@@ -53,8 +53,7 @@ libXvMCgallium_la_LIBADD += $(TARGET_LIB_DEPS) \
 
 else # HAVE_GALLIUM_STATIC_TARGETS
 libXvMCgallium_la_LIBADD += \
-       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS)
+       $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la
 
 endif # HAVE_GALLIUM_STATIC_TARGETS
 
index b30cb13eee60fed1d9ebfb9f4942a57a262ad83f..175bef2d3d4cddd098bcf5304a39fb7e8e8c5686 100644 (file)
@@ -9,7 +9,6 @@ LDADD = \
        $(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
        $(top_builddir)/src/gallium/auxiliary/libgallium.la \
        $(top_builddir)/src/util/libmesautil.la \
-       $(GALLIUM_PIPE_LOADER_WINSYS_LIBS) \
        $(GALLIUM_COMMON_LIB_DEPS)
 
 noinst_PROGRAMS = compute tri quad-tex