i965: When doing a swizzled kill pixel, don't do redundant channel compares.
authorEric Anholt <eric@anholt.net>
Wed, 10 Mar 2010 23:44:32 +0000 (15:44 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 12 Mar 2010 23:12:01 +0000 (15:12 -0800)
This was obvious when looking at the compiled output of ETQW's
shaders.

src/mesa/drivers/dri/i965/brw_wm_emit.c

index b16957601747f86c810549d56df20cfadd70f74c..3a4057bb6b876f5ed8863c859c2f50cca67a0721 100644 (file)
@@ -1110,11 +1110,19 @@ static void emit_kil( struct brw_wm_compile *c,
 {
    struct brw_compile *p = &c->func;
    struct brw_reg r0uw = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW);
-   GLuint i;
-   
-   /* XXX - usually won't need 4 compares!
-    */
+   GLuint i, j;
+
    for (i = 0; i < 4; i++) {
+      /* Check if we've already done the comparison for this reg
+       * -- common when someone does KIL TEMP.wwww.
+       */
+      for (j = 0; j < i; j++) {
+        if (memcmp(&arg0[j], &arg0[i], sizeof(arg0[0])) == 0)
+           break;
+      }
+      if (j != i)
+        continue;
+
       brw_push_insn_state(p);
       brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_GE, arg0[i], brw_imm_f(0));   
       brw_set_predicate_control_flag_value(p, 0xff);