build/amd: add amd-use-llvm build option

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 <timur.kristof@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Tested-by: Mike Lothian <mike@fireburn.co.uk>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28969>
This commit is contained in:
Mike Blumenkrantz
2024-04-29 10:52:25 -04:00
committed by Marge Bot
parent 38dfbae116
commit 2aaa6ebba1
18 changed files with 51 additions and 36 deletions

View File

@@ -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

View File

@@ -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',

View File

@@ -73,7 +73,7 @@ get_disasm_string(Program* program, std::vector<uint32_t>& 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");

View File

@@ -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<bool, size_t>
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<uint32_t>& 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<uint32_t>& 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);
}

View File

@@ -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 = []

View File

@@ -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',

View File

@@ -8,7 +8,7 @@
#include "bvh/bvh.h"
#include "radv_debug.h"
#if LLVM_AVAILABLE
#if AMD_LLVM_AVAILABLE
#include <llvm/Config/llvm-config.h>
#endif

View File

@@ -70,7 +70,7 @@ typedef void *drmDevicePtr;
#include "aco_interface.h"
#if LLVM_AVAILABLE
#if AMD_LLVM_AVAILABLE
#include "ac_llvm_util.h"
#endif

View File

@@ -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");

View File

@@ -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

View File

@@ -23,7 +23,7 @@
#include <sys/utsname.h>
#include <stdlib.h>
#if LLVM_AVAILABLE
#if AMD_LLVM_AVAILABLE
#include <llvm-c/TargetMachine.h>
#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
")",

View File

@@ -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',

View File

@@ -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";

View File

@@ -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

View File

@@ -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);

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: MIT
*/
#if LLVM_AVAILABLE
#if AMD_LLVM_AVAILABLE
#include "ac_llvm_util.h"
#endif

View File

@@ -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

View File

@@ -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]