Mesa (master): glsl: pass shader source keys to the disk cache

Timothy Arceri tarceri at kemper.freedesktop.org
Fri Aug 25 03:22:53 UTC 2017


Module: Mesa
Branch: master
Commit: ea2515d780a40599036ff50b572d309e69635d20
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ea2515d780a40599036ff50b572d309e69635d20

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Wed Aug 23 16:33:00 2017 +1000

glsl: pass shader source keys to the disk cache

We don't actually write them to disk here. That will happen in the
following commit.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

---

 src/compiler/glsl/shader_cache.cpp              | 20 +++++++++++++++++---
 src/compiler/glsl/tests/cache_test.c            | 12 ++++++------
 src/gallium/drivers/radeonsi/si_state_shaders.c |  2 +-
 src/mesa/state_tracker/st_shader_cache.c        |  2 +-
 src/util/disk_cache.c                           |  8 +++++---
 src/util/disk_cache.h                           |  6 ++++--
 6 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index aa6c067d04..3af14be9a1 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -1406,23 +1406,37 @@ shader_cache_write_program_metadata(struct gl_context *ctx,
 
    write_program_resource_list(metadata, prog);
 
+   struct cache_item_metadata cache_item_metadata;
+   cache_item_metadata.type = CACHE_ITEM_TYPE_GLSL;
+   cache_item_metadata.keys =
+      (cache_key *) malloc(prog->NumShaders * sizeof(cache_key));
+   cache_item_metadata.num_keys = prog->NumShaders;
+
+   if (!cache_item_metadata.keys)
+      goto fail;
+
    char sha1_buf[41];
    for (unsigned i = 0; i < prog->NumShaders; i++) {
       disk_cache_put_key(cache, prog->Shaders[i]->sha1);
+      memcpy(cache_item_metadata.keys[i], prog->Shaders[i]->sha1,
+             sizeof(cache_key));
       if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
          _mesa_sha1_format(sha1_buf, prog->Shaders[i]->sha1);
          fprintf(stderr, "marking shader: %s\n", sha1_buf);
       }
    }
 
-   disk_cache_put(cache, prog->data->sha1, metadata->data, metadata->size);
-
-   blob_destroy(metadata);
+   disk_cache_put(cache, prog->data->sha1, metadata->data, metadata->size,
+                  &cache_item_metadata);
 
    if (ctx->_Shader->Flags & GLSL_CACHE_INFO) {
       _mesa_sha1_format(sha1_buf, prog->data->sha1);
       fprintf(stderr, "putting program metadata in cache: %s\n", sha1_buf);
    }
+
+fail:
+   free(cache_item_metadata.keys);
+   blob_destroy(metadata);
 }
 
 bool
diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
index 3796ce6170..8e7912c71b 100644
--- a/src/compiler/glsl/tests/cache_test.c
+++ b/src/compiler/glsl/tests/cache_test.c
@@ -268,7 +268,7 @@ test_put_and_get(void)
    expect_equal(size, 0, "disk_cache_get with non-existent item (size)");
 
    /* Simple test of put and get. */
-   disk_cache_put(cache, blob_key, blob, sizeof(blob));
+   disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
 
    /* disk_cache_put() hands things off to a thread give it some time to
     * finish.
@@ -283,7 +283,7 @@ test_put_and_get(void)
 
    /* Test put and get of a second item. */
    disk_cache_compute_key(cache, string, sizeof(string), string_key);
