i965: Only use the effective subset of the WM sampler key.
authorEric Anholt <eric@anholt.net>
Fri, 5 Mar 2010 22:13:24 +0000 (14:13 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 5 Mar 2010 23:23:30 +0000 (15:23 -0800)
The whole structure is 836 bytes, but if only the first one or two
samplers are used (as is common), the part that matters is only 56 or
108 bytes.  By using just that subset as the key (since the key size
is also part of the key), we improve firefox-talos-gfx performance by
1%.

src/mesa/drivers/dri/i965/brw_wm_sampler_state.c

index 3a33996..d7650af 100644 (file)
@@ -229,7 +229,7 @@ brw_wm_sampler_populate_key(struct brw_context *brw,
    GLcontext *ctx = &brw->intel.ctx;
    int unit;
 
-   memset(key, 0, sizeof(*key));
+   key->sampler_count = 0;
 
    for (unit = 0; unit < BRW_MAX_TEX_UNIT; unit++) {
       if (ctx->Texture.Unit[unit]._ReallyEnabled) {
@@ -240,6 +240,8 @@ brw_wm_sampler_populate_key(struct brw_context *brw,
         struct gl_texture_image *firstImage =
            texObj->Image[0][intelObj->firstLevel];
 
+        memset(entry, 0, sizeof(*entry));
+
          entry->tex_target = texObj->Target;
 
         entry->seamless_cube_map = (texObj->Target == GL_TEXTURE_CUBE_MAP)
@@ -288,7 +290,7 @@ static void upload_wm_samplers( struct brw_context *brw )
 {
    GLcontext *ctx = &brw->intel.ctx;
    struct wm_sampler_key key;
-   int i;
+   int i, sampler_key_size;
 
    brw_wm_sampler_populate_key(brw, &key);
 
@@ -302,8 +304,11 @@ static void upload_wm_samplers( struct brw_context *brw )
    if (brw->wm.sampler_count == 0)
       return;
 
+   /* Only include the populated portion of the key in the search. */
+   sampler_key_size = offsetof(struct wm_sampler_key,
+                              sampler[key.sampler_count]);
    brw->wm.sampler_bo = brw_search_cache(&brw->cache, BRW_SAMPLER,
-                                        &key, sizeof(key),
+                                        &key, sampler_key_size,
                                         brw->wm.sdc_bo, key.sampler_count,
                                         NULL);
 
@@ -323,7 +328,7 @@ static void upload_wm_samplers( struct brw_context *brw )
       }
 
       brw->wm.sampler_bo = brw_upload_cache(&brw->cache, BRW_SAMPLER,
-                                           &key, sizeof(key),
+                                           &key, sampler_key_size,
                                            brw->wm.sdc_bo, key.sampler_count,
                                            &sampler, sizeof(sampler));