Henri Verbeet : wined3d: Merge surface_unload() and volume_unload().

Alexandre Julliard julliard at wine.codeweavers.com
Tue Apr 19 10:55:57 CDT 2016


Module: wine
Branch: master
Commit: 9cdcc3e120d5d76166f18ecc4b1bf9d9397885e8
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9cdcc3e120d5d76166f18ecc4b1bf9d9397885e8

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Mon Apr 18 19:06:28 2016 +0200

wined3d: Merge surface_unload() and volume_unload().

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wined3d/device.c  |  8 ++++++--
 dlls/wined3d/surface.c | 44 +------------------------------------------
 dlls/wined3d/texture.c | 51 +++++++++++++++++++++++++++++++++++++++++---------
 dlls/wined3d/volume.c  | 27 +-------------------------
 4 files changed, 50 insertions(+), 80 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 149234b..f3fb732 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1138,8 +1138,10 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
     /* Unload resources */
     LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
     {
-        TRACE("Unloading resource %p.\n", resource);
+        if (resource->type == WINED3D_RTYPE_SURFACE || resource->type == WINED3D_RTYPE_VOLUME)
+            continue;
 
+        TRACE("Unloading resource %p.\n", resource);
         resource->resource_ops->resource_unload(resource);
     }
 
@@ -4532,8 +4534,10 @@ static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d
 
     LIST_FOR_EACH_ENTRY_SAFE(resource, cursor, &device->resources, struct wined3d_resource, resource_list_entry)
     {
-        TRACE("Unloading resource %p.\n", resource);
+        if (resource->type == WINED3D_RTYPE_SURFACE || resource->type == WINED3D_RTYPE_VOLUME)
+            continue;
 
+        TRACE("Unloading resource %p.\n", resource);
         resource->resource_ops->resource_unload(resource);
     }
 
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 9e8fddb..f43b186 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -845,49 +845,7 @@ static ULONG surface_resource_decref(struct wined3d_resource *resource)
 
 static void surface_unload(struct wined3d_resource *resource)
 {
-    struct wined3d_surface *surface = surface_from_resource(resource);
-    unsigned int sub_resource_idx = surface_get_sub_resource_idx(surface);
-    struct wined3d_texture *texture = surface->container;
-    struct wined3d_renderbuffer_entry *entry, *entry2;
-    struct wined3d_device *device = resource->device;
-    const struct wined3d_gl_info *gl_info;
-    struct wined3d_context *context;
-
-    TRACE("surface %p.\n", surface);
-
-    context = context_acquire(device, NULL);
-    gl_info = context->gl_info;
-
-    if (resource->pool == WINED3D_POOL_DEFAULT)
-    {
-        /* We should only get here on device reset/teardown for implicit
-         * resources. */
-        wined3d_texture_validate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
-        wined3d_texture_invalidate_location(texture, sub_resource_idx, ~WINED3D_LOCATION_DISCARDED);
-    }
-    else
-    {
-        surface_load_location(surface, context, texture->resource.map_binding);
-        wined3d_texture_invalidate_location(texture, sub_resource_idx, ~texture->resource.map_binding);
-    }
-
-    /* Destroy fbo render buffers. This is needed for implicit render targets, for
-     * all application-created targets the application has to release the surface
-     * before calling _Reset
-     */
-    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &surface->renderbuffers, struct wined3d_renderbuffer_entry, entry)
-    {
-        context_gl_resource_released(device, entry->id, TRUE);
-        gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
-        list_remove(&entry->entry);
-        HeapFree(GetProcessHeap(), 0, entry);
-    }
-    list_init(&surface->renderbuffers);
-    surface->current_renderbuffer = NULL;
-
-    context_release(context);
-
-    resource_unload(resource);
+    ERR("Not supported on sub-resources.\n");
 }
 
 static HRESULT surface_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index f89b5c9..e4ff67c 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1358,26 +1358,59 @@ static void wined3d_texture_unload(struct wined3d_resource *resource)
 {
     struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
     UINT sub_count = texture->level_count * texture->layer_count;
-    struct wined3d_context *context = NULL;
+    struct wined3d_device *device = resource->device;
+    const struct wined3d_gl_info *gl_info;
+    struct wined3d_context *context;
     UINT i;
 
     TRACE("texture %p.\n", texture);
 
+    context = context_acquire(device, NULL);
+    gl_info = context->gl_info;
+
     for (i = 0; i < sub_count; ++i)
     {
-        struct wined3d_resource *sub_resource = texture->sub_resources[i].resource;
-
-        sub_resource->resource_ops->resource_unload(sub_resource);
+        struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[i];
 
-        if (texture->sub_resources[i].buffer_object)
+        if (resource->pool != WINED3D_POOL_DEFAULT
+                && texture->texture_ops->texture_load_location(texture, i, context, resource->map_binding))
         {
-            if (!context)
-                context = context_acquire(texture->resource.device, NULL);
+            wined3d_texture_invalidate_location(texture, i, ~resource->map_binding);
+        }
+        else
+        {
+            /* We should only get here on device reset/teardown for implicit
+             * resources. */
+            if (resource->pool != WINED3D_POOL_DEFAULT || resource->type != WINED3D_RTYPE_TEXTURE_2D)
+                ERR("Discarding %s %p sub-resource %u in the %s pool.\n", debug_d3dresourcetype(resource->type),
+                        resource, i, debug_d3dpool(resource->pool));
+            wined3d_texture_validate_location(texture, i, WINED3D_LOCATION_DISCARDED);
+            wined3d_texture_invalidate_location(texture, i, ~WINED3D_LOCATION_DISCARDED);
+        }
+
+        if (sub_resource->buffer_object)
             wined3d_texture_remove_buffer_object(texture, i, context->gl_info);
+
+        if (resource->type == WINED3D_RTYPE_TEXTURE_2D)
+        {
+            struct wined3d_surface *surface = sub_resource->u.surface;
+            struct wined3d_renderbuffer_entry *entry, *entry2;
+
+            LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &surface->renderbuffers, struct wined3d_renderbuffer_entry, entry)
+            {
+                context_gl_resource_released(device, entry->id, TRUE);
+                gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
+                list_remove(&entry->entry);
+                HeapFree(GetProcessHeap(), 0, entry);
+            }
+            list_init(&surface->renderbuffers);
+            surface->current_renderbuffer = NULL;
         }
+
+        resource_unload(sub_resource->resource);
     }
