i965/vs: Rework memory contexts for shader compilation data.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 27 Nov 2012 07:52:20 +0000 (23:52 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 29 Nov 2012 02:15:53 +0000 (18:15 -0800)
During compilation, we allocate a bunch of things: the IR needs to last
at least until code generation...and then the program store needs to
last until after we upload the program.

For simplicity's sake, just keep it all around until we upload the
program.  After that, it can all be freed.

This will also save a lot of headaches during the upcoming refactoring.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4.h
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/drivers/dri/i965/brw_vs.c
src/mesa/drivers/dri/i965/brw_vs.h

index d203ca907656396512105c97a99bd02425537b14..7e6e79e5e7e8ac91acc767c2757f46ec319c0ff0 100644 (file)
@@ -1130,7 +1130,8 @@ extern "C" {
 bool
 brw_vs_emit(struct brw_context *brw,
             struct gl_shader_program *prog,
-            struct brw_vs_compile *c)
+            struct brw_vs_compile *c,
+            void *mem_ctx)
 {
    struct intel_context *intel = &brw->intel;
    bool start_busy = false;
@@ -1169,7 +1170,7 @@ brw_vs_emit(struct brw_context *brw,
       shader->compiled_once = true;
    }
 
-   vec4_visitor v(brw, c, prog, shader);
+   vec4_visitor v(brw, c, prog, shader, mem_ctx);
    if (!v.run()) {
       prog->LinkStatus = false;
       ralloc_strcat(&prog->InfoLog, v.fail_msg);
index f474b0f76213fb11a8b988b4c260b558a811834b..3d9d0dc504fe05f4b459775fcc8afcd0fd3eb394 100644 (file)
@@ -200,7 +200,9 @@ class vec4_visitor : public backend_visitor
 public:
    vec4_visitor(struct brw_context *brw,
                 struct brw_vs_compile *c,
-               struct gl_shader_program *prog, struct brw_shader *shader);
+               struct gl_shader_program *prog,
+               struct brw_shader *shader,
+               void *mem_ctx);
    ~vec4_visitor();
 
    dst_reg dst_null_f()
index 982b74c19ec250e3d44f0fc3a416c55866c90b3e..4579e0c45e7dc83d0a64a2601fa9a940247794a4 100644 (file)
@@ -2809,7 +2809,8 @@ vec4_visitor::resolve_ud_negate(src_reg *reg)
 vec4_visitor::vec4_visitor(struct brw_context *brw,
                           struct brw_vs_compile *c,
                           struct gl_shader_program *prog,
-                          struct brw_shader *shader)
+                          struct brw_shader *shader,
+                          void *mem_ctx)
 {
    this->c = c;
    this->p = &c->func;
@@ -2819,7 +2820,7 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
    this->prog = prog;
    this->shader = shader;
 
-   this->mem_ctx = ralloc_context(NULL);
+   this->mem_ctx = mem_ctx;
    this->failed = false;
 
    this->base_ir = NULL;
@@ -2849,7 +2850,6 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
 
 vec4_visitor::~vec4_visitor()
 {
-   ralloc_free(this->mem_ctx);
    hash_table_dtor(this->variable_ht);
 }
 
index ff91f4eadc014928725ca2f0d15c339a18929be6..b1b7a4f35a58453cec1adb69f28e56bb74218ddc 100644 (file)
@@ -279,7 +279,7 @@ do_vs_prog(struct brw_context *brw,
 
    /* Emit GEN4 code.
     */
-   if (!brw_vs_emit(brw, prog, &c)) {
+   if (!brw_vs_emit(brw, prog, &c, mem_ctx)) {
       ralloc_free(mem_ctx);
       return false;
    }
index 2c085474733b40acda1a2db53c37a215fbe2561d..d0e260e4e81f3900e8dcd11cea4df69358a77dcd 100644 (file)
@@ -105,7 +105,8 @@ struct brw_vs_compile {
 
 bool brw_vs_emit(struct brw_context *brw,
                  struct gl_shader_program *prog,
-                 struct brw_vs_compile *c);
+                 struct brw_vs_compile *c,
+                 void *mem_ctx);
 bool brw_vs_precompile(struct gl_context *ctx, struct gl_shader_program *prog);
 void brw_vs_debug_recompile(struct brw_context *brw,
                             struct gl_shader_program *prog,