diff --git a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp index 4816638c91..9500b5ce42 100644 --- a/pcsx2/GS/Renderers/DX11/GSDevice11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSDevice11.cpp @@ -2614,10 +2614,10 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config) GSTexture* draw_rt_clone = nullptr; - // Used as "bind rt" flag when texture barrier is unsupported. if (config.require_one_barrier || (config.tex && config.tex == config.rt)) { // Requires a copy of the RT. + // Used as "bind rt" flag when texture barrier is unsupported for tex is fb. draw_rt_clone = CreateTexture(rtsize.x, rtsize.y, 1, colclip_rt ? GSTexture::Format::ColorClip : GSTexture::Format::Color, true); if (draw_rt_clone) { @@ -2629,6 +2629,19 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config) } } + GSTexture* draw_ds_clone = nullptr; + + if (config.tex && config.tex == config.ds) + { + // DX requires a copy when sampling the depth buffer. + draw_ds_clone = CreateDepthStencil(rtsize.x, rtsize.y, config.ds->GetFormat(), false); + if (draw_ds_clone) + { + CopyRect(config.ds, draw_ds_clone, config.drawarea, config.drawarea.left, config.drawarea.top); + PSSetShaderResource(0, draw_ds_clone); + } + } + SetupVS(config.vs, &config.cb_vs); SetupPS(config.ps, &config.cb_ps, config.sampler); @@ -2681,6 +2694,10 @@ void GSDevice11::RenderHW(GSHWDrawConfig& config) if (draw_rt_clone) Recycle(draw_rt_clone); + + if (draw_ds_clone) + Recycle(draw_ds_clone); + if (primid_tex) Recycle(primid_tex); diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index 34c876c341..77268085da 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -3828,6 +3828,7 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config) GSTexture12* draw_rt = static_cast(config.rt); GSTexture12* draw_ds = static_cast(config.ds); GSTexture12* draw_rt_clone = nullptr; + GSTexture12* draw_ds_clone = nullptr; // Align the render area to 128x128, hopefully avoiding render pass restarts for small render area changes (e.g. Ratchet and Clank). const GSVector2i rtsize(config.rt ? config.rt->GetSize() : config.ds->GetSize()); @@ -3883,7 +3884,7 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config) // bind textures before checking the render pass, in case we need to transition them if (config.tex) { - PSSetShaderResource(0, config.tex, config.tex != config.rt); + PSSetShaderResource(0, config.tex, config.tex != config.rt && config.tex != config.ds); PSSetSampler(config.sampler); } if (config.pal) @@ -3907,15 +3908,16 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config) } } - if (config.require_one_barrier || (config.tex && config.tex == config.rt)) // Used as "bind rt" flag when texture barrier is unsupported. + if (config.require_one_barrier || (config.tex && config.tex == config.rt)) { - // requires a copy of the RT + // Requires a copy of the RT. + // Used as "bind rt" flag when texture barrier is unsupported for tex is fb. draw_rt_clone = static_cast(CreateTexture(rtsize.x, rtsize.y, 1, colclip_rt ? GSTexture::Format::ColorClip : GSTexture::Format::Color, true)); if (draw_rt_clone) { EndRenderPass(); - GL_PUSH("Copy RT to temp texture for fbmask {%d,%d %dx%d}", config.drawarea.left, config.drawarea.top, + GL_PUSH("Copy RT to temp texture {%d,%d %dx%d}", config.drawarea.left, config.drawarea.top, config.drawarea.width(), config.drawarea.height()); draw_rt_clone->SetState(GSTexture::State::Invalidated); @@ -3927,6 +3929,23 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config) } } + if (config.tex && config.tex == config.ds) + { + // DX requires a copy when sampling the depth buffer. + draw_ds_clone = static_cast(CreateDepthStencil(rtsize.x, rtsize.y, config.ds->GetFormat(), false)); + if (draw_ds_clone) + { + EndRenderPass(); + + GL_PUSH("Copy RT to temp texture {%d,%d %dx%d}", config.drawarea.left, config.drawarea.top, + config.drawarea.width(), config.drawarea.height()); + + draw_ds_clone->SetState(GSTexture::State::Invalidated); + CopyRect(config.ds, draw_ds_clone, config.drawarea, config.drawarea.left, config.drawarea.top); + PSSetShaderResource(0, draw_ds_clone, true); + } + } + // Switch to colclip target for colclip hw rendering if (pipe.ps.colclip_hw) { @@ -4073,6 +4092,9 @@ void GSDevice12::RenderHW(GSHWDrawConfig& config) if (draw_rt_clone) Recycle(draw_rt_clone); + if (draw_ds_clone) + Recycle(draw_ds_clone); + if (date_image) Recycle(date_image);