r600,compute: Plug few memory leaks
authorJan Vesely <jan.vesely@rutgers.edu>
Thu, 21 Jan 2016 16:17:29 +0000 (11:17 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 26 Jan 2016 18:04:38 +0000 (19:04 +0100)
v2: drop inline keyword
    drop radeon_llvm_dispose_kernel_module wrapper

v3: move definitions to .c file
    use in radeonsi

Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/r600/evergreen_compute.c
src/gallium/drivers/r600/r600_llvm.c
src/gallium/drivers/r600/r600_llvm.h
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader.h

index 74250ae81392f48794f7b8ae662a478aba2a1f4a..6c5aa8576aefe8013ca71d792b2eb323ec3763f5 100644 (file)
@@ -225,7 +225,7 @@ void *evergreen_create_compute_state(
                }
        }
 #else
-       memset(&shader->binary, 0, sizeof(shader->binary));
+       radeon_shader_binary_init(&shader->binary);
        radeon_elf_read(code, header->num_bytes, &shader->binary);
        r600_create_shader(&shader->bc, &shader->binary, &use_kill);
 
@@ -245,13 +245,31 @@ void *evergreen_create_compute_state(
        return shader;
 }
 
-void evergreen_delete_compute_state(struct pipe_context *ctx, void* state)
+void evergreen_delete_compute_state(struct pipe_context *ctx_, void* state)
 {
-       struct r600_pipe_compute *shader = (struct r600_pipe_compute *)state;
+       struct r600_context *ctx = (struct r600_context *)ctx_;
+       COMPUTE_DBG(ctx->screen, "*** evergreen_delete_compute_state\n");
+       struct r600_pipe_compute *shader = state;
 
        if (!shader)
                return;
 
+#ifdef HAVE_OPENCL
+#if HAVE_LLVM < 0x0306
+       for (unsigned i = 0; i < shader->num_kernels; i++) {
+               struct r600_kernel *kernel = &shader->kernels[i];
+               LLVMDisposeModule(module);
+       }
+       FREE(shader->kernels);
+       LLVMContextDispose(shader->llvm_ctx);
+#else
+       radeon_shader_binary_clean(&shader->binary);
+       r600_destroy_shader(&shader->bc);
+
+       /* TODO destroy shader->code_bo, shader->const_bo
+        * we'll need something like r600_buffer_free */
+#endif
+#endif
        FREE(shader);
 }
 
index 8b91372f3ae43b1f6e8a1dc65df2b386369970a4..232db135be994c499b87bfe84d2fc13776fbd812 100644 (file)
@@ -910,6 +910,11 @@ unsigned r600_create_shader(struct r600_bytecode *bc,
        return 0;
 }
 
+void r600_destroy_shader(struct r600_bytecode *bc)
+{
+       FREE(bc->bytecode);
+}
+
 unsigned r600_llvm_compile(
        LLVMModuleRef mod,
        enum radeon_family family,
@@ -922,17 +927,14 @@ unsigned r600_llvm_compile(
        struct radeon_shader_binary binary;
        const char * gpu_family = r600_get_llvm_processor_name(family);
 
-       memset(&binary, 0, sizeof(struct radeon_shader_binary));
+       radeon_shader_binary_init(&binary);
        if (dump)
                LLVMDumpModule(mod);
        r = radeon_llvm_compile(mod, &binary, gpu_family, NULL, debug);
 
        r = r600_create_shader(bc, &binary, use_kill);
 
-       FREE(binary.code);
-       FREE(binary.config);
-       FREE(binary.rodata);
-       FREE(binary.global_symbol_offsets);
+       radeon_shader_binary_clean(&binary);
 
        return r;
 }
index f570b739fbed2b7ef47a20b765ecf4b080a8585f..3f7fc4bef7e2b811b64a116b68a5e872e7b40943 100644 (file)
@@ -30,6 +30,8 @@ unsigned r600_create_shader(struct r600_bytecode *bc,
                const struct radeon_shader_binary *binary,
                boolean *use_kill);
 
+void r600_destroy_shader(struct r600_bytecode *bc);
+
 void r600_shader_binary_read_config(const struct radeon_shader_binary *binary,
                struct r600_bytecode *bc,
                uint64_t symbol_offset,
index 4c066c14cd80d53891af944bde2e8182694a87da..34fe57b73b19746054ba4d3d91a3c9b708c7ab77 100644 (file)
@@ -48,6 +48,26 @@ struct r600_multi_fence {
        struct pipe_fence_handle *sdma;
 };
 
+/*
+ * shader binary helpers.
+ */
+void radeon_shader_binary_init(struct radeon_shader_binary *b)
+{
+       memset(b, 0, sizeof(*b));
+}
+
+void radeon_shader_binary_clean(struct radeon_shader_binary *b)
+{
+       if (!b)
+               return;
+       FREE(b->code);
+       FREE(b->config);
+       FREE(b->rodata);
+       FREE(b->global_symbol_offsets);
+       FREE(b->relocs);
+       FREE(b->disasm_string);
+}
+
 /*
  * pipe_context
  */
index d66e74f92541775fb923f2abece834890746c57c..a8928f254f0c51d9f69ac7b2db0176fb311ad8ff 100644 (file)
@@ -129,6 +129,9 @@ struct radeon_shader_binary {
        char *disasm_string;
 };
 
+void radeon_shader_binary_init(struct radeon_shader_binary *b);
+void radeon_shader_binary_clean(struct radeon_shader_binary *b);
+
 struct r600_resource {
        struct u_resource               b;
 
index 6ef6eeec1786994cb3359402e52a8670abbdc679..825fbb181ba1069a7d649c355c8f4e0b1b39c58d 100644 (file)
@@ -461,9 +461,6 @@ static void si_delete_compute_state(struct pipe_context *ctx, void* state){
                LLVMContextDispose(program->llvm_ctx);
        }
 #else
-       FREE(program->shader.binary.config);
-       FREE(program->shader.binary.rodata);
-       FREE(program->shader.binary.global_symbol_offsets);
        si_shader_destroy(&program->shader);
 #endif
 
index f295843c76db9bc278705c8a2c99a4797e13c2a2..2192b2120f28ac0b95ef2f3f906f40c655b66981 100644 (file)
@@ -4423,14 +4423,6 @@ out:
        return r;
 }
 
-void si_shader_destroy_binary(struct radeon_shader_binary *binary)
-{
-       FREE(binary->code);
-       FREE(binary->rodata);
-       FREE(binary->relocs);
-       FREE(binary->disasm_string);
-}
-
 void si_shader_destroy(struct si_shader *shader)
 {
        if (shader->gs_copy_shader) {
@@ -4442,5 +4434,6 @@ void si_shader_destroy(struct si_shader *shader)
                r600_resource_reference(&shader->scratch_bo, NULL);
 
        r600_resource_reference(&shader->bo, NULL);
-       si_shader_destroy_binary(&shader->binary);
+
+       radeon_shader_binary_clean(&shader->binary);
 }
index c1512078a18af72463a643770322ac227150881c..98bdb890a45c7ec34f6795f3176b9a6e18bfbaf2 100644 (file)
@@ -345,7 +345,6 @@ int si_compile_llvm(struct si_screen *sscreen,
                    struct pipe_debug_callback *debug,
                    unsigned processor);
 void si_shader_destroy(struct si_shader *shader);
-void si_shader_destroy_binary(struct radeon_shader_binary *binary);
 unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index);
 int si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader);
 void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader,