From 2aaa6ebba186fad610208ea5553ff93760718dba Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 29 Apr 2024 10:52:25 -0400 Subject: [PATCH] build/amd: add amd-use-llvm build option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this allows amd drivers to disable llvm support while still allowing llvmpipe/lavapipe to be built by disabling llvm support in amd drivers, the load times for these drivers decreases by 5-10ms Reviewed-by: Timur Kristóf Reviewed-by: Samuel Pitoiset Tested-by: Mike Lothian Part-of: --- meson.build | 7 +++++++ meson_options.txt | 8 ++++++++ src/amd/compiler/aco_interface.cpp | 2 +- src/amd/compiler/aco_print_asm.cpp | 10 +++++----- src/amd/meson.build | 2 +- src/amd/vulkan/meson.build | 2 +- src/amd/vulkan/nir/radv_nir_rt_common.c | 2 +- src/amd/vulkan/radv_device.c | 2 +- src/amd/vulkan/radv_physical_device.c | 8 ++++---- src/amd/vulkan/radv_shader.c | 12 ++++++------ src/gallium/drivers/r600/r600_pipe_common.c | 4 ++-- src/gallium/drivers/radeonsi/meson.build | 2 +- src/gallium/drivers/radeonsi/si_get.c | 2 +- src/gallium/drivers/radeonsi/si_pipe.c | 12 ++++++------ src/gallium/drivers/radeonsi/si_shader.c | 6 +++--- src/gallium/drivers/radeonsi/si_state_shaders.cpp | 2 +- src/gallium/meson.build | 2 +- src/gallium/targets/pipe-loader/meson.build | 2 +- 18 files changed, 51 insertions(+), 36 deletions(-) diff --git a/meson.build b/meson.build index 063c5d3adff..ac0c9104df8 100644 --- a/meson.build +++ b/meson.build @@ -1756,6 +1756,7 @@ if draw_with_llvm # lto is needded with LLVM>=15, but we don't know what LLVM verrsion we are using yet llvm_optional_modules += ['lto'] endif +amd_with_llvm = get_option('amd-use-llvm') if with_amd_vk or with_gallium_radeonsi or with_clc _llvm_version = '>= 15.0.0' @@ -1797,6 +1798,10 @@ if with_llvm error('Lavapipe requires LLVM draw support.') endif + if with_gallium_r600 and not amd_with_llvm + error('R600 requires LLVM AMD support.') + endif + if host_machine.system() != 'windows' # LLVM can be built without rtti, turning off rtti changes the ABI of C++ # programs, so we need to build all C++ code in mesa without rtti as well to @@ -1835,8 +1840,10 @@ elif with_clc else draw_with_llvm = false endif +amd_with_llvm = amd_with_llvm and with_llvm pre_args += '-DLLVM_AVAILABLE=@0@'.format(with_llvm.to_int()) pre_args += '-DDRAW_LLVM_AVAILABLE=@0@'.format((with_llvm and draw_with_llvm).to_int()) +pre_args += '-DAMD_LLVM_AVAILABLE=@0@'.format(amd_with_llvm.to_int()) with_opencl_spirv = (_opencl != 'disabled' and get_option('opencl-spirv')) or with_clc if with_opencl_spirv diff --git a/meson_options.txt b/meson_options.txt index 7c021c14cfe..b2678c1d4fe 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -423,6 +423,14 @@ option( 'is included.' ) +option( + 'amd-use-llvm', + type : 'boolean', + value : true, + description : 'Whether to use LLVM for the AMD drivers, if LLVM ' + + 'is included.' +) + option( 'valgrind', type : 'feature', diff --git a/src/amd/compiler/aco_interface.cpp b/src/amd/compiler/aco_interface.cpp index 12253f7f397..db96e17d038 100644 --- a/src/amd/compiler/aco_interface.cpp +++ b/src/amd/compiler/aco_interface.cpp @@ -73,7 +73,7 @@ get_disasm_string(Program* program, std::vector& code, unsigned exec_s print_asm(program, code, exec_size / 4u, memf); } else { fprintf(memf, "Shader disassembly is not supported in the current configuration" -#if !LLVM_AVAILABLE +#if !AMD_LLVM_AVAILABLE " (LLVM not available)" #endif ", falling back to print_program.\n\n"); diff --git a/src/amd/compiler/aco_print_asm.cpp b/src/amd/compiler/aco_print_asm.cpp index e590cdf698c..d21acd47623 100644 --- a/src/amd/compiler/aco_print_asm.cpp +++ b/src/amd/compiler/aco_print_asm.cpp @@ -8,7 +8,7 @@ #include "util/u_debug.h" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #if defined(_MSC_VER) && defined(restrict) #undef restrict #endif @@ -248,7 +248,7 @@ fail: #endif } -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE std::pair disasm_instr(amd_gfx_level gfx_level, LLVMDisasmContextRef disasm, uint32_t* binary, unsigned exec_size, size_t pos, char* outline, unsigned outline_size) @@ -366,14 +366,14 @@ print_asm_llvm(Program* program, std::vector& binary, unsigned exec_si return invalid; } -#endif /* LLVM_AVAILABLE */ +#endif /* AMD_LLVM_AVAILABLE */ } /* end namespace */ bool check_print_asm_support(Program* program) { -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (program->gfx_level >= GFX8) { /* LLVM disassembler only supports GFX8+ */ const char* name = ac_get_llvm_processor_name(program->family); @@ -404,7 +404,7 @@ check_print_asm_support(Program* program) bool print_asm(Program* program, std::vector& binary, unsigned exec_size, FILE* output) { -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (program->gfx_level >= GFX8) { return print_asm_llvm(program, binary, exec_size, output); } diff --git a/src/amd/meson.build b/src/amd/meson.build index 4c0bd4abc5d..5e4e3f6e566 100644 --- a/src/amd/meson.build +++ b/src/amd/meson.build @@ -23,7 +23,7 @@ inc_amd = include_directories('.') if with_amd_vk or with_gallium_radeonsi subdir('addrlib') subdir('common') - if with_llvm + if amd_with_llvm subdir('llvm') else libamd_common_llvm = [] diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index 1269087b706..a9412c76625 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -182,7 +182,7 @@ if not with_platform_windows ) endif -if with_llvm +if amd_with_llvm libradv_files += files( 'radv_llvm_helper.cpp', 'radv_llvm_helper.h', diff --git a/src/amd/vulkan/nir/radv_nir_rt_common.c b/src/amd/vulkan/nir/radv_nir_rt_common.c index c6fe6c91129..60683550d98 100644 --- a/src/amd/vulkan/nir/radv_nir_rt_common.c +++ b/src/amd/vulkan/nir/radv_nir_rt_common.c @@ -8,7 +8,7 @@ #include "bvh/bvh.h" #include "radv_debug.h" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include #endif diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 132f39b2d0e..fe8c976b05b 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -70,7 +70,7 @@ typedef void *drmDevicePtr; #include "aco_interface.h" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include "ac_llvm_util.h" #endif diff --git a/src/amd/vulkan/radv_physical_device.c b/src/amd/vulkan/radv_physical_device.c index c3a38a1becc..a0463a0f460 100644 --- a/src/amd/vulkan/radv_physical_device.c +++ b/src/amd/vulkan/radv_physical_device.c @@ -41,7 +41,7 @@ typedef void *drmDevicePtr; #include "winsys/null/radv_null_winsys_public.h" #include "git_sha1.h" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include "ac_llvm_util.h" #endif @@ -191,7 +191,7 @@ radv_device_get_cache_uuid(struct radv_physical_device *pdev, void *uuid) return -1; #endif -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (pdev->use_llvm && !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, &ctx)) return -1; #endif @@ -1268,7 +1268,7 @@ radv_get_compiler_string(struct radv_physical_device *pdev) return ""; } -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE return " (LLVM " MESA_LLVM_VERSION_STRING ")"; #else unreachable("LLVM is not available"); @@ -2022,7 +2022,7 @@ radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm pdev->ws->query_info(pdev->ws, &pdev->info); pdev->use_llvm = instance->debug_flags & RADV_DEBUG_LLVM; -#if !LLVM_AVAILABLE +#if !AMD_LLVM_AVAILABLE if (pdev->use_llvm) { fprintf(stderr, "ERROR: LLVM compiler backend selected for radv, but LLVM support was not " "enabled at build time.\n"); diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 8fd7fe6f38d..5b9ee737fa5 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -43,7 +43,7 @@ #include "aco_shader_info.h" #include "radv_aco_shader_info.h" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include "ac_llvm_util.h" #endif @@ -531,7 +531,7 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st bool gfx7minus = pdev->info.gfx_level <= GFX7; bool has_inverse_ballot = true; -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE has_inverse_ballot = !radv_use_llvm_for_stage(pdev, nir->info.stage) || LLVM_VERSION_MAJOR >= 17; #endif @@ -2786,7 +2786,7 @@ shader_compile(struct radv_device *device, struct nir_shader *const *shaders, in struct radv_shader_binary *binary = NULL; -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE const struct radv_physical_device *pdev = radv_device_physical(device); if (radv_use_llvm_for_stage(pdev, stage) || options->dump_shader || options->record_ir) @@ -2934,7 +2934,7 @@ radv_create_rt_prolog(struct radv_device *device) radv_declare_rt_shader_args(options.info->gfx_level, &out_args); info.user_sgprs_locs = in_args.user_sgprs_locs; -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (options.dump_shader || options.record_ir) ac_init_llvm_once(); #endif @@ -2999,7 +2999,7 @@ radv_create_vs_prolog(struct radv_device *device, const struct radv_vs_prolog_ke info.user_sgprs_locs = args.user_sgprs_locs; info.inline_push_constant_mask = args.ac.inline_push_const_mask; -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (options.dump_shader || options.record_ir) ac_init_llvm_once(); #endif @@ -3054,7 +3054,7 @@ radv_create_ps_epilog(struct radv_device *device, const struct radv_ps_epilog_ke radv_declare_ps_epilog_args(device, key, &args); -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (options.dump_shader || options.record_ir) ac_init_llvm_once(); #endif diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index 14d1aa6cf5a..aaa171a07ed 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -23,7 +23,7 @@ #include #include -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include #endif @@ -1252,7 +1252,7 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen, snprintf(rscreen->renderer_string, sizeof(rscreen->renderer_string), "%s (%sDRM %i.%i.%i%s" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE ", LLVM " MESA_LLVM_VERSION_STRING #endif ")", diff --git a/src/gallium/drivers/radeonsi/meson.build b/src/gallium/drivers/radeonsi/meson.build index 9901be68ef5..e69b84a16b3 100644 --- a/src/gallium/drivers/radeonsi/meson.build +++ b/src/gallium/drivers/radeonsi/meson.build @@ -130,7 +130,7 @@ files_libradeonsi += ['si_perfetto.cpp', 'si_perfetto.h'] amd_common_libs = [libamd_common] -if with_llvm +if amd_with_llvm files_libradeonsi += files( 'si_shader_llvm.c', 'si_shader_llvm.h', diff --git a/src/gallium/drivers/radeonsi/si_get.c b/src/gallium/drivers/radeonsi/si_get.c index f795c31935d..bafc44ed53b 100644 --- a/src/gallium/drivers/radeonsi/si_get.c +++ b/src/gallium/drivers/radeonsi/si_get.c @@ -1338,7 +1338,7 @@ static void si_init_renderer_string(struct si_screen *sscreen) snprintf(kernel_version, sizeof(kernel_version), ", %s", uname_data.release); const char *compiler_name = -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE !sscreen->use_aco ? "LLVM " MESA_LLVM_VERSION_STRING : #endif "ACO"; diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index d4ddaa0f073..be309e4311d 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -27,7 +27,7 @@ #include "aco_interface.h" -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include "ac_llvm_util.h" #endif @@ -133,7 +133,7 @@ static const struct debug_named_value test_options[] = { struct ac_llvm_compiler *si_create_llvm_compiler(struct si_screen *sscreen) { -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE struct ac_llvm_compiler *compiler = CALLOC_STRUCT(ac_llvm_compiler); if (!compiler) return NULL; @@ -177,7 +177,7 @@ void si_init_aux_async_compute_ctx(struct si_screen *sscreen) static void si_destroy_llvm_compiler(struct ac_llvm_compiler *compiler) { -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE ac_destroy_llvm_compiler(compiler); FREE(compiler); #endif @@ -1106,7 +1106,7 @@ static void si_disk_cache_create(struct si_screen *sscreen) * the LLVM function identifier. ACO is a built-in component in mesa, so no need * to add aco function here. */ -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE if (!sscreen->use_aco && !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, &ctx)) return; @@ -1180,7 +1180,7 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws, if (sscreen->debug_flags & DBG(SHADOW_REGS)) sscreen->info.register_shadowing_required = true; -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE sscreen->use_aco = (sscreen->debug_flags & DBG(USE_ACO)); #else sscreen->use_aco = true; @@ -1523,7 +1523,7 @@ struct pipe_screen *radeonsi_screen_create(int fd, const struct pipe_screen_conf if (!version) return NULL; -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE /* LLVM must be initialized before util_queue because both u_queue and LLVM call atexit, * and LLVM must call it first because its atexit handler executes C++ destructors, * which must be done after our compiler threads using LLVM in u_queue are finished diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 35994c18398..f833e883032 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -2653,7 +2653,7 @@ si_nir_generate_gs_copy_shader(struct si_screen *sscreen, } bool ok = -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE !sscreen->use_aco ? si_llvm_compile_shader(sscreen, compiler, shader, &args, debug, nir) : #endif si_aco_compile_shader(shader, &args, nir, debug); @@ -2923,7 +2923,7 @@ bool si_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compi float_mode &= ~V_00B028_FP_16_64_DENORMS; ret = -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE !sscreen->use_aco ? si_llvm_compile_shader(sscreen, compiler, shader, &args, debug, nir) : #endif si_aco_compile_shader(shader, &args, nir, debug); @@ -3089,7 +3089,7 @@ si_get_shader_part(struct si_screen *sscreen, struct si_shader_part **list, result->key = *key; bool ok = -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE !sscreen->use_aco ? si_llvm_build_shader_part(sscreen, stage, prolog, compiler, debug, name, result) : #endif si_aco_build_shader_part(sscreen, stage, prolog, debug, name, result); diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.cpp b/src/gallium/drivers/radeonsi/si_state_shaders.cpp index 058a269526f..0d36c93ce39 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.cpp +++ b/src/gallium/drivers/radeonsi/si_state_shaders.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -#if LLVM_AVAILABLE +#if AMD_LLVM_AVAILABLE #include "ac_llvm_util.h" #endif diff --git a/src/gallium/meson.build b/src/gallium/meson.build index 5014bdbd700..c820f288ab0 100644 --- a/src/gallium/meson.build +++ b/src/gallium/meson.build @@ -25,7 +25,7 @@ foreach d : [[with_gallium_r300 or with_gallium_radeonsi or with_gallium_r600, ' [with_gallium_radeonsi, 'amdgpu_winsys_create'], [with_gallium_nouveau, 'nouveau_drm_screen_create'], [with_gallium_freedreno, 'fd_drm_screen_create_renderonly'], - [with_llvm and with_gallium_radeonsi, 'ac_init_shared_llvm_once']] + [amd_with_llvm and with_gallium_radeonsi, 'ac_init_shared_llvm_once']] if d[0] sym_config.set(d[1], d[1] + ';') else diff --git a/src/gallium/targets/pipe-loader/meson.build b/src/gallium/targets/pipe-loader/meson.build index 48497fa9feb..d5946dd41b4 100644 --- a/src/gallium/targets/pipe-loader/meson.build +++ b/src/gallium/targets/pipe-loader/meson.build @@ -65,7 +65,7 @@ foreach x : pipe_loaders foreach d : [[x[1] in ['r300', 'r600', 'radeonsi'], 'radeon_drm_winsys_create'], [x[1] == 'radeonsi', 'amdgpu_winsys_create'], - [x[1] == 'radeonsi' and with_llvm, 'ac_init_shared_llvm_once'], + [x[1] == 'radeonsi' and amd_with_llvm, 'ac_init_shared_llvm_once'], [x[1] != 'swrast', 'driver_descriptor'], [x[1] == 'swrast', 'swrast_driver_descriptor']] if d[0]