summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2011-12-10 15:40:10 -0600
committerSonicadvance1 <sonicadvance1@RH-Live.(none)>2012-10-09 23:41:06 -0500
commit5b06bbf87d75cb3d06dfae6c58c05ade0374a676 (patch)
tree8f7b7f6fe9f0cfdc518230ab642d03c5e581a402 /Source
parent5bcbf92f439663900a8fe60c1fee4eea2d96a192 (diff)
Use UBOs in every shader. I had missed a few. Only cache Uniform locations if we aren't using UBOs.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/VideoCommon/Src/TextureConversionShader.cpp29
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp54
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp8
-rw-r--r--Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp6
4 files changed, 73 insertions, 24 deletions
diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
index e4638f8b16..33c6bca038 100644
--- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
+++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp
@@ -74,6 +74,14 @@ const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
sprintf(result, " : register(%s%d)", prefix, num);
return result;
}
+const char *WriteLocation(API_TYPE ApiType)
+{
+ if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ return "";
+ static char result[64];
+ sprintf(result, "uniform ");
+ return result;
+}
// block dimensions : widthStride, heightStride
// texture dims : width, height, x offset, y offset
@@ -82,7 +90,13 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
- WRITE(p, "uniform float4 "I_COLORS"[2] %s;\n", WriteRegister(ApiType, "c", C_COLORS));
+ if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
+
+ WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
+
+ if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
@@ -168,7 +182,11 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
- WRITE(p, "uniform float4 "I_COLORS"[2] %s;\n", WriteRegister(ApiType, "c", C_COLORS));
+ if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
+ WRITE(p, "%sfloat4 "I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
+ if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
@@ -839,10 +857,13 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
if(ApiType == API_GLSL)
{
// A few required defines and ones that will make our lives a lot easier
- if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
WRITE(p, "#version 330 compatibility\n");
- WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
+ WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
+ if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
}
else
WRITE(p, "#version 120\n");
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
index ff3196fa41..4e5fa9c66f 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp
@@ -120,7 +120,9 @@ void PixelShaderCache::Init()
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
- "uniform vec4 "I_COLORS"[7];\n"
+ "%s\n"
+ "%svec4 "I_COLORS"[7];\n"
+ "%s\n"
"void main(){\n"
"vec4 Temp0, Temp1;\n"
"vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
@@ -134,14 +136,20 @@ void PixelShaderCache::Init()
"Temp1.z = dot(Temp0, "I_COLORS"[%d]);\n"
"Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
"gl_FragData[0] = Temp1 + "I_COLORS"[%d];\n"
- "}\n", C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+ "}\n",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140, binding = 1) uniform PSBlock {" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
+ C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
}
else
{
sprintf(pmatrixprog, "#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
- "uniform vec4 "I_COLORS"[7];\n"
+ "%s\n"
+ "%svec4 "I_COLORS"[7];\n"
+ "%s\n"
"void main(){\n"
"vec4 Temp0, Temp1;\n"
"vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\n"
@@ -155,9 +163,13 @@ void PixelShaderCache::Init()
"Temp1.z = dot(Temp0, "I_COLORS"[%d]);\n"
"Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
"gl_FragData[0] = Temp1 + "I_COLORS"[%d];\n"
- "}\n", C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+ "}\n",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
+ C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
}
- if (!pCompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
+ if (!PixelShaderCache::CompilePixelShader(s_ColorMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
s_ColorMatrixProgram.Destroy();
@@ -168,7 +180,9 @@ void PixelShaderCache::Init()
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
- "uniform vec4 "I_COLORS"[5];\n"
+ "%s\n"
+ "%svec4 "I_COLORS"[5];\n"
+ "%s\n"
"void main(){\n"
"vec4 R0, R1, R2;\n"
"vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
@@ -192,14 +206,20 @@ void PixelShaderCache::Init()
"R1.z = dot(R0, "I_COLORS"[%d]);\n"
"R1.w = dot(R0, "I_COLORS"[%d]);\n"
"gl_FragData[0] = R1 * "I_COLORS"[%d];\n"
- "}\n", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+ "}\n",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140, binding = 1) uniform PSBlock {" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
+ C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
}
else
{
sprintf(pmatrixprog, "#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
- "uniform vec4 "I_COLORS"[5];\n"
+ "%s\n"
+ "%svec4 "I_COLORS"[5];\n"
+ "%s\n"
"void main(){\n"
"vec4 R0, R1, R2;\n"
"vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\n"
@@ -223,9 +243,13 @@ void PixelShaderCache::Init()
"R1.z = dot(R0, "I_COLORS"[%d]);\n"
"R1.w = dot(R0, "I_COLORS"[%d]);\n"
"gl_FragData[0] = R1 * "I_COLORS"[%d];\n"
- "}\n", C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
+ "}\n",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
+ g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
+ C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
}
- if (!pCompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
+ if (!PixelShaderCache::CompilePixelShader(s_DepthMatrixProgram, pmatrixprog))
{
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
s_DepthMatrixProgram.Destroy();
@@ -444,9 +468,9 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
GLsizei charsWritten;
GLchar* infoLog = new GLchar[length];
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
- WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog);
+ WARN_LOG(VIDEO, "PS Shader info log:\n%s", infoLog);
char szTemp[MAX_PATH];
- sprintf(szTemp, "vs_%d.txt", result);
+ sprintf(szTemp, "ps_%d.txt", result);
FILE *fp = fopen(szTemp, "wb");
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
fclose(fp);
@@ -503,7 +527,7 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
ProgramShaderCache::SetUniformObjects(0, const_number, f);
- //return;
+ return;
}
for (unsigned int a = 0; a < 10; ++a)
{
@@ -521,7 +545,7 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
ProgramShaderCache::SetUniformObjects(0, const_number, f);
- //return;
+ return;
}
for (unsigned int a = 0; a < 10; ++a)
{
@@ -539,7 +563,7 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
ProgramShaderCache::SetUniformObjects(0, const_number, f, count);
- //return;
+ return;
}
for (unsigned int a = 0; a < 10; ++a)
{
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
index 37923d2f47..562843ebb1 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp
@@ -111,8 +111,9 @@ namespace OGL
//For some reason this fails on my hardware
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
//Got to do it this crappy way.
- for(int a = 0; a < NUM_UNIFORMS; ++a)
- entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
+ if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
+ for(int a = 0; a < NUM_UNIFORMS; ++a)
+ entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
// Need to get some attribute locations
if(uid.uid.vsid != 0) // We have no vertex Shader
@@ -176,7 +177,7 @@ namespace OGL
// Repeat for VS shader
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]);
- glBufferData(GL_UNIFORM_BUFFER, 1024*1024, NULL, GL_DYNAMIC_DRAW);
+ glBufferData(GL_UNIFORM_BUFFER, 1024 * 1024, NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]);
}
void ProgramShaderCache::Shutdown(void)
@@ -185,6 +186,7 @@ namespace OGL
for (; iter != pshaders.end(); iter++)
iter->second.Destroy();
pshaders.clear();
+ glDeleteBuffers(2, UBOBuffers);
}
}
diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
index 6a5becae7b..bfee0c193c 100644
--- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
+++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp
@@ -488,8 +488,10 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
}
glViewport(0, 0, srcWidth, srcHeight);
-
- PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
+ if(g_ActiveConfig.bUseGLSL)
+ ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
+ else
+ PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
GL_REPORT_ERRORD();