From 60a7047550451495274c488606d9d872addb5c70 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Fri, 30 Jul 2021 23:53:48 +0200 Subject: [PATCH] [d3d9] Fix D3DLOCK_READONLY handling with evictManagedOnUnlock --- src/d3d9/d3d9_device.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 3fae30c0..f1dfd500 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -4280,7 +4280,9 @@ namespace dxvk { pResource->SetLocked(Subresource, true); - if ((desc.Pool == D3DPOOL_DEFAULT || !(Flags & D3DLOCK_NO_DIRTY_UPDATE)) && !(Flags & D3DLOCK_READONLY)) { + const bool noDirtyUpdate = Flags & D3DLOCK_NO_DIRTY_UPDATE; + if (likely((pResource->IsManaged() && m_d3d9Options.evictManagedOnUnlock) + || ((desc.Pool == D3DPOOL_DEFAULT || !noDirtyUpdate) && !readOnly))) { if (pBox && MipLevel != 0) { D3DBOX scaledBox = *pBox; scaledBox.Left <<= MipLevel; @@ -4341,8 +4343,9 @@ namespace dxvk { // Flush image contents from staging if we aren't read only // and we aren't deferring for managed. + const D3DBOX& box = pResource->GetDirtyBox(Face); bool shouldFlush = pResource->GetMapMode() == D3D9_COMMON_TEXTURE_MAP_MODE_BACKED; - shouldFlush &= !pResource->GetReadOnlyLocked(Subresource); + shouldFlush &= box.Left < box.Right && box.Top < box.Bottom && box.Front < box.Back; shouldFlush &= !pResource->IsManaged() || m_d3d9Options.evictManagedOnUnlock; if (shouldFlush) { @@ -4658,7 +4661,7 @@ namespace dxvk { if (pResource->GetMapMode() != D3D9_COMMON_BUFFER_MAP_MODE_BUFFER) return D3D_OK; - if (pResource->GetMapFlags() & D3DLOCK_READONLY) + if (pResource->DirtyRange().IsDegenerate()) return D3D_OK; pResource->SetMapFlags(0);