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 | 49 ++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_shader_cache.c b/src/mesa/drivers/dri/i965/brw_shader_cache.c index b21eaad..19bd45e 100644 --- a/src/mesa/drivers/dri/i965/brw_shader_cache.c +++ b/src/mesa/drivers/dri/i965/brw_shader_cache.c @@ -470,6 +470,40 @@ write_program_data(struct gl_shader_program *prog, struct blob *binary, } } +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); +} + void write_cached_program(struct brw_context *brw) { @@ -478,7 +512,6 @@ write_cached_program(struct brw_context *brw) size_t program_size; struct gl_shader_program *prog; struct program_cache *cache; - char buf[41]; cache = brw->ctx.Cache; if (cache == NULL) @@ -525,12 +558,7 @@ write_cached_program(struct brw_context *brw) write_program_data(prog, binary, &brw->vs.prog_data->base.base, MESA_SHADER_VERTEX); - if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) { - fprintf(stderr, "putting binary in cache: %s\n", - _mesa_sha1_format(buf, vs_sha1)); - } - - cache_put(cache, vs_sha1, binary->data, binary->size); + cache_binary(brw, binary, cache, vs_sha1); ralloc_free (binary); } @@ -562,12 +590,7 @@ write_cached_program(struct brw_context *brw) write_program_data(prog, binary, &brw->wm.prog_data->base, MESA_SHADER_FRAGMENT); - if (brw->ctx._Shader->Flags & GLSL_CACHE_INFO) { - fprintf(stderr, "putting binary in cache: %s\n", - _mesa_sha1_format(buf, wm_sha1)); - } - - cache_put(cache, wm_sha1, binary->data, binary->size); + cache_binary(brw, binary, cache, wm_sha1); ralloc_free (binary); } -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev