Skip to content

Commit 7910506

Browse files
committed
GS:HW: Avoid using blend + fbfetch for AFAIL RGB_ONLY
1 parent 5393d72 commit 7910506

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

bin/resources/shaders/opengl/tfx_fs.glsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#define SW_AD_TO_HW (PS_BLEND_C == 1 && PS_A_MASKED)
2626
#define PS_PRIMID_INIT (PS_DATE == 1 || PS_DATE == 2)
2727
#define NEEDS_RT_EARLY (PS_TEX_IS_FB == 1 || PS_DATE >= 5)
28-
#define NEEDS_RT (NEEDS_RT_EARLY || (!PS_PRIMID_INIT && (PS_FBMASK || SW_BLEND_NEEDS_RT || SW_AD_TO_HW)))
28+
#define NEEDS_RT_FOR_AFAIL (PS_AFAIL == 3 && PS_NO_COLOR1)
29+
#define NEEDS_RT (NEEDS_RT_EARLY || NEEDS_RT_FOR_AFAIL || (!PS_PRIMID_INIT && (PS_FBMASK || SW_BLEND_NEEDS_RT || SW_AD_TO_HW)))
2930
#define NEEDS_TEX (PS_TFX != 4)
3031

3132
layout(std140, binding = 0) uniform cb21
@@ -1114,7 +1115,7 @@ void ps_main()
11141115

11151116
ps_fbmask(C);
11161117

1117-
#if PS_AFAIL == 3 // RGB_ONLY
1118+
#if PS_AFAIL == 3 && !PS_NO_COLOR1 // RGB_ONLY
11181119
// Use alpha blend factor to determine whether to update A.
11191120
alpha_blend.a = float(atst_pass);
11201121
#endif
@@ -1130,6 +1131,10 @@ void ps_main()
11301131
#else
11311132
SV_Target0.rgb = C.rgb / 255.0f;
11321133
#endif
1134+
#if PS_AFAIL == 3 && !PS_NO_COLOR1 // RGB_ONLY, no dual src blend
1135+
if (!atst_pass)
1136+
SV_Target0.a = sample_from_rt().a;
1137+
#endif
11331138
#if !PS_NO_COLOR1
11341139
SV_Target1 = alpha_blend;
11351140
#endif

bin/resources/shaders/vulkan/tfx.glsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ void main()
299299
#define SW_BLEND (PS_BLEND_A || PS_BLEND_B || PS_BLEND_D)
300300
#define SW_BLEND_NEEDS_RT (SW_BLEND && (PS_BLEND_A == 1 || PS_BLEND_B == 1 || PS_BLEND_C == 1 || PS_BLEND_D == 1))
301301
#define SW_AD_TO_HW (PS_BLEND_C == 1 && PS_A_MASKED)
302+
#define AFAIL_NEEDS_RT (PS_AFAIL == 3 && PS_NO_COLOR1)
302303

303-
#define PS_FEEDBACK_LOOP_IS_NEEDED (PS_TEX_IS_FB == 1 || PS_FBMASK || SW_BLEND_NEEDS_RT || SW_AD_TO_HW || (PS_DATE >= 5))
304+
#define PS_FEEDBACK_LOOP_IS_NEEDED (PS_TEX_IS_FB == 1 || AFAIL_NEEDS_RT || PS_FBMASK || SW_BLEND_NEEDS_RT || SW_AD_TO_HW || (PS_DATE >= 5))
304305

305306
#define NEEDS_TEX (PS_TFX != 4)
306307

@@ -1381,7 +1382,7 @@ void main()
13811382

13821383
ps_fbmask(C);
13831384

1384-
#if PS_AFAIL == 3 // RGB_ONLY
1385+
#if PS_AFAIL == 3 && !PS_NO_COLOR1 // RGB_ONLY
13851386
// Use alpha blend factor to determine whether to update A.
13861387
alpha_blend.a = float(atst_pass);
13871388
#endif
@@ -1400,6 +1401,10 @@ void main()
14001401
#if !PS_NO_COLOR1
14011402
o_col1 = alpha_blend;
14021403
#endif
1404+
#if PS_AFAIL == 3 && PS_NO_COLOR1 // RGB_ONLY, no dual src blend
1405+
if (!atst_pass)
1406+
o_col0.a = sample_from_rt().a;
1407+
#endif
14031408
#endif
14041409

14051410
#if PS_ZCLAMP

