From e0a5f7842e6f3122bc01a6647e21bd1800ec8ea8 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 25 Jul 2013 16:13:33 +0000 Subject: [PATCH] Fix Mali-T604 shader compilation --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 9c80d078ff..9e831541bd 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -328,13 +328,10 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api if (per_pixel_depth) out.Write("#define depth gl_FragDepth\n"); - out.Write("float4 rawpos = gl_FragCoord;\n"); out.Write("VARYIN float4 colors_02;\n"); out.Write("VARYIN float4 colors_12;\n"); - out.Write("float4 colors_0 = colors_02;\n"); - out.Write("float4 colors_1 = colors_12;\n"); - + // compute window position if needed because binding semantic WPOS is not widely supported // Let's set up attributes if (xfregs.numTexGen.numTexGens < 7) @@ -342,14 +339,11 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api for (int i = 0; i < 8; ++i) { out.Write("VARYIN float3 uv%d_2;\n", i); - out.Write("float3 uv%d = uv%d_2;\n", i, i); } out.Write("VARYIN float4 clipPos_2;\n"); - out.Write("float4 clipPos = clipPos_2;\n"); if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { out.Write("VARYIN float4 Normal_2;\n"); - out.Write("float4 Normal = Normal_2;\n"); } } else @@ -360,7 +354,6 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api for (int i = 0; i < 8; ++i) { out.Write("VARYIN float4 uv%d_2;\n", i); - out.Write("float4 uv%d = uv%d_2;\n", i, i); } } else @@ -368,7 +361,6 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) { out.Write("VARYIN float%d uv%d_2;\n", i < 4 ? 4 : 3 , i); - out.Write("float%d uv%d = uv%d_2;\n", i < 4 ? 4 : 3 , i, i); } } out.Write("float4 clipPos;\n"); @@ -443,6 +435,50 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api " float4 cc2=float4(0.0f,0.0f,0.0f,0.0f), cprev=float4(0.0f,0.0f,0.0f,0.0f);\n" " float4 crastemp=float4(0.0f,0.0f,0.0f,0.0f),ckonsttemp=float4(0.0f,0.0f,0.0f,0.0f);\n\n"); + if (ApiType == API_OPENGL) + { + // On Mali, global variables must be initialized as constants. + // This is why we initialize these variables locally instead. + out.Write("float4 rawpos = gl_FragCoord;\n"); + out.Write("float4 colors_0 = colors_02;\n"); + out.Write("float4 colors_1 = colors_12;\n"); + // compute window position if needed because binding semantic WPOS is not widely supported + // Let's set up attributes + if (xfregs.numTexGen.numTexGens < 7) + { + if(numTexgen) + { + for (int i = 0; i < 8; ++i) + { + out.Write("float3 uv%d = uv%d_2;\n", i, i); + } + } + out.Write("float4 clipPos = clipPos_2;\n"); + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + out.Write("float4 Normal = Normal_2;\n"); + } + } + else + { + // wpos is in w of first 4 texcoords + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) + { + for (int i = 0; i < 8; ++i) + { + out.Write("float4 uv%d = uv%d_2;\n", i, i); + } + } + else + { + for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) + { + out.Write("float%d uv%d = uv%d_2;\n", i < 4 ? 4 : 3 , i, i); + } + } + } + } + if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { uid_data.xfregs_numTexGen_numTexGens = xfregs.numTexGen.numTexGens;