Commit e1d53373 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

winevulkan: Introduce conversion_context and use it for conversion memory allocation.

parent cc3fc9a4
......@@ -366,12 +366,7 @@ static void wine_vk_device_get_queues(struct wine_device *device,
}
}
static void wine_vk_device_free_create_info(VkDeviceCreateInfo *create_info)
{
free_VkDeviceCreateInfo_struct_chain(create_info);
}
static VkResult wine_vk_device_convert_create_info(const VkDeviceCreateInfo *src,
static VkResult wine_vk_device_convert_create_info(struct conversion_context *ctx, const VkDeviceCreateInfo *src,
VkDeviceCreateInfo *dst)
{
unsigned int i;
......@@ -379,7 +374,7 @@ static VkResult wine_vk_device_convert_create_info(const VkDeviceCreateInfo *src
*dst = *src;
if ((res = convert_VkDeviceCreateInfo_struct_chain(src->pNext, dst)) < 0)
if ((res = convert_VkDeviceCreateInfo_struct_chain(ctx, src->pNext, dst)) < 0)
{
WARN("Failed to convert VkDeviceCreateInfo pNext chain, res=%d.\n", res);
return res;
......@@ -397,7 +392,6 @@ static VkResult wine_vk_device_convert_create_info(const VkDeviceCreateInfo *src
if (!wine_vk_device_extension_supported(extension_name))
{
WARN("Extension %s is not supported.\n", debugstr_a(extension_name));
wine_vk_device_free_create_info(dst);
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
}
......@@ -455,7 +449,7 @@ NTSTATUS init_vulkan(void *args)
* This function takes care of extensions handled at winevulkan layer, a Wine graphics
* driver is responsible for handling e.g. surface extensions.
*/
static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src,
static VkResult wine_vk_instance_convert_create_info(struct conversion_context *ctx, const VkInstanceCreateInfo *src,
VkInstanceCreateInfo *dst, struct wine_instance *object)
{
VkDebugUtilsMessengerCreateInfoEXT *debug_utils_messenger;
......@@ -466,7 +460,7 @@ static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo
*dst = *src;
if ((res = convert_VkInstanceCreateInfo_struct_chain(src->pNext, dst)) < 0)
if ((res = convert_VkInstanceCreateInfo_struct_chain(ctx, src->pNext, dst)) < 0)
{
WARN("Failed to convert VkInstanceCreateInfo pNext chain, res=%d.\n", res);
return res;
......@@ -524,7 +518,6 @@ static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo
if (!wine_vk_instance_extension_supported(extension_name))
{
WARN("Extension %s is not supported.\n", debugstr_a(extension_name));
free_VkInstanceCreateInfo_struct_chain(dst);
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
if (!strcmp(extension_name, "VK_EXT_debug_utils") || !strcmp(extension_name, "VK_EXT_debug_report"))
......@@ -707,6 +700,7 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre
struct VkQueue_T *queue_handles;
struct wine_queue *next_queue;
struct wine_device *object;
struct conversion_context ctx;
unsigned int i;
VkResult res;
......@@ -729,13 +723,12 @@ VkResult wine_vkCreateDevice(VkPhysicalDevice phys_dev_handle, const VkDeviceCre
object->phys_dev = phys_dev;
res = wine_vk_device_convert_create_info(create_info, &create_info_host);
if (res != VK_SUCCESS)
goto fail;
res = phys_dev->instance->funcs.p_vkCreateDevice(phys_dev->phys_dev,
&create_info_host, NULL /* allocator */, &object->device);
wine_vk_device_free_create_info(&create_info_host);
init_conversion_context(&ctx);
res = wine_vk_device_convert_create_info(&ctx, create_info, &create_info_host);
if (res == VK_SUCCESS)
res = phys_dev->instance->funcs.p_vkCreateDevice(phys_dev->phys_dev,
&create_info_host, NULL /* allocator */, &object->device);
free_conversion_context(&ctx);
WINE_VK_ADD_DISPATCHABLE_MAPPING(phys_dev->instance, device_handle, object->device, object);
if (res != VK_SUCCESS)
{
......@@ -801,6 +794,7 @@ VkResult wine_vkCreateInstance(const VkInstanceCreateInfo *create_info,
VkInstanceCreateInfo create_info_host;
const VkApplicationInfo *app_info;
struct wine_instance *object;
struct conversion_context ctx;
VkResult res;
if (allocator)
......@@ -814,15 +808,11 @@ VkResult wine_vkCreateInstance(const VkInstanceCreateInfo *create_info,
list_init(&object->wrappers);
pthread_rwlock_init(&object->wrapper_lock, NULL);
res = wine_vk_instance_convert_create_info(create_info, &create_info_host, object);
if (res != VK_SUCCESS)
{
wine_vk_instance_free(object);
return res;
}
res = vk_funcs->p_vkCreateInstance(&create_info_host, NULL /* allocator */, &object->instance);
free_VkInstanceCreateInfo_struct_chain(&create_info_host);
init_conversion_context(&ctx);
res = wine_vk_instance_convert_create_info(&ctx, create_info, &create_info_host, object);
if (res == VK_SUCCESS)
res = vk_funcs->p_vkCreateInstance(&create_info_host, NULL /* allocator */, &object->instance);
free_conversion_context(&ctx);
if (res != VK_SUCCESS)
{
ERR("Failed to create instance, res=%d\n", res);
......
......@@ -239,4 +239,42 @@ NTSTATUS WINAPI vk_direct_unix_call(unixlib_handle_t handle, unsigned int code,
NTSTATUS vk_is_available_instance_function(void *arg) DECLSPEC_HIDDEN;
NTSTATUS vk_is_available_device_function(void *arg) DECLSPEC_HIDDEN;
struct conversion_context
{
char buffer[2048];
uint32_t used;
struct list alloc_entries;
};
static inline void init_conversion_context(struct conversion_context *pool)
{
pool->used = 0;
list_init(&pool->alloc_entries);
}
static inline void free_conversion_context(struct conversion_context *pool)
{
struct list *entry, *next;
LIST_FOR_EACH_SAFE(entry, next, &pool->alloc_entries)
free(entry);
}
static inline void *conversion_context_alloc(struct conversion_context *pool, size_t size)
{
if (pool->used + size <= sizeof(pool->buffer))
{
void *ret = pool->buffer + pool->used;
pool->used += size;
return ret;
}
else
{
struct list *entry;
if (!(entry = malloc(sizeof(*entry) + size)))
return NULL;
list_add_tail(&pool->alloc_entries, entry);
return entry + 1;
}
}
#endif /* __WINE_VULKAN_PRIVATE_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -1959,10 +1959,9 @@ typedef VkCopyDescriptorSet VkCopyDescriptorSet_host;
#endif
VkResult convert_VkDeviceCreateInfo_struct_chain(const void *pNext, VkDeviceCreateInfo *out_struct) DECLSPEC_HIDDEN;
void free_VkDeviceCreateInfo_struct_chain(VkDeviceCreateInfo *s) DECLSPEC_HIDDEN;
VkResult convert_VkInstanceCreateInfo_struct_chain(const void *pNext, VkInstanceCreateInfo *out_struct) DECLSPEC_HIDDEN;
void free_VkInstanceCreateInfo_struct_chain(VkInstanceCreateInfo *s) DECLSPEC_HIDDEN;
struct conversion_context;
VkResult convert_VkDeviceCreateInfo_struct_chain(struct conversion_context *ctx, const void *pNext, VkDeviceCreateInfo *out_struct) DECLSPEC_HIDDEN;
VkResult convert_VkInstanceCreateInfo_struct_chain(struct conversion_context *ctx, const void *pNext, VkInstanceCreateInfo *out_struct) DECLSPEC_HIDDEN;
/* For use by vkDevice and children */
struct vulkan_device_funcs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment