i965: new VS: move clip distance computation (GEN5+) to a separate function.
authorPaul Berry <stereotype441@gmail.com>
Tue, 23 Aug 2011 17:41:31 +0000 (10:41 -0700)
committerPaul Berry <stereotype441@gmail.com>
Tue, 6 Sep 2011 18:04:15 +0000 (11:04 -0700)
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_vec4.h
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp

index 8c613bd957240843d604c4689acd1f5ec4889096..01313ec192dbc15a2b7e82034ed45ee6365a7373 100644 (file)
@@ -465,6 +465,7 @@ public:
 
    void emit_ndc_computation();
    void emit_psiz_and_flags(struct brw_reg reg);
+   void emit_clip_distances(struct brw_reg reg, int offset);
    int emit_vue_header_gen6(int header_mrf);
    int emit_vue_header_gen4(int header_mrf);
    void emit_urb_writes(void);
index bd8878a1ebea52257605fd5b8433e56eadddee39..8cc52c1d18175a0320830d3df7ab4696b16ce64f 100644 (file)
@@ -1789,6 +1789,24 @@ vec4_visitor::emit_psiz_and_flags(struct brw_reg reg)
    }
 }
 
+void
+vec4_visitor::emit_clip_distances(struct brw_reg reg, int offset)
+{
+   if (intel->gen < 6) {
+      /* Clip distance slots are set aside in gen5, but they are not used.  It
+       * is not clear whether we actually need to set aside space for them,
+       * but the performance cost is negligible.
+       */
+      return;
+   }
+
+   for (int i = 0; i + offset < c->key.nr_userclip && i < 4; ++i) {
+      emit(DP4(dst_reg(brw_writemask(reg, 1 << i)),
+               src_reg(output_reg[VERT_RESULT_HPOS]),
+               src_reg(c->userplane[i + offset])));
+   }
+}
+
 int
 vec4_visitor::emit_vue_header_gen4(int header_mrf)
 {
@@ -1814,7 +1832,8 @@ vec4_visitor::emit_vue_header_gen4(int header_mrf)
                src_reg(output_reg[VERT_RESULT_HPOS])));
 
       /* user clip distance. */
-      header_mrf += 2;
+      emit_clip_distances(brw_message_reg(header_mrf++), 0);
+      emit_clip_distances(brw_message_reg(header_mrf++), 4);
 
       /* Pad so that vertex element data is aligned. */
       header_mrf++;
@@ -1858,18 +1877,8 @@ vec4_visitor::emit_vue_header_gen6(int header_mrf)
 
    current_annotation = "user clip distances";
    if (c->key.nr_userclip) {
-      for (int i = 0; i < c->key.nr_userclip; i++) {
-        struct brw_reg m;
-        if (i < 4)
-           m = brw_message_reg(header_mrf);
-        else
-           m = brw_message_reg(header_mrf + 1);
-
-        emit(DP4(dst_reg(brw_writemask(m, 1 << (i & 3))),
-                 src_reg(output_reg[VERT_RESULT_HPOS]),
-                 src_reg(c->userplane[i])));
-      }
-      header_mrf += 2;
+      emit_clip_distances(brw_message_reg(header_mrf++), 0);
+      emit_clip_distances(brw_message_reg(header_mrf++), 4);
    }
 
    current_annotation = NULL;