From 2d87f930869bcd32273e722a50a13a9330ce6a30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 30 Aug 2013 22:42:33 +0200
Subject: wined3d: Fence texture reads in draws

This is probably stricter than necessary. GL BOs and allocated sysmem
are just staging resources. After they have been uploaded into the GL
texture, it's in theory OK to write new data buffer without interfering
with old draws. However, it is impossible to tell when if data has been
transfered into the texture because texture loads are delayed until draw
time. Specifically, it is difficult to separate two consecutive maps
from a map, draw, map sequence, where the draw hasn't been executed by
the time the second map occurs.

The other problem is that sRGB may cause a texture load from
buffer/sysmem even though the GL texture is thought to be loaded. This
is limited to situations where sRGB textures are supported, but
sRGB_decode isn't.
---
 dlls/wined3d/cs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index 9a7e6df..0277a1e 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -601,6 +601,11 @@ static UINT wined3d_cs_exec_draw(struct wined3d_cs *cs, const void *data)
         if (cs->state.streams[i].buffer)
             wined3d_resource_dec_fence(&cs->state.streams[i].buffer->resource);
     }
+    for (i = 0; i < sizeof(cs->state.textures) / sizeof(*cs->state.textures); i++)
+    {
+        if (cs->state.textures[i])
+            wined3d_resource_dec_fence(&cs->state.textures[i]->resource);
+    }
 
     return sizeof(*op);
 }
@@ -627,6 +632,11 @@ void wined3d_cs_emit_draw(struct wined3d_cs *cs, UINT start_idx, UINT index_coun
         if (state->streams[i].buffer)
             wined3d_resource_inc_fence(&state->streams[i].buffer->resource);
     }
+    for (i = 0; i < sizeof(state->textures) / sizeof(*state->textures); i++)
+    {
+        if (state->textures[i])
+            wined3d_resource_inc_fence(&state->textures[i]->resource);
+    }
 
     cs->ops->submit(cs, sizeof(*op));
 }
-- 
2.1.3

