i965/vs: Add a function for how many MRFs get written as part of a SEND.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_clip_unfilled.c
index 6f20d798d84f31a18f5dd962f35947b36fab5c3a..6ddb2d57890f4ba69da34ecd9ac84084e57c49af 100644 (file)
   *   Keith Whitwell <keith@tungstengraphics.com>
   */
 
-#include "glheader.h"
-#include "macros.h"
-#include "enums.h"
+#include "main/glheader.h"
+#include "main/macros.h"
+#include "main/enums.h"
+#include "program/program.h"
 
-#include "shader/program.h"
 #include "intel_batchbuffer.h"
 
 #include "brw_defines.h"
 #include "brw_context.h"
 #include "brw_eu.h"
-#include "brw_util.h"
 #include "brw_clip.h"
 
 
@@ -53,9 +52,11 @@ static void compute_tri_direction( struct brw_clip_compile *c )
    struct brw_compile *p = &c->func;
    struct brw_reg e = c->reg.tmp0;
    struct brw_reg f = c->reg.tmp1;
-   struct brw_reg v0 = byte_offset(c->reg.vertex[0], c->offset[VERT_RESULT_HPOS]); 
-   struct brw_reg v1 = byte_offset(c->reg.vertex[1], c->offset[VERT_RESULT_HPOS]); 
-   struct brw_reg v2 = byte_offset(c->reg.vertex[2], c->offset[VERT_RESULT_HPOS]); 
+   GLuint hpos_offset = brw_vert_result_to_offset(&c->vue_map,
+                                                  VERT_RESULT_HPOS);
+   struct brw_reg v0 = byte_offset(c->reg.vertex[0], hpos_offset);
+   struct brw_reg v1 = byte_offset(c->reg.vertex[1], hpos_offset);
+   struct brw_reg v2 = byte_offset(c->reg.vertex[2], hpos_offset);
 
 
    struct brw_reg v0n = get_tmp(c);
