libs/vkd3d: Re-use vkd3d_array_reserve() in d3d12_fence_SetEventOnCompletion().

This commit is contained in:
Józef Kucia 2016-10-05 19:01:57 +02:00
parent b224b6372c
commit c558118f70
2 changed files with 9 additions and 22 deletions

View File

@ -179,21 +179,12 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_SetEventOnCompletion(ID3D12Fence *i
} }
} }
if (fence->event_array_size == fence->event_count) if (!vkd3d_array_reserve((void **)&fence->events, &fence->events_size,
fence->event_count + 1, sizeof(*fence->events)))
{ {
unsigned int new_size = 2 * fence->event_array_size; WARN("Failed to add event.\n");
struct vkd3d_waiting_event *new_events; pthread_mutex_unlock(&fence->mutex);
return E_OUTOFMEMORY;
TRACE("Resizing waiting events array from %u to %u.\n", fence->event_array_size, new_size);
if (!(new_events = vkd3d_realloc(fence->events, new_size * sizeof(*fence->events))))
{
pthread_mutex_unlock(&fence->mutex);
return E_OUTOFMEMORY;
}
fence->event_array_size = new_size;
fence->events = new_events;
} }
fence->events[fence->event_count].value = value; fence->events[fence->event_count].value = value;
@ -280,12 +271,8 @@ static HRESULT d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device *
if (flags) if (flags)
FIXME("Ignoring flags %#x.\n", flags); FIXME("Ignoring flags %#x.\n", flags);
fence->event_array_size = 2; fence->events = NULL;
if (!(fence->events = vkd3d_calloc(fence->event_array_size, sizeof(*fence->events)))) fence->events_size = 0;
{
pthread_mutex_destroy(&fence->mutex);
return E_OUTOFMEMORY;
}
fence->event_count = 0; fence->event_count = 0;
fence->device = device; fence->device = device;

View File

@ -69,9 +69,9 @@ struct d3d12_fence
UINT64 value; UINT64 value;
pthread_mutex_t mutex; pthread_mutex_t mutex;
unsigned int event_array_size;
unsigned int event_count;
struct vkd3d_waiting_event *events; struct vkd3d_waiting_event *events;
size_t events_size;
size_t event_count;
struct d3d12_device *device; struct d3d12_device *device;
}; };