configure/swr: configurable swr architectures
authorTim Rowley <timothy.o.rowley@intel.com>
Fri, 7 Jul 2017 18:38:22 +0000 (13:38 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Wed, 19 Jul 2017 20:12:07 +0000 (15:12 -0500)
Allow configuration of the SWR architecture depend libraries
we build for with --with-swr-archs.  Maintains current behavior
by defaulting to avx,avx2.

Scons changes made to make it still build and work, but
without the changes for configuring which architectures.

v2:
 * add missing comma for swr_archs default
 * check that at least one architecture is enabled
 * modify loader logic to make it clearer how to add archs

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
configure.ac
src/gallium/drivers/swr/Makefile.am
src/gallium/drivers/swr/SConscript
src/gallium/drivers/swr/swr_loader.cpp

index 7ee777bc4601010be77b5c5b62acf094295b18af..cfc53de608ea5b18aceee2723c8cba0775017182 100644 (file)
@@ -2352,6 +2352,15 @@ AC_ARG_WITH([d3d-libdir],
     [D3D_DRIVER_INSTALL_DIR="${libdir}/d3d"])
 AC_SUBST([D3D_DRIVER_INSTALL_DIR])
 
+dnl Architectures to build SWR library for
+
+AC_ARG_WITH([swr-archs],
+    [AS_HELP_STRING([--with-swr-archs@<:@=DIRS...@:>@],
+        [comma delimited swr architectures list, e.g.
+        "avx,avx2" @<:@default="avx,avx2"@:>@])],
+    [with_swr_archs="$withval"],
+    [with_swr_archs="avx,avx2"])
+
 dnl
 dnl r300 doesn't strictly require LLVM, but for performance reasons we
 dnl highly recommend LLVM usage. So require it at least on x86 and x86_64
@@ -2499,10 +2508,29 @@ if test -n "$with_gallium_drivers"; then
                 SWR_AVX_CXXFLAGS
             AC_SUBST([SWR_AVX_CXXFLAGS])
 
-            swr_require_cxx_feature_flags "AVX2" "defined(__AVX2__)" \
-                ",-mavx2 -mfma -mbmi2 -mf16c,-march=core-avx2" \
-                SWR_AVX2_CXXFLAGS
-            AC_SUBST([SWR_AVX2_CXXFLAGS])
+            swr_archs=`IFS=', '; echo $with_swr_archs`
+            for arch in $swr_archs; do
+                case "x$arch" in
+                xavx)
+                    HAVE_SWR_AVX=yes
+                    ;;
+                xavx2)
+                    swr_require_cxx_feature_flags "AVX2" "defined(__AVX2__)" \
+                        ",-mavx2 -mfma -mbmi2 -mf16c,-march=core-avx2" \
+                        SWR_AVX2_CXXFLAGS
+                    AC_SUBST([SWR_AVX2_CXXFLAGS])
+                    HAVE_SWR_AVX2=yes
+                    ;;
+                *)
+                    AC_MSG_ERROR([unknown SWR build architecture '$arch'])
+                    ;;
+                esac
+            done
+
+            if test "x$HAVE_SWR_AVX" != xyes -a \
+                    "x$HAVE_SWR_AVX2" != xyes; then
+               AC_MSG_ERROR([swr enabled but no swr architectures selected])
+            fi
 
             HAVE_GALLIUM_SWR=yes
             ;;
@@ -2541,6 +2569,9 @@ if test "x$enable_llvm" = "xyes" -a "$with_gallium_drivers"; then
     llvm_add_default_components "gallium"
 fi
 
+AM_CONDITIONAL(HAVE_SWR_AVX, test "x$HAVE_SWR_AVX" = xyes)
+AM_CONDITIONAL(HAVE_SWR_AVX2, test "x$HAVE_SWR_AVX2" = xyes)
+
 dnl We need to validate some needed dependencies for renderonly drivers.
 
 if test "x$HAVE_GALLIUM_ETNAVIV" != xyes -a "x$HAVE_GALLIUM_IMX" = xyes  ; then
@@ -2980,6 +3011,11 @@ else
     echo "        HUD lmsensors:   yes"
 fi
 
+echo ""
+if test "x$HAVE_GALLIUM_SWR" != x; then
+    echo "        SWR archs:       $swr_archs"
+fi
+
 dnl Libraries
 echo ""
 echo "        Shared libs:     $enable_shared"
index 74612280fe73729e67d86ab923810109f48fb063..f38ce7b1d97d279436472008fc3483b280fd9aad 100644 (file)
@@ -55,6 +55,14 @@ libmesaswr_la_CXXFLAGS = \
        $(SWR_AVX_CXXFLAGS) \
        $(COMMON_CXXFLAGS)
 
+if HAVE_SWR_AVX
+libmesaswr_la_CXXFLAGS += -DHAVE_SWR_AVX
+endif
+
+if HAVE_SWR_AVX2
+libmesaswr_la_CXXFLAGS += -DHAVE_SWR_AVX2
+endif
+
 COMMON_SOURCES = \
        $(ARCHRAST_CXX_SOURCES) \
        $(COMMON_CXX_SOURCES) \
@@ -224,7 +232,10 @@ COMMON_LDFLAGS = \
        $(GC_SECTIONS) \
        $(NO_UNDEFINED)
 
-lib_LTLIBRARIES = libswrAVX.la libswrAVX2.la
+lib_LTLIBRARIES =
+
+if HAVE_SWR_AVX
+lib_LTLIBRARIES += libswrAVX.la
 
 libswrAVX_la_CXXFLAGS = \
        $(SWR_AVX_CXXFLAGS) \
@@ -236,7 +247,10 @@ libswrAVX_la_SOURCES = \
 
 libswrAVX_la_LDFLAGS = \
        $(COMMON_LDFLAGS)
+endif
 
+if HAVE_SWR_AVX2
+lib_LTLIBRARIES += libswrAVX2.la
 libswrAVX2_la_CXXFLAGS = \
        $(SWR_AVX2_CXXFLAGS) \
        -DKNOB_ARCH=KNOB_ARCH_AVX2 \
@@ -247,6 +261,7 @@ libswrAVX2_la_SOURCES = \
 
 libswrAVX2_la_LDFLAGS = \
        $(COMMON_LDFLAGS)
+endif
 
 include $(top_srcdir)/install-gallium-links.mk
 
index cdfb91a5bba42d15f3a70fb2739d77ed11599c44..a32807d36bd4bbbbe5de6ce030835e88df59d427 100644 (file)
@@ -245,6 +245,7 @@ source += [
 
 # main SWR lib
 envSWR = envavx.Clone() # pick up the arch flag for intrinsic usage
+envSWR.Append(CPPDEFINES = ['HAVE_SWR_AVX', 'HAVE_SWR_AVX2'])
 swr = envSWR.ConvenienceLibrary(
     target = 'swr',
     source = source,
index d56fb0e59fb0d86b71482c1423719e807ec56b80..4aa850a6b8d61513f78ae46f1e2611211f6959ac 100644 (file)
 struct pipe_screen *
 swr_create_screen(struct sw_winsys *winsys)
 {
-   char filename[256];
+   char filename[256] = { 0 };
    fprintf(stderr, "SWR detected ");
 
    util_dl_library *pLibrary = nullptr;
 
    util_cpu_detect();
-   if (util_cpu_caps.has_avx2) {
-      fprintf(stderr, "AVX2\n");
+
+   if (!strlen(filename) && util_cpu_caps.has_avx2) {
+#if HAVE_SWR_AVX2
+      fprintf(stderr, "AVX2 ");
       sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX2", UTIL_DL_EXT);
-   } else if (util_cpu_caps.has_avx) {
-      fprintf(stderr, "AVX\n");
+#else
+      fprintf(stderr, "AVX2 (not built) ");
+#endif
+   }
+
+   if (!strlen(filename) && util_cpu_caps.has_avx) {
+#if HAVE_SWR_AVX
+      fprintf(stderr, "AVX ");
       sprintf(filename, "%s%s%s", UTIL_DL_PREFIX, "swrAVX", UTIL_DL_EXT);
-   } else {
-      fprintf(stderr, "no AVX/AVX2 support.  Aborting!\n");
+#else
+      fprintf(stderr, "AVX (not built) ");
+#endif
+   }
+
+   if (!strlen(filename)) {
+      fprintf(stderr, "- no appropriate swr architecture library.  Aborting!\n");
       exit(-1);
+   } else {
+      fprintf(stderr, "\n");
    }
+
    pLibrary = util_dl_open(filename);
 
    if (!pLibrary) {