pcsx2/GS/Renderers/HW/GSRendererHW.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6240,23 +6240,32 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta
62406240
// Blending might be off, ensure it's enabled.
62416241
// We write the alpha pass/fail to SRC1_ALPHA, which is used to update A.
62426242
m_conf.ps.afail = AFAIL_RGB_ONLY;
6243-
m_conf.ps.no_color1 = false;
6244-
if (!m_conf.blend.enable)
6243+
if ((features.framebuffer_fetch && m_conf.require_one_barrier) || m_conf.require_full_barrier)
62456244
{
6246-
m_conf.blend = GSHWDrawConfig::BlendState(true, GSDevice::CONST_ONE, GSDevice::CONST_ZERO,
6247-
GSDevice::OP_ADD, GSDevice::SRC1_ALPHA, GSDevice::INV_SRC1_ALPHA, false, 0);
6245+
// We're reading the rt anyways, use it for AFAIL
6246+
// This ensures we don't attempt to use fbfetch + blend, which breaks Intel GPUs on Metal
6247+
// Setting afail to RGB_ONLY without enabling color1 will enable this mode in the shader, so nothing more to do here.
62486248
}
62496249
else
62506250
{
6251-
if (m_conf.blend_multi_pass.enable)
6251+
m_conf.ps.no_color1 = false;
6252+
if (!m_conf.blend.enable)
62526253
{
6253-
m_conf.blend_multi_pass.blend.src_factor_alpha = GSDevice::SRC1_ALPHA;
6254-
m_conf.blend_multi_pass.blend.dst_factor_alpha = GSDevice::INV_SRC1_ALPHA;
6254+
m_conf.blend = GSHWDrawConfig::BlendState(true, GSDevice::CONST_ONE, GSDevice::CONST_ZERO,
6255+
GSDevice::OP_ADD, GSDevice::SRC1_ALPHA, GSDevice::INV_SRC1_ALPHA, false, 0);
62556256
}
62566257
else
62576258
{
6258-
m_conf.blend.src_factor_alpha = GSDevice::SRC1_ALPHA;
6259-
m_conf.blend.dst_factor_alpha = GSDevice::INV_SRC1_ALPHA;
6259+
if (m_conf.blend_multi_pass.enable)
6260+
{
6261+
m_conf.blend_multi_pass.blend.src_factor_alpha = GSDevice::SRC1_ALPHA;
6262+
m_conf.blend_multi_pass.blend.dst_factor_alpha = GSDevice::INV_SRC1_ALPHA;
6263+
}
6264+
else
6265+
{
6266+
m_conf.blend.src_factor_alpha = GSDevice::SRC1_ALPHA;
6267+
m_conf.blend.dst_factor_alpha = GSDevice::INV_SRC1_ALPHA;
6268+
}
62606269
}
62616270
}
62626271

pcsx2/GS/Renderers/Metal/tfx.metal

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ constant bool SW_BLEND = (PS_BLEND_A != PS_BLEND_B) || PS_BLEND_D;
9797
constant bool SW_AD_TO_HW = (PS_BLEND_C == 1 && PS_A_MASKED);
9898
constant bool NEEDS_RT_FOR_BLEND = (((PS_BLEND_A != PS_BLEND_B) && (PS_BLEND_A == 1 || PS_BLEND_B == 1 || PS_BLEND_C == 1)) || PS_BLEND_D == 1 || SW_AD_TO_HW);
9999
constant bool NEEDS_RT_EARLY = PS_TEX_IS_FB || PS_DATE >= 5;
100-
constant bool NEEDS_RT = NEEDS_RT_EARLY || (!PS_PRIM_CHECKING_INIT && (PS_FBMASK || NEEDS_RT_FOR_BLEND));
100+
constant bool NEEDS_RT_FOR_AFAIL = PS_AFAIL == 3 && PS_NO_COLOR1;
101+
constant bool NEEDS_RT = NEEDS_RT_FOR_AFAIL || NEEDS_RT_EARLY || (!PS_PRIM_CHECKING_INIT && (PS_FBMASK || NEEDS_RT_FOR_BLEND));
101102

102103
constant bool PS_COLOR0 = !PS_NO_COLOR;
103104
constant bool PS_COLOR1 = !PS_NO_COLOR1;
@@ -1202,8 +1203,12 @@ struct PSMain
12021203
alpha_blend.a = float(atst_pass);
12031204

12041205
if (PS_COLOR0)
1206+
{
12051207
out.c0.a = PS_RTA_CORRECTION ? C.a / 128.f : C.a / 255.f;
12061208
out.c0.rgb = PS_HDR ? float3(C.rgb / 65535.f) : C.rgb / 255.f;
1209+
if (PS_AFAIL == 3 && !PS_COLOR1 && !atst_pass) // Doing RGB_ONLY without COLOR1
1210+
out.c0.a = current_color.a;
1211+
}
12071212
if (PS_COLOR1)
12081213
out.c1 = alpha_blend;
12091214
if (PS_ZCLAMP)

pcsx2/ShaderCacheVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
/// Version number for GS and other shaders. Increment whenever any of the contents of the
55
/// shaders change, to invalidate the cache.
6-
static constexpr u32 SHADER_CACHE_VERSION = 59;
6+
static constexpr u32 SHADER_CACHE_VERSION = 60;

0 commit comments

Comments
 (0)