From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winevulkan/loader.c | 23 ++++++++++---------- dlls/winevulkan/vulkan.c | 36 +++++++++++++++++--------------- dlls/winevulkan/vulkan_loader.h | 27 +++++++----------------- dlls/winevulkan/vulkan_private.h | 13 ++++++------ include/wine/vulkan_driver.h | 18 ++++++++++++++++ 5 files changed, 61 insertions(+), 56 deletions(-)
diff --git a/dlls/winevulkan/loader.c b/dlls/winevulkan/loader.c index 24605d82e12..0f58d17bdd7 100644 --- a/dlls/winevulkan/loader.c +++ b/dlls/winevulkan/loader.c @@ -98,9 +98,9 @@ static BOOL is_available_device_function(VkDevice device, const char *name) return UNIX_CALL(is_available_device_function, ¶ms); }
-static void *alloc_vk_object(size_t size) +static void *vulkan_client_object_create(size_t size) { - struct wine_vk_base *object = calloc(1, size); + struct vulkan_client_object *object = calloc(1, size); object->loader_magic = VULKAN_ICD_MAGIC_VALUE; return object; } @@ -358,11 +358,11 @@ VkResult WINAPI vkCreateInstance(const VkInstanceCreateInfo *create_info,
for (;;) { - if (!(instance = alloc_vk_object(FIELD_OFFSET(struct VkInstance_T, phys_devs[phys_dev_count])))) + if (!(instance = vulkan_client_object_create(FIELD_OFFSET(struct VkInstance_T, phys_devs[phys_dev_count])))) return VK_ERROR_OUT_OF_HOST_MEMORY; instance->phys_dev_count = phys_dev_count; for (i = 0; i < phys_dev_count; i++) - instance->phys_devs[i].base.loader_magic = VULKAN_ICD_MAGIC_VALUE; + instance->phys_devs[i].obj.loader_magic = VULKAN_ICD_MAGIC_VALUE;
params.pCreateInfo = create_info; params.pAllocator = allocator; @@ -376,7 +376,7 @@ VkResult WINAPI vkCreateInstance(const VkInstanceCreateInfo *create_info, free(instance); }
- if (!instance->base.unix_handle) + if (!instance->obj.unix_handle) free(instance); return params.result; } @@ -571,10 +571,10 @@ VkResult WINAPI vkCreateDevice(VkPhysicalDevice phys_dev, const VkDeviceCreateIn
for (i = 0; i < create_info->queueCreateInfoCount; i++) queue_count += create_info->pQueueCreateInfos[i].queueCount; - if (!(device = alloc_vk_object(FIELD_OFFSET(struct VkDevice_T, queues[queue_count])))) + if (!(device = vulkan_client_object_create(FIELD_OFFSET(struct VkDevice_T, queues[queue_count])))) return VK_ERROR_OUT_OF_HOST_MEMORY; for (i = 0; i < queue_count; i++) - device->queues[i].base.loader_magic = VULKAN_ICD_MAGIC_VALUE; + device->queues[i].obj.loader_magic = VULKAN_ICD_MAGIC_VALUE;
params.physicalDevice = phys_dev; params.pCreateInfo = create_info; @@ -583,7 +583,7 @@ VkResult WINAPI vkCreateDevice(VkPhysicalDevice phys_dev, const VkDeviceCreateIn params.client_ptr = device; status = UNIX_CALL(vkCreateDevice, ¶ms); assert(!status); - if (!device->base.unix_handle) + if (!device->obj.unix_handle) free(device); return params.result; } @@ -607,9 +607,8 @@ VkResult WINAPI vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateIn struct vk_command_pool *cmd_pool; NTSTATUS status;
- if (!(cmd_pool = malloc(sizeof(*cmd_pool)))) + if (!(cmd_pool = vulkan_client_object_create(sizeof(*cmd_pool)))) return VK_ERROR_OUT_OF_HOST_MEMORY; - cmd_pool->unix_handle = 0; list_init(&cmd_pool->command_buffers);
params.device = device; @@ -619,7 +618,7 @@ VkResult WINAPI vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateIn params.client_ptr = cmd_pool; status = UNIX_CALL(vkCreateCommandPool, ¶ms); assert(!status); - if (!cmd_pool->unix_handle) + if (!cmd_pool->obj.unix_handle) free(cmd_pool); return params.result; } @@ -660,7 +659,7 @@ VkResult WINAPI vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferA uint32_t i;
for (i = 0; i < allocate_info->commandBufferCount; i++) - buffers[i] = alloc_vk_object(sizeof(*buffers[i])); + buffers[i] = vulkan_client_object_create(sizeof(*buffers[i]));
params.device = device; params.pAllocateInfo = allocate_info; diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c index 56a6ade850d..5067faec4db 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c @@ -352,7 +352,7 @@ static void wine_phys_dev_cleanup(struct wine_phys_dev *phys_dev) }
static VkResult wine_vk_physical_device_init(struct wine_phys_dev *object, VkPhysicalDevice host_handle, - VkPhysicalDevice client_handle, struct wine_instance *instance) + VkPhysicalDevice client_physical_device, struct wine_instance *instance) { BOOL have_memory_placed = FALSE, have_map_memory2 = FALSE; uint32_t num_host_properties, num_properties = 0; @@ -362,10 +362,10 @@ static VkResult wine_vk_physical_device_init(struct wine_phys_dev *object, VkPhy unsigned int i, j;
object->instance = instance; - object->handle = client_handle; + object->handle = client_physical_device; object->host_physical_device = host_handle;
- client_handle->base.unix_handle = (uintptr_t)object; + client_physical_device->obj.unix_handle = (uintptr_t)object;
instance->funcs.p_vkGetPhysicalDeviceMemoryProperties(host_handle, &object->memory_properties);
@@ -505,7 +505,7 @@ 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; + buffer->handle->obj.unix_handle = 0; free(buffer); } } @@ -521,9 +521,10 @@ static void wine_vk_device_init_queues(struct wine_device *device, const VkDevic for (i = 0; i < info->queueCount; i++) { struct wine_queue *queue = device->queues + device->queue_count + i; + VkQueue client_queue = *handles++;
queue->device = device; - queue->handle = (*handles)++; + queue->handle = client_queue; queue->family_index = info->queueFamilyIndex; queue->queue_index = i; queue->flags = info->flags; @@ -547,7 +548,7 @@ static void wine_vk_device_init_queues(struct wine_device *device, const VkDevic device->funcs.p_vkGetDeviceQueue(device->host_device, info->queueFamilyIndex, i, &queue->host_queue); }
- queue->handle->base.unix_handle = (uintptr_t)queue; + client_queue->obj.unix_handle = (uintptr_t)queue; TRACE("Got device %p queue %p, host_queue %p.\n", device, queue, queue->host_queue); }
@@ -831,6 +832,7 @@ VkResult wine_vkAllocateCommandBuffers(VkDevice handle, const VkCommandBufferAll for (i = 0; i < allocate_info->commandBufferCount; i++) { VkCommandBufferAllocateInfo allocate_info_host; + VkCommandBuffer client_command_buffer = *buffers++;
/* TODO: future extensions (none yet) may require pNext conversion. */ allocate_info_host.pNext = allocate_info->pNext; @@ -848,11 +850,11 @@ VkResult wine_vkAllocateCommandBuffers(VkDevice handle, const VkCommandBufferAll break; }
- buffer->handle = buffers[i]; + buffer->handle = client_command_buffer; buffer->device = device; res = device->funcs.p_vkAllocateCommandBuffers(device->host_device, &allocate_info_host, &buffer->host_command_buffer); - buffer->handle->base.unix_handle = (uintptr_t)buffer; + client_command_buffer->obj.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) { @@ -874,7 +876,7 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre { struct wine_phys_dev *phys_dev = wine_phys_dev_from_handle(phys_dev_handle); struct wine_instance *instance = phys_dev->instance; - VkDevice device_handle = client_ptr; + VkDevice client_device = client_ptr; VkDeviceCreateInfo create_info_host; struct VkQueue_T *queue_handles; struct conversion_context ctx; @@ -928,12 +930,12 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre ALL_VK_DEVICE_FUNCS() #undef USE_VK_FUNC
- queue_handles = device_handle->queues; + queue_handles = client_device->queues; for (i = 0; i < create_info_host.queueCreateInfoCount; i++) wine_vk_device_init_queues(object, create_info_host.pQueueCreateInfos + i, &queue_handles);
- device_handle->quirks = instance->quirks; - device_handle->base.unix_handle = (uintptr_t)object; + client_device->quirks = instance->quirks; + client_device->obj.unix_handle = (uintptr_t)object;
TRACE("Created device %p, host_device %p.\n", object, object->host_device); for (i = 0; i < object->queue_count; i++) @@ -942,7 +944,7 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre add_handle_mapping_ptr(instance, queue->handle, queue->host_queue, &queue->wrapper_entry); }
- *ret_device = device_handle; + *ret_device = client_device; add_handle_mapping_ptr(instance, *ret_device, object->host_device, &object->wrapper_entry); return VK_SUCCESS; } @@ -1019,7 +1021,7 @@ VkResult wine_vkCreateInstance(const VkInstanceCreateInfo *create_info, object->quirks |= WINEVULKAN_QUIRK_GET_DEVICE_PROC_ADDR; }
- client_instance->base.unix_handle = (uintptr_t)object; + client_instance->obj.unix_handle = (uintptr_t)object;
TRACE("Created instance %p, host_instance %p.\n", object, object->host_instance);
@@ -1272,7 +1274,7 @@ VkResult wine_vkCreateCommandPool(VkDevice device_handle, const VkCommandPoolCre void *client_ptr) { struct wine_device *device = wine_device_from_handle(device_handle); - struct vk_command_pool *handle = client_ptr; + struct vk_command_pool *client_command_pool = client_ptr; struct wine_cmd_pool *object; VkResult res;
@@ -1289,8 +1291,8 @@ VkResult wine_vkCreateCommandPool(VkDevice device_handle, const VkCommandPoolCre return res; }
- object->handle = (uintptr_t)handle; - handle->unix_handle = (uintptr_t)object; + object->handle = (uintptr_t)client_command_pool; + client_command_pool->obj.unix_handle = (uintptr_t)object;
*command_pool = object->handle; add_handle_mapping(device->phys_dev->instance, *command_pool, object->host_command_pool, &object->wrapper_entry); diff --git a/dlls/winevulkan/vulkan_loader.h b/dlls/winevulkan/vulkan_loader.h index 6d3d30ce615..6c9cbeb9f83 100644 --- a/dlls/winevulkan/vulkan_loader.h +++ b/dlls/winevulkan/vulkan_loader.h @@ -31,6 +31,7 @@ #include "ntuser.h" #include "wine/debug.h" #include "wine/vulkan.h" +#include "wine/vulkan_driver.h" #include "wine/unixlib.h" #include "wine/list.h"
@@ -41,47 +42,33 @@
#define WINEVULKAN_QUIRK_GET_DEVICE_PROC_ADDR 0x00000001
-/* Base 'class' for our Vulkan dispatchable objects such as VkDevice and VkInstance. - * This structure MUST be the first element of a dispatchable object as the ICD - * loader depends on it. For now only contains loader_magic, but over time more common - * functionality is expected. - */ -struct wine_vk_base -{ - /* Special section in each dispatchable object for use by the ICD loader for - * storing dispatch tables. The start contains a magical value '0x01CDC0DE'. - */ - UINT64 loader_magic; - UINT64 unix_handle; -}; - struct VkPhysicalDevice_T { - struct wine_vk_base base; + struct vulkan_client_object obj; };
struct VkInstance_T { - struct wine_vk_base base; + struct vulkan_client_object obj; uint32_t phys_dev_count; struct VkPhysicalDevice_T phys_devs[1]; };
struct VkQueue_T { - struct wine_vk_base base; + struct vulkan_client_object obj; };
struct VkDevice_T { - struct wine_vk_base base; + struct vulkan_client_object obj; unsigned int quirks; struct VkQueue_T queues[1]; };
struct vk_command_pool { - UINT64 unix_handle; + struct vulkan_client_object obj; struct list command_buffers; };
@@ -92,7 +79,7 @@ static inline struct vk_command_pool *command_pool_from_handle(VkCommandPool han
struct VkCommandBuffer_T { - struct wine_vk_base base; + struct vulkan_client_object obj; struct list pool_link; };
diff --git a/dlls/winevulkan/vulkan_private.h b/dlls/winevulkan/vulkan_private.h index b4cbf12c949..df49b4922e3 100644 --- a/dlls/winevulkan/vulkan_private.h +++ b/dlls/winevulkan/vulkan_private.h @@ -27,7 +27,6 @@
#include "vulkan_loader.h" #include "vulkan_thunks.h" -#include "wine/rbtree.h"
#include "wine/rbtree.h"
@@ -53,7 +52,7 @@ struct wine_cmd_buffer
static inline struct wine_cmd_buffer *wine_cmd_buffer_from_handle(VkCommandBuffer handle) { - return (struct wine_cmd_buffer *)(uintptr_t)handle->base.unix_handle; + return (struct wine_cmd_buffer *)(uintptr_t)handle->obj.unix_handle; }
struct wine_queue @@ -72,7 +71,7 @@ struct wine_queue
static inline struct wine_queue *wine_queue_from_handle(VkQueue handle) { - return (struct wine_queue *)(uintptr_t)handle->base.unix_handle; + return (struct wine_queue *)(uintptr_t)handle->obj.unix_handle; }
struct wine_device @@ -93,7 +92,7 @@ C_ASSERT(sizeof(struct wine_device) == offsetof(struct wine_device, queues[0]));
static inline struct wine_device *wine_device_from_handle(VkDevice handle) { - return (struct wine_device *)(uintptr_t)handle->base.unix_handle; + return (struct wine_device *)(uintptr_t)handle->obj.unix_handle; }
struct wine_debug_utils_messenger; @@ -128,7 +127,7 @@ struct wine_phys_dev
static inline struct wine_phys_dev *wine_phys_dev_from_handle(VkPhysicalDevice handle) { - return (struct wine_phys_dev *)(uintptr_t)handle->base.unix_handle; + return (struct wine_phys_dev *)(uintptr_t)handle->obj.unix_handle; }
struct wine_debug_report_callback; @@ -163,7 +162,7 @@ C_ASSERT(sizeof(struct wine_instance) == offsetof(struct wine_instance, phys_dev
static inline struct wine_instance *wine_instance_from_handle(VkInstance handle) { - return (struct wine_instance *)(uintptr_t)handle->base.unix_handle; + return (struct wine_instance *)(uintptr_t)handle->obj.unix_handle; }
struct wine_cmd_pool @@ -177,7 +176,7 @@ struct wine_cmd_pool static inline struct wine_cmd_pool *wine_cmd_pool_from_handle(VkCommandPool handle) { struct vk_command_pool *client_ptr = command_pool_from_handle(handle); - return (struct wine_cmd_pool *)(uintptr_t)client_ptr->unix_handle; + return (struct wine_cmd_pool *)(uintptr_t)client_ptr->obj.unix_handle; }
struct wine_device_memory diff --git a/include/wine/vulkan_driver.h b/include/wine/vulkan_driver.h index c2b53cc884a..7612ef34cd2 100644 --- a/include/wine/vulkan_driver.h +++ b/include/wine/vulkan_driver.h @@ -26,6 +26,22 @@ #include <windef.h> #include <winbase.h>
+/* Base 'class' for our Vulkan dispatchable objects such as VkDevice and VkInstance. + * This structure MUST be the first element of a dispatchable object as the ICD + * loader depends on it. For now only contains loader_magic, but over time more common + * functionality is expected. + */ +struct vulkan_client_object +{ + /* Special section in each dispatchable object for use by the ICD loader for + * storing dispatch tables. The start contains a magical value '0x01CDC0DE'. + */ + UINT64 loader_magic; + UINT64 unix_handle; +}; + +#ifdef WINE_UNIX_LIB + #define WINE_VK_HOST #include "wine/vulkan.h"
@@ -64,4 +80,6 @@ struct vulkan_driver_funcs const char *(*p_get_host_surface_extension)(void); };
+#endif /* WINE_UNIX_LIB */ + #endif /* __WINE_VULKAN_DRIVER_H */