Skip to content

Commit e10f80d

Browse files
committed
GS/HW: Change config settings for depth feedback.
1 parent 850fa17 commit e10f80d

File tree

8 files changed

+50
-18
lines changed

8 files changed

+50
-18
lines changed

pcsx2/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ struct Pcsx2Config
732732
DisableShaderCache : 1,
733733
DisableFramebufferFetch : 1,
734734
DisableVertexShaderExpand : 1,
735+
DisableDepthFeedback : 1,
735736
SkipDuplicateFrames : 1,
736737
OsdShowSpeed : 1,
737738
OsdShowFPS : 1,
@@ -757,7 +758,6 @@ struct Pcsx2Config
757758
PreloadFrameWithGSData : 1,
758759
Mipmap : 1,
759760
HWMipmap : 1,
760-
HWAFAILFeedback : 1,
761761
ManualUserHacks : 1,
762762
UserHacks_AlignSpriteX : 1,
763763
UserHacks_CPUFBConversion : 1,

pcsx2/GS/Renderers/Common/GSDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@ class GSDevice : public GSAlignedClass<32>
900900
bool stencil_buffer : 1; ///< Supports stencil buffer, and can use for DATE.
901901
bool cas_sharpening : 1; ///< Supports sufficient functionality for contrast adaptive sharpening.
902902
bool test_and_sample_depth: 1; ///< Supports concurrently binding the depth-stencil buffer for sampling and depth testing.
903-
bool depth_as_rt_feedback : 1; ///< Depth feedback loops/barriers by converting depth to a temporary color target.
903+
bool depth_feedback : 1; ///< Depth feedback loops by directly binding DepthStencil target for read/write.
904+
bool depth_as_rt_feedback : 1; ///< Depth feedback loops by converting depth to a temporary color target.
904905
FeatureSupport()
905906
{
906907
memset(this, 0, sizeof(*this));

pcsx2/GS/Renderers/DX11/GSDevice11.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ GSDevice11::GSDevice11()
5959
m_features.stencil_buffer = true;
6060
m_features.cas_sharpening = true;
6161
m_features.test_and_sample_depth = true;
62+
m_features.depth_feedback = m_features.test_and_sample_depth && !GSConfig.DisableDepthFeedback;
63+
m_features.depth_as_rt_feedback = false;
6264
}
6365

6466
GSDevice11::~GSDevice11() = default;

pcsx2/GS/Renderers/DX12/GSDevice12.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "common/BitUtils.h"
1717
#include "common/Error.h"
1818
#include "common/HostSys.h"
19-
#include "common/ScopedGuard.h"
2019
#include "common/SmallString.h"
2120
#include "common/StringUtil.h"
2221

@@ -1240,7 +1239,8 @@ bool GSDevice12::CheckFeatures(const u32& vendor_id)
12401239
m_features.cas_sharpening = true;
12411240
m_features.test_and_sample_depth = true;
12421241
m_features.vs_expand = !GSConfig.DisableVertexShaderExpand;
1243-
m_features.depth_as_rt_feedback = m_features.texture_barrier;
1242+
m_features.depth_feedback = false;
1243+
m_features.depth_as_rt_feedback = m_features.test_and_sample_depth && !GSConfig.DisableDepthFeedback;
12441244

