Commit cc9c18a4 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Synchronise resource destruction with the command stream.

parent b21f3c93
......@@ -1342,6 +1342,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
ERR("Out of memory.\n");
buffer_unload(&buffer->resource);
resource_cleanup(&buffer->resource);
wined3d_resource_wait_idle(&buffer->resource);
return E_OUTOFMEMORY;
}
buffer->maps_size = 1;
......@@ -1351,6 +1352,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
ERR("Failed to upload data, hr %#x.\n", hr);
buffer_unload(&buffer->resource);
resource_cleanup(&buffer->resource);
wined3d_resource_wait_idle(&buffer->resource);
HeapFree(GetProcessHeap(), 0, buffer->maps);
return hr;
}
......
......@@ -239,6 +239,7 @@ static void wined3d_resource_destroy_object(void *object)
wined3d_resource_free_sysmem(resource);
context_resource_released(resource->device, resource, resource->type);
wined3d_resource_release(resource);
}
void resource_cleanup(struct wined3d_resource *resource)
......@@ -254,6 +255,7 @@ void resource_cleanup(struct wined3d_resource *resource)
}
device_resource_released(resource->device, resource);
wined3d_resource_acquire(resource);
wined3d_cs_emit_destroy_object(resource->device->cs, wined3d_resource_destroy_object, resource);
}
......
......@@ -816,6 +816,7 @@ static void wined3d_texture_cleanup_sync(struct wined3d_texture *texture)
{
wined3d_texture_sub_resources_destroyed(texture);
resource_cleanup(&texture->resource);
wined3d_resource_wait_idle(&texture->resource);
wined3d_texture_cleanup(texture);
}
......
......@@ -2498,6 +2498,7 @@ struct wined3d_resource
DWORD priority;
void *heap_memory;
struct list resource_list_entry;
LONG access_count;
void *parent;
const struct wined3d_parent_ops *parent_ops;
......@@ -2514,6 +2515,21 @@ static inline ULONG wined3d_resource_decref(struct wined3d_resource *resource)
return resource->resource_ops->resource_decref(resource);
}
static inline void wined3d_resource_acquire(struct wined3d_resource *resource)
{
InterlockedIncrement(&resource->access_count);
}
static inline void wined3d_resource_release(struct wined3d_resource *resource)
{
InterlockedDecrement(&resource->access_count);
}
static inline void wined3d_resource_wait_idle(struct wined3d_resource *resource)
{
while (InterlockedCompareExchange(&resource->access_count, 0, 0));
}
void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
enum wined3d_resource_type type, const struct wined3d_format *format,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment