Use UBOs in every shader. I had missed a few. Only cache Uniform locations if we aren't using UBOs.
This commit is contained in:
parent
c72a244809
commit
97c3c156e6
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -579,8 +579,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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue