From 623448f852044dd7bbb117f4869359058ce96dd1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 30 Jan 2016 22:56:24 -0800 Subject: [PATCH] d3d9: Support blitting depth on frame switch. Can be optimized more, but this makes Jeanne d'Arc work in D3D9 now. Not sure why it didn't work before. --- GPU/Directx9/FramebufferDX9.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 9939fb865e..e17ef677cf 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -433,7 +433,6 @@ namespace DX9 { // If depth wasn't updated, then we're at least "two degrees" away from the data. // This is an optimization: it probably doesn't need to be copied in this case. } else { - // TODO: Needs work BlitFramebufferDepth(prevVfb, vfb); } } @@ -521,16 +520,14 @@ namespace DX9 { } void FramebufferManagerDX9::BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst) { - if (src->z_address == dst->z_address && - src->z_stride != 0 && dst->z_stride != 0 && - src->renderWidth == dst->renderWidth && - src->renderHeight == dst->renderHeight) { - + bool matchingDepthBuffer = src->z_address == dst->z_address && src->z_stride != 0 && dst->z_stride != 0; + bool matchingSize = src->width == dst->width && src->height == dst->height; + if (matchingDepthBuffer && matchingSize) { // Doesn't work. Use a shader maybe? - /*fbo_unbind(); + fbo_unbind(); - LPDIRECT3DTEXTURE9 srcTex = fbo_get_depth_texture(src->fbo); - LPDIRECT3DTEXTURE9 dstTex = fbo_get_depth_texture(dst->fbo); + LPDIRECT3DTEXTURE9 srcTex = fbo_get_depth_texture(src->fbo_dx9); + LPDIRECT3DTEXTURE9 dstTex = fbo_get_depth_texture(dst->fbo_dx9); if (srcTex && dstTex) { D3DSURFACE_DESC srcDesc; @@ -543,12 +540,16 @@ namespace DX9 { HRESULT srcLockRes = srcTex->LockRect(0, &srcLock, nullptr, D3DLOCK_READONLY); HRESULT dstLockRes = dstTex->LockRect(0, &dstLock, nullptr, 0); if (SUCCEEDED(srcLockRes) && SUCCEEDED(dstLockRes)) { - int pitch = std::min(srcLock.Pitch, dstLock.Pitch); + u32 pitch = std::min(srcLock.Pitch, dstLock.Pitch); + u32 w = std::min(pitch / 4, std::min(srcDesc.Width, dstDesc.Width)); u32 h = std::min(srcDesc.Height, dstDesc.Height); const u8 *srcp = (const u8 *)srcLock.pBits; u8 *dstp = (u8 *)dstLock.pBits; + // TODO: Optimize. But probably don't change the stencil bits. for (u32 y = 0; y < h; ++y) { - memcpy(dstp, srcp, pitch); + for (u32 x = 0; x < w; ++x) { + memcpy(dstp + x * 4, srcp + x * 4, 3); + } dstp += dstLock.Pitch; srcp += srcLock.Pitch; } @@ -561,7 +562,7 @@ namespace DX9 { } } - RebindFramebuffer();*/ + RebindFramebuffer(); } }