From 3ed777b0f99a2cbbc77c35a8e3b87f364cbc0630 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 26 Dec 2014 00:56:12 +0100 Subject: [PATCH] PixelShaderGen: Don't assign to input variables. --- Source/Core/VideoCommon/LightingShaderGen.h | 2 +- Source/Core/VideoCommon/PixelShaderGen.cpp | 26 +++++++++++---------- Source/Core/VideoCommon/VertexShaderGen.cpp | 8 +++---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Source/Core/VideoCommon/LightingShaderGen.h b/Source/Core/VideoCommon/LightingShaderGen.h index 05f4e607c5..b28fe5b386 100644 --- a/Source/Core/VideoCommon/LightingShaderGen.h +++ b/Source/Core/VideoCommon/LightingShaderGen.h @@ -264,7 +264,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com GenerateLightShader(object, uid_data, i, lit_index, coloralpha); } } - object.Write("lacc = clamp(lacc, 0, 255);"); + object.Write("lacc = clamp(lacc, 0, 255);\n"); object.Write("%s%d = float4((mat * (lacc + (lacc >> 7))) >> 8) / 255.0;\n", dest, j); object.Write("}\n"); } diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index f7b63bfb30..77ccd0b683 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -124,8 +124,8 @@ static const char *tevAInputTable[] = static const char *tevRasTable[] = { - "iround(colors_0 * 255.0)", - "iround(colors_1 * 255.0)", + "iround(col0 * 255.0)", + "iround(col1 * 255.0)", "ERROR13", //2 "ERROR14", //3 "ERROR15", //4 @@ -331,8 +331,8 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T } else { - out.Write("centroid in float4 colors_02;\n"); - out.Write("centroid in float4 colors_12;\n"); + out.Write("centroid in float4 colors_0;\n"); + out.Write("centroid in float4 colors_1;\n"); // compute window position if needed because binding semantic WPOS is not widely supported // Let's set up attributes for (unsigned int i = 0; i < numTexgen; ++i) @@ -353,13 +353,6 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T for (unsigned int i = 0; i < numTexgen; ++i) out.Write("\tfloat3 uv%d = tex%d;\n", i, i); } - else - { - // On Mali, global variables must be initialized as constants. - // This is why we initialize these variables locally instead. - out.Write("\tfloat4 colors_0 = colors_02;\n"); - out.Write("\tfloat4 colors_1 = colors_12;\n"); - } out.Write("\tfloat4 rawpos = gl_FragCoord;\n"); } @@ -402,13 +395,22 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T "\tfloat3 ldir, h;\n" "\tfloat dist, dist2, attn;\n"); + // On GLSL, input variables must not be assigned to. + // This is why we declare these variables locally instead. + out.Write("\tfloat4 col0, col1;\n"); + // TODO: Our current constant usage code isn't able to handle more than one buffer. // So we can't mark the VS constant as used here. But keep them here as reference. //out.SetConstantsUsed(C_PLIGHT_COLORS, C_PLIGHT_COLORS+7); // TODO: Can be optimized further //out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+31); // TODO: Can be optimized further //out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3); uid_data->components = components; - GenerateLightingShader(out, uid_data->lighting, components, "colors_", "colors_"); + GenerateLightingShader(out, uid_data->lighting, components, "colors_", "col"); + } + else + { + out.Write("\tfloat4 col0 = colors_0;\n"); + out.Write("\tfloat4 col1 = colors_1;\n"); } // HACK to handle cases where the tex gen is not enabled diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 98ca1d8451..e30f28d463 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -93,8 +93,8 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ out.Write("centroid out float4 clipPos;\n"); if (g_ActiveConfig.bEnablePixelLighting) out.Write("centroid out float4 Normal;\n"); - out.Write("centroid out float4 colors_02;\n"); - out.Write("centroid out float4 colors_12;\n"); + out.Write("centroid out float4 colors_0;\n"); + out.Write("centroid out float4 colors_1;\n"); } out.Write("void main()\n{\n"); @@ -396,8 +396,8 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ out.Write("clipPos = o.clipPos;\n"); if (g_ActiveConfig.bEnablePixelLighting) out.Write("Normal = o.Normal;\n"); - out.Write("colors_02 = o.colors_0;\n"); - out.Write("colors_12 = o.colors_1;\n"); + out.Write("colors_0 = o.colors_0;\n"); + out.Write("colors_1 = o.colors_1;\n"); } out.Write("gl_Position = o.pos;\n");