[Mesa-dev] [PATCH 26/27] i965: Initialize disk shader cache when INTEL_SHADER_CACHE env var is set

Jordan Justen jordan.l.justen at intel.com
Sat Aug 19 07:44:42 UTC 2017


We use the build-id of i965_dri.so for the timestamp, and the name
from i965_pci_ids.h for the device name.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.c    |  2 ++
 src/mesa/drivers/dri/i965/brw_disk_cache.c | 45 ++++++++++++++++++++++++++++++
 src/mesa/drivers/dri/i965/brw_state.h      |  1 +
 3 files changed, 48 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 3904bc708b..5d7d555f79 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1014,6 +1014,8 @@ brwCreateContext(gl_api api,
                          brw->dri_config_options_sha1);
    brw->ctx.Const.dri_config_options_sha1 = brw->dri_config_options_sha1;
 
+   brw_disk_cache_init(brw);
+
    return true;
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_disk_cache.c b/src/mesa/drivers/dri/i965/brw_disk_cache.c
index 036b56225e..ef5380126a 100644
--- a/src/mesa/drivers/dri/i965/brw_disk_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_disk_cache.c
@@ -29,6 +29,8 @@
 #include "main/mtypes.h"
 #include "main/shaderobj.h"
 #include "program/program.h"
+#include "util/build_id.h"
+#include "util/debug.h"
 #include "util/disk_cache.h"
 #include "util/macros.h"
 #include "util/mesa-sha1.h"
@@ -652,3 +654,46 @@ brw_disk_cache_write_compute_program(struct brw_context *brw)
                          MESA_SHADER_COMPUTE);
    }
 }
+
+void
+brw_disk_cache_init(struct brw_context *brw)
+{
+#ifdef ENABLE_SHADER_CACHE
+   if (!env_var_as_boolean("INTEL_SHADER_CACHE", false))
+      return;
+
+   char *renderer = NULL;
+   int len = asprintf(&renderer, "i965_%04x", brw->screen->deviceID);
+   if (len < 0) {
+      renderer = strdup("i965");
+   }
+   if (renderer == NULL)
+       return;
+
+   const struct build_id_note *note = build_id_find_nhdr("i965_dri.so");
+   int id_size = note ? build_id_length(note) : 0;
+   char *timestamp;
+   if (id_size > 0) {
+      timestamp = malloc(2 * id_size + 1);
+      if (!timestamp)
+         id_size = 0;
+   }
+   if (id_size > 0) {
+      const uint8_t *data = build_id_data(note);
+      int i;
+
+      for (i = 0; i < id_size; i++)
+         snprintf(&timestamp[2 * i], 3, "%02x", data[i]);
+   } else {
+      timestamp = strdup("now");
+   }
+   if (timestamp == NULL) {
+      free(renderer);
+      return;
+   }
+
+   brw->ctx.Cache = disk_cache_create(renderer, timestamp, 0);
+   free(renderer);
+   free(timestamp);
+#endif
+}
diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h
index ff8f1b5157..695446f175 100644
--- a/src/mesa/drivers/dri/i965/brw_state.h
+++ b/src/mesa/drivers/dri/i965/brw_state.h
@@ -132,6 +132,7 @@ void gen8_write_pma_stall_bits(struct brw_context *brw,
                                uint32_t pma_stall_bits);
 
 /* brw_disk_cache.c */
+void brw_disk_cache_init(struct brw_context *brw);
 bool brw_disk_cache_upload_program(struct brw_context *brw,
                                    gl_shader_stage stage);
 void brw_disk_cache_write_compute_program(struct brw_context *brw);
-- 
2.14.0



More information about the mesa-dev mailing list