diff options
| author | Stenzek <stenzek@gmail.com> | 2019-01-23 18:11:17 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2019-01-23 18:34:22 +1000 |
| commit | 68cb24172b4e76c96f38b7a44d8d5d45e4adc900 (patch) | |
| tree | c2d71004767237e71658ea157b4c0d9e6447f265 /Source/Core/VideoCommon/VertexShaderGen.cpp | |
| parent | 3627ef8a0489765eb10ab29a7988866b52493239 (diff) | |
ShaderGen: Omit some unused varyings when possible
Removes the clipPos varying unless slow-depth is used, and the
clipDistance varyings if geometry shaders are not used.
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderGen.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index ccec60731c..2c89b368ad 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -98,7 +98,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho out.Write("};\n"); out.Write("struct VS_OUTPUT {\n"); - GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, ""); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, host_config, ""); out.Write("};\n"); if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) @@ -132,7 +132,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) { out.Write("VARYING_LOCATION(0) out VertexData {\n"); - GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, host_config, GetInterpolationQualifier(msaa, ssaa, true, false)); out.Write("} vs;\n"); } @@ -146,7 +146,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho out.Write("%s out float3 tex%u;\n", GetInterpolationQualifier(msaa, ssaa), i); } } - out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + if (!host_config.fast_depth_calc) + out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); if (per_pixel_lighting) { out.Write("%s out float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); @@ -398,7 +399,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho } // clipPos/w needs to be done in pixel shader, not here - out.Write("o.clipPos = o.pos;\n"); + if (!host_config.fast_depth_calc) + out.Write("o.clipPos = o.pos;\n"); if (per_pixel_lighting) { @@ -422,8 +424,13 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho // We adjust our depth value for clipping purposes to match the perspective projection in the // software backend, which is a hack to fix Sonic Adventure and Unleashed games. out.Write("float clipDepth = o.pos.z * (1.0 - 1e-7);\n"); - out.Write("o.clipDist0 = clipDepth + o.pos.w;\n"); // Near: z < -w - out.Write("o.clipDist1 = -clipDepth;\n"); // Far: z > 0 + out.Write("float clipDist0 = clipDepth + o.pos.w;\n"); // Near: z < -w + out.Write("float clipDist1 = -clipDepth;\n"); // Far: z > 0 + if (host_config.backend_geometry_shaders) + { + out.Write("o.clipDist0 = clipDist0;\n"); + out.Write("o.clipDist1 = clipDist1;\n"); + } } // Write the true depth value. If the game uses depth textures, then the pixel shader will @@ -487,7 +494,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho { if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) { - AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, per_pixel_lighting); + AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, host_config); } else { @@ -495,7 +502,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho // are not supported, however that will require at least OpenGL 3.2 support. for (unsigned int i = 0; i < uid_data->numTexGens; ++i) out.Write("tex%d.xyz = o.tex%d;\n", i, i); - out.Write("clipPos = o.clipPos;\n"); + if (!host_config.fast_depth_calc) + out.Write("clipPos = o.clipPos;\n"); if (per_pixel_lighting) { out.Write("Normal = o.Normal;\n"); @@ -507,8 +515,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& ho if (host_config.backend_depth_clamp) { - out.Write("gl_ClipDistance[0] = o.clipDist0;\n"); - out.Write("gl_ClipDistance[1] = o.clipDist1;\n"); + out.Write("gl_ClipDistance[0] = clipDist0;\n"); + out.Write("gl_ClipDistance[1] = clipDist1;\n"); } // Vulkan NDC space has Y pointing down (right-handed NDC space). |
