From 74140c2e859c15593a379cbde96b1048f2ad69dc Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 15 Jun 2020 11:15:52 -0700 Subject: [PATCH] freedreno/ir3: convert over to ralloc The `ir3_shader` is the root mem ctx, with `ir3_shader_variant` hanging off that, and various variant specific allocations hanging off the variant. This lets us delete a bunch of cleanup code. Signed-off-by: Rob Clark Part-of: --- src/freedreno/ir3/ir3.c | 4 ++-- src/freedreno/ir3/ir3_assembler.c | 4 ++-- src/freedreno/ir3/ir3_shader.c | 26 ++++---------------------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/freedreno/ir3/ir3.c b/src/freedreno/ir3/ir3.c index 3d41a7b5cc4..7b1b3043818 100644 --- a/src/freedreno/ir3/ir3.c +++ b/src/freedreno/ir3/ir3.c @@ -48,7 +48,7 @@ void * ir3_alloc(struct ir3 *shader, int sz) struct ir3 * ir3_create(struct ir3_compiler *compiler, struct ir3_shader_variant *v) { - struct ir3 *shader = rzalloc(NULL, struct ir3); + struct ir3 *shader = rzalloc(v, struct ir3); shader->compiler = compiler; shader->type = v->type; @@ -944,7 +944,7 @@ void * ir3_assemble(struct ir3_shader_variant *v) info->sizedwords = align(info->sizedwords, 4 * 2); } - ptr = dwords = calloc(4, info->sizedwords); + ptr = dwords = rzalloc_size(v, 4 * info->sizedwords); foreach_block (block, &shader->block_list) { unsigned sfu_delay = 0; diff --git a/src/freedreno/ir3/ir3_assembler.c b/src/freedreno/ir3/ir3_assembler.c index 99104243a53..005f52859a8 100644 --- a/src/freedreno/ir3/ir3_assembler.c +++ b/src/freedreno/ir3/ir3_assembler.c @@ -34,12 +34,12 @@ struct ir3_shader * ir3_parse_asm(struct ir3_compiler *c, struct ir3_kernel_info *info, FILE *in) { - struct ir3_shader *shader = calloc(1, sizeof(*shader)); + struct ir3_shader *shader = rzalloc_size(NULL, sizeof(*shader)); shader->compiler = c; shader->type = MESA_SHADER_COMPUTE; mtx_init(&shader->variants_lock, mtx_plain); - struct ir3_shader_variant *v = calloc(1, sizeof(*v)); + struct ir3_shader_variant *v = rzalloc_size(shader, sizeof(*v)); v->type = MESA_SHADER_COMPUTE; v->shader = shader; diff --git a/src/freedreno/ir3/ir3_shader.c b/src/freedreno/ir3/ir3_shader.c index 78ed751a3f2..82b6c59d5af 100644 --- a/src/freedreno/ir3/ir3_shader.c +++ b/src/freedreno/ir3/ir3_shader.c @@ -41,18 +41,6 @@ ir3_glsl_type_size(const struct glsl_type *type, bool bindless) return glsl_count_attribute_slots(type, false); } -static void -delete_variant(struct ir3_shader_variant *v) -{ - if (v->ir) - ir3_destroy(v->ir); - assert(!v->bo); - if (v->binning) - delete_variant(v->binning); - free(v->bin); - free(v); -} - /* for vertex shader, the inputs are loaded into registers before the shader * is executed, so max_regs from the shader instructions might not properly * reflect the # of registers actually used, especially in case passthrough @@ -184,7 +172,7 @@ static struct ir3_shader_variant * create_variant(struct ir3_shader *shader, const struct ir3_shader_key *key, struct ir3_shader_variant *nonbinning) { - struct ir3_shader_variant *v = CALLOC_STRUCT(ir3_shader_variant); + struct ir3_shader_variant *v = rzalloc_size(shader, sizeof(*v)); int ret; if (!v) @@ -232,7 +220,7 @@ create_variant(struct ir3_shader *shader, const struct ir3_shader_key *key, return v; fail: - delete_variant(v); + ralloc_free(v); return NULL; } @@ -283,16 +271,10 @@ ir3_shader_get_variant(struct ir3_shader *shader, const struct ir3_shader_key *k void ir3_shader_destroy(struct ir3_shader *shader) { - struct ir3_shader_variant *v, *t; - for (v = shader->variants; v; ) { - t = v; - v = v->next; - delete_variant(t); - } free(shader->const_state.immediates); ralloc_free(shader->nir); mtx_destroy(&shader->variants_lock); - free(shader); + ralloc_free(shader); } /** @@ -355,7 +337,7 @@ struct ir3_shader * ir3_shader_from_nir(struct ir3_compiler *compiler, nir_shader *nir, unsigned reserved_user_consts, struct ir3_stream_output_info *stream_output) { - struct ir3_shader *shader = CALLOC_STRUCT(ir3_shader); + struct ir3_shader *shader = rzalloc_size(NULL, sizeof(*shader)); mtx_init(&shader->variants_lock, mtx_plain); shader->compiler = compiler; -- 2.30.2