[Mesa-dev] [PATCH v4 09/10] gallium: swr: Added swr build for windows

George Kyriazis george.kyriazis at intel.com
Fri Nov 18 04:27:41 UTC 2016


Also, modify gen_knobs.py so that each invocation creates a single generated
file.  This is more similar to how the other generators behave.
---
 src/gallium/SConscript                             |   1 +
 src/gallium/drivers/swr/Makefile.am                |  15 +-
 src/gallium/drivers/swr/SConscript                 | 216 +++++++++++++++++++++
 .../drivers/swr/rasterizer/scripts/gen_knobs.py    |  51 ++---
 4 files changed, 257 insertions(+), 26 deletions(-)
 create mode 100644 src/gallium/drivers/swr/SConscript

diff --git a/src/gallium/SConscript b/src/gallium/SConscript
index f98268f..9273db7 100644
--- a/src/gallium/SConscript
+++ b/src/gallium/SConscript
@@ -18,6 +18,7 @@ SConscript([
     'drivers/softpipe/SConscript',
     'drivers/svga/SConscript',
     'drivers/trace/SConscript',
+    'drivers/swr/SConscript',
 ])
 
 #
diff --git a/src/gallium/drivers/swr/Makefile.am b/src/gallium/drivers/swr/Makefile.am
index dd1c2e6..b22ded0 100644
--- a/src/gallium/drivers/swr/Makefile.am
+++ b/src/gallium/drivers/swr/Makefile.am
@@ -71,11 +71,21 @@ swr_context_llvm.h: rasterizer/jitter/scripts/gen_llvm_types.py swr_context.h
 		--input $(srcdir)/swr_context.h \
 		--output swr_context_llvm.h
 
-rasterizer/scripts/gen_knobs.cpp rasterizer/scripts/gen_knobs.h: rasterizer/scripts/gen_knobs.py rasterizer/scripts/knob_defs.py rasterizer/scripts/templates/knobs.template
+rasterizer/scripts/gen_knobs.cpp: rasterizer/scripts/gen_knobs.py rasterizer/scripts/knob_defs.py rasterizer/scripts/templates/knobs.template
 	$(MKDIR_GEN)
 	$(PYTHON_GEN) \
 		$(srcdir)/rasterizer/scripts/gen_knobs.py \
-		rasterizer/scripts
+		--input $(srcdir)/rasterizer/scripts/templates/knobs.template \
+		--output rasterizer/scripts/gen_knobs.cpp \
+		--gen_cpp
+
+rasterizer/scripts/gen_knobs.h: rasterizer/scripts/gen_knobs.py rasterizer/scripts/knob_defs.py rasterizer/scripts/templates/knobs.template
+	$(MKDIR_GEN)
+	$(PYTHON_GEN) \
+		$(srcdir)/rasterizer/scripts/gen_knobs.py \
+		--input $(srcdir)/rasterizer/scripts/templates/knobs.template \
+		--output rasterizer/scripts/gen_knobs.h \
+		--gen_h
 
 rasterizer/jitter/state_llvm.h: rasterizer/jitter/scripts/gen_llvm_types.py rasterizer/core/state.h
 	$(MKDIR_GEN)
@@ -235,6 +245,7 @@ libswrAVX2_la_LDFLAGS = \
 include $(top_srcdir)/install-gallium-links.mk
 
 EXTRA_DIST = \
+	SConscript \
 	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..0de51a7
