From: Rémi Bernon rbernon@codeweavers.com
We don't yet have mappings when objects are constructed, so this also removes them consistently before destroying the objects. --- dlls/winevulkan/vulkan.c | 97 ++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 39 deletions(-)
diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c index 543a7c1afa5..a2112765008 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c @@ -220,7 +220,6 @@ static void wine_vk_physical_device_free(struct wine_phys_dev *phys_dev) if (!phys_dev) return;
- remove_handle_mapping(phys_dev->instance, &phys_dev->wrapper_entry); free(phys_dev->extensions); free(phys_dev); } @@ -244,7 +243,6 @@ static struct wine_phys_dev *wine_vk_physical_device_alloc(struct wine_instance object->host_physical_device = phys_dev;
handle->base.unix_handle = (uintptr_t)object; - add_handle_mapping_ptr(instance, handle, phys_dev, &object->wrapper_entry);
instance->funcs.p_vkGetPhysicalDeviceMemoryProperties(phys_dev, &object->memory_properties);
@@ -383,7 +381,6 @@ static void wine_vk_free_command_buffers(struct wine_device *device,
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); } @@ -426,8 +423,6 @@ static void wine_vk_device_get_queues(struct wine_device *device, }
queue->handle->base.unix_handle = (uintptr_t)queue; - add_handle_mapping_ptr(device->phys_dev->instance, queue->handle, queue->host_queue, &queue->wrapper_entry); - TRACE("Got device %p queue %p, host_queue %p.\n", device, queue, queue->host_queue); } } @@ -509,27 +504,14 @@ static VkResult wine_vk_device_convert_create_info(struct wine_phys_dev *phys_de */ static void wine_vk_device_free(struct wine_device *device) { - struct wine_queue *queue; - - if (!device) - return; - if (device->queues) { - unsigned int i; - for (i = 0; i < device->queue_count; i++) - { - queue = &device->queues[i]; - if (queue && queue->host_queue) - remove_handle_mapping(device->phys_dev->instance, &queue->wrapper_entry); - } free(device->queues); device->queues = NULL; }
if (device->host_device && device->funcs.p_vkDestroyDevice) { - remove_handle_mapping(device->phys_dev->instance, &device->wrapper_entry); device->funcs.p_vkDestroyDevice(device->host_device, NULL /* pAllocator */); }
@@ -734,17 +716,12 @@ static void wine_vk_instance_free(struct wine_instance *instance) unsigned int i;
for (i = 0; i < instance->phys_dev_count; i++) - { wine_vk_physical_device_free(instance->phys_devs[i]); - } free(instance->phys_devs); }
if (instance->host_instance) - { vk_funcs->p_vkDestroyInstance(instance->host_instance, NULL /* allocator */); - remove_handle_mapping(instance, &instance->wrapper_entry); - }
pthread_rwlock_destroy(&instance->wrapper_lock); rb_destroy(&instance->wrappers, NULL, NULL); @@ -789,7 +766,6 @@ VkResult wine_vkAllocateCommandBuffers(VkDevice handle, const VkCommandBufferAll res = device->funcs.p_vkAllocateCommandBuffers(device->host_device, &allocate_info_host, &buffer->host_command_buffer); 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); @@ -799,9 +775,17 @@ VkResult wine_vkAllocateCommandBuffers(VkDevice handle, const VkCommandBufferAll }
if (res != VK_SUCCESS) + { wine_vk_free_command_buffers(device, pool, i + 1, buffers); + return res; + }
- return res; + for (i = 0; i < allocate_info->commandBufferCount; i++) + { + struct wine_cmd_buffer *buffer = wine_cmd_buffer_from_handle(buffers[i]); + add_handle_mapping_ptr(device->phys_dev->instance, buffer->handle, buffer->host_command_buffer, &buffer->wrapper_entry); + } + return VK_SUCCESS; }
VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCreateInfo *create_info, @@ -844,7 +828,6 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre res = instance->funcs.p_vkCreateDevice(phys_dev->host_physical_device, &create_info_host, NULL /* allocator */, &object->host_device); free_conversion_context(&ctx); - add_handle_mapping_ptr(instance, device_handle, object->host_device, &object->wrapper_entry); if (res != VK_SUCCESS) { WARN("Failed to create device, res=%d.\n", res); @@ -891,9 +874,16 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre
device_handle->quirks = instance->quirks; device_handle->base.unix_handle = (uintptr_t)object; - *ret_device = device_handle;
TRACE("Created device %p, host_device %p.\n", object, object->host_device); + for (i = 0; i < object->queue_count; i++) + { + struct wine_queue *queue = object->queues + i; + add_handle_mapping_ptr(instance, queue->handle, queue->host_queue, &queue->wrapper_entry); + } + + *ret_device = device_handle; + add_handle_mapping_ptr(instance, *ret_device, object->host_device, &object->wrapper_entry); return VK_SUCCESS;
fail: @@ -910,6 +900,7 @@ VkResult wine_vkCreateInstance(const VkInstanceCreateInfo *create_info, const VkApplicationInfo *app_info; struct conversion_context ctx; struct wine_instance *object; + unsigned int i; VkResult res;
if (allocator) @@ -936,7 +927,6 @@ VkResult wine_vkCreateInstance(const VkInstanceCreateInfo *create_info, }
object->handle = client_instance; - add_handle_mapping_ptr(object, object->handle, object->host_instance, &object->wrapper_entry);
/* Load all instance functions we are aware of. Note the loader takes care * of any filtering for extensions which were not requested, but which the @@ -973,18 +963,35 @@ VkResult wine_vkCreateInstance(const VkInstanceCreateInfo *create_info, }
client_instance->base.unix_handle = (uintptr_t)object; - *instance = client_instance; + TRACE("Created instance %p, host_instance %p.\n", object, object->host_instance); + for (i = 0; i < object->phys_dev_count; i++) + { + struct wine_phys_dev *phys_dev = object->phys_devs[i]; + add_handle_mapping_ptr(object, phys_dev->handle, phys_dev->host_physical_device, &phys_dev->wrapper_entry); + }
+ *instance = client_instance; + add_handle_mapping_ptr(object, *instance, object->host_instance, &object->wrapper_entry); return VK_SUCCESS; }
void wine_vkDestroyDevice(VkDevice handle, const VkAllocationCallbacks *allocator) { struct wine_device *device = wine_device_from_handle(handle); + unsigned int i;
if (allocator) FIXME("Support for allocation callbacks not implemented yet\n"); + if (!device) + return; + + for (i = 0; i < device->queue_count; i++) + { + struct wine_queue *queue = device->queues + i; + remove_handle_mapping(device->phys_dev->instance, &queue->wrapper_entry); + } + remove_handle_mapping(device->phys_dev->instance, &device->wrapper_entry);
wine_vk_device_free(device); } @@ -992,9 +999,19 @@ void wine_vkDestroyDevice(VkDevice handle, const VkAllocationCallbacks *allocato void wine_vkDestroyInstance(VkInstance handle, const VkAllocationCallbacks *allocator) { struct wine_instance *instance = wine_instance_from_handle(handle); + unsigned int i;
if (allocator) FIXME("Support allocation allocators\n"); + if (!instance) + return; + + for (i = 0; i < instance->phys_dev_count; i++) + { + struct wine_phys_dev *phys_dev = instance->phys_devs[i]; + remove_handle_mapping(phys_dev->instance, &phys_dev->wrapper_entry); + } + remove_handle_mapping(instance, &instance->wrapper_entry);
wine_vk_instance_free(instance); } @@ -1138,6 +1155,13 @@ 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; + + for (i = 0; i < count; i++) + { + struct wine_cmd_buffer *buffer = wine_cmd_buffer_from_handle(buffers[i]); + if (buffer) remove_handle_mapping(device->phys_dev->instance, &buffer->wrapper_entry); + }
wine_vk_free_command_buffers(device, pool, count, buffers); } @@ -1622,9 +1646,8 @@ void wine_vkDestroySurfaceKHR(VkInstance handle, VkSurfaceKHR surface, if (!object) return;
- instance->funcs.p_vkDestroySurfaceKHR(instance->host_instance, object->driver_surface, NULL); remove_handle_mapping(instance, &object->wrapper_entry); - + instance->funcs.p_vkDestroySurfaceKHR(instance->host_instance, object->driver_surface, NULL); free(object); }
@@ -1679,9 +1702,8 @@ void wine_vkDestroySwapchainKHR(VkDevice device_handle, VkSwapchainKHR swapchain if (allocator) FIXME("Support for allocation callbacks not implemented yet\n"); if (!swapchain) return;
- device->funcs.p_vkDestroySwapchainKHR(device->host_device, swapchain->host_swapchain, NULL); remove_handle_mapping(device->phys_dev->instance, &swapchain->wrapper_entry); - + device->funcs.p_vkDestroySwapchainKHR(device->host_device, swapchain->host_swapchain, NULL); free(swapchain); }
@@ -2170,9 +2192,8 @@ void wine_vkDestroyDebugUtilsMessengerEXT(VkInstance handle, VkDebugUtilsMesseng if (!object) return;
- instance->funcs.p_vkDestroyDebugUtilsMessengerEXT(instance->host_instance, object->host_debug_messenger, NULL); remove_handle_mapping(instance, &object->wrapper_entry); - + instance->funcs.p_vkDestroyDebugUtilsMessengerEXT(instance->host_instance, object->host_debug_messenger, NULL); free(object); }
@@ -2225,9 +2246,8 @@ void wine_vkDestroyDebugReportCallbackEXT(VkInstance handle, VkDebugReportCallba if (!object) return;
- instance->funcs.p_vkDestroyDebugReportCallbackEXT(instance->host_instance, object->host_debug_callback, NULL); remove_handle_mapping(instance, &object->wrapper_entry); - + instance->funcs.p_vkDestroyDebugReportCallbackEXT(instance->host_instance, object->host_debug_callback, NULL); free(object); }
@@ -2272,9 +2292,8 @@ void wine_vkDestroyDeferredOperationKHR(VkDevice handle, if (!object) return;
- device->funcs.p_vkDestroyDeferredOperationKHR(device->host_device, object->host_deferred_operation, NULL); remove_handle_mapping(device->phys_dev->instance, &object->wrapper_entry); - + device->funcs.p_vkDestroyDeferredOperationKHR(device->host_device, object->host_deferred_operation, NULL); free_conversion_context(&object->ctx); free(object); }