i965: Drop the confusing saturate argument to math instruction setup.
authorEric Anholt <eric@anholt.net>
Mon, 6 Aug 2012 21:59:39 +0000 (14:59 -0700)
committerEric Anholt <eric@anholt.net>
Wed, 8 Aug 2012 23:21:30 +0000 (16:21 -0700)
This was ridiculous.  We were ignoring the inst->header.saturate flag in the
case of math and only math.  On gen4, we would leave inst->header.saturate in
place if it happened to be set, which would end up being applied to the
implicit mov and thus trash the first argument.  On gen6, we would overwrite
inst->header.saturate with the saturate flag from the argument, which was not
set appropriately in brw_vec4_emit.cpp, and was only not a bug due to our
incompetence at coalescing saturate moves.

By ripping the argument out and making saturate work just like all the other
brw_eu_emit.c code generation, we can avoid both these classes of bugs.

Fixes piglit fog-modes, and the new specific fs-saturate-exp2 case.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48628
NOTE: This is a candidate for the 8.0 branch.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_eu.h
src/mesa/drivers/dri/i965/brw_eu_emit.c
src/mesa/drivers/dri/i965/brw_eu_util.c
src/mesa/drivers/dri/i965/brw_fs_emit.cpp
src/mesa/drivers/dri/i965/brw_sf_emit.c
src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
src/mesa/drivers/dri/i965/brw_vs_emit.c
src/mesa/drivers/dri/i965/brw_wm_emit.c

