i965/drm: Rewrite relocation handling.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_clip_tri.c
index bea08530ec01d087c7815c9effd3934821c58dcc..d98e1ccb5f00941e196d4649d9545666ce50cdb7 100644 (file)
@@ -1,8 +1,8 @@
 /*
  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ Intel funded Tungsten Graphics to
  develop this 3D driver.
+
  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:
+
  The above copyright notice and this permission notice (including the
  next paragraph) shall be included in all copies or substantial
  portions of the Software.
+
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
  **********************************************************************/
  /*
   * Authors:
-  *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Keith Whitwell <keithw@vmware.com>
   */
 
-#include "main/glheader.h"
 #include "main/macros.h"
 #include "main/enums.h"
 #include "program/program.h"
@@ -38,7 +37,6 @@
 
 #include "brw_defines.h"
 #include "brw_context.h"
-#include "brw_eu.h"
 #include "brw_clip.h"
 
 static void release_tmps( struct brw_clip_compile *c )
@@ -47,10 +45,10 @@ static void release_tmps( struct brw_clip_compile *c )
 }
 
 
-void brw_clip_tri_alloc_regs( struct brw_clip_compile *c, 
+void brw_clip_tri_alloc_regs( struct brw_clip_compile *c,
                              GLuint nr_verts )
 {
-   struct brw_context *brw = c->func.brw;
+   const struct gen_device_info *devinfo = c->func.devinfo;
    GLuint i = 0,j;
 
    /* Register usage is static, precompute here:
@@ -106,7 +104,7 @@ void brw_clip_tri_alloc_regs( struct brw_clip_compile *c,
    i++;
 
    if (!c->key.nr_userclip) {
-      c->reg.fixed_planes = brw_vec8_grf(i, 0); 
+      c->reg.fixed_planes = brw_vec8_grf(i, 0);
       i++;
    }
 
@@ -120,9 +118,10 @@ void brw_clip_tri_alloc_regs( struct brw_clip_compile *c,
    }
 
    c->reg.vertex_src_mask = retype(brw_vec1_grf(i, 0), BRW_REGISTER_TYPE_UD);
+   c->reg.clipdistance_offset = retype(brw_vec1_grf(i, 1), BRW_REGISTER_TYPE_W);
    i++;
 
-   if (brw->gen == 5) {
+   if (devinfo->gen == 5) {
       c->reg.ff_sync = retype(brw_vec1_grf(i, 0), BRW_REGISTER_TYPE_UD);
       i++;
    }
@@ -138,15 +137,15 @@ void brw_clip_tri_alloc_regs( struct brw_clip_compile *c,
 
 void brw_clip_tri_init_vertices( struct brw_clip_compile *c )
 {
-   struct brw_compile *p = &c->func;
+   struct brw_codegen *p = &c->func;
    struct brw_reg tmp0 = c->reg.loopcount; /* handy temporary */
 
    /* Initial list of indices for incoming vertexes:
     */
-   brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK)); 
-   brw_CMP(p, 
-          vec1(brw_null_reg()), 
-          BRW_CONDITIONAL_EQ, 
+   brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK));
+   brw_CMP(p,
+          vec1(brw_null_reg()),
+          BRW_CONDITIONAL_EQ,
           tmp0,
           brw_imm_ud(_3DPRIM_TRISTRIP_REVERSE));
 
@@ -154,7 +153,7 @@ void brw_clip_tri_init_vertices( struct brw_clip_compile *c )
     * second tristrip element:  Can ignore sometimes?
     */
    brw_IF(p, BRW_EXECUTE_1);
