From 4006a4b1435dd53f8f609dc8892126e4b5f41a74 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 3 Jan 2021 08:12:42 -0800 Subject: [PATCH] GPU: Ignore color write mask if unusable. We unconditionally attempt to use a shader with color write mask, so we can't just refuse to generate a shader - it'll mean non-supporting devices get no shader at all. It's better to continue ignoring the mask in that case. --- GPU/Common/FragmentShaderGenerator.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index 22af75c14a..b57234e58c 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -81,12 +81,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu bool doFlatShading = id.Bit(FS_BIT_FLATSHADE) && !bugs.Has(Draw::Bugs::BROKEN_FLAT_IN_SHADER); bool shaderDepal = id.Bit(FS_BIT_SHADER_DEPAL); bool bgraTexture = id.Bit(FS_BIT_BGRA_TEXTURE); - bool colorWriteMask = id.Bit(FS_BIT_COLOR_WRITEMASK); - - if (colorWriteMask && !compat.bitwiseOps) { - *errorString = "Color Write Mask requires bitwise ops"; - return false; - } + bool colorWriteMask = id.Bit(FS_BIT_COLOR_WRITEMASK) && compat.bitwiseOps; GEComparison alphaTestFunc = (GEComparison)id.Bits(FS_BIT_ALPHA_TEST_FUNC, 3); GEComparison colorTestFunc = (GEComparison)id.Bits(FS_BIT_COLOR_TEST_FUNC, 2); @@ -299,7 +294,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR); } } else if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) { - if (shaderDepal && gl_extensions.IsGLES) { + if ((shaderDepal || colorWriteMask) && gl_extensions.IsGLES) { WRITE(p, "precision highp int;\n"); } @@ -819,10 +814,9 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, " vec3 colortest = roundAndScaleTo255v(v.rgb);\n"); WRITE(p, " if ((colortest.r %s u_alphacolorref.r) && (colortest.g %s u_alphacolorref.g) && (colortest.b %s u_alphacolorref.b)) %s\n", test, test, test, discardStatement); } else if (compat.bitwiseOps) { - // Apparently GLES3 does not support vector bitwise ops. WRITE(p, " ivec3 v_scaled = roundAndScaleTo255iv(v.rgb);\n"); if (compat.shaderLanguage == GLSL_VULKAN) { - // TODO: Use this for GL as well? + // Apparently GLES3 does not support vector bitwise ops, but Vulkan does? WRITE(p, " if ((v_scaled & u_alphacolormask.rgb) %s (u_alphacolorref.rgb & u_alphacolormask.rgb)) %s\n", colorTestFuncs[colorTestFunc], discardStatement); } else { const char *maskedFragColor = "ivec3(v_scaled.r & u_alphacolormask.r, v_scaled.g & u_alphacolormask.g, v_scaled.b & u_alphacolormask.b)";