--- /dev/null
+++ b/src/gallium/drivers/swr/SConscript
@@ -0,0 +1,216 @@
+Import('*')
+
+from sys import executable as python_cmd
+import os.path
+import distutils.version
+
+if not env['swr']:
+    Return()
+
+if not env['llvm']:
+    print 'warning: LLVM disabled: not building swr'
+    env['swr'] = False
+    Return()
+
+if env['LLVM_VERSION'] < distutils.version.LooseVersion('3.9'):
+    print "warning: swr requires LLVM >= 3.9: not building swr"
+    env['swr'] = False
+    Return()
+
+if env['platform'] != 'windows':
+    print "warning: swr scons build only supports windows: not building swr"
+    env['swr'] = False
+    Return()
+
+env.MSVC2013Compat()
+
+env = env.Clone()
+
+# construct llvm include dir
+if env['platform'] == 'windows':
+    # on windows there is no llvm-config, so LLVM is defined
+    llvm_includedir = os.path.join(os.environ['LLVM'], 'include')
+else:
+    llvm_includedir = env.backtick('llvm-config --includedir').rstrip()
+    print "llvm include dir %s" % llvm_includedir
+
+# the loader is included in the mesa lib itself
+# All the remaining files are in loadable modules
+loadersource = env.ParseSourceList('Makefile.sources', [
+    'LOADER_SOURCES'
+])
+
+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 = 'rasterizer/scripts/templates/knobs.template',
+    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp'
+)
+
+env.CodeGenerate(
+    target = 'rasterizer/scripts/gen_knobs.h',
+    script = swrroot + 'rasterizer/scripts/gen_knobs.py',
+    source = 'rasterizer/scripts/templates/knobs.template',
+    command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h'
+)
+
+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'
+)
+
+# Auto-generated .cpp files (that need to generate object files)
+built_sources = [
+    'rasterizer/scripts/gen_knobs.cpp',
+    'rasterizer/jitter/builder_gen.cpp',
+    'rasterizer/jitter/builder_x86.cpp',
+    'rasterizer/archrast/gen_ar_event.cpp',
+    ]
+
+source = built_sources
+source += env.ParseSourceList(swrroot + 'Makefile.sources', [
+    'CXX_SOURCES',
+    'ARCHRAST_CXX_SOURCES',
+    'COMMON_CXX_SOURCES',
+    'CORE_CXX_SOURCES',
+    'JITTER_CXX_SOURCES',
+    'MEMORY_CXX_SOURCES'
+])
+
+env.Prepend(LIBS = [ mesautil, mesa, gallium ])
+
+env.Prepend(CPPPATH = [
+    '.',
+    'rasterizer',
+    'rasterizer/scripts',
+    'rasterizer/core',
+    'rasterizer/jitter',
+    'rasterizer/archrast',
+    ])
+
+# AVX lib
+envavx = env.Clone()
+
+envavx.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX'])
+if env['platform'] == 'windows':
+    envavx.Append(CCFLAGS = ['/arch:AVX'])
+else:
+    envavx.Append(CCFLAGS = ['-mavx'])
+
+swrAVX = envavx.SharedLibrary(
+    target = 'swrAVX',
+    source = source,
+    OBJPREFIX = 'avx_'
+    )
+env.Alias('swrAVX', swrAVX)
+
+# AVX2 lib
+envavx2 = env.Clone()
+
+envavx2.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX2'])
+if env['platform'] == 'windows':
+    envavx2.Append(CCFLAGS = ['/arch:AVX2'])
+else:
+    envavx2.Append(CCFLAGS = ['-mavx2'])
+
+swrAVX2 = envavx2.SharedLibrary(
+    target = 'swrAVX2',
+    source = source,
+    OBJPREFIX = 'avx2_'
+    )
+env.Alias('swrAVX2', swrAVX2)
+
+
+# main SWR lib
+swr = env.ConvenienceLibrary(
+    target = 'swr',
+    source = loadersource,
+    )
+
+
+# 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/rasterizer/scripts/gen_knobs.py b/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py
index 3d003fb..225082e 100644
--- a/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py
+++ b/src/gallium/drivers/swr/rasterizer/scripts/gen_knobs.py
@@ -23,13 +23,14 @@
 from __future__ import print_function
 import os
 import sys
+import argparse
 import knob_defs
 from mako.template import Template
 from mako.exceptions import RichTraceback
 
 def write_template_to_string(template_filename, **kwargs):
     try:
-        template = Template(filename=template_filename)
+        template = Template(filename=os.path.abspath(template_filename))
         # Split + Join fixes line-endings for whatever platform you are using
         return '\n'.join(template.render(**kwargs).splitlines())
     except:
@@ -40,37 +41,39 @@ def write_template_to_string(template_filename, **kwargs):
         print("%s: %s" % (str(traceback.error.__class__.__name__), traceback.error))
 
 def write_template_to_file(template_filename, output_filename, **kwargs):
+    output_dirname = os.path.dirname(output_filename)
+    if not os.path.exists(output_dirname):
+        os.makedirs(output_dirname)
     with open(output_filename, "w") as outfile:
         print(write_template_to_string(template_filename, **kwargs), file=outfile)
 
 def main(args=sys.argv[1:]):
-    if len(args) != 1:
-        print('Usage:', sys.argv[0], '<output_directory>', file=sys.stderr)
-        return 1
 
-    output_dir = args[0]
-    if not os.path.isdir(output_dir):
-        if os.path.exists(output_dir):
-            print('ERROR: Invalid output directory:', output_dir, file=sys.stderr)
-            return 1
+    # parse args
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--input", "-i", help="Path to knobs.template", required=True)
+    parser.add_argument("--output", "-o", help="Path to output file", required=True)
+    parser.add_argument("--gen_h", "-gen_h", help="Generate gen_knobs.h", action="store_true", default=False)
+    parser.add_argument("--gen_cpp", "-gen_cpp", help="Generate gen_knobs.cpp", action="store_true", required=False)
 
-        try:
-            os.makedirs(output_dir)
-        except:
-            print('ERROR: Could not create output directory:', output_dir, file=sys.stderr)
-            return 1
+    args = parser.parse_args()
 
-    # Output path exists, now just run the template
-    template_file = os.sep.join([sys.path[0], 'templates', 'knobs.template'])
-    output_file = os.sep.join([output_dir, 'gen_knobs.cpp'])
-    output_header = os.sep.join([output_dir, 'gen_knobs.h'])
+    if args.input:
+        if args.gen_h:
+            write_template_to_file(args.input,
+                                   args.output,
+                                   filename='gen_knobs',
+                                   knobs=knob_defs.KNOBS,
+                                   includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],
+                                   gen_header=True)
 
-    for f in [output_header, output_file]:
-        write_template_to_file(template_file, f,
-                filename='gen_knobs',
-                knobs=knob_defs.KNOBS,
-                includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],
-                gen_header=True if f == output_header else False)
+        if args.gen_cpp:
+            write_template_to_file(args.input,
+                                   args.output,
+                                   filename='gen_knobs',
+                                   knobs=knob_defs.KNOBS,
+                                   includes=['core/knobs_init.h', 'common/os.h', 'sstream', 'iomanip'],
+                                   gen_header=False)
 
     return 0
 
-- 
2.10.0.windows.1



More information about the mesa-dev mailing list