Skip to content

Commit 2c608b4

Browse files
GS/GL: Backport multidraw fb copy for depth feedbacks.
1 parent 2c908f4 commit 2c608b4

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.cpp

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,18 @@ bool GSDeviceOGL::CheckFeatures()
827827
m_features.depth_feedback = GSDevice::DepthFeedbackSupport::None;
828828
}
829829
}
830+
else if (m_features.multidraw_fb_copy)
831+
{
832+
if (GSConfig.DepthFeedbackMode == GSDepthFeedbackMode::Depth ||
833+
GSConfig.DepthFeedbackMode == GSDepthFeedbackMode::Auto)
834+
{
835+
m_features.depth_feedback = GSDevice::DepthFeedbackSupport::Depth;
836+
}
837+
else
838+
{
839+
m_features.depth_feedback = GSDevice::DepthFeedbackSupport::None;
840+
}
841+
}
830842
else
831843
{
832844
m_features.depth_feedback = GSDevice::DepthFeedbackSupport::None;
@@ -2592,11 +2604,20 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
25922604
if (config.pal)
25932605
CommitClear(config.pal, true);
25942606

2595-
GSVector2i rtsize = (config.rt ? config.rt : config.ds)->GetSize();
2596-
2597-
GSTexture* primid_texture = nullptr;
2598-
GSTexture* draw_rt_clone = nullptr;
2607+
const GSVector2i rtsize = (config.rt ? config.rt : config.ds)->GetSize();
25992608
GSTexture* colclip_rt = g_gs_device->GetColorClipTexture();
2609+
GSTexture* draw_rt_clone = nullptr;
2610+
GSTexture* draw_ds_clone = nullptr;
2611+
GSTexture* primid_texture = nullptr;
2612+
2613+
ScopedGuard recycle_temp_textures([&]() {
2614+
if (draw_rt_clone)
2615+
Recycle(draw_rt_clone);
2616+
if (draw_ds_clone)
2617+
Recycle(draw_ds_clone);
2618+
if (primid_texture)
2619+
Recycle(primid_texture);
2620+
});
26002621

26012622
if (colclip_rt)
26022623
{
@@ -2700,10 +2721,10 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
27002721
PSSetShaderResource(1, config.pal);
27012722
if (m_features.texture_barrier && (config.require_one_barrier || config.require_full_barrier))
27022723
PSSetShaderResource(2, colclip_rt ? colclip_rt : config.rt);
2703-
if (m_features.texture_barrier && (config.require_one_barrier || config.require_full_barrier) && config.ps.IsFeedbackLoopDepth())
2704-
PSSetShaderResource(4, m_features.depth_feedback == GSDevice::DepthFeedbackSupport::DepthAsRT ? config.ds_as_rt :
2705-
m_features.depth_feedback == GSDevice::DepthFeedbackSupport::Depth ? config.ds : nullptr);
2706-
2724+
const bool depth_feedback = m_features.depth_feedback == GSDevice::DepthFeedbackSupport::Depth;
2725+
if (m_features.texture_barrier && (config.require_one_barrier || config.require_full_barrier) && config.ps.IsFeedbackLoopDepth() &&
2726+
(depth_feedback || m_features.depth_feedback == GSDevice::DepthFeedbackSupport::DepthAsRT))
2727+
PSSetShaderResource(4, depth_feedback ? config.ds : config.ds_as_rt);
27072728
SetupSampler(config.sampler);
27082729

27092730
if (m_vs_cb_cache.Update(config.cb_vs))
@@ -2847,6 +2868,15 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
28472868
Console.Warning("GL: Failed to allocate temp texture for RT copy.");
28482869
}
28492870

2871+
if (draw_ds && (config.require_one_barrier || (config.require_full_barrier && m_features.multidraw_fb_copy)) &&
2872+
!m_features.texture_barrier && depth_feedback && config.ps.IsFeedbackLoopDepth())
2873+
{
2874+
// Requires a copy of the DS.
2875+
draw_ds_clone = CreateTexture(rtsize.x, rtsize.y, 1, draw_ds->GetFormat(), true);
2876+
if (!draw_ds_clone)
2877+
Console.Warning("GL: Failed to allocate temp texture for DS copy.");
2878+
}
2879+
28502880
OMSetRenderTargets(draw_rt, draw_ds_as_rt, draw_ds, &config.scissor);
28512881
OMSetColorMaskState(config.colormask);
28522882
SetupOM(config.depth);
@@ -2858,7 +2888,8 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
28582888
glClearBufferiv(GL_STENCIL, 0, &clear_color);
28592889
}
28602890

2861-
SendHWDraw(config, draw_rt_clone, draw_rt, config.require_one_barrier, config.require_full_barrier);
2891+
SendHWDraw(config, draw_rt_clone, draw_rt, draw_ds_clone, draw_ds,
2892+
config.require_one_barrier, config.require_full_barrier);
28622893

28632894
if (config.blend_multi_pass.enable)
28642895
{
@@ -2905,15 +2936,10 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
29052936
OMSetBlendState();
29062937
}
29072938
SetupOM(config.alpha_second_pass.depth);
2908-
SendHWDraw(config, draw_rt_clone, draw_rt, m_features.texture_barrier ? config.alpha_second_pass.require_one_barrier : false,
2909-
config.alpha_second_pass.require_full_barrier);
2939+
SendHWDraw(config, draw_rt_clone, draw_rt, draw_ds_clone, draw_ds,
2940+
m_features.texture_barrier ? config.alpha_second_pass.require_one_barrier : false, config.alpha_second_pass.require_full_barrier);
29102941
}
29112942

2912-
if (primid_texture)
2913-
Recycle(primid_texture);
2914-
if (draw_rt_clone)
2915-
Recycle(draw_rt_clone);
2916-
29172943
if (colclip_rt)
29182944
{
29192945
config.colclip_update_area = config.colclip_update_area.runion(config.drawarea);
@@ -2931,7 +2957,9 @@ void GSDeviceOGL::RenderHW(GSHWDrawConfig& config)
29312957
}
29322958
}
29332959

2934-
void GSDeviceOGL::SendHWDraw(const GSHWDrawConfig& config, GSTexture* draw_rt_clone, GSTexture* draw_rt, bool one_barrier, bool full_barrier)
2960+
void GSDeviceOGL::SendHWDraw(const GSHWDrawConfig& config,
2961+
GSTexture* draw_rt_clone, GSTexture* draw_rt, GSTexture* draw_ds_clone, GSTexture* draw_ds,
2962+
const bool one_barrier, const bool full_barrier)
29352963
{
29362964
#ifdef PCSX2_DEVBUILD
29372965
if ((one_barrier || full_barrier) && !(config.ps.IsFeedbackLoopRT() || config.ps.IsFeedbackLoopDepth())) [[unlikely]]
@@ -2940,11 +2968,18 @@ void GSDeviceOGL::SendHWDraw(const GSHWDrawConfig& config, GSTexture* draw_rt_cl
29402968

29412969
auto CopyAndBind = [&](GSVector4i drawarea) {
29422970
if (draw_rt_clone)
2971+
{
29432972
CopyRect(draw_rt, draw_rt_clone, drawarea, drawarea.left, drawarea.top);
2944-
if ((one_barrier || full_barrier) && draw_rt_clone)
2945-
PSSetShaderResource(2, draw_rt_clone);
2946-
if (config.tex && config.tex == draw_rt)
2947-
PSSetShaderResource(0, draw_rt_clone);
2973+
if ((one_barrier || full_barrier))
2974+
PSSetShaderResource(2, draw_rt_clone);
2975+
if (config.tex && config.tex == draw_rt)
2976+
PSSetShaderResource(0, draw_rt_clone);
2977+
}
2978+
if (draw_ds_clone)
2979+
{
2980+
CopyRect(draw_ds, draw_ds_clone, drawarea, drawarea.left, drawarea.top);
2981+
PSSetShaderResource(4, draw_ds_clone);
2982+
}
29482983
};
29492984

29502985
const GSVector4i rtsize(0, 0, (draw_rt ? draw_rt : draw_ds)->GetWidth(), (draw_rt ? draw_rt : draw_ds)->GetHeight());

pcsx2/GS/Renderers/OpenGL/GSDeviceOGL.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ class GSDeviceOGL final : public GSDevice
340340
void DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rects, const GSVector2& ds);
341341

342342
void RenderHW(GSHWDrawConfig& config) override;
343-
void SendHWDraw(const GSHWDrawConfig& config, GSTexture* draw_rt_clone, GSTexture* draw_rt, bool one_barrier, bool full_barrier);
344-
343+
void SendHWDraw(const GSHWDrawConfig& config,
344+
GSTexture* draw_rt_clone, GSTexture* draw_rt, GSTexture* draw_ds_clone, GSTexture* draw_ds,
345+
const bool one_barrier, const bool full_barrier);
345346
void SetupDATE(GSTexture* rt, GSTexture* ds, SetDATM datm, const GSVector4i& bbox);
346347

347348
void IASetVAO(GLuint vao);

0 commit comments

Comments
 (0)