-
Notifications
You must be signed in to change notification settings - Fork 811
Expand file tree
/
Copy pathMetalPipelineCache.h
More file actions
52 lines (37 loc) · 2.24 KB
/
MetalPipelineCache.h
File metadata and controls
52 lines (37 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include "Cafe/HW/Latte/Renderer/Metal/MetalPipelineCompiler.h"
#include "util/helpers/ConcurrentQueue.h"
#include "util/helpers/fspinlock.h"
#include "util/math/vector2.h"
class MetalPipelineCache
{
public:
static MetalPipelineCache& GetInstance();
MetalPipelineCache(class MetalRenderer* metalRenderer);
~MetalPipelineCache();
PipelineObject* GetRenderPipelineState(const LatteFetchShader* fetchShader, const LatteDecompilerShader* vertexShader, const LatteDecompilerShader* geometryShader, const LatteDecompilerShader* pixelShader, const class MetalAttachmentsInfo& lastUsedAttachmentsInfo, const class MetalAttachmentsInfo& activeAttachmentsInfo, Vector2i extend, uint32 indexCount, const LatteContextRegister& lcr);
// Cache loading
uint32 BeginLoading(uint64 cacheTitleId); // returns count of pipelines stored in cache
bool UpdateLoading(uint32& pipelinesLoadedTotal, uint32& pipelinesMissingShaders);
void EndLoading();
void LoadPipelineFromCache(std::span<uint8> fileData);
void Close(); // called on title exit
// Debug
size_t GetPipelineCacheSize() const { return m_pipelineCache.size(); }
private:
class MetalRenderer* m_mtlr;
std::map<uint64, PipelineObject*> m_pipelineCache;
FSpinlock m_pipelineCacheLock;
std::thread* m_pipelineCacheStoreThread = nullptr;
class FileCache* s_cache = nullptr;
std::atomic_uint32_t m_numCompilationThreads{ 0 };
ConcurrentQueue<std::vector<uint8>> m_compilationQueue;
std::atomic_uint32_t m_compilationCount;
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, const class MetalAttachmentsInfo& lastUsedAttachmentsInfo);
// pipeline serialization for file
bool SerializePipeline(class MemStreamWriter& memWriter, struct CachedPipeline& cachedPipeline);
bool DeserializePipeline(class MemStreamReader& memReader, struct CachedPipeline& cachedPipeline);
int CompilerThread();
void WorkerThread();
};