wined3d: Merge surface_unload() and volume_unload().

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2016-04-18 19:06:28 +02:00 committed by Alexandre Julliard
parent 16ff4e7cf6
commit 9cdcc3e120
4 changed files with 51 additions and 81 deletions

View File

@ -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);
}

View File

@ -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,

View File

@ -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;
struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[i];
sub_resource->resource_ops->resource_unload(sub_resource);
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_remove_buffer_object(texture, i, context->gl_info);
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);

View File

@ -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)