[Mesa-dev] [PATCH 49/56] i965: handle incompatiable binaries in shader-cache

Timothy Arceri timothy.arceri at collabora.com
Tue Nov 29 03:58:48 UTC 2016


Remove incompatiable binaries of a program before attempting
to store a new one.

A previous commit already handles deleting an incompatiable
binary for shader variants this handles the case for an initial
shader compile. Without this a variant would delete the binary
then fallback to a full recompile but would skip recreating state
that would otherwise normally already exist already and crash.
---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 42 +++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index bb57e9a..f64b888 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -462,6 +462,40 @@ FAIL:
 }
 
 static void
+cache_binary(struct brw_context *brw, struct blob *binary,
+             struct disk_cache *cache, unsigned char *sha1)
+{
+   char buf[41];
+   size_t size;
+   uint8_t *buffer = disk_cache_get(cache, sha1, &size);
+
+   if (buffer) {
+      struct blob_reader read_b;
+      blob_reader_init(&read_b, buffer, size);
+
+      char *version_string = blob_read_string(&read_b);
+      if (strcmp(brw->ctx.VersionString, version_string) != 0) {
+         /* The cached version of the program was created with a different
+          * version of Mesa so remove it.
+          */
+         if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
+            fprintf(stderr, "removing binary created with incompatible mesa "
+                    "version\n");
+         }
+         disk_cache_remove(cache, sha1);
+      }
+      free(buffer);
+   }
+
+   if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
+      fprintf(stderr, "putting binary in cache: %s\n",
+              _mesa_sha1_format(buf, sha1));
+   }
+
+   disk_cache_put(cache, sha1, binary->data, binary->size);
+}
+
+static void
 write_program_data(struct brw_context *brw, struct gl_program *prog,
                    void *key, struct brw_stage_prog_data *prog_data,
                    size_t program_size, size_t prog_data_size,
@@ -469,7 +503,6 @@ write_program_data(struct brw_context *brw, struct gl_program *prog,
                    gl_shader_stage stage)
 {
    unsigned char sha1[20];
-   char buf[41];
 
    struct blob *binary = blob_create(NULL);
    if (!binary)
@@ -526,12 +559,7 @@ write_program_data(struct brw_context *brw, struct gl_program *prog,
                         ptr_to_uint64_t((void *) prog_data->pull_param[i]));
    }
 
-   if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
-      fprintf(stderr, "putting binary in cache: %s\n",
-              _mesa_sha1_format(buf, sha1));
-   }
-
-   disk_cache_put(cache, sha1, binary->data, binary->size);
+   cache_binary(brw, binary, cache, sha1);
 
    prog->program_written_to_cache = true;
    ralloc_free(binary);
-- 
2.7.4



More information about the mesa-dev mailing list