Files
dolphin/Source/Core/VideoBackends/OGL/ProgramShaderCache.h
T

123 lines
2.4 KiB
C++
Raw Normal View History

// Copyright 2011 Dolphin Emulator Project
2015-05-18 01:08:10 +02:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
2011-11-30 21:00:21 -06:00
#pragma once
2011-11-30 21:00:21 -06:00
2014-02-17 05:18:15 -05:00
#include "Common/LinearDiskCache.h"
#include "Common/GL/GLUtil.h"
#include "Core/ConfigManager.h"
2014-10-30 23:40:03 +01:00
#include "VideoCommon/GeometryShaderGen.h"
2014-02-17 05:18:15 -05:00
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/VertexShaderGen.h"
2011-11-30 21:00:21 -06:00
namespace OGL
{
2013-03-26 22:16:29 +01:00
class SHADERUID
{
public:
2013-03-26 22:16:29 +01:00
VertexShaderUid vuid;
PixelShaderUid puid;
GeometryShaderUid guid;
2013-03-26 22:16:29 +01:00
SHADERUID() {}
SHADERUID(const SHADERUID& r) : vuid(r.vuid), puid(r.puid), guid(r.guid) {}
2013-03-26 22:16:29 +01:00
bool operator <(const SHADERUID& r) const
{
2014-08-15 14:09:53 -04:00
if (puid < r.puid)
return true;
if (r.puid < puid)
return false;
if (vuid < r.vuid)
return true;
if (r.vuid < vuid)
return false;
if (guid < r.guid)
return true;
return false;
}
2013-03-26 22:16:29 +01:00
bool operator ==(const SHADERUID& r) const
{
return puid == r.puid && vuid == r.vuid && guid == r.guid;
}
};
struct SHADER
{
SHADER() : glprogid(0) { }
void Destroy()
{
glDeleteProgram(glprogid);
glprogid = 0;
}
2014-11-14 14:46:49 -05:00
GLuint glprogid; // OpenGL program id
std::string strvprog, strpprog, strgprog;
void SetProgramVariables();
void SetProgramBindings();
void Bind();
};
2011-11-30 21:00:21 -06:00
class ProgramShaderCache
{
2011-12-26 02:58:52 -05:00
public:
2011-12-11 11:08:18 +01:00
struct PCacheEntry
{
SHADER shader;
2013-02-13 16:30:15 +01:00
bool in_cache;
void Destroy()
{
shader.Destroy();
}
2011-12-11 11:08:18 +01:00
};
2013-03-29 15:08:00 +01:00
2014-08-15 14:09:53 -04:00
static PCacheEntry GetShaderProgram();
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 primitive_type);
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 primitive_type);
static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode, const char* gcode = nullptr);
static GLuint CompileSingleShader(GLuint type, const char *code);
2013-01-14 13:58:11 +01:00
static void UploadConstants();
2014-08-15 14:09:53 -04:00
static void Init();
static void Shutdown();
static void CreateHeader();
2011-12-26 02:58:52 -05:00
private:
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>
2011-12-26 02:58:52 -05:00
{
public:
void Read(const SHADERUID &key, const u8 *value, u32 value_size) override;
2011-12-26 02:58:52 -05:00
};
2015-10-29 13:51:25 +01:00
typedef std::map<SHADERUID, PCacheEntry> PCache;
2011-12-26 02:58:52 -05:00
static PCache pshaders;
static PCacheEntry* last_entry;
static SHADERUID last_uid;
2011-12-26 02:58:52 -05:00
2015-10-29 14:43:05 +01:00
static UidChecker<PixelShaderUid, ShaderCode> pixel_uid_checker;
static UidChecker<VertexShaderUid, ShaderCode> vertex_uid_checker;
static UidChecker<GeometryShaderUid, ShaderCode> geometry_uid_checker;
2013-04-29 21:00:39 +02:00
2013-01-14 13:58:11 +01:00
static u32 s_ubo_buffer_size;
static s32 s_ubo_align;
2011-11-30 21:00:21 -06:00
};
} // namespace OGL