-   {   
+   {
       brw_MOV(p, get_element(c->reg.inlist, 0),  brw_address(c->reg.vertex[1]) );
       brw_MOV(p, get_element(c->reg.inlist, 1),  brw_address(c->reg.vertex[0]) );
       if (c->need_direction)
@@ -178,20 +177,20 @@ void brw_clip_tri_init_vertices( struct brw_clip_compile *c )
 
 void brw_clip_tri_flat_shade( struct brw_clip_compile *c )
 {
-   struct brw_compile *p = &c->func;
+   struct brw_codegen *p = &c->func;
    struct brw_reg tmp0 = c->reg.loopcount; /* handy temporary */
 
-   brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK)); 
-   brw_CMP(p, 
-          vec1(brw_null_reg()), 
-          BRW_CONDITIONAL_EQ, 
+   brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK));
+   brw_CMP(p,
+          vec1(brw_null_reg()),
+          BRW_CONDITIONAL_EQ,
           tmp0,
           brw_imm_ud(_3DPRIM_POLYGON));
 
    brw_IF(p, BRW_EXECUTE_1);
    {
-      brw_clip_copy_colors(c, 1, 0);
-      brw_clip_copy_colors(c, 2, 0);
+      brw_clip_copy_flatshaded_attributes(c, 1, 0);
+      brw_clip_copy_flatshaded_attributes(c, 2, 0);
    }
    brw_ELSE(p);
    {
@@ -203,48 +202,55 @@ void brw_clip_tri_flat_shade( struct brw_clip_compile *c )
                 brw_imm_ud(_3DPRIM_TRIFAN));
         brw_IF(p, BRW_EXECUTE_1);
         {
-           brw_clip_copy_colors(c, 0, 1);
-           brw_clip_copy_colors(c, 2, 1);
+           brw_clip_copy_flatshaded_attributes(c, 0, 1);
+           brw_clip_copy_flatshaded_attributes(c, 2, 1);
         }
         brw_ELSE(p);
         {
-           brw_clip_copy_colors(c, 1, 0);
-           brw_clip_copy_colors(c, 2, 0);
+           brw_clip_copy_flatshaded_attributes(c, 1, 0);
+           brw_clip_copy_flatshaded_attributes(c, 2, 0);
         }
         brw_ENDIF(p);
       }
       else {
-         brw_clip_copy_colors(c, 0, 2);
-         brw_clip_copy_colors(c, 1, 2);
+         brw_clip_copy_flatshaded_attributes(c, 0, 2);
+         brw_clip_copy_flatshaded_attributes(c, 1, 2);
       }
    }
    brw_ENDIF(p);
 }
 
 
+/**
+ * Loads the clip distance for a vertex into `dst`, and ends with
+ * a comparison of it to zero with the condition `cond`.
+ *
+ * - If using a fixed plane, the distance is dot(hpos, plane).
+ * - If using a user clip plane, the distance is directly available in the vertex.
+ */
 static inline void
-load_vertex_pos(struct brw_clip_compile *c, struct brw_indirect vtx,
-                struct brw_reg dst,
-                GLuint hpos_offset, GLuint clip_offset)
+load_clip_distance(struct brw_clip_compile *c, struct brw_indirect vtx,
+                struct brw_reg dst, GLuint hpos_offset, int cond)
 {
-   struct brw_compile *p = &c->func;
+   struct brw_codegen *p = &c->func;
 
-   /*
-    * Roughly:
-    * dst = (vertex_src_mask & 1) ? src.hpos : src.clipvertex;
-    */
-
-   brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
+   dst = vec4(dst);
    brw_AND(p, vec1(brw_null_reg()), c->reg.vertex_src_mask, brw_imm_ud(1));
+   brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
    brw_IF(p, BRW_EXECUTE_1);
    {
-      brw_MOV(p, dst, deref_4f(vtx, clip_offset));
+      struct brw_indirect temp_ptr = brw_indirect(7, 0);
+      brw_ADD(p, get_addr_reg(temp_ptr), get_addr_reg(vtx), c->reg.clipdistance_offset);
+      brw_MOV(p, vec1(dst), deref_1f(temp_ptr, 0));
    }
    brw_ELSE(p);
    {
       brw_MOV(p, dst, deref_4f(vtx, hpos_offset));
+      brw_DP4(p, dst, dst, c->reg.plane_equation);
    }
    brw_ENDIF(p);
+
+   brw_CMP(p, brw_null_reg(), cond, vec1(dst), brw_imm_f(0.0f));
 }
 
 
