Home | History | Annotate | Download | only in swr
      1 Import('*')
      2 
      3 from sys import executable as python_cmd
      4 import os.path
      5 import distutils.version
      6 
      7 if not env['swr']:
      8     Return()
      9 
     10 if not env['llvm']:
     11     print 'warning: LLVM disabled: not building swr'
     12     env['swr'] = False
     13     Return()
     14 
     15 if env['LLVM_VERSION'] < distutils.version.LooseVersion('3.9'):
     16     print "warning: swr requires LLVM >= 3.9: not building swr"
     17     env['swr'] = False
     18     Return()
     19 
     20 if env['platform'] != 'windows':
     21     print "warning: swr scons build only supports windows: not building swr"
     22     env['swr'] = False
     23     Return()
     24 
     25 env.MSVC2013Compat()
     26 
     27 env = env.Clone()
     28 
     29 # construct llvm include dir
     30 if env['platform'] == 'windows':
     31     # on windows there is no llvm-config, so LLVM is defined
     32     llvm_includedir = os.path.join(os.environ['LLVM'], 'include')
     33 else:
     34     llvm_config = os.environ.get('LLVM_CONFIG', 'llvm-config')
     35     llvm_includedir = env.backtick('%s --includedir' % llvm_config).rstrip()
     36     print "llvm include dir %s" % llvm_includedir
     37 
     38 # the loader is included in the mesa lib itself
     39 # All the remaining files are in loadable modules
     40 loadersource = env.ParseSourceList('Makefile.sources', [
     41     'LOADER_SOURCES'
     42 ])
     43 
     44 env.Append(CPPDEFINES = [
     45     '__STDC_CONSTANT_MACROS',
     46     '__STDC_LIMIT_MACROS'
     47     ])
     48 
     49 if not env['msvc'] :
     50     env.Append(CCFLAGS = [
     51         '-std=c++11',
     52     ])
     53 
     54 swrroot = '#src/gallium/drivers/swr/'
     55 
     56 env.CodeGenerate(
     57     target = 'rasterizer/scripts/gen_knobs.cpp',
     58     script = swrroot + 'rasterizer/scripts/gen_knobs.py',
     59     source = 'rasterizer/scripts/templates/knobs.template',
     60     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp'
     61 )
     62 
     63 env.CodeGenerate(
     64     target = 'rasterizer/scripts/gen_knobs.h',
     65     script = swrroot + 'rasterizer/scripts/gen_knobs.py',
     66     source = 'rasterizer/scripts/templates/knobs.template',
     67     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h'
     68 )
     69 
     70 env.CodeGenerate(
     71     target = 'rasterizer/jitter/state_llvm.h',
     72     script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_types.py',
     73     source = 'rasterizer/core/state.h',
     74     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
     75 )
     76 
     77 env.CodeGenerate(
     78     target = 'rasterizer/jitter/builder_gen.h',
     79     script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
     80     source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
     81     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_h'
     82 )
     83 
     84 env.CodeGenerate(
     85     target = 'rasterizer/jitter/builder_gen.cpp',
     86     script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
     87     source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
     88     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET --gen_cpp'
     89 )
     90 
     91 env.CodeGenerate(
     92     target = 'rasterizer/jitter/builder_x86.h',
     93     script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
     94     source = '',
     95     command = python_cmd + ' $SCRIPT --output $TARGET --gen_x86_h'
     96 )
     97 
     98 env.CodeGenerate(
     99     target = 'rasterizer/jitter/builder_x86.cpp',
    100     script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_ir_macros.py',
    101     source = '',
    102     command = python_cmd + ' $SCRIPT --output $TARGET --gen_x86_cpp'
    103 )
    104 
    105 env.CodeGenerate(
    106     target = 'swr_context_llvm.h',
    107     script = swrroot + 'rasterizer/jitter/scripts/gen_llvm_types.py',
    108     source = 'swr_context.h',
    109     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
    110 )
    111 
    112 env.CodeGenerate(
    113     target = 'rasterizer/archrast/gen_ar_event.h',
    114     script = swrroot + 'rasterizer/scripts/gen_archrast.py',
    115     source = 'rasterizer/archrast/events.proto',
    116     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_h'
    117 )
    118 
    119 env.CodeGenerate(
    120     target = 'rasterizer/archrast/gen_ar_event.cpp',
    121     script = swrroot + 'rasterizer/scripts/gen_archrast.py',
    122     source = 'rasterizer/archrast/events.proto',
    123     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_cpp'
    124 )
    125 
    126 env.CodeGenerate(
    127     target = 'rasterizer/archrast/gen_ar_eventhandler.h',
    128     script = swrroot + 'rasterizer/scripts/gen_archrast.py',
    129     source = 'rasterizer/archrast/events.proto',
    130     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandler_h'
    131 )
    132 
    133 env.CodeGenerate(
    134     target = 'rasterizer/archrast/gen_ar_eventhandlerfile.h',
    135     script = swrroot + 'rasterizer/scripts/gen_archrast.py',
    136     source = 'rasterizer/archrast/events.proto',
    137     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandlerfile_h'
    138 )
    139 
    140 # Auto-generated .cpp files (that need to generate object files)
    141 built_sources = [
    142     'rasterizer/scripts/gen_knobs.cpp',
    143     'rasterizer/jitter/builder_gen.cpp',
    144     'rasterizer/jitter/builder_x86.cpp',
    145     'rasterizer/archrast/gen_ar_event.cpp',
    146     ]
    147 
    148 source = built_sources
    149 source += env.ParseSourceList(swrroot + 'Makefile.sources', [
    150     'CXX_SOURCES',
    151     'ARCHRAST_CXX_SOURCES',
    152     'COMMON_CXX_SOURCES',
    153     'CORE_CXX_SOURCES',
    154     'JITTER_CXX_SOURCES',
    155     'MEMORY_CXX_SOURCES'
    156 ])
    157 
    158 env.Prepend(LIBS = [ mesautil, mesa, gallium ])
    159 
    160 env.Prepend(CPPPATH = [
    161     '.',
    162     'rasterizer',
    163     'rasterizer/scripts',
    164     'rasterizer/core',
    165     'rasterizer/jitter',
    166     'rasterizer/archrast',
    167     ])
    168 
    169 # AVX lib
    170 envavx = env.Clone()
    171 
    172 envavx.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX'])
    173 if env['platform'] == 'windows':
    174     envavx.Append(CCFLAGS = ['/arch:AVX'])
    175 else:
    176     envavx.Append(CCFLAGS = ['-mavx'])
    177 
    178 swrAVX = envavx.SharedLibrary(
    179     target = 'swrAVX',
    180     source = source,
    181     OBJPREFIX = 'avx_'
    182     )
    183 env.Alias('swrAVX', swrAVX)
    184 
    185 # AVX2 lib
    186 envavx2 = env.Clone()
    187 
    188 envavx2.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX2'])
    189 if env['platform'] == 'windows':
    190     envavx2.Append(CCFLAGS = ['/arch:AVX2'])
    191 else:
    192     envavx2.Append(CCFLAGS = ['-mavx2'])
    193 
    194 swrAVX2 = envavx2.SharedLibrary(
    195     target = 'swrAVX2',
    196     source = source,
    197     OBJPREFIX = 'avx2_'
    198     )
    199 env.Alias('swrAVX2', swrAVX2)
    200 
    201 
    202 # main SWR lib
    203 swr = env.ConvenienceLibrary(
    204     target = 'swr',
    205     source = loadersource,
    206     )
    207 
    208 
    209 # treat arch libs as dependencies, even though they are not linked
    210 # into swr, so we don't have to build them separately
    211 Depends(swr, ['swrAVX', 'swrAVX2'])
    212 
    213 env.Alias('swr', swr)
    214 
    215 env.Prepend(LIBS = [swr])
    216 
    217 Export('swr')
    218