From 41c4108ce66d73b81c254165f18a23f72aabf09a Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 29 Mar 2013 14:54:44 +0100 Subject: OpenGL: Reimplement shader uid debugging. --- .../Plugin_VideoOGL/Src/ProgramShaderCache.cpp | 64 +++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp') diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 53b0210919..6ce4e1e04c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -23,6 +23,9 @@ #include "ImageWrite.h" #include "Render.h" +#include +#include + namespace OGL { @@ -353,14 +356,71 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code ) return result; } +template UidT GetPartialUid(const SHADERUID& uid); +template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; } +template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; } + +template const std::string& GetShaderCode(const SHADER& shader); +template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strpprog; } +template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strvprog; } + +template +void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid) +{ + static std::map s_shaders; + static std::vector s_uids; + + bool uid_is_indexed = std::find(s_uids.begin(), s_uids.end(), new_uid) != s_uids.end(); + if (!uid_is_indexed) + { + s_uids.push_back(new_uid); + s_shaders[new_uid] = new_code.GetBuffer(); + } + else + { + // uid is already in the index => check if there's a shader with the same uid but different code + auto& old_code = s_shaders[new_uid]; + if (strcmp(old_code.c_str(), new_code.GetBuffer()) != 0) + { + static int num_failures = 0; + + char szTemp[MAX_PATH]; + sprintf(szTemp, "%s%ssuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), + std::is_same::value ? "p" : std::is_same::value ? "v" : "o", + ++num_failures); + + // TODO: Should also dump uids + std::ofstream file; + OpenFStream(file, szTemp, std::ios_base::out); + file << "Old shader code:\n" << old_code; + file << "\n\nNew shader code:\n" << new_code.GetBuffer(); + file.close(); + + // TODO: Make this more idiot-proof + ERROR_LOG(VIDEO, "%s shader uid mismatch!", + std::is_same::value ? "Pixel" : std::is_same::value ? "Vertex" : "Other"); + } + } +} -void ProgramShaderCache::GetShaderId ( SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 components ) +void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 components) { GetPixelShaderUid(uid->puid, dstAlphaMode, API_OPENGL, components); GetVertexShaderUid(uid->vuid, components, API_OPENGL); -} + if (g_ActiveConfig.bEnableShaderDebugging) + { + PixelShaderCode pcode; + VertexShaderCode vcode; + + GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components); + GenerateVertexShaderCode(vcode, components, API_OPENGL); + + CheckForUidMismatch(pshaders, pcode, uid->puid); + CheckForUidMismatch(pshaders, vcode, uid->vuid); + } +} ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram(void) -- cgit v1.2.3 From 4e9c3db545b2ff9dc4469f3440dc6caffd3f1832 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 29 Mar 2013 15:02:48 +0100 Subject: OSX build fix. --- Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp') diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 6ce4e1e04c..79bcc1abbd 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -24,7 +24,7 @@ #include "Render.h" #include -#include +#include namespace OGL { @@ -386,7 +386,7 @@ void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_cod char szTemp[MAX_PATH]; sprintf(szTemp, "%s%ssuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), - std::is_same::value ? "p" : std::is_same::value ? "v" : "o", + (typeid(UidT) == typeid(PixelShaderUid)) ? "p" : (typeid(UidT) == typeid(VertexShaderUid)) ? "v" : "o", ++num_failures); // TODO: Should also dump uids @@ -398,7 +398,7 @@ void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_cod // TODO: Make this more idiot-proof ERROR_LOG(VIDEO, "%s shader uid mismatch!", - std::is_same::value ? "Pixel" : std::is_same::value ? "Vertex" : "Other"); + (typeid(UidT) == typeid(PixelShaderUid)) ? "Pixel" : (typeid(UidT) == typeid(VertexShaderUid)) ? "Vertex" : "Other"); } } } -- cgit v1.2.3 From 3c02f227db1e02f233f3aac8dc42476bd0b17f7a Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 29 Mar 2013 20:33:28 +0100 Subject: PixelShaderManager: Disable constant cache (won't work in the non-UBO path of the opengl backend). ShaderGen: Replace typeid usage with more general code. --- Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp') diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 79bcc1abbd..188145ebcf 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -201,9 +201,9 @@ SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 componen return &last_entry->shader; } } - + last_uid = uid; - + // Check if shader is already in cache PCache::iterator iter = pshaders.find(uid); if (iter != pshaders.end()) @@ -215,17 +215,17 @@ SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 componen last_entry->shader.Bind(); return &last_entry->shader; } - + // Make an entry in the table PCacheEntry& newentry = pshaders[uid]; last_entry = &newentry; newentry.in_cache = 0; - + VertexShaderCode vcode; PixelShaderCode pcode; GenerateVertexShaderCode(vcode, components, API_OPENGL); GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components); - + if (g_ActiveConfig.bEnableShaderDebugging) { newentry.shader.strvprog = vcode.GetBuffer(); @@ -260,7 +260,7 @@ bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, cons { GLuint vsid = CompileSingleShader(GL_VERTEX_SHADER, vcode); GLuint psid = CompileSingleShader(GL_FRAGMENT_SHADER, pcode); - + if(!vsid || !psid) { glDeleteShader(vsid); -- cgit v1.2.3 From 2afd892e466e656a2dc623bb5d6574d0d6c5533a Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Fri, 29 Mar 2013 22:24:49 +0100 Subject: ShaderGen: More interface cleanups. Less wtfs :) --- Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp') diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 188145ebcf..81621d2d38 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -360,9 +360,9 @@ template UidT GetPartialUid(const SHADERUID& uid); template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; } template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; } -template const std::string& GetShaderCode(const SHADER& shader); -template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strpprog; } -template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strvprog; } +template const std::string& GetShaderCode(const SHADER& shader); +template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strpprog; } +template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strvprog; } template void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid) -- cgit v1.2.3 From ec08914905ca1c4fe3b2456a9cc037a3f7eedd49 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Wed, 10 Apr 2013 12:54:22 +0200 Subject: Move Shader UID mismatch checking to VideoCommon. --- .../Plugin_VideoOGL/Src/ProgramShaderCache.cpp | 64 ---------------------- 1 file changed, 64 deletions(-) (limited to 'Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp') diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 81621d2d38..0d571c29a9 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -23,9 +23,6 @@ #include "ImageWrite.h" #include "Render.h" -#include -#include - namespace OGL { @@ -356,73 +353,12 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code ) return result; } -template UidT GetPartialUid(const SHADERUID& uid); -template<> PixelShaderUid GetPartialUid(const SHADERUID& uid) { return uid.puid; } -template<> VertexShaderUid GetPartialUid(const SHADERUID& uid) { return uid.vuid; } - -template const std::string& GetShaderCode(const SHADER& shader); -template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strpprog; } -template<> const std::string& GetShaderCode(const SHADER& shader) { return shader.strvprog; } - -template -void CheckForUidMismatch(const ProgramShaderCache::PCache& cache, CodeT& new_code, const UidT& new_uid) -{ - static std::map s_shaders; - static std::vector s_uids; - - bool uid_is_indexed = std::find(s_uids.begin(), s_uids.end(), new_uid) != s_uids.end(); - if (!uid_is_indexed) - { - s_uids.push_back(new_uid); - s_shaders[new_uid] = new_code.GetBuffer(); - } - else - { - // uid is already in the index => check if there's a shader with the same uid but different code - auto& old_code = s_shaders[new_uid]; - if (strcmp(old_code.c_str(), new_code.GetBuffer()) != 0) - { - static int num_failures = 0; - - char szTemp[MAX_PATH]; - sprintf(szTemp, "%s%ssuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), - (typeid(UidT) == typeid(PixelShaderUid)) ? "p" : (typeid(UidT) == typeid(VertexShaderUid)) ? "v" : "o", - ++num_failures); - - // TODO: Should also dump uids - std::ofstream file; - OpenFStream(file, szTemp, std::ios_base::out); - file << "Old shader code:\n" << old_code; - file << "\n\nNew shader code:\n" << new_code.GetBuffer(); - file.close(); - - // TODO: Make this more idiot-proof - ERROR_LOG(VIDEO, "%s shader uid mismatch!", - (typeid(UidT) == typeid(PixelShaderUid)) ? "Pixel" : (typeid(UidT) == typeid(VertexShaderUid)) ? "Vertex" : "Other"); - } - } -} - - void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 components) { GetPixelShaderUid(uid->puid, dstAlphaMode, API_OPENGL, components); GetVertexShaderUid(uid->vuid, components, API_OPENGL); - - if (g_ActiveConfig.bEnableShaderDebugging) - { - PixelShaderCode pcode; - VertexShaderCode vcode; - - GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components); - GenerateVertexShaderCode(vcode, components, API_OPENGL); - - CheckForUidMismatch(pshaders, pcode, uid->puid); - CheckForUidMismatch(pshaders, vcode, uid->vuid); - } } - ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram(void) { return *last_entry; -- cgit v1.2.3 From 02afec507622d2fcf705f9147de21f081f77aaa5 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Mon, 29 Apr 2013 21:00:39 +0200 Subject: Polish shader uid checking. --- .../Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp') diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index bab52073fb..732c63ac67 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -29,6 +29,8 @@ static GLuint CurrentProgram = 0; ProgramShaderCache::PCache ProgramShaderCache::pshaders; ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry; SHADERUID ProgramShaderCache::last_uid; +UidChecker ProgramShaderCache::pixel_uid_checker; +UidChecker ProgramShaderCache::vertex_uid_checker; static char s_glsl_header[1024] = ""; @@ -351,6 +353,17 @@ void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, { GetPixelShaderUid(uid->puid, dstAlphaMode, API_OPENGL, components); GetVertexShaderUid(uid->vuid, components, API_OPENGL); + + if (g_ActiveConfig.bEnableShaderDebugging) + { + PixelShaderCode pcode; + GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components); + pixel_uid_checker.AddToIndexAndCheck(pcode, uid->puid, "Pixel", "p"); + + VertexShaderCode vcode; + GenerateVertexShaderCode(vcode, components, API_OPENGL); + vertex_uid_checker.AddToIndexAndCheck(vcode, uid->vuid, "Vertex", "v"); + } } ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram(void) @@ -448,6 +461,9 @@ void ProgramShaderCache::Shutdown(void) iter->second.Destroy(); pshaders.clear(); + pixel_uid_checker.Invalidate(); + vertex_uid_checker.Invalidate(); + if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { delete s_buffer; -- cgit v1.2.3