From e7637b3b410855296289ec8ebe199b80b5a7a2b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Sat, 6 Jul 2013 22:52:06 +0200
Subject: wined3d: Ignore buffer->resource.map_count in the CS

This fixes sporadic test failures caused by preload refusing to load
data into the GL buffer.

It's fine to preload or create a VBO if a DISCARD or NOOVERWRITE map is
happening at the same time. A non-dynamic map will finish the CS before
incrementing map_count.
---
 dlls/wined3d/buffer.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 551cc7a..3ac45c6 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -457,7 +457,8 @@ void buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *co
     data->buffer_object = buffer->buffer_object;
     if (!buffer->buffer_object)
     {
-        if ((buffer->flags & WINED3D_BUFFER_CREATEBO) && !buffer->resource.map_count)
+        if ((!buffer->resource.map_count || buffer->flags & WINED3D_BUFFER_DOUBLEBUFFER)
+                && buffer->flags & WINED3D_BUFFER_CREATEBO)
         {
             buffer_create_buffer_object(buffer, context);
             buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
@@ -737,12 +738,6 @@ void buffer_internal_preload(struct wined3d_buffer *buffer, struct wined3d_conte
 
     TRACE("buffer %p.\n", buffer);
 
-    if (buffer->resource.map_count)
-    {
-        WARN("Buffer is mapped, skipping preload.\n");
-        return;
-    }
-
     buffer_mark_used(buffer);
 
     if (!buffer->buffer_object)
@@ -934,6 +929,12 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer)
     struct wined3d_context *context;
     struct wined3d_device *device = buffer->resource.device;
 
+    if (buffer->resource.map_count)
+    {
+        WARN("Buffer is mapped, skipping preload.\n");
+        return;
+    }
+
     if (wined3d_settings.cs_multithreaded)
     {
         FIXME("Waiting for cs.\n");
-- 
2.1.3

