[PATCH 3/5] wined3d: Add a map_binding resource field to switch between sysmem and buffer.

Stefan Dösinger stefan at codeweavers.com
Tue Oct 1 06:05:41 CDT 2013


---
 dlls/wined3d/volume.c          | 168 ++++++++++++++++++++++++-----------------
 dlls/wined3d/wined3d_private.h |   5 +-
 2 files changed, 102 insertions(+), 71 deletions(-)

diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index dd34290..4376c9c 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -355,7 +355,7 @@ static void wined3d_volume_load_location(struct wined3d_resource *resource,
             break;
 
         case WINED3D_LOCATION_BUFFER:
-            if (!volume->pbo || !(volume->flags & WINED3D_VFLAG_PBO))
+            if (!volume->pbo || volume->resource.map_binding != WINED3D_LOCATION_BUFFER)
                 ERR("Trying to load WINED3D_LOCATION_BUFFER without setting it up first.\n");
 
             if (volume->resource.locations & WINED3D_LOCATION_DISCARDED)
@@ -609,12 +609,67 @@ static BOOL wined3d_volume_check_box_dimensions(const struct wined3d_volume *vol
     return TRUE;
 }
 
+/* Context activation is done by the caller. */
+static BOOL wined3d_volume_prepare_map_memory(struct wined3d_volume *volume, struct wined3d_context *context)
+{
+    switch (volume->resource.map_binding)
+    {
+        case WINED3D_LOCATION_BUFFER:
+            wined3d_volume_prepare_pbo(volume, context);
+            return TRUE;
+
+        case WINED3D_LOCATION_SYSMEM:
+            return volume_prepare_system_memory(volume);
+
+        default:
+            ERR("Unexpected map binding %s.\n", wined3d_debug_location(volume->resource.map_binding));
+            return FALSE;
+    }
+}
+
+static BYTE *wined3d_volume_get_map_ptr(const struct wined3d_volume *volume,
+        const struct wined3d_context *context, DWORD flags)
+{
+    const struct wined3d_gl_info *gl_info;
+    BYTE *ptr;
+
+    switch (volume->resource.map_binding)
+    {
+        case WINED3D_LOCATION_BUFFER:
+            gl_info = context->gl_info;
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
+
+            if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
+            {
+                GLbitfield mapflags = wined3d_resource_gl_map_flags(flags);
+                mapflags &= ~GL_MAP_FLUSH_EXPLICIT_BIT;
+                ptr = GL_EXTCALL(glMapBufferRange(GL_PIXEL_UNPACK_BUFFER_ARB,
+                        0, volume->resource.size, mapflags));
+            }
+            else
+            {
+                GLenum access = wined3d_resource_gl_legacy_map_flags(flags);
+                ptr = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, access));
+            }
+
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
+            checkGLcall("Map PBO");
+            return ptr;
+
+        case WINED3D_LOCATION_SYSMEM:
+            return volume->resource.heap_memory;
+
+        default:
+            ERR("Unexpected map binding %s.\n", wined3d_debug_location(volume->resource.map_binding));
+            return NULL;
+    }
+}
+
 HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
         struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
 {
     struct wined3d_device *device = volume->resource.device;
     struct wined3d_context *context;
-    const struct wined3d_gl_info *gl_info;
     BYTE *base_memory;
     const struct wined3d_format *format = volume->resource.format;
 
@@ -646,58 +701,22 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
 
     flags = wined3d_resource_sanitize_map_flags(&volume->resource, flags);
 
-    if (volume->flags & WINED3D_VFLAG_PBO)
+    context = context_acquire(device, NULL);
+    if (!wined3d_volume_prepare_map_memory(volume, context))
     {
-        context = context_acquire(device, NULL);
-        gl_info = context->gl_info;
-
-        wined3d_volume_prepare_pbo(volume, context);
-        if (flags & WINED3D_MAP_DISCARD)
-            wined3d_resource_validate_location(&volume->resource, WINED3D_LOCATION_BUFFER);
-        else
-            wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_BUFFER);
-
-        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
-
-        if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
-        {
-            GLbitfield mapflags = wined3d_resource_gl_map_flags(flags);
-            mapflags &= ~GL_MAP_FLUSH_EXPLICIT_BIT;
-            base_memory = GL_EXTCALL(glMapBufferRange(GL_PIXEL_UNPACK_BUFFER_ARB,
-                    0, volume->resource.size, mapflags));
-        }
-        else
-        {
-            GLenum access = wined3d_resource_gl_legacy_map_flags(flags);
-            base_memory = GL_EXTCALL(glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, access));
-        }
-
-        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
-        checkGLcall("Map PBO");
-
+        WARN("Out of memory.\n");
+        map_desc->data = NULL;
         context_release(context);
+        return E_OUTOFMEMORY;
     }
