[PATCH 4/5] wined3d: Move buffer mapping into resource.c.

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


The buffer type, GL usage etc. will be parameterized once d3d buffers
use the resource facilities for buffer management as well.
---
 dlls/wined3d/resource.c        | 64 +++++++++++++++++++++++++++++-
 dlls/wined3d/volume.c          | 90 +++++++-----------------------------------
 dlls/wined3d/wined3d_private.h |  7 +++-
 3 files changed, 82 insertions(+), 79 deletions(-)

diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 3398ebc..8a42cb6 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -420,7 +420,7 @@ GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags)
     return ret;
 }
 
-GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags)
+static GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags)
 {
     if (d3d_flags & WINED3D_MAP_READONLY)
         return GL_READ_ONLY_ARB;
@@ -487,3 +487,65 @@ void wined3d_resource_load_location(struct wined3d_resource *resource,
 
     resource->resource_ops->resource_load_location(resource, context, location);
 }
+
+BYTE *wined3d_resource_get_map_ptr(const struct wined3d_resource *resource,
+        const struct wined3d_context *context, DWORD flags)
+{
+    const struct wined3d_gl_info *gl_info;
+    BYTE *ptr;
+
+    switch (resource->map_binding)
+    {
+        case WINED3D_LOCATION_BUFFER:
+            gl_info = context->gl_info;
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, resource->buffer_object));
+
+            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, 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 GL buffer");
+            return ptr;
+
+        case WINED3D_LOCATION_SYSMEM:
+            return resource->heap_memory;
+
+        default:
+            ERR("Unexpected map binding %s.\n", wined3d_debug_location(resource->map_binding));
+            return NULL;
+    }
+}
+
+void wined3d_resource_release_map_ptr(const struct wined3d_resource *resource,
+        const struct wined3d_context *context)
+{
+    const struct wined3d_gl_info *gl_info;
+
+    switch (resource->map_binding)
+    {
+        case WINED3D_LOCATION_BUFFER:
+            gl_info = context->gl_info;
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, resource->buffer_object));
+            GL_EXTCALL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
+            checkGLcall("Unmap GL buffer");
+            return;
+
+        case WINED3D_LOCATION_SYSMEM:
+            return;
+
+        default:
+            ERR("Unexpected map binding %s.\n", wined3d_debug_location(resource->map_binding));
+            return;
+    }
+}
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 4376c9c..22e5523 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -301,7 +301,7 @@ static void wined3d_volume_load_location(struct wined3d_resource *resource,
             }
             else if (volume->resource.locations & WINED3D_LOCATION_BUFFER)
             {
-                struct wined3d_bo_address data = {volume->pbo, NULL};
+                struct wined3d_bo_address data = {volume->resource.buffer_object, NULL};
                 wined3d_volume_upload_data(volume, context, &data);
             }
             else if (volume->resource.locations & WINED3D_LOCATION_TEXTURE_RGB)
@@ -355,7 +355,7 @@ static void wined3d_volume_load_location(struct wined3d_resource *resource,
             break;
 
         case WINED3D_LOCATION_BUFFER:
-            if (!volume->pbo || volume->resource.map_binding != WINED3D_LOCATION_BUFFER)
+            if (!volume->resource.buffer_object || 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)
@@ -365,7 +365,7 @@ static void wined3d_volume_load_location(struct wined3d_resource *resource,
             }
             else if (volume->resource.locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
             {
-                struct wined3d_bo_address data = {volume->pbo, NULL};
+                struct wined3d_bo_address data = {volume->resource.buffer_object, NULL};
 
                 if (volume->resource.locations & WINED3D_LOCATION_TEXTURE_RGB)
                     volume_bind_and_dirtify(volume, context, FALSE);
@@ -421,16 +421,16 @@ static void wined3d_volume_prepare_pbo(struct wined3d_volume *volume, struct win
 {
     const struct wined3d_gl_info *gl_info = context->gl_info;
 
-    if (volume->pbo)
+    if (volume->resource.buffer_object)
         return;
 
-    GL_EXTCALL(glGenBuffersARB(1, &volume->pbo));
-    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
+    GL_EXTCALL(glGenBuffersARB(1, &volume->resource.buffer_object));
+    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->resource.buffer_object));
     GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->resource.size, NULL, GL_STREAM_DRAW_ARB));
     GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
     checkGLcall("Create PBO");
 
-    TRACE("Created PBO %u for volume %p.\n", volume->pbo, volume);
+    TRACE("Created PBO %u for volume %p.\n", volume->resource.buffer_object, volume);
 }
 
 static void wined3d_volume_free_pbo(struct wined3d_volume *volume)
