From 8273bd46877e2ea2b8a02b87a11c68102d07e1f2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 4 Aug 2010 12:34:56 -0700 Subject: glsl2: Make the clone() method take a talloc context. In most cases, we needed to be reparenting the cloned IR to a different context (for example, to the linked shader instead of the unlinked shader), or optimization before the reparent would cause memory usage of the original object to grow and grow. --- src/glsl/linker.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/glsl/linker.cpp') diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index a5faff2be7..65f3697d35 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -323,7 +323,8 @@ cross_validate_globals(struct gl_shader_program *prog, * FINISHME: modify the shader, and linking with the second * FINISHME: will fail. */ - existing->constant_value = var->constant_value->clone(NULL); + existing->constant_value = + var->constant_value->clone(talloc_parent(existing), NULL); } } else variables.add_variable(var->name, var); @@ -488,16 +489,17 @@ populate_symbol_table(gl_shader *sh) * should be added. */ void -remap_variables(ir_instruction *inst, glsl_symbol_table *symbols, - exec_list *instructions, hash_table *temps) +remap_variables(ir_instruction *inst, struct gl_shader *target, + hash_table *temps) { class remap_visitor : public ir_hierarchical_visitor { public: - remap_visitor(glsl_symbol_table *symbols, exec_list *instructions, + remap_visitor(struct gl_shader *target, hash_table *temps) { - this->symbols = symbols; - this->instructions = instructions; + this->target = target; + this->symbols = target->symbols; + this->instructions = target->ir; this->temps = temps; } @@ -516,7 +518,7 @@ remap_variables(ir_instruction *inst, glsl_symbol_table *symbols, if (existing != NULL) ir->var = existing; else { - ir_variable *copy = ir->var->clone(NULL); + ir_variable *copy = ir->var->clone(this->target, NULL); this->symbols->add_variable(copy->name, copy); this->instructions->push_head(copy); @@ -527,12 +529,13 @@ remap_variables(ir_instruction *inst, glsl_symbol_table *symbols, } private: + struct gl_shader *target; glsl_symbol_table *symbols; exec_list *instructions; hash_table *temps; }; - remap_visitor v(symbols, instructions, temps); + remap_visitor v(target, temps); inst->accept(&v); } @@ -583,12 +586,12 @@ move_non_declarations(exec_list *instructions, exec_node *last, || ((var != NULL) && (var->mode == ir_var_temporary))); if (make_copies) { - inst = inst->clone(NULL); + inst = inst->clone(target, NULL); if (var != NULL) hash_table_insert(temps, inst, var); else - remap_variables(inst, target->symbols, target->ir, temps); + remap_variables(inst, target, temps); } else { inst->remove(); } @@ -713,7 +716,7 @@ link_intrastage_shaders(struct gl_shader_program *prog, gl_shader *const linked = _mesa_new_shader(NULL, 0, main->Type); linked->ir = new(linked) exec_list; - clone_ir_list(linked->ir, main->ir); + clone_ir_list(linked, linked->ir, main->ir); populate_symbol_table(linked); -- cgit v1.2.3