mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Add runtime checks to make sure we aren't overoptimizing the pixel shader cache.
This commit is contained in:
@ -184,12 +184,30 @@ void PixelShaderCache::Shutdown()
|
||||
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||
{
|
||||
PIXELSHADERUID uid;
|
||||
PIXELSHADERUIDSAFE safe_uid;
|
||||
GetPixelShaderId(&uid, dstAlphaMode);
|
||||
GetSafePixelShaderId(&safe_uid, dstAlphaMode);
|
||||
|
||||
// Check if the shader is already set
|
||||
// Check if the shader is already set - TODO: Use pShaderLast instead of PixelShaders[uid]?
|
||||
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount)
|
||||
{
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
|
||||
if (!(safe_uid == PixelShaders[uid].safe_uid))
|
||||
{
|
||||
std::string code(GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components));
|
||||
if (code != PixelShaders[uid].code)
|
||||
{
|
||||
char msg[4096];
|
||||
char* ptr = msg;
|
||||
ptr += sprintf(ptr, "Mismatch!\nUnique IDs:\n");
|
||||
for (int i = 0; i < PixelShaders[uid].safe_uid.GetNumValues()/2; ++i)
|
||||
ptr += sprintf(ptr, "%02d, %08X %08X | %08X %08X\n", 2*i, PixelShaders[uid].safe_uid.values[2*i], PixelShaders[uid].safe_uid.values[2*i+1],
|
||||
safe_uid.values[2*i], safe_uid.values[2*i+1]);
|
||||
PanicAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return pShaderLast;
|
||||
}
|
||||
|
||||
@ -207,14 +225,31 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
|
||||
}
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||
if (!(safe_uid == entry.safe_uid))
|
||||
{
|
||||
std::string code(GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components));
|
||||
if (code != entry.code)
|
||||
{
|
||||
char msg[4096];
|
||||
char *ptr = msg;
|
||||
ptr += sprintf(ptr, "Mismatch!\nUnique IDs:\n");
|
||||
for (int i = 0; i < entry.safe_uid.GetNumValues()/2; ++i)
|
||||
ptr += sprintf(ptr, "%02d\t%08X %08X | %08X %08X\n", 2*i, entry.safe_uid.values[2*i], entry.safe_uid.values[2*i+1],
|
||||
safe_uid.values[2*i], safe_uid.values[2*i+1]);
|
||||
PanicAlert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return pShaderLast;
|
||||
}
|
||||
|
||||
// Make an entry in the table
|
||||
PSCacheEntry& newentry = PixelShaders[uid];
|
||||
newentry.frameCount = frameCount;
|
||||
newentry.safe_uid = safe_uid;
|
||||
pShaderLast = &newentry.shader;
|
||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
||||
newentry.code = code;
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
|
||||
|
Reference in New Issue
Block a user