@@ -252,7 +258,7 @@ load_vertex_pos(struct brw_clip_compile *c, struct brw_indirect vtx,
  */
 void brw_clip_tri( struct brw_clip_compile *c )
 {
-   struct brw_compile *p = &c->func;
+   struct brw_codegen *p = &c->func;
    struct brw_indirect vtx = brw_indirect(0, 0);
    struct brw_indirect vtxPrev = brw_indirect(1, 0);
    struct brw_indirect vtxOut = brw_indirect(2, 0);
@@ -261,9 +267,9 @@ void brw_clip_tri( struct brw_clip_compile *c )
    struct brw_indirect outlist_ptr = brw_indirect(5, 0);
    struct brw_indirect freelist_ptr = brw_indirect(6, 0);
    GLuint hpos_offset = brw_varying_to_offset(&c->vue_map, VARYING_SLOT_POS);
-   GLuint clipvert_offset = brw_clip_have_varying(c, VARYING_SLOT_CLIP_VERTEX)
-      ? brw_varying_to_offset(&c->vue_map, VARYING_SLOT_CLIP_VERTEX)
-      : hpos_offset;
+   GLint clipdist0_offset = c->key.nr_userclip
+      ? brw_varying_to_offset(&c->vue_map, VARYING_SLOT_CLIP_DIST0)
+      : 0;
 
    brw_MOV(p, get_addr_reg(vtxPrev),     brw_address(c->reg.vertex[2]) );
    brw_MOV(p, get_addr_reg(plane_ptr),   brw_clip_plane0_address(c));
@@ -273,20 +279,24 @@ void brw_clip_tri( struct brw_clip_compile *c )
    brw_MOV(p, get_addr_reg(freelist_ptr), brw_address(c->reg.vertex[3]) );
 
    /* Set the initial vertex source mask: The first 6 planes are the bounds
-    * of the view volume; the next 6 planes are the user clipping planes.
+    * of the view volume; the next 8 planes are the user clipping planes.
     */
-   brw_MOV(p, c->reg.vertex_src_mask, brw_imm_ud(0xfc0));
+   brw_MOV(p, c->reg.vertex_src_mask, brw_imm_ud(0x3fc0));
+
+   /* Set the initial clipdistance offset to be 6 floats before gl_ClipDistance[0].
+    * We'll increment 6 times before we start hitting actual user clipping. */
+   brw_MOV(p, c->reg.clipdistance_offset, brw_imm_d(clipdist0_offset - 6*sizeof(float)));
 
    brw_DO(p, BRW_EXECUTE_1);
    {
       /* if (planemask & 1)
        */
-      brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
       brw_AND(p, vec1(brw_null_reg()), c->reg.planemask, brw_imm_ud(1));
-      
+      brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
+
       brw_IF(p, BRW_EXECUTE_1);
       {
-        /* vtxOut = freelist_ptr++ 
+        /* vtxOut = freelist_ptr++
          */
         brw_MOV(p, get_addr_reg(vtxOut),       get_addr_reg(freelist_ptr) );
         brw_ADD(p, get_addr_reg(freelist_ptr), get_addr_reg(freelist_ptr), brw_imm_uw(c->nr_regs * REG_SIZE));
@@ -295,7 +305,7 @@ void brw_clip_tri( struct brw_clip_compile *c )
            brw_MOV(p, c->reg.plane_equation, deref_4f(plane_ptr, 0));
         else
            brw_MOV(p, c->reg.plane_equation, deref_4b(plane_ptr, 0));
-           
+
         brw_MOV(p, c->reg.loopcount, c->reg.nr_verts);
         brw_MOV(p, c->reg.nr_verts, brw_imm_ud(0));
 
@@ -305,17 +315,13 @@ void brw_clip_tri( struct brw_clip_compile *c )
             */
            brw_MOV(p, get_addr_reg(vtx), deref_1uw(inlist_ptr, 0));
 
-            load_vertex_pos(c, vtxPrev, vec4(c->reg.dpPrev), hpos_offset, clipvert_offset);
-           /* IS_NEGATIVE(prev) */
-           brw_set_conditionalmod(p, BRW_CONDITIONAL_L);
-           brw_DP4(p, vec4(c->reg.dpPrev), vec4(c->reg.dpPrev), c->reg.plane_equation);
+            load_clip_distance(c, vtxPrev, c->reg.dpPrev, hpos_offset, BRW_CONDITIONAL_L);
+           /* (prev < 0.0f) */
            brw_IF(p, BRW_EXECUTE_1);
            {
-               load_vertex_pos(c, vtx, vec4(c->reg.dp), hpos_offset, clipvert_offset);
+               load_clip_distance(c, vtx, c->reg.dp, hpos_offset, BRW_CONDITIONAL_GE);
               /* IS_POSITIVE(next)
                */
-              brw_set_conditionalmod(p, BRW_CONDITIONAL_GE);
-              brw_DP4(p, vec4(c->reg.dp), vec4(c->reg.dp), c->reg.plane_equation);
               brw_IF(p, BRW_EXECUTE_1);
               {
 
@@ -328,13 +334,14 @@ void brw_clip_tri( struct brw_clip_compile *c )
                  /* If (vtxOut == 0) vtxOut = vtxPrev
                   */
                  brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_EQ, get_addr_reg(vtxOut), brw_imm_uw(0) );
-                 brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtxPrev) );
-                 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+                  brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtxPrev));
+                  brw_inst_set_pred_control(p->devinfo, brw_last_inst,
+                                            BRW_PREDICATE_NORMAL);
 
                  brw_clip_interp_vertex(c, vtxOut, vtxPrev, vtx, c->reg.t, false);
 
                  /* *outlist_ptr++ = vtxOut;
-                  * nr_verts++; 
+                  * nr_verts++;
                   * vtxOut = 0;
                   */
                  brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxOut));
