From e2f09806ffc0332e4b3fdb3a6112ad9a2bedb1c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Sun, 7 Jul 2013 12:06:31 +0200
Subject: wined3d: Preload buffers if streamsrc is not dirty

FIXME: Merge this with the preload calls done by
context_update_stream_info, preload only used buffers

FIXME2: Merge this patch with the patch that removes
PreLoad from buffer_unmap

FIXME3: There may be more unintended consequences of calling preload
here...
---
 dlls/wined3d/buffer.c          | 2 +-
 dlls/wined3d/context.c         | 6 +++++-
 dlls/wined3d/wined3d_private.h | 1 -
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 4e91176..7eef51e 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -711,7 +711,7 @@ static void buffer_direct_upload(struct wined3d_buffer *This, const struct wined
     checkGLcall("glUnmapBuffer");
 }
 
-void buffer_mark_used(struct wined3d_buffer *buffer)
+static void buffer_mark_used(struct wined3d_buffer *buffer)
 {
     buffer->flags &= ~(WINED3D_BUFFER_SYNC | WINED3D_BUFFER_DISCARD);
 }
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 46aa0cc..116bf67 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -3227,8 +3227,12 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de
         for (i = 0, map = context->stream_info.use_map; map; map >>= 1, ++i)
         {
             if (map & 1)
-                buffer_mark_used(state->streams[context->stream_info.elements[i].stream_idx].buffer);
+                buffer_internal_preload(state->streams[context->stream_info.elements[i].stream_idx].buffer,
+                        context, state);
         }
+        /* PreLoad may kick buffers out of vram. */
+        if (isStateDirty(context, STATE_STREAMSRC))
+            context_update_stream_info(context, state);
     }
     if (state->index_buffer)
     {
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index d320a62..4bbfe42 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2786,7 +2786,6 @@ void buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *co
 BYTE *buffer_get_sysmem(struct wined3d_buffer *This, struct wined3d_context *context) DECLSPEC_HIDDEN;
 void buffer_internal_preload(struct wined3d_buffer *buffer, struct wined3d_context *context,
         const struct wined3d_state *state) DECLSPEC_HIDDEN;
-void buffer_mark_used(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
 HRESULT wined3d_buffer_upload_data(struct wined3d_buffer *buffer,
         const struct wined3d_box *box, const void *data) DECLSPEC_HIDDEN;
 
-- 
2.6.4

