i965: Make the param pointer arrays for the WM dynamically sized.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_emit.c
index e27ff3528a89f3d524666d08d6ff7aae64634c66..b6defa3d59d90bca2979da66ee00c0005ed2c894 100644 (file)
@@ -297,13 +297,11 @@ void emit_pixel_w(struct brw_wm_compile *c,
       if (c->dispatch_width == 16) {
         brw_math_16(p, dst[3],
                     BRW_MATH_FUNCTION_INV,
-                    BRW_MATH_SATURATE_NONE,
                     2, src,
                     BRW_MATH_PRECISION_FULL);
       } else {
         brw_math(p, dst[3],
                  BRW_MATH_FUNCTION_INV,
-                 BRW_MATH_SATURATE_NONE,
                  2, src,
                  BRW_MATH_DATA_VECTOR,
                  BRW_MATH_PRECISION_FULL);
@@ -457,12 +455,16 @@ void emit_frontfacing(struct brw_compile *p,
  * between each other.  We could probably do it like ddx and swizzle the right
  * order later, but bail for now and just produce
  * ((ss0.tl - ss0.bl)x4 (ss1.tl - ss1.bl)x4)
+ *
+ * The negate_value boolean is used to negate the d/dy computation for FBOs,
+ * since they place the origin at the upper left instead of the lower left.
  */
 void emit_ddxy(struct brw_compile *p,
               const struct brw_reg *dst,
               GLuint mask,
               bool is_ddx,
-              const struct brw_reg *arg0)
+              const struct brw_reg *arg0,
+               bool negate_value)
 {
    int i;
    struct brw_reg src0, src1;
@@ -498,7 +500,10 @@ void emit_ddxy(struct brw_compile *p,
                           BRW_HORIZONTAL_STRIDE_0,
                           BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
         }
-        brw_ADD(p, dst[i], src0, negate(src1));
+         if (negate_value)
+            brw_ADD(p, dst[i], src1, negate(src0));
+         else
+            brw_ADD(p, dst[i], src0, negate(src1));
       }
    }
    if (mask & SATURATE)
@@ -883,9 +888,6 @@ void emit_math1(struct brw_wm_compile *c,
    struct brw_compile *p = &c->func;
    struct intel_context *intel = &p->brw->intel;
    int dst_chan = ffs(mask & WRITEMASK_XYZW) - 1;
-   GLuint saturate = ((mask & SATURATE) ?
-                     BRW_MATH_SATURATE_SATURATE :
-                     BRW_MATH_SATURATE_NONE);
    struct brw_reg src;
 
    if (!(mask & WRITEMASK_XYZW))
@@ -911,11 +913,11 @@ void emit_math1(struct brw_wm_compile *c,
    /* Send two messages to perform all 16 operations:
     */
    brw_push_insn_state(p);
+   brw_set_saturate(p, (mask & SATURATE) ? 1 : 0);
    brw_set_compression_control(p, BRW_COMPRESSION_NONE);
    brw_math(p,
            dst[dst_chan],
            function,
-           saturate,
            2,
            src,
            BRW_MATH_DATA_VECTOR,
@@ -926,7 +928,6 @@ void emit_math1(struct brw_wm_compile *c,
       brw_math(p,
               offset(dst[dst_chan],1),
               function,
-              saturate,
               3,
               sechalf(src),
               BRW_MATH_DATA_VECTOR,
@@ -998,10 +999,6 @@ void emit_math2(struct brw_wm_compile *c,
                   sechalf(src1));
       }
    } else {
-      GLuint saturate = ((mask & SATURATE) ?
-                        BRW_MATH_SATURATE_SATURATE :
-                        BRW_MATH_SATURATE_NONE);
-
       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
       brw_MOV(p, brw_message_reg(3), arg1[0]);
       if (c->dispatch_width == 16) {
@@ -1009,11 +1006,11 @@ void emit_math2(struct brw_wm_compile *c,
         brw_MOV(p, brw_message_reg(5), sechalf(arg1[0]));
       }
 
+      brw_set_saturate(p, (mask & SATURATE) ? 1 : 0);
       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
       brw_math(p,
               dst[dst_chan],
               function,
-              saturate,
               2,
               arg0[0],
               BRW_MATH_DATA_VECTOR,
@@ -1026,7 +1023,6 @@ void emit_math2(struct brw_wm_compile *c,
         brw_math(p,
                  offset(dst[dst_chan],1),
                  function,
-                 saturate,
                  4,
                  sechalf(arg0[0]),
                  BRW_MATH_DATA_VECTOR,
@@ -1746,11 +1742,15 @@ void brw_wm_emit( struct brw_wm_compile *c )
         break;
 
       case OPCODE_DDX:
-        emit_ddxy(p, dst, dst_flags, true, args[0]);
+        emit_ddxy(p, dst, dst_flags, true, args[0], false);
         break;
 
       case OPCODE_DDY:
-        emit_ddxy(p, dst, dst_flags, false, args[0]);
+         /* Make sure fp->program.UsesDFdy flag got set (otherwise there's no
+          * guarantee that c->key.render_to_fbo is set).
+          */
+         assert(c->fp->program.UsesDFdy);
+        emit_ddxy(p, dst, dst_flags, false, args[0], c->key.render_to_fbo);
         break;
 
       case OPCODE_DP2: