Commit 6f8d02b0 authored by Józef Kucia's avatar Józef Kucia Committed by Alexandre Julliard

winevulkan: Wrap VkCommandPools.

We need to wrap VkCommandPools to track allocated VkCommandBuffers. Signed-off-by: 's avatarJózef Kucia <jkucia@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 6f3e83f7
...@@ -157,6 +157,8 @@ FUNCTION_OVERRIDES = { ...@@ -157,6 +157,8 @@ FUNCTION_OVERRIDES = {
# Device functions # Device functions
"vkAllocateCommandBuffers" : {"dispatch" : True, "driver" : False, "thunk" : False}, "vkAllocateCommandBuffers" : {"dispatch" : True, "driver" : False, "thunk" : False},
"vkCmdExecuteCommands" : {"dispatch" : True, "driver" : False, "thunk" : False}, "vkCmdExecuteCommands" : {"dispatch" : True, "driver" : False, "thunk" : False},
"vkCreateCommandPool" : {"dispatch": True, "driver" : False, "thunk" : False},
"vkDestroyCommandPool" : {"dispatch": True, "driver" : False, "thunk" : False},
"vkDestroyDevice" : {"dispatch" : True, "driver" : False, "thunk" : False}, "vkDestroyDevice" : {"dispatch" : True, "driver" : False, "thunk" : False},
"vkFreeCommandBuffers" : {"dispatch" : True, "driver" : False, "thunk" : False}, "vkFreeCommandBuffers" : {"dispatch" : True, "driver" : False, "thunk" : False},
"vkGetDeviceProcAddr" : {"dispatch" : False, "driver" : True, "thunk" : False}, "vkGetDeviceProcAddr" : {"dispatch" : False, "driver" : True, "thunk" : False},
...@@ -838,27 +840,31 @@ class VkHandle(object): ...@@ -838,27 +840,31 @@ class VkHandle(object):
def is_required(self): def is_required(self):
return self.required return self.required
def native_handle(self): def native_handle(self, name):
""" Provide access to the native handle of a dispatchable object. """ Provide access to the native handle of a wrapped object. """
Dispatchable objects wrap an underlying 'native' object. if self.name == "VkCommandPool":
This method provides access to the native object. return "wine_cmd_pool_from_handle({0})->command_pool".format(name)
"""
if not self.is_dispatchable(): native_handle_name = None
return None
if self.name == "VkCommandBuffer": if self.name == "VkCommandBuffer":
return "command_buffer" native_handle_name = "command_buffer"
elif self.name == "VkDevice": if self.name == "VkDevice":
return "device" native_handle_name = "device"
elif self.name == "VkInstance": if self.name == "VkInstance":
return "instance" native_handle_name = "instance"
elif self.name == "VkPhysicalDevice": if self.name == "VkPhysicalDevice":
return "phys_dev" native_handle_name = "phys_dev"
elif self.name == "VkQueue": if self.name == "VkQueue":
return "queue" native_handle_name = "queue"
else:
if native_handle_name:
return "{0}->{1}".format(name, native_handle_name)
if self.is_dispatchable():
LOGGER.error("Unhandled native handle for: {0}".format(self.name)) LOGGER.error("Unhandled native handle for: {0}".format(self.name))
return None
class VkMember(object): class VkMember(object):
...@@ -1471,17 +1477,15 @@ class VkParam(object): ...@@ -1471,17 +1477,15 @@ class VkParam(object):
LOGGER.debug("TODO: setting NULL VkAllocationCallbacks for {0}".format(self.name)) LOGGER.debug("TODO: setting NULL VkAllocationCallbacks for {0}".format(self.name))
return "NULL" return "NULL"
# Dispatchable objects wrap the native handle. For thunk generation we if conv and self.needs_conversion():
# need to pass the native handle to the native Vulkan calls.
if self.is_dispatchable():
return "{0}->{1}".format(self.name, self.handle.native_handle())
elif conv and self.needs_conversion():
if self.is_dynamic_array(): if self.is_dynamic_array():
return "{0}_host".format(self.name) return "{0}_host".format(self.name)
else: else:
return "&{0}_host".format(self.name) return "&{0}_host".format(self.name)
else: else:
return self.name # We need to pass the native handle to the native Vulkan calls.
native_handle = self.handle.native_handle(self.name) if self.is_handle() else None
return native_handle if native_handle else self.name
class VkStruct(Sequence): class VkStruct(Sequence):
......
...@@ -154,9 +154,8 @@ err: ...@@ -154,9 +154,8 @@ err:
return NULL; return NULL;
} }
/* Helper function to release command buffers. */ static void wine_vk_free_command_buffers(struct VkDevice_T *device,
static void wine_vk_command_buffers_free(struct VkDevice_T *device, VkCommandPool pool, struct wine_cmd_pool *pool, uint32_t count, const VkCommandBuffer *buffers)
uint32_t count, const VkCommandBuffer *buffers)
{ {
unsigned int i; unsigned int i;
...@@ -165,12 +164,11 @@ static void wine_vk_command_buffers_free(struct VkDevice_T *device, VkCommandPoo ...@@ -165,12 +164,11 @@ static void wine_vk_command_buffers_free(struct VkDevice_T *device, VkCommandPoo
if (!buffers[i]) if (!buffers[i])
continue; continue;
device->funcs.p_vkFreeCommandBuffers(device->device, pool, 1, &buffers[i]->command_buffer); device->funcs.p_vkFreeCommandBuffers(device->device, pool->command_pool, 1, &buffers[i]->command_buffer);
heap_free(buffers[i]); heap_free(buffers[i]);
} }
} }
/* Helper function to create queues for a given family index. */
static struct VkQueue_T *wine_vk_device_alloc_queues(struct VkDevice_T *device, static struct VkQueue_T *wine_vk_device_alloc_queues(struct VkDevice_T *device,
uint32_t family_index, uint32_t queue_count, VkDeviceQueueCreateFlags flags) uint32_t family_index, uint32_t queue_count, VkDeviceQueueCreateFlags flags)
{ {
...@@ -506,10 +504,13 @@ static void wine_vk_instance_free(struct VkInstance_T *instance) ...@@ -506,10 +504,13 @@ static void wine_vk_instance_free(struct VkInstance_T *instance)
VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device, VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device,
const VkCommandBufferAllocateInfo *allocate_info, VkCommandBuffer *buffers) const VkCommandBufferAllocateInfo *allocate_info, VkCommandBuffer *buffers)
{ {
struct wine_cmd_pool *pool;
VkResult res = VK_SUCCESS; VkResult res = VK_SUCCESS;
unsigned int i; unsigned int i;
TRACE("%p %p %p\n", device, allocate_info, buffers); TRACE("%p, %p, %p\n", device, allocate_info, buffers);
pool = wine_cmd_pool_from_handle(allocate_info->commandPool);
memset(buffers, 0, allocate_info->commandBufferCount * sizeof(*buffers)); memset(buffers, 0, allocate_info->commandBufferCount * sizeof(*buffers));
...@@ -523,7 +524,7 @@ VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device, ...@@ -523,7 +524,7 @@ VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device,
/* TODO: future extensions (none yet) may require pNext conversion. */ /* TODO: future extensions (none yet) may require pNext conversion. */
allocate_info_host.pNext = allocate_info->pNext; allocate_info_host.pNext = allocate_info->pNext;
allocate_info_host.sType = allocate_info->sType; allocate_info_host.sType = allocate_info->sType;
allocate_info_host.commandPool = allocate_info->commandPool; allocate_info_host.commandPool = pool->command_pool;
allocate_info_host.level = allocate_info->level; allocate_info_host.level = allocate_info->level;
allocate_info_host.commandBufferCount = 1; allocate_info_host.commandBufferCount = 1;
...@@ -550,7 +551,7 @@ VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device, ...@@ -550,7 +551,7 @@ VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device,
if (res != VK_SUCCESS) if (res != VK_SUCCESS)
{ {
wine_vk_command_buffers_free(device, allocate_info->commandPool, i, buffers); wine_vk_free_command_buffers(device, pool, i, buffers);
memset(buffers, 0, allocate_info->commandBufferCount * sizeof(*buffers)); memset(buffers, 0, allocate_info->commandBufferCount * sizeof(*buffers));
return res; return res;
} }
...@@ -920,12 +921,14 @@ VkResult WINAPI wine_vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *c ...@@ -920,12 +921,14 @@ VkResult WINAPI wine_vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *c
return *count < instance->phys_dev_count ? VK_INCOMPLETE : VK_SUCCESS; return *count < instance->phys_dev_count ? VK_INCOMPLETE : VK_SUCCESS;
} }
void WINAPI wine_vkFreeCommandBuffers(VkDevice device, VkCommandPool pool, uint32_t count, void WINAPI wine_vkFreeCommandBuffers(VkDevice device, VkCommandPool pool_handle,
const VkCommandBuffer *buffers) uint32_t count, const VkCommandBuffer *buffers)
{ {
TRACE("%p 0x%s %u %p\n", device, wine_dbgstr_longlong(pool), count, buffers); struct wine_cmd_pool *pool = wine_cmd_pool_from_handle(pool_handle);
wine_vk_command_buffers_free(device, pool, count, buffers); TRACE("%p, 0x%s, %u, %p\n", device, wine_dbgstr_longlong(pool_handle), count, buffers);
wine_vk_free_command_buffers(device, pool, count, buffers);
} }
PFN_vkVoidFunction WINAPI wine_vkGetDeviceProcAddr(VkDevice device, const char *name) PFN_vkVoidFunction WINAPI wine_vkGetDeviceProcAddr(VkDevice device, const char *name)
...@@ -1115,6 +1118,47 @@ err: ...@@ -1115,6 +1118,47 @@ err:
return res; return res;
} }
VkResult WINAPI wine_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *info,
const VkAllocationCallbacks *allocator, VkCommandPool *command_pool)
{
struct wine_cmd_pool *object;
VkResult res;
TRACE("%p, %p, %p, %p\n", device, info, allocator, command_pool);
if (allocator)
FIXME("Support for allocation callbacks not implemented yet\n");
if (!(object = heap_alloc_zero(sizeof(*object))))
return VK_ERROR_OUT_OF_HOST_MEMORY;
res = device->funcs.p_vkCreateCommandPool(device->device, info, NULL, &object->command_pool);
if (res == VK_SUCCESS)
*command_pool = wine_cmd_pool_to_handle(object);
else
heap_free(object);
return res;
}
void WINAPI wine_vkDestroyCommandPool(VkDevice device, VkCommandPool handle,
const VkAllocationCallbacks *allocator)
{
struct wine_cmd_pool *pool = wine_cmd_pool_from_handle(handle);
TRACE("%p, 0x%s, %p\n", device, wine_dbgstr_longlong(handle), allocator);
if (!handle)
return;
if (allocator)
FIXME("Support for allocation callbacks not implemented yet\n");
device->funcs.p_vkDestroyCommandPool(device->device, pool->command_pool, NULL);
heap_free(pool);
}
static VkResult wine_vk_enumerate_physical_device_groups(struct VkInstance_T *instance, static VkResult wine_vk_enumerate_physical_device_groups(struct VkInstance_T *instance,
VkResult (*p_vkEnumeratePhysicalDeviceGroups)(VkInstance, uint32_t *, VkPhysicalDeviceGroupProperties *), VkResult (*p_vkEnumeratePhysicalDeviceGroups)(VkInstance, uint32_t *, VkPhysicalDeviceGroupProperties *),
uint32_t *count, VkPhysicalDeviceGroupProperties *properties) uint32_t *count, VkPhysicalDeviceGroupProperties *properties)
......
...@@ -110,6 +110,21 @@ struct VkQueue_T ...@@ -110,6 +110,21 @@ struct VkQueue_T
VkDeviceQueueCreateFlags flags; VkDeviceQueueCreateFlags flags;
}; };
struct wine_cmd_pool
{
VkCommandPool command_pool;
};
static inline struct wine_cmd_pool *wine_cmd_pool_from_handle(VkCommandPool handle)
{
return (struct wine_cmd_pool *)(uintptr_t)handle;
}
static inline VkCommandPool wine_cmd_pool_to_handle(struct wine_cmd_pool *cmd_pool)
{
return (VkCommandPool)(uintptr_t)cmd_pool;
}
void *wine_vk_get_device_proc_addr(const char *name) DECLSPEC_HIDDEN; void *wine_vk_get_device_proc_addr(const char *name) DECLSPEC_HIDDEN;
void *wine_vk_get_instance_proc_addr(const char *name) DECLSPEC_HIDDEN; void *wine_vk_get_instance_proc_addr(const char *name) DECLSPEC_HIDDEN;
......
...@@ -1744,12 +1744,6 @@ VkResult WINAPI wine_vkCreateBufferView(VkDevice device, const VkBufferViewCreat ...@@ -1744,12 +1744,6 @@ VkResult WINAPI wine_vkCreateBufferView(VkDevice device, const VkBufferViewCreat
#endif #endif
} }
VkResult WINAPI wine_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool)
{
TRACE("%p, %p, %p, %p\n", device, pCreateInfo, pAllocator, pCommandPool);
return device->funcs.p_vkCreateCommandPool(device->device, pCreateInfo, NULL, pCommandPool);
}
VkResult WINAPI wine_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines) VkResult WINAPI wine_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines)
{ {
#if defined(USE_STRUCT_CONVERSION) #if defined(USE_STRUCT_CONVERSION)
...@@ -1979,12 +1973,6 @@ void WINAPI wine_vkDestroyBufferView(VkDevice device, VkBufferView bufferView, c ...@@ -1979,12 +1973,6 @@ void WINAPI wine_vkDestroyBufferView(VkDevice device, VkBufferView bufferView, c
device->funcs.p_vkDestroyBufferView(device->device, bufferView, NULL); device->funcs.p_vkDestroyBufferView(device->device, bufferView, NULL);
} }
void WINAPI wine_vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator)
{
TRACE("%p, 0x%s, %p\n", device, wine_dbgstr_longlong(commandPool), pAllocator);
device->funcs.p_vkDestroyCommandPool(device->device, commandPool, NULL);
}
void WINAPI wine_vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks *pAllocator) void WINAPI wine_vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks *pAllocator)
{ {
TRACE("%p, 0x%s, %p\n", device, wine_dbgstr_longlong(descriptorPool), pAllocator); TRACE("%p, 0x%s, %p\n", device, wine_dbgstr_longlong(descriptorPool), pAllocator);
...@@ -2744,7 +2732,7 @@ VkResult WINAPI wine_vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkComma ...@@ -2744,7 +2732,7 @@ VkResult WINAPI wine_vkResetCommandBuffer(VkCommandBuffer commandBuffer, VkComma
VkResult WINAPI wine_vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) VkResult WINAPI wine_vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
{ {
TRACE("%p, 0x%s, %#x\n", device, wine_dbgstr_longlong(commandPool), flags); TRACE("%p, 0x%s, %#x\n", device, wine_dbgstr_longlong(commandPool), flags);
return device->funcs.p_vkResetCommandPool(device->device, commandPool, flags); return device->funcs.p_vkResetCommandPool(device->device, wine_cmd_pool_from_handle(commandPool)->command_pool, flags);
} }
VkResult WINAPI wine_vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags) VkResult WINAPI wine_vkResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags)
...@@ -2774,13 +2762,13 @@ VkResult WINAPI wine_vkSetEvent(VkDevice device, VkEvent event) ...@@ -2774,13 +2762,13 @@ VkResult WINAPI wine_vkSetEvent(VkDevice device, VkEvent event)
void WINAPI wine_vkTrimCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags) void WINAPI wine_vkTrimCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags)
{ {
TRACE("%p, 0x%s, %#x\n", device, wine_dbgstr_longlong(commandPool), flags); TRACE("%p, 0x%s, %#x\n", device, wine_dbgstr_longlong(commandPool), flags);
device->funcs.p_vkTrimCommandPool(device->device, commandPool, flags); device->funcs.p_vkTrimCommandPool(device->device, wine_cmd_pool_from_handle(commandPool)->command_pool, flags);
} }
static void WINAPI wine_vkTrimCommandPoolKHR(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags) static void WINAPI wine_vkTrimCommandPoolKHR(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags)
{ {
TRACE("%p, 0x%s, %#x\n", device, wine_dbgstr_longlong(commandPool), flags); TRACE("%p, 0x%s, %#x\n", device, wine_dbgstr_longlong(commandPool), flags);
device->funcs.p_vkTrimCommandPoolKHR(device->device, commandPool, flags); device->funcs.p_vkTrimCommandPoolKHR(device->device, wine_cmd_pool_from_handle(commandPool)->command_pool, flags);
} }
void WINAPI wine_vkUnmapMemory(VkDevice device, VkDeviceMemory memory) void WINAPI wine_vkUnmapMemory(VkDevice device, VkDeviceMemory memory)
......
...@@ -43,7 +43,9 @@ ...@@ -43,7 +43,9 @@
/* Functions for which we have custom implementations outside of the thunks. */ /* Functions for which we have custom implementations outside of the thunks. */
VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers); VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers);
void WINAPI wine_vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers); void WINAPI wine_vkCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers);
VkResult WINAPI wine_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool);
VkResult WINAPI wine_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice); VkResult WINAPI wine_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
void WINAPI wine_vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator);
void WINAPI wine_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator); void WINAPI wine_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator);
void WINAPI wine_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator); void WINAPI wine_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);
VkResult WINAPI wine_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties); VkResult WINAPI wine_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties);
......
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