[PATCH 4/5] wined3d: Move load_location into the resource.

Stefan Dösinger stefan at codeweavers.com
Thu Oct 3 06:08:20 CDT 2013


The resource part of load_location will handle transfers between sysmem
locations (heap memory, user memory, dib) and buffers. Texture loading
and downloading from textures will be delegated to surfaces / volumes.
---
 dlls/wined3d/buffer.c          |  8 ++++++++
 dlls/wined3d/resource.c        | 45 ++++++++++++++++++++++++++++++++++++++++++
 dlls/wined3d/surface.c         | 12 +++++++++--
 dlls/wined3d/texture.c         | 10 ++++++++++
 dlls/wined3d/volume.c          | 44 ++++++++++-------------------------------
 dlls/wined3d/wined3d_private.h |  5 +++++
 6 files changed, 88 insertions(+), 36 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index de06ae8..280f9d1 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -1128,9 +1128,17 @@ void CDECL wined3d_buffer_unmap(struct wined3d_buffer *buffer)
     }
 }
 
+/* Context activation is done by the caller. */
+static void wined3d_buffer_load_location(struct wined3d_resource *resource,
+        struct wined3d_context *context, DWORD location)
+{
+    ERR("Not yet implemented.\n");
+}
+
 static const struct wined3d_resource_ops buffer_resource_ops =
 {
     buffer_unload,
+    wined3d_buffer_load_location,
 };
 
 static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device *device,
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index e50ac29..1815c94 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -442,3 +442,48 @@ void wined3d_resource_invalidate_location(struct wined3d_resource *resource, DWO
     resource->locations &= ~location;
     TRACE("new location flags are %s.\n", wined3d_debug_location(resource->locations));
 }
+
+DWORD wined3d_resource_access_from_location(DWORD location)
+{
+    switch (location)
+    {
+        case WINED3D_LOCATION_DISCARDED:
+            return 0;
+
+        case WINED3D_LOCATION_SYSMEM:
+            return WINED3D_RESOURCE_ACCESS_CPU;
+
+        case WINED3D_LOCATION_BUFFER:
+        case WINED3D_LOCATION_TEXTURE_RGB:
+        case WINED3D_LOCATION_TEXTURE_SRGB:
+            return WINED3D_RESOURCE_ACCESS_GPU;
+
+        default:
+            FIXME("Unhandled location %#x.\n", location);
+            return 0;
+    }
+}
+
+/* Context activation is optionally by the caller. Context may be NULL. */
+void wined3d_resource_load_location(struct wined3d_resource *resource,
+        struct wined3d_context *context, DWORD location)
+{
+    DWORD required_access = wined3d_resource_access_from_location(location);
+
+    if ((resource->locations & location) == location)
+    {
+        TRACE("Location(s) already up to date.\n");
+        return;
+    }
+
+    /* Keep this a WARN for now until surfaces are cleaned up. */
+    if ((resource->access_flags & required_access) != required_access)
+        WARN("Operation requires %#x access, but resource only has %#x.\n",
+                required_access, resource->access_flags);
+
+    /* Context is NULL in ddraw-only operation without OpenGL. */
+    if (!context)
+        ERR("A context is required for non-sysmem operation.\n");
+
+    resource->resource_ops->resource_load_location(resource, context, location);
+}
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 9d7accd..4f2470f 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1561,9 +1561,17 @@ static void surface_unload(struct wined3d_resource *resource)
     resource_unload(resource);
 }
 
+/* Context activation is done by the caller. */
+static void wined3d_surface_load_location(struct wined3d_resource *resource,
+        struct wined3d_context *context, DWORD location)
+{
+    ERR("Not yet implemented.\n");
+}
+
 static const struct wined3d_resource_ops surface_resource_ops =
 {
     surface_unload,
+    wined3d_surface_load_location,
 };
 
 static const struct wined3d_surface_ops surface_ops =
@@ -5324,7 +5332,7 @@ void surface_invalidate_location(struct wined3d_surface *surface, DWORD location
         ERR("Surface %p does not have any up to date location.\n", surface);
 }
 