@@ -97,7 +98,6 @@ static void compute_tri_direction( struct brw_clip_compile *c )
 static void cull_direction( struct brw_clip_compile *c )
 {
    struct brw_compile *p = &c->func;
-   struct brw_instruction *ccw;
    GLuint conditional;
 
    assert (!(c->key.fill_ccw == CLIP_CULL &&
@@ -114,11 +114,11 @@ static void cull_direction( struct brw_clip_compile *c )
           get_element(c->reg.dir, 2),
           brw_imm_f(0));
    
-   ccw = brw_IF(p, BRW_EXECUTE_1);
+   brw_IF(p, BRW_EXECUTE_1);
    {
       brw_clip_kill_thread(c);
    }
-   brw_ENDIF(p, ccw);
+   brw_ENDIF(p);
 }
 
 
@@ -126,13 +126,14 @@ static void cull_direction( struct brw_clip_compile *c )
 static void copy_bfc( struct brw_clip_compile *c )
 {
    struct brw_compile *p = &c->func;
-   struct brw_instruction *ccw;
    GLuint conditional;
 
    /* Do we have any colors to copy? 
     */
-   if (!(c->offset[VERT_RESULT_COL0] && c->offset[VERT_RESULT_BFC0]) &&
-       !(c->offset[VERT_RESULT_COL1] && c->offset[VERT_RESULT_BFC1]))
+   if (!(brw_clip_have_vert_result(c, VERT_RESULT_COL0) &&
+         brw_clip_have_vert_result(c, VERT_RESULT_BFC0)) &&
+       !(brw_clip_have_vert_result(c, VERT_RESULT_COL1) &&
+         brw_clip_have_vert_result(c, VERT_RESULT_BFC1)))
       return;
 
    /* In some wierd degnerate cases we can end up testing the
@@ -150,23 +151,33 @@ static void copy_bfc( struct brw_clip_compile *c )
           get_element(c->reg.dir, 2),
           brw_imm_f(0));
    
-   ccw = brw_IF(p, BRW_EXECUTE_1);
+   brw_IF(p, BRW_EXECUTE_1);
    {
       GLuint i;
 
       for (i = 0; i < 3; i++) {
-        if (c->offset[VERT_RESULT_COL0] && c->offset[VERT_RESULT_BFC0])
+        if (brw_clip_have_vert_result(c, VERT_RESULT_COL0) &&
+             brw_clip_have_vert_result(c, VERT_RESULT_BFC0))
            brw_MOV(p, 
-                   byte_offset(c->reg.vertex[i], c->offset[VERT_RESULT_COL0]),
-                   byte_offset(c->reg.vertex[i], c->offset[VERT_RESULT_BFC0]));
-
-        if (c->offset[VERT_RESULT_COL1] && c->offset[VERT_RESULT_BFC1])
+                   byte_offset(c->reg.vertex[i],
+                                brw_vert_result_to_offset(&c->vue_map,
+                                                          VERT_RESULT_COL0)),
+                   byte_offset(c->reg.vertex[i],
+                                brw_vert_result_to_offset(&c->vue_map,
+                                                          VERT_RESULT_BFC0)));
+
+        if (brw_clip_have_vert_result(c, VERT_RESULT_COL1) &&
+             brw_clip_have_vert_result(c, VERT_RESULT_BFC1))
            brw_MOV(p, 
-                   byte_offset(c->reg.vertex[i], c->offset[VERT_RESULT_COL1]),
-                   byte_offset(c->reg.vertex[i], c->offset[VERT_RESULT_BFC1]));
+                   byte_offset(c->reg.vertex[i],
+                                brw_vert_result_to_offset(&c->vue_map,
+                                                          VERT_RESULT_COL1)),
+                   byte_offset(c->reg.vertex[i],
+                                brw_vert_result_to_offset(&c->vue_map,
+                                                          VERT_RESULT_BFC1)));
       }
    }
-   brw_ENDIF(p, ccw);
+   brw_ENDIF(p);
 }
 
 
@@ -206,7 +217,6 @@ static void compute_offset( struct brw_clip_compile *c )
 static void merge_edgeflags( struct brw_clip_compile *c )
 {
    struct brw_compile *p = &c->func;
-   struct brw_instruction *is_poly;
    struct brw_reg tmp0 = get_element_ud(c->reg.tmp0, 0);
 
    brw_AND(p, tmp0, get_element_ud(c->reg.R0, 2), brw_imm_ud(PRIM_MASK)); 
@@ -219,19 +229,25 @@ static void merge_edgeflags( struct brw_clip_compile *c )
    /* Get away with using reg.vertex because we know that this is not
     * a _3DPRIM_TRISTRIP_REVERSE:
     */
-   is_poly = brw_IF(p, BRW_EXECUTE_1);
+   brw_IF(p, BRW_EXECUTE_1);
    {   
       brw_set_conditionalmod(p, BRW_CONDITIONAL_EQ);
       brw_AND(p, vec1(brw_null_reg()), get_element_ud(c->reg.R0, 2), brw_imm_ud(1<<8));
-      brw_MOV(p, byte_offset(c->reg.vertex[0], c->offset[VERT_RESULT_EDGE]), brw_imm_f(0));
+      brw_MOV(p, byte_offset(c->reg.vertex[0],
+                             brw_vert_result_to_offset(&c->vue_map,
+                                                       VERT_RESULT_EDGE)),
+              brw_imm_f(0));
       brw_set_predicate_control(p, BRW_PREDICATE_NONE);
 
       brw_set_conditionalmod(p, BRW_CONDITIONAL_EQ);
       brw_AND(p, vec1(brw_null_reg()), get_element_ud(c->reg.R0, 2), brw_imm_ud(1<<9));
-      brw_MOV(p, byte_offset(c->reg.vertex[2], c->offset[VERT_RESULT_EDGE]), brw_imm_f(0));
+      brw_MOV(p, byte_offset(c->reg.vertex[2],
+                             brw_vert_result_to_offset(&c->vue_map,
+                                                       VERT_RESULT_EDGE)),
+              brw_imm_f(0));
       brw_set_predicate_control(p, BRW_PREDICATE_NONE);
    }
-   brw_ENDIF(p, is_poly);
+   brw_ENDIF(p);
 }
 
 
@@ -240,7 +256,9 @@ static void apply_one_offset( struct brw_clip_compile *c,
                          struct brw_indirect vert )
 {
    struct brw_compile *p = &c->func;
-   struct brw_reg z = deref_1f(vert, c->header_position_offset +
+   GLuint ndc_offset = brw_vert_result_to_offset(&c->vue_map,
+                                                 BRW_VERT_RESULT_NDC);
+   struct brw_reg z = deref_1f(vert, ndc_offset +
                               2 * type_sz(BRW_REGISTER_TYPE_F));
 
    brw_ADD(p, z, z, vec1(c->reg.offset));
@@ -256,7 +274,6 @@ static void emit_lines(struct brw_clip_compile *c,
 {
    struct brw_compile *p = &c->func;
    struct brw_instruction *loop;
-   struct brw_instruction *draw_edge;
    struct brw_indirect v0 = brw_indirect(0, 0);
    struct brw_indirect v1 = brw_indirect(1, 0);
    struct brw_indirect v0ptr = brw_indirect(2, 0);
@@ -299,14 +316,15 @@ static void emit_lines(struct brw_clip_compile *c,
       /* draw edge if edgeflag != 0 */
       brw_CMP(p, 
              vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, 
-             deref_1f(v0, c->offset[VERT_RESULT_EDGE]),
+             deref_1f(v0, brw_vert_result_to_offset(&c->vue_map,
+                                                     VERT_RESULT_EDGE)),
              brw_imm_f(0));
-      draw_edge = brw_IF(p, BRW_EXECUTE_1);
+      brw_IF(p, BRW_EXECUTE_1);
       {
         brw_clip_emit_vue(c, v0, 1, 0, (_3DPRIM_LINESTRIP << 2) | R02_PRIM_START);
         brw_clip_emit_vue(c, v1, 1, 0, (_3DPRIM_LINESTRIP << 2) | R02_PRIM_END);
       }
-      brw_ENDIF(p, draw_edge);
+      brw_ENDIF(p);
 
       brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
       brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1));
@@ -321,7 +339,6 @@ static void emit_points(struct brw_clip_compile *c,
 {
    struct brw_compile *p = &c->func;
    struct brw_instruction *loop;
-   struct brw_instruction *draw_point;
 
    struct brw_indirect v0 = brw_indirect(0, 0);
    struct brw_indirect v0ptr = brw_indirect(2, 0);
@@ -338,16 +355,17 @@ static void emit_points(struct brw_clip_compile *c,
        */
       brw_CMP(p, 
              vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, 
-             deref_1f(v0, c->offset[VERT_RESULT_EDGE]),
+             deref_1f(v0, brw_vert_result_to_offset(&c->vue_map,
+                                                     VERT_RESULT_EDGE)),
              brw_imm_f(0));
-      draw_point = brw_IF(p, BRW_EXECUTE_1);
+      brw_IF(p, BRW_EXECUTE_1);
       {
         if (do_offset)
            apply_one_offset(c, v0);
 
         brw_clip_emit_vue(c, v0, 1, 0, (_3DPRIM_POINTLIST << 2) | R02_PRIM_START | R02_PRIM_END);
       }
-      brw_ENDIF(p, draw_point);
+      brw_ENDIF(p);
 
       brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
       brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1));
@@ -389,7 +407,6 @@ static void emit_primitives( struct brw_clip_compile *c,
 static void emit_unfilled_primitives( struct brw_clip_compile *c )
 {
    struct brw_compile *p = &c->func;
-   struct brw_instruction *ccw;
 
    /* Direction culling has already been done.
     */
@@ -403,15 +420,15 @@ static void emit_unfilled_primitives( struct brw_clip_compile *c )
              get_element(c->reg.dir, 2),
              brw_imm_f(0));
    
-      ccw = brw_IF(p, BRW_EXECUTE_1);
+      brw_IF(p, BRW_EXECUTE_1);
       {
         emit_primitives(c, c->key.fill_ccw, c->key.offset_ccw);
       }
-      ccw = brw_ELSE(p, ccw);
+      brw_ELSE(p);
       {
         emit_primitives(c, c->key.fill_cw, c->key.offset_cw);
       }
-      brw_ENDIF(p, ccw);
+      brw_ENDIF(p);
    }
    else if (c->key.fill_cw != CLIP_CULL) {
       emit_primitives(c, c->key.fill_cw, c->key.offset_cw);
@@ -427,22 +444,19 @@ static void emit_unfilled_primitives( struct brw_clip_compile *c )
 static void check_nr_verts( struct brw_clip_compile *c )
 {
    struct brw_compile *p = &c->func;
-   struct brw_instruction *if_insn;
 
    brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_L, c->reg.nr_verts, brw_imm_d(3));      
-   if_insn = brw_IF(p, BRW_EXECUTE_1);
+   brw_IF(p, BRW_EXECUTE_1);
    {
       brw_clip_kill_thread(c);
    }
-   brw_ENDIF(p, if_insn);
+   brw_ENDIF(p);
 }
 
 
 void brw_emit_unfilled_clip( struct brw_clip_compile *c )
 {
    struct brw_compile *p = &c->func;
-   struct brw_instruction *do_clip;
-   
 
    c->need_direction = ((c->key.offset_ccw || c->key.offset_cw) ||
                        (c->key.fill_ccw != c->key.fill_cw) ||
@@ -453,8 +467,9 @@ void brw_emit_unfilled_clip( struct brw_clip_compile *c )
 
    brw_clip_tri_alloc_regs(c, 3 + c->key.nr_userclip + 6);
    brw_clip_tri_init_vertices(c);
+   brw_clip_init_ff_sync(c);
 
-   assert(c->offset[VERT_RESULT_EDGE]);
+   assert(brw_clip_have_vert_result(c, VERT_RESULT_EDGE));
 
    if (c->key.fill_ccw == CLIP_CULL &&
        c->key.fill_cw == CLIP_CULL) {
@@ -488,14 +503,14 @@ void brw_emit_unfilled_clip( struct brw_clip_compile *c )
    
    brw_clip_init_clipmask(c);
    brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_NZ, c->reg.planemask, brw_imm_ud(0));
-   do_clip = brw_IF(p, BRW_EXECUTE_1);
+   brw_IF(p, BRW_EXECUTE_1);
    {
       brw_clip_init_planes(c);
       brw_clip_tri(c);
       check_nr_verts(c);
    }
-   brw_ENDIF(p, do_clip);
-   
+   brw_ENDIF(p);
+
    emit_unfilled_primitives(c);
    brw_clip_kill_thread(c);
 }