mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-21 10:19:04 +02:00
Loading trusted whatever was in the file, apart from a few sanity
checks, and a damaged entry stayed in the cache for good, since loading
it put it back in the pipeline map and every save wrote it out again.
A Syphon Filter: Logan's Shadow cache had pipeline keys with garbage in
useHWTransform, which MoltenVK refused to create ("Vertex attribute
texcoord(1) is missing from the vertex descriptor").
Now the files end in an XXH3 checksum of everything before it, checked
before anything is read, and a cache that fails it is deleted and
rebuilt.
Bumps both cache versions, since the files have a new layout. Old files
fail the checksum anyway.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
33 lines
910 B
C++
33 lines
910 B
C++
#include <cstring>
|
|
#include <string>
|
|
|
|
#include "Common/File/FileUtil.h"
|
|
#include "Common/GPU/Shader.h"
|
|
#include "GPU/Common/ShaderCommon.h"
|
|
#include "ext/xxhash.h"
|
|
|
|
bool AppendShaderCacheChecksum(const Path &filename) {
|
|
std::string data;
|
|
if (!File::ReadBinaryFileToString(filename, &data)) {
|
|
return false;
|
|
}
|
|
const uint64_t checksum = XXH3_64bits(data.data(), data.size());
|
|
FILE *f = File::OpenCFile(filename, "ab");
|
|
if (!f) {
|
|
return false;
|
|
}
|
|
const bool ok = fwrite(&checksum, sizeof(checksum), 1, f) == 1;
|
|
return fclose(f) == 0 && ok;
|
|
}
|
|
|
|
bool VerifyShaderCacheChecksum(const Path &filename) {
|
|
std::string data;
|
|
if (!File::ReadBinaryFileToString(filename, &data) || data.size() < sizeof(uint64_t)) {
|
|
return false;
|
|
}
|
|
const size_t size = data.size() - sizeof(uint64_t);
|
|
uint64_t stored;
|
|
memcpy(&stored, data.data() + size, sizeof(stored));
|
|
return XXH3_64bits(data.data(), size) == stored;
|
|
}
|