[Mesa-dev] [PATCH V2] util/disk_cache: support caches for multiple architectures

Timothy Arceri tarceri at itsqueeze.com
Fri Mar 3 03:27:31 UTC 2017


Previously we were deleting the entire cache if a user switched
between 32 and 64 bit applications.

V2: make the check more generic, it should now work with any
platform we are likely to support.
---
 src/util/disk_cache.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 3abdec4..92528a9 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -40,20 +40,30 @@
 #include "zlib.h"
 
 #include "util/crc32.h"
 #include "util/u_atomic.h"
 #include "util/mesa-sha1.h"
 #include "util/ralloc.h"
 #include "main/errors.h"
 
 #include "disk_cache.h"
 
+#if defined(__ILP32__)
+#if defined(__x86_64__) || defined(__arm__)
+#define CACHE_ARCH "ilp-32"
+#else
+#define CACHE_ARCH "32"
+#endif
+#else
+#define CACHE_ARCH "64"
+#endif
+
 /* Number of bits to mask off from a cache key to get an index. */
 #define CACHE_INDEX_KEY_BITS 16
 
 /* Mask for computing an index from a key. */
 #define CACHE_INDEX_KEY_MASK ((1 << CACHE_INDEX_KEY_BITS) - 1)
 
 /* The number of keys that can be stored in the index. */
 #define CACHE_INDEX_MAX_KEYS (1 << CACHE_INDEX_KEY_BITS)
 
 struct disk_cache {
@@ -170,20 +180,29 @@ remove_old_cache_directories(void *mem_ctx, char *path, const char *timestamp)
 }
 
 static char *
 create_mesa_cache_dir(void *mem_ctx, char *path, const char *timestamp,
                       const char *gpu_name)
 {
    char *new_path = concatenate_and_mkdir(mem_ctx, path, "mesa");
    if (new_path == NULL)
       return NULL;
 
+   /* Create a parent architecture directory so that we don't remove cache
+    * files for other architectures. In theory we could share the cache
+    * between architectures but we have no way of knowing if they were created
+    * by a compatible Mesa version.
+    */
+   new_path = concatenate_and_mkdir(mem_ctx, new_path, CACHE_ARCH);
+   if (new_path == NULL)
+      return NULL;
+
    /* Remove cache directories for old Mesa versions */
    remove_old_cache_directories(mem_ctx, new_path, timestamp);
 
    new_path = concatenate_and_mkdir(mem_ctx, new_path, timestamp);
    if (new_path == NULL)
       return NULL;
 
    new_path = concatenate_and_mkdir(mem_ctx, new_path, gpu_name);
    if (new_path == NULL)
       return NULL;
-- 
2.9.3



More information about the mesa-dev mailing list