From 7dd7345e08acba7e9fc42c6021c250e8906972ea Mon Sep 17 00:00:00 2001 From: lightningterror <18107717+lightningterror@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:26:27 +0200 Subject: [PATCH] GS/HW: Minor shader optimization. Use saturate instead of min max, saturate is faster than min max. --- bin/resources/shaders/dx11/tfx.fx | 8 ++------ pcsx2/GS/Renderers/Metal/tfx.metal | 5 +++-- pcsx2/ShaderCacheVersion.h | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index 668edde56a..3aa6f15044 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -898,7 +898,7 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) // We shouldn't clamp blend mix with blend hw 1 as we want alpha higher float C_clamped = C; if (PS_BLEND_MIX > 0 && PS_BLEND_HW != 1 && PS_BLEND_HW != 2) - C_clamped = min(C_clamped, 1.0f); + C_clamped = saturate(C_clamped); if (PS_BLEND_A == PS_BLEND_B) Color.rgb = D; @@ -953,17 +953,13 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) if (PS_BLEND_HW == 1) { // Needed for Cd * (As/Ad/F + 1) blending modes - Color.rgb = (float3)255.0f; } else if (PS_BLEND_HW == 2) { // Cd*As,Cd*Ad or Cd*F - float Alpha = PS_BLEND_C == 2 ? Af : As; - - Color.rgb = saturate((float3)Alpha - (float3)1.0f); - Color.rgb *= (float3)255.0f; + Color.rgb = saturate((float3)Alpha - (float3)1.0f) * (float3)255.0f; } else if (PS_BLEND_HW == 3 && PS_RTA_CORRECTION == 0) { diff --git a/pcsx2/GS/Renderers/Metal/tfx.metal b/pcsx2/GS/Renderers/Metal/tfx.metal index 0bf368170d..bdffe58994 100644 --- a/pcsx2/GS/Renderers/Metal/tfx.metal +++ b/pcsx2/GS/Renderers/Metal/tfx.metal @@ -967,7 +967,7 @@ struct PSMain // We shouldn't clamp blend mix with blend hw 1 as we want alpha higher float C_clamped = C; if (PS_BLEND_MIX > 0 && PS_BLEND_HW != 1 && PS_BLEND_HW != 2) - C_clamped = min(C_clamped, 1.f); + C_clamped = saturate(C_clamped); if (PS_BLEND_A == PS_BLEND_B) Color.rgb = D; @@ -1019,13 +1019,14 @@ struct PSMain } else { - // Needed for Cd * (As/Ad/F + 1) blending mdoes if (PS_BLEND_HW == 1) { + // Needed for Cd * (As/Ad/F + 1) blending modes Color.rgb = 255.f; } else if (PS_BLEND_HW == 2) { + // Cd*As,Cd*Ad or Cd*F float Alpha = PS_BLEND_C == 2 ? cb.alpha_fix : As; Color.rgb = saturate(Alpha - 1.f) * 255.f; } diff --git a/pcsx2/ShaderCacheVersion.h b/pcsx2/ShaderCacheVersion.h index b5c115fdf4..12a331b52d 100644 --- a/pcsx2/ShaderCacheVersion.h +++ b/pcsx2/ShaderCacheVersion.h @@ -3,4 +3,4 @@ /// Version number for GS and other shaders. Increment whenever any of the contents of the /// shaders change, to invalidate the cache. -static constexpr u32 SHADER_CACHE_VERSION = 45; +static constexpr u32 SHADER_CACHE_VERSION = 46;