From 6a220e67cef359c3dc9978a1d730b1d2b5fba5c7 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Mon, 1 Jul 2019 03:21:58 +0200 Subject: [PATCH] radv: Switch to using rtld. Reviewed-by: Samuel Pitoiset --- src/amd/vulkan/radv_llvm_helper.cpp | 14 +++---- src/amd/vulkan/radv_nir_to_llvm.c | 64 +++++++++++------------------ src/amd/vulkan/radv_shader_helper.h | 6 +-- 3 files changed, 35 insertions(+), 49 deletions(-) diff --git a/src/amd/vulkan/radv_llvm_helper.cpp b/src/amd/vulkan/radv_llvm_helper.cpp index d1e1e376f90..036368b3d7c 100644 --- a/src/amd/vulkan/radv_llvm_helper.cpp +++ b/src/amd/vulkan/radv_llvm_helper.cpp @@ -52,9 +52,9 @@ public: } bool compile_to_memory_buffer(LLVMModuleRef module, - struct ac_shader_binary *binary) + char **pelf_buffer, size_t *pelf_size) { - return ac_compile_module_to_binary(passes, module, binary); + return ac_compile_module_to_elf(passes, module, pelf_buffer, pelf_size); } bool is_same(enum radeon_family arg_family, @@ -74,9 +74,9 @@ private: /* we have to store a linked list per thread due to the possiblity of multiple gpus being required */ static thread_local std::list radv_llvm_per_thread_list; -bool radv_compile_to_binary(struct ac_llvm_compiler *info, - LLVMModuleRef module, - struct ac_shader_binary *binary) +bool radv_compile_to_elf(struct ac_llvm_compiler *info, + LLVMModuleRef module, + char **pelf_buffer, size_t *pelf_size) { radv_llvm_per_thread_info *thread_info = nullptr; @@ -89,12 +89,12 @@ bool radv_compile_to_binary(struct ac_llvm_compiler *info, if (!thread_info) { struct ac_compiler_passes *passes = ac_create_llvm_passes(info->tm); - bool ret = ac_compile_module_to_binary(passes, module, binary); + bool ret = ac_compile_module_to_elf(passes, module, pelf_buffer, pelf_size); ac_destroy_llvm_passes(passes); return ret; } - return thread_info->compile_to_memory_buffer(module, binary); + return thread_info->compile_to_memory_buffer(module, pelf_buffer, pelf_size); } bool radv_init_llvm_compiler(struct ac_llvm_compiler *info, diff --git a/src/amd/vulkan/radv_nir_to_llvm.c b/src/amd/vulkan/radv_nir_to_llvm.c index 934d98bcc8f..43e169108e8 100644 --- a/src/amd/vulkan/radv_nir_to_llvm.c +++ b/src/amd/vulkan/radv_nir_to_llvm.c @@ -3842,9 +3842,9 @@ static void ac_diagnostic_handler(LLVMDiagnosticInfoRef di, void *context) LLVMDisposeMessage(description); } -static unsigned ac_llvm_compile(LLVMModuleRef M, - struct ac_shader_binary *binary, - struct ac_llvm_compiler *ac_llvm) +static unsigned radv_llvm_compile(LLVMModuleRef M, + char **pelf_buffer, size_t *pelf_size, + struct ac_llvm_compiler *ac_llvm) { unsigned retval = 0; LLVMContextRef llvm_ctx; @@ -3856,7 +3856,7 @@ static unsigned ac_llvm_compile(LLVMModuleRef M, &retval); /* Compile IR*/ - if (!radv_compile_to_binary(ac_llvm, M, binary)) + if (!radv_compile_to_elf(ac_llvm, M, pelf_buffer, pelf_size)) retval = 1; return retval; } @@ -3868,57 +3868,43 @@ static void ac_compile_llvm_module(struct ac_llvm_compiler *ac_llvm, gl_shader_stage stage, const struct radv_nir_compiler_options *options) { - struct ac_shader_binary binary; - struct ac_shader_config config; + char *elf_buffer = NULL; + size_t elf_size = 0; + char *llvm_ir_string = NULL; if (options->dump_shader) ac_dump_module(llvm_module); - memset(&binary, 0, sizeof(binary)); - if (options->record_llvm_ir) { char *llvm_ir = LLVMPrintModuleToString(llvm_module); - binary.llvm_ir_string = strdup(llvm_ir); + llvm_ir_string = strdup(llvm_ir); LLVMDisposeMessage(llvm_ir); } - int v = ac_llvm_compile(llvm_module, &binary, ac_llvm); + int v = radv_llvm_compile(llvm_module, &elf_buffer, &elf_size, ac_llvm); if (v) { fprintf(stderr, "compile failed\n"); } - ac_shader_binary_read_config(&binary, &config, 0, options->supports_spill); - LLVMContextRef ctx = LLVMGetModuleContext(llvm_module); LLVMDisposeModule(llvm_module); LLVMContextDispose(ctx); - size_t disasm_size = binary.disasm_string ? strlen(binary.disasm_string) : 0; - size_t llvm_ir_size = binary.llvm_ir_string ? strlen(binary.llvm_ir_string) : 0; - size_t alloc_size = sizeof(struct radv_shader_binary_legacy) + binary.code_size + - disasm_size + llvm_ir_size + 2; - struct radv_shader_binary_legacy *lbin = calloc(1, alloc_size); - memcpy(lbin->data, binary.code, binary.code_size); - if (binary.llvm_ir_string) - memcpy(lbin->data + binary.code_size, binary.llvm_ir_string, llvm_ir_size + 1); - if (binary.disasm_string) - memcpy(lbin->data + binary.code_size + llvm_ir_size + 1, binary.disasm_string, disasm_size + 1); - - lbin->base.type = RADV_BINARY_TYPE_LEGACY; - lbin->base.stage = stage; - lbin->base.total_size = alloc_size; - lbin->config = config; - lbin->code_size = binary.code_size; - lbin->llvm_ir_size = llvm_ir_size; - lbin->disasm_size = disasm_size; - *rbinary = &lbin->base; - - free(binary.code); - free(binary.config); - free(binary.rodata); - free(binary.global_symbol_offsets); - free(binary.relocs); - free(binary.disasm_string); - free(binary.llvm_ir_string); + size_t llvm_ir_size = llvm_ir_string ? strlen(llvm_ir_string) : 0; + size_t alloc_size = sizeof(struct radv_shader_binary_rtld) + elf_size + llvm_ir_size + 1; + struct radv_shader_binary_rtld *rbin = calloc(1, alloc_size); + memcpy(rbin->data, elf_buffer, elf_size); + if (llvm_ir_string) + memcpy(rbin->data + elf_size, llvm_ir_string, llvm_ir_size + 1); + + rbin->base.type = RADV_BINARY_TYPE_RTLD; + rbin->base.stage = stage; + rbin->base.total_size = alloc_size; + rbin->elf_size = elf_size; + rbin->llvm_ir_size = llvm_ir_size; + *rbinary = &rbin->base; + + free(llvm_ir_string); + free(elf_buffer); } static void diff --git a/src/amd/vulkan/radv_shader_helper.h b/src/amd/vulkan/radv_shader_helper.h index faaf965eab5..d9dace0b495 100644 --- a/src/amd/vulkan/radv_shader_helper.h +++ b/src/amd/vulkan/radv_shader_helper.h @@ -33,9 +33,9 @@ bool radv_init_llvm_compiler(struct ac_llvm_compiler *info, void radv_destroy_llvm_compiler(struct ac_llvm_compiler *info, bool thread_compiler); -bool radv_compile_to_binary(struct ac_llvm_compiler *info, - LLVMModuleRef module, - struct ac_shader_binary *binary); +bool radv_compile_to_elf(struct ac_llvm_compiler *info, + LLVMModuleRef module, + char **pelf_buffer, size_t *pelf_size); #ifdef __cplusplus } -- 2.30.2