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>
This commit is contained in:
committed by
Marge Bot
parent
eca6bb9540
commit
644fcd9486
+33
-16
@@ -103,7 +103,7 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
|
||||
goto path_fail;
|
||||
#endif
|
||||
|
||||
char *path = disk_cache_generate_cache_dir(local);
|
||||
char *path = disk_cache_generate_cache_dir(local, gpu_name, driver_id);
|
||||
if (!path)
|
||||
goto path_fail;
|
||||
|
||||
@@ -111,6 +111,11 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
|
||||
if (cache->path == NULL)
|
||||
goto path_fail;
|
||||
|
||||
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false)) {
|
||||
if (!disk_cache_load_cache_index(local, cache, path))
|
||||
goto path_fail;
|
||||
}
|
||||
|
||||
if (!disk_cache_mmap_cache_index(local, cache, path))
|
||||
goto path_fail;
|
||||
|
||||
@@ -227,6 +232,10 @@ disk_cache_destroy(struct disk_cache *cache)
|
||||
if (cache && !cache->path_init_failed) {
|
||||
util_queue_finish(&cache->cache_queue);
|
||||
util_queue_destroy(&cache->cache_queue);
|
||||
|
||||
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false))
|
||||
foz_destroy(&cache->foz_db);
|
||||
|
||||
disk_cache_destroy_mmap(cache);
|
||||
}
|
||||
|
||||
@@ -315,21 +324,25 @@ cache_put(void *job, int thread_index)
|
||||
char *filename = NULL;
|
||||
struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
|
||||
|
||||
filename = disk_cache_get_cache_filename(dc_job->cache, dc_job->key);
|
||||
if (filename == NULL)
|
||||
goto done;
|
||||
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false)) {
|
||||
disk_cache_write_item_to_disk_foz(dc_job);
|
||||
} else {
|
||||
filename = disk_cache_get_cache_filename(dc_job->cache, dc_job->key);
|
||||
if (filename == NULL)
|
||||
goto done;
|
||||
|
||||
/* If the cache is too large, evict something else first. */
|
||||
while (*dc_job->cache->size + dc_job->size > dc_job->cache->max_size &&
|
||||
i < 8) {
|
||||
disk_cache_evict_lru_item(dc_job->cache);
|
||||
i++;
|
||||
}
|
||||
/* If the cache is too large, evict something else first. */
|
||||
while (*dc_job->cache->size + dc_job->size > dc_job->cache->max_size &&
|
||||
i < 8) {
|
||||
disk_cache_evict_lru_item(dc_job->cache);
|
||||
i++;
|
||||
}
|
||||
|
||||
disk_cache_write_item_to_disk(dc_job, filename);
|
||||
disk_cache_write_item_to_disk(dc_job, filename);
|
||||
|
||||
done:
|
||||
free(filename);
|
||||
free(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -383,11 +396,15 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
|
||||
return blob;
|
||||
}
|
||||
|
||||
char *filename = disk_cache_get_cache_filename(cache, key);
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false)) {
|
||||
return disk_cache_load_item_foz(cache, key, size);
|
||||
} else {
|
||||
char *filename = disk_cache_get_cache_filename(cache, key);
|
||||
if (filename == NULL)
|
||||
return NULL;
|
||||
|
||||
return disk_cache_load_item(cache, filename, size);
|
||||
return disk_cache_load_item(cache, filename, size);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user