[Mesa-dev] [PATCH 6/8] i965/fs: Refactor DEPTH_TEXTURE_MODE swizzling into a helper function.

Kenneth Graunke kenneth at whitecape.org
Wed Jun 15 01:24:53 PDT 2011


The next patch will add a few additional uses.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_fs.h           |    2 ++
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp |   25 ++++++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 7570dda..e9068b2 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_shadow_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 63fd91d..03687ce 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1047,15 +1047,26 @@ fs_visitor::visit(ir_texture *ir)
    if (ir->shadow_comparitor)
       inst->shadow_compare = true;
 
+   swizzle_shadow_result(ir, dst, sampler);
+}
+
+/**
+ * Swizzle the result of a shadow comparison based on DEPTH_TEXTURE_MODE.
+ * The hardware returns the comparison result splatted across all four
+ * channels; for */
+void
+fs_visitor::swizzle_shadow_result(ir_texture *ir, fs_reg orig_val, int sampler)
+{
    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);
+      this->result = orig_val;
+   } 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) {
@@ -1063,12 +1074,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;
    }
 }
 
-- 
1.7.5.4



More information about the mesa-dev mailing list