Mesa (master): i965/fs: Refactor texture result swizzling into a helper function.

Kenneth Graunke kwg at kemper.freedesktop.org
Sun Jun 19 00:54:25 UTC 2011


Module: Mesa
Branch: master
Commit: 01fa9addf447120e994415ad8fc8246ac234ec27
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=01fa9addf447120e994415ad8fc8246ac234ec27

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Jun 10 14:45:24 2011 -0700

i965/fs: Refactor texture result swizzling into a helper function.

The next patch will add a few additional uses.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/mesa/drivers/dri/i965/brw_fs.h           |    2 +
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |   28 +++++++++++++++++--------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 7570dda..2bf850e 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -441,6 +441,8 @@ public:
    void visit(ir_function *ir);
    void visit(ir_function_signature *ir);
 
+   void swizzle_result(ir_texture *ir, fs_reg orig_val, int sampler);
+
    fs_inst *emit(fs_inst inst);
 
    fs_inst *emit(int opcode)
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index ac24375..35bda58 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1045,20 +1045,30 @@ fs_visitor::visit(ir_texture *ir)
 
    inst->sampler = sampler;
 
-   this->result = dst;
-
    if (ir->shadow_comparitor)
       inst->shadow_compare = true;
 
+   swizzle_result(ir, dst, sampler);
+}
+
+/**
+ * Swizzle the result of a texture result.  This is necessary for
+ * EXT_texture_swizzle as well as DEPTH_TEXTURE_MODE for shadow comparisons.
+ */
+void
+fs_visitor::swizzle_result(ir_texture *ir, fs_reg orig_val, int sampler)
+{
+   this->result = orig_val;
+
    if (ir->type == glsl_type::float_type) {
       /* Ignore DEPTH_TEXTURE_MODE swizzling. */
       assert(ir->sampler->type->sampler_shadow);
-   } else if (c->key.tex_swizzles[inst->sampler] != SWIZZLE_NOOP) {
-      fs_reg swizzle_dst = fs_reg(this, glsl_type::vec4_type);
+   } else if (c->key.tex_swizzles[sampler] != SWIZZLE_NOOP) {
+      fs_reg swizzled_result = fs_reg(this, glsl_type::vec4_type);
 
       for (int i = 0; i < 4; i++) {
-	 int swiz = GET_SWZ(c->key.tex_swizzles[inst->sampler], i);
-	 fs_reg l = swizzle_dst;
+	 int swiz = GET_SWZ(c->key.tex_swizzles[sampler], i);
+	 fs_reg l = swizzled_result;
 	 l.reg_offset += i;
 
 	 if (swiz == SWIZZLE_ZERO) {
@@ -1066,12 +1076,12 @@ fs_visitor::visit(ir_texture *ir)
 	 } else if (swiz == SWIZZLE_ONE) {
 	    emit(BRW_OPCODE_MOV, l, fs_reg(1.0f));
 	 } else {
-	    fs_reg r = dst;
-	    r.reg_offset += GET_SWZ(c->key.tex_swizzles[inst->sampler], i);
+	    fs_reg r = orig_val;
+	    r.reg_offset += GET_SWZ(c->key.tex_swizzles[sampler], i);
 	    emit(BRW_OPCODE_MOV, l, r);
 	 }
       }
-      this->result = swizzle_dst;
+      this->result = swizzled_result;
    }
 }
 




More information about the mesa-commit mailing list