Clean up various things.
This commit is contained in:
parent
ddfe219293
commit
81c614fa07
|
@ -24,7 +24,7 @@
|
||||||
// Increment this every time you change shader generation code.
|
// Increment this every time you change shader generation code.
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LINEAR_DISKCACHE_VER = 6965
|
LINEAR_DISKCACHE_VER = 6966
|
||||||
};
|
};
|
||||||
|
|
||||||
// On disk format:
|
// On disk format:
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#include "VideoConfig.h"
|
#include "VideoConfig.h"
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
|
|
||||||
PIXELSHADERUID last_pixel_shader_uid;
|
|
||||||
|
|
||||||
static int AlphaPreTest();
|
static int AlphaPreTest();
|
||||||
|
|
||||||
static void StageHash(int stage, u32* out)
|
static void StageHash(int stage, u32* out)
|
||||||
|
@ -104,8 +102,9 @@ static void StageHash(int stage, u32* out)
|
||||||
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
|
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
|
||||||
// It would likely be a lot more efficient to build this incrementally as the attributes
|
// It would likely be a lot more efficient to build this incrementally as the attributes
|
||||||
// are set...
|
// are set...
|
||||||
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode)
|
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||||
{
|
{
|
||||||
|
memset(uid->values, 0, sizeof(uid->values));
|
||||||
uid->values[0] |= bpmem.genMode.numtevstages; // 4
|
uid->values[0] |= bpmem.genMode.numtevstages; // 4
|
||||||
uid->values[0] |= bpmem.genMode.numtexgens << 4; // 4
|
uid->values[0] |= bpmem.genMode.numtexgens << 4; // 4
|
||||||
uid->values[0] |= dstAlphaMode << 8; // 2
|
uid->values[0] |= dstAlphaMode << 8; // 2
|
||||||
|
@ -192,13 +191,17 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode)
|
||||||
|
|
||||||
++ptr;
|
++ptr;
|
||||||
if (enablePL)
|
if (enablePL)
|
||||||
|
{
|
||||||
ptr += GetLightingShaderId(ptr);
|
ptr += GetLightingShaderId(ptr);
|
||||||
|
*ptr++ = components;
|
||||||
|
}
|
||||||
|
|
||||||
uid->num_values = ptr - uid->values;
|
uid->num_values = ptr - uid->values;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
|
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||||
{
|
{
|
||||||
|
memset(uid->values, 0, sizeof(uid->values));
|
||||||
u32* ptr = uid->values;
|
u32* ptr = uid->values;
|
||||||
*ptr++ = dstAlphaMode; // 0
|
*ptr++ = dstAlphaMode; // 0
|
||||||
*ptr++ = bpmem.genMode.hex; // 1
|
*ptr++ = bpmem.genMode.hex; // 1
|
||||||
|
@ -211,11 +214,11 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
|
||||||
|
|
||||||
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
||||||
{
|
{
|
||||||
// TODO: Include register states for lighting shader
|
|
||||||
*ptr++ = xfregs.color[0].hex;
|
*ptr++ = xfregs.color[0].hex;
|
||||||
*ptr++ = xfregs.alpha[0].hex;
|
*ptr++ = xfregs.alpha[0].hex;
|
||||||
*ptr++ = xfregs.color[1].hex;
|
*ptr++ = xfregs.color[1].hex;
|
||||||
*ptr++ = xfregs.alpha[1].hex;
|
*ptr++ = xfregs.alpha[1].hex;
|
||||||
|
*ptr++ = components;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 8; ++i)
|
for (unsigned int i = 0; i < 8; ++i)
|
||||||
|
@ -251,7 +254,7 @@ void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PIXELSHADERUIDSAFE new_id;
|
PIXELSHADERUIDSAFE new_id;
|
||||||
GetSafePixelShaderId(&new_id, dstAlphaMode);
|
GetSafePixelShaderId(&new_id, dstAlphaMode, components);
|
||||||
|
|
||||||
if (!(old_id == new_id))
|
if (!(old_id == new_id))
|
||||||
{
|
{
|
||||||
|
@ -874,13 +877,13 @@ static void WriteStage(char *&p, int n, API_TYPE ApiType)
|
||||||
}
|
}
|
||||||
else if (bpmem.tevind[n].mid <= 7 && bHasTexCoord)
|
else if (bpmem.tevind[n].mid <= 7 && bHasTexCoord)
|
||||||
{ // s matrix
|
{ // s matrix
|
||||||
// TODO: Might become negative?
|
_assert_(bpmem.tevind[n].mid >= 5);
|
||||||
int mtxidx = 2*(bpmem.tevind[n].mid-5);
|
int mtxidx = 2*(bpmem.tevind[n].mid-5);
|
||||||
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n);
|
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.xx;\n", n, mtxidx, texcoord, n);
|
||||||
}
|
}
|
||||||
else if (bpmem.tevind[n].mid <= 11 && bHasTexCoord)
|
else if (bpmem.tevind[n].mid <= 11 && bHasTexCoord)
|
||||||
{ // t matrix
|
{ // t matrix
|
||||||
// TODO: Might become negative?
|
_assert_(bpmem.tevind[n].mid >= 9);
|
||||||
int mtxidx = 2*(bpmem.tevind[n].mid-9);
|
int mtxidx = 2*(bpmem.tevind[n].mid-9);
|
||||||
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n);
|
WRITE(p, "float2 indtevtrans%d = "I_INDTEXMTX"[%d].ww * uv%d.xy * indtevcrd%d.yy;\n", n, mtxidx, texcoord, n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
#define C_PLIGHTS (C_FOG + 3)
|
#define C_PLIGHTS (C_FOG + 3)
|
||||||
#define C_PMATERIALS (C_PLIGHTS + 40)
|
#define C_PMATERIALS (C_PLIGHTS + 40)
|
||||||
#define C_PENVCONST_END (C_PMATERIALS + 4)
|
#define C_PENVCONST_END (C_PMATERIALS + 4)
|
||||||
#define PIXELSHADERUID_MAX_VALUES 69
|
#define PIXELSHADERUID_MAX_VALUES 70
|
||||||
#define PIXELSHADERUID_MAX_VALUES_SAFE 117
|
#define PIXELSHADERUID_MAX_VALUES_SAFE 120
|
||||||
|
|
||||||
// DO NOT make anything in this class virtual.
|
// DO NOT make anything in this class virtual.
|
||||||
template<bool safe>
|
template<bool safe>
|
||||||
|
@ -53,14 +53,10 @@ class _PIXELSHADERUID
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
u32 values[safe ? PIXELSHADERUID_MAX_VALUES_SAFE : PIXELSHADERUID_MAX_VALUES];
|
u32 values[safe ? PIXELSHADERUID_MAX_VALUES_SAFE : PIXELSHADERUID_MAX_VALUES];
|
||||||
u16 num_values;
|
int num_values;
|
||||||
|
|
||||||
_PIXELSHADERUID()
|
_PIXELSHADERUID()
|
||||||
{
|
{
|
||||||
memset(values, 0, sizeof(values));
|
|
||||||
|
|
||||||
if (safe) num_values = sizeof(values) / sizeof(values[0]);
|
|
||||||
else num_values = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_PIXELSHADERUID(const _PIXELSHADERUID& r)
|
_PIXELSHADERUID(const _PIXELSHADERUID& r)
|
||||||
|
@ -119,13 +115,10 @@ enum DSTALPHA_MODE
|
||||||
|
|
||||||
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
|
const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components);
|
||||||
|
|
||||||
// TODO: Wtf, those need components as well! -.-
|
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode);
|
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode);
|
|
||||||
|
|
||||||
// Used to make sure that our optimized pixel shader IDs don't lose any possible shader code changes
|
// Used to make sure that our optimized pixel shader IDs don't lose any possible shader code changes
|
||||||
void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::string& old_code, DSTALPHA_MODE dstAlphaMode, u32 components);
|
void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::string& old_code, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
|
|
||||||
extern PIXELSHADERUID last_pixel_shader_uid;
|
|
||||||
|
|
||||||
#endif // GCOGL_PIXELSHADER_H
|
#endif // GCOGL_PIXELSHADER_H
|
||||||
|
|
|
@ -26,12 +26,11 @@
|
||||||
#include "VertexShaderGen.h"
|
#include "VertexShaderGen.h"
|
||||||
#include "VideoConfig.h"
|
#include "VideoConfig.h"
|
||||||
|
|
||||||
VERTEXSHADERUID last_vertex_shader_uid;
|
|
||||||
|
|
||||||
// Mash together all the inputs that contribute to the code of a generated vertex shader into
|
// Mash together all the inputs that contribute to the code of a generated vertex shader into
|
||||||
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
|
// a unique identifier, basically containing all the bits. Yup, it's a lot ....
|
||||||
void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components)
|
void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components)
|
||||||
{
|
{
|
||||||
|
memset(uid->values, 0, sizeof(uid->values));
|
||||||
uid->values[0] = components |
|
uid->values[0] = components |
|
||||||
(xfregs.numTexGen.numTexGens << 23) |
|
(xfregs.numTexGen.numTexGens << 23) |
|
||||||
(xfregs.numChan.numColorChans << 27) |
|
(xfregs.numChan.numColorChans << 27) |
|
||||||
|
@ -67,6 +66,7 @@ void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components)
|
||||||
void GetSafeVertexShaderId(VERTEXSHADERUIDSAFE *uid, u32 components)
|
void GetSafeVertexShaderId(VERTEXSHADERUIDSAFE *uid, u32 components)
|
||||||
{
|
{
|
||||||
// Just store all used registers here without caring whether we need all bits or less.
|
// Just store all used registers here without caring whether we need all bits or less.
|
||||||
|
memset(uid->values, 0, sizeof(uid->values));
|
||||||
u32* ptr = uid->values;
|
u32* ptr = uid->values;
|
||||||
*ptr++ = components;
|
*ptr++ = components;
|
||||||
*ptr++ = xfregs.numTexGen.hex;
|
*ptr++ = xfregs.numTexGen.hex;
|
||||||
|
|
|
@ -57,7 +57,6 @@ public:
|
||||||
|
|
||||||
_VERTEXSHADERUID()
|
_VERTEXSHADERUID()
|
||||||
{
|
{
|
||||||
memset(values, 0, sizeof(values));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_VERTEXSHADERUID(const _VERTEXSHADERUID& r)
|
_VERTEXSHADERUID(const _VERTEXSHADERUID& r)
|
||||||
|
@ -116,6 +115,4 @@ void GetSafeVertexShaderId(VERTEXSHADERUIDSAFE *uid, u32 components);
|
||||||
// Used to make sure that our optimized vertex shader IDs don't lose any possible shader code changes
|
// Used to make sure that our optimized vertex shader IDs don't lose any possible shader code changes
|
||||||
void ValidateVertexShaderIDs(API_TYPE api, VERTEXSHADERUIDSAFE old_id, const std::string& old_code, u32 components);
|
void ValidateVertexShaderIDs(API_TYPE api, VERTEXSHADERUIDSAFE old_id, const std::string& old_code, u32 components);
|
||||||
|
|
||||||
extern VERTEXSHADERUID last_vertex_shader_uid;
|
|
||||||
|
|
||||||
#endif // GCOGL_VERTEXSHADER_H
|
#endif // GCOGL_VERTEXSHADER_H
|
||||||
|
|
|
@ -413,7 +413,7 @@ void PixelShaderCache::Init()
|
||||||
PixelShaderCacheInserter inserter;
|
PixelShaderCacheInserter inserter;
|
||||||
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
|
|
||||||
if (g_Config.bEnableShaderDebugging) // TODO: Hacks..
|
if (g_Config.bEnableShaderDebugging)
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ void VertexShaderCache::Init()
|
||||||
VertexShaderCacheInserter inserter;
|
VertexShaderCacheInserter inserter;
|
||||||
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
|
|
||||||
if (g_Config.bEnableShaderDebugging) // TODO: Hacks..
|
if (g_Config.bEnableShaderDebugging)
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,7 @@ void PixelShaderCache::Init()
|
||||||
PixelShaderCacheInserter inserter;
|
PixelShaderCacheInserter inserter;
|
||||||
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
|
|
||||||
if (g_Config.bEnableShaderDebugging) // TODO: Hacks..
|
if (g_Config.bEnableShaderDebugging)
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ void VertexShaderCache::Init()
|
||||||
VertexShaderCacheInserter inserter;
|
VertexShaderCacheInserter inserter;
|
||||||
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
|
g_vs_disk_cache.OpenAndRead(cache_filename, inserter);
|
||||||
|
|
||||||
if (g_Config.bEnableShaderDebugging) // TODO: Hacks..
|
if (g_Config.bEnableShaderDebugging)
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@ bool PixelShaderCache::s_displayCompileAlert;
|
||||||
GLuint PixelShaderCache::CurrentShader;
|
GLuint PixelShaderCache::CurrentShader;
|
||||||
bool PixelShaderCache::ShaderEnabled;
|
bool PixelShaderCache::ShaderEnabled;
|
||||||
|
|
||||||
static FRAGMENTSHADER* pShaderLast = NULL;
|
PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry = NULL;
|
||||||
|
PIXELSHADERUID PixelShaderCache::last_uid;
|
||||||
|
|
||||||
GLuint PixelShaderCache::GetDepthMatrixProgram()
|
GLuint PixelShaderCache::GetDepthMatrixProgram()
|
||||||
{
|
{
|
||||||
|
@ -61,10 +62,9 @@ void PixelShaderCache::Init()
|
||||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||||
ShaderEnabled = true;
|
ShaderEnabled = true;
|
||||||
CurrentShader = 0;
|
CurrentShader = 0;
|
||||||
|
last_entry = NULL;
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
||||||
memset(&last_pixel_shader_uid, 0xFF, sizeof(last_pixel_shader_uid));
|
|
||||||
|
|
||||||
s_displayCompileAlert = true;
|
s_displayCompileAlert = true;
|
||||||
|
|
||||||
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
|
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
|
||||||
|
@ -184,41 +184,40 @@ void PixelShaderCache::Shutdown()
|
||||||
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||||
{
|
{
|
||||||
PIXELSHADERUID uid;
|
PIXELSHADERUID uid;
|
||||||
GetPixelShaderId(&uid, dstAlphaMode);
|
GetPixelShaderId(&uid, dstAlphaMode, components);
|
||||||
|
|
||||||
// Check if the shader is already set - TODO: Use pShaderLast instead of PixelShaders[uid]?
|
// Check if the shader is already set
|
||||||
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount)
|
if (last_entry)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
if (uid == last_uid)
|
||||||
ValidatePixelShaderIDs(API_OPENGL, PixelShaders[uid].safe_uid, PixelShaders[uid].shader.strprog, dstAlphaMode, components);
|
{
|
||||||
return pShaderLast;
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components);
|
||||||
|
return &last_entry->shader;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&last_pixel_shader_uid, &uid, sizeof(PIXELSHADERUID));
|
last_uid = uid;
|
||||||
|
|
||||||
PSCache::iterator iter = PixelShaders.find(uid);
|
PSCache::iterator iter = PixelShaders.find(uid);
|
||||||
|
|
||||||
if (iter != PixelShaders.end())
|
if (iter != PixelShaders.end())
|
||||||
{
|
{
|
||||||
iter->second.frameCount = frameCount;
|
|
||||||
PSCacheEntry &entry = iter->second;
|
PSCacheEntry &entry = iter->second;
|
||||||
if (&entry.shader != pShaderLast)
|
last_entry = &entry;
|
||||||
pShaderLast = &entry.shader;
|
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
|
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
|
||||||
return pShaderLast;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make an entry in the table
|
// Make an entry in the table
|
||||||
PSCacheEntry& newentry = PixelShaders[uid];
|
PSCacheEntry& newentry = PixelShaders[uid];
|
||||||
newentry.frameCount = frameCount;
|
last_entry = &newentry;
|
||||||
pShaderLast = &newentry.shader;
|
|
||||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
||||||
|
|
||||||
if (g_ActiveConfig.bEnableShaderDebugging && code)
|
if (g_ActiveConfig.bEnableShaderDebugging && code)
|
||||||
{
|
{
|
||||||
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode);
|
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
|
||||||
newentry.shader.strprog = code;
|
newentry.shader.strprog = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +239,7 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
|
||||||
INCSTAT(stats.numPixelShadersCreated);
|
INCSTAT(stats.numPixelShadersCreated);
|
||||||
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
return pShaderLast;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
bool PixelShaderCache::CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||||
|
|
|
@ -47,8 +47,7 @@ class PixelShaderCache
|
||||||
struct PSCacheEntry
|
struct PSCacheEntry
|
||||||
{
|
{
|
||||||
FRAGMENTSHADER shader;
|
FRAGMENTSHADER shader;
|
||||||
int frameCount;
|
PSCacheEntry() {}
|
||||||
PSCacheEntry() : frameCount(0) {}
|
|
||||||
~PSCacheEntry() {}
|
~PSCacheEntry() {}
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
|
@ -66,6 +65,8 @@ class PixelShaderCache
|
||||||
static bool s_displayCompileAlert;
|
static bool s_displayCompileAlert;
|
||||||
|
|
||||||
static GLuint CurrentShader;
|
static GLuint CurrentShader;
|
||||||
|
static PSCacheEntry* last_entry;
|
||||||
|
static PIXELSHADERUID last_uid;
|
||||||
|
|
||||||
static bool ShaderEnabled;
|
static bool ShaderEnabled;
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,9 @@ VertexShaderCache::VSCache VertexShaderCache::vshaders;
|
||||||
GLuint VertexShaderCache::CurrentShader;
|
GLuint VertexShaderCache::CurrentShader;
|
||||||
bool VertexShaderCache::ShaderEnabled;
|
bool VertexShaderCache::ShaderEnabled;
|
||||||
|
|
||||||
static VERTEXSHADER *pShaderLast = NULL;
|
VertexShaderCache::VSCacheEntry* VertexShaderCache::last_entry = NULL;
|
||||||
|
VERTEXSHADERUID VertexShaderCache::last_uid;
|
||||||
|
|
||||||
static int s_nMaxVertexInstructions;
|
static int s_nMaxVertexInstructions;
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ void VertexShaderCache::Init()
|
||||||
glEnable(GL_VERTEX_PROGRAM_ARB);
|
glEnable(GL_VERTEX_PROGRAM_ARB);
|
||||||
ShaderEnabled = true;
|
ShaderEnabled = true;
|
||||||
CurrentShader = 0;
|
CurrentShader = 0;
|
||||||
memset(&last_vertex_shader_uid, 0xFF, sizeof(last_vertex_shader_uid));
|
last_entry = NULL;
|
||||||
|
|
||||||
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
|
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
|
||||||
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
|
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxVertexInstructions = 4096;
|
||||||
|
@ -74,31 +76,32 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
||||||
{
|
{
|
||||||
VERTEXSHADERUID uid;
|
VERTEXSHADERUID uid;
|
||||||
GetVertexShaderId(&uid, components);
|
GetVertexShaderId(&uid, components);
|
||||||
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
if (last_entry)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
if (uid == last_uid)
|
||||||
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
|
{
|
||||||
return pShaderLast;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID));
|
|
||||||
|
last_uid = uid;
|
||||||
|
|
||||||
VSCache::iterator iter = vshaders.find(uid);
|
VSCache::iterator iter = vshaders.find(uid);
|
||||||
if (iter != vshaders.end())
|
if (iter != vshaders.end())
|
||||||
{
|
{
|
||||||
iter->second.frameCount = frameCount;
|
|
||||||
VSCacheEntry &entry = iter->second;
|
VSCacheEntry &entry = iter->second;
|
||||||
if (&entry.shader != pShaderLast)
|
last_entry = &entry;
|
||||||
pShaderLast = &entry.shader;
|
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
|
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
|
||||||
return pShaderLast;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make an entry in the table
|
// Make an entry in the table
|
||||||
VSCacheEntry& entry = vshaders[uid];
|
VSCacheEntry& entry = vshaders[uid];
|
||||||
entry.frameCount = frameCount;
|
last_entry = &entry;
|
||||||
pShaderLast = &entry.shader;
|
|
||||||
const char *code = GenerateVertexShaderCode(components, API_OPENGL);
|
const char *code = GenerateVertexShaderCode(components, API_OPENGL);
|
||||||
GetSafeVertexShaderId(&entry.safe_uid, components);
|
GetSafeVertexShaderId(&entry.safe_uid, components);
|
||||||
|
|
||||||
|
@ -120,7 +123,7 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
||||||
INCSTAT(stats.numVertexShadersCreated);
|
INCSTAT(stats.numVertexShadersCreated);
|
||||||
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
|
SETSTAT(stats.numVertexShadersAlive, vshaders.size());
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
return pShaderLast;
|
return &last_entry->shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
|
||||||
|
|
|
@ -32,9 +32,7 @@ struct VERTEXSHADER
|
||||||
VERTEXSHADER() : glprogid(0) {}
|
VERTEXSHADER() : glprogid(0) {}
|
||||||
GLuint glprogid; // opengl program id
|
GLuint glprogid; // opengl program id
|
||||||
|
|
||||||
//#if defined(_DEBUG) || defined(DEBUGFAST)
|
|
||||||
std::string strprog;
|
std::string strprog;
|
||||||
//#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class VertexShaderCache
|
class VertexShaderCache
|
||||||
|
@ -43,8 +41,7 @@ class VertexShaderCache
|
||||||
{
|
{
|
||||||
VERTEXSHADER shader;
|
VERTEXSHADER shader;
|
||||||
VERTEXSHADERUIDSAFE safe_uid;
|
VERTEXSHADERUIDSAFE safe_uid;
|
||||||
int frameCount;
|
VSCacheEntry() {}
|
||||||
VSCacheEntry() : frameCount(0) {}
|
|
||||||
void Destroy() {
|
void Destroy() {
|
||||||
// printf("Destroying vs %i\n", shader.glprogid);
|
// printf("Destroying vs %i\n", shader.glprogid);
|
||||||
glDeleteProgramsARB(1, &shader.glprogid);
|
glDeleteProgramsARB(1, &shader.glprogid);
|
||||||
|
@ -56,6 +53,9 @@ class VertexShaderCache
|
||||||
|
|
||||||
static VSCache vshaders;
|
static VSCache vshaders;
|
||||||
|
|
||||||
|
static VSCacheEntry* last_entry;
|
||||||
|
static VERTEXSHADERUID last_uid;
|
||||||
|
|
||||||
static GLuint CurrentShader;
|
static GLuint CurrentShader;
|
||||||
static bool ShaderEnabled;
|
static bool ShaderEnabled;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue