From ae14afd5f76f47eb8afc2ab12af68216c1f3e423 Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Tue, 1 Feb 2022 19:19:20 +0100 Subject: [PATCH] GS-hw: Combine BLEND_C_CLR2_AF and BLEND_C_CLR3_AS in one shader bit. Free a shader bit. --- bin/resources/shaders/dx11/tfx.fx | 7 +++---- bin/resources/shaders/opengl/tfx_fs.glsl | 7 +++---- bin/resources/shaders/vulkan/tfx.glsl | 7 +++---- pcsx2/GS/Renderers/Common/GSDevice.cpp | 8 ++++---- pcsx2/GS/Renderers/Common/GSDevice.h | 4 ++-- pcsx2/GS/Renderers/HW/GSRendererNew.cpp | 17 +++++++++-------- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index 818cc0dd18..7b679c14bd 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -769,17 +769,16 @@ void ps_blend(inout float4 Color, float As, float2 pos_xy) Color.rgb = (float3)255.0f; } - else if (PS_CLR_HW == 2 || PS_CLR_HW == 3) + else if (PS_CLR_HW == 2) { - // PS_CLR_HW 2 Af, PS_CLR_HW 3 As // Cd*As or Cd*F - float Alpha = PS_CLR_HW == 2 ? Af : As; + float Alpha = PS_BLEND_C == 2 ? Af : As; Color.rgb = max((float3)0.0f, (Alpha - (float3)1.0f)); Color.rgb *= (float3)255.0f; } - else if (PS_CLR_HW == 4) + else if (PS_CLR_HW == 3) { // Needed for Cs*Ad, Cs*Ad + Cd, Cd - Cs*Ad // Multiply Color.rgb by (255/128) to compensate for wrong Ad/255 value diff --git a/bin/resources/shaders/opengl/tfx_fs.glsl b/bin/resources/shaders/opengl/tfx_fs.glsl index 584cb1a99f..57bd9bba1e 100644 --- a/bin/resources/shaders/opengl/tfx_fs.glsl +++ b/bin/resources/shaders/opengl/tfx_fs.glsl @@ -729,11 +729,10 @@ void ps_blend(inout vec4 Color, float As) // Needed for Cd * (As/Ad/F + 1) blending modes #if PS_CLR_HW == 1 Color.rgb = vec3(255.0f); -#elif PS_CLR_HW == 2 || PS_CLR_HW == 3 - // PS_CLR_HW 2 Af, PS_CLR_HW 3 As +#elif PS_CLR_HW == 2 // Cd*As or Cd*F -#if PS_CLR_HW == 2 +#if PS_BLEND_C == 2 float Alpha = Af; #else float Alpha = As; @@ -741,7 +740,7 @@ void ps_blend(inout vec4 Color, float As) Color.rgb = max(vec3(0.0f), (Alpha - vec3(1.0f))); Color.rgb *= vec3(255.0f); -#elif PS_CLR_HW == 4 +#elif PS_CLR_HW == 3 // Needed for Cs*Ad, Cs*Ad + Cd, Cd - Cs*Ad // Multiply Color.rgb by (255/128) to compensate for wrong Ad/255 value diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl index 3a29fd76ae..2b6c97db2a 100644 --- a/bin/resources/shaders/vulkan/tfx.glsl +++ b/bin/resources/shaders/vulkan/tfx.glsl @@ -1067,11 +1067,10 @@ void ps_blend(inout vec4 Color, float As) #if PS_CLR_HW == 1 // Needed for Cd * (As/Ad/F + 1) blending modes Color.rgb = vec3(255.0f); - #elif PS_CLR_HW == 2 || PS_CLR_HW == 3 - // PS_CLR_HW 2 Af, PS_CLR_HW 3 As + #elif PS_CLR_HW == 2 // Cd*As or Cd*F - #if PS_CLR_HW == 2 + #if PS_BLEND_C == 2 float Alpha = Af; #else float Alpha = As; @@ -1079,7 +1078,7 @@ void ps_blend(inout vec4 Color, float As) Color.rgb = max(vec3(0.0f), (Alpha - vec3(1.0f))); Color.rgb *= vec3(255.0f); - #elif PS_CLR_HW == 4 + #elif PS_CLR_HW == 3 // Needed for Cs*Ad, Cs*Ad + Cd, Cd - Cs*Ad // Multiply Color.rgb by (255/128) to compensate for wrong Ad/255 value diff --git a/pcsx2/GS/Renderers/Common/GSDevice.cpp b/pcsx2/GS/Renderers/Common/GSDevice.cpp index 2b2752ca2a..8dee8b8a2a 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.cpp +++ b/pcsx2/GS/Renderers/Common/GSDevice.cpp @@ -534,8 +534,8 @@ std::array GSDevice::m_blendMap = { BLEND_ACCU , OP_ADD , SRC1_ALPHA , CONST_ONE} , //?0201: (Cs - 0)*As + Cd ==> Cs*As + Cd { BLEND_NO_REC , OP_ADD , SRC1_ALPHA , CONST_ZERO} , // 0202: (Cs - 0)*As + 0 ==> Cs*As { BLEND_A_MAX , OP_ADD , CONST_ONE , CONST_ZERO} , //*0210: (Cs - 0)*Ad + Cs ==> Cs*(Ad + 1) - { BLEND_C_CLR4 , OP_ADD , DST_ALPHA , CONST_ONE} , // 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd - { BLEND_C_CLR4 , OP_ADD , DST_ALPHA , CONST_ZERO} , // 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad + { BLEND_C_CLR3 , OP_ADD , DST_ALPHA , CONST_ONE} , // 0211: (Cs - 0)*Ad + Cd ==> Cs*Ad + Cd + { BLEND_C_CLR3 , OP_ADD , DST_ALPHA , CONST_ZERO} , // 0212: (Cs - 0)*Ad + 0 ==> Cs*Ad { BLEND_NO_REC | BLEND_A_MAX , OP_ADD , CONST_ONE , CONST_ZERO} , //*0220: (Cs - 0)*F + Cs ==> Cs*(F + 1) { BLEND_ACCU , OP_ADD , CONST_COLOR , CONST_ONE} , //?0221: (Cs - 0)*F + Cd ==> Cs*F + Cd { BLEND_NO_REC , OP_ADD , CONST_COLOR , CONST_ZERO} , // 0222: (Cs - 0)*F + 0 ==> Cs*F @@ -559,7 +559,7 @@ std::array GSDevice::m_blendMap = { BLEND_NO_REC , OP_ADD , CONST_ZERO , CONST_ZERO} , // 1122: (Cd - Cd)*F + 0 ==> 0 { 0 , OP_ADD , CONST_ONE , SRC1_ALPHA} , // 1200: (Cd - 0)*As + Cs ==> Cs + Cd*As { BLEND_C_CLR1 , OP_ADD , DST_COLOR , SRC1_ALPHA} , //#1201: (Cd - 0)*As + Cd ==> Cd*(1 + As) - { BLEND_C_CLR3_AS , OP_ADD , DST_COLOR , SRC1_ALPHA} , // 1202: (Cd - 0)*As + 0 ==> Cd*As + { BLEND_C_CLR2_AS , OP_ADD , DST_COLOR , SRC1_ALPHA} , // 1202: (Cd - 0)*As + 0 ==> Cd*As { 0 , OP_ADD , CONST_ONE , DST_ALPHA} , // 1210: (Cd - 0)*Ad + Cs ==> Cs + Cd*Ad { BLEND_C_CLR1 , OP_ADD , DST_COLOR , DST_ALPHA} , //#1211: (Cd - 0)*Ad + Cd ==> Cd*(1 + Ad) { 0 , OP_ADD , CONST_ZERO , DST_ALPHA} , // 1212: (Cd - 0)*Ad + 0 ==> Cd*Ad @@ -570,7 +570,7 @@ std::array GSDevice::m_blendMap = { BLEND_ACCU , OP_REV_SUBTRACT , SRC1_ALPHA , CONST_ONE} , //?2001: (0 - Cs)*As + Cd ==> Cd - Cs*As { BLEND_NO_REC , OP_REV_SUBTRACT , SRC1_ALPHA , CONST_ZERO} , // 2002: (0 - Cs)*As + 0 ==> 0 - Cs*As { 0 , OP_ADD , INV_DST_ALPHA , CONST_ZERO} , // 2010: (0 - Cs)*Ad + Cs ==> Cs*(1 - Ad) - { BLEND_C_CLR4 , OP_REV_SUBTRACT , DST_ALPHA , CONST_ONE} , // 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad + { BLEND_C_CLR3 , OP_REV_SUBTRACT , DST_ALPHA , CONST_ONE} , // 2011: (0 - Cs)*Ad + Cd ==> Cd - Cs*Ad { 0 , OP_REV_SUBTRACT , DST_ALPHA , CONST_ZERO} , // 2012: (0 - Cs)*Ad + 0 ==> 0 - Cs*Ad { BLEND_NO_REC , OP_ADD , INV_CONST_COLOR , CONST_ZERO} , // 2020: (0 - Cs)*F + Cs ==> Cs*(1 - F) { BLEND_ACCU , OP_REV_SUBTRACT , CONST_COLOR , CONST_ONE} , //?2021: (0 - Cs)*F + Cd ==> Cd - Cs*F diff --git a/pcsx2/GS/Renderers/Common/GSDevice.h b/pcsx2/GS/Renderers/Common/GSDevice.h index d8ec5a333e..dbc1912cac 100644 --- a/pcsx2/GS/Renderers/Common/GSDevice.h +++ b/pcsx2/GS/Renderers/Common/GSDevice.h @@ -122,8 +122,8 @@ enum HWBlendFlags BLEND_A_MAX = 0x80, // Impossible blending uses coeff bigger than 1 BLEND_C_CLR1 = 0x100, // Clear color blending (use directly the destination color as blending factor) BLEND_C_CLR2_AF = 0x200, // Clear color blending (use directly the destination color as blending factor) - BLEND_C_CLR3_AS = 0x400, // Clear color blending (use directly the destination color as blending factor) - BLEND_C_CLR4 = 0x800, // Multiply Cs by (255/128) to compensate for wrong Ad/255 value, should be Ad/128 + BLEND_C_CLR2_AS = 0x400, // Clear color blending (use directly the destination color as blending factor) + BLEND_C_CLR3 = 0x800, // Multiply Cs by (255/128) to compensate for wrong Ad/255 value, should be Ad/128 BLEND_NO_REC = 0x1000, // Doesn't require sampling of the RT as a texture BLEND_ACCU = 0x2000, // Allow to use a mix of SW and HW blending to keep the best of the 2 worlds }; diff --git a/pcsx2/GS/Renderers/HW/GSRendererNew.cpp b/pcsx2/GS/Renderers/HW/GSRendererNew.cpp index d8f0273be5..871dabc145 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererNew.cpp +++ b/pcsx2/GS/Renderers/HW/GSRendererNew.cpp @@ -603,7 +603,7 @@ void GSRendererNew::EmulateBlending(bool& DATE_PRIMID, bool& DATE_BARRIER) // Blend can be done on hw. As and F cases should be accurate. // BLEND_C_CLR1 with Ad, BLEND_C_CLR4 Cs > 0.5f will require sw blend. // BLEND_C_CLR1 with As/F, BLEND_C_CLR2_AF, BLEND_C_CLR3_AS can be done in hw. - const bool clr_blend = !!(blend_flag & (BLEND_C_CLR1 | BLEND_C_CLR2_AF | BLEND_C_CLR3_AS | BLEND_C_CLR4)); + const bool clr_blend = !!(blend_flag & (BLEND_C_CLR1 | BLEND_C_CLR2_AF | BLEND_C_CLR2_AS | BLEND_C_CLR3)); // FBMASK already reads the fb so it is safe to enable sw blend when there is no overlap. const bool fbmask_no_overlap = m_conf.require_one_barrier && (m_prim_overlap == PRIM_OVERLAP_NO); @@ -793,19 +793,20 @@ void GSRendererNew::EmulateBlending(bool& DATE_PRIMID, bool& DATE_BARRIER) { m_conf.ps.clr_hw = 1; } - else if (blend_flag & BLEND_C_CLR2_AF) + else if (blend_flag & (BLEND_C_CLR2_AF | BLEND_C_CLR2_AS)) { - m_conf.cb_ps.TA_MaxDepth_Af.a = static_cast(ALPHA.FIX) / 128.0f; + if (ALPHA.C == 2) + { + m_conf.ps.blend_c = 2; + m_conf.cb_ps.TA_MaxDepth_Af.a = static_cast(ALPHA.FIX) / 128.0f; + } + m_conf.ps.clr_hw = 2; } - else if (blend_flag & BLEND_C_CLR3_AS) + else if (blend_flag & BLEND_C_CLR3) { m_conf.ps.clr_hw = 3; } - else if (blend_flag & BLEND_C_CLR4) - { - m_conf.ps.clr_hw = 4; - } if (m_conf.ps.dfmt == 1 && ALPHA.C == 1) {