[Mesa-dev] [PATCH 09/36] i965: new VS: move clip distance computation (GEN5+) to a separate function.

Paul Berry stereotype441 at gmail.com
Fri Sep 2 09:06:48 PDT 2011


---
 src/mesa/drivers/dri/i965/brw_vec4.h           |    1 +
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |   32 ++++++++++++++---------
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 8c613bd..01313ec 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -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);
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index bd8878a..374cf8a 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -1789,6 +1789,21 @@ 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 because the hardware
+       * requires them to be, but they are not used. */
+      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 +1829,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 +1874,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;
-- 
1.7.6



More information about the mesa-dev mailing list