From 607eeb6bdbea6787dd6f5cc10c74e9b92e903e0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 30 Aug 2013 10:41:42 +0200
Subject: wined3d: Fence update_texture and update_surface calls

---
 dlls/wined3d/cs.c       |  6 ++++++
 dlls/wined3d/resource.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index d05f65d..7111c98 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -1967,6 +1967,9 @@ static UINT wined3d_cs_exec_update_texture(struct wined3d_cs *cs, const void *da
     device_exec_update_texture(context, op->src, op->dst);
     context_release(context);
 
+    wined3d_resource_dec_fence(&op->src->resource);
+    wined3d_resource_dec_fence(&op->dst->resource);
+
     return sizeof(*op);
 }
 
@@ -1980,6 +1983,9 @@ void wined3d_cs_emit_update_texture(struct wined3d_cs *cs, struct wined3d_textur
     op->src = src;
     op->dst = dst;
 
+    wined3d_resource_inc_fence(&op->src->resource);
+    wined3d_resource_inc_fence(&op->dst->resource);
+
     cs->ops->submit(cs, sizeof(*op));
 }
 
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index e1ae8d4..1e3f6b4 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -821,6 +821,32 @@ void *wined3d_resource_map_internal(struct wined3d_resource *resource, DWORD fla
     return mem;
 }
 
+static void wined3d_resource_sync(struct wined3d_resource *resource)
+{
+    struct wined3d_resource *real_res = resource;
+    struct wined3d_surface *surface;
+    struct wined3d_volume *volume;
+
+    switch (resource->type)
+    {
+        case WINED3D_RTYPE_SURFACE:
+            surface = surface_from_resource(resource);
+            if (surface->container)
+                real_res = &surface->container->resource;
+            break;
+
+        case WINED3D_RTYPE_VOLUME:
+            volume = volume_from_resource(resource);
+            real_res = &volume->container->resource;
+            break;
+
+        default:
+            break;
+    }
+    if (!real_res->access_fence)
+        FIXME("Waiting for CS even though resource %p is idle.\n", resource);
+}
+
 HRESULT wined3d_resource_map(struct wined3d_resource *resource,
         struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
 {
@@ -840,6 +866,8 @@ HRESULT wined3d_resource_map(struct wined3d_resource *resource,
 
     flags = wined3d_resource_sanitize_map_flags(resource, flags);
 
+    wined3d_resource_sync(resource);
+
     base_memory = wined3d_cs_emit_resource_map(device->cs, resource, flags);
     if (!base_memory)
     {
-- 
2.7.0

