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 ac35819a6e5..cb8ec89e2b4 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/auxiliary/pipe-loader/meson.build b/src/gallium/auxiliary/pipe-loader/meson.build index 9b12432aea0..869a2935149 100644 --- a/src/gallium/auxiliary/pipe-loader/meson.build +++ b/src/gallium/auxiliary/pipe-loader/meson.build @@ -60,7 +60,8 @@ libpipe_loader_dynamic = static_library( ], c_args : [ c_vis_args, libpipe_loader_defines, '-DHAVE_PIPE_LOADER_DRI', - '-DPIPE_SEARCH_DIR="@0@"'.format(join_paths(get_option('libdir'), 'gallium-pipe') + '-DPIPE_SEARCH_DIR="@0@"'.format( + join_paths(get_option('prefix'), get_option('libdir'), 'gallium-pipe') ) ], link_with : [libloader, libxmlconfig], 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..d1497e657ea --- /dev/null +++ b/src/gallium/state_trackers/clover/meson.build @@ -0,0 +1,122 @@ +# Copyright © 2017-2018 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..6141d4374fe --- /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 + 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_@0@'.format(x[1]), + 'pipe_@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