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 env.MSVC2013Compat()
     21 
     22 env = env.Clone()
     23 
     24 # construct llvm include dir
     25 if env['platform'] == 'windows':
     26     # on windows there is no llvm-config, so LLVM is defined
     27     llvm_includedir = os.path.join(os.environ['LLVM'], 'include')
     28 else:
     29     llvm_config = os.environ.get('LLVM_CONFIG', 'llvm-config')
     30     llvm_includedir = env.backtick('%s --includedir' % llvm_config).rstrip()
     31     print("llvm include dir %s" % llvm_includedir)
     32 
     33 if not env['msvc'] :
     34     env.Append(CCFLAGS = [
     35         '-std=c++11',
     36     ])
     37 
     38 swrroot = '#src/gallium/drivers/swr/'
     39 bldroot = Dir('.').abspath
     40 
     41 env.CodeGenerate(
     42     target = 'rasterizer/codegen/gen_knobs.cpp',
     43     script = swrroot + 'rasterizer/codegen/gen_knobs.py',
     44     source = '',
     45     command = python_cmd + ' $SCRIPT --output $TARGET --gen_cpp'
     46 )
     47 Depends('rasterizer/codegen/gen_knobs.cpp',
     48         swrroot + 'rasterizer/codegen/templates/gen_knobs.cpp')
     49 
     50 env.CodeGenerate(
     51     target = 'rasterizer/codegen/gen_knobs.h',
     52     script = swrroot + 'rasterizer/codegen/gen_knobs.py',
     53     source = '',
     54     command = python_cmd + ' $SCRIPT --output $TARGET --gen_h'
     55 )
     56 Depends('rasterizer/codegen/gen_knobs.h',
     57         swrroot + 'rasterizer/codegen/templates/gen_knobs.h')
     58 
     59 env.CodeGenerate(
     60     target = 'rasterizer/jitter/gen_state_llvm.h',
     61     script = swrroot + 'rasterizer/codegen/gen_llvm_types.py',
     62     source = 'rasterizer/core/state.h',
     63     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
     64 )
     65 Depends('rasterizer/jitter/gen_state_llvm.h',
     66         swrroot + 'rasterizer/codegen/templates/gen_llvm.hpp')
     67 
     68 env.CodeGenerate(
     69     target = 'rasterizer/jitter/gen_builder.hpp',
     70     script = swrroot + 'rasterizer/codegen/gen_llvm_ir_macros.py',
     71     source = os.path.join(llvm_includedir, 'llvm/IR/IRBuilder.h'),
     72     command = python_cmd + ' $SCRIPT --input $SOURCE --output ' + bldroot + '/rasterizer/jitter --gen_h'
     73 )
     74 Depends('rasterizer/jitter/gen_builder.hpp',
     75         swrroot + 'rasterizer/codegen/templates/gen_builder.hpp')
     76 
     77 env.CodeGenerate(
     78     target = 'rasterizer/jitter/gen_builder_x86.hpp',
     79     script = swrroot + 'rasterizer/codegen/gen_llvm_ir_macros.py',
     80     source = '',
     81     command = python_cmd + ' $SCRIPT --output ' + bldroot + '/rasterizer/jitter --gen_x86_h'
     82 )
     83 Depends('rasterizer/jitter/gen_builder.hpp',
     84         swrroot + 'rasterizer/codegen/templates/gen_builder.hpp')
     85 
     86 env.CodeGenerate(
     87     target = './gen_swr_context_llvm.h',
     88     script = swrroot + 'rasterizer/codegen/gen_llvm_types.py',
     89     source = 'swr_context.h',
     90     command = python_cmd + ' $SCRIPT --input $SOURCE --output $TARGET'
     91 )
     92 Depends('rasterizer/jitter/gen_state_llvm.h',
     93         swrroot + 'rasterizer/codegen/templates/gen_llvm.hpp')
     94 
     95 env.CodeGenerate(
     96     target = 'rasterizer/archrast/gen_ar_event.hpp',
     97     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
     98     source = 'rasterizer/archrast/events.proto',
     99     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_h'
    100 )
    101 Depends('rasterizer/jitter/gen_state_llvm.h',
    102         swrroot + 'rasterizer/codegen/templates/gen_ar_event.hpp')
    103 
    104 env.CodeGenerate(
    105     target = 'rasterizer/archrast/gen_ar_event.cpp',
    106     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
    107     source = 'rasterizer/archrast/events.proto',
    108     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_event_cpp'
    109 )
    110 Depends('rasterizer/jitter/gen_state_llvm.h',
    111         swrroot + 'rasterizer/codegen/templates/gen_ar_event.cpp')
    112 
    113 env.CodeGenerate(
    114     target = 'rasterizer/archrast/gen_ar_eventhandler.hpp',
    115     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
    116     source = 'rasterizer/archrast/events.proto',
    117     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandler_h'
    118 )
    119 Depends('rasterizer/jitter/gen_state_llvm.h',
    120         swrroot + 'rasterizer/codegen/templates/gen_ar_eventhandler.hpp')
    121 
    122 env.CodeGenerate(
    123     target = 'rasterizer/archrast/gen_ar_eventhandlerfile.hpp',
    124     script = swrroot + 'rasterizer/codegen/gen_archrast.py',
    125     source = 'rasterizer/archrast/events.proto',
    126     command = python_cmd + ' $SCRIPT --proto $SOURCE --output $TARGET --gen_eventhandlerfile_h'
    127 )
    128 Depends('rasterizer/jitter/gen_state_llvm.h',
    129         swrroot + 'rasterizer/codegen/templates/gen_ar_eventhandlerfile.hpp')
    130 
    131 # 5 SWR_MULTISAMPLE_TYPE_COUNT
    132 # 2 SWR_MSAA_SAMPLE_PATTERN_COUNT
    133 # 3 SWR_INPUT_COVERAGE_COUNT
    134 # 2 centroid
    135 # 2 forcedSampleCount
    136 # 2 canEarlyZ
    137 backendPixelRateFileCount = 4
    138 backendPixelRateFilePat = "rasterizer/core/backends/gen_BackendPixelRate%s.cpp"
    139 backendPixelRateFiles = list(backendPixelRateFilePat % x for x in range(0, backendPixelRateFileCount))
    140 env.CodeGenerate(
    141     target = 'rasterizer/core/backends/gen_BackendPixelRate.hpp',
    142     script = swrroot + 'rasterizer/codegen/gen_backends.py',
    143     source = '',
    144     command = python_cmd + ' $SCRIPT --outdir ' + bldroot + '/rasterizer/core/backends --dim 5 2 3 2 2 2 --numfiles ' + str(backendPixelRateFileCount) + ' --cpp --hpp'
    145     )
    146 Depends(backendPixelRateFiles,
    147         ['rasterizer/core/backends/gen_BackendPixelRate.hpp',
    148          'rasterizer/archrast/gen_ar_event.hpp',
    149          'rasterizer/archrast/gen_ar_eventhandler.hpp',
    150          'rasterizer/codegen/gen_knobs.h']
    151         )
    152 
    153 # 5 SWR_MULTISAMPLE_TYPE_COUNT
    154 # 2 CenterPattern
    155 # 2 Conservative
    156 # 3 SWR_INPUT_COVERAGE_COUNT
    157 # 5 STATE_VALID_TRI_EDGE_COUNT
    158 # 2 RasterScissorEdges
    159 genRasterizerFileCount = 4
    160 genRasterizerFilePat = "rasterizer/core/backends/gen_rasterizer%s.cpp"
    161 genRasterizerFiles = list(genRasterizerFilePat % x for x in range(0, genRasterizerFileCount))
    162 env.CodeGenerate(
    163     target = 'rasterizer/core/backends/gen_rasterizer.hpp',
    164     script = swrroot + 'rasterizer/codegen/gen_backends.py',
    165     source = '',
    166     command = python_cmd + ' $SCRIPT --outdir ' + bldroot + '/rasterizer/core/backends --rast --dim 5 2 2 3 5 2 --numfiles ' + str(genRasterizerFileCount) + ' --cpp --hpp'
    167     )
    168 Depends(genRasterizerFiles,
    169         ['rasterizer/core/backends/gen_rasterizer.hpp',
    170          'rasterizer/archrast/gen_ar_event.hpp',
    171          'rasterizer/archrast/gen_ar_eventhandler.hpp',
    172          'rasterizer/codegen/gen_knobs.h']
    173         )
    174 
    175 Depends('rasterizer/jitter/gen_state_llvm.h',
    176         swrroot + 'rasterizer/codegen/templates/gen_backend.cpp')
    177 
    178 # Auto-generated .cpp files (that need to generate object files)
    179 built_sources = [
    180     'rasterizer/codegen/gen_knobs.cpp',
    181     'rasterizer/archrast/gen_ar_event.cpp',
    182     ]
    183 
    184 built_sources += [backendPixelRateFiles, genRasterizerFiles]
    185 
    186 source = built_sources
    187 source += env.ParseSourceList(swrroot + 'Makefile.sources', [
    188     'ARCHRAST_CXX_SOURCES',
    189     'COMMON_CXX_SOURCES',
    190     'CORE_CXX_SOURCES',
    191     'MEMORY_CXX_SOURCES'
    192 ])
    193 
    194 env.Prepend(CPPPATH = [
    195     '.',
    196     'rasterizer',
    197     'rasterizer/codegen',
    198     'rasterizer/core',
    199     'rasterizer/jitter',
    200     'rasterizer/archrast',
    201     ])
    202 
    203 # AVX lib
    204 envavx = env.Clone()
    205 
    206 envavx.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX'])
    207 if env['platform'] == 'windows':
    208     envavx.Append(CCFLAGS = ['/arch:AVX'])
    209 else:
    210     envavx.Append(CCFLAGS = ['-mavx'])
    211 
    212 swrAVX = envavx.SharedLibrary(
    213     target = 'swrAVX',
    214     source = source,
    215     OBJPREFIX = 'avx_'
    216     )
    217 env.Alias('swrAVX', swrAVX)
    218 
    219 # AVX2 lib
    220 envavx2 = env.Clone()
    221 
    222 envavx2.Append(CPPDEFINES = ['KNOB_ARCH=KNOB_ARCH_AVX2'])
    223 if env['platform'] == 'windows':
    224     envavx2.Append(CCFLAGS = ['/arch:AVX2'])
    225 else:
    226     envavx2.Append(CCFLAGS = ['-mavx2', '-mfma', '-mbmi2', '-mf16c'])
    227 
    228 swrAVX2 = envavx2.SharedLibrary(
    229     target = 'swrAVX2',
    230     source = source,
    231     OBJPREFIX = 'avx2_'
    232     )
    233 env.Alias('swrAVX2', swrAVX2)
    234 
    235 source = env.ParseSourceList(swrroot + 'Makefile.sources', [
    236     'CXX_SOURCES',
    237     'COMMON_CXX_SOURCES',
    238     'JITTER_CXX_SOURCES',
    239     'LOADER_SOURCES'
    240 ])
    241 source += [
    242     'rasterizer/codegen/gen_knobs.cpp',
    243     'rasterizer/archrast/gen_ar_event.cpp',
    244     ]
    245 
    246 # main SWR lib
    247 envSWR = envavx.Clone() # pick up the arch flag for intrinsic usage
    248 envSWR.Append(CPPDEFINES = ['HAVE_SWR_AVX', 'HAVE_SWR_AVX2'])
    249 swr = envSWR.ConvenienceLibrary(
    250     target = 'swr',
    251     source = source,
    252     )
    253 
    254 # treat arch libs as dependencies, even though they are not linked
    255 # into swr, so we don't have to build them separately
    256 Depends(swr, ['swrAVX', 'swrAVX2'])
    257 
    258 env.Alias('swr', swr)
    259 
    260 env.Prepend(LIBS = [swr])
    261 
    262 Export('swr')
    263