From a1a91dd76663ecd5fddd6e3388857a839ec097dc Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Sun, 11 Jun 2023 13:42:01 +0200 Subject: [PATCH] [d3d9] Fix potential race when discarding systemmem textures --- src/d3d9/d3d9_device.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index d6788c3a..8764aab3 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -4384,7 +4384,11 @@ namespace dxvk { // then we need to copy -> buffer // We are also always dirty if we are a render target, // a depth stencil, or auto generate mipmaps. - bool needsReadback = (pResource->NeedsReadback(Subresource) || renderable) && !(Flags & D3DLOCK_DISCARD); + bool needsReadback = pResource->NeedsReadback(Subresource) || renderable; + + // Skip readback if we discard is specified. We can only do this for textures that have an associated Vulkan image. + // Any other texture might write to the Vulkan staging buffer directly. (GetBackbufferData for example) + needsReadback &= pResource->GetImage() != nullptr || !(Flags & D3DLOCK_DISCARD); pResource->SetNeedsReadback(Subresource, false);