@@ -343,7 +350,7 @@ void brw_clip_tri( struct brw_clip_compile *c )
                  brw_MOV(p, get_addr_reg(vtxOut), brw_imm_uw(0) );
               }
               brw_ENDIF(p);
-              
+
            }
            brw_ELSE(p);
            {
@@ -354,11 +361,9 @@ void brw_clip_tri( struct brw_clip_compile *c )
               brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short)));
               brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1));
 
-               load_vertex_pos(c, vtx, vec4(c->reg.dp), hpos_offset, clipvert_offset);
-              /* IS_NEGATIVE(next)
+               load_clip_distance(c, vtx, c->reg.dp, hpos_offset, BRW_CONDITIONAL_L);
+              /* (next < 0.0f)
                */
-              brw_set_conditionalmod(p, BRW_CONDITIONAL_L);
-              brw_DP4(p, vec4(c->reg.dp), vec4(c->reg.dp), c->reg.plane_equation);
               brw_IF(p, BRW_EXECUTE_1);
               {
                  /* Going out of bounds.  Avoid division by zero as we
@@ -371,24 +376,25 @@ void brw_clip_tri( struct brw_clip_compile *c )
                  /* If (vtxOut == 0) vtxOut = vtx
                   */
                  brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_EQ, get_addr_reg(vtxOut), brw_imm_uw(0) );
