From 3c92054a6e93495145e0d145a9b4d56261fe7f29 Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Sat, 8 Jan 2022 18:43:28 +0100 Subject: [PATCH] GS-hw: Move PABE shader bit to the top of sw blending. Early return when there is no sw blending, no need to run the blend code. Optimization. --- bin/resources/shaders/dx11/tfx.fx | 12 ++++++++---- bin/resources/shaders/opengl/tfx_fs.glsl | 13 ++++++++----- bin/resources/shaders/vulkan/tfx.glsl | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index 6079f8df90..c52e16b174 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -727,6 +727,14 @@ void ps_blend(inout float4 Color, float As, float2 pos_xy) { if (SW_BLEND) { + // PABE + if (PS_PABE) + { + // No blending so early exit + if (As < 1.0f) + return; + } + float4 RT = trunc(RtSampler.Load(int3(pos_xy, 0)) * 255.0f + 0.1f); float Ad = (PS_DFMT == FMT_24) ? 1.0f : RT.a / 128.0f; @@ -744,10 +752,6 @@ void ps_blend(inout float4 Color, float As, float2 pos_xy) C = min(C, (float)1.0f); Color.rgb = (PS_BLEND_A == PS_BLEND_B) ? D : trunc(((A - B) * C) + D); - - // PABE - if (PS_PABE) - Color.rgb = (As >= 1.0f) ? Color.rgb : Cs; } } diff --git a/bin/resources/shaders/opengl/tfx_fs.glsl b/bin/resources/shaders/opengl/tfx_fs.glsl index 9baba090c0..70b8a61d76 100644 --- a/bin/resources/shaders/opengl/tfx_fs.glsl +++ b/bin/resources/shaders/opengl/tfx_fs.glsl @@ -656,6 +656,14 @@ void ps_color_clamp_wrap(inout vec3 C) void ps_blend(inout vec4 Color, float As) { #if SW_BLEND + + // PABE +#if PS_PABE + // No blending so early exit + if (As < 1.0f) + return; +#endif + vec4 RT = trunc(texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0) * 255.0f + 0.1f); #if PS_DFMT == FMT_24 @@ -713,11 +721,6 @@ void ps_blend(inout vec4 Color, float As) Color.rgb = trunc((A - B) * C + D); #endif - // PABE -#if PS_PABE - Color.rgb = (As >= 1.0f) ? Color.rgb : Cs; -#endif - #endif } diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl index 7655f51575..1012dee480 100644 --- a/bin/resources/shaders/vulkan/tfx.glsl +++ b/bin/resources/shaders/vulkan/tfx.glsl @@ -989,11 +989,19 @@ void ps_color_clamp_wrap(inout vec3 C) void ps_blend(inout vec4 Color, float As) { #if SW_BLEND + + // PABE + #if PS_PABE + // No blending so early exit + if (As < 1.0f) + return; + #endif + #if PS_FEEDBACK_LOOP_IS_NEEDED - vec4 RT = trunc(subpassLoad(RtSampler) * 255.0f + 0.1f); + vec4 RT = trunc(subpassLoad(RtSampler) * 255.0f + 0.1f); #else - // Not used, but we define it to make the selection below simpler. - vec4 RT = vec4(0.0f); + // Not used, but we define it to make the selection below simpler. + vec4 RT = vec4(0.0f); #endif #if PS_DFMT == FMT_24 @@ -1051,11 +1059,6 @@ void ps_blend(inout vec4 Color, float As) Color.rgb = trunc((A - B) * C + D); #endif - // PABE - #if PS_PABE - Color.rgb = (As >= 1.0f) ? Color.rgb : Cs; - #endif - #endif }