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();
|
|
|
|
bool SetShader(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type);
|
|
|
|
|
|
|
|
protected:
|
2016-07-21 23:04:57 +00:00
|
|
|
virtual Uid GetUid(DSTALPHA_MODE dst_alpha_mode, 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:
|
|
|
|
VertexShaderUid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type,
|
2016-07-21 23:04:57 +00:00
|
|
|
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:
|
|
|
|
GeometryShaderUid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type,
|
2016-07-21 23:04:57 +00:00
|
|
|
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-07-21 23:04:57 +00:00
|
|
|
PixelShaderUid GetUid(DSTALPHA_MODE dst_alpha_mode, u32 primitive_type, APIType api_type) override
|
2014-02-03 13:02:17 +00:00
|
|
|
{
|
2016-01-16 12:41:26 +00:00
|
|
|
return GetPixelShaderUid(dst_alpha_mode);
|
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
|