diff --git a/bin/resources/shaders/dx11/tfx.fx b/bin/resources/shaders/dx11/tfx.fx index d6ee87eaea..532e1186cd 100644 --- a/bin/resources/shaders/dx11/tfx.fx +++ b/bin/resources/shaders/dx11/tfx.fx @@ -1177,7 +1177,15 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) As_rgba.rgb = (float3)1.0f; } - float4 RT = SW_BLEND_NEEDS_RT ? RtLoad(int2(pos_xy)) : (float4)0.0f; + float4 RT = (float4)0.0f; + if (SW_BLEND_NEEDS_RT) + { + RT = RtLoad(int2(pos_xy)); + float color_multi = PS_COLCLIP_HW ? 65535.0f : 255.0f; + float alpha_multi = PS_RTA_CORRECTION ? 128.0f : 255.0f; + RT.rgb = trunc(RT.rgb * color_multi + 0.1f); + RT.a = trunc(RT.a * alpha_multi + 0.1f); + } if (PS_SHUFFLE && SW_BLEND_NEEDS_RT) { @@ -1198,9 +1206,8 @@ void ps_blend(inout float4 Color, inout float4 As_rgba, float2 pos_xy) } } - float Ad = PS_RTA_CORRECTION ? trunc(RT.a * 128.0f + 0.1f) / 128.0f : trunc(RT.a * 255.0f + 0.1f) / 128.0f; - float color_multi = PS_COLCLIP_HW ? 65535.0f : 255.0f; - float3 Cd = trunc(RT.rgb * color_multi + 0.1f); + float Ad = RT.a / 128.0f; + float3 Cd = RT.rgb; float3 Cs = Color.rgb; float3 A = (PS_BLEND_A == 0) ? Cs : ((PS_BLEND_A == 1) ? Cd : (float3)0.0f); diff --git a/bin/resources/shaders/opengl/tfx_fs.glsl b/bin/resources/shaders/opengl/tfx_fs.glsl index 0beee27060..a119f855d2 100644 --- a/bin/resources/shaders/opengl/tfx_fs.glsl +++ b/bin/resources/shaders/opengl/tfx_fs.glsl @@ -1026,38 +1026,40 @@ float As = As_rgba.a; #if SW_BLEND_NEEDS_RT vec4 RT = sample_from_rt(); + #if PS_COLCLIP_HW + float color_multi = 65535.0f; + #else + float color_multi = 255.0f; + #endif + #if PS_RTA_CORRECTION + float alpha_multi = 128.0f; + #else + float alpha_multi = 255.0f; + #endif + RT.rgb = trunc(RT.rgb * color_multi + 0.1f); + RT.a = trunc(RT.a * alpha_multi + 0.1f); #else // Not used, but we define it to make the selection below simpler. vec4 RT = vec4(0.0f); #endif - #if PS_RTA_CORRECTION - float Ad = trunc(RT.a * 128.0f + 0.1f) / 128.0f; +#if PS_SHUFFLE && SW_BLEND_NEEDS_RT + uvec4 denorm_rt = uvec4(RT); + #if (PS_PROCESS_BA & SHUFFLE_WRITE) + RT.r = float((denorm_rt.b << 3) & 0xF8u); + RT.g = float(((denorm_rt.b >> 2) & 0x38u) | ((denorm_rt.a << 6) & 0xC0u)); + RT.b = float((denorm_rt.a << 1) & 0xF8u); + RT.a = float(denorm_rt.a & 0x80u); #else - float Ad = trunc(RT.a * 255.0f + 0.1f) / 128.0f; + RT.r = float((denorm_rt.r << 3) & 0xF8u); + RT.g = float(((denorm_rt.r >> 2) & 0x38u) | ((denorm_rt.g << 6) & 0xC0u)); + RT.b = float((denorm_rt.g << 1) & 0xF8u); + RT.a = float(denorm_rt.g & 0x80u); #endif +#endif - #if PS_SHUFFLE && SW_BLEND_NEEDS_RT - uvec4 denorm_rt = uvec4(RT); - #if (PS_PROCESS_BA & SHUFFLE_WRITE) - RT.r = float((denorm_rt.b << 3) & 0xF8u); - RT.g = float(((denorm_rt.b >> 2) & 0x38u) | ((denorm_rt.a << 6) & 0xC0u)); - RT.b = float((denorm_rt.a << 1) & 0xF8u); - RT.a = float(denorm_rt.a & 0x80u); - #else - RT.r = float((denorm_rt.r << 3) & 0xF8u); - RT.g = float(((denorm_rt.r >> 2) & 0x38u) | ((denorm_rt.g << 6) & 0xC0u)); - RT.b = float((denorm_rt.g << 1) & 0xF8u); - RT.a = float(denorm_rt.g & 0x80u); - #endif - #endif - - // Let the compiler do its jobs ! - #if PS_COLCLIP_HW == 1 - vec3 Cd = trunc(RT.rgb * 65535.0f); - #else - vec3 Cd = trunc(RT.rgb * 255.0f + 0.1f); - #endif + float Ad = RT.a / 128.0f; + vec3 Cd = RT.rgb; vec3 Cs = Color.rgb; #if PS_BLEND_A == 0 diff --git a/bin/resources/shaders/vulkan/tfx.glsl b/bin/resources/shaders/vulkan/tfx.glsl index 264a472a94..30f94479a5 100644 --- a/bin/resources/shaders/vulkan/tfx.glsl +++ b/bin/resources/shaders/vulkan/tfx.glsl @@ -1544,20 +1544,26 @@ void ps_blend(inout vec4 Color, inout vec4 As_rgba) As_rgba.rgb = vec3(1.0f); #endif - #if PS_FEEDBACK_LOOP_IS_NEEDED_RT + #if SW_BLEND_NEEDS_RT vec4 RT = sample_from_rt(); + #if PS_COLCLIP_HW + float color_multi = 65535.0f; + #else + float color_multi = 255.0f; + #endif + #if PS_RTA_CORRECTION + float alpha_multi = 128.0f; + #else + float alpha_multi = 255.0f; + #endif + RT.rgb = trunc(RT.rgb * color_multi + 0.1f); + RT.a = trunc(RT.a * alpha_multi + 0.1f); #else // Not used, but we define it to make the selection below simpler. vec4 RT = vec4(0.0f); #endif - #if PS_RTA_CORRECTION - float Ad = trunc(RT.a * 128.0f + 0.1f) / 128.0f; - #else - float Ad = trunc(RT.a * 255.0f + 0.1f) / 128.0f; - #endif - - #if PS_SHUFFLE && PS_FEEDBACK_LOOP_IS_NEEDED_RT + #if PS_SHUFFLE && SW_BLEND_NEEDS_RT uvec4 denorm_rt = uvec4(RT); #if (PS_PROCESS_BA & SHUFFLE_WRITE) RT.r = float((denorm_rt.b << 3) & 0xF8u); @@ -1572,13 +1578,9 @@ void ps_blend(inout vec4 Color, inout vec4 As_rgba) #endif #endif - // Let the compiler do its jobs ! - #if PS_COLCLIP_HW == 1 - vec3 Cd = trunc(RT.rgb * 65535.0f); - #else - vec3 Cd = trunc(RT.rgb * 255.0f + 0.1f); - #endif - vec3 Cs = Color.rgb; + float Ad = RT.a / 128.0f; + vec3 Cd = RT.rgb; + vec3 Cs = Color.rgb; #if PS_BLEND_A == 0 vec3 A = Cs; diff --git a/pcsx2/GS/Renderers/Metal/tfx.metal b/pcsx2/GS/Renderers/Metal/tfx.metal index 687f25e76d..d4d16a7964 100644 --- a/pcsx2/GS/Renderers/Metal/tfx.metal +++ b/pcsx2/GS/Renderers/Metal/tfx.metal @@ -1393,28 +1393,37 @@ struct PSMain As_rgba.rgb = float3(1.f); } - float Ad = PS_RTA_CORRECTION ? trunc(current_color.a * 128.1f) / 128.f : trunc(current_color.a * 255.1f) / 128.f; - - if (PS_SHUFFLE && NEEDS_RT) + float4 RT = float4(0.f); + if (NEEDS_RT_FOR_BLEND) { - uint4 denorm_rt = uint4(current_color); + RT = current_color; + float color_multi = PS_COLCLIP_HW ? 65535.f : 255.f; + float alpha_multi = PS_RTA_CORRECTION ? 128.f : 255.f; + RT.rgb = trunc(RT.rgb * color_multi + 0.1f); + RT.a = trunc(RT.a * alpha_multi + 0.1f); + } + + if (PS_SHUFFLE && NEEDS_RT_FOR_BLEND) + { + uint4 denorm_rt = uint4(RT); if (PS_PROCESS_BA & SHUFFLE_WRITE) { - current_color.r = float((denorm_rt.b << 3) & 0xF8); - current_color.g = float(((denorm_rt.b >> 2) & 0x38) | ((denorm_rt.a << 6) & 0xC0)); - current_color.b = float((denorm_rt.a << 1) & 0xF8); - current_color.a = float(denorm_rt.a & 0x80); + RT.r = float((denorm_rt.b << 3) & 0xF8); + RT.g = float(((denorm_rt.b >> 2) & 0x38) | ((denorm_rt.a << 6) & 0xC0)); + RT.b = float((denorm_rt.a << 1) & 0xF8); + RT.a = float(denorm_rt.a & 0x80); } else { - current_color.r = float((denorm_rt.r << 3) & 0xF8); - current_color.g = float(((denorm_rt.r >> 2) & 0x38) | ((denorm_rt.g << 6) & 0xC0)); - current_color.b = float((denorm_rt.g << 1) & 0xF8); - current_color.a = float(denorm_rt.g & 0x80); + RT.r = float((denorm_rt.r << 3) & 0xF8); + RT.g = float(((denorm_rt.r >> 2) & 0x38) | ((denorm_rt.g << 6) & 0xC0)); + RT.b = float((denorm_rt.g << 1) & 0xF8); + RT.a = float(denorm_rt.g & 0x80); } } - float multi = PS_COLCLIP_HW ? 65535.0 : 255.5; - float3 Cd = trunc(current_color.rgb * multi); + + float Ad = RT.a / 128.f; + float3 Cd = RT.rgb; float3 Cs = Color.rgb; float3 A = pick(PS_BLEND_A, Cs, Cd, float3(0.f)); diff --git a/pcsx2/ShaderCacheVersion.h b/pcsx2/ShaderCacheVersion.h index b296dab1fa..e732834bff 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 = 117; // Last changed in PR 15005 +static constexpr u32 SHADER_CACHE_VERSION = 118; // Last changed in PR 14987