mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Improve the shader UID debugging stuff and merge it to VideoCommon, effectively enabling it in D3D9 and D3D11 as well.
This commit is contained in:
@ -53,7 +53,7 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...)
|
|||||||
{
|
{
|
||||||
// Read message and write it to the log
|
// Read message and write it to the log
|
||||||
std::string caption;
|
std::string caption;
|
||||||
char buffer[4096];
|
char buffer[2048];
|
||||||
|
|
||||||
static std::string info_caption;
|
static std::string info_caption;
|
||||||
static std::string warn_caption;
|
static std::string warn_caption;
|
||||||
|
@ -241,6 +241,39 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
|
|||||||
_assert_((ptr - uid->values) == uid->GetNumValues());
|
_assert_((ptr - uid->values) == uid->GetNumValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::string& old_code, DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||||
|
{
|
||||||
|
PIXELSHADERUIDSAFE new_id;
|
||||||
|
GetSafePixelShaderId(&new_id, dstAlphaMode);
|
||||||
|
|
||||||
|
if (!(old_id == new_id))
|
||||||
|
{
|
||||||
|
std::string new_code(GeneratePixelShaderCode(dstAlphaMode, api, components));
|
||||||
|
if (old_code != new_code)
|
||||||
|
{
|
||||||
|
_assert_(old_id.GetNumValues() == new_id.GetNumValues());
|
||||||
|
|
||||||
|
char msg[8192];
|
||||||
|
char* ptr = msg;
|
||||||
|
ptr += sprintf(ptr, "Pixel shader IDs matched but unique IDs did not!\nUnique IDs (old <-> new):\n");
|
||||||
|
const int N = new_id.GetNumValues();
|
||||||
|
for (int i = 0; i < N/2; ++i)
|
||||||
|
ptr += sprintf(ptr, "%02d, %08X %08X | %08X %08X\n", 2*i, old_id.values[2*i], old_id.values[2*i+1],
|
||||||
|
new_id.values[2*i], new_id.values[2*i+1]);
|
||||||
|
if (N % 2)
|
||||||
|
ptr += sprintf(ptr, "%02d, %08X | %08X\n", N-1, old_id.values[N-1], new_id.values[N-1]);
|
||||||
|
|
||||||
|
static int num_failures = 0;
|
||||||
|
char szTemp[MAX_PATH];
|
||||||
|
sprintf(szTemp, "%spsuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
||||||
|
std::ofstream file(szTemp);
|
||||||
|
file << msg;
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
PanicAlert("Unique pixel shader ID mismatch!\n\nReport this to the devs, along with the contents of %s.", szTemp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// old tev->pixelshader notes
|
// old tev->pixelshader notes
|
||||||
//
|
//
|
||||||
|
@ -123,6 +123,9 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
|||||||
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode);
|
void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode);
|
||||||
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode);
|
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
|
||||||
|
void ValidatePixelShaderIDs(API_TYPE api, PIXELSHADERUIDSAFE old_id, const std::string& old_code, DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
|
|
||||||
extern PIXELSHADERUID last_pixel_shader_uid;
|
extern PIXELSHADERUID last_pixel_shader_uid;
|
||||||
|
|
||||||
#endif // GCOGL_PIXELSHADER_H
|
#endif // GCOGL_PIXELSHADER_H
|
||||||
|
@ -90,6 +90,42 @@ void GetSafeVertexShaderId(VERTEXSHADERUIDSAFE *uid, u32 components)
|
|||||||
_assert_((ptr - uid->values) == uid->GetNumValues());
|
_assert_((ptr - uid->values) == uid->GetNumValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ValidateVertexShaderIDs(API_TYPE api, VERTEXSHADERUIDSAFE old_id, const std::string& old_code, u32 components)
|
||||||
|
{
|
||||||
|
VERTEXSHADERUIDSAFE new_id;
|
||||||
|
GetSafeVertexShaderId(&new_id, components);
|
||||||
|
|
||||||
|
if (!(old_id == new_id))
|
||||||
|
{
|
||||||
|
std::string new_code(GenerateVertexShaderCode(components, api));
|
||||||
|
if (old_code != new_code)
|
||||||
|
{
|
||||||
|
_assert_(old_id.GetNumValues() == new_id.GetNumValues());
|
||||||
|
|
||||||
|
char msg[8192];
|
||||||
|
char* ptr = msg;
|
||||||
|
ptr += sprintf(ptr, "Vertex shader IDs matched but unique IDs did not!\nUnique IDs (old <-> new):\n");
|
||||||
|
const int N = new_id.GetNumValues();
|
||||||
|
for (int i = 0; i < N/2; ++i)
|
||||||
|
ptr += sprintf(ptr, "%02d, %08X %08X | %08X %08X\n", 2*i, old_id.values[2*i], old_id.values[2*i+1],
|
||||||
|
new_id.values[2*i], new_id.values[2*i+1]);
|
||||||
|
if (N % 2)
|
||||||
|
ptr += sprintf(ptr, "%02d, %08X | %08X\n", N-1, old_id.values[N-1], new_id.values[N-1]);
|
||||||
|
|
||||||
|
static int num_failures = 0;
|
||||||
|
char szTemp[MAX_PATH];
|
||||||
|
sprintf(szTemp, "%svsuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
||||||
|
std::ofstream file(szTemp);
|
||||||
|
file << msg;
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
PanicAlert("Unique pixel shader ID mismatch!\n\nReport this to the devs, along with the contents of %s.", szTemp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static char text[16384];
|
static char text[16384];
|
||||||
|
|
||||||
#define WRITE p+=sprintf
|
#define WRITE p+=sprintf
|
||||||
|
@ -109,9 +109,13 @@ typedef _VERTEXSHADERUID<true> VERTEXSHADERUIDSAFE;
|
|||||||
// components is included in the uid.
|
// components is included in the uid.
|
||||||
char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE api_type);
|
char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE api_type);
|
||||||
const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type);
|
const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type);
|
||||||
|
|
||||||
void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components);
|
void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components);
|
||||||
void GetSafeVertexShaderId(VERTEXSHADERUIDSAFE *uid, u32 components);
|
void GetSafeVertexShaderId(VERTEXSHADERUIDSAFE *uid, u32 components);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
extern VERTEXSHADERUID last_vertex_shader_uid;
|
extern VERTEXSHADERUID last_vertex_shader_uid;
|
||||||
|
|
||||||
#endif // GCOGL_VERTEXSHADER_H
|
#endif // GCOGL_VERTEXSHADER_H
|
||||||
|
@ -461,6 +461,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
|||||||
{
|
{
|
||||||
PSCache::const_iterator iter = PixelShaders.find(uid);
|
PSCache::const_iterator iter = PixelShaders.find(uid);
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
|
||||||
|
ValidatePixelShaderIDs(API_D3D11, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components);
|
||||||
return (iter != PixelShaders.end() && iter->second.shader);
|
return (iter != PixelShaders.end() && iter->second.shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,6 +477,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
|||||||
last_entry = &entry;
|
last_entry = &entry;
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
|
||||||
|
ValidatePixelShaderIDs(API_D3D11, entry.safe_uid, entry.code, dstAlphaMode, components);
|
||||||
return (entry.shader != NULL);
|
return (entry.shader != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,10 +496,17 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
|||||||
g_ps_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
|
g_ps_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
|
||||||
g_ps_disk_cache.Sync();
|
g_ps_disk_cache.Sync();
|
||||||
|
|
||||||
bool result = InsertByteCode(uid, pbytecode->Data(), pbytecode->Size());
|
bool success = InsertByteCode(uid, pbytecode->Data(), pbytecode->Size());
|
||||||
pbytecode->Release();
|
pbytecode->Release();
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
PixelShaders[uid].code = code;
|
||||||
|
GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode);
|
||||||
|
}
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
return result;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const void* bytecode, unsigned int bytecodelen)
|
bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const void* bytecode, unsigned int bytecodelen)
|
||||||
|
@ -55,6 +55,9 @@ private:
|
|||||||
ID3D11PixelShader* shader;
|
ID3D11PixelShader* shader;
|
||||||
int frameCount;
|
int frameCount;
|
||||||
|
|
||||||
|
PIXELSHADERUIDSAFE safe_uid;
|
||||||
|
std::string code;
|
||||||
|
|
||||||
PSCacheEntry() : shader(NULL), frameCount(0) {}
|
PSCacheEntry() : shader(NULL), frameCount(0) {}
|
||||||
void Destroy() { SAFE_RELEASE(shader); }
|
void Destroy() { SAFE_RELEASE(shader); }
|
||||||
};
|
};
|
||||||
|
@ -205,6 +205,7 @@ bool VertexShaderCache::SetShader(u32 components)
|
|||||||
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
|
ValidateVertexShaderIDs(API_D3D11, vshaders[uid].safe_uid, vshaders[uid].code, components);
|
||||||
return (vshaders[uid].shader != NULL);
|
return (vshaders[uid].shader != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +219,7 @@ bool VertexShaderCache::SetShader(u32 components)
|
|||||||
last_entry = &entry;
|
last_entry = &entry;
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
|
ValidateVertexShaderIDs(API_D3D11, entry.safe_uid, entry.code, components);
|
||||||
return (entry.shader != NULL);
|
return (entry.shader != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,10 +237,17 @@ bool VertexShaderCache::SetShader(u32 components)
|
|||||||
g_vs_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
|
g_vs_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
|
||||||
g_vs_disk_cache.Sync();
|
g_vs_disk_cache.Sync();
|
||||||
|
|
||||||
bool result = InsertByteCode(uid, pbytecode);
|
bool success = InsertByteCode(uid, pbytecode);
|
||||||
pbytecode->Release();
|
pbytecode->Release();
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
vshaders[uid].code = code;
|
||||||
|
GetSafeVertexShaderId(&vshaders[uid].safe_uid, components);
|
||||||
|
}
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
return result;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcodeblob)
|
bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcodeblob)
|
||||||
|
@ -53,6 +53,9 @@ private:
|
|||||||
D3DBlob* bytecode; // needed to initialize the input layout
|
D3DBlob* bytecode; // needed to initialize the input layout
|
||||||
int frameCount;
|
int frameCount;
|
||||||
|
|
||||||
|
VERTEXSHADERUIDSAFE safe_uid;
|
||||||
|
std::string code;
|
||||||
|
|
||||||
VSCacheEntry() : shader(NULL), bytecode(NULL), frameCount(0) {}
|
VSCacheEntry() : shader(NULL), bytecode(NULL), frameCount(0) {}
|
||||||
void SetByteCode(D3DBlob* blob)
|
void SetByteCode(D3DBlob* blob)
|
||||||
{
|
{
|
||||||
|
@ -334,6 +334,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
|||||||
{
|
{
|
||||||
PSCache::const_iterator iter = PixelShaders.find(uid);
|
PSCache::const_iterator iter = PixelShaders.find(uid);
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
ValidatePixelShaderIDs(API_D3D9, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components);
|
||||||
return (iter != PixelShaders.end() && iter->second.shader);
|
return (iter != PixelShaders.end() && iter->second.shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,11 +351,11 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
|||||||
|
|
||||||
if (entry.shader) D3D::SetPixelShader(entry.shader);
|
if (entry.shader) D3D::SetPixelShader(entry.shader);
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
ValidatePixelShaderIDs(API_D3D9, entry.safe_uid, entry.code, dstAlphaMode, components);
|
||||||
return (entry.shader != NULL);
|
return (entry.shader != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Need to compile a new shader
|
// Need to compile a new shader
|
||||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, ((D3D::GetCaps().PixelShaderVersion >> 8) & 0xFF) < 3 ? API_D3D9_SM20 : API_D3D9_SM30, components);
|
const char *code = GeneratePixelShaderCode(dstAlphaMode, ((D3D::GetCaps().PixelShaderVersion >> 8) & 0xFF) < 3 ? API_D3D9_SM20 : API_D3D9_SM30, components);
|
||||||
|
|
||||||
@ -384,11 +385,17 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
|||||||
g_ps_disk_cache.Sync();
|
g_ps_disk_cache.Sync();
|
||||||
|
|
||||||
// And insert it into the shader cache.
|
// And insert it into the shader cache.
|
||||||
bool result = InsertByteCode(uid, bytecode, bytecodelen, true);
|
bool success = InsertByteCode(uid, bytecode, bytecodelen, true);
|
||||||
delete [] bytecode;
|
delete [] bytecode;
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
PixelShaders[uid].code = code;
|
||||||
|
GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode);
|
||||||
|
}
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
return result;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate)
|
bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate)
|
||||||
|
@ -42,6 +42,9 @@ private:
|
|||||||
bool owns_shader;
|
bool owns_shader;
|
||||||
int frameCount;
|
int frameCount;
|
||||||
|
|
||||||
|
PIXELSHADERUIDSAFE safe_uid;
|
||||||
|
std::string code;
|
||||||
|
|
||||||
PSCacheEntry() : shader(NULL), owns_shader(true), frameCount(0) {}
|
PSCacheEntry() : shader(NULL), owns_shader(true), frameCount(0) {}
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
|
@ -187,6 +187,7 @@ bool VertexShaderCache::SetShader(u32 components)
|
|||||||
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
|
ValidateVertexShaderIDs(API_D3D9, vshaders[uid].safe_uid, vshaders[uid].code, components);
|
||||||
return (vshaders[uid].shader != NULL);
|
return (vshaders[uid].shader != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +202,7 @@ bool VertexShaderCache::SetShader(u32 components)
|
|||||||
|
|
||||||
if (entry.shader) D3D::SetVertexShader(entry.shader);
|
if (entry.shader) D3D::SetVertexShader(entry.shader);
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
|
ValidateVertexShaderIDs(API_D3D9, entry.safe_uid, entry.code, components);
|
||||||
return (entry.shader != NULL);
|
return (entry.shader != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,10 +217,15 @@ bool VertexShaderCache::SetShader(u32 components)
|
|||||||
g_vs_disk_cache.Append(uid, bytecode, bytecodelen);
|
g_vs_disk_cache.Append(uid, bytecode, bytecodelen);
|
||||||
g_vs_disk_cache.Sync();
|
g_vs_disk_cache.Sync();
|
||||||
|
|
||||||
bool result = InsertByteCode(uid, bytecode, bytecodelen, true);
|
bool success = InsertByteCode(uid, bytecode, bytecodelen, true);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
vshaders[uid].code = code;
|
||||||
|
GetSafeVertexShaderId(&vshaders[uid].safe_uid, components);
|
||||||
|
}
|
||||||
delete [] bytecode;
|
delete [] bytecode;
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
return result;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate) {
|
bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate) {
|
||||||
|
@ -35,9 +35,10 @@ private:
|
|||||||
{
|
{
|
||||||
LPDIRECT3DVERTEXSHADER9 shader;
|
LPDIRECT3DVERTEXSHADER9 shader;
|
||||||
int frameCount;
|
int frameCount;
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
//#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
std::string code;
|
std::string code;
|
||||||
#endif
|
VERTEXSHADERUIDSAFE safe_uid;
|
||||||
|
//#endif
|
||||||
VSCacheEntry() : shader(NULL), frameCount(0) {}
|
VSCacheEntry() : shader(NULL), frameCount(0) {}
|
||||||
void Destroy()
|
void Destroy()
|
||||||
{
|
{
|
||||||
|
@ -184,30 +184,13 @@ void PixelShaderCache::Shutdown()
|
|||||||
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
|
||||||
{
|
{
|
||||||
PIXELSHADERUID uid;
|
PIXELSHADERUID uid;
|
||||||
PIXELSHADERUIDSAFE safe_uid;
|
|
||||||
GetPixelShaderId(&uid, dstAlphaMode);
|
GetPixelShaderId(&uid, dstAlphaMode);
|
||||||
GetSafePixelShaderId(&safe_uid, dstAlphaMode);
|
|
||||||
|
|
||||||
// Check if the shader is already set - TODO: Use pShaderLast instead of PixelShaders[uid]?
|
// Check if the shader is already set - TODO: Use pShaderLast instead of PixelShaders[uid]?
|
||||||
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount)
|
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
|
ValidatePixelShaderIDs(API_OPENGL, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components);
|
||||||
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;
|
return pShaderLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,35 +203,19 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
|
|||||||
iter->second.frameCount = frameCount;
|
iter->second.frameCount = frameCount;
|
||||||
PSCacheEntry &entry = iter->second;
|
PSCacheEntry &entry = iter->second;
|
||||||
if (&entry.shader != pShaderLast)
|
if (&entry.shader != pShaderLast)
|
||||||
{
|
|
||||||
pShaderLast = &entry.shader;
|
pShaderLast = &entry.shader;
|
||||||
}
|
|
||||||
|
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
||||||
if (!(safe_uid == entry.safe_uid))
|
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.code, dstAlphaMode, components);
|
||||||
{
|
|
||||||
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;
|
return pShaderLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make an entry in the table
|
// Make an entry in the table
|
||||||
PSCacheEntry& newentry = PixelShaders[uid];
|
PSCacheEntry& newentry = PixelShaders[uid];
|
||||||
newentry.frameCount = frameCount;
|
newentry.frameCount = frameCount;
|
||||||
newentry.safe_uid = safe_uid;
|
|
||||||
pShaderLast = &newentry.shader;
|
pShaderLast = &newentry.shader;
|
||||||
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
|
||||||
|
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode);
|
||||||
newentry.code = code;
|
newentry.code = code;
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
|
@ -77,6 +77,7 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
|||||||
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount)
|
||||||
{
|
{
|
||||||
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
|
||||||
|
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
|
||||||
return pShaderLast;
|
return pShaderLast;
|
||||||
}
|
}
|
||||||
memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID));
|
memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID));
|
||||||
@ -86,11 +87,11 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
|
|||||||
{
|
{
|
||||||
iter->second.frameCount = frameCount;
|
iter->second.frameCount = frameCount;
|
||||||
VSCacheEntry &entry = iter->second;
|
VSCacheEntry &entry = iter->second;
|
||||||
if (&entry.shader != pShaderLast) {
|
if (&entry.shader != pShaderLast)
|
||||||
pShaderLast = &entry.shader;
|
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);
|
||||||
return pShaderLast;
|
return pShaderLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,9 +183,9 @@ bool VertexShaderCache::CompileVertexShader(VERTEXSHADER& vs, const char* pstrpr
|
|||||||
cgDestroyProgram(tempprog);
|
cgDestroyProgram(tempprog);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
//#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
vs.strprog = pstrprogram;
|
vs.strprog = pstrprogram;
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ struct VERTEXSHADER
|
|||||||
VERTEXSHADER() : glprogid(0) {}
|
VERTEXSHADER() : glprogid(0) {}
|
||||||
GLuint glprogid; // opengl program id
|
GLuint glprogid; // opengl program id
|
||||||
|
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
//#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
std::string strprog;
|
std::string strprog;
|
||||||
#endif
|
//#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class VertexShaderCache
|
class VertexShaderCache
|
||||||
@ -42,6 +42,7 @@ class VertexShaderCache
|
|||||||
struct VSCacheEntry
|
struct VSCacheEntry
|
||||||
{
|
{
|
||||||
VERTEXSHADER shader;
|
VERTEXSHADER shader;
|
||||||
|
VERTEXSHADERUIDSAFE safe_uid;
|
||||||
int frameCount;
|
int frameCount;
|
||||||
VSCacheEntry() : frameCount(0) {}
|
VSCacheEntry() : frameCount(0) {}
|
||||||
void Destroy() {
|
void Destroy() {
|
||||||
|
Reference in New Issue
Block a user