From 71f9196d618099dfa0708f996e4753f8c0ea22cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 16 Jan 2021 12:56:04 +0100 Subject: [PATCH] VK: Re-apply the old Adreno driver bug workaround. Fixes #13910. Should likely fix issue #13923 too. --- GPU/Common/FragmentShaderGenerator.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index e4afd7868a23..3effac63a970 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -778,10 +778,21 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu // When testing against 0 (common), we can avoid some math. // 0.002 is approximately half of 1.0 / 255.0. if (colorTestFunc == GE_COMP_NOTEQUAL) { - WRITE(p, " if (v.r < 0.002 && v.g < 0.002 && v.b < 0.002) %s\n", discardStatement); + if (compat.shaderLanguage == GLSL_VULKAN) { + // Old workaround for Adreno driver bug. We could make this the main path actually + // since the math is roughly equivalent given the non-negative inputs. + WRITE(p, " if (v.r + v.g + v.b < 0.002) %s\n", discardStatement); + } else { + WRITE(p, " if (v.r < 0.002 && v.g < 0.002 && v.b < 0.002) %s\n", discardStatement); + } } else if (colorTestFunc != GE_COMP_NEVER) { - // Anything else is a test for == 0. - WRITE(p, " if (v.r > 0.002 || v.g > 0.002 || v.b > 0.002) %s\n", discardStatement); + if (compat.shaderLanguage == GLSL_VULKAN) { + // See the GE_COMP_NOTEQUAL case. + WRITE(p, " if (v.r + v.g + v.b > 0.002) %s\n", discardStatement); + } else { + // Anything else is a test for == 0. + WRITE(p, " if (v.r > 0.002 || v.g > 0.002 || v.b > 0.002) %s\n", discardStatement); + } } else { // NEVER has been logged as used by games, although it makes little sense - statically failing. // Maybe we could discard the drawcall, but it's pretty rare. Let's just statically discard here.