12451245
m_features.dxt_textures = SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) &&
12461246
SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) &&
@@ -4225,7 +4225,7 @@ void GSDevice12::SendHWDraw(const PipelineSelector& pipe, const GSHWDrawConfig&
42254225
PSSetShaderResource(0, draw_rt, false, true);
42264226
if ((one_barrier || full_barrier) && feedback_depth)
42274227
PSSetShaderResource(4, draw_ds, false, true);
4228-
4228+
42294229
std::array<D3D12_RESOURCE_BARRIER, 2> barriers;
42304230
u32 n_barriers = 0;
42314231
// Specify null for the after resource as both resources are used after the barrier.
@@ -4257,7 +4257,7 @@ void GSDevice12::SendHWDraw(const PipelineSelector& pipe, const GSHWDrawConfig&
42574257
const u32 count = (*config.drawlist)[n] * indices_per_prim;
42584258

42594259
EndRenderPass();
4260-
4260+
42614261
GetCommandList()->ResourceBarrier(n_barriers, barriers.data());
42624262

42634263
if (BindDrawPipeline(pipe))

pcsx2/GS/Renderers/HW/GSRendererHW.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7346,22 +7346,44 @@ void GSRendererHW::EmulateAlphaTest(const bool& DATE, bool& DATE_BARRIER, bool&
73467346
// Determine whether the feedback methods require a single pass.
73477347
const bool feedback_one_pass = simple_fb_only || simple_rgb_only || simple_zb_only;
73487348

7349+
// Determine if the method for doing depth feedback uses multiple render targets.
7350+
// This should not be used in conjunction with dual source blend.
7351+
// This also requires 2 full screen copies of depth <-> color so avoid if possible.
7352+
const bool depth_as_rt_feedback = afail_needs_depth && features.depth_as_rt_feedback;
7353+
73497354
// If we are already have the required barriers for the accurate feedback path.
7350-
const bool already_have_barriers =
7355+
const bool free_to_use_barriers =
73517356
((m_conf.require_one_barrier && feedback_one_pass) || m_conf.require_full_barrier) &&
7352-
(features.texture_barrier || features.multidraw_fb_copy);
7357+
(features.texture_barrier || features.multidraw_fb_copy) &&
7358+
!depth_as_rt_feedback;
73537359

73547360
// Dual source blend comes with some restrictions, so detect and avoid them here.
73557361
const bool using_dual_source_blend = !m_conf.ps.no_color1;
73567362

7357-
// Determines if the method for doing depth feedback uses multiple render targets.
7358-
// This should not be used in conjunction with dual source blend.
7359-
const bool depth_as_rt_feedback = afail_needs_depth && features.depth_as_rt_feedback;
7363+
// Determine if we have the correct features for depth feedback.
7364+
const bool depth_feedback_supported = features.depth_feedback ||
7365+
features.depth_as_rt_feedback || features.multidraw_fb_copy;
7366+
7367+
const bool avoid_feedback =
7368+
// Do not use dual source blend with FB-fetch, which breaks Intel GPUs on Metal.
7369+
// Also do not use dual source blend with multiple render targets, which is against spec.
7370+
((features.framebuffer_fetch || depth_as_rt_feedback) && using_dual_source_blend) ||
7371+
// We need depth feedback but do not have the correct features.
7372+
(afail_needs_depth && !depth_feedback_supported);
7373+
7374+
// Determine if we can use FB-fetch for color only feedback.
7375+
const bool free_fbfetch_feedback = features.framebuffer_fetch && !depth_as_rt_feedback;
73607376

7361-
// Also do not use dual source blend with FB-fetch, which breaks Intel GPUs on Metal.
7362-
const bool avoid_feedback = (features.framebuffer_fetch || depth_as_rt_feedback) && using_dual_source_blend;
7377+
// Prefer feedback method only if blend level requests it or it's free.
7378+
const bool prefer_feedback = (GSConfig.AccurateBlendingUnit >= AccBlendLevel::Maximum) ||
7379+
free_to_use_barriers || free_fbfetch_feedback;
73637380

7364-
if ((GSConfig.HWAFAILFeedback || already_have_barriers || features.framebuffer_fetch) && !avoid_feedback)
7381+
// The two simple cases can be handle accurately in two passes so no point
7382+
// in requiring barriers if they are not already being used.
7383+
const bool prefer_two_pass = !(m_conf.require_full_barrier || m_conf.require_full_barrier) &&
7384+
(simple_fb_only || simple_rgb_only);
7385+
7386+
if (prefer_feedback && !prefer_two_pass && !avoid_feedback)
73657387
{
73667388
// Use RT and/or depth sampling for accurate AFAIL in the shader.
73677389
GL_INS("Alpha test with RT/depth feedback (accurate)");
@@ -8321,14 +8343,15 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta
83218343
if (m_conf.alpha_second_pass.enable)
83228344
{
83238345
m_conf.alpha_second_pass.depth.zwe = 0;
8324-
m_conf.alpha_second_pass.depth.ztst = 0;
8346+
m_conf.alpha_second_pass.depth.ztst = ZTST_ALWAYS;
83258347
}
83268348

83278349
// Create the temporary depth copy
83288350
m_conf.ds_as_rt = g_gs_device->CreateRenderTarget(m_conf.ds->GetWidth(), m_conf.ds->GetHeight(),
83298351
GSTexture::Format::Float32, false, true);
83308352
const GSVector4 dRect(0.0f, 0.0f, static_cast<float>(m_conf.ds->GetWidth()), static_cast<float>(m_conf.ds->GetHeight()));
83318353
g_gs_device->StretchRect(m_conf.ds, m_conf.ds_as_rt, dRect, ShaderConvert::FLOAT32_DEPTH_TO_COLOR, false);
8354+
g_perfmon.Put(GSPerfMon::TextureCopies, 1.0);
83328355
}
83338356

83348357
// rs
@@ -8363,6 +8386,7 @@ __ri void GSRendererHW::DrawPrims(GSTextureCache::Target* rt, GSTextureCache::Ta
83638386
g_gs_device->StretchRect(m_conf.ds_as_rt, m_conf.ds, dRect, ShaderConvert::FLOAT32_COLOR_TO_DEPTH, false);
83648387
g_gs_device->Recycle(m_conf.ds_as_rt);
83658388
m_conf.ds_as_rt = nullptr;
8389+
g_perfmon.Put(GSPerfMon::TextureCopies, 1.0);
83668390
}
83678391
}
83688392

pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,8 @@ bool GSDeviceOGL::CheckFeatures()
741741
m_features.prefer_new_textures = false;
742742
m_features.stencil_buffer = true;
743743
m_features.test_and_sample_depth = m_features.texture_barrier;
744-
m_features.depth_as_rt_feedback = m_features.texture_barrier;
744+
m_features.depth_feedback = false;
745+
m_features.depth_as_rt_feedback = m_features.test_and_sample_depth && !GSConfig.DisableDepthFeedback;
745746

746747
if (GLAD_GL_ARB_shader_storage_buffer_object)
747748
{

pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,9 @@ bool GSDeviceVK::CheckFeatures()
27052705
m_features.line_expand =
27062706
(m_device_features.wideLines && limits.lineWidthRange[0] <= f_upscale && limits.lineWidthRange[1] >= f_upscale);
27072707

2708+
m_features.depth_feedback = m_features.test_and_sample_depth && !GSConfig.DisableDepthFeedback;
2709+
m_features.depth_as_rt_feedback = false;
2710+
27082711
DevCon.WriteLn("Optional features:%s%s%s%s%s", m_features.primitive_id ? " primitive_id" : "",
27092712
m_features.texture_barrier ? " texture_barrier" : "", m_features.framebuffer_fetch ? " framebuffer_fetch" : "",
27102713
m_features.provoking_vertex_last ? " provoking_vertex_last" : "", m_features.vs_expand ? " vs_expand" : "");

pcsx2/Pcsx2Config.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ Pcsx2Config::GSOptions::GSOptions()
722722
DisableShaderCache = false;
723723
DisableFramebufferFetch = false;
724724
DisableVertexShaderExpand = false;
725+
DisableDepthFeedback = true; // Disable depth feedback default; can lead to high barriers/texture copies and Z fighting.
725726
SkipDuplicateFrames = false;
726727
OsdMessagesPos = OsdOverlayPos::TopLeft;
727728
OsdPerformancePos = OsdOverlayPos::TopRight;
@@ -751,7 +752,6 @@ Pcsx2Config::GSOptions::GSOptions()
751752
PreloadFrameWithGSData = false;
752753
Mipmap = true;
753754
HWMipmap = true;
754-
HWAFAILFeedback = false;
755755

756756
ManualUserHacks = false;
757757
UserHacks_AlignSpriteX = false;
@@ -900,6 +900,7 @@ bool Pcsx2Config::GSOptions::RestartOptionsAreEqual(const GSOptions& right) cons
900900
OpEqu(DisableShaderCache) &&
901901
OpEqu(DisableFramebufferFetch) &&
902902
OpEqu(DisableVertexShaderExpand) &&
903+
OpEqu(DisableDepthFeedback) &&
903904
OpEqu(OverrideTextureBarriers) &&
904905
OpEqu(ExclusiveFullscreenControl);
905906
}
@@ -945,6 +946,7 @@ void Pcsx2Config::GSOptions::LoadSave(SettingsWrapper& wrap)
945946
SettingsWrapBitBool(DisableShaderCache);
946947
SettingsWrapBitBool(DisableFramebufferFetch);
947948
SettingsWrapBitBool(DisableVertexShaderExpand);
949+
SettingsWrapBitBool(DisableDepthFeedback);
948950
SettingsWrapBitBool(SkipDuplicateFrames);
949951
SettingsWrapBitBool(OsdShowSpeed);
950952
SettingsWrapBitBool(OsdShowFPS);
@@ -1022,7 +1024,6 @@ void Pcsx2Config::GSOptions::LoadSave(SettingsWrapper& wrap)
10221024
SettingsWrapEntryEx(UpscaleMultiplier, "upscale_multiplier");
10231025

10241026
SettingsWrapBitBoolEx(HWMipmap, "hw_mipmap");
1025-
SettingsWrapBitBoolEx(HWAFAILFeedback, "HWAFAILFeedback");
10261027
SettingsWrapIntEnumEx(AccurateBlendingUnit, "accurate_blending_unit");
10271028
SettingsWrapIntEnumEx(TextureFiltering, "filter");
10281029
SettingsWrapIntEnumEx(TexturePreloading, "texture_preloading");

0 commit comments

Comments
 (0)