From 180d8cf49a4f4481b08e373e8c8a75c116094e63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Mon, 8 Sep 2014 15:09:44 +0200
Subject: wined3d: Don't try to sync VBOs manually on OSX with CSMT.

This fixes a performance regression in some games caused by
aaf4849718c3c3a763c460a24a51dd6c6b55524a.

GL_ARB_sync and GL_APPLE_fence seem to be fairly slow on OSX. Putting the
buffer back into synchonized mode and synchronizing all future uploads
is about twice as fast. This was benchmarked with 3DMark2001. Gunpoint,
another game that depends on synchronized dynamic buffer maps, feels
smoother, although the lack of a benchmark mode makes testing this difficult.

This assumes that if a game maps a dynamic buffer without NOOVERWRITE or
DISCARD once it will always do so. I have not seen a game yet that mixes
async and sync maps. If the game mixes them, the wined3d-side CS will still
update the buffer asynchronously. Only the worker thread -> GL copy is
synchronized, as it used to be for all buffers in cx13.

This patch only changes the double-buffered (used for CSMT) codepath. Making
the same change to the glMapBuffer codepath improves 3DMark2001 performance
as well, but the difference is much smaller. I will leave the manual sync
code in place until we have a game that clearly profits from this change.
---
 dlls/wined3d/buffer.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index e6e56bb..b33dd5a 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -676,8 +676,14 @@ static void buffer_direct_upload(struct wined3d_buffer *This, const struct wined
     else if (flags & WINED3D_BUFFER_SYNC && This->flags & WINED3D_BUFFER_APPLESYNC)
     {
         /* OSX doesn't do non-blocking asynchonous glBufferSubData like Linux drivers do, so we want to set
-         * GL_BUFFER_FLUSHING_UNMAP_APPLE to GL_FALSE. This means we have to do synchonization ourselves. */
-        buffer_sync_apple(This, 0, gl_info);
+         * GL_BUFFER_SERIALIZED_MODIFY_APPLE to GL_FALSE. Unfortunately ARB_sync and APPLE_fence are pretty
+         * slow on OSX. Putting the buffer back into synchronized mode for future maps is a lot faster.
+         * (GeForce 650M, Mavericks). The difference between ARB_sync and normal buffer operation is small
+         * in the glMapBuffer codepath without CSMT. */
+        glFinish();
+        GL_EXTCALL(glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_TRUE));
+        checkGLcall("glBufferParameteriAPPLE(This->buffer_type_hint, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_TRUE)");
+        This->flags &= ~WINED3D_BUFFER_APPLESYNC;
     }
 
     while (This->modified_areas)
-- 
2.1.3

