forked from enlightenment/efl
Evas: Discard shaders cache when the code changed
Since we now have only two shader strings, this is trivial to do: hash the strings and add them to the cache filename. This will allow people using 1.17.0-alpha, etc... to discard their old shaders cache automagically and use the latest version of the shaders (because alpha is not in the filename). If we end up adding more runtime generated shaders, we might need a better strategy, but this should be good enough for now.
This commit is contained in:
parent
3fc6e48c8a
commit
ebc3b88d09
|
@ -191,6 +191,7 @@ struct _Evas_GL_Shared
|
|||
|
||||
Eet_File *shaders_cache;
|
||||
Eina_Hash *shaders_hash;
|
||||
Eina_Stringshare *shaders_cache_name;
|
||||
|
||||
#ifdef GL_GLES
|
||||
// FIXME: hack.
|
||||
|
|
|
@ -1041,6 +1041,7 @@ evas_gl_common_context_free(Evas_Engine_GL_Context *gc)
|
|||
eina_hash_free(gc->shared->native_wl_hash);
|
||||
eina_hash_free(gc->shared->native_tbm_hash);
|
||||
eina_hash_free(gc->shared->native_evasgl_hash);
|
||||
eina_stringshare_del(gc->shared->shaders_cache_name);
|
||||
free(gc->shared);
|
||||
shared = NULL;
|
||||
}
|
||||
|
|
|
@ -204,6 +204,20 @@ _evas_gl_common_shader_program_binary_save(Evas_GL_Program *p, Eet_File *ef)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
_evas_gl_common_shader_binary_hash(Evas_GL_Shared *shared)
|
||||
{
|
||||
if (shared->shaders_cache_name)
|
||||
return;
|
||||
|
||||
/* This hash makes it sure that if the shaders code changes, then we
|
||||
* will not reuse the old binaries. */
|
||||
shared->shaders_cache_name = eina_stringshare_printf
|
||||
("%#x:%#x::binary_shader",
|
||||
eina_hash_superfast(fragment_glsl, strlen(fragment_glsl)),
|
||||
eina_hash_superfast(vertex_glsl, strlen(vertex_glsl)));
|
||||
}
|
||||
|
||||
static int
|
||||
_evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
|
||||
{
|
||||
|
@ -220,8 +234,9 @@ _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
|
|||
if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path)))
|
||||
return 0;
|
||||
|
||||
if (!evas_gl_common_file_cache_file_check(bin_dir_path, "binary_shader", bin_file_path,
|
||||
sizeof(bin_dir_path)))
|
||||
_evas_gl_common_shader_binary_hash(shared);
|
||||
if (!evas_gl_common_file_cache_file_check(bin_dir_path, shared->shaders_cache_name,
|
||||
bin_file_path, sizeof(bin_dir_path)))
|
||||
return 0;
|
||||
|
||||
if (!eet_init()) return 0;
|
||||
|
@ -259,8 +274,9 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
|
|||
return 0; /* we can't make directory */
|
||||
}
|
||||
|
||||
copy = evas_gl_common_file_cache_file_check(bin_dir_path, "binary_shader", bin_file_path,
|
||||
sizeof(bin_dir_path));
|
||||
_evas_gl_common_shader_binary_hash(shared);
|
||||
copy = evas_gl_common_file_cache_file_check(bin_dir_path, shared->shaders_cache_name,
|
||||
bin_file_path, sizeof(bin_dir_path));
|
||||
|
||||
/* use mkstemp for writing */
|
||||
snprintf(tmp_file_name, sizeof(tmp_file_name), "%s.XXXXXX.cache", bin_file_path);
|
||||
|
|
Loading…
Reference in New Issue