radv: Switch to using rtld.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 1 Jul 2019 01:21:58 +0000 (03:21 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 4 Jul 2019 10:52:26 +0000 (10:52 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_llvm_helper.cpp
src/amd/vulkan/radv_nir_to_llvm.c
src/amd/vulkan/radv_shader_helper.h

index d1e1e376f909150b4fc695f57984dfd0b3dcb863..036368b3d7cbd4d8b1612cf3c3fadd2e01ab2b0f 100644 (file)
@@ -52,9 +52,9 @@ public:
        }
 
        bool compile_to_memory_buffer(LLVMModuleRef module,
        }
 
        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,
        }
 
        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_info> radv_llvm_per_thread_list;
 
 /* 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_info> 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;
 
 {
        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);
 
        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;
        }
 
                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,
 }
 
 bool radv_init_llvm_compiler(struct ac_llvm_compiler *info,
index 934d98bcc8f456190567b208017c380e909b3f14..43e169108e886e012ac9d1c216d8c303470c36d2 100644 (file)
@@ -3842,9 +3842,9 @@ static void ac_diagnostic_handler(LLVMDiagnosticInfoRef di, void *context)
        LLVMDisposeMessage(description);
 }
 
        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;
 {
        unsigned retval = 0;
        LLVMContextRef llvm_ctx;
@@ -3856,7 +3856,7 @@ static unsigned ac_llvm_compile(LLVMModuleRef M,
                                        &retval);
 
        /* Compile IR*/
                                        &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;
 }
                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)
 {
                                   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);
 
        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);
        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);
        }
 
                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");
        }
 
        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);
 
        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
 }
 
 static void
index faaf965eab508c0185cb1b7e818a74376444de3b..d9dace0b495588ee20c46c943e27a18bd2871d2d 100644 (file)
@@ -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);
 
 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
 }
 
 #ifdef __cplusplus
 }