<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 6, 2017 at 9:42 PM, Timothy Arceri <span dir="ltr"><<a href="mailto:tarceri@itsqueeze.com" target="_blank">tarceri@itsqueeze.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In order to avoid costly fallback recompiles when cache items are<br>
created with an old version of Mesa or for a different gpu on the<br>
same system we want to create directories that look like this:<br>
<br>
./{MESA_VERSION_STRING}/{GPU_<wbr>ID}<br>
<br>
For llvm based drivers we will probably want an additional<br>
{LLVM_VERSION} folder although it looks like there is currently<br>
no support for querying this at runtime.<br>
---<br>
 src/compiler/glsl/tests/cache_<wbr>test.c | 20 ++++++++++----------<br>
 src/util/disk_cache.c                | 29 +++++++++++++++++++++++++----<br>
 src/util/disk_cache.h                |  4 ++--<br>
 3 files changed, 37 insertions(+), 16 deletions(-)<br>
<br>
diff --git a/src/compiler/glsl/tests/<wbr>cache_test.c b/src/compiler/glsl/tests/<wbr>cache_test.c<br>
index 8547141..ba56441 100644<br>
--- a/src/compiler/glsl/tests/<wbr>cache_test.c<br>
+++ b/src/compiler/glsl/tests/<wbr>cache_test.c<br>
@@ -126,7 +126,7 @@ test_disk_cache_create(void)<br>
     * MESA_GLSL_CACHE_DISABLE set, that disk_cache_create returns NULL.<br>
     */<br>
    setenv("MESA_GLSL_CACHE_<wbr>DISABLE", "1", 1);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
    expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set");<br>
<br>
    unsetenv("MESA_GLSL_CACHE_<wbr>DISABLE");<br>
@@ -137,19 +137,19 @@ test_disk_cache_create(void)<br>
    unsetenv("MESA_GLSL_CACHE_DIR"<wbr>);<br>
    unsetenv("XDG_CACHE_HOME");<br>
<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
    expect_non_null(cache, "disk_cache_create with no environment variables");<br>
<br>
    disk_cache_destroy(cache);<br>
<br>
    /* Test with XDG_CACHE_HOME set */<br>
    setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
    expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"<br>
                "a non-existing parent directory");<br>
<br>
    mkdir(CACHE_TEST_TMP, 0755);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
    expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");<br>
<br>
    disk_cache_destroy(cache);<br>
@@ -159,12 +159,12 @@ test_disk_cache_create(void)<br>
    expect_equal(err, 0, "Removing " CACHE_TEST_TMP);<br>
<br>
    setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
    expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"<br>
                "a non-existing parent directory");<br>
<br>
    mkdir(CACHE_TEST_TMP, 0755);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
    expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");<br>
<br>
    disk_cache_destroy(cache);<br>
@@ -203,7 +203,7 @@ test_put_and_get(void)<br>
    uint8_t one_KB_key[20], one_MB_key[20];<br>
    int count;<br>
<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
<br>
    _mesa_sha1_compute(blob, sizeof(blob), blob_key);<br>
<br>
@@ -235,7 +235,7 @@ test_put_and_get(void)<br>
    disk_cache_destroy(cache);<br>
<br>
    setenv("MESA_GLSL_CACHE_MAX_<wbr>SIZE", "1K", 1);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
<br>
    one_KB = calloc(1, 1024);<br>
<br>
@@ -287,7 +287,7 @@ test_put_and_get(void)<br>
    disk_cache_destroy(cache);<br>
<br>
    setenv("MESA_GLSL_CACHE_MAX_<wbr>SIZE", "1M", 1);<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
<br>
    disk_cache_put(cache, blob_key, blob, sizeof(blob));<br>
    disk_cache_put(cache, string_key, string, sizeof(string));<br>
@@ -343,7 +343,7 @@ test_put_key_and_get_key(void)<br>
                         { 0,  1, 42, 43, 44, 45, 46, 47, 48, 49,<br>
                          50, 55, 52, 53, 54, 55, 56, 57, 58, 59};<br>
