util: Decouple disk cache from EGL_ANDROID_blob_cache

Just because the user / system-integrater doesn't want shader disk
cache, doesn't mean they don't want EGL_ANDROID_blob_cache to work.
We've kind of already solved this for the android case, so just
generalize that solution.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9520
Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24636>
This commit is contained in:
Rob Clark 2023-08-10 14:48:56 -07:00 committed by Marge Bot
parent 5bd0750921
commit 39f26642d6
3 changed files with 10 additions and 21 deletions

View file

@ -106,9 +106,6 @@ disk_cache_type_create(const char *gpu_name,
uint8_t cache_version = CACHE_VERSION;
size_t cv_size = sizeof(cache_version);
if (!disk_cache_enabled())
return NULL;
/* A ralloc context for transient data during this invocation. */
local = ralloc_context(NULL);
if (local == NULL)
@ -122,13 +119,8 @@ disk_cache_type_create(const char *gpu_name,
cache->path_init_failed = true;
cache->type = DISK_CACHE_NONE;
#ifdef ANDROID
/* Android needs the "disk cache" to be enabled for
* EGL_ANDROID_blob_cache's callbacks to be called, but it doesn't actually
* want any storing to disk to happen inside of the driver.
*/
goto path_fail;
#endif
if (!disk_cache_enabled())
goto path_fail;
char *path = disk_cache_generate_cache_dir(local, gpu_name, driver_id,
cache_type);
@ -444,7 +436,7 @@ cache_put(void *job, void *gdata, int thread_index)
disk_cache_write_item_to_disk_foz(dc_job);
} else if (dc_job->cache->type == DISK_CACHE_DATABASE) {
disk_cache_db_write_item_to_disk(dc_job);
} else {
} else if (dc_job->cache->type == DISK_CACHE_MULTI_FILE) {
filename = disk_cache_get_cache_filename(dc_job->cache, dc_job->key);
if (filename == NULL)
goto done;
@ -602,7 +594,7 @@ disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size)
buf = disk_cache_load_item_foz(cache, key, size);
} else if (cache->type == DISK_CACHE_DATABASE) {
buf = disk_cache_db_load_item(cache, key, size);
} else {
} else if (cache->type == DISK_CACHE_MULTI_FILE) {
char *filename = disk_cache_get_cache_filename(cache, key);
if (filename)
buf = disk_cache_load_item(cache, filename, size);

View file

@ -933,6 +933,12 @@ 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 (geteuid() != getuid())
return false;

View file

@ -154,15 +154,6 @@ test_disk_cache_create(void *mem_ctx, const char *cache_dir_name,
struct disk_cache *cache;
int err;
/* Before doing anything else, ensure that with
* MESA_SHADER_CACHE_DISABLE set to true, that disk_cache_create returns NULL.
*/
setenv("MESA_SHADER_CACHE_DISABLE", "true", 1);
cache = disk_cache_create("test", driver_id, 0);
EXPECT_EQ(cache, nullptr) << "disk_cache_create with MESA_SHADER_CACHE_DISABLE set";
unsetenv("MESA_SHADER_CACHE_DISABLE");
#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
/* With SHADER_CACHE_DISABLE_BY_DEFAULT, ensure that with
* MESA_SHADER_CACHE_DISABLE set to nothing, disk_cache_create returns NULL.