2013-04-17 23:29:41 -04:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2011-11-30 21:00:21 -06:00
|
|
|
|
2013-01-28 15:18:54 -06:00
|
|
|
#ifndef PROGRAM_SHADER_CACHE_H_
|
|
|
|
#define PROGRAM_SHADER_CACHE_H_
|
2011-11-30 21:00:21 -06:00
|
|
|
|
|
|
|
#include "GLUtil.h"
|
|
|
|
|
|
|
|
#include "PixelShaderGen.h"
|
|
|
|
#include "VertexShaderGen.h"
|
|
|
|
|
2011-12-21 00:15:48 -06:00
|
|
|
#include "LinearDiskCache.h"
|
|
|
|
#include "ConfigManager.h"
|
|
|
|
|
2011-12-26 02:58:52 -05:00
|
|
|
namespace OGL
|
2011-12-26 00:15:54 -05:00
|
|
|
{
|
2011-11-30 21:00:21 -06:00
|
|
|
|
2013-03-26 22:16:29 +01:00
|
|
|
class SHADERUID
|
2013-02-13 13:12:19 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-03-26 22:16:29 +01:00
|
|
|
VertexShaderUid vuid;
|
|
|
|
PixelShaderUid puid;
|
2013-02-13 13:12:19 +01:00
|
|
|
|
2013-03-26 22:16:29 +01:00
|
|
|
SHADERUID() {}
|
2013-02-13 13:12:19 +01:00
|
|
|
|
2013-03-26 22:16:29 +01:00
|
|
|
SHADERUID(const SHADERUID& r) : vuid(r.vuid), puid(r.puid) {}
|
2013-02-13 13:12:19 +01:00
|
|
|
|
2013-03-26 22:16:29 +01:00
|
|
|
bool operator <(const SHADERUID& r) const
|
2013-02-13 13:12:19 +01:00
|
|
|
{
|
|
|
|
if(puid < r.puid) return true;
|
|
|
|
if(r.puid < puid) return false;
|
|
|
|
if(vuid < r.vuid) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-26 22:16:29 +01:00
|
|
|
bool operator ==(const SHADERUID& r) const
|
2013-02-13 13:12:19 +01:00
|
|
|
{
|
|
|
|
return puid == r.puid && vuid == r.vuid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-19 00:12:02 +01:00
|
|
|
const int NUM_UNIFORMS = 19;
|
2011-12-26 02:58:52 -05:00
|
|
|
extern const char *UniformNames[NUM_UNIFORMS];
|
2013-02-13 13:12:19 +01:00
|
|
|
|
|
|
|
struct SHADER
|
|
|
|
{
|
|
|
|
SHADER() : glprogid(0) { }
|
|
|
|
void Destroy()
|
|
|
|
{
|
|
|
|
glDeleteProgram(glprogid);
|
|
|
|
glprogid = 0;
|
|
|
|
}
|
|
|
|
GLuint glprogid; // opengl program id
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2013-02-13 13:12:19 +01:00
|
|
|
std::string strvprog, strpprog;
|
|
|
|
GLint UniformLocations[NUM_UNIFORMS];
|
2013-08-23 17:52:47 +02:00
|
|
|
u32 UniformSize[NUM_UNIFORMS];
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2013-02-13 13:12:19 +01:00
|
|
|
void SetProgramVariables();
|
|
|
|
void SetProgramBindings();
|
|
|
|
void Bind();
|
|
|
|
};
|
2011-12-26 02:58:52 -05:00
|
|
|
|
|
|
|
class ProgramShaderCache
|
2011-11-30 21:00:21 -06:00
|
|
|
{
|
|
|
|
public:
|
2011-12-11 11:08:18 +01:00
|
|
|
|
2011-12-26 02:58:52 -05:00
|
|
|
struct PCacheEntry
|
2011-12-11 11:08:18 +01:00
|
|
|
{
|
2013-02-13 13:12:19 +01:00
|
|
|
SHADER shader;
|
2013-02-13 16:30:15 +01:00
|
|
|
bool in_cache;
|
2011-11-30 21:00:21 -06:00
|
|
|
|
2011-12-26 02:58:52 -05:00
|
|
|
void Destroy()
|
|
|
|
{
|
2013-02-13 13:12:19 +01:00
|
|
|
shader.Destroy();
|
2011-12-21 00:15:48 -06:00
|
|
|
}
|
|
|
|
};
|
2011-12-26 00:15:54 -05:00
|
|
|
|
2013-03-29 15:08:00 +01:00
|
|
|
typedef std::map<SHADERUID, PCacheEntry> PCache;
|
|
|
|
|
2011-12-26 02:58:52 -05:00
|
|
|
static PCacheEntry GetShaderProgram(void);
|
|
|
|
static GLuint GetCurrentProgram(void);
|
2013-02-13 13:12:19 +01:00
|
|
|
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
|
|
|
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
2013-10-29 01:23:17 -04:00
|
|
|
|
2013-02-13 13:12:19 +01:00
|
|
|
static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode);
|
|
|
|
static GLuint CompileSingleShader(GLuint type, const char *code);
|
2013-01-14 13:58:11 +01:00
|
|
|
static void UploadConstants();
|
2011-12-26 02:58:52 -05:00
|
|
|
|
|
|
|
static void Init(void);
|
|
|
|
static void Shutdown(void);
|
2013-02-13 21:34:48 +01:00
|
|
|
static void CreateHeader(void);
|
2011-12-26 02:58:52 -05:00
|
|
|
|
|
|
|
private:
|
2013-02-13 13:12:19 +01:00
|
|
|
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>
|
2011-12-21 00:15:48 -06:00
|
|
|
{
|
2011-12-26 00:15:54 -05:00
|
|
|
public:
|
2013-10-29 01:34:26 -04:00
|
|
|
void Read(const SHADERUID &key, const u8 *value, u32 value_size) override;
|
2011-12-11 11:08:18 +01:00
|
|
|
};
|
2011-12-26 00:15:54 -05:00
|
|
|
|
2011-12-11 11:08:18 +01:00
|
|
|
static PCache pshaders;
|
2013-02-13 13:12:19 +01:00
|
|
|
static PCacheEntry* last_entry;
|
|
|
|
static SHADERUID last_uid;
|
2011-12-11 11:08:18 +01:00
|
|
|
|
2013-04-29 21:00:39 +02:00
|
|
|
static UidChecker<PixelShaderUid,PixelShaderCode> pixel_uid_checker;
|
|
|
|
static UidChecker<VertexShaderUid,VertexShaderCode> vertex_uid_checker;
|
|
|
|
|
2013-01-14 13:58:11 +01:00
|
|
|
static u32 s_ubo_buffer_size;
|
2013-10-07 17:19:47 +02:00
|
|
|
static s32 s_ubo_align;
|
2011-11-30 21:00:21 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OGL
|
2013-01-28 15:18:54 -06:00
|
|
|
#endif
|