store loaded pipelines

This commit is contained in:
Samuliak 2024-10-15 17:47:47 +02:00
parent cd21d957b3
commit 944cc8be7d
No known key found for this signature in database
2 changed files with 20 additions and 48 deletions

View file

@ -7,29 +7,6 @@
// TODO: binary archives
class MetalPipelineCache
{
private:
struct PipelineHash
{
PipelineHash(uint64 h0, uint64 h1) : h0(h0), h1(h1) {};
uint64 h0;
uint64 h1;
bool operator==(const PipelineHash& r) const
{
return h0 == r.h0 && h1 == r.h1;
}
struct HashFunc
{
size_t operator()(const PipelineHash& v) const
{
static_assert(sizeof(uint64) == sizeof(size_t));
return v.h0 ^ v.h1;
}
};
};
public:
static MetalPipelineCache& GetInstance();
@ -45,13 +22,6 @@ public:
void LoadPipelineFromCache(std::span<uint8> fileData);
void Close(); // called on title exit
bool HasPipelineCached(uint64 baseHash, uint64 pipelineStateHash);
void AddCurrentStateToCache(uint64 baseHash, uint64 pipelineStateHash);
// pipeline serialization for file
bool SerializePipeline(class MemStreamWriter& memWriter, struct CachedPipeline& cachedPipeline);
bool DeserializePipeline(class MemStreamReader& memReader, struct CachedPipeline& cachedPipeline);
// Debug
size_t GetPipelineCacheSize() const { return m_pipelineCache.size(); }
@ -59,11 +29,10 @@ private:
class MetalRenderer* m_mtlr;
std::map<uint64, MTL::RenderPipelineState*> m_pipelineCache;
FSpinlock m_pipelineCacheLock;
std::thread* m_pipelineCacheStoreThread;
std::unordered_set<PipelineHash, PipelineHash::HashFunc> m_pipelineIsCached;
FSpinlock m_pipelineIsCachedLock;
class FileCache* s_cache;
std::atomic_uint32_t m_numCompilationThreads{ 0 };
@ -72,6 +41,12 @@ private:
static uint64 CalculatePipelineHash(const LatteFetchShader* fetchShader, const LatteDecompilerShader* vertexShader, const LatteDecompilerShader* geometryShader, const LatteDecompilerShader* pixelShader, const class MetalAttachmentsInfo& lastUsedAttachmentsInfo, const class MetalAttachmentsInfo& activeAttachmentsInfo, const LatteContextRegister& lcr);
void AddCurrentStateToCache(uint64 pipelineStateHash);
// pipeline serialization for file
bool SerializePipeline(class MemStreamWriter& memWriter, struct CachedPipeline& cachedPipeline);
bool DeserializePipeline(class MemStreamReader& memReader, struct CachedPipeline& cachedPipeline);
int CompilerThread();
void WorkerThread();
};