From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winevulkan/vulkan.c | 91 +++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 49 deletions(-)
diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c index 2d43f81d98f..a69c6c0c9cd 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c @@ -361,24 +361,11 @@ err: return res; }
-static void wine_vk_free_command_buffers(struct wine_device *device, - struct wine_cmd_pool *pool, uint32_t count, const VkCommandBuffer *buffers) +static void wine_cmd_buffer_destroy(struct wine_device *device, struct wine_cmd_buffer *buffer) { - unsigned int i; - - for (i = 0; i < count; i++) - { - struct wine_cmd_buffer *buffer = wine_cmd_buffer_from_handle(buffers[i]); - - if (!buffer) - continue; - - device->funcs.p_vkFreeCommandBuffers(device->host_device, pool->host_command_pool, 1, - &buffer->host_command_buffer); - remove_handle_mapping(device->phys_dev->instance, &buffer->wrapper_entry); - buffer->handle->base.unix_handle = 0; - free(buffer); - } + remove_handle_mapping(device->phys_dev->instance, &buffer->wrapper_entry); + buffer->handle->base.unix_handle = 0; + free(buffer); }
static void wine_vk_device_init_queues(struct wine_device *device, const VkDeviceQueueCreateInfo *info, @@ -727,54 +714,53 @@ static void wine_vk_instance_free(struct wine_instance *instance) }
VkResult wine_vkAllocateCommandBuffers(VkDevice handle, const VkCommandBufferAllocateInfo *allocate_info, - VkCommandBuffer *buffers ) + VkCommandBuffer *buffers) { + struct wine_cmd_pool *pool = wine_cmd_pool_from_handle(allocate_info->commandPool); struct wine_device *device = wine_device_from_handle(handle); + VkCommandBufferAllocateInfo allocate_info_host; struct wine_cmd_buffer *buffer; - struct wine_cmd_pool *pool; + VkCommandBuffer *host_handles; VkResult res = VK_SUCCESS; - unsigned int i; + unsigned int i, buffer_count = allocate_info->commandBufferCount;
- pool = wine_cmd_pool_from_handle(allocate_info->commandPool); + TRACE("Allocating %u command buffer from pool %p.\n", buffer_count, pool);
- for (i = 0; i < allocate_info->commandBufferCount; i++) - { - VkCommandBufferAllocateInfo allocate_info_host; + if (!(host_handles = malloc(buffer_count * sizeof(*host_handles)))) return VK_ERROR_OUT_OF_HOST_MEMORY;
- /* TODO: future extensions (none yet) may require pNext conversion. */ - allocate_info_host.pNext = allocate_info->pNext; - allocate_info_host.sType = allocate_info->sType; - allocate_info_host.commandPool = pool->host_command_pool; - allocate_info_host.level = allocate_info->level; - allocate_info_host.commandBufferCount = 1; + /* TODO: future extensions (none yet) may require pNext conversion. */ + allocate_info_host.pNext = allocate_info->pNext; + allocate_info_host.sType = allocate_info->sType; + allocate_info_host.commandPool = pool->host_command_pool; + allocate_info_host.level = allocate_info->level; + allocate_info_host.commandBufferCount = buffer_count;
- TRACE("Allocating command buffer %u from pool 0x%s.\n", - i, wine_dbgstr_longlong(allocate_info_host.commandPool)); + if ((res = device->funcs.p_vkAllocateCommandBuffers(device->host_device, &allocate_info_host, host_handles)) != VK_SUCCESS) + { + ERR("Failed to allocate command buffers, res=%d.\n", res); + free(host_handles); + return res; + }
+ for (i = 0; i < buffer_count; i++) + { if (!(buffer = calloc(1, sizeof(*buffer)))) - { - res = VK_ERROR_OUT_OF_HOST_MEMORY; - break; - } - + goto err; buffer->handle = buffers[i]; buffer->device = device; - res = device->funcs.p_vkAllocateCommandBuffers(device->host_device, &allocate_info_host, - &buffer->host_command_buffer); + buffer->host_command_buffer = host_handles[i]; buffer->handle->base.unix_handle = (uintptr_t)buffer; add_handle_mapping_ptr(device->phys_dev->instance, buffer->handle, buffer->host_command_buffer, &buffer->wrapper_entry); - if (res != VK_SUCCESS) - { - ERR("Failed to allocate command buffer, res=%d.\n", res); - buffer->host_command_buffer = VK_NULL_HANDLE; - break; - } }
- if (res != VK_SUCCESS) - wine_vk_free_command_buffers(device, pool, i + 1, buffers); + free(host_handles); + return VK_SUCCESS;
- return res; +err: + device->funcs.p_vkFreeCommandBuffers(device->host_device, pool->host_command_pool, buffer_count, host_handles); + while (i) wine_cmd_buffer_destroy(device, wine_cmd_buffer_from_handle(buffers[--i])); + free(host_handles); + return VK_ERROR_OUT_OF_HOST_MEMORY; }
VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCreateInfo *create_info, @@ -1090,8 +1076,15 @@ void wine_vkFreeCommandBuffers(VkDevice handle, VkCommandPool command_pool, uint { struct wine_device *device = wine_device_from_handle(handle); struct wine_cmd_pool *pool = wine_cmd_pool_from_handle(command_pool); + unsigned int i;
- wine_vk_free_command_buffers(device, pool, count, buffers); + for (i = 0; i < count; i++) + { + struct wine_cmd_buffer *buffer = wine_cmd_buffer_from_handle(buffers[i]); + device->funcs.p_vkFreeCommandBuffers(device->host_device, pool->host_command_pool, 1, + &buffer->host_command_buffer); + wine_cmd_buffer_destroy(device, buffer); + } }
static VkQueue wine_vk_device_find_queue(VkDevice handle, const VkDeviceQueueInfo2 *info)