[Mesa-dev] [PATCH 5/6] i965 VS: Change nr_userclip to nr_userclip_planes.

Paul Berry stereotype441 at gmail.com
Mon Oct 3 15:11:19 PDT 2011


The only remaining uses of brw_vs_prog_key::nr_userclip only occurred
when using clip planes (as opposed to gl_ClipDistance).  This patch
renames the value to nr_userclip_planes and sets it to zero when
gl_ClipDistance is in use.  This avoids unnecessary VS recompiles.
---
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |    4 ++--
 src/mesa/drivers/dri/i965/brw_vs.c             |    6 ++++--
 src/mesa/drivers/dri/i965/brw_vs.h             |    5 +++--
 src/mesa/drivers/dri/i965/brw_vs_emit.c        |   14 +++++++-------
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 5d75946..3c2f9ba 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -1807,7 +1807,7 @@ vec4_visitor::emit_psiz_and_flags(struct brw_reg reg)
       }
 
       current_annotation = "Clipping flags";
-      for (i = 0; i < c->key.nr_userclip; i++) {
+      for (i = 0; i < c->key.nr_userclip_planes; i++) {
 	 vec4_instruction *inst;
 
 	 inst = emit(DP4(dst_null_f(), src_reg(output_reg[VERT_RESULT_HPOS]),
@@ -1883,7 +1883,7 @@ vec4_visitor::emit_clip_distances(struct brw_reg reg, int offset)
       clip_vertex = VERT_RESULT_HPOS;
    }
 
-   for (int i = 0; i + offset < c->key.nr_userclip && i < 4; ++i) {
+   for (int i = 0; i + offset < c->key.nr_userclip_planes && i < 4; ++i) {
       emit(DP4(dst_reg(brw_writemask(reg, 1 << i)),
                src_reg(output_reg[clip_vertex]),
                src_reg(this->userplane[i + offset])));
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 97a4c39..19d9552 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -289,10 +289,12 @@ static void brw_upload_vs_prog(struct brw_context *brw)
     */
    key.program_string_id = vp->id;
    key.userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
-   key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
    key.uses_clip_distance = vp->program.UsesClipDistance;
-   if (!key.uses_clip_distance)
+   if (!key.uses_clip_distance) {
       key.userclip_planes_enabled = ctx->Transform.ClipPlanesEnabled;
+      key.nr_userclip_planes
+         = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
+   }
    key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
 			ctx->Polygon.BackMode != GL_FILL);
 
diff --git a/src/mesa/drivers/dri/i965/brw_vs.h b/src/mesa/drivers/dri/i965/brw_vs.h
index bd81764..b8d11df 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.h
+++ b/src/mesa/drivers/dri/i965/brw_vs.h
@@ -53,9 +53,10 @@ struct brw_vs_prog_key {
    GLuint userclip_active:1;
 
    /**
-    * Number of user clip planes (or clip distances) that are active.
+    * Number of user clip planes active.  Zero if the shader uses
+    * gl_ClipDistance.
     */
-   GLuint nr_userclip:4;
+   GLuint nr_userclip_planes:4;
 
    /**
     * True if the shader uses gl_ClipDistance, regardless of whether any clip
diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c
index e78cb6c..8845580 100644
--- a/src/mesa/drivers/dri/i965/brw_vs_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c
@@ -204,17 +204,17 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )
     */
    if (c->key.userclip_active) {
       if (intel->gen >= 6) {
-	 for (i = 0; i < c->key.nr_userclip; i++) {
+	 for (i = 0; i < c->key.nr_userclip_planes; i++) {
 	    c->userplane[i] = stride(brw_vec4_grf(reg + i / 2,
 						  (i % 2) * 4), 0, 4, 1);
 	 }
-	 reg += ALIGN(c->key.nr_userclip, 2) / 2;
+	 reg += ALIGN(c->key.nr_userclip_planes, 2) / 2;
       } else {
-	 for (i = 0; i < c->key.nr_userclip; i++) {
+	 for (i = 0; i < c->key.nr_userclip_planes; i++) {
 	    c->userplane[i] = stride(brw_vec4_grf(reg + (6 + i) / 2,
 						  (i % 2) * 4), 0, 4, 1);
 	 }
-	 reg += (ALIGN(6 + c->key.nr_userclip, 4) / 4) * 2;
+	 reg += (ALIGN(6 + c->key.nr_userclip_planes, 4) / 4) * 2;
       }
 
    }
@@ -239,7 +239,7 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )
     */
    if (intel->gen >= 6) {
       /* We can only load 32 regs of push constants. */
-      max_constant = 32 * 2 - c->key.nr_userclip;
+      max_constant = 32 * 2 - c->key.nr_userclip_planes;
    } else {
       max_constant = BRW_MAX_GRF - 20 - c->vp->program.Base.NumTemporaries;
    }
@@ -1565,7 +1565,7 @@ static void emit_vertex_write( struct brw_vs_compile *c)
 
       /* Set the user clip distances in dword 8-15. (m3-4)*/
       if (c->key.userclip_active) {
-	 for (i = 0; i < c->key.nr_userclip; i++) {
+	 for (i = 0; i < c->key.nr_userclip_planes; i++) {
 	    struct brw_reg m;
 	    if (i < 4)
 	       m = brw_message_reg(3);
@@ -1593,7 +1593,7 @@ static void emit_vertex_write( struct brw_vs_compile *c)
 		 header1, brw_imm_ud(0x7ff<<8));
       }
 
-      for (i = 0; i < c->key.nr_userclip; i++) {
+      for (i = 0; i < c->key.nr_userclip_planes; i++) {
 	 brw_set_conditionalmod(p, BRW_CONDITIONAL_L);
 	 brw_DP4(p, brw_null_reg(), pos, c->userplane[i]);
 	 brw_OR(p, brw_writemask(header1, WRITEMASK_W), header1, brw_imm_ud(1<<i));
-- 
1.7.6.2



More information about the mesa-dev mailing list