diff options
author | Kenneth Graunke <[email protected]> | 2011-05-16 11:49:57 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2011-05-17 23:32:58 -0700 |
commit | 774fb90db3e83d5e7326b7a72e05ce805c306b24 (patch) | |
tree | 6d729d4fc538835cbe4fef4134c8721cd4befe9c /src/mesa/drivers | |
parent | ebeea9857339da5f0f0455c45a8350190bbad189 (diff) |
i965: Get a ralloc context into brw_compile.
This would be so much easier if we were using C++; we could simply use
constructors and destructors. Instead, we have to update all the
callers.
While we're at it, ralloc various brw_wm_compile fields rather than
explicitly calloc/free'ing them.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_clip.c | 8 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_eu.c | 5 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_eu.h | 5 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_gs.c | 8 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_sf.c | 7 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_vs.c | 8 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_vtbl.c | 10 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_wm.c | 15 |
8 files changed, 44 insertions, 22 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_clip.c b/src/mesa/drivers/dri/i965/brw_clip.c index 3c175515408..c7d428ba48d 100644 --- a/src/mesa/drivers/dri/i965/brw_clip.c +++ b/src/mesa/drivers/dri/i965/brw_clip.c @@ -42,6 +42,8 @@ #include "brw_state.h" #include "brw_clip.h" +#include "../glsl/ralloc.h" + #define FRONT_UNFILLED_BIT 0x1 #define BACK_UNFILLED_BIT 0x2 @@ -52,16 +54,19 @@ static void compile_clip_prog( struct brw_context *brw, struct intel_context *intel = &brw->intel; struct brw_clip_compile c; const GLuint *program; + void *mem_ctx; GLuint program_size; GLuint delta; GLuint i; GLuint header_regs; memset(&c, 0, sizeof(c)); + + mem_ctx = ralloc_context(NULL); /* Begin the compilation: */ - brw_init_compile(brw, &c.func); + brw_init_compile(brw, &c.func, mem_ctx); c.func.single_program_flow = 1; @@ -150,6 +155,7 @@ static void compile_clip_prog( struct brw_context *brw, program, program_size, &c.prog_data, sizeof(c.prog_data), &brw->clip.prog_data); + ralloc_free(mem_ctx); } /* Calculate interpolants for triangle and line rasterization. diff --git a/src/mesa/drivers/dri/i965/brw_eu.c b/src/mesa/drivers/dri/i965/brw_eu.c index 18f6a4de4d8..aa3f878364a 100644 --- a/src/mesa/drivers/dri/i965/brw_eu.c +++ b/src/mesa/drivers/dri/i965/brw_eu.c @@ -166,7 +166,8 @@ void brw_pop_insn_state( struct brw_compile *p ) /*********************************************************************** */ -void brw_init_compile( struct brw_context *brw, struct brw_compile *p ) +void +brw_init_compile(struct brw_context *brw, struct brw_compile *p, void *mem_ctx) { p->brw = brw; p->nr_insn = 0; @@ -174,6 +175,8 @@ void brw_init_compile( struct brw_context *brw, struct brw_compile *p ) p->compressed = false; memset(p->current, 0, sizeof(p->current[0])); + p->mem_ctx = mem_ctx; + /* Some defaults? */ brw_set_mask_control(p, BRW_MASK_ENABLE); /* what does this do? */ diff --git a/src/mesa/drivers/dri/i965/brw_eu.h b/src/mesa/drivers/dri/i965/brw_eu.h index 3243fdf39ac..a0ac17ac30c 100644 --- a/src/mesa/drivers/dri/i965/brw_eu.h +++ b/src/mesa/drivers/dri/i965/brw_eu.h @@ -104,6 +104,8 @@ struct brw_compile { struct brw_instruction store[BRW_EU_MAX_INSN]; GLuint nr_insn; + void *mem_ctx; + /* Allow clients to push/pop instruction state: */ struct brw_instruction stack[BRW_EU_MAX_INSN_STACK]; @@ -784,7 +786,8 @@ void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse); void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional ); void brw_set_acc_write_control(struct brw_compile *p, GLuint value); -void brw_init_compile( struct brw_context *, struct brw_compile *p ); +void brw_init_compile(struct brw_context *, struct brw_compile *p, + void *mem_ctx); const GLuint *brw_get_program( struct brw_compile *p, GLuint *sz ); diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c index c6d3a09e06a..aaffe94e981 100644 --- a/src/mesa/drivers/dri/i965/brw_gs.c +++ b/src/mesa/drivers/dri/i965/brw_gs.c @@ -42,7 +42,7 @@ #include "brw_state.h" #include "brw_gs.h" - +#include "../glsl/ralloc.h" static void compile_gs_prog( struct brw_context *brw, struct brw_gs_prog_key *key ) @@ -50,6 +50,7 @@ static void compile_gs_prog( struct brw_context *brw, struct intel_context *intel = &brw->intel; struct brw_gs_compile c; const GLuint *program; + void *mem_ctx; GLuint program_size; /* Gen6: VF has already converted into polygon, and LINELOOP is @@ -73,10 +74,11 @@ static void compile_gs_prog( struct brw_context *brw, c.nr_bytes = c.nr_regs * REG_SIZE; + mem_ctx = NULL; /* Begin the compilation: */ - brw_init_compile(brw, &c.func); + brw_init_compile(brw, &c.func, mem_ctx); c.func.single_program_flow = 1; @@ -101,6 +103,7 @@ static void compile_gs_prog( struct brw_context *brw, brw_gs_lines( &c ); break; default: + ralloc_free(mem_ctx); return; } @@ -126,6 +129,7 @@ static void compile_gs_prog( struct brw_context *brw, program, program_size, &c.prog_data, sizeof(c.prog_data), &brw->gs.prog_data); + ralloc_free(mem_ctx); } static const GLenum gs_prim[GL_POLYGON+1] = { diff --git a/src/mesa/drivers/dri/i965/brw_sf.c b/src/mesa/drivers/dri/i965/brw_sf.c index 5a03851b8e6..9b82fe159f9 100644 --- a/src/mesa/drivers/dri/i965/brw_sf.c +++ b/src/mesa/drivers/dri/i965/brw_sf.c @@ -43,20 +43,24 @@ #include "brw_sf.h" #include "brw_state.h" +#include "../glsl/ralloc.h" + static void compile_sf_prog( struct brw_context *brw, struct brw_sf_prog_key *key ) { struct intel_context *intel = &brw->intel; struct brw_sf_compile c; const GLuint *program; + void *mem_ctx; GLuint program_size; GLuint i, idx; memset(&c, 0, sizeof(c)); + mem_ctx = ralloc_context(NULL); /* Begin the compilation: */ - brw_init_compile(brw, &c.func); + brw_init_compile(brw, &c.func, mem_ctx); c.key = *key; c.nr_attrs = brw_count_bits(c.key.attrs); @@ -124,6 +128,7 @@ static void compile_sf_prog( struct brw_context *brw, program, program_size, &c.prog_data, sizeof(c.prog_data), &brw->sf.prog_data); + ralloc_free(mem_ctx); } /* Calculate interpolants for triangle and line rasterization. diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c index 31a2b518c40..d6a53995531 100644 --- a/src/mesa/drivers/dri/i965/brw_vs.c +++ b/src/mesa/drivers/dri/i965/brw_vs.c @@ -37,7 +37,7 @@ #include "program/prog_print.h" #include "program/prog_parameter.h" - +#include "../glsl/ralloc.h" static void do_vs_prog( struct brw_context *brw, struct brw_vertex_program *vp, @@ -47,13 +47,16 @@ static void do_vs_prog( struct brw_context *brw, GLuint program_size; const GLuint *program; struct brw_vs_compile c; + void *mem_ctx; int aux_size; int i; memset(&c, 0, sizeof(c)); memcpy(&c.key, key, sizeof(*key)); - brw_init_compile(brw, &c.func); + mem_ctx = ralloc_context(NULL); + + brw_init_compile(brw, &c.func, mem_ctx); c.vp = vp; c.prog_data.outputs_written = vp->program.Base.OutputsWritten; @@ -108,6 +111,7 @@ static void do_vs_prog( struct brw_context *brw, program, program_size, &c.prog_data, aux_size, &brw->vs.prog_data); + ralloc_free(mem_ctx); } diff --git a/src/mesa/drivers/dri/i965/brw_vtbl.c b/src/mesa/drivers/dri/i965/brw_vtbl.c index f2c417d8a81..28d5f62f34b 100644 --- a/src/mesa/drivers/dri/i965/brw_vtbl.c +++ b/src/mesa/drivers/dri/i965/brw_vtbl.c @@ -46,6 +46,8 @@ #include "brw_vs.h" #include "brw_wm.h" +#include "../glsl/ralloc.h" + static void dri_bo_release(drm_intel_bo **bo) { @@ -64,13 +66,7 @@ static void brw_destroy_context( struct intel_context *intel ) brw_destroy_state(brw); brw_draw_destroy( brw ); brw_clear_validated_bos(brw); - if (brw->wm.compile_data) { - free(brw->wm.compile_data->instruction); - free(brw->wm.compile_data->vreg); - free(brw->wm.compile_data->refs); - free(brw->wm.compile_data->prog_instructions); - free(brw->wm.compile_data); - } + ralloc_free(brw->wm.compile_data); intel_region_release(&brw->state.depth_region); diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index 06512de940f..40589b0d2e4 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -35,6 +35,8 @@ #include "main/formats.h" #include "main/samplerobj.h" +#include "../glsl/ralloc.h" + /** Return number of src args for given instruction */ GLuint brw_wm_nr_args( GLuint opcode ) { @@ -193,7 +195,7 @@ static void do_wm_prog( struct brw_context *brw, c = brw->wm.compile_data; if (c == NULL) { - brw->wm.compile_data = calloc(1, sizeof(*brw->wm.compile_data)); + brw->wm.compile_data = rzalloc(NULL, struct brw_wm_compile); c = brw->wm.compile_data; if (c == NULL) { /* Ouch - big out of memory problem. Can't continue @@ -202,11 +204,10 @@ static void do_wm_prog( struct brw_context *brw, */ return; } - c->instruction = calloc(1, BRW_WM_MAX_INSN * sizeof(*c->instruction)); - c->prog_instructions = calloc(1, BRW_WM_MAX_INSN * - sizeof(*c->prog_instructions)); - c->vreg = calloc(1, BRW_WM_MAX_VREG * sizeof(*c->vreg)); - c->refs = calloc(1, BRW_WM_MAX_REF * sizeof(*c->refs)); + c->instruction = rzalloc_array(c, struct brw_wm_instruction, BRW_WM_MAX_INSN); + c->prog_instructions = rzalloc_array(c, struct prog_instruction, BRW_WM_MAX_INSN); + c->vreg = rzalloc_array(c, struct brw_wm_value, BRW_WM_MAX_VREG); + c->refs = rzalloc_array(c, struct brw_wm_ref, BRW_WM_MAX_REF); } else { void *instruction = c->instruction; void *prog_instructions = c->prog_instructions; @@ -223,7 +224,7 @@ static void do_wm_prog( struct brw_context *brw, c->fp = fp; c->env_param = brw->intel.ctx.FragmentProgram.Parameters; - brw_init_compile(brw, &c->func); + brw_init_compile(brw, &c->func, c); if (!brw_wm_fs_emit(brw, c)) { /* Fallback for fixed function and ARB_fp shaders. */ |