index 3ab00a263ebfdeb936d1133b132d42fadc15620a..e0e02d4f1031b06477130e8d925df3fad865b077 100644 (file)
@@ -975,7 +975,6 @@ void brw_SAMPLE(struct brw_compile *p,
 void brw_math_16( struct brw_compile *p,
                  struct brw_reg dest,
                  GLuint function,
-                 GLuint saturate,
                  GLuint msg_reg_nr,
                  struct brw_reg src,
                  GLuint precision );
@@ -983,7 +982,6 @@ void brw_math_16( struct brw_compile *p,
 void brw_math( struct brw_compile *p,
               struct brw_reg dest,
               GLuint function,
-              GLuint saturate,
               GLuint msg_reg_nr,
               struct brw_reg src,
               GLuint data_type,
index 25bf91be532b1e26572cc9f5a5c8d77ee8780213..b82a858d9a72fc96f77a45504d9f7204fbaaa4d0 100644 (file)
@@ -429,7 +429,6 @@ static void brw_set_math_message( struct brw_compile *p,
                                  GLuint function,
                                  GLuint integer_type,
                                  bool low_precision,
-                                 bool saturate,
                                  GLuint dataType )
 {
    struct brw_context *brw = p->brw;
@@ -461,22 +460,24 @@ static void brw_set_math_message( struct brw_compile *p,
       break;
    }
 
+
    brw_set_message_descriptor(p, insn, BRW_SFID_MATH,
                              msg_length, response_length, false, false);
    if (intel->gen == 5) {
       insn->bits3.math_gen5.function = function;
       insn->bits3.math_gen5.int_type = integer_type;
       insn->bits3.math_gen5.precision = low_precision;
-      insn->bits3.math_gen5.saturate = saturate;
+      insn->bits3.math_gen5.saturate = insn->header.saturate;
       insn->bits3.math_gen5.data_type = dataType;
       insn->bits3.math_gen5.snapshot = 0;
    } else {
       insn->bits3.math.function = function;
       insn->bits3.math.int_type = integer_type;
       insn->bits3.math.precision = low_precision;
-      insn->bits3.math.saturate = saturate;
+      insn->bits3.math.saturate = insn->header.saturate;
       insn->bits3.math.data_type = dataType;
    }
+   insn->header.saturate = 0;
 }
 
 
@@ -1657,7 +1658,6 @@ void brw_WAIT (struct brw_compile *p)
 void brw_math( struct brw_compile *p,
               struct brw_reg dest,
               GLuint function,
-              GLuint saturate,
               GLuint msg_reg_nr,
               struct brw_reg src,
               GLuint data_type,
@@ -1693,7 +1693,6 @@ void brw_math( struct brw_compile *p,
        * becomes FC[3:0] and ThreadCtrl becomes FC[5:4].
        */
       insn->header.destreg__conditionalmod = function;
-      insn->header.saturate = saturate;
 
       brw_set_dest(p, insn, dest);
       brw_set_src0(p, insn, src);
@@ -1714,7 +1713,6 @@ void brw_math( struct brw_compile *p,
                           function,
                           src.type == BRW_REGISTER_TYPE_D,
                           precision,
-                          saturate,
                           data_type);
    }
 }
@@ -1779,7 +1777,6 @@ void brw_math2(struct brw_compile *p,
 void brw_math_16( struct brw_compile *p,
                  struct brw_reg dest,
                  GLuint function,
-                 GLuint saturate,
                  GLuint msg_reg_nr,
                  struct brw_reg src,
                  GLuint precision )
@@ -1794,7 +1791,6 @@ void brw_math_16( struct brw_compile *p,
        * becomes FC[3:0] and ThreadCtrl becomes FC[5:4].
        */
       insn->header.destreg__conditionalmod = function;
-      insn->header.saturate = saturate;
 
       /* Source modifiers are ignored for extended math instructions. */
       assert(!src.negate);
@@ -1822,7 +1818,6 @@ void brw_math_16( struct brw_compile *p,
                        function,
                        BRW_MATH_INTEGER_UNSIGNED,
                        precision,
-                       saturate,
                        BRW_MATH_DATA_VECTOR);
 
    /* Second instruction:
@@ -1838,7 +1833,6 @@ void brw_math_16( struct brw_compile *p,
                        function,
                        BRW_MATH_INTEGER_UNSIGNED,
                        precision,
-                       saturate,
                        BRW_MATH_DATA_VECTOR);
 
    brw_pop_insn_state(p);
index 5405cf17a4eb4a4e407af0ef18010d37b4e7ea17..2037634981c596f17ecf0c2936ad2844a95d5771 100644 (file)
@@ -42,7 +42,6 @@ void brw_math_invert( struct brw_compile *p,
    brw_math( p, 
             dst,
             BRW_MATH_FUNCTION_INV, 
-            BRW_MATH_SATURATE_NONE,
             0,
             src,
             BRW_MATH_PRECISION_FULL, 
index a5cebcb32e695f24f40474ec375cf644cfe4ae2e..4564e3b42e926867d5036103bd1c085dddb46c1c 100644 (file)
@@ -160,8 +160,6 @@ fs_visitor::generate_math1_gen7(fs_inst *inst,
    assert(inst->mlen == 0);
    brw_math(p, dst,
            brw_math_function(inst->opcode),
-           inst->saturate ? BRW_MATH_SATURATE_SATURATE
-                          : BRW_MATH_SATURATE_NONE,
            0, src0,
            BRW_MATH_DATA_VECTOR,
            BRW_MATH_PRECISION_FULL);
@@ -189,8 +187,6 @@ fs_visitor::generate_math1_gen6(fs_inst *inst,
    brw_set_compression_control(p, BRW_COMPRESSION_NONE);
    brw_math(p, dst,
            op,
-           inst->saturate ? BRW_MATH_SATURATE_SATURATE :
-           BRW_MATH_SATURATE_NONE,
            0, src0,
            BRW_MATH_DATA_VECTOR,
            BRW_MATH_PRECISION_FULL);
@@ -199,8 +195,6 @@ fs_visitor::generate_math1_gen6(fs_inst *inst,
       brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
       brw_math(p, sechalf(dst),
               op,
-              inst->saturate ? BRW_MATH_SATURATE_SATURATE :
-              BRW_MATH_SATURATE_NONE,
               0, sechalf(src0),
               BRW_MATH_DATA_VECTOR,
               BRW_MATH_PRECISION_FULL);
@@ -240,8 +234,6 @@ fs_visitor::generate_math_gen4(fs_inst *inst,
    brw_set_compression_control(p, BRW_COMPRESSION_NONE);
    brw_math(p, dst,
            op,
-           inst->saturate ? BRW_MATH_SATURATE_SATURATE :
-           BRW_MATH_SATURATE_NONE,
            inst->base_mrf, src,
            BRW_MATH_DATA_VECTOR,
            BRW_MATH_PRECISION_FULL);
@@ -250,8 +242,6 @@ fs_visitor::generate_math_gen4(fs_inst *inst,
       brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
       brw_math(p, sechalf(dst),
               op,
-              inst->saturate ? BRW_MATH_SATURATE_SATURATE :
-              BRW_MATH_SATURATE_NONE,
               inst->base_mrf + 1, sechalf(src),
               BRW_MATH_DATA_VECTOR,
               BRW_MATH_PRECISION_FULL);
index ff6383bb188bb51d5dd4c41730cafe649d0fa67e..5f3673bec08817bbe087f24b995d46840f4eceb5 100644 (file)
@@ -314,7 +314,6 @@ static void invert_det( struct brw_sf_compile *c)
    brw_math(&c->func, 
            c->inv_det, 
            BRW_MATH_FUNCTION_INV,
-           BRW_MATH_SATURATE_NONE,
            0, 
            c->det,
            BRW_MATH_DATA_SCALAR,
@@ -599,7 +598,6 @@ void brw_emit_point_sprite_setup(struct brw_sf_compile *c, bool allocate)
         brw_math(&c->func,
                  c->tmp,
                  BRW_MATH_FUNCTION_INV,
-                 BRW_MATH_SATURATE_NONE,
                  0,
                  c->dx0,
                  BRW_MATH_DATA_SCALAR,
index 7658bb864549632e2fc7f9b803ce42c46cd0ff9c..21eafcbcb5df1f74d9a4596d314843d5d9ef8055 100644 (file)
@@ -262,7 +262,6 @@ vec4_visitor::generate_math1_gen4(vec4_instruction *inst,
    brw_math(p,
            dst,
            brw_math_function(inst->opcode),
-           BRW_MATH_SATURATE_NONE,
            inst->base_mrf,
            src,
            BRW_MATH_DATA_VECTOR,
@@ -291,7 +290,6 @@ vec4_visitor::generate_math1_gen6(vec4_instruction *inst,
    brw_math(p,
            dst,
            brw_math_function(inst->opcode),
-           BRW_MATH_SATURATE_NONE,
            inst->base_mrf,
            src,
            BRW_MATH_DATA_SCALAR,
@@ -355,7 +353,6 @@ vec4_visitor::generate_math2_gen4(vec4_instruction *inst,
    brw_math(p,
            dst,
            brw_math_function(inst->opcode),
-           BRW_MATH_SATURATE_NONE,
            inst->base_mrf,
            op0,
            BRW_MATH_DATA_VECTOR,
index d0ee5f3b4b7775e7904cd234adc82721f0ae22c2..6169f73741735cb9e4414403cfb1cb32c4954c2b 100644 (file)
@@ -670,7 +670,6 @@ static void emit_math1_gen4(struct brw_vs_compile *c,
    brw_math(p, 
            tmp,
            function,
-           BRW_MATH_SATURATE_NONE,
            2,
            arg0,
            BRW_MATH_DATA_SCALAR,
@@ -705,7 +704,6 @@ emit_math1_gen6(struct brw_vs_compile *c,
    brw_math(p,
            tmp_dst,
            function,
-           BRW_MATH_SATURATE_NONE,
            2,
            tmp_src,
            BRW_MATH_DATA_SCALAR,
@@ -757,7 +755,6 @@ static void emit_math2_gen4( struct brw_vs_compile *c,
    brw_math(p, 
            tmp,
            function,
-           BRW_MATH_SATURATE_NONE,
            2,
            arg0,
            BRW_MATH_DATA_SCALAR,
index 61f66e7ccddb6a8bd2c3c585887b040147483da2..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);
@@ -890,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))
@@ -918,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,
@@ -933,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,
@@ -1005,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) {
@@ -1016,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,
@@ -1033,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,