i965: Make a helper for finding an existing shader variant.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 11 Nov 2016 21:31:06 +0000 (13:31 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 18 Jan 2017 05:47:10 +0000 (21:47 -0800)
We had five copies of the same "walk the cache and look for an
existing shader variant for this program" code.  Now we have one
helper function that returns the key.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
src/mesa/drivers/dri/i965/brw_gs.c
src/mesa/drivers/dri/i965/brw_program_cache.c
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_tcs.c
src/mesa/drivers/dri/i965/brw_tes.c
src/mesa/drivers/dri/i965/brw_vs.c
src/mesa/drivers/dri/i965/brw_wm.c

index b7fb9f9c1eaab697523f716fd23f4b1342cabfef..299620311a5e675c790bc953a2a2482b33a96877 100644 (file)
@@ -40,26 +40,14 @@ static void
 brw_gs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
                        const struct brw_gs_prog_key *key)
 {
-   struct brw_cache_item *c = NULL;
-   const struct brw_gs_prog_key *old_key = NULL;
-   bool found = false;
-
    perf_debug("Recompiling geometry shader for program %d\n", prog->Id);
 
-   for (unsigned int i = 0; i < brw->cache.size; i++) {
-      for (c = brw->cache.items[i]; c; c = c->next) {
-         if (c->cache_id == BRW_CACHE_GS_PROG) {
-            old_key = c->key;
-
-            if (old_key->program_string_id == key->program_string_id)
-               break;
-         }
-      }
-      if (c)
-         break;
-   }
+   bool found = false;
+   const struct brw_gs_prog_key *old_key =
+      brw_find_previous_compile(&brw->cache, BRW_CACHE_GS_PROG,
+                                key->program_string_id);
 
-   if (!c) {
+   if (!old_key) {
       perf_debug("  Didn't find previous compile in the shader cache for "
                  "debug\n");
       return;
index 3947904ac50587881e433d0839c4c1299c14a3c4..3d95372bc0e4052d1094ea168618f42b27d8c9fe 100644 (file)
 
 #define FILE_DEBUG_FLAG DEBUG_STATE
 
+static unsigned
+get_program_string_id(enum brw_cache_id cache_id, const void *key)
+{
+   switch (cache_id) {
+   case BRW_CACHE_VS_PROG:
+      return ((struct brw_vs_prog_key *) key)->program_string_id;
+   case BRW_CACHE_TCS_PROG:
+      return ((struct brw_tcs_prog_key *) key)->program_string_id;
+   case BRW_CACHE_TES_PROG:
+      return ((struct brw_tes_prog_key *) key)->program_string_id;
+   case BRW_CACHE_GS_PROG:
+      return ((struct brw_gs_prog_key *) key)->program_string_id;
+   case BRW_CACHE_CS_PROG:
+      return ((struct brw_cs_prog_key *) key)->program_string_id;
+   case BRW_CACHE_FS_PROG:
+      return ((struct brw_wm_prog_key *) key)->program_string_id;
+   default:
+      unreachable("no program string id for this kind of program");
+   }
+}
+
 static GLuint
 hash_key(struct brw_cache_item *item)
 {
@@ -268,6 +289,23 @@ brw_alloc_item_data(struct brw_cache *cache, uint32_t size)
    return offset;
 }
 
+const void *
+brw_find_previous_compile(struct brw_cache *cache,
+                          enum brw_cache_id cache_id,
+                          unsigned program_string_id)
+{
+   for (unsigned i = 0; i < cache->size; i++) {
+      for (struct brw_cache_item *c = cache->items[i]; c; c = c->next) {
+         if (c->cache_id == cache_id &&
+             get_program_string_id(cache_id, c->key) == program_string_id) {
+            return c->key;
+         }
+      }
+   }
+
+   return NULL;
+}
+
 void
 brw_upload_cache(struct brw_cache *cache,
                  enum brw_cache_id cache_id,
index 176557b7c45e724a99fc6b5bfb48e7831944dd74..bd82212be4dc009a892483ac0088c2d62552353a 100644 (file)
@@ -235,6 +235,11 @@ bool brw_search_cache(struct brw_cache *cache,
                       const void *key,
                       GLuint key_size,
                       uint32_t *inout_offset, void *inout_aux);
+
+const void *brw_find_previous_compile(struct brw_cache *cache,
+                                      enum brw_cache_id cache_id,
+                                      unsigned program_string_id);
+
 void brw_program_cache_check_size(struct brw_context *brw);
 
 void brw_init_caches( struct brw_context *brw );
index 78ad257e3b987a501df7d3ce8ee64c5eaecf63ab..bbba7496fa609bb6923b92e581e6c2edb5e6313d 100644 (file)
@@ -120,27 +120,15 @@ static void
 brw_tcs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
                        const struct brw_tcs_prog_key *key)
 {
-   struct brw_cache_item *c = NULL;
-   const struct brw_tcs_prog_key *old_key = NULL;
-   bool found = false;
-
    perf_debug("Recompiling tessellation control shader for program %d\n",
               prog->Id);
 
-   for (unsigned int i = 0; i < brw->cache.size; i++) {
-      for (c = brw->cache.items[i]; c; c = c->next) {
-         if (c->cache_id == BRW_CACHE_TCS_PROG) {
-            old_key = c->key;
-
-            if (old_key->program_string_id == key->program_string_id)
-               break;
-         }
-      }
-      if (c)
-         break;
-   }
+   bool found = false;
+   const struct brw_tcs_prog_key *old_key =
+      brw_find_previous_compile(&brw->cache, BRW_CACHE_TCS_PROG,
+                                key->program_string_id);
 
-   if (!c) {
+   if (!old_key) {
       perf_debug("  Didn't find previous compile in the shader cache for "
                  "debug\n");
       return;
index 57dcda7140abc7b05db8d01198df785a84abcd00..cb12b9c5a69e61c6a3708fc42d4bc2732313883a 100644 (file)
@@ -38,27 +38,15 @@ static void
 brw_tes_debug_recompile(struct brw_context *brw, struct gl_program *prog,
                        const struct brw_tes_prog_key *key)
 {
-   struct brw_cache_item *c = NULL;
-   const struct brw_tes_prog_key *old_key = NULL;
-   bool found = false;
-
    perf_debug("Recompiling tessellation evaluation shader for program %d\n",
               prog->Id);
 
-   for (unsigned int i = 0; i < brw->cache.size; i++) {
-      for (c = brw->cache.items[i]; c; c = c->next) {
-         if (c->cache_id == BRW_CACHE_TES_PROG) {
-            old_key = c->key;
-
-            if (old_key->program_string_id == key->program_string_id)
-               break;
-         }
-      }
-      if (c)
-         break;
-   }
+   bool found = false;
+   const struct brw_tes_prog_key *old_key =
+      brw_find_previous_compile(&brw->cache, BRW_CACHE_TES_PROG,
+                                key->program_string_id);
 
-   if (!c) {
+   if (!old_key) {
       perf_debug("  Didn't find previous compile in the shader cache for "
                  "debug\n");
       return;
index afb1f2033089c8eeeff1b56e5914f1ce1d626d09..5d1993931819838fbd3e758a55ac0013ddc59861 100644 (file)
@@ -88,26 +88,14 @@ static void
 brw_vs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
                        const struct brw_vs_prog_key *key)
 {
-   struct brw_cache_item *c = NULL;
-   const struct brw_vs_prog_key *old_key = NULL;
-   bool found = false;
-
    perf_debug("Recompiling vertex shader for program %d\n", prog->Id);
 
-   for (unsigned int i = 0; i < brw->cache.size; i++) {
-      for (c = brw->cache.items[i]; c; c = c->next) {
-         if (c->cache_id == BRW_CACHE_VS_PROG) {
-            old_key = c->key;
-
-            if (old_key->program_string_id == key->program_string_id)
-               break;
-         }
-      }
-      if (c)
-         break;
-   }
+   bool found = false;
+   const struct brw_vs_prog_key *old_key =
+      brw_find_previous_compile(&brw->cache, BRW_CACHE_VS_PROG,
+                                key->program_string_id);
 
-   if (!c) {
+   if (!old_key) {
       perf_debug("  Didn't find previous compile in the shader cache for "
                  "debug\n");
       return;
index bd2b24a3bfab0d0c9a8f07a00d9328d8db58971d..a774720202adde26f9259ef49a774a4daaef530c 100644 (file)
@@ -70,26 +70,14 @@ static void
 brw_wm_debug_recompile(struct brw_context *brw, struct gl_program *prog,
                        const struct brw_wm_prog_key *key)
 {
-   struct brw_cache_item *c = NULL;
-   const struct brw_wm_prog_key *old_key = NULL;
-   bool found = false;
-
    perf_debug("Recompiling fragment shader for program %d\n", prog->Id);
 
-   for (unsigned int i = 0; i < brw->cache.size; i++) {
-      for (c = brw->cache.items[i]; c; c = c->next) {
-         if (c->cache_id == BRW_CACHE_FS_PROG) {
-            old_key = c->key;
-
-            if (old_key->program_string_id == key->program_string_id)
-               break;
-         }
-      }
-      if (c)
-         break;
-   }
+   bool found = false;
+   const struct brw_wm_prog_key *old_key =
+      brw_find_previous_compile(&brw->cache, BRW_CACHE_FS_PROG,
+                                key->program_string_id);
 
-   if (!c) {
+   if (!old_key) {
       perf_debug("  Didn't find previous compile in the shader cache for debug\n");
       return;
    }