From 27bf9c1997b77f85c2099436e9ad5dfc0f1608c7 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 4 Aug 2012 20:40:42 -0700 Subject: [PATCH] i965/fs: Factor out texcoord setup into a helper function. With the textureRect support and GL_CLAMP workarounds, it's grown sufficiently that it deserves its own function. Separating it out makes the original function much more readable. Signed-off-by: Kenneth Graunke Reviewed-by: Eric Anholt --- src/mesa/drivers/dri/i965/brw_fs.h | 1 + src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 38 ++++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h index 246dcf0f4e4..1d9c6863f3b 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.h +++ b/src/mesa/drivers/dri/i965/brw_fs.h @@ -304,6 +304,7 @@ public: fs_reg *emit_general_interpolation(ir_variable *ir); void emit_interpolation_setup_gen4(); void emit_interpolation_setup_gen6(); + fs_reg emit_texcoord(ir_texture *ir, int sampler); fs_inst *emit_texture_gen4(ir_texture *ir, fs_reg dst, fs_reg coordinate, int sampler); fs_inst *emit_texture_gen5(ir_texture *ir, fs_reg dst, fs_reg coordinate, diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp index 08b7fb887aa..62668639686 100644 --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp @@ -1155,21 +1155,23 @@ fs_visitor::emit_texture_gen7(ir_texture *ir, fs_reg dst, fs_reg coordinate, return inst; } -void -fs_visitor::visit(ir_texture *ir) +/** + * Emit code to produce the coordinates for a texture lookup. + * + * Returns the fs_reg containing the texture coordinate (as opposed to + * setting this->result). + */ +fs_reg +fs_visitor::emit_texcoord(ir_texture *ir, int sampler) { fs_inst *inst = NULL; - int sampler = _mesa_get_sampler_uniform_value(ir->sampler, prog, &fp->Base); - sampler = fp->Base.SamplerUnits[sampler]; + if (!ir->coordinate) + return fs_reg(); /* Return the default BAD_FILE register. */ - if (ir->coordinate) - ir->coordinate->accept(this); + ir->coordinate->accept(this); fs_reg coordinate = this->result; - /* Should be lowered by do_lower_texture_projection */ - assert(!ir->projector); - bool needs_gl_clamp = true; fs_reg scale_x, scale_y; @@ -1193,8 +1195,7 @@ fs_visitor::visit(ir_texture *ir) if (c->dispatch_width == 16) { fail("rectangle scale uniform setup not supported on 16-wide\n"); - this->result = fs_reg(this, ir->type); - return; + return fs_reg(this, ir->type); } scale_x = fs_reg(UNIFORM, c->prog_data.nr_params); @@ -1269,6 +1270,21 @@ fs_visitor::visit(ir_texture *ir) } } } + return coordinate; +} + +void +fs_visitor::visit(ir_texture *ir) +{ + fs_inst *inst = NULL; + + int sampler = _mesa_get_sampler_uniform_value(ir->sampler, prog, &fp->Base); + sampler = fp->Base.SamplerUnits[sampler]; + + /* Should be lowered by do_lower_texture_projection */ + assert(!ir->projector); + + fs_reg coordinate = emit_texcoord(ir, sampler); /* Writemasking doesn't eliminate channels on SIMD8 texture * samples, so don't worry about them. -- 2.30.2