From 3ec7615e54f93f159dabff7d18ed6a96eb5db70d Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Mon, 17 Feb 2025 12:40:58 +0100 Subject: [PATCH] util/disk_cache: Allow disk cache on Android if explicitly enabled Disk cache is disabled on Android because by default it is managed by EGL_ANDROID_blob_cache layer. However there are cases or custom Android builds where disk cache is needed, then it can be explicitly enabled via `mesa.shader.cache.disable=false` property and cache path must be set via `mesa.shader.cache.dir`. Signed-off-by: Danylo Piliaiev Part-of: --- src/util/disk_cache.c | 7 ++++--- src/util/disk_cache_os.c | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index f81b65a86a4..147f4136f34 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -46,6 +46,7 @@ #include "util/perf/cpu_trace.h" #include "util/ralloc.h" #include "util/compiler.h" +#include "util/log.h" #include "disk_cache.h" #include "disk_cache_os.h" @@ -325,9 +326,9 @@ void disk_cache_destroy(struct disk_cache *cache) { if (unlikely(cache && cache->stats.enabled)) { - printf("disk shader cache: hits = %u, misses = %u\n", - cache->stats.hits, - cache->stats.misses); + mesa_logi("disk shader cache: hits = %u, misses = %u\n", + cache->stats.hits, + cache->stats.misses); } if (cache && util_queue_is_initialized(&cache->cache_queue)) { diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index c2a90bd9fcc..5310e342e02 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -1005,23 +1005,25 @@ disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name, bool disk_cache_enabled() { - /* Disk cache is not enabled for android, but android's EGL layer - * uses EGL_ANDROID_blob_cache to manage the cache itself: - */ - if (DETECT_OS_ANDROID) - return false; - /* If running as a users other than the real user disable cache */ if (!__normal_user()) return false; - /* At user request, disable shader cache entirely. */ -#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT + /* At user request, disable shader cache entirely. + * Disk cache is not enabled by default for android, for most + * applications the EGL layer uses EGL_ANDROID_blob_cache to manage + * the cache itself, however those that wish to use the cache directly + * can set `mesa.shader.cache.disable=false` property. + * Don't forget to also set the shader cache path to something readable + * and writable by the application via `mesa.shader.cache.dir`. + */ +#if defined(SHADER_CACHE_DISABLE_BY_DEFAULT) || DETECT_OS_ANDROID bool disable_by_default = true; #else bool disable_by_default = false; #endif char *envvar_name = "MESA_SHADER_CACHE_DISABLE"; +#if !DETECT_OS_ANDROID if (!getenv(envvar_name)) { envvar_name = "MESA_GLSL_CACHE_DISABLE"; if (getenv(envvar_name)) @@ -1029,6 +1031,7 @@ disk_cache_enabled() "*** MESA_GLSL_CACHE_DISABLE is deprecated; " "use MESA_SHADER_CACHE_DISABLE instead ***\n"); } +#endif if (debug_get_bool_option(envvar_name, disable_by_default) || /* MESA_GLSL_DISABLE_IO_OPT must disable the cache to get expected