From d5ac8bc6fe91bc24584ecf9137fe254ec888aeff Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 5 Aug 2024 10:43:43 +0300 Subject: [PATCH] [Shader Cache] Include engine version and architecture when calculating hash. --- drivers/egl/egl_manager.cpp | 18 +++++++++++++++--- drivers/gles3/shader_gles3.cpp | 14 ++++++++------ servers/rendering/renderer_rd/shader_rd.cpp | 2 ++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/egl/egl_manager.cpp b/drivers/egl/egl_manager.cpp index 9c1d08331d2..9e2a492d06d 100644 --- a/drivers/egl/egl_manager.cpp +++ b/drivers/egl/egl_manager.cpp @@ -30,6 +30,9 @@ #include "egl_manager.h" +#include "core/string/string_builder.h" +#include "core/version.h" + #ifdef EGL_ENABLED #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); shader_cache_dir = String(); } 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) { - 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) { ERR_PRINT("EGL: Can't create shader cache folder, no shader caching will happen: " + shader_cache_dir); shader_cache_dir = String(); } 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 diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index 4a15ed827a0..ea035350658 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -35,6 +35,7 @@ #include "core/io/compression.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" +#include "core/version.h" #include "drivers/gles3/rasterizer_gles3.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; StringBuilder tohash; - /* - tohash.append("[SpirvCacheKey]"); - tohash.append(RenderingDevice::get_singleton()->shader_get_spirv_cache_key()); - tohash.append("[BinaryCacheKey]"); - tohash.append(RenderingDevice::get_singleton()->shader_get_binary_cache_key()); - */ + 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()); + tohash.append("[Vertex]"); tohash.append(p_vertex_code ? p_vertex_code : ""); tohash.append("[Fragment]"); diff --git a/servers/rendering/renderer_rd/shader_rd.cpp b/servers/rendering/renderer_rd/shader_rd.cpp index 1c1b8366e5f..f929c497fcb 100644 --- a/servers/rendering/renderer_rd/shader_rd.cpp +++ b/servers/rendering/renderer_rd/shader_rd.cpp @@ -122,6 +122,8 @@ void ShaderRD::setup(const char *p_vertex_code, const char *p_fragment_code, con tohash.append(VERSION_NUMBER); tohash.append("[GodotVersionHash]"); tohash.append(VERSION_HASH); + tohash.append("[GodotArchitecture]"); + tohash.append(Engine::get_singleton()->get_architecture_name()); tohash.append("[SpirvCacheKey]"); tohash.append(RenderingDevice::get_singleton()->shader_get_spirv_cache_key()); tohash.append("[BinaryCacheKey]");