Move shader caches to VideoCommon

This commit is contained in:
Stenzek
2018-02-25 01:15:35 +10:00
parent 24df896eb8
commit dec0c3bce8
48 changed files with 1448 additions and 3346 deletions

View File

@ -3,7 +3,6 @@ set(SRCS
NullTexture.cpp
Render.cpp
VertexManager.cpp
ShaderCache.cpp
)
set(LIBS

View File

@ -39,14 +39,12 @@
<ClCompile Include="NullBackend.cpp" />
<ClCompile Include="NullTexture.cpp" />
<ClCompile Include="Render.cpp" />
<ClCompile Include="ShaderCache.cpp" />
<ClCompile Include="VertexManager.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="NullTexture.h" />
<ClInclude Include="PerfQuery.h" />
<ClInclude Include="Render.h" />
<ClInclude Include="ShaderCache.h" />
<ClInclude Include="TextureCache.h" />
<ClInclude Include="VertexManager.h" />
<ClInclude Include="VideoBackend.h" />

View File

@ -9,7 +9,6 @@
#include "VideoBackends/Null/PerfQuery.h"
#include "VideoBackends/Null/Render.h"
#include "VideoBackends/Null/ShaderCache.h"
#include "VideoBackends/Null/TextureCache.h"
#include "VideoBackends/Null/VertexManager.h"
#include "VideoBackends/Null/VideoBackend.h"
@ -63,21 +62,15 @@ bool VideoBackend::Initialize(void* window_handle)
g_perf_query = std::make_unique<PerfQuery>();
g_framebuffer_manager = std::make_unique<FramebufferManagerBase>();
g_texture_cache = std::make_unique<TextureCache>();
VertexShaderCache::s_instance = std::make_unique<VertexShaderCache>();
GeometryShaderCache::s_instance = std::make_unique<GeometryShaderCache>();
PixelShaderCache::s_instance = std::make_unique<PixelShaderCache>();
return true;
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
return g_shader_cache->Initialize();
}
void VideoBackend::Shutdown()
{
g_shader_cache->Shutdown();
g_renderer->Shutdown();
PixelShaderCache::s_instance.reset();
VertexShaderCache::s_instance.reset();
GeometryShaderCache::s_instance.reset();
g_texture_cache.reset();
g_perf_query.reset();
g_vertex_manager.reset();

View File

@ -1,77 +0,0 @@
// 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 <typename Uid>
ShaderCache<Uid>::ShaderCache()
{
Clear();
SETSTAT(stats.numPixelShadersCreated, 0);
SETSTAT(stats.numPixelShadersAlive, 0);
}
template <typename Uid>
ShaderCache<Uid>::~ShaderCache()
{
Clear();
}
template <typename Uid>
void ShaderCache<Uid>::Clear()
{
m_shaders.clear();
m_last_entry = nullptr;
}
template <typename Uid>
bool ShaderCache<Uid>::SetShader(PrimitiveType 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<VertexShaderUid>;
template class ShaderCache<GeometryShaderUid>;
template class ShaderCache<PixelShaderUid>;
std::unique_ptr<VertexShaderCache> VertexShaderCache::s_instance;
std::unique_ptr<GeometryShaderCache> GeometryShaderCache::s_instance;
std::unique_ptr<PixelShaderCache> PixelShaderCache::s_instance;
}

View File

@ -1,85 +0,0 @@
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <map>
#include <memory>
#include "VideoCommon/GeometryShaderGen.h"
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/VertexShaderGen.h"
#include "VideoCommon/VideoCommon.h"
namespace Null
{
template <typename Uid>
class ShaderCache
{
public:
ShaderCache();
virtual ~ShaderCache();
void Clear();
bool SetShader(PrimitiveType primitive_type);
protected:
virtual Uid GetUid(PrimitiveType primitive_type, APIType api_type) = 0;
virtual ShaderCode GenerateCode(APIType api_type, Uid uid) = 0;
private:
std::map<Uid, std::string> m_shaders;
const std::string* m_last_entry = nullptr;
Uid m_last_uid;
};
class VertexShaderCache : public ShaderCache<VertexShaderUid>
{
public:
static std::unique_ptr<VertexShaderCache> s_instance;
protected:
VertexShaderUid GetUid(PrimitiveType primitive_type, APIType api_type) override
{
return GetVertexShaderUid();
}
ShaderCode GenerateCode(APIType api_type, VertexShaderUid uid) override
{
return GenerateVertexShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
}
};
class GeometryShaderCache : public ShaderCache<GeometryShaderUid>
{
public:
static std::unique_ptr<GeometryShaderCache> s_instance;
protected:
GeometryShaderUid GetUid(PrimitiveType primitive_type, APIType api_type) override
{
return GetGeometryShaderUid(primitive_type);
}
ShaderCode GenerateCode(APIType api_type, GeometryShaderUid uid) override
{
return GenerateGeometryShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
}
};
class PixelShaderCache : public ShaderCache<PixelShaderUid>
{
public:
static std::unique_ptr<PixelShaderCache> s_instance;
protected:
PixelShaderUid GetUid(PrimitiveType primitive_type, APIType api_type) override
{
return GetPixelShaderUid();
}
ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override
{
return GeneratePixelShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData());
}
};
} // namespace NULL

View File

@ -4,8 +4,6 @@
#include "VideoBackends/Null/VertexManager.h"
#include "VideoBackends/Null/ShaderCache.h"
#include "VideoCommon/IndexGenerator.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/VertexLoaderManager.h"
@ -41,9 +39,6 @@ void VertexManager::ResetBuffer(u32 stride)
void VertexManager::vFlush()
{
VertexShaderCache::s_instance->SetShader(m_current_primitive_type);
GeometryShaderCache::s_instance->SetShader(m_current_primitive_type);
PixelShaderCache::s_instance->SetShader(m_current_primitive_type);
}
} // namespace