-    if (context)
-        context_release(context);
+
+    context_release(context);
 
     wined3d_texture_force_reload(texture);
     wined3d_texture_unload_gl_texture(texture);
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 262bbac..89d5ead 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -366,32 +366,7 @@ void wined3d_volume_cleanup(struct wined3d_volume *volume)
 
 static void volume_unload(struct wined3d_resource *resource)
 {
-    struct wined3d_volume *volume = volume_from_resource(resource);
-    struct wined3d_texture *texture = volume->container;
-    struct wined3d_device *device = texture->resource.device;
-    struct wined3d_context *context;
-
-    if (texture->resource.pool == WINED3D_POOL_DEFAULT)
-        ERR("Unloading DEFAULT pool volume.\n");
-
-    TRACE("texture %p.\n", resource);
-
-    context = context_acquire(device, NULL);
-    if (wined3d_volume_load_location(volume, context, WINED3D_LOCATION_SYSMEM))
-    {
-        wined3d_texture_invalidate_location(texture, volume->texture_level, ~WINED3D_LOCATION_SYSMEM);
-    }
-    else
-    {
-        ERR("Out of memory when unloading volume %p.\n", volume);
-        wined3d_texture_validate_location(texture, volume->texture_level, WINED3D_LOCATION_DISCARDED);
-        wined3d_texture_invalidate_location(texture, volume->texture_level, ~WINED3D_LOCATION_DISCARDED);
-    }
-    context_release(context);
-
-    /* The texture name is managed by the container. */
-
-    resource_unload(resource);
+    ERR("Not supported on sub-resources.\n");
 }
 
 static ULONG volume_resource_incref(struct wined3d_resource *resource)




More information about the wine-cvs mailing list