From 36ea2f7a263ac64f60d9caabc56d7cd319a29fea Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 28 Mar 2018 01:45:59 +1000 Subject: [PATCH 1/2] ShaderCache: Fix issue where shader cache wasn't recreated when invalid --- Source/Core/VideoCommon/ShaderCache.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index cc2ca81b7c..12166d2d4c 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -552,6 +552,7 @@ void ShaderCache::LoadPipelineUIDCache() // If an existing case exists, validate the version before reading entries. u32 existing_magic; u32 existing_version; + bool uid_file_valid = false; if (m_gx_pipeline_uid_cache_file.ReadBytes(&existing_magic, sizeof(existing_magic)) && m_gx_pipeline_uid_cache_file.ReadBytes(&existing_version, sizeof(existing_version)) && existing_magic == CACHE_FILE_MAGIC && existing_version == GX_PIPELINE_UID_VERSION) @@ -563,7 +564,7 @@ void ShaderCache::LoadPipelineUIDCache() const size_t uid_count = static_cast(file_size - CACHE_HEADER_SIZE) / sizeof(SerializedGXPipelineUid); const size_t expected_size = uid_count * sizeof(SerializedGXPipelineUid) + CACHE_HEADER_SIZE; - bool uid_file_valid = file_size == expected_size; + uid_file_valid = file_size == expected_size; if (uid_file_valid) { for (size_t i = 0; i < uid_count; i++) @@ -583,12 +584,13 @@ void ShaderCache::LoadPipelineUIDCache() } // We open the file for reading and writing, so we must seek to the end before writing. - if (!uid_file_valid || !m_gx_pipeline_uid_cache_file.Seek(expected_size, SEEK_SET)) - { - // Close the file. We re-open and truncate it below. - m_gx_pipeline_uid_cache_file.Close(); - } + if (uid_file_valid) + uid_file_valid = m_gx_pipeline_uid_cache_file.Seek(expected_size, SEEK_SET); } + + // If the file is invalid, close it. We re-open and truncate it below. + if (!uid_file_valid) + m_gx_pipeline_uid_cache_file.Close(); } // If the file is not open, it means it was either corrupted or didn't exist. From 8587403e0e454f176a1b259285c3d0ab703adcdf Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 2 Apr 2018 01:01:08 +1000 Subject: [PATCH 2/2] ShaderCache: Write currently-known UIDs to cache when re-creating file This way, if we load a UID cache where the data was incomplete (e.g. Dolphin crashed), we don't lose the existing UIDs which were previously at the beginning. --- Source/Core/VideoCommon/ShaderCache.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 12166d2d4c..cd7ec4ced9 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -602,6 +602,12 @@ void ShaderCache::LoadPipelineUIDCache() m_gx_pipeline_uid_cache_file.WriteBytes(&CACHE_FILE_MAGIC, sizeof(GX_PIPELINE_UID_VERSION)); m_gx_pipeline_uid_cache_file.WriteBytes(&GX_PIPELINE_UID_VERSION, sizeof(GX_PIPELINE_UID_VERSION)); + + // Write any current UIDs out to the file. + // This way, if we load a UID cache where the data was incomplete (e.g. Dolphin crashed), + // we don't lose the existing UIDs which were previously at the beginning. + for (const auto& it : m_gx_pipeline_cache) + AppendGXPipelineUID(it.first); } }