From: Eric Anholt Date: Mon, 19 Mar 2012 23:37:23 +0000 (-0700) Subject: glsl: Add a helper for generating temporary variables in ir_builder. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8bb0091e6838aeee2a5819850c334fde71b5a439;p=mesa.git glsl: Add a helper for generating temporary variables in ir_builder. Reviewed-by: Kenneth Graunke --- diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp index 0c8a15bc86e..9a16c90e5cd 100644 --- a/src/glsl/ir_builder.cpp +++ b/src/glsl/ir_builder.cpp @@ -34,6 +34,17 @@ ir_factory::emit(ir_instruction *ir) instructions->push_tail(ir); } +ir_variable * +ir_factory::make_temp(const glsl_type *type, const char *name) +{ + ir_variable *var; + + var = new(mem_ctx) ir_variable(type, name, ir_var_temporary); + emit(var); + + return var; +} + ir_assignment * assign(deref lhs, operand rhs, int writemask) { diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h index af9d1600f68..0ebcbab95c2 100644 --- a/src/glsl/ir_builder.h +++ b/src/glsl/ir_builder.h @@ -74,6 +74,7 @@ public: class ir_factory { public: void emit(ir_instruction *ir); + ir_variable *make_temp(const glsl_type *type, const char *name); exec_list *instructions; void *mem_ctx; diff --git a/src/mesa/main/ff_fragment_shader.cpp b/src/mesa/main/ff_fragment_shader.cpp index ee106cdc1da..3c91b1a42ad 100644 --- a/src/mesa/main/ff_fragment_shader.cpp +++ b/src/mesa/main/ff_fragment_shader.cpp @@ -823,11 +823,7 @@ emit_texenv(struct texenv_fragment_program *p, GLuint unit) else alpha_saturate = GL_FALSE; - ir_variable *temp_var = new(p->mem_ctx) ir_variable(glsl_type::vec4_type, - "texenv_combine", - ir_var_temporary); - p->emit(temp_var); - + ir_variable *temp_var = p->make_temp(glsl_type::vec4_type, "texenv_combine"); ir_dereference *deref; ir_rvalue *val; @@ -934,9 +930,8 @@ static void load_texture( struct texenv_fragment_program *p, GLuint unit ) } if (!p->state->unit[unit].enabled) { - p->src_texture[unit] = new(p->mem_ctx) ir_variable(glsl_type::vec4_type, - "dummy_tex", - ir_var_temporary); + p->src_texture[unit] = p->make_temp(glsl_type::vec4_type, + "dummy_tex"); p->emit(p->src_texture[unit]); p->emit(assign(p->src_texture[unit], new(p->mem_ctx) ir_constant(0.0f))); @@ -1001,10 +996,8 @@ static void load_texture( struct texenv_fragment_program *p, GLuint unit ) break; } - p->src_texture[unit] = new(p->mem_ctx) ir_variable(glsl_type::vec4_type, - "tex", - ir_var_temporary); - p->emit(p->src_texture[unit]); + p->src_texture[unit] = p->make_temp(glsl_type::vec4_type, + "tex"); ir_texture *tex = new(p->mem_ctx) ir_texture(ir_tex); @@ -1113,9 +1106,7 @@ load_texunit_bumpmap( struct texenv_fragment_program *p, GLuint unit ) texcoord = smear(p, texcoord); /* bump_texcoord = texcoord */ - ir_variable *bumped = new(p->mem_ctx) ir_variable(texcoord->type, - "bump_texcoord", - ir_var_temporary); + ir_variable *bumped = p->make_temp(texcoord->type, "bump_texcoord"); p->emit(bumped); p->emit(assign(bumped, texcoord)); @@ -1150,10 +1141,7 @@ emit_fog_instructions(struct texenv_fragment_program *p, * only affect rgb so we're hanging on to the .a value of fragcolor * this way. */ - ir_variable *fog_result = new(p->mem_ctx) ir_variable(glsl_type::vec4_type, - "fog_result", - ir_var_auto); - p->emit(fog_result); + ir_variable *fog_result = p->make_temp(glsl_type::vec4_type, "fog_result"); p->emit(assign(fog_result, fragcolor)); fragcolor = swizzle_xyz(fog_result); @@ -1163,9 +1151,7 @@ emit_fog_instructions(struct texenv_fragment_program *p, params = p->shader->symbols->get_variable("gl_Fog"); f = new(p->mem_ctx) ir_dereference_variable(fogcoord); - ir_variable *f_var = new(p->mem_ctx) ir_variable(glsl_type::float_type, - "fog_factor", ir_var_auto); - p->emit(f_var); + ir_variable *f_var = p->make_temp(glsl_type::float_type, "fog_factor"); switch (key->fog_mode) { case FOG_LINEAR: @@ -1194,10 +1180,7 @@ emit_fog_instructions(struct texenv_fragment_program *p, * can do this like FOG_EXP but with a squaring after the * multiply by density. */ - ir_variable *temp_var = new(p->mem_ctx) ir_variable(glsl_type::float_type, - "fog_temp", - ir_var_auto); - p->emit(temp_var); + ir_variable *temp_var = p->make_temp(glsl_type::float_type, "fog_temp"); p->emit(assign(temp_var, mul(f, swizzle_w(oparams)))); f = mul(temp_var, temp_var); @@ -1254,11 +1237,8 @@ emit_instructions(struct texenv_fragment_program *p) ir_rvalue *cf = get_source(p, SRC_PREVIOUS, 0); if (key->separate_specular) { - ir_variable *spec_result = new(p->mem_ctx) ir_variable(glsl_type::vec4_type, - "specular_add", - ir_var_temporary); - - p->emit(spec_result); + ir_variable *spec_result = p->make_temp(glsl_type::vec4_type, + "specular_add"); p->emit(assign(spec_result, cf)); ir_rvalue *secondary;