i965/fs: Factor out texcoord setup into a helper function.
authorKenneth Graunke <kenneth@whitecape.org>
Sun, 5 Aug 2012 03:40:42 +0000 (20:40 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 6 Aug 2012 18:16:09 +0000 (11:16 -0700)
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 <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_fs.h
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp

index 246dcf0f4e46b8f5b87624865080b4bcd5690f38..1d9c6863f3b47d262365edfba3b5a57cf480d2b1 100644 (file)
@@ -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,
index 08b7fb887aa213733acb38db835b7e56be9e7107..626686396865fd5460874cd2d1df4e3a9a60a24b 100644 (file)
@@ -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.