GS/HW: Minor shader optimization.

Use saturate instead of min max, saturate is faster than min max.
This commit is contained in:
lightningterror 2024-04-11 15:26:27 +02:00
parent 7e1900a8a1
commit 7dd7345e08
3 changed files with 6 additions and 9 deletions

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;