Mesa (master): i965: Don' t upload clip planes when gl_ClipDistance is in use.

Paul Berry stereotype441 at kemper.freedesktop.org
Fri Sep 23 22:43:48 UTC 2011


Module: Mesa
Branch: master
Commit: d9cb683f81b5daefda2f8599b4ba0365cc6f009a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d9cb683f81b5daefda2f8599b4ba0365cc6f009a

Author: Paul Berry <stereotype441 at gmail.com>
Date:   Fri Sep  2 14:57:18 2011 -0700

i965: Don't upload clip planes when gl_ClipDistance is in use.

When the vertex shader writes to gl_ClipDistance, we do clipping based
on clip distances rather than user clip planes, so don't waste push
constant space storing user clip planes that won't be used.

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/mesa/drivers/dri/i965/brw_vec4_emit.cpp |    2 +-
 src/mesa/drivers/dri/i965/brw_vs.c          |    1 +
 src/mesa/drivers/dri/i965/brw_vs.h          |    1 +
 src/mesa/drivers/dri/i965/gen6_vs_state.c   |   15 +++++++++------
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
index ecaf8b4..b58ebc6 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
@@ -93,7 +93,7 @@ vec4_visitor::setup_uniforms(int reg)
 {
    /* User clip planes from curbe:
     */
-   if (c->key.nr_userclip) {
+   if (c->key.nr_userclip && !c->key.uses_clip_distance) {
       if (intel->gen >= 6) {
 	 for (int i = 0; i < c->key.nr_userclip; i++) {
 	    c->userplane[i] = stride(brw_vec4_grf(reg + i / 2,
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 88564d3..fdccd94 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -256,6 +256,7 @@ static void brw_upload_vs_prog(struct brw_context *brw)
     */
    key.program_string_id = vp->id;
    key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
+   key.uses_clip_distance = vp->program.UsesClipDistance;
    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 28e6b42..7224423 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.h
+++ b/src/mesa/drivers/dri/i965/brw_vs.h
@@ -49,6 +49,7 @@ struct brw_vs_prog_key {
    GLuint copy_edgeflag:1;
    GLuint point_coord_replace:8;
    GLuint clamp_vertex_color:1;
+   GLuint uses_clip_distance:1;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c b/src/mesa/drivers/dri/i965/gen6_vs_state.c
index f1123af..afb4ace 100644
--- a/src/mesa/drivers/dri/i965/gen6_vs_state.c
+++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c
@@ -42,6 +42,7 @@ gen6_prepare_vs_push_constants(struct brw_context *brw)
    const struct brw_vertex_program *vp =
       brw_vertex_program_const(brw->vertex_program);
    unsigned int nr_params = brw->vs.prog_data->nr_params / 4;
+   bool uses_clip_distance = vp->program.UsesClipDistance;
 
    if (brw->vertex_program->IsNVProgram)
       _mesa_load_tracked_matrices(ctx);
@@ -68,12 +69,14 @@ gen6_prepare_vs_push_constants(struct brw_context *brw)
       /* This should be loaded like any other param, but it's ad-hoc
        * until we redo the VS backend.
        */
-      for (i = 0; i < MAX_CLIP_PLANES; i++) {
-	 if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {
-	    memcpy(param, ctx->Transform._ClipUserPlane[i], 4 * sizeof(float));
-	    param += 4;
-	    params_uploaded++;
-	 }
+      if (!uses_clip_distance) {
+         for (i = 0; i < MAX_CLIP_PLANES; i++) {
+            if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {
+               memcpy(param, ctx->Transform._ClipUserPlane[i], 4 * sizeof(float));
+               param += 4;
+               params_uploaded++;
+            }
+         }
       }
       /* Align to a reg for convenience for brw_vs_emit.c */
       if (params_uploaded & 1) {




More information about the mesa-commit mailing list