-static DWORD resource_access_from_location(DWORD location)
+static DWORD surface_access_from_location(DWORD location)
 {
     switch (location)
     {
@@ -5624,7 +5632,7 @@ HRESULT surface_load_location(struct wined3d_surface *surface, DWORD location, c
 
     if (WARN_ON(d3d_surface))
     {
-        DWORD required_access = resource_access_from_location(location);
+        DWORD required_access = surface_access_from_location(location);
         if ((surface->resource.access_flags & required_access) != required_access)
             WARN("Operation requires %#x access, but surface only has %#x.\n",
                     required_access, surface->resource.access_flags);
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 56d13f6..db95794 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -751,9 +751,17 @@ static const struct wined3d_texture_ops texture2d_ops =
     texture2d_sub_resource_cleanup,
 };
 
+/* Context activation is done by the caller. */
+static void wined3d_texture_load_location(struct wined3d_resource *resource,
+        struct wined3d_context *context, DWORD location)
+{
+    ERR("Should not be called on textures.\n");
+}
+
 static const struct wined3d_resource_ops texture2d_resource_ops =
 {
     texture2d_unload,
+    wined3d_texture_load_location,
 };
 
 static HRESULT cubetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
@@ -1114,9 +1122,11 @@ static const struct wined3d_texture_ops texture3d_ops =
     texture3d_sub_resource_cleanup,
 };
 
+/* Context activation is done by the caller. */
 static const struct wined3d_resource_ops texture3d_resource_ops =
 {
     texture3d_unload,
+    wined3d_texture_load_location,
 };
 
 static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index c0d0541..6eb926a 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -222,27 +222,6 @@ static void wined3d_volume_evict_sysmem(struct wined3d_volume *volume)
     wined3d_resource_invalidate_location(&volume->resource, WINED3D_LOCATION_SYSMEM);
 }
 
-static DWORD volume_access_from_location(DWORD location)
-{
-    switch (location)
-    {
-        case WINED3D_LOCATION_DISCARDED:
-            return 0;
-
-        case WINED3D_LOCATION_SYSMEM:
-            return WINED3D_RESOURCE_ACCESS_CPU;
-
-        case WINED3D_LOCATION_BUFFER:
-        case WINED3D_LOCATION_TEXTURE_RGB:
-        case WINED3D_LOCATION_TEXTURE_SRGB:
-            return WINED3D_RESOURCE_ACCESS_GPU;
-
-        default:
-            FIXME("Unhandled location %#x.\n", location);
-            return 0;
-    }
-}
-
 /* Context activation is done by the caller. */
 static void wined3d_volume_srgb_transfer(struct wined3d_volume *volume,
         struct wined3d_context *context, BOOL dest_is_srgb)
@@ -282,21 +261,17 @@ static BOOL wined3d_volume_can_evict(const struct wined3d_volume *volume)
 
     return TRUE;
 }
+
 /* Context activation is done by the caller. */
-static void wined3d_volume_load_location(struct wined3d_volume *volume,
+static void wined3d_volume_load_location(struct wined3d_resource *resource,
         struct wined3d_context *context, DWORD location)
 {
-    DWORD required_access = volume_access_from_location(location);
+    struct wined3d_volume *volume = volume_from_resource(resource);
+    DWORD required_access = wined3d_resource_access_from_location(location);
 
     TRACE("Volume %p, loading %s, have %s.\n", volume, wined3d_debug_location(location),
         wined3d_debug_location(volume->resource.locations));
 
-    if ((volume->resource.locations & location) == location)
-    {
-        TRACE("Location(s) already up to date.\n");
-        return;
-    }
-
     if ((volume->resource.access_flags & required_access) != required_access)
     {
         ERR("Operation requires %#x access, but volume only has %#x.\n",
@@ -427,7 +402,7 @@ void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context *
             volume->flags |= WINED3D_VFLAG_SRGB_ALLOCATED;
         }
 
-        wined3d_volume_load_location(volume, context, WINED3D_LOCATION_TEXTURE_SRGB);
+        wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_TEXTURE_SRGB);
     }
     else
     {
@@ -437,7 +412,7 @@ void wined3d_volume_load(struct wined3d_volume *volume, struct wined3d_context *
             volume->flags |= WINED3D_VFLAG_ALLOCATED;
         }
 
-        wined3d_volume_load_location(volume, context, WINED3D_LOCATION_TEXTURE_RGB);
+        wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_TEXTURE_RGB);
     }
 }
 
@@ -484,7 +459,7 @@ static void volume_unload(struct wined3d_resource *resource)
     if (volume_prepare_system_memory(volume))
     {
         context = context_acquire(device, NULL);
-        wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM);
+        wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_SYSMEM);
         context_release(context);
         wined3d_resource_invalidate_location(&volume->resource, ~WINED3D_LOCATION_SYSMEM);
     }
@@ -680,7 +655,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
         if (flags & WINED3D_MAP_DISCARD)
             wined3d_resource_validate_location(&volume->resource, WINED3D_LOCATION_BUFFER);
         else
-            wined3d_volume_load_location(volume, context, WINED3D_LOCATION_BUFFER);
+            wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_BUFFER);
 
         GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, volume->pbo));
 
@@ -718,7 +693,7 @@ HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
         else if (!(volume->resource.locations & WINED3D_LOCATION_SYSMEM))
         {
             context = context_acquire(device, NULL);
-            wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM);
+            wined3d_resource_load_location(&volume->resource, context, WINED3D_LOCATION_SYSMEM);
             context_release(context);
         }
         base_memory = volume->resource.heap_memory;
@@ -819,6 +794,7 @@ HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
 static const struct wined3d_resource_ops volume_resource_ops =
 {
     volume_unload,
+    wined3d_volume_load_location,
 };
 
 static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device *device, UINT width,
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 9ae4ea8..7a618df 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1987,6 +1987,8 @@ static inline void context_invalidate_active_texture(struct wined3d_context *con
 struct wined3d_resource_ops
 {
     void (*resource_unload)(struct wined3d_resource *resource);
+    void (*resource_load_location)(struct wined3d_resource *resource,
+            struct wined3d_context *context, DWORD location);
 };
 
 struct wined3d_resource
@@ -2039,6 +2041,9 @@ void wined3d_resource_validate_location(struct wined3d_resource *resource,
         DWORD location) DECLSPEC_HIDDEN;
 void wined3d_resource_invalidate_location(struct wined3d_resource *resource,
         DWORD location) DECLSPEC_HIDDEN;
+void wined3d_resource_load_location(struct wined3d_resource *resource,
+        struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
+DWORD wined3d_resource_access_from_location(DWORD location) DECLSPEC_HIDDEN;
 
 /* Tests show that the start address of resources is 32 byte aligned */
 #define RESOURCE_ALIGNMENT 16
-- 
1.8.1.5




More information about the wine-patches mailing list