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

@ -514,15 +514,6 @@ const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
return result;
}
const char* WriteBinding(API_TYPE ApiType, const u32 num)
{
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
return "";
static char result[64];
sprintf(result, "layout(binding = %d) ", num);
return result;
}
const char *WriteLocation(API_TYPE ApiType)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -560,29 +551,14 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
WRITE(p, "#version 130\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");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
WRITE(p, "#define VARYIN in\n");
WRITE(p, "#define VARYOUT out\n");
}
else
{
WRITE(p, "#version 120\n");
WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n"); // Can't really be used, but provide it anyway
WRITE(p, "#define VARYIN varying\n");
WRITE(p, "#define VARYOUT varying\n");
}
WRITE(p, "#version 130\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
WRITE(p, "#define VARYIN in\n");
WRITE(p, "#define VARYOUT out\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
@ -603,7 +579,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "}\n");
for (int i = 0; i < 8; ++i)
WRITE(p, "%suniform sampler2D samp%d;\n", WriteBinding(ApiType, i), i);
WRITE(p, "uniform sampler2D samp%d;\n", i);
}
else
{
@ -659,27 +635,10 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if (ApiType == API_OPENGL)
{
// GLSL doesn't do main arguments
// Once we switch to GLSL 1.3 we will bind a lot of these.
WRITE(p, "out float4 ocol0;\n");
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{
// This won't get hit unless we support GL 3.3
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{
WRITE(p, "layout(location = 0) out float4 ocol0;\n");
WRITE(p, "layout(location = 0, index = 1) out float4 ocol1;\n");
}
else
{
WRITE(p, "out float4 ocol0;\n");
WRITE(p, "out float4 ocol1;\n");
}
}
else
{
WRITE(p, "float4 ocol0;\n");
}
WRITE(p, "out float4 ocol1;\n");
if (DepthTextureEnable)
WRITE(p, "float depth;\n");
WRITE(p, "float4 rawpos = gl_FragCoord;\n");
@ -790,8 +749,6 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
{
if (DepthTextureEnable)
WRITE(p, "\tgl_FragDepth = depth;\n");
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "\tgl_FragData[0] = ocol0;\n");
}
WRITE(p, "\tdiscard;\n");
if(ApiType != API_D3D11)
@ -957,16 +914,15 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
{
// Colors will be blended against the alpha from ocol1...
WRITE(p, "\tocol1 = ocol0;\n");
WRITE(p, "\tocol1 = prev;\n");
// ...and the alpha from ocol0 will be written to the framebuffer.
WRITE(p, "\tocol0.a = " I_ALPHA"[0].a;\n");
}
if (ApiType == API_OPENGL)
{
if (DepthTextureEnable)
WRITE(p, "\tgl_FragDepth = depth;\n");
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "\tgl_FragData[0] = ocol0;\n");
}
WRITE(p, "}\n");
if (text[sizeof(text) - 1] != 0x7C)

View File

@ -93,7 +93,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "layout(std140) uniform PSBlock {\n");
WRITE(p, "%sfloat4 " I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
@ -105,8 +105,6 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
float samples = (float)GetEncodedSampleCount(format);
if (ApiType == API_OPENGL)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
WRITE(p, "layout(binding = 0) ");
WRITE(p, "uniform sampler2DRect samp0;\n");
}
else if (ApiType & API_D3D9)
@ -181,7 +179,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "layout(std140) uniform PSBlock {\n");
WRITE(p, "%sfloat4 " I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
@ -192,8 +190,6 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments
if (ApiType == API_OPENGL)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
WRITE(p, "layout(binding = 0) ");
WRITE(p, "uniform sampler2DRect samp0;\n");
}
else if (ApiType & API_D3D9)
@ -848,16 +844,10 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
WRITE(p, "#version 130\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");
WRITE(p, "#version 130\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");

View File

@ -164,8 +164,7 @@ char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType)
}
extern const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num);
extern const char* WriteBinding(API_TYPE ApiType, const u32 num);
const char *WriteLocation(API_TYPE ApiType);
extern const char *WriteLocation(API_TYPE ApiType);
const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
{
@ -188,28 +187,15 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{
WRITE(p, "#version 130\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");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
WRITE(p, "#define VARYIN in\n");
WRITE(p, "#define VARYOUT out\n");
}
else
{
WRITE(p, "#version 120\n");
WRITE(p, "#define ATTRIN attribute\n");
WRITE(p, "#define ATTROUT attribute\n"); // Can't really be used, but provide it anyway
WRITE(p, "#define VARYIN varying\n");
WRITE(p, "#define VARYOUT varying\n");
}
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
WRITE(p, "#extension GL_ARB_explicit_attrib_location : enable\n");
WRITE(p, "#version 130\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n");
WRITE(p, "#define ATTRIN in\n");
WRITE(p, "#define ATTROUT out\n");
WRITE(p, "#define VARYIN in\n");
WRITE(p, "#define VARYOUT out\n");
// Silly differences
WRITE(p, "#define float2 vec2\n");
WRITE(p, "#define float3 vec3\n");
@ -246,24 +232,12 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n");
if (g_ActiveConfig.backend_info.bSupportsGLSLATTRBind)
{
if (components & VB_HAS_POSMTXIDX)
WRITE(p, "layout(location = %d) ATTRIN float fposmtx;\n", SHADER_POSMTX_ATTRIB);
if (components & VB_HAS_NRM1)
WRITE(p, "layout(location = %d) ATTRIN float3 rawnorm1;\n", SHADER_NORM1_ATTRIB);
if (components & VB_HAS_NRM2)
WRITE(p, "layout(location = %d) ATTRIN float3 rawnorm2;\n", SHADER_NORM2_ATTRIB);
}
else
{
if (components & VB_HAS_POSMTXIDX)
WRITE(p, "ATTRIN float fposmtx; // ATTR%d,\n", SHADER_POSMTX_ATTRIB);
if (components & VB_HAS_NRM1)
WRITE(p, "ATTRIN float3 rawnorm1; // ATTR%d,\n", SHADER_NORM1_ATTRIB);
if (components & VB_HAS_NRM2)
WRITE(p, "ATTRIN float3 rawnorm2; // ATTR%d,\n", SHADER_NORM2_ATTRIB);
}
if (components & VB_HAS_POSMTXIDX)
WRITE(p, "ATTRIN float fposmtx; // ATTR%d,\n", SHADER_POSMTX_ATTRIB);
if (components & VB_HAS_NRM1)
WRITE(p, "ATTRIN float3 rawnorm1; // ATTR%d,\n", SHADER_NORM1_ATTRIB);
if (components & VB_HAS_NRM2)
WRITE(p, "ATTRIN float3 rawnorm2; // ATTR%d,\n", SHADER_NORM2_ATTRIB);
if (components & VB_HAS_COL0)
WRITE(p, " float4 color0 = gl_Color; // COLOR0,\n");

View File

@ -164,10 +164,8 @@ struct VideoConfig
bool bSupportsPixelLighting;
bool bSupportsGLSL;
bool bSupportsGLSLBinding;
bool bSupportsGLSLBlend;
bool bSupportsGLSLUBO;
bool bSupportsGLSLATTRBind;
bool bSupportsGLSLCache;
} backend_info;

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