-                 brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtx) );
-                 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+                  brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtx));
+                  brw_inst_set_pred_control(p->devinfo, brw_last_inst,
+                                            BRW_PREDICATE_NORMAL);
 
                  brw_clip_interp_vertex(c, vtxOut, vtx, vtxPrev, c->reg.t, true);
 
                  /* *outlist_ptr++ = vtxOut;
-                  * nr_verts++; 
+                  * nr_verts++;
                   * vtxOut = 0;
                   */
                  brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxOut));
                  brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short)));
                  brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1));
                  brw_MOV(p, get_addr_reg(vtxOut), brw_imm_uw(0) );
-              }               
+              }
               brw_ENDIF(p);
            }
            brw_ENDIF(p);
-           
+
            /* vtxPrev = vtx;
             * inlist_ptr++;
             */
@@ -397,10 +403,11 @@ void brw_clip_tri( struct brw_clip_compile *c )
 
            /* while (--loopcount != 0)
             */
-           brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
            brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1));
-        } 
+            brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
+        }
         brw_WHILE(p);
+         brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
 
         /* vtxPrev = *(outlist_ptr-1)  OR: outlist[nr_verts-1]
          * inlist = outlist
@@ -414,41 +421,44 @@ void brw_clip_tri( struct brw_clip_compile *c )
         brw_MOV(p, get_addr_reg(outlist_ptr), brw_address(c->reg.outlist));
       }
       brw_ENDIF(p);
-      
+
       /* plane_ptr++;
        */
       brw_ADD(p, get_addr_reg(plane_ptr), get_addr_reg(plane_ptr), brw_clip_plane_stride(c));
 
-      /* nr_verts >= 3 
+      /* nr_verts >= 3
        */
       brw_CMP(p,
              vec1(brw_null_reg()),
              BRW_CONDITIONAL_GE,
              c->reg.nr_verts,
              brw_imm_ud(3));
-   
+      brw_set_default_predicate_control(p, BRW_PREDICATE_NORMAL);
+
       /* && (planemask>>=1) != 0
        */
-      brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
       brw_SHR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud(1));
+      brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
       brw_SHR(p, c->reg.vertex_src_mask, c->reg.vertex_src_mask, brw_imm_ud(1));
+      brw_ADD(p, c->reg.clipdistance_offset, c->reg.clipdistance_offset, brw_imm_w(sizeof(float)));
    }
    brw_WHILE(p);
+   brw_set_default_predicate_control(p, BRW_PREDICATE_NONE);
 }
 
 
 
 void brw_clip_tri_emit_polygon(struct brw_clip_compile *c)
 {
-   struct brw_compile *p = &c->func;
+   struct brw_codegen *p = &c->func;
 
    /* for (loopcount = nr_verts-2; loopcount > 0; loopcount--)
     */
-   brw_set_conditionalmod(p, BRW_CONDITIONAL_G);
    brw_ADD(p,
           c->reg.loopcount,
           c->reg.nr_verts,
           brw_imm_d(-2));
+   brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_G);
 
    brw_IF(p, BRW_EXECUTE_1);
    {
@@ -458,27 +468,28 @@ void brw_clip_tri_emit_polygon(struct brw_clip_compile *c)
       brw_MOV(p, get_addr_reg(vptr), brw_address(c->reg.inlist));
       brw_MOV(p, get_addr_reg(v0), deref_1uw(vptr, 0));
 
-      brw_clip_emit_vue(c, v0, 1, 0,
+      brw_clip_emit_vue(c, v0, BRW_URB_WRITE_ALLOCATE_COMPLETE,
                         ((_3DPRIM_TRIFAN << URB_WRITE_PRIM_TYPE_SHIFT)
                          | URB_WRITE_PRIM_START));
-      
+
       brw_ADD(p, get_addr_reg(vptr), get_addr_reg(vptr), brw_imm_uw(2));
       brw_MOV(p, get_addr_reg(v0), deref_1uw(vptr, 0));
 
       brw_DO(p, BRW_EXECUTE_1);
       {
-        brw_clip_emit_vue(c, v0, 1, 0,
+        brw_clip_emit_vue(c, v0, BRW_URB_WRITE_ALLOCATE_COMPLETE,
                            (_3DPRIM_TRIFAN << URB_WRITE_PRIM_TYPE_SHIFT));
-  
+
         brw_ADD(p, get_addr_reg(vptr), get_addr_reg(vptr), brw_imm_uw(2));
         brw_MOV(p, get_addr_reg(v0), deref_1uw(vptr, 0));
 
-        brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
         brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1));
+         brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
       }
       brw_WHILE(p);
+      brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
 
-      brw_clip_emit_vue(c, v0, 0, 1,
+      brw_clip_emit_vue(c, v0, BRW_URB_WRITE_EOT_COMPLETE,
                         ((_3DPRIM_TRIFAN << URB_WRITE_PRIM_TYPE_SHIFT)
                          | URB_WRITE_PRIM_END));
    }
@@ -495,7 +506,7 @@ static void do_clip_tri( struct brw_clip_compile *c )
 
 static void maybe_do_clip_tri( struct brw_clip_compile *c )
 {
-   struct brw_compile *p = &c->func;
+   struct brw_codegen *p = &c->func;
 
    brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, c->reg.planemask, brw_imm_ud(0));
    brw_IF(p, BRW_EXECUTE_1);
@@ -520,7 +531,7 @@ static void brw_clip_test( struct brw_clip_compile *c )
     struct brw_indirect vt1 = brw_indirect(1, 0);
     struct brw_indirect vt2 = brw_indirect(2, 0);
 
-    struct brw_compile *p = &c->func;
+    struct brw_codegen *p = &c->func;
     struct brw_reg tmp0 = c->reg.loopcount; /* handy temporary */
 
     GLuint hpos_offset = brw_varying_to_offset(&c->vue_map,
@@ -536,26 +547,23 @@ static void brw_clip_test( struct brw_clip_compile *c )
 
     /* test nearz, xmin, ymin plane */
     /* clip.xyz < -clip.w */
-    brw_CMP(p, t1, BRW_CONDITIONAL_L, v0, negate(get_element(v0, 3))); 
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
-    brw_CMP(p, t2, BRW_CONDITIONAL_L, v1, negate(get_element(v1, 3))); 
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
-    brw_CMP(p, t3, BRW_CONDITIONAL_L, v2, negate(get_element(v2, 3))); 
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_CMP(p, t1, BRW_CONDITIONAL_L, v0, negate(get_element(v0, 3)));
+    brw_CMP(p, t2, BRW_CONDITIONAL_L, v1, negate(get_element(v1, 3)));
+    brw_CMP(p, t3, BRW_CONDITIONAL_L, v2, negate(get_element(v2, 3)));
 
     /* All vertices are outside of a plane, rejected */
     brw_AND(p, t, t1, t2);
     brw_AND(p, t, t, t3);
     brw_OR(p, tmp0, get_element(t, 0), get_element(t, 1));
     brw_OR(p, tmp0, tmp0, get_element(t, 2));
-    brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
     brw_AND(p, brw_null_reg(), tmp0, brw_imm_ud(0x1));
+    brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
     brw_IF(p, BRW_EXECUTE_1);
     {
         brw_clip_kill_thread(c);
     }
     brw_ENDIF(p);
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_set_default_predicate_control(p, BRW_PREDICATE_NONE);
 
     /* some vertices are inside a plane, some are outside,need to clip */
     brw_XOR(p, t, t1, t2);
@@ -565,38 +573,35 @@ static void brw_clip_test( struct brw_clip_compile *c )
     brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ,
             get_element(t, 0), brw_imm_ud(0));
     brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<5)));
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
     brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ,
             get_element(t, 1), brw_imm_ud(0));
     brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<3)));
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
     brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ,
             get_element(t, 2), brw_imm_ud(0));
     brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<1)));
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
 
     /* test farz, xmax, ymax plane */
     /* clip.xyz > clip.w */