@@ -438,10 +438,10 @@ static void wined3d_volume_free_pbo(struct wined3d_volume *volume)
     struct wined3d_context *context = context_acquire(volume->resource.device, NULL);
     const struct wined3d_gl_info *gl_info = context->gl_info;
 
-    TRACE("Deleting PBO %u belonging to volume %p.\n", volume->pbo, volume);
-    GL_EXTCALL(glDeleteBuffersARB(1, &volume->pbo));
+    TRACE("Deleting PBO %u belonging to volume %p.\n", volume->resource.buffer_object, volume);
+    GL_EXTCALL(glDeleteBuffersARB(1, &volume->resource.buffer_object));
     checkGLcall("glDeleteBuffersARB");
-    volume->pbo = 0;
+    volume->resource.buffer_object = 0;
     context_release(context);
 }
 
@@ -470,7 +470,7 @@ static void volume_unload(struct wined3d_resource *resource)
         wined3d_resource_invalidate_location(&volume->resource, ~WINED3D_LOCATION_DISCARDED);
     }
 
-    if (volume->pbo)
+    if (volume->resource.buffer_object)
     {
         /* Should not happen because only dynamic default pool volumes
          * have a buffer, and those are not evicted by device_evit_managed_resources
@@ -519,7 +519,7 @@ ULONG CDECL wined3d_volume_decref(struct wined3d_volume *volume)
 
     if (!refcount)
     {
-        if (volume->pbo)
+        if (volume->resource.buffer_object)
             wined3d_volume_free_pbo(volume);
 
         resource_cleanup(&volume->resource);
@@ -627,44 +627,6 @@ static BOOL wined3d_volume_prepare_map_memory(struct wined3d_volume *volume, str
     }
 }
 
-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)
 {
@@ -715,7 +677,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
     else
         wined3d_resource_load_location(&volume->resource, context, volume->resource.map_binding);
 
-    base_memory = wined3d_volume_get_map_ptr(volume, context, flags);
+    base_memory = wined3d_resource_get_map_ptr(&volume->resource, context, flags);
     context_release(context);
 
     TRACE("Base memory pointer %p.\n", base_memory);
@@ -777,30 +739,6 @@ 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;
@@ -814,7 +752,7 @@ HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
     }
 
     context = context_acquire(device, NULL);
-    wined3d_volume_release_map_ptr(volume, context);
+    wined3d_resource_release_map_ptr(&volume->resource, context);
     context_release(context);
 
     volume->resource.map_count--;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 3f28536..c2f1333 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2015,6 +2015,7 @@ struct wined3d_resource
 
     DWORD locations, map_binding;
     void *heap_memory;
+    GLuint buffer_object;
 
     void *parent;
     const struct wined3d_parent_ops *parent_ops;
@@ -2036,7 +2037,6 @@ void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HI
 DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource,
         DWORD flags) DECLSPEC_HIDDEN;
 GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
-GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
 void wined3d_resource_validate_location(struct wined3d_resource *resource,
         DWORD location) DECLSPEC_HIDDEN;
 void wined3d_resource_invalidate_location(struct wined3d_resource *resource,
@@ -2044,6 +2044,10 @@ void wined3d_resource_invalidate_location(struct wined3d_resource *resource,
 void wined3d_resource_load_location(struct wined3d_resource *resource,
         struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
 DWORD resource_access_from_location(DWORD location) DECLSPEC_HIDDEN;
+BYTE *wined3d_resource_get_map_ptr(const struct wined3d_resource *resource,
+        const struct wined3d_context *context, DWORD flags) DECLSPEC_HIDDEN;
+void wined3d_resource_release_map_ptr(const struct wined3d_resource *resource,
+        const struct wined3d_context *context) DECLSPEC_HIDDEN;
 
 /* Tests show that the start address of resources is 32 byte aligned */
 #define RESOURCE_ALIGNMENT 16
@@ -2149,7 +2153,6 @@ struct wined3d_volume
     DWORD flags;
     GLint texture_level;
     DWORD download_count;
-    GLuint pbo;
 };
 
 static inline struct wined3d_volume *volume_from_resource(struct wined3d_resource *resource)
-- 
1.8.1.5




More information about the wine-patches mailing list