[Mesa-dev] [PATCH 21/27] i965: handle incompatiable binaries in shader-cache

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


From: Timothy Arceri <timothy.arceri at collabora.com>

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_disk_cache.c | 42 +++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_disk_cache.c b/src/mesa/drivers/dri/i965/brw_disk_cache.c
index e8b4f2f5a9..036b56225e 100644
--- a/src/mesa/drivers/dri/i965/brw_disk_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_disk_cache.c
@@ -444,6 +444,40 @@ FAIL:
    return false;
 }
 
+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) {
+      _mesa_sha1_format(buf, sha1);
+      fprintf(stderr, "putting binary in cache: %s\n", buf);
+   }
+
+   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,
@@ -452,7 +486,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();
    if (!binary)
@@ -518,12 +551,7 @@ write_program_data(struct brw_context *brw, struct gl_program *prog,
                         ptr_to_uint64_t((void *) prog_data->pull_param[i]));
    }
 
-   _mesa_sha1_format(buf, sha1);
-   if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
-      fprintf(stderr, "putting binary in cache: %s\n", buf);
-   }
-
-   disk_cache_put(cache, sha1, binary->data, binary->size);
+   cache_binary(brw, binary, cache, sha1);
 
    prog->program_written_to_cache = true;
    free(binary);
-- 
2.14.0



More information about the mesa-dev mailing list