util/disk_cache: rename MESA_GLSL_CACHE envvar

Rename MESA_GLSL_CACHE to MESA_SHADER_CACHE, as the on-disk cache can
store not only GLSL but also SPIR-V shaders.

v2:
 - Keep old envvar as deprecated (Mike)

Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15390>
This commit is contained in:
Juan A. Suarez Romero 2022-03-14 18:47:37 +01:00
parent 6d7f04e5de
commit 54d0a2cfad
6 changed files with 63 additions and 37 deletions

View File

@ -136,13 +136,13 @@ Core Mesa environment variables
integers, such as ``130``. Mesa will not really implement all the
features of the given language version if it's higher than what's
normally reported. (for developers only)
:envvar:`MESA_GLSL_CACHE_DISABLE`
if set to ``true``, disables the GLSL shader cache. If set to
``false``, enables the GLSL shader cache when it is disabled by
:envvar:`MESA_SHADER_CACHE_DISABLE`
if set to ``true``, disables the on-disk shader cache. If set to
``false``, enables the on-disk shader cache when it is disabled by
default.
:envvar:`MESA_GLSL_CACHE_MAX_SIZE`
:envvar:`MESA_SHADER_CACHE_MAX_SIZE`
if set, determines the maximum size of the on-disk cache of compiled
GLSL programs. Should be set to a number optionally followed by
shader programs. Should be set to a number optionally followed by
``K``, ``M``, or ``G`` to specify a size in kilobytes, megabytes, or
gigabytes. By default, gigabytes will be assumed. And if unset, a
maximum size of 1GB will be used.
@ -154,9 +154,9 @@ Core Mesa environment variables
you may end up with a 1GB cache for x86_64 and another 1GB cache for
i386.
:envvar:`MESA_GLSL_CACHE_DIR`
:envvar:`MESA_SHADER_CACHE_DIR`
if set, determines the directory to be used for the on-disk cache of
compiled GLSL programs. If this variable is not set, then the cache
compiled shader programs. If this variable is not set, then the cache
will be stored in ``$XDG_CACHE_HOME/mesa_shader_cache`` (if that
variable is set), or else within ``.cache/mesa_shader_cache`` within
the user's home directory.

View File

@ -1045,7 +1045,7 @@ endif
if with_shader_cache
shader_cache_max_size = get_option('shader-cache-max-size')
if shader_cache_max_size != ''
pre_args += '-DMESA_GLSL_CACHE_MAX_SIZE="@0@"'.format(shader_cache_max_size)
pre_args += '-DMESA_SHADER_CACHE_MAX_SIZE="@0@"'.format(shader_cache_max_size)
endif
endif

View File

@ -212,15 +212,15 @@ option(
'shader-cache-default',
type : 'boolean',
value : true,
description : 'If set to false, the feature is only activated when environment variable MESA_GLSL_CACHE_DISABLE is set to false',
description : 'If set to false, the feature is only activated when environment variable MESA_SHADER_CACHE_DISABLE is set to false',
)
option(
'shader-cache-max-size',
type : 'string',
value : '',
description : '''Default value for MESA_GLSL_CACHE_MAX_SIZE enviroment variable.
description : '''Default value for MESA_SHADER_CACHE_MAX_SIZE enviroment variable.
If set, determines the maximum size of the on-disk cache of compiled
GLSL programs, can be overriden by enviroment variable if needed. Should be set to a number optionally followed by
shader programs, can be overriden by enviroment variable if needed. Should be set to a number optionally followed by
``K``, ``M``, or ``G`` to specify a size in kilobytes, megabytes, or
gigabytes. By default, gigabytes will be assumed. And if unset, a
maximum size of 1GB will be used.'''

View File

@ -121,11 +121,19 @@ disk_cache_create(const char *gpu_name, const char *driver_id,
max_size = 0;
max_size_str = getenv("MESA_GLSL_CACHE_MAX_SIZE");
#ifdef MESA_GLSL_CACHE_MAX_SIZE
max_size_str = getenv("MESA_SHADER_CACHE_MAX_SIZE");
if (!max_size_str) {
max_size_str = getenv("MESA_GLSL_CACHE_MAX_SIZE");
if (max_size_str)
fprintf(stderr,
"*** MESA_GLSL_CACHE_MAX_SIZE is deprecated; "
"use MESA_SHADER_CACHE_MAX_SIZE instead ***\n");
}
#ifdef MESA_SHADER_CACHE_MAX_SIZE
if( !max_size_str ) {
max_size_str = MESA_GLSL_CACHE_MAX_SIZE;
max_size_str = MESA_SHADER_CACHE_MAX_SIZE;
}
#endif

View File

@ -766,7 +766,7 @@ disk_cache_write_item_to_disk(struct disk_cache_put_job *dc_job,
/* Determine path for cache based on the first defined name as follows:
*
* $MESA_GLSL_CACHE_DIR
* $MESA_SHADER_CACHE_DIR
* $XDG_CACHE_HOME/mesa_shader_cache
* <pwd.pw_dir>/.cache/mesa_shader_cache
*/
@ -778,7 +778,16 @@ disk_cache_generate_cache_dir(void *mem_ctx, const char *gpu_name,
if (env_var_as_boolean("MESA_DISK_CACHE_SINGLE_FILE", false))
cache_dir_name = CACHE_DIR_NAME_SF;
char *path = getenv("MESA_GLSL_CACHE_DIR");
char *path = getenv("MESA_SHADER_CACHE_DIR");
if (!path) {
path = getenv("MESA_GLSL_CACHE_DIR");
if (path)
fprintf(stderr,
"*** MESA_GLSL_CACHE_DIR is deprecated; "
"use MESA_SHADER_CACHE_DIR instead ***\n");
}
if (path) {
if (mkdir_if_needed(path) == -1)
return NULL;
@ -862,7 +871,16 @@ disk_cache_enabled()
#else
bool disable_by_default = false;
#endif
if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", disable_by_default))
char *envvar_name = "MESA_SHADER_CACHE_DISABLE";
if (!getenv(envvar_name)) {
envvar_name = "MESA_GLSL_CACHE_DISABLE";
if (getenv(envvar_name))
fprintf(stderr,
"*** MESA_GLSL_CACHE_DISABLE is deprecated; "
"use MESA_SHADER_CACHE_DISABLE instead ***\n");
}
if (env_var_as_boolean(envvar_name, disable_by_default))
return false;
return true;

View File

@ -134,32 +134,32 @@ test_disk_cache_create(void *mem_ctx, const char *cache_dir_name)
int err;
/* Before doing anything else, ensure that with
* MESA_GLSL_CACHE_DISABLE set to true, that disk_cache_create returns NULL.
* MESA_SHADER_CACHE_DISABLE set to true, that disk_cache_create returns NULL.
*/
setenv("MESA_GLSL_CACHE_DISABLE", "true", 1);
setenv("MESA_SHADER_CACHE_DISABLE", "true", 1);
cache = disk_cache_create("test", "make_check", 0);
EXPECT_EQ(cache, nullptr) << "disk_cache_create with MESA_GLSL_CACHE_DISABLE set";
EXPECT_EQ(cache, nullptr) << "disk_cache_create with MESA_SHADER_CACHE_DISABLE set";
unsetenv("MESA_GLSL_CACHE_DISABLE");
unsetenv("MESA_SHADER_CACHE_DISABLE");
#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
/* With SHADER_CACHE_DISABLE_BY_DEFAULT, ensure that with
* MESA_GLSL_CACHE_DISABLE set to nothing, disk_cache_create returns NULL.
* MESA_SHADER_CACHE_DISABLE set to nothing, disk_cache_create returns NULL.
*/
unsetenv("MESA_GLSL_CACHE_DISABLE");
unsetenv("MESA_SHADER_CACHE_DISABLE");
cache = disk_cache_create("test", "make_check", 0);
EXPECT_EQ(cache, nullptr)
<< "disk_cache_create with MESA_GLSL_CACHE_DISABLE unset "
<< "disk_cache_create with MESA_SHADER_CACHE_DISABLE unset "
"and SHADER_CACHE_DISABLE_BY_DEFAULT build option";
/* For remaining tests, ensure that the cache is enabled. */
setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
setenv("MESA_SHADER_CACHE_DISABLE", "false", 1);
#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
/* For the first real disk_cache_create() clear these environment
* variables to test creation of cache in home directory.
*/
unsetenv("MESA_GLSL_CACHE_DIR");
unsetenv("MESA_SHADER_CACHE_DIR");
unsetenv("XDG_CACHE_HOME");
cache = disk_cache_create("test", "make_check", 0);
@ -197,14 +197,14 @@ test_disk_cache_create(void *mem_ctx, const char *cache_dir_name)
disk_cache_destroy(cache);
/* Test with MESA_GLSL_CACHE_DIR set */
/* Test with MESA_SHADER_CACHE_DIR set */
err = rmrf_local(CACHE_TEST_TMP);
EXPECT_EQ(err, 0) << "Removing " CACHE_TEST_TMP;
setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
setenv("MESA_SHADER_CACHE_DIR", CACHE_TEST_TMP "/mesa-shader-cache-dir", 1);
cache = disk_cache_create("test", "make_check", 0);
EXPECT_FALSE(cache_exists(cache))
<< "disk_cache_create with MESA_GLSL_CACHE_DIR set with a non-existing parent directory";
<< "disk_cache_create with MESA_SHADER_CACHE_DIR set with a non-existing parent directory";
err = mkdir(CACHE_TEST_TMP, 0755);
if (err != 0) {
@ -214,10 +214,10 @@ test_disk_cache_create(void *mem_ctx, const char *cache_dir_name)
disk_cache_destroy(cache);
cache = disk_cache_create("test", "make_check", 0);
EXPECT_TRUE(cache_exists(cache)) << "disk_cache_create with MESA_GLSL_CACHE_DIR set";
EXPECT_TRUE(cache_exists(cache)) << "disk_cache_create with MESA_SHADER_CACHE_DIR set";
path = ralloc_asprintf(
mem_ctx, "%s%s", CACHE_TEST_TMP "/mesa-glsl-cache-dir/", cache_dir_name);
mem_ctx, "%s%s", CACHE_TEST_TMP "/mesa-shader-cache-dir/", cache_dir_name);
check_directories_created(mem_ctx, path);
disk_cache_destroy(cache);
@ -238,7 +238,7 @@ test_put_and_get(bool test_cache_size_limit)
int count;
#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
setenv("MESA_SHADER_CACHE_DISABLE", "false", 1);
#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
cache = disk_cache_create("test", "make_check", 0);
@ -281,7 +281,7 @@ test_put_and_get(bool test_cache_size_limit)
if (!test_cache_size_limit)
return;
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
setenv("MESA_SHADER_CACHE_MAX_SIZE", "1K", 1);
cache = disk_cache_create("test", "make_check", 0);
one_KB = (uint8_t *) calloc(1, 1024);
@ -344,7 +344,7 @@ test_put_and_get(bool test_cache_size_limit)
*/
disk_cache_destroy(cache);
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
setenv("MESA_SHADER_CACHE_MAX_SIZE", "1M", 1);
cache = disk_cache_create("test", "make_check", 0);
disk_cache_put(cache, blob_key, blob, sizeof(blob), NULL);
@ -416,7 +416,7 @@ test_put_key_and_get_key(void)
50, 55, 52, 53, 54, 55, 56, 57, 58, 59};
#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
setenv("MESA_SHADER_CACHE_DISABLE", "false", 1);
#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
cache = disk_cache_create("test", "make_check", 0);
@ -472,7 +472,7 @@ test_put_and_get_between_instances()
size_t size;
#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT
setenv("MESA_GLSL_CACHE_DISABLE", "false", 1);
setenv("MESA_SHADER_CACHE_DISABLE", "false", 1);
#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */
struct disk_cache *cache1 = disk_cache_create("test_between_instances",