[Mesa-dev] [PATCH v2 3/4] meson: build clover

Francisco Jerez currojerez at riseup.net
Wed Dec 13 21:01:29 UTC 2017


Jan Vesely <jan.vesely at rutgers.edu> writes:

> On Wed, 2017-12-13 at 09:47 -0800, Dylan Baker wrote:
>> This has only been compile tested.
>> 
>> v2: - Have a single option for opencl (Eric E)
>>     - fix typo "tgis" -> "tgsi" (Curro)
>>     - Don't add "lib" prefix to pipe loader libraries, which matches the
>>       autotools behavior
>> 
>> cc: Curro Jerez <currojerez at riseup.net>
>> cc: Jan Vesely <jan.vesely at rutgers.edu>
>> cc: Aaron Watry <awatry at gmail.com>
>> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
>> ---
>> 
>> Jan and Aaron (or whoever decides to test this):
>> 
>> I think this should address the issues raised so far, so maybe this is
>> better for testing?
>> 
>>  include/meson.build                           |  19 ++++
>>  meson.build                                   |  29 +++++-
>>  meson_options.txt                             |   7 ++
>>  src/gallium/meson.build                       |  12 ++-
>>  src/gallium/state_trackers/clover/meson.build | 122 ++++++++++++++++++++++++++
>>  src/gallium/targets/opencl/meson.build        |  73 +++++++++++++++
>>  src/gallium/targets/pipe-loader/meson.build   |  77 ++++++++++++++++
>>  7 files changed, 334 insertions(+), 5 deletions(-)
>>  create mode 100644 src/gallium/state_trackers/clover/meson.build
>>  create mode 100644 src/gallium/targets/opencl/meson.build
>>  create mode 100644 src/gallium/targets/pipe-loader/meson.build
>> 
>> diff --git a/include/meson.build b/include/meson.build
>> index e4dae91cede..a2e7ce6580e 100644
>> --- a/include/meson.build
>> +++ b/include/meson.build
>> @@ -78,3 +78,22 @@ if with_gallium_st_nine
>>      subdir : 'd3dadapter',
>>    )
>>  endif
>> +
>> +# Only install the headers if we are building a stand alone implementation and
>> +# not an ICD enabled implementation
>> +if with_gallium_opencl and not with_opencl_icd
>> +  install_headers(
>> +    'CL/cl.h',
>> +    'CL/cl.hpp',
>> +    'CL/cl_d3d10.h',
>> +    'CL/cl_d3d11.h',
>> +    'CL/cl_dx9_media_sharing.h',
>> +    'CL/cl_egl.h',
>> +    'CL/cl_ext.h',
>> +    'CL/cl_gl.h',
>> +    'CL/cl_gl_ext.h',
>> +    'CL/cl_platform.h',
>> +    'CL/opencl.h',
>> +    subdir: 'CL'
>> +  )
>> +endif
>> diff --git a/meson.build b/meson.build
>> index 842d441199e..74b2d5c49dc 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -583,6 +583,22 @@ if with_gallium_st_nine
>>    endif
>>  endif
>>  
>> +_opencl = get_option('gallium-opencl')
>> +if _opencl !=' disabled'
>> +  if not with_gallium
>> +    error('OpenCL Clover implementation requires at least one gallium driver.')
>> +  endif
>> +
>> +  # TODO: alitvec?
>> +  dep_clc = dependency('libclc')
>> +  with_gallium_opencl = true
>> +  with_opencl_icd = _opencl == 'icd'
>> +else
>> +  dep_clc = []
>> +  with_gallium_opencl = false
>> +  with_gallium_icd = false
>> +endif
>> +
>>  gl_pkgconfig_c_flags = []
>>  if with_platform_x11
>>    if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
>> @@ -930,7 +946,7 @@ dep_thread = dependency('threads')
>>  if dep_thread.found() and host_machine.system() != 'windows'
>>    pre_args += '-DHAVE_PTHREAD'
>>  endif
>> -if with_amd_vk or with_gallium_radeonsi or with_gallium_r600 # TODO: clover
>> +if with_amd_vk or with_gallium_radeonsi or with_gallium_r600 or with_gallium_opencl
>>    dep_elf = dependency('libelf', required : false)
>>    if not dep_elf.found()
>>      dep_elf = cc.find_library('elf')
>> @@ -972,12 +988,19 @@ if with_amd_vk or with_gallium_radeonsi or with_gallium_r600
>>      llvm_modules += 'asmparser'
>>    endif
>>  endif
>> +if with_gallium_opencl
>> +  llvm_modules += [
>> +    'all-targets', 'linker', 'coverage', 'instrumentation', 'ipo', 'irreader',
>> +    'lto', 'option', 'objcarcopts', 'profiledata',
>> +  ]
>> +  # TODO: optional modules
>> +endif
>>  
>>  _llvm = get_option('llvm')
>>  if _llvm == 'auto'
>>    dep_llvm = dependency(
>>      'llvm', version : '>= 3.9.0', modules : llvm_modules,
>> -    required : with_amd_vk or with_gallium_radeonsi or with_gallium_swr,
>> +    required : with_amd_vk or with_gallium_radeonsi or with_gallium_swr or with_gallium_opencl,
>>    )
>>    with_llvm = dep_llvm.found()
>>  elif _llvm == 'true'
>> @@ -1154,8 +1177,6 @@ else
>>    dep_lmsensors = []
>>  endif
>>  
>> -# TODO: clover
>> -
>>  # TODO: gallium tests
>>  
>>  # TODO: various libdirs
>> diff --git a/meson_options.txt b/meson_options.txt
>> index 4f4db5b7d26..894378985fd 100644
>> --- a/meson_options.txt
>> +++ b/meson_options.txt
>> @@ -120,6 +120,13 @@ option(
>>    value : false,
>>    description : 'build gallium "nine" Direct3D 9.x state tracker.',
>>  )
>> +option(
>> +  'gallium-opencl',
>> +  type : 'combo',
>> +  choices : ['icd', 'standalone', 'disabled'],
>> +  value : 'disabled',
>> +  description : 'build gallium "clover" OpenCL state tracker.',
>> +)
>>  option(
>>    'd3d-drivers-path',
>>    type : 'string',
>> diff --git a/src/gallium/meson.build b/src/gallium/meson.build
>> index fc21dcf03e1..6330c7514af 100644
>> --- a/src/gallium/meson.build
>> +++ b/src/gallium/meson.build
>> @@ -145,7 +145,17 @@ endif
>>  if with_gallium_st_nine
>>    subdir('state_trackers/nine')
>>  endif
>> -# TODO: clover
>> +if with_gallium_opencl
>> +  # TODO: this isn't really clover specific, but ATM clover is the only
>> +  # consumer
>> +  subdir('targets/pipe-loader')
>> +
>> +  if meson.version().version_compare('< 0.44.0')
>> +    error('OpenCL requires meson 0.44.0 or greater.')
>> +  endif
>> +  subdir('state_trackers/clover')
>> +  subdir('targets/opencl')
>> +endif
>>  if with_dri
>>    subdir('state_trackers/dri')
>>    subdir('targets/dri')
>> diff --git a/src/gallium/state_trackers/clover/meson.build b/src/gallium/state_trackers/clover/meson.build
>> new file mode 100644
>> index 00000000000..accc090d31f
>> --- /dev/null
>> +++ b/src/gallium/state_trackers/clover/meson.build
>> @@ -0,0 +1,122 @@
>> +# Copyright © 2017 Intel Corporation
>> +
>> +# Permission is hereby granted, free of charge, to any person obtaining a copy
>> +# of this software and associated documentation files (the "Software"), to deal
>> +# in the Software without restriction, including without limitation the rights
>> +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> +# copies of the Software, and to permit persons to whom the Software is
>> +# furnished to do so, subject to the following conditions:
>> +
>> +# The above copyright notice and this permission notice shall be included in
>> +# all copies or substantial portions of the Software.
>> +
>> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
>> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
>> +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
>> +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> +# SOFTWARE.
>> +
>> +clover_cpp_args = []
>> +clover_incs = [inc_include, inc_src, inc_gallium, inc_gallium_aux]
>> +
>> +if with_opencl_icd
>> +  clover_cpp_args += '-DHAVE_CLOVER_ICD'
>> +endif
>> +
>> +libcltgsi = static_library(
>> +  'cltgsi',
>> +  files('tgsi/compiler.cpp', 'tgsi/invocation.hpp'),
>> +  include_directories : clover_incs,
>> +  cpp_args : [cpp_vis_args],
>> +)
>> +
>> +libclllvm = static_library(
>> +  'clllvm',
>> +  files(
>> +    'llvm/codegen/bitcode.cpp',
>> +    'llvm/codegen/common.cpp',
>> +    'llvm/codegen/native.cpp',
>> +    'llvm/codegen.hpp',
>> +    'llvm/compat.hpp',
>> +    'llvm/invocation.cpp',
>> +    'llvm/invocation.hpp',
>> +    'llvm/metadata.hpp',
>> +    'llvm/util.hpp',
>> +  ),
>> +  include_directories : clover_incs,
>> +  cpp_args : [
>> +    cpp_vis_args,
>> +    '-DLIBCLC_INCLUDEDIR="@0@"'.format(dep_clc.get_pkgconfig_variable('includedir')),
>> +    '-DLIBCLC_LIBEXECDIR="@0@"'.format(dep_clc.get_pkgconfig_variable('libexecdir')),
>> +    '-DCLANG_RESOURCE_DIR="@0@"'.format(join_paths(
>> +      dep_llvm.get_configtool_variable('libdir'), 'clang',
>> +      dep_llvm.get_configtool_variable('version'), 'include',
>> +    )),
>> +  ],
>> +  dependencies : [dep_llvm, dep_elf],
>> +)
>> +
>> +clover_files = files(
>> +  'api/context.cpp',
>> +  'api/device.cpp',
>> +  'api/dispatch.cpp',
>> +  'api/dispatch.hpp',
>> +  'api/event.cpp',
>> +  'api/interop.cpp',
>> +  'api/kernel.cpp',
>> +  'api/memory.cpp',
>> +  'api/platform.cpp',
>> +  'api/program.cpp',
>> +  'api/queue.cpp',
>> +  'api/sampler.cpp',
>> +  'api/transfer.cpp',
>> +  'api/util.hpp',
>> +  'core/context.cpp',
>> +  'core/context.hpp',
>> +  'core/device.cpp',
>> +  'core/device.hpp',
>> +  'core/error.hpp',
>> +  'core/event.cpp',
>> +  'core/event.hpp',
>> +  'core/format.cpp',
>> +  'core/format.hpp',
>> +  'core/kernel.cpp',
>> +  'core/kernel.hpp',
>> +  'core/memory.cpp',
>> +  'core/memory.hpp',
>> +  'core/module.cpp',
>> +  'core/module.hpp',
>> +  'core/object.hpp',
>> +  'core/platform.cpp',
>> +  'core/platform.hpp',
>> +  'core/program.cpp',
>> +  'core/program.hpp',
>> +  'core/property.hpp',
>> +  'core/queue.cpp',
>> +  'core/queue.hpp',
>> +  'core/resource.cpp',
>> +  'core/resource.hpp',
>> +  'core/sampler.cpp',
>> +  'core/sampler.hpp',
>> +  'core/timestamp.cpp',
>> +  'core/timestamp.hpp',
>> +  'util/adaptor.hpp',
>> +  'util/algebra.hpp',
>> +  'util/algorithm.hpp',
>> +  'util/factor.hpp',
>> +  'util/functional.hpp',
>> +  'util/lazy.hpp',
>> +  'util/pointer.hpp',
>> +  'util/range.hpp',
>> +  'util/tuple.hpp',
>> +)
>> +
>> +libclover = static_library(
>> +  'clover',
>> +  clover_files,
>> +  include_directories : clover_incs,
>> +  cpp_args : [clover_cpp_args, cpp_vis_args],
>> +  link_with : [libcltgsi, libclllvm],
>> +)
>> diff --git a/src/gallium/targets/opencl/meson.build b/src/gallium/targets/opencl/meson.build
>> new file mode 100644
>> index 00000000000..bebe0547d45
>> --- /dev/null
>> +++ b/src/gallium/targets/opencl/meson.build
>> @@ -0,0 +1,73 @@
>> +# Copyright © 2017 Intel Corporation
>> +
>> +# Permission is hereby granted, free of charge, to any person obtaining a copy
>> +# of this software and associated documentation files (the "Software"), to deal
>> +# in the Software without restriction, including without limitation the rights
>> +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> +# copies of the Software, and to permit persons to whom the Software is
>> +# furnished to do so, subject to the following conditions:
>> +
>> +# The above copyright notice and this permission notice shall be included in
>> +# all copies or substantial portions of the Software.
>> +
>> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
>> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
>> +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
>> +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> +# SOFTWARE.
>> +
>> +opencl_link_args = []
>> +opencl_link_deps = []
>> +opencl_version = '1.0'
>> +
>> +if with_ld_version_script
>> +  opencl_link_args += [
>> +    '-Wl,--version-script', join_paths(meson.current_source_dir(), 'opencl.sym')
>> +  ]
>> +  opencl_link_deps += files('opencl.sym')
>> +endif
>> +
>> +llvm_libdir = dep_llvm.get_configtool_variable('libdir')
>> +
>> +opencl_libname = with_opencl_icd ? 'MesaOpenCL' : 'OpenCL'
>> +
>> +libopencl = shared_library(
>> +  opencl_libname,
>> +  [],
>> +  link_args : [ld_args_gc_sections, opencl_link_args],
>> +  link_depends : opencl_link_deps,
>> +  link_whole : libclover,
>> +  link_with : [libpipe_loader_dynamic, libgallium, libmesa_util],
>> +  dependencies : [
>> +    dep_thread, dep_clock, dep_dl, dep_unwind, dep_elf, dep_expat,
>> +    cpp.find_library('clangCodeGen', dirs : llvm_libdir),
>> +    cpp.find_library('clangFrontendTool', dirs : llvm_libdir),
>> +    cpp.find_library('clangFrontend', dirs : llvm_libdir),
>> +    cpp.find_library('clangDriver', dirs : llvm_libdir),
>> +    cpp.find_library('clangSerialization', dirs : llvm_libdir),
>> +    cpp.find_library('clangParse', dirs : llvm_libdir),
>> +    cpp.find_library('clangSema', dirs : llvm_libdir),
>> +    cpp.find_library('clangAnalysis', dirs : llvm_libdir),
>> +    cpp.find_library('clangAST', dirs : llvm_libdir),
>> +    cpp.find_library('clangEdit', dirs : llvm_libdir),
>> +    cpp.find_library('clangLex', dirs : llvm_libdir),
>> +    cpp.find_library('clangBasic', dirs : llvm_libdir),
>> +  ],
>> +  version : opencl_version,
>> +  install : true,
>> +)
>> +
>> +if with_opencl_icd
>> +  _config = configuration_data()
>> +  _config.set('OPENCL_LIBNAME', 'MesaOpenCL')
>> +  _config.set('OPENCL_VERSION', opencl_version)
>> +  configure_file(
>> +    configuration : _config,
>> +    input : 'mesa.icd.in',
>> +    output : 'mesa.icd',
>> +    install : true,
>> +    install_dir : join_paths(get_option('sysconfdir'), 'OpenCL', 'vendors'),
>> +  )
>> +endif
>> diff --git a/src/gallium/targets/pipe-loader/meson.build b/src/gallium/targets/pipe-loader/meson.build
>> new file mode 100644
>> index 00000000000..fe7e8ab2e67
>> --- /dev/null
>> +++ b/src/gallium/targets/pipe-loader/meson.build
>> @@ -0,0 +1,77 @@
>> +# Copyright © 2017 Intel Corporation
>> +
>> +# Permission is hereby granted, free of charge, to any person obtaining a copy
>> +# of this software and associated documentation files (the "Software"), to deal
>> +# in the Software without restriction, including without limitation the rights
>> +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> +# copies of the Software, and to permit persons to whom the Software is
>> +# furnished to do so, subject to the following conditions:
>> +
>> +# The above copyright notice and this permission notice shall be included in
>> +# all copies or substantial portions of the Software.
>> +
>> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
>> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
>> +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
>> +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> +# SOFTWARE.
>> +
>> +pipe_loader_link_args = [ld_args_gc_sections]
>> +pipe_loader_link_deps = []
>> +pipe_loader_link_with = [libgallium, libnir, libmesa_util, librbug, libtrace]
>> +pipe_loader_comp_args = ['-DGALLIUM_RBUG', '-DGALLIUM_TRACE']
>> +pipe_loader_incs = [
>> +  inc_include, inc_src, inc_util, inc_gallium, inc_gallium_drivers,
>> +  inc_gallium_winsys, inc_gallium_aux,
>> +]
>> +
>> +if (with_gallium_va or with_gallium_vdpau or with_gallium_omx or
>> +    with_gallium_xvmc or with_dri)
>> +  pipe_loader_link_with += libgalliumvl
>> +else
>> +  pipe_loader_link_with += libgalliumvl_stubs
>> +endif
>> +if with_gallium_va or with_gallium_vdpau or with_gallium_omx or with_gallium_xvmc  
>
> git am complains about whitespace errors at the end of the above line.
>
> I tested with:
> meson -Ddri-drivers= -Dgallium-drivers=r600 -Dopengl=true -Dplatforms=x11 -Dopencl=true
>

Thanks!

> meson asked for libdrm_amdgpu dependency even though I'm only building clover+r600g driver.
> after a bit of fiddling with PATH and PK_CONFIG_PATH to pick up the latest llvm/liblclc
> linking failed with:
> src/gallium/auxiliary/libgallium.a(gallivm_lp_bld_misc.cpp.o):(.data.rel.ro._ZTI26DelegatingJITMemoryManager[_ZTI26DelegatingJITMemoryManager]+0x10): undefined reference to `typeinfo for llvm::RTDyldMemoryManager'
> collect2: error: ld returned 1 exit status
>
> this looks like it did not pick up the rtti setting from llvm-config:
> $ ~/.local/bin/llvm-config --has-rtti
> NO
> $ ~/.local/bin/llvm-config --cxxflags | grep -o fno-rtti
> fno-rtti
>
> rtti setting is quite messy since clover uses dynamic_cast. I think it
> should be OK to only support rtti build of llvm if it's detected at
> configure time

Is that any different with autotools?  Clover is not meant to link
against an -fno-rtti LLVM, because an LLVM library built in such a way
has a non-standard C++ ABI.  Picking up the -fno-rtti flag from
llvm-config is not guaranteed to fix anything.  Attempting to do so
should probably lead to a build error at configure time...

>
> it'd also be nice for meson to remember llvm-config location provided
> at configure time. otherwise I need to set PATH every time I run ninja
> in case it tries to reconfigure. I guess that's what "TODO llvm-prefix" 
> will achieve, right?
>
> in the end I got meson built clover to run (clinfo + simple demo) on my
> turks with these changes:
> * build and install libdrm_amdgpu -- should not be necessary for r600g
> only build
> * switch to distro (fedora) provided libclc and llvm -- avoids rtti
> build problem (note libclc is just tagging along llvm since my local
> builds install headers to the same location)
> * fiddle with pipe-loader dir, for some reason LIBGL_DRIVERS_PATH did
> not work when pointed to meson built pipe_r600.so. I'm not sure if this
> is meson specific, it might be just my ignorance.
>
>
> I haven't tested building the ICD version.
>
> Jan
>
>
>> +  pipe_loader_link_with += libgalliumvlwinsys
>> +endif
>> +
>> +if with_ld_version_script
>> +  pipe_loader_link_args += [
>> +    '-Wl,--version-script', join_paths(meson.current_source_dir(), 'pipe.sym')
>> +  ]
>> +  pipe_loader_link_deps += files('pipe.sym')
>> +endif
>> +
>> +pipe_loader_install_dir = join_paths(get_option('libdir'), 'gallium-pipe')
>> +
>> +pipe_loaders = [
>> +  [with_gallium_i915, 'i915', driver_i915, []],
>> +  [with_gallium_nouveau, 'nouveau', driver_nouveau, []],
>> +  [with_gallium_r300, 'r300', driver_r300, []],
>> +  [with_gallium_r600, 'r600', driver_r600, []],
>> +  [with_gallium_radeonsi, 'radeonsi', driver_radeonsi, [libxmlconfig]],
>> +  [with_gallium_freedreno, 'msm', driver_freedreno, []],
>> +  [with_gallium_svga, 'vmwgfx', driver_svga, []],
>> +  [with_gallium_softpipe, 'swrast', [driver_swrast, driver_swr], [libwsw, libws_null]],
>> +]
>> +
>> +foreach x : pipe_loaders
>> +  if x[0]
>> +    shared_library(
>> +      'pipe_ at 0@'.format(x[1]),
>> +      'pipe_ at 0@.c'.format(x[1]),
>> +      c_args : [pipe_loader_comp_args, c_vis_args],
>> +      cpp_args : [pipe_loader_comp_args, cpp_vis_args],
>> +      link_args : pipe_loader_link_args,
>> +      link_depends : pipe_loader_link_deps,
>> +      include_directories : pipe_loader_incs,
>> +      link_with : [pipe_loader_link_with, x[3]],
>> +      dependencies : [dep_thread, x[2]],
>> +      name_prefix : '',
>> +      install : true,
>> +      install_dir : pipe_loader_install_dir,
>> +    )
>> +  endif
>> +endforeach
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 227 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171213/9a7819fe/attachment-0001.sig>


More information about the mesa-dev mailing list