From: Eric Anholt Date: Thu, 12 Jan 2012 20:51:34 +0000 (-0800) Subject: mesa: Make the register allocator allocation take a ralloc context. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b972744c78e45928876ea781b9eeef09b3baf083;p=mesa.git mesa: Make the register allocator allocation take a ralloc context. This fixes a memory leak on i965 context destruction. NOTE: This is a candidate for the 8.0 branch. --- diff --git a/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c b/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c index 30716a34843..bb5b43f2f95 100644 --- a/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c +++ b/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c @@ -547,7 +547,7 @@ static void do_advanced_regalloc(struct regalloc_state * s) struct ra_graph * graph; /* Allocate the main ra data structure */ - regs = ra_alloc_reg_set(s->C->max_temp_regs * RC_MASK_XYZW); + regs = ra_alloc_reg_set(NULL, s->C->max_temp_regs * RC_MASK_XYZW); /* Get list of program variables */ variables = rc_get_variables(s->C); diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp index 3f875cc63d9..d4dd1240b70 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp @@ -88,7 +88,7 @@ brw_alloc_reg_set_for_classes(struct brw_context *brw, ralloc_free(brw->wm.ra_reg_to_grf); brw->wm.ra_reg_to_grf = ralloc_array(brw, uint8_t, ra_reg_count); ralloc_free(brw->wm.regs); - brw->wm.regs = ra_alloc_reg_set(ra_reg_count); + brw->wm.regs = ra_alloc_reg_set(brw, ra_reg_count); ralloc_free(brw->wm.classes); brw->wm.classes = ralloc_array(brw, int, class_count + 1); diff --git a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp index 1ace91fafef..2efe235bff9 100644 --- a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp +++ b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp @@ -108,7 +108,7 @@ brw_alloc_reg_set_for_classes(struct brw_context *brw, ralloc_free(brw->vs.ra_reg_to_grf); brw->vs.ra_reg_to_grf = ralloc_array(brw, uint8_t, ra_reg_count); ralloc_free(brw->vs.regs); - brw->vs.regs = ra_alloc_reg_set(ra_reg_count); + brw->vs.regs = ra_alloc_reg_set(brw, ra_reg_count); ralloc_free(brw->vs.classes); brw->vs.classes = ralloc_array(brw, int, class_count + 1); diff --git a/src/mesa/program/register_allocate.c b/src/mesa/program/register_allocate.c index f5b5174fc18..f08c9d28d6b 100644 --- a/src/mesa/program/register_allocate.c +++ b/src/mesa/program/register_allocate.c @@ -154,13 +154,19 @@ struct ra_graph { unsigned int stack_count; }; +/** + * Creates a set of registers for the allocator. + * + * mem_ctx is a ralloc context for the allocator. The reg set may be freed + * using ralloc_free(). + */ struct ra_regs * -ra_alloc_reg_set(unsigned int count) +ra_alloc_reg_set(void *mem_ctx, unsigned int count) { unsigned int i; struct ra_regs *regs; - regs = rzalloc(NULL, struct ra_regs); + regs = rzalloc(mem_ctx, struct ra_regs); regs->count = count; regs->regs = rzalloc_array(regs, struct ra_reg, count); diff --git a/src/mesa/program/register_allocate.h b/src/mesa/program/register_allocate.h index ee2e58a4756..00b851ec21b 100644 --- a/src/mesa/program/register_allocate.h +++ b/src/mesa/program/register_allocate.h @@ -36,7 +36,7 @@ struct ra_regs; * registers, such as aligned register pairs that conflict with the * two real registers from which they are composed. */ -struct ra_regs *ra_alloc_reg_set(unsigned int count); +struct ra_regs *ra_alloc_reg_set(void *mem_ctx, unsigned int count); unsigned int ra_alloc_reg_class(struct ra_regs *regs); void ra_add_reg_conflict(struct ra_regs *regs, unsigned int r1, unsigned int r2);