[Mesa-dev] [PATCH 02/10] i965 gs: Reduce information in key to avoid unnecessary recompiles.

Paul Berry stereotype441 at gmail.com
Mon Dec 5 09:40:45 PST 2011


Previously, the geometry shader program key was storing all the
information necessary to compute the exact structure of the VUE map
(attrs and userclip_active).  However, the GS program doesn't depend
on the exact structure of the VUE map; only on the size (in 256-bit
registers) of the VUE.  So we were recompiling the GS program
unnecessarily when the VUE map changed in structure but not in size.

This patch changes the key to store just the size of the VUE map, not
its structure.
---
 src/mesa/drivers/dri/i965/brw_gs.c      |   17 ++++++++---------
 src/mesa/drivers/dri/i965/brw_gs.h      |    6 +-----
 src/mesa/drivers/dri/i965/brw_gs_emit.c |    8 ++++----
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index 91f8d0b..1b23f3a 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -62,10 +62,6 @@ static void compile_gs_prog( struct brw_context *brw,
    memset(&c, 0, sizeof(c));
    
    c.key = *key;
-   /* The geometry shader needs to access the entire VUE. */
-   struct brw_vue_map vue_map;
-   brw_compute_vue_map(&vue_map, intel, c.key.userclip_active, c.key.attrs);
-   c.nr_regs = (vue_map.num_slots + 1)/2;
 
    mem_ctx = NULL;
    
@@ -144,8 +140,14 @@ static void populate_key( struct brw_context *brw,
 
    memset(key, 0, sizeof(*key));
 
-   /* CACHE_NEW_VS_PROG */
-   key->attrs = brw->vs.prog_data->outputs_written;
+   /* The geometry shader needs to access the entire VUE. */
+   struct brw_vue_map vue_map;
+   brw_compute_vue_map(&vue_map, intel,
+                       /* _NEW_TRANSFORM */
+                       ctx->Transform.ClipPlanesEnabled != 0,
+                       /* CACHE_NEW_VS_PROG */
+                       brw->vs.prog_data->outputs_written);
+   key->nr_regs = (vue_map.num_slots + 1)/2;
 
    /* BRW_NEW_PRIMITIVE */
    key->primitive = gs_prim[brw->primitive];
@@ -159,9 +161,6 @@ static void populate_key( struct brw_context *brw,
       key->pv_first = true;
    }
 
-   /* _NEW_TRANSFORM */
-   key->userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
-
    key->need_gs_prog = (intel->gen >= 6)
       ? 0
       : (brw->primitive == _3DPRIM_QUADLIST ||
diff --git a/src/mesa/drivers/dri/i965/brw_gs.h b/src/mesa/drivers/dri/i965/brw_gs.h
index 0e4ff3f..270b647 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.h
+++ b/src/mesa/drivers/dri/i965/brw_gs.h
@@ -40,11 +40,10 @@
 #define MAX_GS_VERTS (4)	     
 
 struct brw_gs_prog_key {
-   GLbitfield64 attrs;
    GLuint primitive:8; /**< Hardware primitive, such as _3DPRIM_TRILIST. */
    GLuint pv_first:1;
    GLuint need_gs_prog:1;
-   GLuint userclip_active:1;
+   GLuint nr_regs:8;
 };
 
 struct brw_gs_compile {
@@ -57,9 +56,6 @@ struct brw_gs_compile {
       struct brw_reg vertex[MAX_GS_VERTS];
       struct brw_reg temp;
    } reg;
-
-   /* Number of registers used to store vertex data */
-   GLuint nr_regs;
 };
 
 #define ATTR_SIZE  (4*4)
diff --git a/src/mesa/drivers/dri/i965/brw_gs_emit.c b/src/mesa/drivers/dri/i965/brw_gs_emit.c
index e9875cd..8097fad 100644
--- a/src/mesa/drivers/dri/i965/brw_gs_emit.c
+++ b/src/mesa/drivers/dri/i965/brw_gs_emit.c
@@ -55,12 +55,12 @@ static void brw_gs_alloc_regs( struct brw_gs_compile *c,
     */
    for (j = 0; j < nr_verts; j++) {
       c->reg.vertex[j] = brw_vec4_grf(i, 0);
-      i += c->nr_regs;
+      i += c->key.nr_regs;
    }
 
    c->reg.temp = brw_vec8_grf(i, 0);
 
-   c->prog_data.urb_read_length = c->nr_regs; 
+   c->prog_data.urb_read_length = c->key.nr_regs; 
    c->prog_data.total_grf = i;
 }
 
@@ -90,7 +90,7 @@ static void brw_gs_emit_vue(struct brw_gs_compile *c,
 
    /* Copy the vertex from vertn into m1..mN+1:
     */
-   brw_copy8(p, brw_message_reg(1), vert, c->nr_regs);
+   brw_copy8(p, brw_message_reg(1), vert, c->key.nr_regs);
 
    /* Send each vertex as a seperate write to the urb.  This is
     * different to the concept in brw_sf_emit.c, where subsequent
@@ -104,7 +104,7 @@ static void brw_gs_emit_vue(struct brw_gs_compile *c,
 		 temp,
 		 allocate,
 		 1,		/* used */
-		 c->nr_regs + 1, /* msg length */
+		 c->key.nr_regs + 1, /* msg length */
 		 allocate ? 1 : 0, /* response length */
 		 allocate ? 0 : 1, /* eot */
 		 1,		/* writes_complete */
-- 
1.7.6.4



More information about the mesa-dev mailing list