diff --git a/meson.build b/meson.build index 5238d6f0640..14660219a79 100644 --- a/meson.build +++ b/meson.build @@ -278,7 +278,6 @@ else with_intel_vk_rt = false endif with_clc = with_microsoft_clc or with_intel_clc -with_libclc = with_clc with_spirv_to_dxil = get_option('spirv-to-dxil') if host_machine.system() == 'darwin' @@ -751,7 +750,7 @@ if _opencl != 'disabled' error('The Clover OpenCL state tracker requires rtti') endif - with_libclc = true + with_clc = true with_gallium_opencl = true with_opencl_icd = _opencl == 'icd' else @@ -772,11 +771,10 @@ if with_gallium_rusticl add_languages('rust', required: true) with_clc = true - with_libclc = true endif dep_clc = null_dep -if with_libclc +if with_clc dep_clc = dependency('libclc') endif diff --git a/src/compiler/clc/clc.c b/src/compiler/clc/clc.c index efb06de1a0e..29d207d7d56 100644 --- a/src/compiler/clc/clc.c +++ b/src/compiler/clc/clc.c @@ -27,6 +27,7 @@ #include "nir_types.h" #include "clc.h" #include "clc_helpers.h" +#include "nir_clc_helpers.h" #include "spirv/nir_spirv.h" #include "util/u_debug.h" diff --git a/src/compiler/clc/meson.build b/src/compiler/clc/meson.build index ec5176522e4..e7ca051079f 100644 --- a/src/compiler/clc/meson.build +++ b/src/compiler/clc/meson.build @@ -23,8 +23,11 @@ files_libmesaclc = files( 'clc.c', 'clc_helpers.cpp', + 'nir_load_libclc.c', + 'nir_lower_libclc.c', ) +_libmesaclc_c_args = [] _libmesaclc_cpp_args = ['-DLLVM_LIB_DIR="@0@"'.format(llvm_libdir)] _libmesaclc_sources = [] @@ -70,14 +73,57 @@ if dep_llvm.version().version_compare('>= 14.0') _libmesaclc_cpp_args += ['-DHAS_SPIRV_1_4=1'] endif +_basedir = dep_clc.get_variable(pkgconfig : 'libexecdir') + +_static_libclc = get_option('static-libclc') +if _static_libclc.length() > 0 + if _static_libclc.contains('all') + _static_libclc = ['spirv', 'spirv64'] + endif + prog_zstd = find_program('zstd', required : false, native : true) + _zstd_static_libclc = dep_zstd.found() and prog_zstd.found() + if _zstd_static_libclc + _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_ZSTD' + endif + foreach s : _static_libclc + _libmesaclc_c_args += '-DHAVE_STATIC_LIBCLC_@0@'.format(s.to_upper()) + f = '@0@-mesa3d-.spv'.format(s) + _libclc_file = _basedir / f + if _zstd_static_libclc + _libclc_file = custom_target( + '@0@.zstd'.format(f), + command : [prog_zstd, '-f', '@INPUT@', '-o', '@OUTPUT@'], + input : [_libclc_file], + output : '@0@.zstd'.format(f), + ) + endif + files_libmesaclc += custom_target( + '@0@.h'.format(f), + command : [ + prog_python, files_xxd, '-b', '@INPUT@', '@OUTPUT@', + '-n', 'libclc_@0@_mesa3d_spv'.format(s), + ], + input : [_libclc_file], + output : '@0@.h'.format(f), + depend_files : files_xxd, + ) + endforeach +else + _libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)] + if not cc.has_function('mmap') + error('mmap required for dynamic libCLC loading') + endif +endif + _libmesaclc = static_library( 'libmesaclc', files_libmesaclc, sources: _libmesaclc_sources, include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_compiler, inc_spirv], - cpp_args : _libmesaclc_cpp_args, - dependencies: [idep_nir_headers, dep_clang, dep_llvm, dep_llvmspirvlib, - idep_mesautil, idep_nir, dep_spirv_tools] + c_args : _libmesaclc_c_args, + cpp_args : [_libmesaclc_cpp_args, _libmesaclc_c_args], + dependencies: [idep_nir, dep_clang, dep_llvm, dep_llvmspirvlib, + idep_mesautil, dep_spirv_tools] ) idep_mesaclc = declare_dependency( diff --git a/src/compiler/clc/nir_clc_helpers.h b/src/compiler/clc/nir_clc_helpers.h new file mode 100644 index 00000000000..02a69ae5df4 --- /dev/null +++ b/src/compiler/clc/nir_clc_helpers.h @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Intel Corporation + * SPDX-License-Identifier: MIT + */ + +#ifndef MESA_NIR_CLC_H +#define MESA_NIR_CLC_H + +#include "nir.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct disk_cache; +struct spirv_to_nir_options; + +bool nir_can_find_libclc(unsigned ptr_bit_size); + +nir_shader * +nir_load_libclc_shader(unsigned ptr_bit_size, + struct disk_cache *disk_cache, + const struct spirv_to_nir_options *spirv_options, + const nir_shader_compiler_options *nir_options); + +bool nir_lower_libclc(nir_shader *shader, const nir_shader *clc_shader); + +#ifdef __cplusplus +} +#endif + +#endif /* MESA_NIR_CLC_H */ diff --git a/src/compiler/spirv/nir_load_libclc.c b/src/compiler/clc/nir_load_libclc.c similarity index 99% rename from src/compiler/spirv/nir_load_libclc.c rename to src/compiler/clc/nir_load_libclc.c index 567fb2669dc..c1469313a85 100644 --- a/src/compiler/spirv/nir_load_libclc.c +++ b/src/compiler/clc/nir_load_libclc.c @@ -22,6 +22,7 @@ */ #include "nir.h" +#include "nir_clc_helpers.h" #include "nir_serialize.h" #include "nir_spirv.h" #include "util/mesa-sha1.h" diff --git a/src/compiler/spirv/nir_lower_libclc.c b/src/compiler/clc/nir_lower_libclc.c similarity index 99% rename from src/compiler/spirv/nir_lower_libclc.c rename to src/compiler/clc/nir_lower_libclc.c index b3e121f3aad..ffbee9298c1 100644 --- a/src/compiler/spirv/nir_lower_libclc.c +++ b/src/compiler/clc/nir_lower_libclc.c @@ -28,6 +28,7 @@ * itself to make sure all instances are lowered, before validation. */ #include "nir.h" +#include "nir_clc_helpers.h" #include "nir_builder.h" #include "nir_spirv.h" diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build index 0884c4de074..043690e2a64 100644 --- a/src/compiler/nir/meson.build +++ b/src/compiler/nir/meson.build @@ -301,8 +301,6 @@ files_libnir = files( '../spirv/GLSL.ext.AMD.h', '../spirv/GLSL.std.450.h', '../spirv/gl_spirv.c', - '../spirv/nir_load_libclc.c', - '../spirv/nir_lower_libclc.c', '../spirv/nir_spirv.h', '../spirv/OpenCL.std.h', '../spirv/spirv.h', @@ -319,62 +317,13 @@ files_libnir = files( '../spirv/vtn_variables.c', ) -_libnir_args = [] -if dep_clc.found() - _basedir = dep_clc.get_variable(pkgconfig : 'libexecdir') - - _static_libclc = get_option('static-libclc') - if _static_libclc.length() > 0 - if _static_libclc.contains('all') - _static_libclc = ['spirv', 'spirv64'] - endif - - prog_zstd = find_program('zstd', required : false) - _zstd_static_libclc = dep_zstd.found() and prog_zstd.found() - if _zstd_static_libclc - _libnir_args += '-DHAVE_STATIC_LIBCLC_ZSTD' - endif - - foreach s : _static_libclc - _libnir_args += '-DHAVE_STATIC_LIBCLC_@0@'.format(s.to_upper()) - f = '@0@-mesa3d-.spv'.format(s) - _libclc_file = _basedir / f - - if _zstd_static_libclc - _libclc_file = custom_target( - '@0@.zstd'.format(f), - command : [prog_zstd, '-f', '@INPUT@', '-o', '@OUTPUT@'], - input : [_libclc_file], - output : '@0@.zstd'.format(f), - ) - endif - - files_libnir += custom_target( - '@0@.h'.format(f), - command : [ - prog_python, files_xxd, '-b', '@INPUT@', '@OUTPUT@', - '-n', 'libclc_@0@_mesa3d_spv'.format(s), - ], - input : [_libclc_file], - output : '@0@.h'.format(f), - depend_files : files_xxd, - ) - endforeach - else - _libnir_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)] - if not cc.has_function('mmap') - error('mmap required for dynamic libCLC loading') - endif - endif -endif - _libnir = static_library( 'nir', [files_libnir, spirv_info_c, nir_opt_algebraic_c, nir_opcodes_c, nir_opcodes_h, nir_constant_expressions_c, nir_builder_opcodes_h, vtn_gather_types_c, nir_intrinsics_c, nir_intrinsics_h, nir_intrinsics_indices_h, vtn_generator_ids_h], include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_compiler, include_directories('../spirv')], - c_args : [c_msvc_compat_args, no_override_init_args, _libnir_args], + c_args : [c_msvc_compat_args, no_override_init_args], gnu_symbol_visibility : 'hidden', dependencies : dep_valgrind, link_with : libcompiler, diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h index debcf9acea0..87e9e67c54e 100644 --- a/src/compiler/spirv/nir_spirv.h +++ b/src/compiler/spirv/nir_spirv.h @@ -143,16 +143,6 @@ nir_shader *spirv_to_nir(const uint32_t *words, size_t word_count, const struct spirv_to_nir_options *options, const nir_shader_compiler_options *nir_options); -bool nir_can_find_libclc(unsigned ptr_bit_size); - -nir_shader * -nir_load_libclc_shader(unsigned ptr_bit_size, - struct disk_cache *disk_cache, - const struct spirv_to_nir_options *spirv_options, - const nir_shader_compiler_options *nir_options); - -bool nir_lower_libclc(nir_shader *shader, const nir_shader *clc_shader); - #ifdef __cplusplus } #endif diff --git a/src/gallium/frontends/clover/meson.build b/src/gallium/frontends/clover/meson.build index 0d5cd33f978..4e0308dc7d5 100644 --- a/src/gallium/frontends/clover/meson.build +++ b/src/gallium/frontends/clover/meson.build @@ -88,7 +88,7 @@ libclnir = static_library( 'clnir', files('nir/invocation.cpp', 'nir/invocation.hpp'), include_directories : [clover_incs, inc_mesa], - dependencies : idep_nir, + dependencies : [idep_nir, idep_mesaclc], cpp_args : [clover_opencl_cpp_args, clover_spirv_cpp_args], gnu_symbol_visibility : 'hidden', ) diff --git a/src/gallium/frontends/clover/nir/invocation.cpp b/src/gallium/frontends/clover/nir/invocation.cpp index b0df3a81bb3..9b62529d1a6 100644 --- a/src/gallium/frontends/clover/nir/invocation.cpp +++ b/src/gallium/frontends/clover/nir/invocation.cpp @@ -32,6 +32,7 @@ #include "util/functional.hpp" #include +#include #include #include #include diff --git a/src/gallium/frontends/rusticl/rusticl_mesa_bindings.h b/src/gallium/frontends/rusticl/rusticl_mesa_bindings.h index 42214445567..2c2af47e850 100644 --- a/src/gallium/frontends/rusticl/rusticl_mesa_bindings.h +++ b/src/gallium/frontends/rusticl/rusticl_mesa_bindings.h @@ -1,6 +1,7 @@ #include "rusticl_mesa_inline_bindings_wrapper.h" #include "rusticl_system_bindings.h" +#include "compiler/clc/nir_clc_helpers.h" #include "compiler/clc/clc.h" #include "compiler/clc/clc_helpers.h" #include "compiler/shader_enums.h" diff --git a/src/intel/compiler/brw_kernel.c b/src/intel/compiler/brw_kernel.c index 2776d6ec892..3945ad35b08 100644 --- a/src/intel/compiler/brw_kernel.c +++ b/src/intel/compiler/brw_kernel.c @@ -24,6 +24,7 @@ #include "brw_kernel.h" #include "brw_nir.h" +#include "nir_clc_helpers.h" #include "compiler/nir/nir_builder.h" #include "compiler/spirv/nir_spirv.h" #include "dev/intel_debug.h" diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c index a41718ebfd3..5831c0afe5c 100644 --- a/src/microsoft/clc/clc_compiler.c +++ b/src/microsoft/clc/clc_compiler.c @@ -22,6 +22,7 @@ */ #include "nir.h" +#include "nir_clc_helpers.h" #include "nir_serialize.h" #include "glsl_types.h" #include "nir_types.h"