Implement Program shaders cache. Seems to reduce a small amount of stuttering when F-Zero starts. Did it because I can :|

This commit is contained in:
Ryan Houdek
2011-12-21 00:15:48 -06:00
committed by Sonicadvance1
parent ef1e157786
commit d012c75005
4 changed files with 139 additions and 42 deletions

View File

@ -25,6 +25,9 @@
#include "PixelShaderGen.h"
#include "VertexShaderGen.h"
#include "LinearDiskCache.h"
#include "ConfigManager.h"
union PID
{
struct {
@ -65,14 +68,28 @@ namespace OGL
{
#define NUM_UNIFORMS 27
extern const char *UniformNames[NUM_UNIFORMS];
extern GLenum ProgramFormat;
struct PROGRAMSHADER
{
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){}
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0), binaryLength(0){}
GLuint glprogid; // opengl program id
GLuint vsid, psid;
GLint UniformLocations[NUM_UNIFORMS];
GLint binaryLength;
u8 *Data()
{
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
u8* binary = (u8*)malloc(binaryLength);
glGetProgramBinary(glprogid, binaryLength, NULL, &ProgramFormat, binary);
return binary;
}
GLint Size()
{
if(!binaryLength)
glGetProgramiv(glprogid, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
return binaryLength;
}
};
@ -87,7 +104,44 @@ class ProgramShaderCache
glDeleteProgram(program.glprogid);
program.glprogid = 0;
}
u8* Data()
{
return program.Data();
}
GLint Size()
{
return program.Size();
}
};
class ProgramShaderCacheInserter : public LinearDiskCacheReader<PROGRAMUID, u8>
{
public:
void Read(const PROGRAMUID &key, const u8 *value, u32 value_size)
{
PCacheEntry entry;
// The two shaders might not even exist anymore
// But it is fine, no need to worry about that
entry.program.vsid = key.uid.vsid;
entry.program.psid = key.uid.psid;
entry.program.glprogid = glCreateProgram();
glProgramBinary(entry.program.glprogid, ProgramFormat, value, value_size);
GLint success;
glGetProgramiv(entry.program.glprogid, GL_LINK_STATUS, &success);
if (success)
{
pshaders[std::make_pair(key.uid.psid, key.uid.vsid)] = entry;
glUseProgram(entry.program.glprogid);
SetProgramVariables(entry, key);
}
}
};
typedef std::map<std::pair<u64, u64>, PCacheEntry> PCache;
static PCache pshaders;
@ -96,6 +150,7 @@ class ProgramShaderCache
static GLuint s_ps_vs_ubo;
static GLintptr s_vs_data_offset;
static void SetProgramVariables(PCacheEntry &entry, const PROGRAMUID &uid);
public:
static PROGRAMSHADER GetShaderProgram(void);