This will allow to hash additional data into the cache keys or even change the hashing algorithm easily, should we decide to do so.
Signed-off-by: Grazvydas Ignotas <nota...@gmail.com> --- src/compiler/glsl/glsl_parser_extras.cpp | 2 +- src/compiler/glsl/shader_cache.cpp | 2 +- src/compiler/glsl/tests/cache_test.c | 8 ++++---- src/gallium/drivers/radeonsi/si_state_shaders.c | 6 ++++-- src/mesa/state_tracker/st_shader_cache.c | 12 ++++++------ src/util/disk_cache.c | 7 +++++++ src/util/disk_cache.h | 14 ++++++++++++++ 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 776636c..224e46f 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -1939,7 +1939,7 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader, if (!force_recompile) { char buf[41]; - _mesa_sha1_compute(source, strlen(source), shader->sha1); + disk_cache_compute_key(ctx->Cache, 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) { diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index 6e56d86..d0909c7 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, _mesa_shader_stage_to_abbrev(sh->Stage), _mesa_sha1_format(sha1buf, sh->sha1)); } - _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 7a1ff0a..050c3b9 100644 --- a/src/compiler/glsl/tests/cache_test.c +++ b/src/compiler/glsl/tests/cache_test.c @@ -250,7 +250,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); @@ -267,7 +267,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)); result = disk_cache_get(cache, string_key, &size); @@ -301,7 +301,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); @@ -352,7 +352,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); diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index 9cde0aa..55be6b5 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -207,7 +207,8 @@ static bool si_shader_cache_insert_shader(struct si_screen *sscreen, } if (sscreen->b.disk_shader_cache && insert_into_disk_cache) { - _mesa_sha1_compute(tgsi_binary, *((uint32_t *)tgsi_binary), key); + disk_cache_compute_key(sscreen->b.disk_shader_cache, tgsi_binary, + *((uint32_t *)tgsi_binary), key); disk_cache_put(sscreen->b.disk_shader_cache, key, hw_binary, *((uint32_t *) hw_binary)); } @@ -226,7 +227,8 @@ static bool si_shader_cache_load_shader(struct si_screen *sscreen, unsigned char sha1[CACHE_KEY_SIZE]; size_t tg_size = *((uint32_t *) tgsi_binary); - _mesa_sha1_compute(tgsi_binary, tg_size, sha1); + disk_cache_compute_key(sscreen->b.disk_shader_cache, + tgsi_binary, tg_size, sha1); size_t binary_size; uint8_t *buffer = diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c index f22380c..e392dc0 100644 --- a/src/mesa/state_tracker/st_shader_cache.c +++ b/src/mesa/state_tracker/st_shader_cache.c @@ -183,7 +183,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, struct st_vertex_program *stvp = (struct st_vertex_program *) glprog; stage_sha1[i] = stvp->sha1; ralloc_strcat(&buf, " vs"); - _mesa_sha1_compute(buf, strlen(buf), stage_sha1[i]); + disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]); break; } case MESA_SHADER_TESS_CTRL: { @@ -191,7 +191,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, (struct st_tessctrl_program *) glprog; stage_sha1[i] = stcp->sha1; ralloc_strcat(&buf, " tcs"); - _mesa_sha1_compute(buf, strlen(buf), stage_sha1[i]); + disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]); break; } case MESA_SHADER_TESS_EVAL: { @@ -199,7 +199,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, (struct st_tesseval_program *) glprog; stage_sha1[i] = step->sha1; ralloc_strcat(&buf, " tes"); - _mesa_sha1_compute(buf, strlen(buf), stage_sha1[i]); + disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]); break; } case MESA_SHADER_GEOMETRY: { @@ -207,7 +207,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, (struct st_geometry_program *) glprog; stage_sha1[i] = stgp->sha1; ralloc_strcat(&buf, " gs"); - _mesa_sha1_compute(buf, strlen(buf), stage_sha1[i]); + disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]); break; } case MESA_SHADER_FRAGMENT: { @@ -215,7 +215,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, (struct st_fragment_program *) glprog; stage_sha1[i] = stfp->sha1; ralloc_strcat(&buf, " fs"); - _mesa_sha1_compute(buf, strlen(buf), stage_sha1[i]); + disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]); break; } case MESA_SHADER_COMPUTE: { @@ -223,7 +223,7 @@ st_load_tgsi_from_disk_cache(struct gl_context *ctx, (struct st_compute_program *) glprog; stage_sha1[i] = stcp->sha1; ralloc_strcat(&buf, " cs"); - _mesa_sha1_compute(buf, strlen(buf), stage_sha1[i]); + disk_cache_compute_key(ctx->Cache, buf, strlen(buf), stage_sha1[i]); break; } default: diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index facdcec..7990afb 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -982,4 +982,11 @@ disk_cache_has_key(struct disk_cache *cache, const cache_key key) return memcmp(entry, key, CACHE_KEY_SIZE) == 0; } +void +disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size, + cache_key key) +{ + _mesa_sha1_compute(data, size, key); +} + #endif /* ENABLE_SHADER_CACHE */ diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h index 3659b6d..e3663a6 100644 --- a/src/util/disk_cache.h +++ b/src/util/disk_cache.h @@ -178,6 +178,13 @@ disk_cache_put_key(struct disk_cache *cache, const cache_key key); bool disk_cache_has_key(struct disk_cache *cache, const cache_key key); +/** + * Compute the name \key from \data of given \size. + */ +void +disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size, + cache_key key); + #else static inline struct disk_cache * @@ -222,6 +229,13 @@ disk_cache_has_key(struct disk_cache *cache, const cache_key key) return false; } +void +disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size, + const cache_key key) +{ + return; +} + #endif /* ENABLE_SHADER_CACHE */ #ifdef __cplusplus -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev