[Mesa-dev] [PATCH 3/3] swr: Support windows builds

George Kyriazis george.kyriazis at intel.com
Mon Nov 7 22:32:07 UTC 2016


- Added SConscript files
- better handling of NOMINMAX for <windows.h> inclusion
- Reorder header files in swr_context.cpp to handle NOMINMAX better, since
  mesa header files include windows.h before we get a chance to #define
  NOMINMAX
- cleaner support for .dll and .so prefix/suffix across OSes
- added PUBLIC for some protos
- added swr_gdi_swap() which is call from libgl_gdi.c
---
 src/gallium/drivers/swr/Makefile.am            |   8 ++
 src/gallium/drivers/swr/SConscript             |  46 +++++++
 src/gallium/drivers/swr/SConscript-arch        | 175 +++++++++++++++++++++++++
 src/gallium/drivers/swr/rasterizer/common/os.h |   5 +-
 src/gallium/drivers/swr/swr_context.cpp        |  16 +--
 src/gallium/drivers/swr/swr_context.h          |   2 +
 src/gallium/drivers/swr/swr_loader.cpp         |  37 +++++-
 src/gallium/drivers/swr/swr_public.h           |  11 +-
 src/gallium/drivers/swr/swr_screen.cpp         |  25 +---
 9 files changed, 291 insertions(+), 34 deletions(-)
 create mode 100644 src/gallium/drivers/swr/SConscript
 create mode 100644 src/gallium/drivers/swr/SConscript-arch

diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am
index dd1c2e6..0ec4af2
--- a/src/gallium/drivers/swr/Makefile.am
+++ b/src/gallium/drivers/swr/Makefile.am
@@ -217,6 +217,12 @@ libswrAVX2_la_CXXFLAGS = \
 libswrAVX2_la_SOURCES = \
 	$(COMMON_SOURCES)
 
+# XXX: $(SWR_AVX_CXXFLAGS) should not be included, but we end up including
+# simdintrin.h, which throws a warning if AVX is not enabled
+libmesaswr_la_CXXFLAGS = \
+	$(COMMON_CXXFLAGS) \
+	$(SWR_AVX_CXXFLAGS)
+
 # XXX: Don't ship these generated sources for now, since they are specific
 # to the LLVM version they are generated from. Thus a release tarball
 # containing the said files, generated against eg. LLVM 3.8 will fail to build
@@ -235,6 +241,8 @@ libswrAVX2_la_LDFLAGS = \
 include $(top_srcdir)/install-gallium-links.mk
 
 EXTRA_DIST = \
+	SConscipt \
+	SConscript-arch \
 	rasterizer/archrast/events.proto \
 	rasterizer/jitter/scripts/gen_llvm_ir_macros.py \
 	rasterizer/jitter/scripts/gen_llvm_types.py \
diff --git a/src/gallium/drivers/swr/SConscript b/src/gallium/drivers/swr/SConscript
new file mode 100644
index 0000000..c470bbd
--- /dev/null
+++ b/src/gallium/drivers/swr/SConscript
@@ -0,0 +1,46 @@
+Import('*')
+
+from sys import executable as python_cmd
+import distutils.version
+import os.path
+
+if not 'swr' in COMMAND_LINE_TARGETS:
+    Return()
+
+if not env['llvm']:
+    print 'warning: LLVM disabled: not building swr'
+    Return()
+
+env.MSVC2013Compat()
+
+swr_arch = 'avx'
+VariantDir('avx', '.', duplicate=0)
+SConscript('avx/SConscript-arch', exports='swr_arch')
+
+swr_arch = 'avx2'
+VariantDir('avx2', '.', duplicate=0)
+SConscript('avx2/SConscript-arch', exports='swr_arch')
+
+env = env.Clone()
+
+source = env.ParseSourceList('Makefile.sources', [
+    'LOADER_SOURCES'
+])
+
+env.Prepend(CPPPATH = [
+    'rasterizer/scripts'
+    ])
+
+swr = env.ConvenienceLibrary(
+	target = 'swr',
+	source = source,
+	)
+# treat arch libs as dependencies, even though they are not linked
+# into swr, so we don't have to build them separately
+Depends(swr, ['swrAVX', 'swrAVX2'])
+
+env.Alias('swr', swr)
+
+env.Prepend(LIBS = [swr])
+
+Export('swr')
diff --git a/src/gallium/drivers/swr/SConscript-arch b/src/gallium/drivers/swr/SConscript-arch
new file mode 100644
index 0000000..f7d5b5a
--- /dev/null
+++ b/src/gallium/drivers/swr/SConscript-arch
@@ -0,0 +1,175 @@
+Import('*')
+
+from sys import executable as python_cmd
+import distutils.version
+import os.path
+
+if not env['llvm']:
+    print 'warning: LLVM disabled: not building swr'
+    Return()
+
+Import('swr_arch')
+
+# construct llvm include dir
+llvm_includedir = os.path.join(os.environ['LLVM'], 'include')
+
+# get path for arch-specific build-path.
+# That's where generated files reside.
+build_path = Dir('.').abspath
+
+env.Prepend(CPPPATH = [
+    build_path + '/.',
+    build_path + '/rasterizer',
+    build_path + '/rasterizer/core',
+    build_path + '/rasterizer/jitter',
+    build_path + '/rasterizer/scripts',
+    build_path + '/rasterizer/archrast'
+    ])
+
+env = env.Clone()
+
+env.MSVC2013Compat()
+
+env.Append(CPPDEFINES = [
+	'__STDC_CONSTANT_MACROS',
+	'__STDC_LIMIT_MACROS'
+	])
+
+if not env['msvc'] :
+    env.Append(CCFLAGS = [
+        '-std=c++11',
+    ])
+
+swrroot = '#src/gallium/drivers/swr/'
+
+env.CodeGenerate(
+    target = 'rasterizer/scripts/gen_knobs.cpp',
+    script = swrroot + 'rasterizer/scripts/gen_knobs.py',
+    source = [],
+    command = python_cmd + ' $SCRIPT ' + Dir('rasterizer/scripts').abspath
+    #command = python_cmd + ' $SCRIPT ' + 'rasterizer/scripts'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/scripts/gen_knobs.h',
+    script = swrroot + 'rasterizer/scripts/gen_knobs.py',
+    source = [],
+    command = python_cmd + ' $SCRIPT ' + Dir('rasterizer/scripts').abspath
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/jitter/state_llvm.h',
+    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_types.py',
+    source = 'rasterizer/core/state.h',
+    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/jitter/builder_gen.h',
+    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
+    source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
+    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/jitter/builder_gen.cpp',
+    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
+    source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
+    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/jitter/builder_x86.h',
+    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
+    source = '',
+    command = python_cmd + ' $SCRIPT --output $TARGET --gen_x86_h'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/jitter/builder_x86.cpp',
+    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
+    source = '',
+    command = python_cmd + ' $SCRIPT --output $TARGET --gen_x86_cpp'
+)
+
+env.CodeGenerate(
+    target = 'swr_context_llvm.h',
+    script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_types.py',
+    source = 'swr_context.h',
+    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/archrast/gen_ar_event.h',
+    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
+    source = 'rasterizer/archrast/events.proto',
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_h'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/archrast/gen_ar.event.cpp',
+    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
+    source = 'rasterizer/archrast/events.proto',
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen-event_cpp'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/archrast/gen_ar_eventhandler.h',
+    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
+    source = 'rasterizer/archrast/events.proto',
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandler_h'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/archrast/gen_ar_eventhandlerfile.h',
+    script = swrroot + 'rasterizer/scripts/gen_archrast.py',
+    source = 'rasterizer/archrast/events.proto',
+    command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandlerfile_h'
+)
+
+source = [
+       'rasterizer/scripts/gen_knobs.cpp', 'rasterizer/scripts/gen_knobs.h',
+       'rasterizer/jitter/builder_gen.cpp', 'rasterizer/jitter/builder_gen.h',
+       'rasterizer/jitter/builder_x86.cpp', 'rasterizer/jitter/builder_x86.h',
+       ]
+
+source += env.ParseSourceList(swrroot + 'Makefile.sources', [
+    'CXX_SOURCES',
+    'ARCHRAST_CXX_SOURCES',
+    'COMMON_CXX_SOURCES',
+    'CORE_CXX_SOURCES',
+    'JITTER_CXX_SOURCES',
+    'MEMORY_CXX_SOURCES'
+])
+
+# remove headers, as scons thinks they are static objects for the .so
+source = [x for x in source if not x.endswith(tuple(['.h','.hpp']))]
+
+env.Prepend(LIBS = [ mesautil, mesa, gallium ])
+
+if swr_arch == 'avx':
+    env.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX'])
+    if env['platform'] == 'windows':
+        env.Append(CCFLAGS = ['/arch:AVX'])
+    else:
+        env.Append(CCFLAGS = ['-mavx'])
+
+    swrAVX = env.SharedLibrary(
+        target = 'swrAVX',
+        source = source
+    )
+    env.Alias('swrAVX', swrAVX)
+    Export('swrAVX')
+elif swr_arch == 'avx2':
+    env.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX2'])
+    if env['platform'] == 'windows':
+        env.Append(CCFLAGS = ['/arch:AVX2'])
+    else:
+        env.Append(CCFLAGS = ['-mavx2', '-mfma', '-mbmi2', '-mf16c'])
+
+    swrAVX2 = env.LoadableModule(target = 'swrAVX2',	source = source)
+    env.Alias('swrAVX2', swrAVX2)
+    Export('swrAVX2')
+else:
+    print "unknown swr architecture"
+    exit(1)
diff --git a/src/gallium/drivers/swr/rasterizer/common/os.h b/src/gallium/drivers/swr/rasterizer/common/os.h
index ac52b60..28e7ff5 100644
--- a/src/gallium/drivers/swr/rasterizer/common/os.h
+++ b/src/gallium/drivers/swr/rasterizer/common/os.h
@@ -33,8 +33,11 @@
 
 #ifndef NOMINMAX
 #define NOMINMAX
-#endif
 #include <windows.h>
+#undef NOMINMAX
+#else
+#include <windows.h>
+#endif
 #include <intrin.h>
 #include <cstdint>
 
diff --git a/src/gallium/drivers/swr/swr_context.cpp b/src/gallium/drivers/swr/swr_context.cpp
index cbc60e0..27273e0 100644
--- a/src/gallium/drivers/swr/swr_context.cpp
+++ b/src/gallium/drivers/swr/swr_context.cpp
@@ -21,6 +21,14 @@
  * IN THE SOFTWARE.
  ***************************************************************************/
 
+#include "swr_context.h"
+#include "swr_memory.h"
+#include "swr_screen.h"
+#include "swr_resource.h"
+#include "swr_scratch.h"
+#include "swr_query.h"
+#include "swr_fence.h"
+
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
 #include "util/u_format.h"
@@ -31,14 +39,6 @@ extern "C" {
 #include "util/u_surface.h"
 }
 
-#include "swr_context.h"
-#include "swr_memory.h"
-#include "swr_screen.h"
-#include "swr_resource.h"
-#include "swr_scratch.h"
-#include "swr_query.h"
-#include "swr_fence.h"
-
 #include "api.h"
 #include "backend.h"
 
diff --git a/src/gallium/drivers/swr/swr_context.h b/src/gallium/drivers/swr/swr_context.h
index eecfe0d..04e11fe 100644
--- a/src/gallium/drivers/swr/swr_context.h
+++ b/src/gallium/drivers/swr/swr_context.h
@@ -24,6 +24,8 @@
 #ifndef SWR_CONTEXT_H
 #define SWR_CONTEXT_H
 
+#include "common/os.h"
+
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "util/u_blitter.h"
diff --git a/src/gallium/drivers/swr/swr_loader.cpp b/src/gallium/drivers/swr/swr_loader.cpp
index 2113c37..24970b0 100644
--- a/src/gallium/drivers/swr/swr_loader.cpp
+++ b/src/gallium/drivers/swr/swr_loader.cpp
@@ -25,29 +25,42 @@
 #include "util/u_dl.h"
 #include "swr_public.h"
 
+#include "swr_screen.h"
+#include "swr_resource.h"
+
 #include <stdio.h>
-#include <dlfcn.h>
 
 typedef pipe_screen *(*screen_create_proc)(struct sw_winsys *winsys);
 
 struct pipe_screen *
 swr_create_screen(struct sw_winsys *winsys)
 {
+   char filename[256];
+   const char *prefix, *postfix;
    fprintf(stderr, "SWR detected ");
 
    util_dl_library *pLibrary = nullptr;
 
+#ifdef _WIN32
+   prefix = "";
+   postfix = ".dll";
+#else
+   prefix = "lib";
+   postfix = ".so";
+#endif
+
    util_cpu_detect();
    if (util_cpu_caps.has_avx2) {
       fprintf(stderr, "AVX2\n");
-      pLibrary = util_dl_open("libswrAVX2.so");
+      sprintf(filename, "%s%s%s", prefix, "swrAVX2", postfix);
    } else if (util_cpu_caps.has_avx) {
       fprintf(stderr, "AVX\n");
-      pLibrary = util_dl_open("libswrAVX.so");
+      sprintf(filename, "%s%s%s", prefix, "swrAVX", postfix);
    } else {
       fprintf(stderr, "no AVX/AVX2 support.  Aborting!\n");
       exit(-1);
    }
+   pLibrary = util_dl_open(filename);
 
    if (!pLibrary) {
       fprintf(stderr, "SWR library load failure: %s\n", util_dl_error());
@@ -65,3 +78,21 @@ swr_create_screen(struct sw_winsys *winsys)
 
    return pScreenCreate(winsys);
 }
+
+
+#ifdef _WIN32
+// swap function called from libl_gdi.c
+
+void
+swr_gdi_swap(struct pipe_screen *screen,
+             struct pipe_resource *res,
+             void *hDC)
+{
+   screen->flush_frontbuffer(screen,
+                             res,
+                             0, 0,
+                             hDC,
+                             NULL);
+}
+
+#endif /* _WIN32 */
diff --git a/src/gallium/drivers/swr/swr_public.h b/src/gallium/drivers/swr/swr_public.h
index 0814c3b..fede820 100644
--- a/src/gallium/drivers/swr/swr_public.h
+++ b/src/gallium/drivers/swr/swr_public.h
@@ -32,12 +32,15 @@ struct sw_displaytarget;
 extern "C" {
 #endif
 
-struct pipe_screen *swr_create_screen(struct sw_winsys *winsys);
+PUBLIC struct pipe_screen *swr_create_screen(struct sw_winsys *winsys);
 
-struct sw_winsys *swr_get_winsys(struct pipe_screen *pipe);
-
-struct sw_displaytarget *swr_get_displaytarget(struct pipe_resource *resource);
+#ifdef _WIN32
+void
+swr_gdi_swap(struct pipe_screen *screen,
+             struct pipe_resource *res,
+             void *hDC);
 
+#endif /* _WIN32 */
 
 #ifdef __cplusplus
 }
diff --git a/src/gallium/drivers/swr/swr_screen.cpp b/src/gallium/drivers/swr/swr_screen.cpp
index 704a684..b66618a 100644
--- a/src/gallium/drivers/swr/swr_screen.cpp
+++ b/src/gallium/drivers/swr/swr_screen.cpp
@@ -21,6 +21,13 @@
  * IN THE SOFTWARE.
  ***************************************************************************/
 
+#include "swr_context.h"
+#include "swr_public.h"
+#include "swr_screen.h"
+#include "swr_resource.h"
+#include "swr_fence.h"
+#include "gen_knobs.h"
+
 #include "pipe/p_screen.h"
 #include "pipe/p_defines.h"
 #include "util/u_memory.h"
@@ -35,13 +42,6 @@ extern "C" {
 #include "gallivm/lp_bld_limits.h"
 }
 
-#include "swr_public.h"
-#include "swr_screen.h"
-#include "swr_context.h"
-#include "swr_resource.h"
-#include "swr_fence.h"
-#include "gen_knobs.h"
-
 #include "jit_api.h"
 
 #include <stdio.h>
@@ -1021,14 +1021,3 @@ swr_create_screen(struct sw_winsys *winsys)
    return &screen->base;
 }
 
-struct sw_winsys *
-swr_get_winsys(struct pipe_screen *pipe)
-{
-   return ((struct swr_screen *)pipe)->winsys;
-}
-
-struct sw_displaytarget *
-swr_get_displaytarget(struct pipe_resource *resource)
-{
-   return ((struct swr_resource *)resource)->display_target;
-}
-- 
2.10.0.windows.1



More information about the mesa-dev mailing list