-   disk_cache_put(cache, string_key, string, sizeof(string));
+   disk_cache_put(cache, string_key, string, sizeof(string), NULL);
 
    /* disk_cache_put() hands things off to a thread give it some time to
     * finish.
@@ -324,7 +324,7 @@ test_put_and_get(void)
    disk_cache_compute_key(cache, one_KB, 1024, one_KB_key);
    one_KB_key[0] = blob_key[0];
 
-   disk_cache_put(cache, one_KB_key, one_KB, 1024);
+   disk_cache_put(cache, one_KB_key, one_KB, 1024, NULL);
 
    free(one_KB);
 
@@ -367,8 +367,8 @@ test_put_and_get(void)
    setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
    cache = disk_cache_create("test", "make_check", 0);
 
-   disk_cache_put(cache, blob_key, blob, sizeof(blob));
-   disk_cache_put(cache, string_key, string, sizeof(string));
+   disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
+   disk_cache_put(cache, string_key, string, sizeof(string), NULL);
 
    /* disk_cache_put() hands things off to a thread give it some time to
     * finish.
@@ -394,7 +394,7 @@ test_put_and_get(void)
    disk_cache_compute_key(cache, one_MB, 1024 * 1024, one_MB_key);
    one_MB_key[0] = blob_key[0];
 
-   disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024);
+   disk_cache_put(cache, one_MB_key, one_MB, 1024 * 1024, NULL);
 
    free(one_MB);
 
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index af432e0b3c..35bc0db74e 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -213,7 +213,7 @@ static bool si_shader_cache_insert_shader(struct si_screen *sscreen,
 		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));
+			       *((uint32_t *) hw_binary), NULL);
 	}
 
 	return true;
diff --git a/src/mesa/state_tracker/st_shader_cache.c b/src/mesa/state_tracker/st_shader_cache.c
index ba964eb5f0..2c38f27ffd 100644
--- a/src/mesa/state_tracker/st_shader_cache.c
+++ b/src/mesa/state_tracker/st_shader_cache.c
@@ -47,7 +47,7 @@ write_tgsi_to_cache(struct blob *blob, struct pipe_shader_state *tgsi,
    blob_write_bytes(blob, tgsi->tokens,
                     num_tokens * sizeof(struct tgsi_token));
 
-   disk_cache_put(st->ctx->Cache, sha1, blob->data, blob->size);
+   disk_cache_put(st->ctx->Cache, sha1, blob->data, blob->size, NULL);
 }
 
 /**
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index d2cd4e85c4..6e85a5e2be 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -768,7 +768,8 @@ deflate_and_write_to_disk(const void *in_data, size_t in_data_size, int dest,
 
 static struct disk_cache_put_job *
 create_put_job(struct disk_cache *cache, const cache_key key,
-               const void *data, size_t size)
+               const void *data, size_t size,
+               struct cache_item_metadata *cache_item_metadata)
 {
    struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *)
       malloc(sizeof(struct disk_cache_put_job) + size);
@@ -931,10 +932,11 @@ cache_put(void *job, int thread_index)
 
 void
 disk_cache_put(struct disk_cache *cache, const cache_key key,
-               const void *data, size_t size)
+               const void *data, size_t size,
+               struct cache_item_metadata *cache_item_metadata)
 {
    struct disk_cache_put_job *dc_job =
-      create_put_job(cache, key, data, size);
+      create_put_job(cache, key, data, size, cache_item_metadata);
 
    if (dc_job) {
       util_queue_fence_init(&dc_job->fence);
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index ef5ec2ac92..d2e4d9a69c 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -141,7 +141,8 @@ disk_cache_remove(struct disk_cache *cache, const cache_key key);
  */
 void
 disk_cache_put(struct disk_cache *cache, const cache_key key,
-               const void *data, size_t size);
+               const void *data, size_t size,
+               struct cache_item_metadata *cache_item_metadata);
 
 /**
  * Retrieve an item previously stored in the cache with the name <key>.
@@ -207,7 +208,8 @@ disk_cache_destroy(struct disk_cache *cache) {
 
 static inline void
 disk_cache_put(struct disk_cache *cache, const cache_key key,
-          const void *data, size_t size)
+               const void *data, size_t size,
+               struct cache_item_metadata *cache_item_metadata)
 {
    return;
 }




More information about the mesa-commit mailing list