mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-19 09:32:38 +00:00
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
5bcbf92f43
commit
5b06bbf87d
4 changed files with 73 additions and 24 deletions
|
@ -74,6 +74,14 @@ const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
|
||||||
sprintf(result, " : register(%s%d)", prefix, num);
|
sprintf(result, " : register(%s%d)", prefix, num);
|
||||||
return result;
|
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
|
// block dimensions : widthStride, heightStride
|
||||||
// texture dims : width, height, x offset, y offset
|
// 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
|
// [0] left, top, right, bottom of source rectangle within source texture
|
||||||
// [1] width and height of destination texture in pixels
|
// [1] width and height of destination texture in pixels
|
||||||
// Two were merged for GLSL
|
// 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 blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
|
||||||
float blkH = (float)TexDecoder_GetBlockHeightInTexels(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
|
// [0] left, top, right, bottom of source rectangle within source texture
|
||||||
// [1] width and height of destination texture in pixels
|
// [1] width and height of destination texture in pixels
|
||||||
// Two were merged for GLSL
|
// 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 blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
|
||||||
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
|
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
|
||||||
|
@ -839,10 +857,13 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
|
||||||
if(ApiType == API_GLSL)
|
if(ApiType == API_GLSL)
|
||||||
{
|
{
|
||||||
// A few required defines and ones that will make our lives a lot easier
|
// 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, "#version 330 compatibility\n");
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||||
WRITE(p, "#extension GL_ARB_shading_language_420pack : enable\n");
|
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
|
else
|
||||||
WRITE(p, "#version 120\n");
|
WRITE(p, "#version 120\n");
|
||||||
|
|
|
@ -120,7 +120,9 @@ void PixelShaderCache::Init()
|
||||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||||
"layout(binding = 0) uniform sampler2DRect samp0;\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"
|
"void main(){\n"
|
||||||
"vec4 Temp0, Temp1;\n"
|
"vec4 Temp0, Temp1;\n"
|
||||||
"vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\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.z = dot(Temp0, "I_COLORS"[%d]);\n"
|
||||||
"Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
|
"Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
|
||||||
"gl_FragData[0] = Temp1 + "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
|
else
|
||||||
{
|
{
|
||||||
sprintf(pmatrixprog, "#version 120\n"
|
sprintf(pmatrixprog, "#version 120\n"
|
||||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||||
"uniform sampler2DRect samp0;\n"
|
"uniform sampler2DRect samp0;\n"
|
||||||
"uniform vec4 "I_COLORS"[7];\n"
|
"%s\n"
|
||||||
|
"%svec4 "I_COLORS"[7];\n"
|
||||||
|
"%s\n"
|
||||||
"void main(){\n"
|
"void main(){\n"
|
||||||
"vec4 Temp0, Temp1;\n"
|
"vec4 Temp0, Temp1;\n"
|
||||||
"vec4 K0 = vec4(0.5, 0.5, 0.5, 0.5);\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.z = dot(Temp0, "I_COLORS"[%d]);\n"
|
||||||
"Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
|
"Temp1.w = dot(Temp0, "I_COLORS"[%d]);\n"
|
||||||
"gl_FragData[0] = Temp1 + "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");
|
ERROR_LOG(VIDEO, "Failed to create color matrix fragment program");
|
||||||
s_ColorMatrixProgram.Destroy();
|
s_ColorMatrixProgram.Destroy();
|
||||||
|
@ -168,7 +180,9 @@ void PixelShaderCache::Init()
|
||||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||||
"layout(binding = 0) uniform sampler2DRect samp0;\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"
|
"void main(){\n"
|
||||||
"vec4 R0, R1, R2;\n"
|
"vec4 R0, R1, R2;\n"
|
||||||
"vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\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.z = dot(R0, "I_COLORS"[%d]);\n"
|
||||||
"R1.w = dot(R0, "I_COLORS"[%d]);\n"
|
"R1.w = dot(R0, "I_COLORS"[%d]);\n"
|
||||||
"gl_FragData[0] = R1 * "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
|
else
|
||||||
{
|
{
|
||||||
sprintf(pmatrixprog, "#version 120\n"
|
sprintf(pmatrixprog, "#version 120\n"
|
||||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||||
"uniform sampler2DRect samp0;\n"
|
"uniform sampler2DRect samp0;\n"
|
||||||
"uniform vec4 "I_COLORS"[5];\n"
|
"%s\n"
|
||||||
|
"%svec4 "I_COLORS"[5];\n"
|
||||||
|
"%s\n"
|
||||||
"void main(){\n"
|
"void main(){\n"
|
||||||
"vec4 R0, R1, R2;\n"
|
"vec4 R0, R1, R2;\n"
|
||||||
"vec4 K0 = vec4(255.99998474121, 0.003921568627451, 256.0, 0.0);\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.z = dot(R0, "I_COLORS"[%d]);\n"
|
||||||
"R1.w = dot(R0, "I_COLORS"[%d]);\n"
|
"R1.w = dot(R0, "I_COLORS"[%d]);\n"
|
||||||
"gl_FragData[0] = R1 * "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");
|
ERROR_LOG(VIDEO, "Failed to create depth matrix fragment program");
|
||||||
s_DepthMatrixProgram.Destroy();
|
s_DepthMatrixProgram.Destroy();
|
||||||
|
@ -444,9 +468,9 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||||
GLsizei charsWritten;
|
GLsizei charsWritten;
|
||||||
GLchar* infoLog = new GLchar[length];
|
GLchar* infoLog = new GLchar[length];
|
||||||
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
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];
|
char szTemp[MAX_PATH];
|
||||||
sprintf(szTemp, "vs_%d.txt", result);
|
sprintf(szTemp, "ps_%d.txt", result);
|
||||||
FILE *fp = fopen(szTemp, "wb");
|
FILE *fp = fopen(szTemp, "wb");
|
||||||
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
fwrite(pstrprogram, strlen(pstrprogram), 1, fp);
|
||||||
fclose(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)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetUniformObjects(0, const_number, f);
|
ProgramShaderCache::SetUniformObjects(0, const_number, f);
|
||||||
//return;
|
return;
|
||||||
}
|
}
|
||||||
for (unsigned int a = 0; a < 10; ++a)
|
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)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetUniformObjects(0, const_number, f);
|
ProgramShaderCache::SetUniformObjects(0, const_number, f);
|
||||||
//return;
|
return;
|
||||||
}
|
}
|
||||||
for (unsigned int a = 0; a < 10; ++a)
|
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)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetUniformObjects(0, const_number, f, count);
|
ProgramShaderCache::SetUniformObjects(0, const_number, f, count);
|
||||||
//return;
|
return;
|
||||||
}
|
}
|
||||||
for (unsigned int a = 0; a < 10; ++a)
|
for (unsigned int a = 0; a < 10; ++a)
|
||||||
{
|
{
|
||||||
|
|
|
@ -111,6 +111,7 @@ namespace OGL
|
||||||
//For some reason this fails on my hardware
|
//For some reason this fails on my hardware
|
||||||
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
|
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
|
||||||
//Got to do it this crappy way.
|
//Got to do it this crappy way.
|
||||||
|
if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||||
|
|
||||||
|
@ -185,6 +186,7 @@ namespace OGL
|
||||||
for (; iter != pshaders.end(); iter++)
|
for (; iter != pshaders.end(); iter++)
|
||||||
iter->second.Destroy();
|
iter->second.Destroy();
|
||||||
pshaders.clear();
|
pshaders.clear();
|
||||||
|
glDeleteBuffers(2, UBOBuffers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -488,7 +488,9 @@ void DecodeToTexture(u32 xfbAddr, int srcWidth, int srcHeight, GLuint destTextur
|
||||||
}
|
}
|
||||||
|
|
||||||
glViewport(0, 0, srcWidth, srcHeight);
|
glViewport(0, 0, srcWidth, srcHeight);
|
||||||
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
|
ProgramShaderCache::SetBothShaders(s_yuyvToRgbProgram.glprogid, 0);
|
||||||
|
else
|
||||||
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
|
PixelShaderCache::SetCurrentShader(s_yuyvToRgbProgram.glprogid);
|
||||||
|
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue