util/disk_cache: add new driver_flags param to cache keys
This will be used for things such as adding driver specific environment variables to the key. Allowing us to set environment vars that change the shader and not have the driver ignore them if it finds existing shaders in the cache. Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
This commit is contained in:
@@ -159,7 +159,7 @@ test_disk_cache_create(void)
|
|||||||
* MESA_GLSL_CACHE_DISABLE set, that disk_cache_create returns NULL.
|
* MESA_GLSL_CACHE_DISABLE set, that disk_cache_create returns NULL.
|
||||||
*/
|
*/
|
||||||
setenv("MESA_GLSL_CACHE_DISABLE", "1", 1);
|
setenv("MESA_GLSL_CACHE_DISABLE", "1", 1);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set");
|
expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set");
|
||||||
|
|
||||||
unsetenv("MESA_GLSL_CACHE_DISABLE");
|
unsetenv("MESA_GLSL_CACHE_DISABLE");
|
||||||
@@ -170,19 +170,19 @@ test_disk_cache_create(void)
|
|||||||
unsetenv("MESA_GLSL_CACHE_DIR");
|
unsetenv("MESA_GLSL_CACHE_DIR");
|
||||||
unsetenv("XDG_CACHE_HOME");
|
unsetenv("XDG_CACHE_HOME");
|
||||||
|
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_non_null(cache, "disk_cache_create with no environment variables");
|
expect_non_null(cache, "disk_cache_create with no environment variables");
|
||||||
|
|
||||||
disk_cache_destroy(cache);
|
disk_cache_destroy(cache);
|
||||||
|
|
||||||
/* Test with XDG_CACHE_HOME set */
|
/* Test with XDG_CACHE_HOME set */
|
||||||
setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
|
setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"
|
expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"
|
||||||
"a non-existing parent directory");
|
"a non-existing parent directory");
|
||||||
|
|
||||||
mkdir(CACHE_TEST_TMP, 0755);
|
mkdir(CACHE_TEST_TMP, 0755);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");
|
expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");
|
||||||
|
|
||||||
check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/mesa");
|
check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/mesa");
|
||||||
@@ -194,12 +194,12 @@ test_disk_cache_create(void)
|
|||||||
expect_equal(err, 0, "Removing " CACHE_TEST_TMP);
|
expect_equal(err, 0, "Removing " CACHE_TEST_TMP);
|
||||||
|
|
||||||
setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
|
setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"
|
expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"
|
||||||
"a non-existing parent directory");
|
"a non-existing parent directory");
|
||||||
|
|
||||||
mkdir(CACHE_TEST_TMP, 0755);
|
mkdir(CACHE_TEST_TMP, 0755);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");
|
expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");
|
||||||
|
|
||||||
check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/mesa");
|
check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/mesa");
|
||||||
@@ -256,7 +256,7 @@ test_put_and_get(void)
|
|||||||
uint8_t one_KB_key[20], one_MB_key[20];
|
uint8_t one_KB_key[20], one_MB_key[20];
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
|
|
||||||
disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
|
disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ test_put_and_get(void)
|
|||||||
disk_cache_destroy(cache);
|
disk_cache_destroy(cache);
|
||||||
|
|
||||||
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
|
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
|
|
||||||
one_KB = calloc(1, 1024);
|
one_KB = calloc(1, 1024);
|
||||||
|
|
||||||
@@ -363,7 +363,7 @@ test_put_and_get(void)
|
|||||||
disk_cache_destroy(cache);
|
disk_cache_destroy(cache);
|
||||||
|
|
||||||
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
|
setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
|
|
||||||
disk_cache_put(cache, blob_key, blob, sizeof(blob));
|
disk_cache_put(cache, blob_key, blob, sizeof(blob));
|
||||||
disk_cache_put(cache, string_key, string, sizeof(string));
|
disk_cache_put(cache, string_key, string, sizeof(string));
|
||||||
@@ -438,7 +438,7 @@ test_put_key_and_get_key(void)
|
|||||||
{ 0, 1, 42, 43, 44, 45, 46, 47, 48, 49,
|
{ 0, 1, 42, 43, 44, 45, 46, 47, 48, 49,
|
||||||
50, 55, 52, 53, 54, 55, 56, 57, 58, 59};
|
50, 55, 52, 53, 54, 55, 56, 57, 58, 59};
|
||||||
|
|
||||||
cache = disk_cache_create("test", "make_check");
|
cache = disk_cache_create("test", "make_check", 0);
|
||||||
|
|
||||||
/* First test that disk_cache_has_key returns false before disk_cache_put_key */
|
/* First test that disk_cache_has_key returns false before disk_cache_put_key */
|
||||||
result = disk_cache_has_key(cache, key_a);
|
result = disk_cache_has_key(cache, key_a);
|
||||||
|
@@ -158,7 +158,7 @@ nouveau_disk_cache_create(struct nouveau_screen *screen)
|
|||||||
if (res != -1) {
|
if (res != -1) {
|
||||||
screen->disk_shader_cache =
|
screen->disk_shader_cache =
|
||||||
disk_cache_create(nouveau_screen_get_name(&screen->base),
|
disk_cache_create(nouveau_screen_get_name(&screen->base),
|
||||||
timestamp_str);
|
timestamp_str, 0);
|
||||||
free(timestamp_str);
|
free(timestamp_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -868,7 +868,7 @@ static void r600_disk_cache_create(struct r600_common_screen *rscreen)
|
|||||||
if (res != -1) {
|
if (res != -1) {
|
||||||
rscreen->disk_shader_cache =
|
rscreen->disk_shader_cache =
|
||||||
disk_cache_create(r600_get_chip_name(rscreen),
|
disk_cache_create(r600_get_chip_name(rscreen),
|
||||||
timestamp_str);
|
timestamp_str, 0);
|
||||||
free(timestamp_str);
|
free(timestamp_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -161,7 +161,8 @@ concatenate_and_mkdir(void *ctx, const char *path, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct disk_cache *
|
struct disk_cache *
|
||||||
disk_cache_create(const char *gpu_name, const char *timestamp)
|
disk_cache_create(const char *gpu_name, const char *timestamp,
|
||||||
|
uint64_t driver_flags)
|
||||||
{
|
{
|
||||||
void *local;
|
void *local;
|
||||||
struct disk_cache *cache = NULL;
|
struct disk_cache *cache = NULL;
|
||||||
@@ -356,6 +357,9 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
|
|||||||
size_t ptr_size_size = sizeof(ptr_size);
|
size_t ptr_size_size = sizeof(ptr_size);
|
||||||
cache->driver_keys_blob_size += ptr_size_size;
|
cache->driver_keys_blob_size += ptr_size_size;
|
||||||
|
|
||||||
|
size_t driver_flags_size = sizeof(driver_flags);
|
||||||
|
cache->driver_keys_blob_size += driver_flags_size;
|
||||||
|
|
||||||
cache->driver_keys_blob =
|
cache->driver_keys_blob =
|
||||||
ralloc_size(cache, cache->driver_keys_blob_size);
|
ralloc_size(cache, cache->driver_keys_blob_size);
|
||||||
if (!cache->driver_keys_blob)
|
if (!cache->driver_keys_blob)
|
||||||
@@ -365,6 +369,8 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
|
|||||||
memcpy(cache->driver_keys_blob + ts_size, gpu_name, gpu_name_size);
|
memcpy(cache->driver_keys_blob + ts_size, gpu_name, gpu_name_size);
|
||||||
memcpy(cache->driver_keys_blob + ts_size + gpu_name_size, &ptr_size,
|
memcpy(cache->driver_keys_blob + ts_size + gpu_name_size, &ptr_size,
|
||||||
ptr_size_size);
|
ptr_size_size);
|
||||||
|
memcpy(cache->driver_keys_blob + ts_size + gpu_name_size + ptr_size_size,
|
||||||
|
&driver_flags, driver_flags_size);
|
||||||
|
|
||||||
/* Seed our rand function */
|
/* Seed our rand function */
|
||||||
s_rand_xorshift128plus(cache->seed_xorshift128plus, true);
|
s_rand_xorshift128plus(cache->seed_xorshift128plus, true);
|
||||||
|
@@ -93,7 +93,8 @@ disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
|
|||||||
* assistance in computing SHA-1 signatures.
|
* assistance in computing SHA-1 signatures.
|
||||||
*/
|
*/
|
||||||
struct disk_cache *
|
struct disk_cache *
|
||||||
disk_cache_create(const char *gpu_name, const char *timestamp);
|
disk_cache_create(const char *gpu_name, const char *timestamp,
|
||||||
|
uint64_t driver_flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a cache object, (freeing all associated resources).
|
* Destroy a cache object, (freeing all associated resources).
|
||||||
@@ -171,7 +172,8 @@ disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
static inline struct disk_cache *
|
static inline struct disk_cache *
|
||||||
disk_cache_create(const char *gpu_name, const char *timestamp)
|
disk_cache_create(const char *gpu_name, const char *timestamp,
|
||||||
|
uint64_t driver_flags)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user