2014-02-03 13:02:17 +00:00
|
|
|
// 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();
|
2016-12-28 00:37:41 +00:00
|
|
|
bool SetShader(u32 primitive_type);
|
2014-02-03 13:02:17 +00:00
|
|
|
|
|
|
|
protected:
|
2016-12-28 00:37:41 +00:00
|
|
|
virtual Uid GetUid(u32 primitive_type, APIType api_type) = 0;
|
2016-09-28 20:31:39 +00:00
|
|
|
virtual ShaderCode GenerateCode(APIType api_type, Uid uid) = 0;
|
2014-02-03 13:02:17 +00:00
|
|
|
|
|
|
|
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:
|
2016-12-28 00:37:41 +00:00
|
|
|
VertexShaderUid GetUid(u32 primitive_type, APIType api_type) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-01-16 11:34:06 +00:00
|
|
|
return GetVertexShaderUid();
|
2014-02-03 13:02:17 +00:00
|
|
|
}
|
2016-09-28 20:31:39 +00:00
|
|
|
ShaderCode GenerateCode(APIType api_type, VertexShaderUid uid) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-01-16 11:34:06 +00:00
|
|
|
return GenerateVertexShaderCode(api_type, uid.GetUidData());
|
2014-02-03 13:02:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeometryShaderCache : public ShaderCache<GeometryShaderUid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<GeometryShaderCache> s_instance;
|
|
|
|
|
|
|
|
protected:
|
2016-12-28 00:37:41 +00:00
|
|
|
GeometryShaderUid GetUid(u32 primitive_type, APIType api_type) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-01-16 10:49:39 +00:00
|
|
|
return GetGeometryShaderUid(primitive_type);
|
2014-02-03 13:02:17 +00:00
|
|
|
}
|
2016-09-28 20:31:39 +00:00
|
|
|
ShaderCode GenerateCode(APIType api_type, GeometryShaderUid uid) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-02-27 20:46:58 +00:00
|
|
|
return GenerateGeometryShaderCode(api_type, uid.GetUidData());
|
2014-02-03 13:02:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PixelShaderCache : public ShaderCache<PixelShaderUid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<PixelShaderCache> s_instance;
|
|
|
|
|
|
|
|
protected:
|
2016-12-28 00:37:41 +00:00
|
|
|
PixelShaderUid GetUid(u32 primitive_type, APIType api_type) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-12-28 00:37:41 +00:00
|
|
|
return GetPixelShaderUid();
|
2014-02-03 13:02:17 +00:00
|
|
|
}
|
2016-09-28 20:31:39 +00:00
|
|
|
ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-09-28 20:31:39 +00:00
|
|
|
return GeneratePixelShaderCode(api_type, uid.GetUidData());
|
2014-02-03 13:02:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace NULL
|