// Copyright 2015 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. #include "VideoBackends/Null/ShaderCache.h" #include "VideoCommon/Debugger.h" #include "VideoCommon/Statistics.h" #include "VideoCommon/VideoCommon.h" namespace Null { template ShaderCache::ShaderCache() { Clear(); SETSTAT(stats.numPixelShadersCreated, 0); SETSTAT(stats.numPixelShadersAlive, 0); } template ShaderCache::~ShaderCache() { Clear(); } template void ShaderCache::Clear() { m_shaders.clear(); m_last_entry = nullptr; } template bool ShaderCache::SetShader(u32 primitive_type) { Uid uid = GetUid(primitive_type, APIType::OpenGL); // Check if the shader is already set if (m_last_entry) { if (uid == m_last_uid) { return true; } } m_last_uid = uid; // Check if the shader is already in the cache auto iter = m_shaders.find(uid); if (iter != m_shaders.end()) { const std::string& entry = iter->second; m_last_entry = &entry; GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); return true; } // Need to compile a new shader ShaderCode code = GenerateCode(APIType::OpenGL, uid); m_shaders.emplace(uid, code.GetBuffer()); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); return true; } template class ShaderCache; template class ShaderCache; template class ShaderCache; std::unique_ptr VertexShaderCache::s_instance; std::unique_ptr GeometryShaderCache::s_instance; std::unique_ptr PixelShaderCache::s_instance; }