From 8cc0c9a0f108f4dd27b5c19a3fbd5c47dc921170 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Mon, 22 Mar 2021 14:36:52 +0100 Subject: [PATCH] [d3d9] Clamp dirty buffer range And always maintain dirty range. --- src/d3d9/d3d9_device.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index d5d28854c..82b706c7f 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -4365,19 +4365,17 @@ namespace dxvk { const bool quickRead = ((Flags & D3DLOCK_READONLY) && !pResource->WasWrittenByGPU()); const bool boundsCheck = desc.Pool != D3DPOOL_DEFAULT && !quickRead; - if (boundsCheck) { - // We can only respect this for these cases -- otherwise R/W OOB still get copied on native - // and some stupid games depend on that. - const bool respectUserBounds = !(Flags & D3DLOCK_DISCARD) && - SizeToLock != 0; + // We can only respect this for these cases -- otherwise R/W OOB still get copied on native + // and some stupid games depend on that. + const bool respectUserBounds = !(Flags & D3DLOCK_DISCARD) && + SizeToLock != 0; - // If we don't respect the bounds, encompass it all in our tests/checks - // These values may be out of range and don't get clamped. - uint32_t offset = respectUserBounds ? OffsetToLock : 0; - uint32_t size = respectUserBounds ? SizeToLock : desc.Size; + // If we don't respect the bounds, encompass it all in our tests/checks + // These values may be out of range and don't get clamped. + uint32_t offset = respectUserBounds ? OffsetToLock : 0; + uint32_t size = respectUserBounds ? std::min(SizeToLock, desc.Size - offset) : (desc.Size - offset); - pResource->DirtyRange().Conjoin(D3D9Range(offset, offset + size)); - } + pResource->DirtyRange().Conjoin(D3D9Range(offset, offset + size)); Rc mappingBuffer = pResource->GetBuffer();