[Mesa-dev] [PATCH 5/5] nir/mesa: always pass shader_info to nir_shader_create() from nir_builder_init_simple_shader()

Timothy Arceri timothy.arceri at collabora.com
Fri Oct 28 06:27:37 UTC 2016


Both radv and freedreno seem to leak nir_shader where created with
nir_builder_init_simple_shader() there is no attempt to fix that in this patch.
---
 src/compiler/nir/nir_builder.h | 4 +++-
 src/mesa/program/prog_to_nir.c | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 0ee7d1a..e325410 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -34,6 +34,7 @@ typedef struct nir_builder {
    /* Whether new ALU instructions will be marked "exact" */
    bool exact;
 
+   shader_info *sh_info;
    nir_shader *shader;
    nir_function_impl *impl;
 } nir_builder;
@@ -52,7 +53,8 @@ nir_builder_init_simple_shader(nir_builder *build, void *mem_ctx,
                                gl_shader_stage stage,
                                const nir_shader_compiler_options *options)
 {
-   build->shader = nir_shader_create(mem_ctx, stage, options, NULL);
+   build->sh_info = rzalloc(mem_ctx, shader_info);
+   build->shader = nir_shader_create(mem_ctx, stage, options, build->sh_info);
    nir_function *func = nir_function_create(build->shader, "main");
    build->exact = false;
    build->impl = nir_function_impl_create(func);
diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index 08df05d..9927fff 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -1016,8 +1016,9 @@ prog_to_nir(const struct gl_program *prog,
    nir_builder_init_simple_shader(&c->build, NULL, stage, options);
 
    /* Use the shader_info from gl_program rather than the one nir_builder
-    * created for us. nir_sweep should clean up the other one for us.
+    * created for us.
     */
+   ralloc_free(c->build.sh_info);
    c->build.shader->info = (shader_info *) &prog->info;
 
    s = c->build.shader;
-- 
2.7.4



More information about the mesa-dev mailing list