1# Copyright © Microsoft Corporation 2# SPDX-License-Identifier: MIT 3 4files_libmesaclc = files( 5 'clc.c', 6 'clc_helpers.cpp', 7 'nir_load_libclc.c', 8) 9 10_libmesaclc_c_args = [] 11_libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="@0@"'.format(llvm_libdir)] 12_libmesaclc_sources = [] 13 14if not _shared_llvm 15 # LLVM 16 moved clang header path from using full version to only major version 16 if dep_llvm.version().version_compare('< 16') 17 # Prior to LLVM 16, this path used a full version 18 clang_version_dir = dep_llvm.version() 19 else 20 # LLVM 16 changed to only using a major version 21 clang_version_dir = dep_llvm.version().split('.')[0] 22 endif 23 clang_resource_dir = join_paths(llvm_libdir, 'clang', clang_version_dir, 'include') 24 25 opencl_c_base_h = custom_target( 26 'opencl-c-base.h', 27 input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c-base.h')], 28 output : 'opencl-c-base.h.h', 29 command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_base_source'], 30 ) 31 32 opencl_c_h = custom_target( 33 'opencl-c.h', 34 input : [files_xxd, join_paths(clang_resource_dir, 'opencl-c.h')], 35 output : 'opencl-c.h.h', 36 command : [prog_python, '@INPUT@', '@OUTPUT@', '-n', 'opencl_c_source'], 37 ) 38 39 _libmesaclc_sources += [opencl_c_base_h, opencl_c_h] 40 _libmesaclc_cpp_args += ['-DUSE_STATIC_OPENCL_C_H=1'] 41endif 42 43_basedir = dep_clc.get_variable(pkgconfig : 'libexecdir') 44 45_static_libclc = get_option('static-libclc') 46if _static_libclc.length() > 0 47 if _static_libclc.contains('all') 48 _static_libclc = ['spirv', 'spirv64'] 49 endif 50 prog_zstd = find_program('zstd', required : false, native : true) 51 _zstd_static_libclc = dep_zstd.found() and prog_zstd.found() 52 if _zstd_static_libclc 53 _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_ZSTD' 54 endif 55 foreach s : _static_libclc 56 _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_@0@'.format(s.to_upper()) 57 f = '@0@-mesa3d-.spv'.format(s) 58 _libclc_file = _basedir / f 59 if _zstd_static_libclc 60 _libclc_file = custom_target( 61 '@0@.zstd'.format(f), 62 command : [prog_zstd, '-f', '@INPUT@', '-o', '@OUTPUT@'], 63 input : [_libclc_file], 64 output : '@0@.zstd'.format(f), 65 ) 66 endif 67 files_libmesaclc += custom_target( 68 '@0@.h'.format(f), 69 command : [ 70 prog_python, files_xxd, '-b', '@INPUT@', '@OUTPUT@', 71 '-n', 'libclc_@0@_mesa3d_spv'.format(s), 72 ], 73 input : [_libclc_file], 74 output : '@0@.h'.format(f), 75 depend_files : files_xxd, 76 ) 77 endforeach 78else 79 _libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)] 80 if not cc.has_function('mmap') 81 error('mmap required for dynamic libCLC loading') 82 endif 83endif 84 85has_spirv_link_workaround = cpp.has_member( 86 'spvtools::LinkerOptions', 87 'SetAllowPtrTypeMismatch(true)', 88 prefix : [ 89 '#include <spirv-tools/linker.hpp>', 90 ], 91 dependencies : dep_spirv_tools, 92) 93if dep_llvm.version().version_compare('>= 17.0') and not has_spirv_link_workaround 94 error('SPIRV-Tools doesn\'t contain https://github.com/KhronosGroup/SPIRV-Tools/pull/5534\n') 95endif 96 97if has_spirv_link_workaround 98 _libmesaclc_c_args += ['-DHAS_SPIRV_LINK_LLVM_WORKAROUND=1'] 99endif 100 101_libmesaclc = static_library( 102 'libmesaclc', 103 files_libmesaclc, 104 sources: _libmesaclc_sources, 105 include_directories : [inc_include, inc_src, inc_spirv], 106 c_args : _libmesaclc_c_args, 107 cpp_args : [_libmesaclc_cpp_args, _libmesaclc_c_args], 108 dependencies: [idep_nir, dep_clang, dep_llvm, dep_llvmspirvlib, 109 idep_mesautil, dep_spirv_tools, idep_vtn, dep_version] 110) 111 112_idep_mesaclc_link_args = [] 113if _shared_llvm 114 _idep_mesaclc_link_args += cc.get_supported_link_arguments('-fPIC') 115endif 116 117idep_mesaclc = declare_dependency( 118 link_with : _libmesaclc, 119 include_directories : include_directories('.'), 120 link_args : _idep_mesaclc_link_args, 121) 122 123if get_option('mesa-clc') != 'system' and (with_gallium_asahi or \ 124 with_asahi_vk or \ 125 with_intel_vk or \ 126 with_gallium_iris or \ 127 get_option('install-mesa-clc')) 128 prog_mesa_clc = executable( 129 'mesa_clc', 130 ['mesa_clc.c'], 131 include_directories : [inc_include, inc_src], 132 c_args : [pre_args, no_override_init_args], 133 link_args : [ld_args_build_id], 134 dependencies : [idep_mesaclc, dep_llvm, dep_spirv_tools, idep_getopt], 135 # If we can run host binaries directly, just build mesa_clc for the host. 136 # Most commonly this happens when doing a cross compile from an x86_64 build 137 # machine to an x86 host 138 native : not meson.can_run_host_binaries(), 139 install : get_option('install-mesa-clc'), 140 ) 141endif 142