From ecae0239ce844aa1f6ce04b2f2e376b43f5850a6 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sat, 20 Jan 2024 19:53:00 -0600 Subject: [PATCH] Temporary (?) shader cache changes to disable caching of shaders --- Source/Core/VideoCommon/ShaderCache.cpp | 23 ++++++++++++----------- Source/Core/VideoCommon/ShaderCache.h | 4 +++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 22939e9b90..43402fe691 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -37,10 +37,11 @@ ShaderCache::~ShaderCache() ClearCaches(); } -bool ShaderCache::Initialize() +bool ShaderCache::Initialize(bool force_no_cache) { m_api_type = g_backend_info.api_type; m_host_config.bits = ShaderHostConfig::GetCurrent().bits; + m_should_cache = g_ActiveConfig.bShaderCache && !force_no_cache; if (!CompileSharedPipelines()) return false; @@ -56,7 +57,7 @@ void ShaderCache::InitializeShaderCache() m_async_shader_compiler->ResizeWorkerThreads(g_ActiveConfig.GetShaderPrecompilerThreads()); // Load shader and UID caches. - if (g_ActiveConfig.bShaderCache && m_api_type != APIType::Nothing) + if (m_should_cache && m_api_type != APIType::Nothing) { LoadCaches(); LoadPipelineUIDCache(); @@ -84,7 +85,7 @@ void ShaderCache::Reload() if (!CompileSharedPipelines()) PanicAlertFmt("Failed to compile shared pipelines after reload."); - if (g_ActiveConfig.bShaderCache) + if (m_should_cache) LoadCaches(); // Switch to the precompiling shader configuration while we rebuild. @@ -125,7 +126,7 @@ const AbstractPipeline* ShaderCache::GetPipelineForUid(const GXPipelineUid& uid) std::optional pipeline_config = GetGXPipelineConfig(uid); if (pipeline_config) pipeline = g_gfx->CreatePipeline(*pipeline_config); - if (g_ActiveConfig.bShaderCache && !exists_in_cache) + if (m_should_cache && !exists_in_cache) AppendGXPipelineUID(uid); return InsertGXPipeline(uid, std::move(pipeline)); } @@ -470,7 +471,7 @@ const AbstractShader* ShaderCache::InsertVertexShader(const VertexShaderUid& uid if (shader && !entry.shader) { - if (g_ActiveConfig.bShaderCache && g_backend_info.bSupportsShaderBinaries) + if (m_should_cache && g_backend_info.bSupportsShaderBinaries) { auto binary = shader->GetBinary(); if (!binary.empty()) @@ -492,7 +493,7 @@ const AbstractShader* ShaderCache::InsertVertexUberShader(const UberShader::Vert if (shader && !entry.shader) { - if (g_ActiveConfig.bShaderCache && g_backend_info.bSupportsShaderBinaries) + if (m_should_cache && g_backend_info.bSupportsShaderBinaries) { auto binary = shader->GetBinary(); if (!binary.empty()) @@ -514,7 +515,7 @@ const AbstractShader* ShaderCache::InsertPixelShader(const PixelShaderUid& uid, if (shader && !entry.shader) { - if (g_ActiveConfig.bShaderCache && g_backend_info.bSupportsShaderBinaries) + if (m_should_cache && g_backend_info.bSupportsShaderBinaries) { auto binary = shader->GetBinary(); if (!binary.empty()) @@ -536,7 +537,7 @@ const AbstractShader* ShaderCache::InsertPixelUberShader(const UberShader::Pixel if (shader && !entry.shader) { - if (g_ActiveConfig.bShaderCache && g_backend_info.bSupportsShaderBinaries) + if (m_should_cache && g_backend_info.bSupportsShaderBinaries) { auto binary = shader->GetBinary(); if (!binary.empty()) @@ -563,7 +564,7 @@ const AbstractShader* ShaderCache::CreateGeometryShader(const GeometryShaderUid& if (shader && !entry.shader) { - if (g_ActiveConfig.bShaderCache && g_backend_info.bSupportsShaderBinaries) + if (m_should_cache && g_backend_info.bSupportsShaderBinaries) { auto binary = shader->GetBinary(); if (!binary.empty()) @@ -875,7 +876,7 @@ const AbstractPipeline* ShaderCache::InsertGXPipeline(const GXPipelineUid& confi { entry.first = std::move(pipeline); - if (g_ActiveConfig.bShaderCache) + if (m_should_cache) { auto cache_data = entry.first->GetCacheData(); if (!cache_data.empty()) @@ -901,7 +902,7 @@ ShaderCache::InsertGXUberPipeline(const GXUberPipelineUid& config, { entry.first = std::move(pipeline); - if (g_ActiveConfig.bShaderCache) + if (m_should_cache) { auto cache_data = entry.first->GetCacheData(); if (!cache_data.empty()) diff --git a/Source/Core/VideoCommon/ShaderCache.h b/Source/Core/VideoCommon/ShaderCache.h index c76f7dac16..7d84d99136 100644 --- a/Source/Core/VideoCommon/ShaderCache.h +++ b/Source/Core/VideoCommon/ShaderCache.h @@ -47,7 +47,7 @@ public: ~ShaderCache(); // Perform at startup, create descriptor layouts, compiles all static shaders. - bool Initialize(); + bool Initialize(bool force_no_cache = false); void Shutdown(); // Compiles/loads cached shaders. @@ -252,6 +252,8 @@ private: // Texture decoding shaders std::map, std::unique_ptr> m_texture_decoding_shaders; + bool m_should_cache = false; + Common::EventHook m_frame_end_handler; };