From 468b9ded4645cca6dfdf1df68245043b801aad53 Mon Sep 17 00:00:00 2001 From: Kojin Date: Sun, 20 Jan 2019 01:09:47 -0500 Subject: [PATCH] gsdx-d3d11: Update texture copy method to handle depth - Rename CopyRenderTarget to CloneTexture - Allow copy of depth target Also fix a small oversight from the removal of MSAA. --- plugins/GSdx/Renderers/DX11/GSDevice11.cpp | 41 +++++++++++++++------- plugins/GSdx/Renderers/DX11/GSDevice11.h | 2 +- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/plugins/GSdx/Renderers/DX11/GSDevice11.cpp b/plugins/GSdx/Renderers/DX11/GSDevice11.cpp index 7a5b19c764..d58eaa042c 100644 --- a/plugins/GSdx/Renderers/DX11/GSDevice11.cpp +++ b/plugins/GSdx/Renderers/DX11/GSDevice11.cpp @@ -468,11 +468,15 @@ void GSDevice11::DrawIndexedPrimitive() // DX can't read from the FB // So let's copy it and set that as the shader // resource for slot 4 to avoid issues. - if (m_state.ps_sr_texture[4] && m_state.ps_sr_texture[4]->Equal(m_state.rt_texture)) - { - //fprintf(stdout, "FB read detected on slot 4: copying fb...\n"); + GSTexture11* tex = m_state.ps_sr_texture[4]; - GSTexture* cp = CopyRenderTarget(m_state.rt_texture); + if (tex && (tex->Equal(m_state.rt_texture) || tex->Equal(m_state.rt_ds))) + { + // fprintf(stdout, "FB read detected on slot 4: copying fb...\n"); + + GSTexture* cp = nullptr; + + CloneTexture(m_state.ps_sr_texture[4], &cp); PSSetShaderResource(4, cp); PSUpdateShaderState(); @@ -644,27 +648,40 @@ GSTexture* GSDevice11::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int void GSDevice11::CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r) { - if(!sTex || !dTex) + if (!sTex || !dTex) { ASSERT(0); return; } - D3D11_BOX box = {(UINT)r.left, (UINT)r.top, 0U, (UINT)r.right, (UINT)r.bottom, 1U}; + D3D11_BOX box = { (UINT)r.left, (UINT)r.top, 0U, (UINT)r.right, (UINT)r.bottom, 1U }; - m_ctx->CopySubresourceRegion(*(GSTexture11*)dTex, 0, 0, 0, 0, *(GSTexture11*)sTex, 0, &box); + // DX api isn't happy if we pass a box for depth copy + // It complains that depth/multisample must be a full copy + // and asks us to use a NULL for the box + bool depth = (sTex->GetType() == GSTexture::DepthStencil); + auto pBox = depth ? nullptr : &box; + + m_ctx->CopySubresourceRegion(*(GSTexture11*)dTex, 0, 0, 0, 0, *(GSTexture11*)sTex, 0, pBox); } -GSTexture* GSDevice11::CopyRenderTarget(GSTexture* src) +void GSDevice11::CloneTexture(GSTexture* src, GSTexture** dest) { + if (!src || !(src->GetType() == GSTexture::DepthStencil || src->GetType() == GSTexture::RenderTarget)) + { + ASSERT(0); + return; + } + int w = src->GetWidth(); int h = src->GetHeight(); - GSTexture* dest = CreateRenderTarget(w, h, false); + if (src->GetType() == GSTexture::DepthStencil) + *dest = CreateDepthStencil(w, h, src->GetFormat()); + else + *dest = CreateRenderTarget(w, h, src->GetFormat()); - CopyRect(src, dest, GSVector4i(0, 0, w, h)); - - return dest; + CopyRect(src, *dest, GSVector4i(0, 0, w, h)); } void GSDevice11::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, int shader, bool linear) diff --git a/plugins/GSdx/Renderers/DX11/GSDevice11.h b/plugins/GSdx/Renderers/DX11/GSDevice11.h index 42d7b6c861..8d8625f904 100644 --- a/plugins/GSdx/Renderers/DX11/GSDevice11.h +++ b/plugins/GSdx/Renderers/DX11/GSDevice11.h @@ -192,7 +192,7 @@ public: GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, int ps_shader = 0); - GSTexture* CopyRenderTarget(GSTexture* src); + void CloneTexture(GSTexture* src, GSTexture** dest); void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r);