[Mesa-dev] [PATCH 4/7] util/disk_cache: base key hashes from initial context

Grazvydas Ignotas notasas at gmail.com
Sun Mar 12 18:32:05 UTC 2017


To be used by subsequent patches, for now it's just the initial
sha1 state.

Signed-off-by: Grazvydas Ignotas <notasas at 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



More information about the mesa-dev mailing list