i965: Move ClipPlanesEnabled state to VS cache key.
authorPaul Berry <stereotype441@gmail.com>
Wed, 28 Sep 2011 18:26:57 +0000 (11:26 -0700)
committerPaul Berry <stereotype441@gmail.com>
Fri, 7 Oct 2011 02:29:02 +0000 (19:29 -0700)
Previous to this patch, setup_uniform_clipplane_values() was setting
up clip plane uniforms based on ctx->Transform.ClipPlanesEnabled, a
piece of state not stored in the vertex shader cache key.  As a
result, a change to this piece of state might not trigger a necessary
vertex shader recompile.

The patch adds a field to the vertex shader cache key,
userclip_planes_enabled, to store the current value of
ctx->Transform.ClipPlanesEnabled.  Also, it changes
setup_uniform_clipplane_values() to read from this new field, so that
it's manifestly clear that the vertex shader isn't depending on state
not stored in the cache key.

Note: when the vertex shader uses gl_ClipDistance, the VS backend
doesn't need to know which clip planes are in use, so we leave the
field as zero in that case to avoid unnecessary recompiles.

Fixes Piglit test vs-clip-vertex-enables.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/drivers/dri/i965/brw_vs.c
src/mesa/drivers/dri/i965/brw_vs.h

index 17bde91bb2c64c90f1d871909985c19f115b8f5b..f99dc51682b56c3d8631a5987734241846923ae1 100644 (file)
@@ -561,7 +561,7 @@ vec4_visitor::setup_uniform_clipplane_values()
 
    int compacted_clipplane_index = 0;
    for (int i = 0; i < MAX_CLIP_PLANES; ++i) {
-      if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {
+      if (c->key.userclip_planes_enabled & (1 << i)) {
          this->uniform_vector_size[this->uniforms] = 4;
          this->userplane[compacted_clipplane_index] = dst_reg(UNIFORM, this->uniforms);
          this->userplane[compacted_clipplane_index].type = BRW_REGISTER_TYPE_F;
index 02e60dc20bf6b94418db39dfcebc18bf3fc65556..eb673e29c96e46c4458593f5d10cd78a6d3c26e4 100644 (file)
@@ -289,6 +289,8 @@ static void brw_upload_vs_prog(struct brw_context *brw)
    key.program_string_id = vp->id;
    key.nr_userclip = _mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);
    key.uses_clip_distance = vp->program.UsesClipDistance;
+   if (!key.uses_clip_distance)
+      key.userclip_planes_enabled = ctx->Transform.ClipPlanesEnabled;
    key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
                        ctx->Polygon.BackMode != GL_FILL);
 
index 7ec4ad8e793e4988f8c97c7f8b5a9e1f13fcd4b0..a12b1390aad8b3c99b5bced7a6a222b2cebbad2e 100644 (file)
@@ -57,6 +57,12 @@ struct brw_vs_prog_key {
     */
    GLuint uses_clip_distance:1;
 
+   /**
+    * Which user clip planes are active.  Zero if the shader uses
+    * gl_ClipDistance.
+    */
+   GLuint userclip_planes_enabled:MAX_CLIP_PLANES;
+
    GLuint copy_edgeflag:1;
    GLuint point_coord_replace:8;
    GLuint clamp_vertex_color:1;