diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 14b3c8b8..62fc5149 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -33,17 +33,11 @@ HRESULT vkd3d_queue_create(struct d3d12_device *device, { const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; struct vkd3d_queue *object; - int rc; if (!(object = vkd3d_malloc(sizeof(*object)))) return E_OUTOFMEMORY; - if ((rc = vkd3d_mutex_init(&object->mutex))) - { - ERR("Failed to initialize mutex, error %d.\n", rc); - vkd3d_free(object); - return hresult_from_errno(rc); - } + vkd3d_mutex_init(&object->mutex); object->completed_sequence_number = 0; object->submitted_sequence_number = 0; @@ -71,10 +65,8 @@ void vkd3d_queue_destroy(struct vkd3d_queue *queue, struct d3d12_device *device) { const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; unsigned int i; - int rc; - if ((rc = vkd3d_mutex_lock(&queue->mutex))) - ERR("Failed to lock mutex, error %d.\n", rc); + vkd3d_mutex_lock(&queue->mutex); for (i = 0; i < queue->semaphore_count; ++i) VK_CALL(vkDestroySemaphore(device->vk_device, queue->semaphores[i].vk_semaphore, NULL)); @@ -87,8 +79,7 @@ void vkd3d_queue_destroy(struct vkd3d_queue *queue, struct d3d12_device *device) VK_CALL(vkDestroySemaphore(device->vk_device, queue->old_vk_semaphores[i], NULL)); } - if (!rc) - vkd3d_mutex_unlock(&queue->mutex); + vkd3d_mutex_unlock(&queue->mutex); vkd3d_mutex_destroy(&queue->mutex); vkd3d_free(queue); @@ -96,15 +87,9 @@ void vkd3d_queue_destroy(struct vkd3d_queue *queue, struct d3d12_device *device) VkQueue vkd3d_queue_acquire(struct vkd3d_queue *queue) { - int rc; - TRACE("queue %p.\n", queue); - if ((rc = vkd3d_mutex_lock(&queue->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return VK_NULL_HANDLE; - } + vkd3d_mutex_lock(&queue->mutex); assert(queue->vk_queue); return queue->vk_queue; @@ -148,13 +133,8 @@ static void vkd3d_queue_update_sequence_number(struct vkd3d_queue *queue, uint64_t completed_sequence_number; VkSemaphore vk_semaphore; unsigned int i, j; - int rc; - if ((rc = vkd3d_mutex_lock(&queue->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&queue->mutex); completed_sequence_number = queue->completed_sequence_number; queue->completed_sequence_number = max(sequence_number, queue->completed_sequence_number); @@ -255,15 +235,10 @@ static HRESULT vkd3d_enqueue_gpu_fence(struct vkd3d_fence_worker *worker, struct vkd3d_queue *queue, uint64_t queue_sequence_number) { struct vkd3d_waiting_fence *waiting_fence; - int rc; TRACE("worker %p, fence %p, value %#"PRIx64".\n", worker, fence, value); - if ((rc = vkd3d_mutex_lock(&worker->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&worker->mutex); if (!vkd3d_array_reserve((void **)&worker->fences, &worker->fences_size, worker->fence_count + 1, sizeof(*worker->fences))) @@ -349,24 +324,15 @@ static void *vkd3d_fence_worker_main(void *arg) struct vkd3d_waiting_fence *old_fences, *cur_fences = NULL; struct vkd3d_fence_worker *worker = arg; unsigned int i; - int rc; vkd3d_set_thread_name("vkd3d_fence"); for (;;) { - if ((rc = vkd3d_mutex_lock(&worker->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - break; - } + vkd3d_mutex_lock(&worker->mutex); - if (!worker->fence_count && !worker->should_exit && (rc = vkd3d_cond_wait(&worker->cond, &worker->mutex))) - { - ERR("Failed to wait on condition variable, error %d.\n", rc); - vkd3d_mutex_unlock(&worker->mutex); - break; - } + if (!worker->fence_count && !worker->should_exit) + vkd3d_cond_wait(&worker->cond, &worker->mutex); if (worker->should_exit) { @@ -399,7 +365,6 @@ static HRESULT vkd3d_fence_worker_start(struct vkd3d_fence_worker *worker, struct vkd3d_queue *queue, struct d3d12_device *device) { HRESULT hr; - int rc; TRACE("worker %p.\n", worker); @@ -414,18 +379,9 @@ static HRESULT vkd3d_fence_worker_start(struct vkd3d_fence_worker *worker, worker->wait_for_gpu_fence = device->vk_info.KHR_timeline_semaphore ? vkd3d_wait_for_gpu_timeline_semaphore : vkd3d_wait_for_gpu_fence; - if ((rc = vkd3d_mutex_init(&worker->mutex))) - { - ERR("Failed to initialize mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_init(&worker->mutex); - if ((rc = vkd3d_cond_init(&worker->cond))) - { - ERR("Failed to initialize condition variable, error %d.\n", rc); - vkd3d_mutex_destroy(&worker->mutex); - return hresult_from_errno(rc); - } + vkd3d_cond_init(&worker->cond); if (FAILED(hr = vkd3d_create_thread(device->vkd3d_instance, vkd3d_fence_worker_main, worker, &worker->thread))) @@ -441,15 +397,10 @@ static HRESULT vkd3d_fence_worker_stop(struct vkd3d_fence_worker *worker, struct d3d12_device *device) { HRESULT hr; - int rc; TRACE("worker %p.\n", worker); - if ((rc = vkd3d_mutex_lock(&worker->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&worker->mutex); worker->should_exit = true; vkd3d_cond_signal(&worker->cond); @@ -513,15 +464,10 @@ static VkResult d3d12_fence_create_vk_fence(struct d3d12_fence *fence, VkFence * VkFenceCreateInfo fence_info; unsigned int i; VkResult vr; - int rc; *vk_fence = VK_NULL_HANDLE; - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - goto create_fence; - } + vkd3d_mutex_lock(&fence->mutex); for (i = 0; i < ARRAY_SIZE(fence->old_vk_fences); ++i) { @@ -537,7 +483,6 @@ static VkResult d3d12_fence_create_vk_fence(struct d3d12_fence *fence, VkFence * if (*vk_fence) return VK_SUCCESS; -create_fence: vk_procs = &device->vk_procs; fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; @@ -596,13 +541,8 @@ static void d3d12_fence_destroy_vk_objects(struct d3d12_fence *fence) const struct vkd3d_vk_device_procs *vk_procs; struct d3d12_device *device = fence->device; unsigned int i; - int rc; - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&fence->mutex); vk_procs = &device->vk_procs; @@ -655,13 +595,7 @@ static struct vkd3d_signaled_semaphore *d3d12_fence_acquire_vk_semaphore_locked( static void d3d12_fence_remove_vk_semaphore(struct d3d12_fence *fence, struct vkd3d_signaled_semaphore *semaphore) { - int rc; - - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&fence->mutex); assert(semaphore->u.binary.is_acquired); @@ -672,13 +606,7 @@ static void d3d12_fence_remove_vk_semaphore(struct d3d12_fence *fence, struct vk static void d3d12_fence_release_vk_semaphore(struct d3d12_fence *fence, struct vkd3d_signaled_semaphore *semaphore) { - int rc; - - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&fence->mutex); assert(semaphore->u.binary.is_acquired); semaphore->u.binary.is_acquired = false; @@ -699,13 +627,7 @@ static void d3d12_fence_update_pending_value_locked(struct d3d12_fence *fence) static HRESULT d3d12_fence_update_pending_value(struct d3d12_fence *fence) { - int rc; - - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&fence->mutex); d3d12_fence_update_pending_value_locked(fence); @@ -719,13 +641,8 @@ static HRESULT d3d12_device_add_blocked_command_queues(struct d3d12_device *devi { HRESULT hr = S_OK; unsigned int i; - int rc; - if ((rc = vkd3d_mutex_lock(&device->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&device->mutex); if ((i = ARRAY_SIZE(device->blocked_queues) - device->blocked_queue_count) < count) { @@ -745,15 +662,10 @@ static HRESULT d3d12_device_flush_blocked_queues_once(struct d3d12_device *devic { struct d3d12_command_queue *blocked_queues[VKD3D_MAX_DEVICE_BLOCKED_QUEUES]; unsigned int i, blocked_queue_count; - int rc; *flushed_any = false; - if ((rc = vkd3d_mutex_lock(&device->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&device->mutex); /* Flush any ops unblocked by a new pending value. These cannot be flushed * with the device locked, so move the queue pointers to a local array. */ @@ -799,15 +711,10 @@ static HRESULT d3d12_fence_add_vk_semaphore(struct d3d12_fence *fence, VkSemapho VkFence vk_fence, uint64_t value, const struct vkd3d_queue *signalling_queue) { struct vkd3d_signaled_semaphore *semaphore; - int rc; TRACE("fence %p, value %#"PRIx64".\n", fence, value); - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&fence->mutex); d3d12_fence_garbage_collect_vk_semaphores_locked(fence, false); @@ -874,13 +781,8 @@ static HRESULT d3d12_fence_signal(struct d3d12_fence *fence, uint64_t value, VkF struct d3d12_device *device = fence->device; struct vkd3d_signaled_semaphore *current; unsigned int i; - int rc; - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&fence->mutex); fence->value = value; @@ -922,13 +824,8 @@ static uint64_t d3d12_fence_add_pending_timeline_signal(struct d3d12_fence *fenc const struct vkd3d_queue *signalling_queue) { struct vkd3d_signaled_semaphore *semaphore; - int rc; - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&fence->mutex); if (!vkd3d_array_reserve((void **)&fence->semaphores, &fence->semaphores_size, fence->semaphore_count + 1, sizeof(*fence->semaphores))) @@ -967,13 +864,8 @@ static void d3d12_fence_signal_timeline_semaphore(struct d3d12_fence *fence, uin { bool did_signal; unsigned int i; - int rc; - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&fence->mutex); /* With multiple fence workers, it is possible that signal calls are out of * order. The physical value itself is monotonic, but we need to make sure @@ -1061,7 +953,6 @@ static ULONG STDMETHODCALLTYPE d3d12_fence_Release(ID3D12Fence *iface) static void d3d12_fence_decref(struct d3d12_fence *fence) { ULONG internal_refcount = InterlockedDecrement(&fence->internal_refcount); - int rc; if (!internal_refcount) { @@ -1073,8 +964,7 @@ static void d3d12_fence_decref(struct d3d12_fence *fence) vkd3d_free(fence->events); vkd3d_free(fence->semaphores); - if ((rc = vkd3d_mutex_destroy(&fence->mutex))) - ERR("Failed to destroy mutex, error %d.\n", rc); + vkd3d_mutex_destroy(&fence->mutex); vkd3d_cond_destroy(&fence->null_event_cond); vkd3d_free(fence); @@ -1136,15 +1026,10 @@ static UINT64 STDMETHODCALLTYPE d3d12_fence_GetCompletedValue(ID3D12Fence *iface { struct d3d12_fence *fence = impl_from_ID3D12Fence(iface); uint64_t completed_value; - int rc; TRACE("iface %p.\n", iface); - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return 0; - } + vkd3d_mutex_lock(&fence->mutex); completed_value = fence->value; vkd3d_mutex_unlock(&fence->mutex); return completed_value; @@ -1156,15 +1041,10 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_SetEventOnCompletion(ID3D12Fence *i struct d3d12_fence *fence = impl_from_ID3D12Fence(iface); unsigned int i; bool latch = false; - int rc; TRACE("iface %p, value %#"PRIx64", event %p.\n", iface, value, event); - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&fence->mutex); if (value <= fence->value) { @@ -1215,13 +1095,7 @@ static HRESULT STDMETHODCALLTYPE d3d12_fence_SetEventOnCompletion(ID3D12Fence *i static HRESULT d3d12_fence_signal_cpu_timeline_semaphore(struct d3d12_fence *fence, uint64_t value) { - int rc; - - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&fence->mutex); fence->value = value; d3d12_fence_signal_external_events_locked(fence); @@ -1276,7 +1150,6 @@ static HRESULT d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device * const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; VkResult vr; HRESULT hr; - int rc; fence->ID3D12Fence_iface.lpVtbl = &d3d12_fence_vtbl; fence->internal_refcount = 1; @@ -1285,18 +1158,9 @@ static HRESULT d3d12_fence_init(struct d3d12_fence *fence, struct d3d12_device * fence->value = initial_value; fence->max_pending_value = initial_value; - if ((rc = vkd3d_mutex_init(&fence->mutex))) - { - ERR("Failed to initialize mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_init(&fence->mutex); - if ((rc = vkd3d_cond_init(&fence->null_event_cond))) - { - ERR("Failed to initialize cond variable, error %d.\n", rc); - hr = hresult_from_errno(rc); - goto fail_destroy_mutex; - } + vkd3d_cond_init(&fence->null_event_cond); if (flags) FIXME("Ignoring flags %#x.\n", flags); @@ -1335,7 +1199,6 @@ fail_destroy_timeline_semaphore: VK_CALL(vkDestroySemaphore(device->vk_device, fence->timeline_semaphore, NULL)); fail_destroy_null_cond: vkd3d_cond_destroy(&fence->null_event_cond); -fail_destroy_mutex: vkd3d_mutex_destroy(&fence->mutex); return hr; @@ -6294,7 +6157,6 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm struct vkd3d_cs_op_data *op; VkCommandBuffer *buffers; unsigned int i; - int rc; TRACE("iface %p, command_list_count %u, command_lists %p.\n", iface, command_list_count, command_lists); @@ -6323,11 +6185,7 @@ static void STDMETHODCALLTYPE d3d12_command_queue_ExecuteCommandLists(ID3D12Comm buffers[i] = cmd_list->vk_command_buffer; } - if ((rc = vkd3d_mutex_lock(&command_queue->op_mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&command_queue->op_mutex); if (!command_queue->ops_count) { @@ -6372,15 +6230,10 @@ static HRESULT vkd3d_enqueue_timeline_semaphore(struct vkd3d_fence_worker *worke struct d3d12_fence *fence, uint64_t value, struct vkd3d_queue *queue) { struct vkd3d_waiting_fence *waiting_fence; - int rc; TRACE("worker %p, fence %p, value %#"PRIx64".\n", worker, fence, value); - if ((rc = vkd3d_mutex_lock(&worker->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&worker->mutex); if (!vkd3d_array_reserve((void **)&worker->fences, &worker->fences_size, worker->fence_count + 1, sizeof(*worker->fences))) @@ -6410,15 +6263,10 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_queue_Signal(ID3D12CommandQueue * struct d3d12_fence *fence = unsafe_impl_from_ID3D12Fence(fence_iface); struct vkd3d_cs_op_data *op; HRESULT hr = S_OK; - int rc; TRACE("iface %p, fence %p, value %#"PRIx64".\n", iface, fence_iface, value); - if ((rc = vkd3d_mutex_lock(&command_queue->op_mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&command_queue->op_mutex); if (!command_queue->ops_count) { @@ -6757,21 +6605,11 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_queue_Wait(ID3D12CommandQueue *if struct d3d12_fence *fence = unsafe_impl_from_ID3D12Fence(fence_iface); struct vkd3d_cs_op_data *op; HRESULT hr = S_OK; - int rc; TRACE("iface %p, fence %p, value %#"PRIx64".\n", iface, fence_iface, value); - if ((rc = vkd3d_mutex_lock(&command_queue->op_mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } - if ((rc = vkd3d_mutex_lock(&fence->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - hr = hresult_from_errno(rc); - goto done; - } + vkd3d_mutex_lock(&command_queue->op_mutex); + vkd3d_mutex_lock(&fence->mutex); if (!command_queue->ops_count && value <= fence->max_pending_value) { @@ -6940,7 +6778,6 @@ static bool d3d12_command_queue_flush_ops(struct d3d12_command_queue *queue, boo struct d3d12_fence *fence; bool flushed_all = false; unsigned int i; - int rc; if (!queue->ops_count) return true; @@ -6951,11 +6788,7 @@ static bool d3d12_command_queue_flush_ops(struct d3d12_command_queue *queue, boo if (queue->is_flushing) return true; - if ((rc = vkd3d_mutex_lock(&queue->op_mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return true; - } + vkd3d_mutex_lock(&queue->op_mutex); /* Currently only required for d3d12_command_queue_signal(), but set it here anyway. */ queue->is_flushing = true; @@ -7008,7 +6841,6 @@ static HRESULT d3d12_command_queue_init(struct d3d12_command_queue *queue, struct d3d12_device *device, const D3D12_COMMAND_QUEUE_DESC *desc) { HRESULT hr; - int rc; queue->ID3D12CommandQueue_iface.lpVtbl = &d3d12_command_queue_vtbl; queue->refcount = 1; @@ -7042,11 +6874,7 @@ static HRESULT d3d12_command_queue_init(struct d3d12_command_queue *queue, if (FAILED(hr = vkd3d_private_store_init(&queue->private_store))) return hr; - if ((rc = vkd3d_mutex_init(&queue->op_mutex)) < 0) - { - hr = hresult_from_errno(rc); - goto fail_destroy_private_store; - } + vkd3d_mutex_init(&queue->op_mutex); if (FAILED(hr = vkd3d_fence_worker_start(&queue->fence_worker, queue->vkd3d_queue, device))) goto fail_destroy_op_mutex; @@ -7057,7 +6885,6 @@ static HRESULT d3d12_command_queue_init(struct d3d12_command_queue *queue, fail_destroy_op_mutex: vkd3d_mutex_destroy(&queue->op_mutex); -fail_destroy_private_store: vkd3d_private_store_destroy(&queue->private_store); return hr; } diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 071972d5..21dd17ea 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -2052,13 +2052,8 @@ static HRESULT d3d12_device_init_pipeline_cache(struct d3d12_device *device) const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs; VkPipelineCacheCreateInfo cache_info; VkResult vr; - int rc; - if ((rc = vkd3d_mutex_init(&device->mutex))) - { - ERR("Failed to initialize mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_init(&device->mutex); cache_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; cache_info.pNext = NULL; @@ -2149,17 +2144,12 @@ D3D12_GPU_VIRTUAL_ADDRESS vkd3d_gpu_va_allocator_allocate(struct vkd3d_gpu_va_al size_t alignment, size_t size, void *ptr) { D3D12_GPU_VIRTUAL_ADDRESS address; - int rc; if (size > ~(size_t)0 - (alignment - 1)) return 0; size = align(size, alignment); - if ((rc = vkd3d_mutex_lock(&allocator->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return 0; - } + vkd3d_mutex_lock(&allocator->mutex); if (size <= VKD3D_VA_SLAB_SIZE && allocator->free_slab) address = vkd3d_gpu_va_allocator_allocate_slab(allocator, size, ptr); @@ -2225,7 +2215,6 @@ void *vkd3d_gpu_va_allocator_dereference(struct vkd3d_gpu_va_allocator *allocato D3D12_GPU_VIRTUAL_ADDRESS address) { void *ret; - int rc; /* If we land in the non-fallback region, dereferencing VA is lock-less. * The base pointer is immutable, and the only way we can have a data race @@ -2237,11 +2226,7 @@ void *vkd3d_gpu_va_allocator_dereference(struct vkd3d_gpu_va_allocator *allocato return vkd3d_gpu_va_allocator_dereference_slab(allocator, address); /* Slow fallback. */ - if ((rc = vkd3d_mutex_lock(&allocator->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return NULL; - } + vkd3d_mutex_lock(&allocator->mutex); ret = vkd3d_gpu_va_allocator_dereference_fallback(allocator, address); @@ -2298,13 +2283,7 @@ static void vkd3d_gpu_va_allocator_free_fallback(struct vkd3d_gpu_va_allocator * void vkd3d_gpu_va_allocator_free(struct vkd3d_gpu_va_allocator *allocator, D3D12_GPU_VIRTUAL_ADDRESS address) { - int rc; - - if ((rc = vkd3d_mutex_lock(&allocator->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&allocator->mutex); if (address < VKD3D_VA_FALLBACK_BASE) { @@ -2321,7 +2300,6 @@ void vkd3d_gpu_va_allocator_free(struct vkd3d_gpu_va_allocator *allocator, D3D12 static bool vkd3d_gpu_va_allocator_init(struct vkd3d_gpu_va_allocator *allocator) { unsigned int i; - int rc; memset(allocator, 0, sizeof(*allocator)); allocator->fallback_floor = VKD3D_VA_FALLBACK_BASE; @@ -2341,25 +2319,14 @@ static bool vkd3d_gpu_va_allocator_init(struct vkd3d_gpu_va_allocator *allocator allocator->slabs[i].ptr = &allocator->slabs[i + 1]; } - if ((rc = vkd3d_mutex_init(&allocator->mutex))) - { - ERR("Failed to initialize mutex, error %d.\n", rc); - vkd3d_free(allocator->slabs); - return false; - } + vkd3d_mutex_init(&allocator->mutex); return true; } static void vkd3d_gpu_va_allocator_cleanup(struct vkd3d_gpu_va_allocator *allocator) { - int rc; - - if ((rc = vkd3d_mutex_lock(&allocator->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&allocator->mutex); vkd3d_free(allocator->slabs); vkd3d_free(allocator->fallback_allocations); vkd3d_mutex_unlock(&allocator->mutex); diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index 60f2bb75..856a1ebf 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -443,15 +443,8 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset, struct d3d12_device *device = heap->device; HRESULT hr = S_OK; VkResult vr; - int rc; - if ((rc = vkd3d_mutex_lock(&heap->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - if (data) - *data = NULL; - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&heap->mutex); assert(!resource->map_count || heap->map_ptr); @@ -501,13 +494,8 @@ static HRESULT d3d12_heap_map(struct d3d12_heap *heap, uint64_t offset, static void d3d12_heap_unmap(struct d3d12_heap *heap, struct d3d12_resource *resource) { struct d3d12_device *device = heap->device; - int rc; - if ((rc = vkd3d_mutex_lock(&heap->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return; - } + vkd3d_mutex_lock(&heap->mutex); if (!resource->map_count) { @@ -570,7 +558,6 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap, VkMemoryRequirements memory_requirements; VkDeviceSize vk_memory_size; HRESULT hr; - int rc; heap->ID3D12Heap_iface.lpVtbl = &d3d12_heap_vtbl; heap->refcount = 1; @@ -596,11 +583,7 @@ static HRESULT d3d12_heap_init(struct d3d12_heap *heap, if (FAILED(hr = validate_heap_desc(&heap->desc, resource))) return hr; - if ((rc = vkd3d_mutex_init(&heap->mutex))) - { - ERR("Failed to initialize mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_init(&heap->mutex); if (FAILED(hr = vkd3d_private_store_init(&heap->private_store))) { diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index 02f739d2..44f57f60 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -1689,14 +1689,8 @@ HRESULT vkd3d_render_pass_cache_find(struct vkd3d_render_pass_cache *cache, bool found = false; HRESULT hr = S_OK; unsigned int i; - int rc; - if ((rc = vkd3d_mutex_lock(&device->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - *vk_render_pass = VK_NULL_HANDLE; - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&device->mutex); for (i = 0; i < cache->render_pass_count; ++i) { @@ -3371,28 +3365,23 @@ static VkPipeline d3d12_pipeline_state_find_compiled_pipeline(const struct d3d12 struct d3d12_device *device = state->device; VkPipeline vk_pipeline = VK_NULL_HANDLE; struct vkd3d_compiled_pipeline *current; - int rc; *vk_render_pass = VK_NULL_HANDLE; - if (!(rc = vkd3d_mutex_lock(&device->mutex))) + vkd3d_mutex_lock(&device->mutex); + + LIST_FOR_EACH_ENTRY(current, &graphics->compiled_pipelines, struct vkd3d_compiled_pipeline, entry) { - LIST_FOR_EACH_ENTRY(current, &graphics->compiled_pipelines, struct vkd3d_compiled_pipeline, entry) + if (!memcmp(¤t->key, key, sizeof(*key))) { - if (!memcmp(¤t->key, key, sizeof(*key))) - { - vk_pipeline = current->vk_pipeline; - *vk_render_pass = current->vk_render_pass; - break; - } + vk_pipeline = current->vk_pipeline; + *vk_render_pass = current->vk_render_pass; + break; } - vkd3d_mutex_unlock(&device->mutex); - } - else - { - ERR("Failed to lock mutex, error %d.\n", rc); } + vkd3d_mutex_unlock(&device->mutex); + return vk_pipeline; } @@ -3402,7 +3391,6 @@ static bool d3d12_pipeline_state_put_pipeline_to_cache(struct d3d12_pipeline_sta struct d3d12_graphics_pipeline_state *graphics = &state->u.graphics; struct vkd3d_compiled_pipeline *compiled_pipeline, *current; struct d3d12_device *device = state->device; - int rc; if (!(compiled_pipeline = vkd3d_malloc(sizeof(*compiled_pipeline)))) return false; @@ -3411,12 +3399,7 @@ static bool d3d12_pipeline_state_put_pipeline_to_cache(struct d3d12_pipeline_sta compiled_pipeline->vk_pipeline = vk_pipeline; compiled_pipeline->vk_render_pass = vk_render_pass; - if ((rc = vkd3d_mutex_lock(&device->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - vkd3d_free(compiled_pipeline); - return false; - } + vkd3d_mutex_lock(&device->mutex); LIST_FOR_EACH_ENTRY(current, &graphics->compiled_pipelines, struct vkd3d_compiled_pipeline, entry) { diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index 5f67c8b9..9b28068b 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -948,16 +948,11 @@ HRESULT vkd3d_get_private_data(struct vkd3d_private_store *store, const struct vkd3d_private_data *data; HRESULT hr = S_OK; unsigned int size; - int rc; if (!out_size) return E_INVALIDARG; - if ((rc = vkd3d_mutex_lock(&store->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&store->mutex); if (!(data = vkd3d_private_store_get_private_data(store, tag))) { @@ -990,13 +985,8 @@ HRESULT vkd3d_set_private_data(struct vkd3d_private_store *store, const GUID *tag, unsigned int data_size, const void *data) { HRESULT hr; - int rc; - if ((rc = vkd3d_mutex_lock(&store->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&store->mutex); hr = vkd3d_private_store_set_private_data(store, tag, data, data_size, false); @@ -1009,13 +999,8 @@ HRESULT vkd3d_set_private_data_interface(struct vkd3d_private_store *store, { const void *data = object ? object : (void *)&object; HRESULT hr; - int rc; - if ((rc = vkd3d_mutex_lock(&store->mutex))) - { - ERR("Failed to lock mutex, error %d.\n", rc); - return hresult_from_errno(rc); - } + vkd3d_mutex_lock(&store->mutex); hr = vkd3d_private_store_set_private_data(store, tag, data, sizeof(object), !!object); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 3cabb2da..9920275d 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -207,56 +207,52 @@ struct vkd3d_cond CONDITION_VARIABLE cond; }; -static inline int vkd3d_mutex_init(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_init(struct vkd3d_mutex *lock) { InitializeCriticalSection(&lock->lock); - return 0; } -static inline int vkd3d_mutex_lock(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_lock(struct vkd3d_mutex *lock) { EnterCriticalSection(&lock->lock); - return 0; } -static inline int vkd3d_mutex_unlock(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_unlock(struct vkd3d_mutex *lock) { LeaveCriticalSection(&lock->lock); - return 0; } -static inline int vkd3d_mutex_destroy(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_destroy(struct vkd3d_mutex *lock) { DeleteCriticalSection(&lock->lock); - return 0; } -static inline int vkd3d_cond_init(struct vkd3d_cond *cond) +static inline void vkd3d_cond_init(struct vkd3d_cond *cond) { InitializeConditionVariable(&cond->cond); - return 0; } -static inline int vkd3d_cond_signal(struct vkd3d_cond *cond) +static inline void vkd3d_cond_signal(struct vkd3d_cond *cond) { WakeConditionVariable(&cond->cond); - return 0; } -static inline int vkd3d_cond_broadcast(struct vkd3d_cond *cond) +static inline void vkd3d_cond_broadcast(struct vkd3d_cond *cond) { WakeAllConditionVariable(&cond->cond); - return 0; } -static inline int vkd3d_cond_wait(struct vkd3d_cond *cond, struct vkd3d_mutex *lock) +static inline void vkd3d_cond_wait(struct vkd3d_cond *cond, struct vkd3d_mutex *lock) { - return !SleepConditionVariableCS(&cond->cond, &lock->lock, INFINITE); + BOOL ret; + + ret = SleepConditionVariableCS(&cond->cond, &lock->lock, INFINITE); + if (ret) + ERR("Could not sleep on the condition variable, error %u.\n", GetLastError()); } -static inline int vkd3d_cond_destroy(struct vkd3d_cond *cond) +static inline void vkd3d_cond_destroy(struct vkd3d_cond *cond) { - return 0; } #else /* _WIN32 */ @@ -280,49 +276,85 @@ struct vkd3d_cond }; -static inline int vkd3d_mutex_init(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_init(struct vkd3d_mutex *lock) { - return pthread_mutex_init(&lock->lock, NULL); + int ret; + + ret = pthread_mutex_init(&lock->lock, NULL); + if (ret) + ERR("Could not initialize the mutex, error %d.\n", ret); } -static inline int vkd3d_mutex_lock(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_lock(struct vkd3d_mutex *lock) { - return pthread_mutex_lock(&lock->lock); + int ret; + + ret = pthread_mutex_lock(&lock->lock); + if (ret) + ERR("Could not lock the mutex, error %d.\n", ret); } -static inline int vkd3d_mutex_unlock(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_unlock(struct vkd3d_mutex *lock) { - return pthread_mutex_unlock(&lock->lock); + int ret; + + ret = pthread_mutex_unlock(&lock->lock); + if (ret) + ERR("Could not unlock the mutex, error %d.\n", ret); } -static inline int vkd3d_mutex_destroy(struct vkd3d_mutex *lock) +static inline void vkd3d_mutex_destroy(struct vkd3d_mutex *lock) { - return pthread_mutex_destroy(&lock->lock); + int ret; + + ret = pthread_mutex_destroy(&lock->lock); + if (ret) + ERR("Could not destroy the mutex, error %d.\n", ret); } -static inline int vkd3d_cond_init(struct vkd3d_cond *cond) +static inline void vkd3d_cond_init(struct vkd3d_cond *cond) { - return pthread_cond_init(&cond->cond, NULL); + int ret; + + ret = pthread_cond_init(&cond->cond, NULL); + if (ret) + ERR("Could not initialize the condition variable, error %d.\n", ret); } -static inline int vkd3d_cond_signal(struct vkd3d_cond *cond) +static inline void vkd3d_cond_signal(struct vkd3d_cond *cond) { - return pthread_cond_signal(&cond->cond); + int ret; + + ret = pthread_cond_signal(&cond->cond); + if (ret) + ERR("Could not signal the condition variable, error %d.\n", ret); } -static inline int vkd3d_cond_broadcast(struct vkd3d_cond *cond) +static inline void vkd3d_cond_broadcast(struct vkd3d_cond *cond) { - return pthread_cond_broadcast(&cond->cond); + int ret; + + ret = pthread_cond_broadcast(&cond->cond); + if (ret) + ERR("Could not broadcast the condition variable, error %d.\n", ret); } -static inline int vkd3d_cond_wait(struct vkd3d_cond *cond, struct vkd3d_mutex *lock) +static inline void vkd3d_cond_wait(struct vkd3d_cond *cond, struct vkd3d_mutex *lock) { - return pthread_cond_wait(&cond->cond, &lock->lock); + int ret; + + ret = pthread_cond_wait(&cond->cond, &lock->lock); + if (ret) + ERR("Could not wait on the condition variable, error %d.\n", ret); } -static inline int vkd3d_cond_destroy(struct vkd3d_cond *cond) +static inline void vkd3d_cond_destroy(struct vkd3d_cond *cond) { - return pthread_cond_destroy(&cond->cond); + int ret; + + ret = pthread_cond_destroy(&cond->cond); + if (ret) + ERR("Could not destroy the condition variable, error %d.\n", ret); } #endif /* _WIN32 */ @@ -447,14 +479,11 @@ static inline void vkd3d_private_data_destroy(struct vkd3d_private_data *data) static inline HRESULT vkd3d_private_store_init(struct vkd3d_private_store *store) { - int rc; - list_init(&store->content); - if ((rc = vkd3d_mutex_init(&store->mutex))) - ERR("Failed to initialize mutex, error %d.\n", rc); + vkd3d_mutex_init(&store->mutex); - return hresult_from_errno(rc); + return S_OK; } static inline void vkd3d_private_store_destroy(struct vkd3d_private_store *store)