[2/6] WineD3D: Do not free regularily locked surfaces

Stefan Dösinger stefan at codeweavers.com
Fri Jan 12 11:57:26 CST 2007


This activates a long planned and partially started optimization in our 
surface loading code. If a surface is locked regularily do not free the 
system memory copy so it doesn't have to be downloaded on the next lock. The 
SFLAG_DYNLOCK flag is read already in the other code via SFLAG_DONOTFREE, and 
if the gl surface is modified readback still takes place
-------------- next part --------------
From e8c00acc0c5a975fb4e642d6c7034162956fee09 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Fri, 12 Jan 2007 12:52:58 +0100
Subject: [PATCH] WineD3D: Do not free regularily locked surfaces

---
 dlls/wined3d/surface.c         |   13 +++++++++++++
 dlls/wined3d/wined3d_private.h |    2 ++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index de263b9..ca9900a 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -824,6 +824,19 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED
         }
     }
 
+    /* Performance optimization: Count how often a surface is locked, if it is locked regularly do not throw away the system memory copy.
+     * This avoids the need to download the surface from opengl all the time. The surface is still downloaded if the opengl texture is
+     * changed
+     */
+    if(!(This->Flags & SFLAG_DYNLOCK)) {
+        This->lockCount++;
+        /* MAXLOCKCOUNT is defined in wined3d_private.h */
+        if(This->lockCount > MAXLOCKCOUNT) {
+            TRACE("Surface is locked regularily, not freeing the system memory copy any more\n");
+            This->Flags |= SFLAG_DYNLOCK;
+        }
+    }
+
     TRACE("returning memory@%p, pitch(%d) dirtyfied(%d)\n", pLockedRect->pBits, pLockedRect->Pitch, This->Flags & SFLAG_DIRTY ? 0 : 1);
 
     This->Flags |= SFLAG_LOCKED;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 5fe7c71..6d99657 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -984,6 +984,8 @@ struct IWineD3DSurfaceImpl
 
     RECT                      lockedRect;
     RECT                      dirtyRect;
+    int                       lockCount;
+#define MAXLOCKCOUNT          50 /* After this amount of locks do not free the sysmem copy */
 
     glDescriptor              glDescription;
 
-- 
1.4.4.3



More information about the wine-patches mailing list