Files
SaloQT 24c934a770 feat(recompiler): load prebuilt shader packs before the writable cache
Read-only packs of encoded cache entries are mapped once at startup from
the shader cache prebuilt directory (plus ANYPS5_PREBUILT_SHADER_CACHE,
opt out with ANYPS5_NO_PREBUILT_SHADERS). Disk loads try packs and loose
prebuilt folders first and fall through to the writable cache and the
compiler on a miss. Keys, source version, format and payload checksums
are validated exactly as for writable entries, and interval logs report
prebuilt hits, misses, rejections and load timings.

Depends on the uncached compile entry point only through the offline
tool that produces these packs; the loader itself is independent.
2026-10-15 05:44:34 +11:00

52 lines
1.6 KiB
C++

#pragma once
#include "ShaderDiskCache.hpp"
#include <array>
namespace ShaderRecompiler::ShaderDiskCache {
inline constexpr std::uint64_t PackMagic = 0x314b434150535041ull;
struct PackHeader {
std::uint64_t magic = PackMagic;
std::uint64_t sourceVersion = 0;
std::uint64_t fileBytes = 0;
std::uint64_t entryCount = 0;
std::uint64_t indexHash = 0;
};
struct PackRecord {
std::array<std::uint64_t, 2> hash{};
std::uint64_t offset = 0;
std::uint64_t size = 0;
};
static_assert(sizeof(PackHeader) == 40 && sizeof(PackRecord) == 32);
struct PackLoadTimings {
std::uint64_t lookupNanoseconds = 0;
std::uint64_t decodeNanoseconds = 0;
std::uint64_t bytes = 0;
};
[[nodiscard]] std::array<std::uint64_t, 2> PackKeyHash(std::span<const std::byte> key);
[[nodiscard]] std::vector<std::filesystem::path> PrebuiltCachePaths(const std::filesystem::path& cacheRoot);
class CachePack {
public:
explicit CachePack(const std::filesystem::path& path);
~CachePack();
CachePack(const CachePack&) = delete;
CachePack& operator=(const CachePack&) = delete;
[[nodiscard]] bool Valid() const { return error.empty(); }
[[nodiscard]] const std::string& Error() const { return error; }
[[nodiscard]] std::size_t Count() const { return records.size(); }
[[nodiscard]] LoadStatus Load(std::span<const std::byte> key, CompiledVariant& variant, PackLoadTimings& timings) const;
private:
void Validate();
std::span<const std::byte> file;
std::span<const PackRecord> records;
std::string error;
void* mapping = nullptr;
void* fileHandle = nullptr;
};
}