[Mesa-dev] [PATCH 50/77] i965: track mesa version shader cache items were created with

Timothy Arceri timothy.arceri at collabora.com
Mon Oct 3 06:05:09 UTC 2016


Also remove cache item and fallback to full recompile if current Mesa
version differs.
---
 src/mesa/drivers/dri/i965/brw_shader_cache.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c
index ea050df..d003c71 100644
--- a/src/mesa/drivers/dri/i965/brw_shader_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c
@@ -290,6 +290,20 @@ read_and_upload(struct brw_context *brw, struct program_cache *cache,
 
    blob_reader_init(binary, buffer, size);
 
+   char *version_string = blob_read_string(binary);
+   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 and fallback to full recompile.
+       */
+      if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) {
+         fprintf(stderr, "removing binary was created with incompatible mesa "
+                 "version\n");
+      }
+      cache_remove(cache, binary_sha1);
+      free(buffer);
+      return false;
+   }
+
    /* Read shader program from blob. */
    size_t program_size = blob_read_uint32(binary);
    uint8_t *program = blob_read_bytes(binary, program_size);
@@ -385,6 +399,8 @@ write_program_data(struct brw_context *brw, struct gl_shader_program *prog,
    if (binary == NULL)
       return false;
 
+   blob_write_string(binary, brw->ctx.VersionString);
+
    gen_shader_sha1(brw, prog, stage, key, sha1);
 
    /* Write program to blob. */
-- 
2.7.4



More information about the mesa-dev mailing list