Replace the shader uid system with a new one which quasi-automatically generates uids for shaders.

Currently used in the vertex shader only (had to fork lighting shaders for now).
This commit is contained in:
NeoBrainX
2012-08-06 22:41:30 +02:00
parent a8d4c78cec
commit ca0e292dd4
5 changed files with 464 additions and 294 deletions

View File

@ -42,7 +42,7 @@ GLuint VertexShaderCache::CurrentShader;
bool VertexShaderCache::ShaderEnabled;
VertexShaderCache::VSCacheEntry* VertexShaderCache::last_entry = NULL;
VERTEXSHADERUID VertexShaderCache::last_uid;
ShaderUid VertexShaderCache::last_uid;
static int s_nMaxVertexInstructions;
@ -74,14 +74,14 @@ void VertexShaderCache::Shutdown()
VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
{
VERTEXSHADERUID uid;
GetVertexShaderId(&uid, components);
// Possible optimization: Don't always generate the shader uid, but keep track of changes in BPStructs instead
ShaderUid uid;
GenerateShaderUid(uid, components, API_OPENGL);
if (last_entry)
{
if (uid == last_uid)
{
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
return &last_entry->shader;
}
}
@ -95,15 +95,14 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
return &last_entry->shader;
}
// Make an entry in the table
VSCacheEntry& entry = vshaders[uid];
last_entry = &entry;
const char *code = GenerateVertexShaderCode(components, API_OPENGL);
GetSafeVertexShaderId(&entry.safe_uid, components);
ShaderCode code;
GenerateShaderCode(code, components, API_OPENGL);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
@ -111,11 +110,11 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
char szTemp[MAX_PATH];
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(szTemp, code);
SaveData(szTemp, code.GetBuffer());
}
#endif
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
if (!code.GetBuffer() || !VertexShaderCache::CompileVertexShader(entry.shader, code.GetBuffer())) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL;
}

View File

@ -40,7 +40,7 @@ class VertexShaderCache
struct VSCacheEntry
{
VERTEXSHADER shader;
VERTEXSHADERUIDSAFE safe_uid;
ShaderUid safe_uid;
VSCacheEntry() {}
void Destroy() {
// printf("Destroying vs %i\n", shader.glprogid);
@ -49,12 +49,12 @@ class VertexShaderCache
}
};
typedef std::map<VERTEXSHADERUID, VSCacheEntry> VSCache;
typedef std::map<ShaderUid, VSCacheEntry> VSCache;
static VSCache vshaders;
static VSCacheEntry* last_entry;
static VERTEXSHADERUID last_uid;
static ShaderUid last_uid; // TODO: Use reference instead..
static GLuint CurrentShader;
static bool ShaderEnabled;