+
+    if (flags & WINED3D_MAP_DISCARD)
+        wined3d_resource_validate_location(&volume->resource, volume->resource.map_binding);
     else
-    {
-        if (!volume_prepare_system_memory(volume))
-        {
-            WARN("Out of memory.\n");
-            map_desc->data = NULL;
-            return E_OUTOFMEMORY;
-        }
+        wined3d_resource_load_location(&volume->resource, context, volume->resource.map_binding);
 
-        if (flags & WINED3D_MAP_DISCARD)
-        {
-            wined3d_resource_validate_location(&volume->resource, WINED3D_LOCATION_SYSMEM);
-        }
-        else if (!(volume->resource.locations & WINED3D_LOCATION_SYSMEM))
-        {
-            context = context_acquire(device, NULL);
-            wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_SYSMEM);
-            context_release(context);
-        }
-        base_memory = volume->resource.heap_memory;
-    }
+    base_memory = wined3d_volume_get_map_ptr(volume, context, flags);
+    context_release(context);
 
     TRACE("Base memory pointer %p.\n", base_memory);
 
@@ -742,11 +761,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
     if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
     {
         wined3d_texture_set_dirty(volume->container);
-
-        if (volume->flags & WINED3D_VFLAG_PBO)
-            wined3d_resource_invalidate_location(&volume->resource, ~WINED3D_LOCATION_BUFFER);
-        else
-            wined3d_resource_invalidate_location(&volume->resource, ~WINED3D_LOCATION_SYSMEM);
+        wined3d_resource_invalidate_location(&volume->resource, ~volume->resource.map_binding);
     }
 
     volume->resource.map_count++;
@@ -762,8 +777,34 @@ struct wined3d_volume * CDECL wined3d_volume_from_resource(struct wined3d_resour
     return volume_from_resource(resource);
 }
 
+static void wined3d_volume_release_map_ptr(const struct wined3d_volume *volume,
+        const struct wined3d_context *context)
+{
+    const struct wined3d_gl_info *gl_info;
+
+    switch (volume->resource.map_binding)
+    {
+        case WINED3D_LOCATION_BUFFER:
+            gl_info = context->gl_info;
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
+            GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
+            checkGLcall("Unmap PBO");
+            return;
+
+        case WINED3D_LOCATION_SYSMEM:
+            return;
+
+        default:
+            ERR("Unexpected map binding %s.\n", wined3d_debug_location(volume->resource.map_binding));
+            return;
+    }
+}
+
 HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
 {
+    struct wined3d_device *device = volume->resource.device;
+    struct wined3d_context *context;
     TRACE("volume %p.\n", volume);
 
     if (!volume->resource.map_count)
@@ -772,19 +813,9 @@ HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
         return WINED3DERR_INVALIDCALL;
     }
 
-    if (volume->flags & WINED3D_VFLAG_PBO)
-    {
-        struct wined3d_device *device = volume->resource.device;
-        struct wined3d_context *context = context_acquire(device, NULL);
-        const struct wined3d_gl_info *gl_info = context->gl_info;
-
-        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
-        GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
-        GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
-        checkGLcall("Unmap PBO");
-
-        context_release(context);
-    }
+    context = context_acquire(device, NULL);
+    wined3d_volume_release_map_ptr(volume, context);
+    context_release(context);
 
     volume->resource.map_count--;
 
@@ -833,13 +864,14 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device
 
     volume->texture_level = level;
     volume->resource.locations = WINED3D_LOCATION_DISCARDED;
+    volume->resource.map_binding = WINED3D_LOCATION_SYSMEM;
 
     if (pool == WINED3D_POOL_DEFAULT && usage & WINED3DUSAGE_DYNAMIC
             && gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]
             && !format->convert)
     {
         wined3d_resource_free_sysmem(&volume->resource);
-        volume->flags |= WINED3D_VFLAG_PBO;
+        volume->resource.map_binding = WINED3D_LOCATION_BUFFER;
     }
 
     return WINED3D_OK;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index ebfd668..3f28536 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2013,7 +2013,7 @@ struct wined3d_resource
     struct list privateData;
     struct list resource_list_entry;
 
-    DWORD locations;
+    DWORD locations, map_binding;
     void *heap_memory;
 
     void *parent;
@@ -2131,8 +2131,7 @@ void wined3d_texture_set_dirty(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
 
 #define WINED3D_VFLAG_ALLOCATED         0x00000001
 #define WINED3D_VFLAG_SRGB_ALLOCATED    0x00000002
-#define WINED3D_VFLAG_PBO               0x00000004
-#define WINED3D_VFLAG_CLIENT_STORAGE    0x00000008
+#define WINED3D_VFLAG_CLIENT_STORAGE    0x00000004
 
 #define WINED3D_LOCATION_DISCARDED      0x00000001
 #define WINED3D_LOCATION_SYSMEM         0x00000002
-- 
1.8.1.5




More information about the wine-patches mailing list