-    brw_CMP(p, t1, BRW_CONDITIONAL_G, v0, get_element(v0, 3)); 
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
-    brw_CMP(p, t2, BRW_CONDITIONAL_G, v1, get_element(v1, 3)); 
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
-    brw_CMP(p, t3, BRW_CONDITIONAL_G, v2, get_element(v2, 3)); 
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_CMP(p, t1, BRW_CONDITIONAL_G, v0, get_element(v0, 3));
+    brw_CMP(p, t2, BRW_CONDITIONAL_G, v1, get_element(v1, 3));
+    brw_CMP(p, t3, BRW_CONDITIONAL_G, v2, get_element(v2, 3));
 
     /* All vertices are outside of a plane, rejected */
     brw_AND(p, t, t1, t2);
     brw_AND(p, t, t, t3);
     brw_OR(p, tmp0, get_element(t, 0), get_element(t, 1));
     brw_OR(p, tmp0, tmp0, get_element(t, 2));
-    brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
     brw_AND(p, brw_null_reg(), tmp0, brw_imm_ud(0x1));
+    brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
     brw_IF(p, BRW_EXECUTE_1);
     {
         brw_clip_kill_thread(c);
     }
     brw_ENDIF(p);
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_set_default_predicate_control(p, BRW_PREDICATE_NONE);
 
     /* some vertices are inside a plane, some are outside,need to clip */
     brw_XOR(p, t, t1, t2);
@@ -606,15 +611,15 @@ static void brw_clip_test( struct brw_clip_compile *c )
     brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ,
             get_element(t, 0), brw_imm_ud(0));
     brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<4)));
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
     brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ,
             get_element(t, 1), brw_imm_ud(0));
     brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<2)));
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
     brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_NZ,
             get_element(t, 2), brw_imm_ud(0));
     brw_OR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud((1<<0)));
-    brw_set_predicate_control(p, BRW_PREDICATE_NONE);
+    brw_inst_set_pred_control(p->devinfo, brw_last_inst, BRW_PREDICATE_NORMAL);
 
     release_tmps(c);
 }
@@ -622,19 +627,18 @@ static void brw_clip_test( struct brw_clip_compile *c )
 
 void brw_emit_tri_clip( struct brw_clip_compile *c )
 {
-   struct brw_compile *p = &c->func;
-   struct brw_context *brw = p->brw;
+   struct brw_codegen *p = &c->func;
    brw_clip_tri_alloc_regs(c, 3 + c->key.nr_userclip + 6);
    brw_clip_tri_init_vertices(c);
    brw_clip_init_clipmask(c);
    brw_clip_init_ff_sync(c);
 
-   /* if -ve rhw workaround bit is set, 
+   /* if -ve rhw workaround bit is set,
       do cliptest */
-   if (brw->has_negative_rhw_bug) {
-      brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
-      brw_AND(p, brw_null_reg(), get_element_ud(c->reg.R0, 2), 
+   if (p->devinfo->has_negative_rhw_bug) {
+      brw_AND(p, brw_null_reg(), get_element_ud(c->reg.R0, 2),
               brw_imm_ud(1<<20));
+      brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ);
       brw_IF(p, BRW_EXECUTE_1);
       {
          brw_clip_test(c);
@@ -645,13 +649,13 @@ void brw_emit_tri_clip( struct brw_clip_compile *c )
     * flatshading, need to apply the flatshade here because we don't
     * respect the PV when converting to trifan for emit:
     */
-   if (c->key.do_flat_shading) 
-      brw_clip_tri_flat_shade(c); 
-      
+   if (c->key.contains_flat_varying)
+      brw_clip_tri_flat_shade(c);
+
    if ((c->key.clip_mode == BRW_CLIPMODE_NORMAL) ||
        (c->key.clip_mode == BRW_CLIPMODE_KERNEL_CLIP))
       do_clip_tri(c);
-   else 
+   else
       maybe_do_clip_tri(c);
 
    brw_clip_tri_emit_polygon(c);