Set Sampler values at program make time instead of every frame. Fix an issue when The user had UBO support but not Binding support.
This commit is contained in:
parent
73c3f198f4
commit
b837ae25fc
|
@ -119,39 +119,10 @@ void PixelShaderCache::Init()
|
||||||
if(g_ActiveConfig.bUseGLSL)
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
{
|
{
|
||||||
char pmatrixprog[2048];
|
char pmatrixprog[2048];
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
sprintf(pmatrixprog, "#version %s\n"
|
||||||
{
|
|
||||||
sprintf(pmatrixprog, "#version 330 compatibility\n"
|
|
||||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
"%s\n"
|
||||||
"layout(binding = 0) uniform sampler2DRect samp0;\n"
|
"%suniform sampler2DRect samp0;\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"
|
|
||||||
"Temp0 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
|
|
||||||
"Temp0 = Temp0 * "I_COLORS"[%d];\n"
|
|
||||||
"Temp0 = Temp0 + K0;\n"
|
|
||||||
"Temp0 = floor(Temp0);\n"
|
|
||||||
"Temp0 = Temp0 * "I_COLORS"[%d];\n"
|
|
||||||
"Temp1.x = dot(Temp0, "I_COLORS"[%d]);\n"
|
|
||||||
"Temp1.y = dot(Temp0, "I_COLORS"[%d]);\n"
|
|
||||||
"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",
|
|
||||||
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"
|
|
||||||
"%s\n"
|
"%s\n"
|
||||||
"%svec4 "I_COLORS"[7];\n"
|
"%svec4 "I_COLORS"[7];\n"
|
||||||
"%s\n"
|
"%s\n"
|
||||||
|
@ -169,59 +140,25 @@ void PixelShaderCache::Init()
|
||||||
"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",
|
"}\n",
|
||||||
|
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
|
||||||
|
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
|
||||||
|
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
|
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
|
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
|
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);
|
C_COLORS+5, C_COLORS+6, C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||||
}
|
|
||||||
|
|
||||||
if (!PixelShaderCache::CompilePixelShader(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();
|
||||||
}
|
}
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
|
||||||
{
|
sprintf(pmatrixprog, "#version %s\n"
|
||||||
sprintf(pmatrixprog, "#version 330 compatibility\n"
|
|
||||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
"%s\n"
|
||||||
"layout(binding = 0) uniform sampler2DRect samp0;\n"
|
"%suniform sampler2DRect samp0;\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"
|
|
||||||
"vec4 K1 = vec4(15.0, 0.066666666666, 0.0, 0.0);\n"
|
|
||||||
"R2 = texture2DRect(samp0, gl_TexCoord[0].xy);\n"
|
|
||||||
"R0.x = R2.x * K0.x;\n"
|
|
||||||
"R0.x = floor(R0).x;\n"
|
|
||||||
"R0.yzw = (R0 - R0.x).yzw;\n"
|
|
||||||
"R0.yzw = (R0 * K0.z).yzw;\n"
|
|
||||||
"R0.y = floor(R0).y;\n"
|
|
||||||
"R0.zw = (R0 - R0.y).zw;\n"
|
|
||||||
"R0.zw = (R0 * K0.z).zw;\n"
|
|
||||||
"R0.z = floor(R0).z;\n"
|
|
||||||
"R0.w = R0.x;\n"
|
|
||||||
"R0 = R0 * K0.y;\n"
|
|
||||||
"R0.w = (R0 * K1.x).w;\n"
|
|
||||||
"R0.w = floor(R0).w;\n"
|
|
||||||
"R0.w = (R0 * K1.y).w;\n"
|
|
||||||
"R1.x = dot(R0, "I_COLORS"[%d]);\n"
|
|
||||||
"R1.y = dot(R0, "I_COLORS"[%d]);\n"
|
|
||||||
"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",
|
|
||||||
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"
|
|
||||||
"%s\n"
|
"%s\n"
|
||||||
"%svec4 "I_COLORS"[5];\n"
|
"%svec4 "I_COLORS"[5];\n"
|
||||||
"%s\n"
|
"%s\n"
|
||||||
|
@ -249,11 +186,14 @@ void PixelShaderCache::Init()
|
||||||
"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",
|
"}\n",
|
||||||
|
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "330 compatibility" : "120",
|
||||||
|
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
|
||||||
|
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
|
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
|
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
|
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
|
||||||
C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
C_COLORS, C_COLORS+1, C_COLORS+2, C_COLORS+3, C_COLORS+4);
|
||||||
}
|
|
||||||
if (!PixelShaderCache::CompilePixelShader(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");
|
||||||
|
@ -492,23 +432,6 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||||
ps.bGLSL = true;
|
ps.bGLSL = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
|
|
||||||
{
|
|
||||||
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
|
||||||
return;
|
|
||||||
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
|
||||||
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
|
||||||
if (!strcmp(name, UniformNames[a]))
|
|
||||||
{
|
|
||||||
if(tmp.UniformLocations[a] == -1)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glUniform1i(tmp.UniformLocations[a], Tex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
||||||
{
|
{
|
||||||
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
|
|
|
@ -78,8 +78,6 @@ class PixelShaderCache
|
||||||
public:
|
public:
|
||||||
static void Init();
|
static void Init();
|
||||||
static void Shutdown();
|
static void Shutdown();
|
||||||
// This is a GLSL only function
|
|
||||||
static void SetPSSampler(const char * name, unsigned int Tex);
|
|
||||||
|
|
||||||
static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
|
||||||
static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
|
static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram);
|
||||||
|
@ -88,8 +86,6 @@ public:
|
||||||
|
|
||||||
static GLuint GetDepthMatrixProgram();
|
static GLuint GetDepthMatrixProgram();
|
||||||
|
|
||||||
static bool SupportsBinding();
|
|
||||||
|
|
||||||
static void SetCurrentShader(GLuint Shader);
|
static void SetCurrentShader(GLuint Shader);
|
||||||
|
|
||||||
static void DisableShader();
|
static void DisableShader();
|
||||||
|
|
|
@ -117,6 +117,14 @@ namespace OGL
|
||||||
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
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]);
|
||||||
|
else if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||||
|
for(int a = 0; a < 8; ++a)
|
||||||
|
{
|
||||||
|
// Still need to get sampler locations since we aren't binding them statically in the shaders
|
||||||
|
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
|
||||||
|
if(entry.program.UniformLocations[a] != -1)
|
||||||
|
glUniform1i(entry.program.UniformLocations[a], a);
|
||||||
|
}
|
||||||
|
|
||||||
// Need to get some attribute locations
|
// Need to get some attribute locations
|
||||||
if(uid.uid.vsid != 0) // We have no vertex Shader
|
if(uid.uid.vsid != 0) // We have no vertex Shader
|
||||||
|
|
|
@ -298,10 +298,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||||
glViewport(0, 0, virtualW, virtualH);
|
glViewport(0, 0, virtualW, virtualH);
|
||||||
|
|
||||||
if(g_ActiveConfig.bUseGLSL)
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
{
|
|
||||||
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
|
ProgramShaderCache::SetBothShaders((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram(), 0);
|
||||||
PixelShaderCache::SetPSSampler("samp0", 0);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
|
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
|
||||||
PixelShaderManager::SetColorMatrix(colmat); // set transformation
|
PixelShaderManager::SetColorMatrix(colmat); // set transformation
|
||||||
|
|
|
@ -314,8 +314,6 @@ void EncodeToRamUsingShader(GLuint srcTexture, const TargetRectangle& sourceRc,
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
if(g_ActiveConfig.bUseGLSL)
|
|
||||||
PixelShaderCache::SetPSSampler("samp0", 0);
|
|
||||||
|
|
||||||
glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight);
|
glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight);
|
||||||
|
|
||||||
|
|
|
@ -219,16 +219,6 @@ void VertexManager::vFlush()
|
||||||
if (g_nativeVertexFmt)
|
if (g_nativeVertexFmt)
|
||||||
g_nativeVertexFmt->SetupVertexPointers();
|
g_nativeVertexFmt->SetupVertexPointers();
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
if(g_ActiveConfig.bUseGLSL)
|
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
if (usedtextures & (1 << i))
|
|
||||||
{
|
|
||||||
char tmp[16];
|
|
||||||
sprintf(tmp, "samp%d", i); // Bake this in to something so we don't have to sprintf?
|
|
||||||
PixelShaderCache::SetPSSampler(tmp, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
|
@ -243,15 +233,6 @@ void VertexManager::vFlush()
|
||||||
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
|
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
|
||||||
if (g_nativeVertexFmt)
|
if (g_nativeVertexFmt)
|
||||||
g_nativeVertexFmt->SetupVertexPointers();
|
g_nativeVertexFmt->SetupVertexPointers();
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
if (usedtextures & (1 << i))
|
|
||||||
{
|
|
||||||
char tmp[16];
|
|
||||||
sprintf(tmp, "samp%d", i); // Bake this in to something so we don't have to sprintf?
|
|
||||||
PixelShaderCache::SetPSSampler(tmp, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid);
|
if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid);
|
||||||
|
|
Loading…
Reference in New Issue