From 0fc755c4dfd8b55b12461011550994ed6974e043 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 2 Dec 2011 20:17:26 -0600 Subject: [PATCH] More stuff --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 2 +- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 20 +-- Source/Core/VideoCommon/Src/VideoConfig.cpp | 4 +- .../Plugin_VideoOGL/Src/PixelShaderCache.cpp | 10 +- .../Plugin_VideoOGL/Src/TextureConverter.cpp | 132 ++++++++++++------ .../Plugin_VideoOGL/Src/VertexShaderCache.cpp | 10 +- 6 files changed, 126 insertions(+), 52 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index bc7b8cc375..1a5908c068 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -1198,7 +1198,7 @@ void SampleTexture(char *&p, const char *destination, const char *texcoords, con if (ApiType == API_D3D11) WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap); else - WRITE(p, "%s=tex2D(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, texmap, texcoords, texmap, texswap); + WRITE(p, "%s=%s(samp%d,%s.xy * "I_TEXDIMS"[%d].xy).%s;\n", destination, ApiType == API_GLSL ? "texture2D" : "tex2D", texmap, texcoords, texmap, texswap); } static const char *tevAlphaFuncsTable[] = diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 7ebd6fd3b9..f22926462d 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -132,30 +132,32 @@ static char text[16384]; char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType) { + // This turned a bit ugly with GLSL + // Will be less ugly with GLSL 1.3...hopefully WRITE(p, "struct VS_OUTPUT {\n"); - WRITE(p, " float4 pos : POSITION;\n"); - WRITE(p, " float4 colors_0 : COLOR0;\n"); - WRITE(p, " float4 colors_1 : COLOR1;\n"); + WRITE(p, " float4 pos %s POSITION;\n", ApiType == API_GLSL ? ";//" : ":"); + WRITE(p, " float4 colors_0 %s COLOR0;\n", ApiType == API_GLSL ? ";//" : ":"); + WRITE(p, " float4 colors_1 %s COLOR1;\n", ApiType == API_GLSL ? ";//" : ":"); if (xfregs.numTexGen.numTexGens < 7) { for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) - WRITE(p, " float3 tex%d : TEXCOORD%d;\n", i, i); - WRITE(p, " float4 clipPos : TEXCOORD%d;\n", xfregs.numTexGen.numTexGens); + WRITE(p, " float3 tex%d %s TEXCOORD%d;\n", i, ApiType == API_GLSL ? ";//" : ":", i); + WRITE(p, " float4 clipPos %s TEXCOORD%d;\n", ApiType == API_GLSL ? ";//" : ":", xfregs.numTexGen.numTexGens); if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) - WRITE(p, " float4 Normal : TEXCOORD%d;\n", xfregs.numTexGen.numTexGens + 1); + WRITE(p, " float4 Normal %s TEXCOORD%d;\n", ApiType == API_GLSL ? ";//" : ":", xfregs.numTexGen.numTexGens + 1); } else { // clip position is in w of first 4 texcoords if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { for (int i = 0; i < 8; ++i) - WRITE(p, " float4 tex%d : TEXCOORD%d;\n", i, i); + WRITE(p, " float4 tex%d %s TEXCOORD%d;\n", i, ApiType == API_GLSL ? ";//" : ":", i); } else { for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) - WRITE(p, " float%d tex%d : TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, i); + WRITE(p, " float%d tex%d %s TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, ApiType == API_GLSL ? ";//" : ":", i); } - } + } WRITE(p, "};\n"); return p; diff --git a/Source/Core/VideoCommon/Src/VideoConfig.cpp b/Source/Core/VideoCommon/Src/VideoConfig.cpp index c972d46716..85b51c3f74 100644 --- a/Source/Core/VideoCommon/Src/VideoConfig.cpp +++ b/Source/Core/VideoCommon/Src/VideoConfig.cpp @@ -43,6 +43,7 @@ VideoConfig::VideoConfig() backend_info.APIType = API_NONE; backend_info.bUseRGBATextures = false; backend_info.bSupports3DVision = false; + backend_info.bSupportsGLSL = false; } void VideoConfig::Load(const char *ini_file) @@ -86,6 +87,7 @@ void VideoConfig::Load(const char *ini_file) iniFile.Get("Settings", "TexFmtOverlayCenter", &bTexFmtOverlayCenter, 0); iniFile.Get("Settings", "WireFrame", &bWireFrame, 0); iniFile.Get("Settings", "DisableFog", &bDisableFog, 0); + iniFile.Get("Settings", "UseGLSL", &bUseGLSL, 0); iniFile.Get("Settings", "EnableOpenCL", &bEnableOpenCL, false); iniFile.Get("Settings", "OMPDecoder", &bOMPDecoder, false); @@ -216,7 +218,7 @@ void VideoConfig::Save(const char *ini_file) iniFile.Set("Settings", "Wireframe", bWireFrame); iniFile.Set("Settings", "DstAlphaPass", bDstAlphaPass); iniFile.Set("Settings", "DisableFog", bDisableFog); - iniFile.Set("Settings", "bUseGLSL", bUseGLSL); + iniFile.Set("Settings", "UseGLSL", bUseGLSL); iniFile.Set("Settings", "EnableOpenCL", bEnableOpenCL); iniFile.Set("Settings", "OMPDecoder", bOMPDecoder); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 6d56df3216..2b9deb03aa 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -314,7 +314,15 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram) GLsizei charsWritten; GLchar* infoLog = new GLchar[length]; glGetShaderInfoLog(result, length, &charsWritten, infoLog); - WARN_LOG(VIDEO, "Shader info log:\n%s", infoLog); + WARN_LOG(VIDEO, "PS Shader info log:\n%s", infoLog); + char szTemp[MAX_PATH]; + sprintf(szTemp, "ps_%d.txt", result); + FILE *fp = fopen(szTemp, "wb"); + fwrite(pstrprogram, strlen(pstrprogram), 1, fp); + fclose(fp); + + if(strstr(infoLog, "warning") != NULL || strstr(infoLog, "error") != NULL) + exit(0); delete[] infoLog; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index c73d3abdbf..069991daf1 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -60,51 +60,105 @@ static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS]; void CreateRgbToYuyvProgram() { // Output is BGRA because that is slightly faster than RGBA. - const char *FProgram = - "uniform samplerRECT samp0 : register(s0);\n" - "void main(\n" - " out float4 ocol0 : COLOR0,\n" - " in float2 uv0 : TEXCOORD0)\n" - "{\n" - " float2 uv1 = float2(uv0.x + 1.0f, uv0.y);\n" - " float3 c0 = texRECT(samp0, uv0).rgb;\n" - " float3 c1 = texRECT(samp0, uv1).rgb;\n" - " float3 y_const = float3(0.257f,0.504f,0.098f);\n" - " float3 u_const = float3(-0.148f,-0.291f,0.439f);\n" - " float3 v_const = float3(0.439f,-0.368f,-0.071f);\n" - " float4 const3 = float4(0.0625f,0.5f,0.0625f,0.5f);\n" - " float3 c01 = (c0 + c1) * 0.5f;\n" - " ocol0 = float4(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."); + if(g_ActiveConfig.bUseGLSL) + { + 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" + " 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 = + "uniform samplerRECT samp0 : register(s0);\n" + "void main(\n" + " out float4 ocol0 : COLOR0,\n" + " in float2 uv0 : TEXCOORD0)\n" + "{\n" + " float2 uv1 = float2(uv0.x + 1.0f, uv0.y);\n" + " float3 c0 = texRECT(samp0, uv0).rgb;\n" + " float3 c1 = texRECT(samp0, uv1).rgb;\n" + " float3 y_const = float3(0.257f,0.504f,0.098f);\n" + " float3 u_const = float3(-0.148f,-0.291f,0.439f);\n" + " float3 v_const = float3(0.439f,-0.368f,-0.071f);\n" + " float4 const3 = float4(0.0625f,0.5f,0.0625f,0.5f);\n" + " float3 c01 = (c0 + c1) * 0.5f;\n" + " ocol0 = float4(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() { - const char *FProgram = - "uniform samplerRECT samp0 : register(s0);\n" - "void main(\n" - " out float4 ocol0 : COLOR0,\n" - " in float2 uv0 : TEXCOORD0)\n" - "{\n" - " float4 c0 = texRECT(samp0, uv0).rgba;\n" + if(g_ActiveConfig.bUseGLSL) + { + 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, frac(uv0.x));\n" - " float y = lerp(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" - " ocol0 = float4(yComp + (1.596f * vComp),\n" - " yComp - (0.813f * vComp) - (0.391f * uComp),\n" - " yComp + (2.018f * uComp),\n" - " 1.0f);\n" - "}\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 = + "uniform samplerRECT samp0 : register(s0);\n" + "void main(\n" + " out float4 ocol0 : COLOR0,\n" + " in float2 uv0 : TEXCOORD0)\n" + "{\n" + " float4 c0 = texRECT(samp0, uv0).rgba;\n" - if (!PixelShaderCache::CompilePixelShader(s_yuyvToRgbProgram, FProgram)) - ERROR_LOG(VIDEO, "Failed to create YUYV to RGB fragment program."); + " float f = step(0.5, frac(uv0.x));\n" + " float y = lerp(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" + + " ocol0 = float4(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) @@ -117,7 +171,7 @@ FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format) if (s_encodingPrograms[format].glprogid == 0) { - const char* shader = TextureConversionShader::GenerateEncodingShader(format,API_OPENGL); + const char* shader = TextureConversionShader::GenerateEncodingShader(format, g_ActiveConfig.bUseGLSL ? API_GLSL : API_OPENGL); #if defined(_DEBUG) || defined(DEBUGFAST) if (g_ActiveConfig.iLog & CONF_SAVESHADERS && shader) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp index ea7a97196b..c543dfb86e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexShaderCache.cpp @@ -198,7 +198,15 @@ bool CompileGLSLVertexShader(VERTEXSHADER& vs, const char* pstrprogram) GLsizei charsWritten; GLchar* infoLog = new GLchar[length]; glGetShaderInfoLog(result, length, &charsWritten, infoLog); - WARN_LOG(VIDEO, "Shader info log:\n%s", infoLog); + WARN_LOG(VIDEO, "VS Shader info log:\n%s", infoLog); + char szTemp[MAX_PATH]; + sprintf(szTemp, "vs_%d.txt", result); + FILE *fp = fopen(szTemp, "wb"); + fwrite(pstrprogram, strlen(pstrprogram), 1, fp); + fclose(fp); + + if(strstr(infoLog, "warning") != NULL || strstr(infoLog, "error") != NULL) + exit(0); delete[] infoLog; }