[Shader Cache] Include engine version and architecture when calculating hash.

This commit is contained in:
bruvzg 2024-08-05 10:43:43 +03:00
parent 3978628c6c
commit d5ac8bc6fe
3 changed files with 25 additions and 9 deletions

View File

@ -30,6 +30,9 @@
#include "egl_manager.h" #include "egl_manager.h"
#include "core/string/string_builder.h"
#include "core/version.h"
#ifdef EGL_ENABLED #ifdef EGL_ENABLED
#if defined(EGL_STATIC) #if defined(EGL_STATIC)
@ -411,15 +414,24 @@ Error EGLManager::initialize(void *p_native_display) {
ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir); ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
shader_cache_dir = String(); shader_cache_dir = String();
} else { } else {
err = da->change_dir(String("shader_cache").path_join("EGL")); StringBuilder tohash;
tohash.append("[GodotVersionNumber]");
tohash.append(VERSION_NUMBER);
tohash.append("[GodotVersionHash]");
tohash.append(VERSION_HASH);
tohash.append("[GodotArchitecture]");
tohash.append(Engine::get_singleton()->get_architecture_name());
String base_sha256 = tohash.as_string().sha256_text();
err = da->change_dir(String("shader_cache").path_join("EGL").path_join(base_sha256));
if (err != OK) { if (err != OK) {
err = da->make_dir_recursive(String("shader_cache").path_join("EGL")); err = da->make_dir_recursive(String("shader_cache").path_join("EGL").path_join(base_sha256));
} }
if (err != OK) { if (err != OK) {
ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir); ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir);
shader_cache_dir = String(); shader_cache_dir = String();
} else { } else {
shader_cache_dir = shader_cache_dir.path_join(String("shader_cache").path_join("EGL")); shader_cache_dir = shader_cache_dir.path_join(String("shader_cache").path_join("EGL").path_join(base_sha256));
} }
} }
#endif #endif

View File

@ -35,6 +35,7 @@
#include "core/io/compression.h" #include "core/io/compression.h"
#include "core/io/dir_access.h" #include "core/io/dir_access.h"
#include "core/io/file_access.h" #include "core/io/file_access.h"
#include "core/version.h"
#include "drivers/gles3/rasterizer_gles3.h" #include "drivers/gles3/rasterizer_gles3.h"
#include "drivers/gles3/storage/config.h" #include "drivers/gles3/storage/config.h"
@ -130,12 +131,13 @@ void ShaderGLES3::_setup(const char *p_vertex_code, const char *p_fragment_code,
feedback_count = p_feedback_count; feedback_count = p_feedback_count;
StringBuilder tohash; StringBuilder tohash;
/* tohash.append("[GodotVersionNumber]");
tohash.append("[SpirvCacheKey]"); tohash.append(VERSION_NUMBER);
tohash.append(RenderingDevice::get_singleton()->shader_get_spirv_cache_key()); tohash.append("[GodotVersionHash]");
tohash.append("[BinaryCacheKey]"); tohash.append(VERSION_HASH);
tohash.append(RenderingDevice::get_singleton()->shader_get_binary_cache_key()); tohash.append("[GodotArchitecture]");
*/ tohash.append(Engine::get_singleton()->get_architecture_name());
tohash.append("[Vertex]"); tohash.append("[Vertex]");
tohash.append(p_vertex_code ? p_vertex_code : ""); tohash.append(p_vertex_code ? p_vertex_code : "");
tohash.append("[Fragment]"); tohash.append("[Fragment]");

View File

@ -122,6 +122,8 @@ void ShaderRD::setup(const char *p_vertex_code, const char *p_fragment_code, con
tohash.append(VERSION_NUMBER); tohash.append(VERSION_NUMBER);
tohash.append("[GodotVersionHash]"); tohash.append("[GodotVersionHash]");
tohash.append(VERSION_HASH); tohash.append(VERSION_HASH);
tohash.append("[GodotArchitecture]");
tohash.append(Engine::get_singleton()->get_architecture_name());
tohash.append("[SpirvCacheKey]"); tohash.append("[SpirvCacheKey]");
tohash.append(RenderingDevice::get_singleton()->shader_get_spirv_cache_key()); tohash.append(RenderingDevice::get_singleton()->shader_get_spirv_cache_key());
tohash.append("[BinaryCacheKey]"); tohash.append("[BinaryCacheKey]");