diff --git a/docs/envvars.rst b/docs/envvars.rst index aab4646f463..cd9e9e11288 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -141,7 +141,9 @@ Core Mesa environment variables features of the given language version if it's higher than what's normally reported. (for developers only) ``MESA_GLSL_CACHE_DISABLE`` - if set to ``true``, disables the GLSL shader cache + if set to ``true``, disables the GLSL shader cache. If set to + ``false``, enables the GLSL shader cache when it is disabled by + default. ``MESA_GLSL_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 diff --git a/meson.build b/meson.build index 59582318f47..4eb6a982424 100644 --- a/meson.build +++ b/meson.build @@ -908,11 +908,14 @@ elif _shader_cache == 'false' endif if _shader_cache != 'disabled' if host_machine.system() == 'windows' - if _shader_cache == 'enabled' + if ['enabled', 'default-disabled'].contains(_shader_cache) error('Shader Cache does not currently work on Windows') endif else pre_args += '-DENABLE_SHADER_CACHE' + if _shader_cache == 'default-disabled' + pre_args += '-DSHADER_CACHE_DISABLE_BY_DEFAULT' + endif with_shader_cache = true endif endif diff --git a/meson_options.txt b/meson_options.txt index 5bbf28f98dc..f35165eb685 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -186,8 +186,8 @@ option( 'shader-cache', type : 'combo', value : 'auto', - choices : ['auto', 'true', 'false', 'enabled', 'disabled'], - description : 'Build with on-disk shader cache support' + choices : ['auto', 'true', 'false', 'enabled', 'disabled', 'default-disabled'], + description : 'Build with on-disk shader cache support. If set to default-disabled, the feature is only activated when environment variable MESA_GLSL_CACHE_DISABLE is set to false' ) option( 'vulkan-icd-dir', diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c index ab36aa49266..76ea8e8b841 100644 --- a/src/compiler/glsl/tests/cache_test.c +++ b/src/compiler/glsl/tests/cache_test.c @@ -193,6 +193,19 @@ test_disk_cache_create(void) unsetenv("MESA_GLSL_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. + */ + unsetenv("MESA_GLSL_CACHE_DISABLE"); + cache = disk_cache_create("test", "make_check", 0); + expect_null(cache, "disk_cache_create with MESA_GLSL_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); +#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. */ @@ -273,6 +286,10 @@ test_put_and_get(void) uint8_t one_KB_key[20], one_MB_key[20]; int count; +#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT + setenv("MESA_GLSL_CACHE_DISABLE", "false", 1); +#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */ + cache = disk_cache_create("test", "make_check", 0); disk_cache_compute_key(cache, blob, sizeof(blob), blob_key); @@ -444,6 +461,10 @@ test_put_key_and_get_key(void) { 0, 1, 42, 43, 44, 45, 46, 47, 48, 49, 50, 55, 52, 53, 54, 55, 56, 57, 58, 59}; +#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT + setenv("MESA_GLSL_CACHE_DISABLE", "false", 1); +#endif /* SHADER_CACHE_DISABLE_BY_DEFAULT */ + cache = disk_cache_create("test", "make_check", 0); /* First test that disk_cache_has_key returns false before disk_cache_put_key */ diff --git a/src/util/disk_cache_os.c b/src/util/disk_cache_os.c index 9de004e99e5..d48fe877c56 100644 --- a/src/util/disk_cache_os.c +++ b/src/util/disk_cache_os.c @@ -873,7 +873,12 @@ disk_cache_enabled() return false; /* At user request, disable shader cache entirely. */ - if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", false)) +#ifdef SHADER_CACHE_DISABLE_BY_DEFAULT + bool disable_by_default = true; +#else + bool disable_by_default = false; +#endif + if (env_var_as_boolean("MESA_GLSL_CACHE_DISABLE", disable_by_default)) return false; return true;