diff options
author | Grazvydas Ignotas <[email protected]> | 2017-03-16 01:09:27 +0200 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-03-21 11:15:52 +1100 |
commit | 529a767041c880f90c4465cb34a89430459c7fce (patch) | |
tree | b19c1fcbc36ffe1314155559c7fa52226c8c6e2d /src/compiler/glsl | |
parent | 021c87fa24afe849e51dd0249ec8e7b59e097062 (diff) |
util/disk_cache: use a helper to compute cache keys
This will allow to hash additional data into the cache keys or even
change the hashing algorithm easily, should we decide to do so.
v2: don't try to compute key (and crash) if cache is disabled
Signed-off-by: Grazvydas Ignotas <[email protected]>
Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src/compiler/glsl')
-rw-r--r-- | src/compiler/glsl/glsl_parser_extras.cpp | 27 | ||||
-rw-r--r-- | src/compiler/glsl/shader_cache.cpp | 2 | ||||
-rw-r--r-- | src/compiler/glsl/tests/cache_test.c | 8 |
3 files changed, 20 insertions, 17 deletions
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 48cbc01ba74..8b5df3bdd89 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -1938,19 +1938,22 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, add_builtin_defines, state, ctx); if (!force_recompile) { - char buf[41]; - _mesa_sha1_compute(source, strlen(source), shader->sha1); - if (ctx->Cache && disk_cache_has_key(ctx->Cache, shader->sha1)) { - /* We've seen this shader before and know it compiles */ - if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { - _mesa_sha1_format(buf, shader->sha1); - fprintf(stderr, "deferring compile of shader: %s\n", buf); - } - shader->CompileStatus = compile_skipped; + if (ctx->Cache) { + char buf[41]; + disk_cache_compute_key(ctx->Cache, source, strlen(source), + shader->sha1); + if (disk_cache_has_key(ctx->Cache, shader->sha1)) { + /* We've seen this shader before and know it compiles */ + if (ctx->_Shader->Flags & GLSL_CACHE_INFO) { + _mesa_sha1_format(buf, shader->sha1); + fprintf(stderr, "deferring compile of shader: %s\n", buf); + } + shader->CompileStatus = compile_skipped; - free((void *)shader->FallbackSource); - shader->FallbackSource = NULL; - return; + free((void *)shader->FallbackSource); + shader->FallbackSource = NULL; + return; + } } } else { /* We should only ever end up here if a re-compile has been forced by a diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index 4b314d59b0e..dd8c6c0b408 100644 --- a/src/compiler/glsl/shader_cache.cpp +++ b/src/compiler/glsl/shader_cache.cpp @@ -1331,7 +1331,7 @@ shader_cache_read_program_metadata(struct gl_context *ctx, ralloc_asprintf_append(&buf, "%s: %s\n", _mesa_shader_stage_to_abbrev(sh->Stage), sha1buf); } - _mesa_sha1_compute(buf, strlen(buf), prog->data->sha1); + disk_cache_compute_key(cache, buf, strlen(buf), prog->data->sha1); ralloc_free(buf); size_t size; diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c index 832693e1039..ee6e84b45a4 100644 --- a/src/compiler/glsl/tests/cache_test.c +++ b/src/compiler/glsl/tests/cache_test.c @@ -271,7 +271,7 @@ test_put_and_get(void) cache = disk_cache_create("test", "make_check"); - _mesa_sha1_compute(blob, sizeof(blob), blob_key); + disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); /* Ensure that disk_cache_get returns nothing before anything is added. */ result = disk_cache_get(cache, blob_key, &size); @@ -293,7 +293,7 @@ test_put_and_get(void) free(result); /* Test put and get of a second item. */ - _mesa_sha1_compute(string, sizeof(string), string_key); + disk_cache_compute_key(cache, string, sizeof(string), string_key); disk_cache_put(cache, string_key, string, sizeof(string)); /* disk_cache_put() hands things off to a thread give it some time to @@ -332,7 +332,7 @@ test_put_and_get(void) * For this test, we force this signature to land in the same * directory as the original blob first written to the cache. */ - _mesa_sha1_compute(one_KB, 1024, one_KB_key); + disk_cache_compute_key(cache, one_KB, 1024, one_KB_key); one_KB_key[0] = blob_key_byte_zero; disk_cache_put(cache, one_KB_key, one_KB, 1024); @@ -402,7 +402,7 @@ test_put_and_get(void) /* Finally, check eviction again after adding an object of size 1M. */ one_MB = calloc(1024, 1024); - _mesa_sha1_compute(one_MB, 1024 * 1024, one_MB_key); + disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key); one_MB_key[0] = blob_key_byte_zero;; disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024); |