<br>
-   cache = disk_cache_create();<br>
+   cache = disk_cache_create("test", "make_check");<br>
<br>
    /* First test that disk_cache_has_key returns false before disk_cache_put_key */<br>
    result = disk_cache_has_key(cache, key_a);<br>
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c<br>
index 382ac6c..df511e4 100644<br>
--- a/src/util/disk_cache.c<br>
+++ b/src/util/disk_cache.c<br>
@@ -115,7 +115,7 @@ mkdir_if_needed(char *path)<br>
  *      <path>/<name> cannot be created as a directory<br>
  */<br>
 static char *<br>
-concatenate_and_mkdir(void *ctx, char *path, char *name)<br>
+concatenate_and_mkdir(void *ctx, char *path, const char *name)<br>
 {<br>
    char *new_path;<br>
    struct stat sb;<br>
@@ -131,8 +131,27 @@ concatenate_and_mkdir(void *ctx, char *path, char *name)<br>
       return NULL;<br>
 }<br>
<br>
+static char *<br>
+create_mesa_cache_dir(void *mem_ctx, char *path, const char *mesa_version,<br>
+                      const char *gpu_name)<br>
+{<br>
+   char *new_path = concatenate_and_mkdir(mem_ctx, path, "mesa");<br>
+   if (new_path == NULL)<br>
+      return NULL;<br>
+<br>
+   new_path = concatenate_and_mkdir(mem_ctx, new_path, mesa_version);<br>
+   if (new_path == NULL)<br>
+      return NULL;<br>
+<br>
+   new_path = concatenate_and_mkdir(mem_ctx, new_path, gpu_name);<br>
+   if (new_path == NULL)<br>
+      return NULL;<br>
+<br>
+   return new_path;<br>
+}<br>
+<br>
 struct disk_cache *<br>
-disk_cache_create(void)<br>
+disk_cache_create(const char *gpu_name, const char *mesa_version)<br></blockquote><div><br></div><div>You forgot to update cache_test.c, so make check now fails:<br><br>DIR/src/mesa/src/compiler/glsl/tests/cache_test.c: In function ‘test_put_key_and_get_key’:<br>DIR/src/mesa/src/compiler/glsl/tests/cache_test.c:346:12: error: too few arguments to function ‘disk_cache_create’<br>    cache = disk_cache_create();<br>            ^<br>In file included from DIR/src/mesa/src/compiler/glsl/tests/cache_test.c:36:0:<br>DIR/src/mesa/src/util/disk_cache.h:72:1: note: declared here<br> disk_cache_create(const char *driver_directory, const char *mesa_version);<br> ^<br>Makefile:2362: recipe for target 'glsl/tests/glsl_tests_cache_test-cache_test.o' failed<br><br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 {<br>
    void *local;<br>
    struct disk_cache *cache = NULL;<br>
@@ -180,7 +199,8 @@ disk_cache_create(void)<br>
          if (mkdir_if_needed(xdg_cache_<wbr>home) == -1)<br>
             goto fail;<br>
<br>
-         path = concatenate_and_mkdir(local, xdg_cache_home, "mesa");<br>
+         path = create_mesa_cache_dir(local, xdg_cache_home, mesa_version,<br>
+                                      gpu_name);<br>
          if (path == NULL)<br>
             goto fail;<br>
       }<br>
@@ -216,7 +236,8 @@ disk_cache_create(void)<br>
       if (path == NULL)<br>
          goto fail;<br>
<br>
-      path = concatenate_and_mkdir(local, path, "mesa");<br>
+      path = create_mesa_cache_dir(local, path, mesa_version,<br>
+                                   gpu_name);<br>
       if (path == NULL)<br>
          goto fail;<br>
    }<br>
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h<br>
index 1f2bf3d..e429db5 100644<br>
--- a/src/util/disk_cache.h<br>
+++ b/src/util/disk_cache.h<br>
@@ -69,7 +69,7 @@ struct disk_cache;<br>
  * assistance in computing SHA-1 signatures.<br>
  */<br>
 struct disk_cache *<br>
-disk_cache_create(void);<br>
+disk_cache_create(const char *gpu_name, const char *mesa_version);<br>
<br>
 /**<br>
  * Destroy a cache object, (freeing all associated resources).<br>
@@ -140,7 +140,7 @@ disk_cache_has_key(struct disk_cache *cache, cache_key key);<br>
 #else<br>
<br>
 static inline struct disk_cache *<br>
-disk_cache_create(void)<br>
+disk_cache_create(const char *gpu_name, const char *mesa_version)<br>
 {<br>
    return NULL;<br>
 }<br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
2.9.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>