[Mesa-dev] [PATCH 58/77] i965: handle incompatiable binaries in shader-cache

Timothy Arceri timothy.arceri at collabora.com
Mon Oct 3 06:05:17 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 | 41 ++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index e326195..280d117 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -422,6 +422,40 @@ FAIL:
    fallback_to_full_recompile(brw, prog);
 }
 
+static void
+cache_binary(struct brw_context *brw, struct blob *binary,
+             struct program_cache *cache, unsigned char *sha1)
+{
+   char buf[41];
+   size_t size;
+   uint8_t *buffer = 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");
+         }
+         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));
+   }
+
+   cache_put(cache, sha1, binary->data, binary->size);
+}
+
 static bool
 write_program_data(struct brw_context *brw, struct gl_shader_program *prog,
                    void *key, struct brw_stage_prog_data *stage_prog_data,
@@ -489,12 +523,7 @@ write_program_data(struct brw_context *brw, struct gl_shader_program *prog,
                         ptr_to_uint64_t((void *) stage_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));
-   }
-
-   cache_put(cache, sha1, binary->data, binary->size);
+   cache_binary(brw, binary, cache, sha1);
    ralloc_free (binary);
 
    return true;
-- 
2.7.4



More information about the mesa-dev mailing list