From 1d61041985ddfea3662855a89dcc930515a41c0c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 23 Jan 2019 18:12:13 +1000 Subject: [PATCH] ShaderGen: Don't use interface blocks on Vulkan without GS Doing so causes the Adreno driver to choke and spew errors about too many output locations/components, when clearly we're under the limit. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 23 ++++++++++------ Source/Core/VideoCommon/UberShaderPixel.cpp | 26 ++++++++++++------ Source/Core/VideoCommon/UberShaderVertex.cpp | 29 +++++++++++++------- Source/Core/VideoCommon/VertexShaderGen.cpp | 29 +++++++++++--------- 4 files changed, 66 insertions(+), 41 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index ce42363d19..9fbbb2cda4 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -587,8 +587,7 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host if (uid_data->per_pixel_depth) out.Write("#define depth gl_FragDepth\n"); - // We need to always use output blocks for Vulkan, but geometry shaders are also optional. - if (host_config.backend_geometry_shaders || ApiType == APIType::Vulkan) + if (host_config.backend_geometry_shaders) { out.Write("VARYING_LOCATION(0) in VertexData {\n"); GenerateVSOutputMembers(out, ApiType, uid_data->genMode_numtexgens, host_config, @@ -601,20 +600,26 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host } else { - out.Write("%s in float4 colors_0;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s in float4 colors_1;\n", GetInterpolationQualifier(msaa, ssaa)); - // compute window position if needed because binding semantic WPOS is not widely supported // Let's set up attributes + u32 counter = 0; + out.Write("VARYING_LOCATION(%u) %s in float4 colors_0;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float4 colors_1;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); for (unsigned int i = 0; i < uid_data->genMode_numtexgens; ++i) { - out.Write("%s in float3 tex%d;\n", GetInterpolationQualifier(msaa, ssaa), i); + out.Write("VARYING_LOCATION(%u) %s in float3 tex%d;\n", counter++, + GetInterpolationQualifier(msaa, ssaa), i); } if (!host_config.fast_depth_calc) - out.Write("%s in float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float4 clipPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); if (per_pixel_lighting) { - out.Write("%s in float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s in float3 WorldPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float3 Normal;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float3 WorldPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); } } diff --git a/Source/Core/VideoCommon/UberShaderPixel.cpp b/Source/Core/VideoCommon/UberShaderPixel.cpp index 0d5d733fa2..27e69808dc 100644 --- a/Source/Core/VideoCommon/UberShaderPixel.cpp +++ b/Source/Core/VideoCommon/UberShaderPixel.cpp @@ -103,7 +103,7 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config, if (per_pixel_depth) out.Write("#define depth gl_FragDepth\n"); - if (host_config.backend_geometry_shaders || ApiType == APIType::Vulkan) + if (host_config.backend_geometry_shaders) { out.Write("VARYING_LOCATION(0) in VertexData {\n"); GenerateVSOutputMembers(out, ApiType, numTexgen, host_config, @@ -116,18 +116,26 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config, } else { - out.Write("%s in float4 colors_0;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s in float4 colors_1;\n", GetInterpolationQualifier(msaa, ssaa)); - // compute window position if needed because binding semantic WPOS is not widely supported // Let's set up attributes - for (u32 i = 0; i < numTexgen; ++i) - out.Write("%s in float3 tex%d;\n", GetInterpolationQualifier(msaa, ssaa), i); + u32 counter = 0; + out.Write("VARYING_LOCATION(%u) %s in float4 colors_0;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float4 colors_1;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + for (unsigned int i = 0; i < numTexgen; ++i) + { + out.Write("VARYING_LOCATION(%u) %s in float3 tex%d;\n", counter++, + GetInterpolationQualifier(msaa, ssaa), i); + } if (!host_config.fast_depth_calc) - out.Write("%s in float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float4 clipPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); if (per_pixel_lighting) { - out.Write("%s in float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s in float3 WorldPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float3 Normal;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s in float3 WorldPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); } } } diff --git a/Source/Core/VideoCommon/UberShaderVertex.cpp b/Source/Core/VideoCommon/UberShaderVertex.cpp index af2b12110c..4032e0df40 100644 --- a/Source/Core/VideoCommon/UberShaderVertex.cpp +++ b/Source/Core/VideoCommon/UberShaderVertex.cpp @@ -63,8 +63,7 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config, for (int i = 0; i < 8; ++i) out.Write("ATTRIBUTE_LOCATION(%d) in float3 rawtex%d;\n", SHADER_TEXTURE0_ATTRIB + i, i); - // We need to always use output blocks for Vulkan, but geometry shaders are also optional. - if (host_config.backend_geometry_shaders || ApiType == APIType::Vulkan) + if (host_config.backend_geometry_shaders) { out.Write("VARYING_LOCATION(0) out VertexData {\n"); GenerateVSOutputMembers(out, ApiType, numTexgen, host_config, @@ -74,18 +73,28 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config, else { // Let's set up attributes + u32 counter = 0; + out.Write("VARYING_LOCATION(%u) %s out float4 colors_0;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float4 colors_1;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); for (u32 i = 0; i < numTexgen; ++i) - out.Write("%s out float3 tex%u;\n", GetInterpolationQualifier(msaa, ssaa), i); - + { + out.Write("VARYING_LOCATION(%u) %s out float3 tex%u;\n", counter++, + GetInterpolationQualifier(msaa, ssaa), i); + } if (!host_config.fast_depth_calc) - out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + { + out.Write("VARYING_LOCATION(%u) %s out float4 clipPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + } if (per_pixel_lighting) { - out.Write("%s out float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s out float3 WorldPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float3 Normal;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float3 WorldPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); } - out.Write("%s out float4 colors_0;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s out float4 colors_1;\n", GetInterpolationQualifier(msaa, ssaa)); } out.Write("void main()\n{\n"); @@ -276,7 +285,7 @@ ShaderCode GenVertexShader(APIType ApiType, const ShaderHostConfig& host_config, if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan) { - if (host_config.backend_geometry_shaders || ApiType == APIType::Vulkan) + if (host_config.backend_geometry_shaders) { AssignVSOutputMembers(out, "vs", "o", numTexgen, host_config); } diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 2c89b368ad..678df11a0e 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -128,8 +128,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho } } - // We need to always use output blocks for Vulkan, but geometry shaders are also optional. - if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) + if (host_config.backend_geometry_shaders) { out.Write("VARYING_LOCATION(0) out VertexData {\n"); GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, host_config, @@ -139,22 +138,26 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho else { // Let's set up attributes - for (u32 i = 0; i < 8; ++i) + u32 counter = 0; + out.Write("VARYING_LOCATION(%u) %s out float4 colors_0;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float4 colors_1;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + for (u32 i = 0; i < uid_data->numTexGens; ++i) { - if (i < uid_data->numTexGens) - { - out.Write("%s out float3 tex%u;\n", GetInterpolationQualifier(msaa, ssaa), i); - } + out.Write("VARYING_LOCATION(%u) %s out float3 tex%u;\n", counter++, + GetInterpolationQualifier(msaa, ssaa), i); } if (!host_config.fast_depth_calc) - out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float4 clipPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); if (per_pixel_lighting) { - out.Write("%s out float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s out float3 WorldPos;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float3 Normal;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); + out.Write("VARYING_LOCATION(%u) %s out float3 WorldPos;\n", counter++, + GetInterpolationQualifier(msaa, ssaa)); } - out.Write("%s out float4 colors_0;\n", GetInterpolationQualifier(msaa, ssaa)); - out.Write("%s out float4 colors_1;\n", GetInterpolationQualifier(msaa, ssaa)); } out.Write("void main()\n{\n"); @@ -492,7 +495,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) { - if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) + if (host_config.backend_geometry_shaders) { AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, host_config); }