Skip to content

Commit

Permalink
GS/HW: Minor shader optimization.
Browse files Browse the repository at this point in the history
Use saturate instead of min max, saturate is faster than min max.
  • Loading branch information
lightningterror committed Apr 21, 2024
1 parent 7e1900a commit 7dd7345
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
8 changes: 2 additions & 6 deletions bin/resources/shaders/dx11/tfx.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions pcsx2/GS/Renderers/Metal/tfx.metal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/ShaderCacheVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 7dd7345

Please sign in to comment.