summaryrefslogtreecommitdiff
path: root/src/util/disk_cache_os.c
diff options
context:
space:
mode:
authorTimothy Arceri <tarceri@itsqueeze.com>2020-10-01 20:02:59 +1000
committerMarge Bot <eric+marge@anholt.net>2021-02-21 02:50:45 +0000
commit644fcd94864260218037d0b9a0dfd3b00be073d8 (patch)
tree65d49795db39f829fa56ae23632b984d714aeaf0 /src/util/disk_cache_os.c
parenteca6bb9540d8d1b260511cd0a71bdddb00ff4a3c (diff)
util/disk_cache: make use of single file cache when env var set
When the MESA_DISK_CACHE_SINGLE_FILE environment variable is set we make use of the new single file shader cache implementation. The new cache uses the following directory structure based on the first defined name as follows: $MESA_GLSL_CACHE_DIR/driver_id/gpu_name/foz_cache.foz $MESA_GLSL_CACHE_DIR/driver_id/gpu_name/foz_cache_idx.foz $XDG_CACHE_HOME/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache.foz $XDG_CACHE_HOME/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache_idx.foz <pwd.pw_dir>/.cache/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache.foz <pwd.pw_dir>/.cache/mesa_shader_cache_sf/driver_id/gpu_name/foz_cache_idx.foz Where foz_cache_idx.foz is a database of offsets pointing to the location of the shader cache entries in foz_cache.foz This initial implementation doesn't have any max cache size handling and is initially intended to be use by applications such as steam that will handle cache management for us. Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7725>
Diffstat (limited to 'src/util/disk_cache_os.c')
-rw-r--r--src/util/disk_cache_os.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c
index 9e59644d2bb..865ff7bf3dd 100644
--- a/src/util/disk_cache_os.c
+++ b/src/util/disk_cache_os.c
@@ -841,7 +841,8 @@ disk_cache_write_item_to_disk(struct disk_cache_put_job *dc_job,
* <pwd.pw_dir>/.cache/mesa_shader_cache
*/
char *
-disk_cache_generate_cache_dir(void *mem_ctx)
+disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name,
+ const char *driver_id)
{
char *cache_dir_name = CACHE_DIR_NAME;
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false))
@@ -905,6 +906,16 @@ disk_cache_generate_cache_dir(void *mem_ctx)
return NULL;
}
+ if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false)) {
+ path = concatenate_and_mkdir(mem_ctx, path, driver_id);
+ if (!path)
+ return NULL;
+
+ path = concatenate_and_mkdir(mem_ctx, path, gpu_name);
+ if (!path)
+ return NULL;
+ }
+
return path;
}
@@ -927,6 +938,32 @@ disk_cache_enabled()
return true;
}
+void *
+disk_cache_load_item_foz(struct disk_cache *cache, const cache_key key,
+ size_t *size)
+{
+ return foz_read_entry(&cache->foz_db, key, size);
+}
+
+bool
+disk_cache_write_item_to_disk_foz(struct disk_cache_put_job *dc_job)
+{
+ return foz_write_entry(&dc_job->cache->foz_db, dc_job->key, dc_job->data,
+ dc_job->size);
+}
+
+bool
+disk_cache_load_cache_index(void *mem_ctx, struct disk_cache *cache,
+ char *path)
+{
+ path = ralloc_asprintf(mem_ctx, "%s/foz_cache", cache->path);
+ if (path == NULL)
+ return false;
+
+ /* Load cache index into a hash map (from fossilise files) */
+ return foz_prepare(&cache->foz_db, path);
+}
+
bool
disk_cache_mmap_cache_index(void *mem_ctx, struct disk_cache *cache,
char *path)