[PATCH 2/4] wined3d: Do not use double-buffered dynamic buffers

Stefan Dösinger stefan at codeweavers.com
Tue Feb 28 05:19:26 CST 2012


This is for bug 30019.

They are a lot slower than using no VBO at all in at least some, if not all
games. The reason for the slowdown is the memcpy call, not the buffer
map.
---
 dlls/wined3d/buffer.c |   49 ++++++++++++++++++++++++++++---------------------
 1 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 495fe2f..691e0b9 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -734,6 +734,23 @@ static void buffer_direct_upload(struct wined3d_buffer *This, const struct wined
 }
 
 /* Do not call while under the GL lock. */
+static void wined3d_buffer_drop_bo(struct wined3d_buffer *buffer)
+{
+    struct wined3d_device *device = buffer->resource.device;
+
+    buffer_unload(&buffer->resource);
+    buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
+
+    /* The stream source state handler might have read the memory of
+     * the vertex buffer already and got the memory in the vbo which
+     * is not valid any longer. Dirtify the stream source to force a
+     * reload. This happens only once per changed vertexbuffer and
+     * should occur rather rarely. */
+    if (buffer->bind_count)
+        device_invalidate_state(device, STATE_STREAMSRC);
+}
+
+/* Do not call while under the GL lock. */
 void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer)
 {
     DWORD flags = buffer->flags & (WINED3D_BUFFER_NOSYNC | WINED3D_BUFFER_DISCARD);
@@ -782,6 +799,12 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer)
             buffer->full_conversion_count = 0;
         return;
     }
+    if (buffer->resource.usage & WINED3DUSAGE_DYNAMIC)
+    {
+        FIXME("Dropping VBO for double-buffered dynamic buffer %p\n", buffer);
+        wined3d_buffer_drop_bo(buffer);
+        return;
+    }
 
     /* If applications change the declaration over and over, reconverting all the time is a huge
      * performance hit. So count the declaration changes and release the VBO if there are too many
@@ -792,20 +815,10 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer)
         ++buffer->decl_change_count;
         buffer->draw_count = 0;
 
-        if (buffer->decl_change_count > VB_MAXDECLCHANGES
-                || (buffer->conversion_map && (buffer->resource.usage & WINED3DUSAGE_DYNAMIC)))
+        if (buffer->decl_change_count > VB_MAXDECLCHANGES)
         {
-            FIXME("Too many declaration changes or converting dynamic buffer, stopping converting\n");
-
-            buffer_unload(&buffer->resource);
-            buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
-
-            /* The stream source state handler might have read the memory of
-             * the vertex buffer already and got the memory in the vbo which
-             * is not valid any longer. Dirtify the stream source to force a
-             * reload. This happens only once per changed vertexbuffer and
-             * should occur rather rarely. */
-            device_invalidate_state(device, STATE_STREAMSRC);
+            FIXME("Too many declaration changes, stopping converting\n");
+            wined3d_buffer_drop_bo(buffer);
             return;
         }
 
@@ -834,10 +847,7 @@ void CDECL wined3d_buffer_preload(struct wined3d_buffer *buffer)
             if (buffer->full_conversion_count > VB_MAXFULLCONVERSIONS)
             {
                 FIXME("Too many full buffer conversions, stopping converting.\n");
-                buffer_unload(&buffer->resource);
-                buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
-                if (buffer->bind_count)
-                    device_invalidate_state(device, STATE_STREAMSRC);
+                wined3d_buffer_drop_bo(buffer);
                 return;
             }
         }
@@ -1061,10 +1071,7 @@ HRESULT CDECL wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UIN
                          * that returns unaligned pointers
                          */
                         TRACE("Dynamic buffer, dropping VBO\n");
-                        buffer_unload(&buffer->resource);
-                        buffer->flags &= ~WINED3D_BUFFER_CREATEBO;
-                        if (buffer->bind_count)
-                            device_invalidate_state(device, STATE_STREAMSRC);
+                        wined3d_buffer_drop_bo(buffer);
                     }
                     else
                     {
-- 
1.7.3.4




More information about the wine-patches mailing list