remove glsl binding support. convert every shader to version 130

This commit is contained in:
degasus
2013-01-02 16:56:08 +01:00
parent c2898748ac
commit b38b62afc6
9 changed files with 143 additions and 297 deletions

View File

@ -70,32 +70,30 @@ void PixelShaderCache::Init()
s_displayCompileAlert = true;
char pmatrixprog[2048];
sprintf(pmatrixprog, "#version %s\n"
sprintf(pmatrixprog, "#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
"%s\n"
"%suniform sampler2DRect samp0;\n"
"uniform sampler2DRect samp0;\n"
"%s\n"
"%svec4 " I_COLORS"[7];\n"
"%s\n"
"out vec4 ocol0;\n"
"\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"
" 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"
" ocol0 = Temp1 + " I_COLORS"[%d];\n"
"}\n",
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "130" : "120",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "#extension GL_ARB_uniform_buffer_object : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",
@ -108,42 +106,40 @@ void PixelShaderCache::Init()
s_ColorMatrixProgram.Destroy();
}
sprintf(pmatrixprog, "#version %s\n"
sprintf(pmatrixprog, "#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"%s\n"
"%s\n"
"%suniform sampler2DRect samp0;\n"
"uniform sampler2DRect samp0;\n"
"%s\n"
"%svec4 " I_COLORS"[5];\n"
"%s\n"
"out vec4 ocol0;\n"
"\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"
" 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"
" ocol0 = R1 * " I_COLORS"[%d];\n"
"}\n",
(g_ActiveConfig.backend_info.bSupportsGLSLUBO || g_ActiveConfig.backend_info.bSupportsGLSLBinding) ? "130" : "120",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "#extension GL_ARB_shading_language_420pack : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "#extension GL_ARB_uniform_buffer_object : enable" : "",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "layout(binding = 0) " : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "layout(std140) uniform PSBlock {" : "",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "uniform ",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "};" : "",

View File

@ -61,18 +61,18 @@ const char *UniformNames[NUM_UNIFORMS] =
void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry)
{
// Dunno why this is needed when I have the binding
// points statically set in the shader source
// We should only need these two functions when we don't support binding but do support UBO
// Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64
// Bind UBO
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
glUniformBlockBinding(entry.prog_id, glGetUniformBlockIndex(entry.prog_id, "PSBlock"), 1);
// Some things have no vertex shader
if (entry.vsid != 0)
glUniformBlockBinding(entry.prog_id, glGetUniformBlockIndex(entry.prog_id, "VSBlock"), 2);
GLint PSBlock_id = glGetUniformBlockIndex(entry.prog_id, "PSBlock");
GLint VSBlock_id = glGetUniformBlockIndex(entry.prog_id, "VSBlock");
if(PSBlock_id != -1)
glUniformBlockBinding(entry.prog_id, PSBlock_id, 1);
if(VSBlock_id != -1)
glUniformBlockBinding(entry.prog_id, VSBlock_id, 2);
}
// We cache our uniform locations for now
// Once we move up to a newer version of GLSL, ~1.30
// We can remove this
@ -84,40 +84,32 @@ void ProgramShaderCache::SetProgramVariables(PCacheEntry &entry)
for (int a = 8; a < NUM_UNIFORMS; ++a)
entry.UniformLocations[a] = glGetUniformLocation(entry.prog_id, UniformNames[a]);
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
// Bind Texture Sampler
for (int a = 0; a < 8; ++a)
{
for (int a = 0; a < 8; ++a)
{
// Still need to get sampler locations since we aren't binding them statically in the shaders
entry.UniformLocations[a] = glGetUniformLocation(entry.prog_id, UniformNames[a]);
if (entry.UniformLocations[a] != -1)
glUniform1i(entry.UniformLocations[a], a);
}
// Still need to get sampler locations since we aren't binding them statically in the shaders
entry.UniformLocations[a] = glGetUniformLocation(entry.prog_id, UniformNames[a]);
if (entry.UniformLocations[a] != -1)
glUniform1i(entry.UniformLocations[a], a);
}
}
void ProgramShaderCache::SetProgramBindings ( ProgramShaderCache::PCacheEntry& entry )
{
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
if (g_ActiveConfig.backend_info.bSupportsGLSLBlend)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBlend)
{
// So we don't support binding, but we do support extended blending
// So we need to set a few more things here.
// Bind our out locations
glBindFragDataLocationIndexed(entry.prog_id, 0, 0, "ocol0");
glBindFragDataLocationIndexed(entry.prog_id, 0, 1, "ocol1");
}
// So we do support extended blending
// So we need to set a few more things here.
// Bind our out locations
glBindFragDataLocationIndexed(entry.prog_id, 0, 0, "ocol0");
glBindFragDataLocationIndexed(entry.prog_id, 0, 1, "ocol1");
}
// Need to set some attribute locations
if (entry.vsid != 0 && !g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
{
// We have no vertex Shader
glBindAttribLocation(entry.prog_id, SHADER_NORM1_ATTRIB, "rawnorm1");
glBindAttribLocation(entry.prog_id, SHADER_NORM2_ATTRIB, "rawnorm2");
glBindAttribLocation(entry.prog_id, SHADER_POSMTX_ATTRIB, "fposmtx");
}
glBindAttribLocation(entry.prog_id, SHADER_NORM1_ATTRIB, "rawnorm1");
glBindAttribLocation(entry.prog_id, SHADER_NORM2_ATTRIB, "rawnorm2");
glBindAttribLocation(entry.prog_id, SHADER_POSMTX_ATTRIB, "fposmtx");
}

View File

@ -315,20 +315,16 @@ Renderer::Renderer()
s_bHaveFramebufferBlit = strstr(ptoken, "GL_EXT_framebuffer_blit") != NULL;
s_bHaveCoverageMSAA = strstr(ptoken, "GL_NV_framebuffer_multisample_coverage") != NULL;
if (glewIsSupported("GL_ARB_shading_language_420pack"))
g_Config.backend_info.bSupportsGLSLBinding = true;
if (glewIsSupported("GL_ARB_blend_func_extended"))
g_Config.backend_info.bSupportsGLSLBlend = true;
if (glewIsSupported("GL_ARB_uniform_buffer_object"))
g_Config.backend_info.bSupportsGLSLUBO = true;
if ((g_Config.backend_info.bSupportsGLSLBinding || g_Config.backend_info.bSupportsGLSLUBO) && glewIsSupported("GL_ARB_explicit_attrib_location"))
g_Config.backend_info.bSupportsGLSLATTRBind = true;
if (glewIsSupported("GL_ARB_get_program_binary"))
g_Config.backend_info.bSupportsGLSLCache = true;
UpdateActiveConfig();
OSD::AddMessage(StringFromFormat("Supports Binding: %s UBOs: %s Cache: %s",
g_ActiveConfig.backend_info.bSupportsGLSLBinding ? "True" : "False",
OSD::AddMessage(StringFromFormat("Supports Blending: %s UBOs: %s Cache: %s",
g_ActiveConfig.backend_info.bSupportsGLSLBlend ? "True" : "False",
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "True" : "False",
g_ActiveConfig.backend_info.bSupportsGLSLCache ? "True" : "False").c_str(), 5000);

View File

@ -69,106 +69,49 @@ static int s_cached_srcHeight = 0;
void CreateRgbToYuyvProgram()
{
// Output is BGRA because that is slightly faster than RGBA.
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
const char *FProgram =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"#extension GL_ARB_explicit_attrib_location : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
}
else
{
const char *FProgram =
"#version 120\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
}
const char *FProgram =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec2 uv1 = vec2(gl_TexCoord[0].x + 1.0f, gl_TexCoord[0].y);\n"
" vec3 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgb;\n"
" vec3 c1 = texture2DRect(samp0, uv1).rgb;\n"
" vec3 y_const = vec3(0.257f,0.504f,0.098f);\n"
" vec3 u_const = vec3(-0.148f,-0.291f,0.439f);\n"
" vec3 v_const = vec3(0.439f,-0.368f,-0.071f);\n"
" vec4 const3 = vec4(0.0625f,0.5f,0.0625f,0.5f);\n"
" vec3 c01 = (c0 + c1) * 0.5f;\n"
" gl_FragData[0] = vec4(dot(c1,y_const),dot(c01,u_const),dot(c0,y_const),dot(c01, v_const)) + const3;\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create RGB to YUYV fragment program.");
}
void CreateYuyvToRgbProgram()
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
const char *FProgram =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"#extension GL_ARB_shading_language_420pack : enable\n"
"#extension GL_ARB_explicit_attrib_location : enable\n"
"layout(binding = 0) uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
const char *FProgram =
"#version 130\n"
"#extension GL_ARB_texture_rectangle : enable\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
else
{
const char *FProgram =
"#version 120\n"
"#ifdef GL_ARB_texture_rectangle\n"
"#extension GL_ARB_texture_rectangle : require\n"
"#endif\n"
"uniform sampler2DRect samp0;\n"
"void main()\n"
"{\n"
" vec4 c0 = texture2DRect(samp0, gl_TexCoord[0].xy).rgba;\n"
" float f = step(0.5, fract(gl_TexCoord[0].x));\n"
" float y = mix(c0.b, c0.r, f);\n"
" float yComp = 1.164f * (y - 0.0625f);\n"
" float uComp = c0.g - 0.5f;\n"
" float vComp = c0.a - 0.5f;\n"
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
" gl_FragData[0] = vec4(yComp + (1.596f * vComp),\n"
" yComp - (0.813f * vComp) - (0.391f * uComp),\n"
" yComp + (2.018f * uComp),\n"
" 1.0f);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram))
ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program.");
}
FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format)

View File

@ -224,8 +224,9 @@ void VertexManager::vFlush()
ProgramShaderCache::SetBothShaders(ps->glprogid, vs->glprogid);
if (!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
// Need to set these again, if we don't support UBO
VertexShaderManager::SetConstants();
PixelShaderManager::SetConstants();
}
// only update alpha