From 608799f1e454f8473e5709204adb544eac52ddca Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 28 Feb 2022 00:04:31 +0100 Subject: [PATCH] PixelShaderGen: Check uid_data for use_shader_logic_op On devices which have hardware support for dual source blending but not logic ops, this lets us skip performing the framebuffer fetch in situations where the game isn't actually using logic ops. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 49 ++++++++++------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index ddb03f8e96..18834339f4 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -944,9 +944,9 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DUAL_SOURCE_BLENDING) || uid_data->useDstAlpha); const bool use_shader_blend = - !use_dual_source && (uid_data->useDstAlpha && host_config.backend_shader_framebuffer_fetch); - const bool use_shader_logic_op = - !host_config.backend_logic_op && host_config.backend_shader_framebuffer_fetch; + !use_dual_source && uid_data->useDstAlpha && host_config.backend_shader_framebuffer_fetch; + const bool use_shader_logic_op = !host_config.backend_logic_op && uid_data->logic_op_enable && + host_config.backend_shader_framebuffer_fetch; if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) { @@ -1949,30 +1949,27 @@ static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data) static void WriteLogicOp(ShaderCode& out, const pixel_shader_uid_data* uid_data) { - if (uid_data->logic_op_enable) - { - static constexpr std::array logic_op_mode{ - "int4(0, 0, 0, 0)", // CLEAR - "prev & fb_value", // AND - "prev & ~fb_value", // AND_REVERSE - "prev", // COPY - "~prev & fb_value", // AND_INVERTED - "fb_value", // NOOP - "prev ^ fb_value", // XOR - "prev | fb_value", // OR - "~(prev | fb_value)", // NOR - "~(prev ^ fb_value)", // EQUIV - "~fb_value", // INVERT - "prev | ~fb_value", // OR_REVERSE - "~prev", // COPY_INVERTED - "~prev | fb_value", // OR_INVERTED - "~(prev & fb_value)", // NAND - "int4(255, 255, 255, 255)", // SET - }; + static constexpr std::array logic_op_mode{ + "int4(0, 0, 0, 0)", // CLEAR + "prev & fb_value", // AND + "prev & ~fb_value", // AND_REVERSE + "prev", // COPY + "~prev & fb_value", // AND_INVERTED + "fb_value", // NOOP + "prev ^ fb_value", // XOR + "prev | fb_value", // OR + "~(prev | fb_value)", // NOR + "~(prev ^ fb_value)", // EQUIV + "~fb_value", // INVERT + "prev | ~fb_value", // OR_REVERSE + "~prev", // COPY_INVERTED + "~prev | fb_value", // OR_INVERTED + "~(prev & fb_value)", // NAND + "int4(255, 255, 255, 255)", // SET + }; - out.Write("\tint4 fb_value = iround(initial_ocol0 * 255.0);\n"); - out.Write("\tprev = {};\n", logic_op_mode[uid_data->logic_op_mode]); - } + out.Write("\tint4 fb_value = iround(initial_ocol0 * 255.0);\n"); + out.Write("\tprev = {};\n", logic_op_mode[uid_data->logic_op_mode]); } static void WriteColor(ShaderCode& out, APIType api_type, const pixel_shader_uid_data* uid_data,