[Mesa-dev] [PATCH 6/8] i965: Set up clip distance VUE slots appropriately for gl_ClipDistance.

Paul Berry stereotype441 at gmail.com
Tue Sep 20 15:42:36 PDT 2011


When gl_ClipDistance is in use, the contents of the gl_ClipDistance
array just need to be copied directly into the clip distance VUE
slots, so we re-use the code that copies all other generic VUE slots
(this has been extracted to its own method).  When gl_ClipDistance is
not in use, the vertex shader needs to calculate the clip distances
based on user-specified clipping planes.

This patch also removes the i965-specific enum values
BRW_VERT_RESULT_CLIP[01], since we now have generic Mesa enums that
serve the same purpose (VERT_RESULT_CLIP_DIST[01]).
---
 src/mesa/drivers/dri/i965/brw_context.h        |    2 -
 src/mesa/drivers/dri/i965/brw_vec4.h           |    1 +
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |   48 +++++++++++++----------
 src/mesa/drivers/dri/i965/brw_vs.c             |    8 ++--
 4 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index 6772029..d32eded 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -290,8 +290,6 @@ typedef enum
 {
    BRW_VERT_RESULT_NDC = VERT_RESULT_MAX,
    BRW_VERT_RESULT_HPOS_DUPLICATE,
-   BRW_VERT_RESULT_CLIP0,
-   BRW_VERT_RESULT_CLIP1,
    BRW_VERT_RESULT_PAD,
    BRW_VERT_RESULT_MAX
 } brw_vert_result;
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 19190a7..876a691 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -486,6 +486,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);
+   void emit_generic_urb_slot(dst_reg reg, int vert_result);
    void emit_urb_slot(int mrf, int vert_result);
    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 833349a..d45eed0 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -1829,6 +1829,23 @@ vec4_visitor::emit_clip_distances(struct brw_reg reg, int offset)
 }
 
 void
+vec4_visitor::emit_generic_urb_slot(dst_reg reg, int vert_result)
+{
+   assert (vert_result < VERT_RESULT_MAX);
+   current_annotation = output_reg_annotation[vert_result];
+   /* Copy the register, saturating if necessary */
+   vec4_instruction *inst = emit(MOV(reg,
+                                     src_reg(output_reg[vert_result])));
+   if ((vert_result == VERT_RESULT_COL0 ||
+        vert_result == VERT_RESULT_COL1 ||
+        vert_result == VERT_RESULT_BFC0 ||
+        vert_result == VERT_RESULT_BFC1) &&
+       c->key.clamp_vertex_color) {
+      inst->saturate = true;
+   }
+}
+
+void
 vec4_visitor::emit_urb_slot(int mrf, int vert_result)
 {
    struct brw_reg hw_reg = brw_message_reg(mrf);
@@ -1850,31 +1867,20 @@ vec4_visitor::emit_urb_slot(int mrf, int vert_result)
       current_annotation = "gl_Position";
       emit(MOV(reg, src_reg(output_reg[VERT_RESULT_HPOS])));
       break;
-   case BRW_VERT_RESULT_CLIP0:
-      current_annotation = "user clip distances";
-      emit_clip_distances(hw_reg, 0);
-      break;
-   case BRW_VERT_RESULT_CLIP1:
-      current_annotation = "user clip distances";
-      emit_clip_distances(hw_reg, 4);
+   case VERT_RESULT_CLIP_DIST0:
+   case VERT_RESULT_CLIP_DIST1:
+      if (this->c->key.uses_clip_distance) {
+         emit_generic_urb_slot(reg, vert_result);
+      } else {
+         current_annotation = "user clip distances";
+         emit_clip_distances(hw_reg, (vert_result - VERT_RESULT_CLIP_DIST0) * 4);
+      }
       break;
    case BRW_VERT_RESULT_PAD:
       /* No need to write to this slot */
       break;
-   default: {
-      assert (vert_result < VERT_RESULT_MAX);
-      current_annotation = output_reg_annotation[vert_result];
-      /* Copy the register, saturating if necessary */
-      vec4_instruction *inst = emit(MOV(reg,
-                                        src_reg(output_reg[vert_result])));
-      if ((vert_result == VERT_RESULT_COL0 ||
-	   vert_result == VERT_RESULT_COL1 ||
-	   vert_result == VERT_RESULT_BFC0 ||
-	   vert_result == VERT_RESULT_BFC1) &&
-	  c->key.clamp_vertex_color) {
-	 inst->saturate = true;
-      }
-   }
+   default:
+      emit_generic_urb_slot(reg, vert_result);
       break;
    }
 }
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index fdccd94..93c6838 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -96,8 +96,8 @@ brw_compute_vue_map(struct brw_vue_map *vue_map,
       assign_vue_slot(vue_map, VERT_RESULT_PSIZ);
       assign_vue_slot(vue_map, BRW_VERT_RESULT_NDC);
       assign_vue_slot(vue_map, BRW_VERT_RESULT_HPOS_DUPLICATE);
-      assign_vue_slot(vue_map, BRW_VERT_RESULT_CLIP0);
-      assign_vue_slot(vue_map, BRW_VERT_RESULT_CLIP1);
+      assign_vue_slot(vue_map, VERT_RESULT_CLIP_DIST0);
+      assign_vue_slot(vue_map, VERT_RESULT_CLIP_DIST1);
       assign_vue_slot(vue_map, BRW_VERT_RESULT_PAD);
       assign_vue_slot(vue_map, VERT_RESULT_HPOS);
       break;
@@ -113,8 +113,8 @@ brw_compute_vue_map(struct brw_vue_map *vue_map,
       assign_vue_slot(vue_map, VERT_RESULT_PSIZ);
       assign_vue_slot(vue_map, VERT_RESULT_HPOS);
       if (nr_userclip) {
-         assign_vue_slot(vue_map, BRW_VERT_RESULT_CLIP0);
-         assign_vue_slot(vue_map, BRW_VERT_RESULT_CLIP1);
+         assign_vue_slot(vue_map, VERT_RESULT_CLIP_DIST0);
+         assign_vue_slot(vue_map, VERT_RESULT_CLIP_DIST1);
       }
       /* front and back colors need to be consecutive so that we can use
        * ATTRIBUTE_SWIZZLE_INPUTATTR_FACING to swizzle them when doing
-- 
1.7.6.2



More information about the mesa-dev mailing list