diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index b963912443..977de656d6 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -518,7 +518,7 @@ const char* WriteBinding(API_TYPE ApiType, const u32 num) } const char *WriteLocation(API_TYPE ApiType) { - if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) + if(ApiType == API_GLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO) return ""; static char result[64]; sprintf(result, "uniform "); @@ -611,7 +611,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType WRITE(p, "\n"); if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) - WRITE(p, "layout(std140, binding = 0) uniform PSBlock {\n"); + WRITE(p, "layout(std140, binding = 1) uniform PSBlock {\n"); WRITE(p, "%sfloat4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS)); WRITE(p, "%sfloat4 "I_KCOLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_KCOLORS)); diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index c693a7b06b..8b945af530 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -166,12 +166,6 @@ char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType) extern const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num); extern const char* WriteBinding(API_TYPE ApiType, const u32 num); const char *WriteLocation(API_TYPE ApiType); -const char *WriteLocation2(API_TYPE ApiType) -{ - static char result[64]; - sprintf(result, "uniform "); - return result; -} const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) { @@ -222,20 +216,21 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) } // uniforms - //if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) - //WRITE(p, "layout(std140, binding = 2) uniform VSBlock {\n"); + if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) + WRITE(p, "layout(std140, binding = 2) uniform VSBlock {\n"); - WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX)); - //if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) - //WRITE(p, "};\n"); - WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_PROJECTION)); - WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_MATERIALS)); - WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_LIGHTS)); - WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices - WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_TRANSFORMMATRICES)); - WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES)); - WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES)); - WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation2(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS)); + WRITE(p, "%sfloat4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX)); + WRITE(p, "%sfloat4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PROJECTION)); + WRITE(p, "%sfloat4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_MATERIALS)); + WRITE(p, "%sfloat4 "I_LIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_LIGHTS)); + WRITE(p, "%sfloat4 "I_TEXMATRICES"[24] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_TEXMATRICES)); // also using tex matrices + WRITE(p, "%sfloat4 "I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType),WriteRegister(ApiType, "c", C_TRANSFORMMATRICES)); + WRITE(p, "%sfloat4 "I_NORMALMATRICES"[32] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_NORMALMATRICES)); + WRITE(p, "%sfloat4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES)); + WRITE(p, "%sfloat4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS)); + + if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO) + WRITE(p, "};\n"); diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index 939e751f55..5a12392ed2 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -173,7 +173,7 @@ void VertexShaderManager::Dirty() // TODO: A cleaner way to control the matricies without making a mess in the parameters field void VertexShaderManager::SetConstants() { - //if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO) + if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO) Dirty(); if (nTransformMatricesChanged[0] >= 0) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index c957ccd894..4172237bb2 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -429,24 +429,6 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) glShaderSource(result, 1, &pstrprogram, NULL); glCompileShader(result); - GLsizei length = 0; - - glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length); - if (length > 0) - { - GLsizei charsWritten; - GLchar* infoLog = new GLchar[length]; - glGetShaderInfoLog(result, length, &charsWritten, infoLog); - WARN_LOG(VIDEO, "PS Shader info log:\n%s", infoLog); - char szTemp[MAX_PATH]; - sprintf(szTemp, "ps_%d.txt", result); - FILE *fp = fopen(szTemp, "wb"); - fwrite(pstrprogram, strlen(pstrprogram), 1, fp); - fclose(fp); - if(strstr(infoLog, "warning") != NULL || strstr(infoLog, "error") != NULL) - exit(0); - delete[] infoLog; - } GLint compileStatus; glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus); @@ -454,6 +436,23 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) { // Compile failed ERROR_LOG(VIDEO, "Shader compilation failed; see info log"); + + GLsizei length = 0; + glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length); + if (length > 0) + { + GLsizei charsWritten; + GLchar* infoLog = new GLchar[length]; + glGetShaderInfoLog(result, length, &charsWritten, infoLog); + WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog); + char szTemp[MAX_PATH]; + sprintf(szTemp, "vs_%d.txt", result); + FILE *fp = fopen(szTemp, "wb"); + fwrite(pstrprogram, strlen(pstrprogram), 1, fp); + fclose(fp); + + delete[] infoLog; + } // Don't try to use this shader glDeleteShader(result); return false; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 4b1f8b28d2..073e8b430c 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -17,16 +17,6 @@ #include "ProgramShaderCache.h" #include -GLuint GLERR(const char *function) -{ - GLint err = glGetError(); - if (err != GL_NO_ERROR) - { - printf( "(%s) OpenGL error 0x%x - %s\n", - function, err, gluErrorString(err)); - } - return err; -} namespace OGL { GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0; @@ -101,19 +91,14 @@ namespace OGL glAttachShader(entry.program.glprogid, entry.program.psid); glLinkProgram(entry.program.glprogid); - GLsizei length = 0; - - glGetProgramiv(entry.program.glprogid, GL_INFO_LOG_LENGTH, &length); - if (length > 0) - { - GLsizei charsWritten; - GLchar* infoLog = new GLchar[length]; - glGetProgramInfoLog(entry.program.glprogid, length, &charsWritten, infoLog); - printf("Program info log:\n%s", infoLog); - delete[] infoLog; - } glUseProgram(entry.program.glprogid); + + // Dunno why this is needed when I have the binding + // points statically set in the shader source + // Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64 + glUniformBlockBinding( entry.program.glprogid, 0, 1 ); + glUniformBlockBinding( entry.program.glprogid, 1, 2 ); // We cache our uniform locations for now // Once we move up to a newer version of GLSL, ~1.30 @@ -148,13 +133,11 @@ namespace OGL } void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count) { - GLERR(""); assert(Buffer > 1); static int _Buffer = -1; if(_Buffer != Buffer) { _Buffer = Buffer; - GLERR("bind"); glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[_Buffer]); } // Query for the offsets of each block variable @@ -162,7 +145,6 @@ namespace OGL // glBufferSubData expects data in bytes, so multiply count by four // Expects the offset in bytes as well, so multiply by *4 *4 since we are passing in a vec4 location glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4 * 4, f); - GLERR("sub"); } GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; } @@ -179,7 +161,6 @@ namespace OGL { glGenBuffers(2, UBOBuffers); - glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[0]); // We multiply by *4*4 because we need to get down to basic machine units. // So multiply by four to get how many floats we have from vec4s @@ -187,13 +168,12 @@ namespace OGL glBufferData(GL_UNIFORM_BUFFER, C_PENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW); // Now bind the buffer to the index point // We know PS is 0 since we have it statically set in the shader - glBindBufferBase(GL_UNIFORM_BUFFER, 0, UBOBuffers[0]); + glBindBufferBase(GL_UNIFORM_BUFFER, 1, UBOBuffers[0]); // Repeat for VS shader - //glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]); - //glBufferData(GL_UNIFORM_BUFFER, C_PENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW); - //glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]); - GLERR("init"); + glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]); + glBufferData(GL_UNIFORM_BUFFER, 1024*1024, NULL, GL_DYNAMIC_DRAW); + glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]); } void ProgramShaderCache::Shutdown(void) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index 0550e99b18..97dfc9a3bb 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -189,25 +189,6 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram) glShaderSource(result, 1, &pstrprogram, NULL); glCompileShader(result); - GLsizei length = 0; - - glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length); - if (length > 0) - { - GLsizei charsWritten; - GLchar* infoLog = new GLchar[length]; - glGetShaderInfoLog(result, length, &charsWritten, infoLog); - WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog); - char szTemp[MAX_PATH]; - sprintf(szTemp, "vs_%d.txt", result); - FILE *fp = fopen(szTemp, "wb"); - fwrite(pstrprogram, strlen(pstrprogram), 1, fp); - fclose(fp); - - if(strstr(infoLog, "warning") != NULL || strstr(infoLog, "error") != NULL) - exit(0); - delete[] infoLog; - } GLint compileStatus; glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus); @@ -215,6 +196,23 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram) { // Compile failed ERROR_LOG(VIDEO, "Shader compilation failed; see info log"); + + GLsizei length = 0; + glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length); + if (length > 0) + { + GLsizei charsWritten; + GLchar* infoLog = new GLchar[length]; + glGetShaderInfoLog(result, length, &charsWritten, infoLog); + WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog); + char szTemp[MAX_PATH]; + sprintf(szTemp, "vs_%d.txt", result); + FILE *fp = fopen(szTemp, "wb"); + fwrite(pstrprogram, strlen(pstrprogram), 1, fp); + fclose(fp); + + delete[] infoLog; + } // Don't try to use this shader glDeleteShader(result); return false; @@ -240,7 +238,6 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float } } } -#define MAX_UNIFORM 0 void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) { float buf[4]; @@ -250,9 +247,8 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3 buf[3] = f4; if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { - if(const_number < MAX_UNIFORM) - ProgramShaderCache::SetUniformObjects(1, const_number, buf); - //return; + ProgramShaderCache::SetUniformObjects(1, const_number, buf); + return; } for( unsigned int a = 0; a < 9; ++a) { @@ -269,9 +265,8 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f) { if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { - if(const_number < MAX_UNIFORM) ProgramShaderCache::SetUniformObjects(1, const_number, f); - //return; + return; } for( unsigned int a = 0; a < 9; ++a) { @@ -288,9 +283,8 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co { if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { - if(const_number < MAX_UNIFORM) ProgramShaderCache::SetUniformObjects(1, const_number, f, count); - //return; + return; } for( unsigned int a = 0; a < 9; ++a) { @@ -315,9 +309,8 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co } if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) { - if(const_number < MAX_UNIFORM) ProgramShaderCache::SetUniformObjects(1, const_number, buf, count); - //return; + return; } for( unsigned int a = 0; a < 9; ++a) {