To be used by subsequent patches, for now it's just the initial sha1 state.
Signed-off-by: Grazvydas Ignotas <nota...@gmail.com> --- src/util/disk_cache.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index 7990afb..b639907 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -60,6 +60,9 @@ struct disk_cache { /* The path to the cache directory. */ char *path; + /* Base hashing context for computing cache keys. */ + struct mesa_sha1 *key_hash_base; + /* A pointer to the mmapped index file within the cache directory. */ uint8_t *index_mmap; size_t index_mmap_size; @@ -295,6 +298,10 @@ disk_cache_create(const char *gpu_name, const char *timestamp) if (cache == NULL) goto fail; + cache->key_hash_base = _mesa_sha1_init(); + if (cache->key_hash_base == NULL) + goto fail; + cache->path = ralloc_strdup(cache, path); if (cache->path == NULL) goto fail; @@ -384,8 +391,11 @@ disk_cache_create(const char *gpu_name, const char *timestamp) fail: if (fd != -1) close(fd); - if (cache) + if (cache) { + if (cache->key_hash_base) + _mesa_sha1_final(cache->key_hash_base, NULL); ralloc_free(cache); + } ralloc_free(local); return NULL; @@ -394,8 +404,10 @@ disk_cache_create(const char *gpu_name, const char *timestamp) void disk_cache_destroy(struct disk_cache *cache) { - if (cache) + if (cache) { munmap(cache->index_mmap, cache->index_mmap_size); + _mesa_sha1_final(cache->key_hash_base, NULL); + } ralloc_free(cache); } @@ -986,7 +998,12 @@ void disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size, cache_key key) { - _mesa_sha1_compute(data, size, key); + struct mesa_sha1 *ctx = _mesa_sha1_clone(cache->key_hash_base); + + if (ctx == NULL) + return; + _mesa_sha1_update(ctx, data, size); + _mesa_sha1_final(ctx, key); } #endif /* ENABLE_SHADER_CACHE */ -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev