From 6d37f61a4dcc786ebee7a01af9021fddf71383fe Mon Sep 17 00:00:00 2001 From: Harshal Joshi Date: Tue, 14 Jul 2026 12:27:46 +0530 Subject: [PATCH] Fix shader cache invalidation caused by struct padding memcmp(Fixes #4645) (#4704) * Fix shader cache invalidation caused by struct padding memcmp * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Harshalj2108 Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/shader_recompiler/profile.h | 2 ++ .../renderer_vulkan/vk_pipeline_serialization.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/shader_recompiler/profile.h b/src/shader_recompiler/profile.h index 7ce262f98..22b45a1ee 100644 --- a/src/shader_recompiler/profile.h +++ b/src/shader_recompiler/profile.h @@ -52,6 +52,8 @@ struct Profile { bool needs_unorm_fixup{}; bool needs_clip_distance_emulation{}; bool supports_shader_stencil_export{}; + + bool operator==(const Profile&) const = default; }; } // namespace Shader diff --git a/src/video_core/renderer_vulkan/vk_pipeline_serialization.cpp b/src/video_core/renderer_vulkan/vk_pipeline_serialization.cpp index 2ac920d9b..d16d7a557 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_serialization.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_serialization.cpp @@ -313,7 +313,17 @@ void PipelineCache::WarmUp() { std::move(profile_data)); return; } - if (std::memcmp(profile_data.data(), &profile, sizeof(profile)) != 0) { + if (profile_data.size() != sizeof(Shader::Profile)) { + LOG_WARNING(Render, + "Pipeline cache profile has unexpected size ({} != {}). Ignoring the cache", + profile_data.size(), sizeof(Shader::Profile)); + Storage::DataBase::Instance().Close(); + return; + } + + Shader::Profile cached_profile{}; + std::memcpy(&cached_profile, profile_data.data(), sizeof(cached_profile)); + if (cached_profile != profile) { LOG_WARNING(Render, "Pipeline cache isn't compatible with current system. Ignoring the cache"); Storage::DataBase::Instance().Close();