[Mesa-dev] [PATCH 1/7] mesa: Make the register allocator allocation take a ralloc context.

Eric Anholt eric at anholt.net
Thu Jan 12 13:47:08 PST 2012


This fixes a memory leak on i965 context destruction.

NOTE: This is a candidate for the 8.0 branch.
---
 .../drivers/r300/compiler/radeon_pair_regalloc.c   |    2 +-
 src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp  |    2 +-
 .../drivers/dri/i965/brw_vec4_reg_allocate.cpp     |    2 +-
 src/mesa/program/register_allocate.c               |   10 ++++++++--
 src/mesa/program/register_allocate.h               |    2 +-
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c b/src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c
index 30716a3..bb5b43f 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 3f875cc..d4dd124 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 1ace91f..2efe235 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 f5b5174..f08c9d2 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 ee2e58a..00b851e 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);
-- 
1.7.7.3



More information about the mesa-dev mailing list