From f23d42ca6a96a3d257fc57dbae8d5ebd3620e4b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Tue, 23 Sep 2014 22:18:56 +0200
Subject: wined3d: Render target lock hack

---
 dlls/wined3d/resource.c        | 17 +++++++++++++++++
 dlls/wined3d/wined3d_main.c    |  7 +++++++
 dlls/wined3d/wined3d_private.h |  1 +
 3 files changed, 25 insertions(+)

diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index cd60356..dc36dd5 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -777,6 +777,17 @@ HRESULT wined3d_resource_map(struct wined3d_resource *resource,
     TRACE("resource %p, map_desc %p, box %p, flags %#x.\n",
             resource, map_desc, box, flags);
 
+    if (resource->usage & WINED3DUSAGE_RENDERTARGET && wined3d_settings.ignore_rt_map)
+    {
+        WARN("Ignoring render target map, only finishing CS.\n");
+        wined3d_cs_emit_glfinish(device->cs);
+        map_desc->row_pitch = 0;
+        map_desc->slice_pitch = 0;
+        map_desc->data = NULL;
+        device->cs->ops->finish(device->cs);
+        return WINED3D_OK;
+    }
+
     if (resource->map_count)
     {
         WARN("Volume is already mapped.\n");
@@ -880,6 +891,12 @@ HRESULT wined3d_resource_unmap(struct wined3d_resource *resource)
     struct wined3d_device *device = resource->device;
     TRACE("resource %p.\n", resource);
 
+    if (resource->usage & WINED3DUSAGE_RENDERTARGET && wined3d_settings.ignore_rt_map)
+    {
+        WARN("Ignoring render target unmap.\n");
+        return WINED3D_OK;
+    }
+
     if (!resource->map_count)
     {
         WARN("Trying to unlock an unlocked resource %p.\n", resource);
diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c
index e6dc444..a1e4e6c 100644
--- a/dlls/wined3d/wined3d_main.c
+++ b/dlls/wined3d/wined3d_main.c
@@ -86,6 +86,7 @@ struct wined3d_settings wined3d_settings =
     ~0U,            /* No PS shader model limit by default. */
     FALSE,          /* 3D support enabled by default. */
     FALSE,          /* No multithreaded CS by default. */
+    FALSE,          /* Do not ignore render target maps. */
 };
 
 struct wined3d * CDECL wined3d_create(DWORD flags)
@@ -311,6 +312,12 @@ static BOOL wined3d_dll_init(HINSTANCE hInstDLL)
             TRACE("Enabling multithreaded command stream.\n");
             wined3d_settings.cs_multithreaded = TRUE;
         }
+        if (!get_config_key(hkey, appkey, "ignore_rt_map", buffer, size)
+                && !strcmp(buffer,"enabled"))
+        {
+            TRACE("Ignoring render target maps.\n");
+            wined3d_settings.ignore_rt_map = TRUE;
+        }
     }
 
     if (appkey) RegCloseKey( appkey );
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 88329e5..dd06525 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -281,6 +281,7 @@ struct wined3d_settings
     unsigned int max_sm_ps;
     BOOL no_3d;
     BOOL cs_multithreaded;
+    BOOL ignore_rt_map;
 };
 
 extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN;
-- 
2.1.3

