OpenGLDevice: Fix invalidating pipeline cache on Windows

This commit is contained in:
Stenzek 2024-10-15 18:16:41 +10:00
parent 005d48a387
commit c6055affbf
No known key found for this signature in database

View File

@ -757,12 +757,12 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
{ {
DebugAssert(!m_pipeline_disk_cache_file); DebugAssert(!m_pipeline_disk_cache_file);
m_pipeline_disk_cache_file = FileSystem::OpenCFile(path.c_str(), "r+b", error); std::FILE* fp = FileSystem::OpenCFile(path.c_str(), "r+b", error);
if (!m_pipeline_disk_cache_file) if (!fp)
return false; return false;
// Read footer. // Read footer.
const s64 size = FileSystem::FSize64(m_pipeline_disk_cache_file); const s64 size = FileSystem::FSize64(fp);
if (size < static_cast<s64>(sizeof(PipelineDiskCacheFooter)) || if (size < static_cast<s64>(sizeof(PipelineDiskCacheFooter)) ||
size >= static_cast<s64>(std::numeric_limits<u32>::max())) size >= static_cast<s64>(std::numeric_limits<u32>::max()))
{ {
@ -771,10 +771,11 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
} }
PipelineDiskCacheFooter file_footer; PipelineDiskCacheFooter file_footer;
if (FileSystem::FSeek64(m_pipeline_disk_cache_file, size - sizeof(PipelineDiskCacheFooter), SEEK_SET) != 0 || if (FileSystem::FSeek64(fp, size - sizeof(PipelineDiskCacheFooter), SEEK_SET) != 0 ||
std::fread(&file_footer, sizeof(file_footer), 1, m_pipeline_disk_cache_file) != 1) std::fread(&file_footer, sizeof(file_footer), 1, fp) != 1)
{ {
Error::SetStringView(error, "Invalid cache file footer."); Error::SetStringView(error, "Invalid cache file footer.");
std::fclose(fp);
return false; return false;
} }
@ -790,15 +791,16 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
0) 0)
{ {
Error::SetStringView(error, "Cache does not match expected driver/version."); Error::SetStringView(error, "Cache does not match expected driver/version.");
std::fclose(fp);
return false; return false;
} }
m_pipeline_disk_cache_data_end = static_cast<u32>(size) - sizeof(PipelineDiskCacheFooter) - m_pipeline_disk_cache_data_end = static_cast<u32>(size) - sizeof(PipelineDiskCacheFooter) -
(sizeof(PipelineDiskCacheIndexEntry) * file_footer.num_programs); (sizeof(PipelineDiskCacheIndexEntry) * file_footer.num_programs);
if (m_pipeline_disk_cache_data_end < 0 || if (m_pipeline_disk_cache_data_end < 0 || FileSystem::FSeek64(fp, m_pipeline_disk_cache_data_end, SEEK_SET) != 0)
FileSystem::FSeek64(m_pipeline_disk_cache_file, m_pipeline_disk_cache_data_end, SEEK_SET) != 0)
{ {
Error::SetStringView(error, "Failed to seek to start of index entries."); Error::SetStringView(error, "Failed to seek to start of index entries.");
std::fclose(fp);
return false; return false;
} }
@ -806,11 +808,12 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
for (u32 i = 0; i < file_footer.num_programs; i++) for (u32 i = 0; i < file_footer.num_programs; i++)
{ {
PipelineDiskCacheIndexEntry entry; PipelineDiskCacheIndexEntry entry;
if (std::fread(&entry, sizeof(entry), 1, m_pipeline_disk_cache_file) != 1 || if (std::fread(&entry, sizeof(entry), 1, fp) != 1 ||
(static_cast<s64>(entry.offset) + static_cast<s64>(entry.compressed_size)) >= size) (static_cast<s64>(entry.offset) + static_cast<s64>(entry.compressed_size)) >= size)
{ {
Error::SetStringView(error, "Failed to read disk cache entry."); Error::SetStringView(error, "Failed to read disk cache entry.");
m_program_cache.clear(); m_program_cache.clear();
std::fclose(fp);
return false; return false;
} }
@ -818,6 +821,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
{ {
Error::SetStringView(error, "Duplicate program in disk cache."); Error::SetStringView(error, "Duplicate program in disk cache.");
m_program_cache.clear(); m_program_cache.clear();
std::fclose(fp);
return false; return false;
} }
@ -832,6 +836,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
} }
VERBOSE_LOG("Read {} programs from disk cache.", m_program_cache.size()); VERBOSE_LOG("Read {} programs from disk cache.", m_program_cache.size());
m_pipeline_disk_cache_file = fp;
return true; return true;
} }