From 8dc3653ac9ec07040c8bcd0748c8040cf831d632 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 17 Dec 2014 23:44:05 +0100 Subject: [PATCH] VideoCommon: Don't pass structs between shader stages when geometry shaders are unsupported. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 39 ++++++++++++++------- Source/Core/VideoCommon/VertexShaderGen.cpp | 30 +++++++++++++++- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 8557f9e98b..77f24d115c 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -329,27 +329,42 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T } else { - out.Write("centroid in VS_OUTPUT o;\n"); + out.Write("centroid in float4 colors_02;\n"); + out.Write("centroid in float4 colors_12;\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) + { + out.Write("centroid in float3 uv%d;\n", i); + } + out.Write("centroid in float4 clipPos;\n"); + if (g_ActiveConfig.bEnablePixelLighting) + { + out.Write("centroid in float4 Normal;\n"); + } } out.Write("void main()\n{\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) + if (g_ActiveConfig.backend_info.bSupportsGeometryShaders) { - out.Write("\tfloat3 uv%d = o.tex%d;\n", i, i); - } - out.Write("\tfloat4 clipPos = o.clipPos;\n"); - if (g_ActiveConfig.bEnablePixelLighting) - { - out.Write("\tfloat4 Normal = o.Normal;\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) + { + out.Write("\tfloat3 uv%d = o.tex%d;\n", i, i); + } + out.Write("\tfloat4 clipPos = o.clipPos;\n"); + if (g_ActiveConfig.bEnablePixelLighting) + { + out.Write("\tfloat4 Normal = o.Normal;\n"); + } } // On Mali, global variables must be initialized as constants. // This is why we initialize these variables locally instead. - out.Write("\tfloat4 colors_0 = o.colors_0;\n"); - out.Write("\tfloat4 colors_1 = o.colors_1;\n"); + out.Write("\tfloat4 colors_0 = %s;\n", g_ActiveConfig.backend_info.bSupportsGeometryShaders ? "o.colors_0" : "colors_02"); + out.Write("\tfloat4 colors_1 = %s;\n", g_ActiveConfig.backend_info.bSupportsGeometryShaders ? "o.colors_1" : "colors_12"); out.Write("\tfloat4 rawpos = gl_FragCoord;\n"); } diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index bd033967ee..123f137ff2 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -80,10 +80,25 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ } else { - out.Write("centroid out VS_OUTPUT o; \n"); + // Let's set up attributes + for (size_t i = 0; i < 8; ++i) + { + if (i < xfmem.numTexGen.numTexGens) + { + out.Write("centroid out float3 uv%d;\n", i); + } + } + 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("void main()\n{\n"); + + if (!g_ActiveConfig.backend_info.bSupportsGeometryShaders) + out.Write("VS_OUTPUT o;\n"); } else // D3D { @@ -369,6 +384,19 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ if (api_type == API_OPENGL) { + if (!g_ActiveConfig.backend_info.bSupportsGeometryShaders) + { + // TODO: Pass structs between shader stages even if geometry shaders + // are not supported, however that will break GL 3.0 and 3.1 support. + for (unsigned int i = 0; i < xfmem.numTexGen.numTexGens; ++i) + out.Write("uv%d.xyz = o.tex%d;\n", i, i); + 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("gl_Position = o.pos;\n"); } else // D3D