mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-12 09:48:30 +12:00
save pipelines to a binary archive
This commit is contained in:
parent
53efb9e5b2
commit
3c1a7479c2
6 changed files with 150 additions and 93 deletions
|
@ -2,24 +2,18 @@
|
|||
#include "Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalCommon.h"
|
||||
#include "Cemu/FileCache/FileCache.h"
|
||||
#include "config/ActiveSettings.h"
|
||||
//#include "Cemu/FileCache/FileCache.h"
|
||||
//#include "config/ActiveSettings.h"
|
||||
|
||||
#include "Cemu/Logging/CemuLogging.h"
|
||||
#include "Common/precompiled.h"
|
||||
|
||||
bool s_isLoadingShadersMtl{ false };
|
||||
class FileCache* s_mslCache{nullptr};
|
||||
|
||||
extern std::atomic_int g_compiled_shaders_total;
|
||||
extern std::atomic_int g_compiled_shaders_async;
|
||||
|
||||
RendererShaderMtl::RendererShaderMtl(MetalRenderer* mtlRenderer, ShaderType type, uint64 baseHash, uint64 auxHash, bool isGameShader, bool isGfxPackShader, const std::string& mslCode)
|
||||
: RendererShader(type, baseHash, auxHash, isGameShader, isGfxPackShader), m_mtlr{mtlRenderer}
|
||||
{
|
||||
if (LoadBinary())
|
||||
return;
|
||||
|
||||
if (m_type == ShaderType::kFragment)
|
||||
{
|
||||
// Fragment functions are compiled just-in-time
|
||||
|
@ -30,12 +24,8 @@ RendererShaderMtl::RendererShaderMtl(MetalRenderer* mtlRenderer, ShaderType type
|
|||
Compile(mslCode);
|
||||
}
|
||||
|
||||
// Store the compiled shader in the cache
|
||||
StoreBinary();
|
||||
|
||||
// Count shader compilation
|
||||
if (!s_isLoadingShadersMtl)
|
||||
g_compiled_shaders_total++;
|
||||
g_compiled_shaders_total++;
|
||||
}
|
||||
|
||||
RendererShaderMtl::~RendererShaderMtl()
|
||||
|
@ -85,33 +75,6 @@ void RendererShaderMtl::CompileFragmentFunction(CachedFBOMtl* activeFBO)
|
|||
Compile(fullCode);
|
||||
}
|
||||
|
||||
void RendererShaderMtl::ShaderCacheLoading_begin(uint64 cacheTitleId)
|
||||
{
|
||||
if (s_mslCache)
|
||||
{
|
||||
delete s_mslCache;
|
||||
}
|
||||
uint32 spirvCacheMagic = GeneratePrecompiledCacheId();
|
||||
const std::string cacheFilename = fmt::format("{:016x}_msl.bin", cacheTitleId);
|
||||
const fs::path cachePath = ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename);
|
||||
s_mslCache = FileCache::Open(cachePath, true, spirvCacheMagic);
|
||||
if (!s_mslCache)
|
||||
cemuLog_log(LogType::Force, "Unable to open MSL cache {}", cacheFilename);
|
||||
s_isLoadingShadersMtl = true;
|
||||
}
|
||||
|
||||
void RendererShaderMtl::ShaderCacheLoading_end()
|
||||
{
|
||||
s_isLoadingShadersMtl = false;
|
||||
}
|
||||
|
||||
void RendererShaderMtl::ShaderCacheLoading_Close()
|
||||
{
|
||||
delete s_mslCache;
|
||||
g_compiled_shaders_total = 0;
|
||||
g_compiled_shaders_async = 0;
|
||||
}
|
||||
|
||||
void RendererShaderMtl::Compile(const std::string& mslCode)
|
||||
{
|
||||
NS::Error* error = nullptr;
|
||||
|
@ -125,33 +88,3 @@ void RendererShaderMtl::Compile(const std::string& mslCode)
|
|||
m_function = library->newFunction(NS::String::string("main0", NS::ASCIIStringEncoding));
|
||||
library->release();
|
||||
}
|
||||
|
||||
bool RendererShaderMtl::LoadBinary()
|
||||
{
|
||||
// HACK: since fragment functions are compiled just-in-time, we cannot load them from the cache
|
||||
if (m_type == ShaderType::kFragment)
|
||||
return false;
|
||||
|
||||
uint64 h1, h2;
|
||||
GenerateShaderPrecompiledCacheFilename(m_type, m_baseHash, m_auxHash, h1, h2);
|
||||
if (!s_mslCache->GetFile({h1, h2 }, m_binary))
|
||||
return false;
|
||||
|
||||
// TODO: implement
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RendererShaderMtl::StoreBinary()
|
||||
{
|
||||
if (m_binary.size() == 0)
|
||||
{
|
||||
// TODO: retrieve the binary from the function
|
||||
return;
|
||||
}
|
||||
|
||||
uint64 h1, h2;
|
||||
GenerateShaderPrecompiledCacheFilename(m_type, m_baseHash, m_auxHash, h1, h2);
|
||||
s_mslCache->AddFileAsync({h1, h2 }, m_binary.data(), m_binary.size());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue