From b2223847abd9875a4bd31f1713c8fcf105eebc61 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Tue, 11 Dec 2018 18:29:38 +0100 Subject: [PATCH] trampoline: extract device cration routine --- loader/loader.c | 115 ++++++++++++++++++++++++++++++++++++++++++++ loader/loader.h | 3 ++ loader/trampoline.c | 111 +----------------------------------------- 3 files changed, 119 insertions(+), 110 deletions(-) diff --git a/loader/loader.c b/loader/loader.c index c74a501a..3ba7a9f9 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -5205,6 +5205,121 @@ bool loaderGetLayerInterfaceVersion(PFN_vkNegotiateLoaderLayerInterfaceVersion f return true; } +VKAPI_ATTR VkResult VKAPI_CALL vkLayerCreateDevice(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, + const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA) { + VkResult res; + struct loader_physical_device_tramp *phys_dev = NULL; + struct loader_device *dev = NULL; + struct loader_instance *inst = NULL; + + assert(pCreateInfo->queueCreateInfoCount >= 1); + + phys_dev = (struct loader_physical_device_tramp *)physicalDevice; + inst = (struct loader_instance *)phys_dev->this_instance; + + // Get the physical device (ICD) extensions + struct loader_extension_list icd_exts; + icd_exts.list = NULL; + res = loader_init_generic_list(inst, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); + if (VK_SUCCESS != res) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to create ICD extension list"); + goto out; + } + + res = loader_add_device_extensions(inst, inst->disp->layer_inst_disp.EnumerateDeviceExtensionProperties, phys_dev->phys_dev, + "Unknown", &icd_exts); + if (res != VK_SUCCESS) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to add extensions to list"); + goto out; + } + + // Make sure requested extensions to be enabled are supported + res = loader_validate_device_extensions(phys_dev, &inst->expanded_activated_layer_list, &icd_exts, pCreateInfo); + if (res != VK_SUCCESS) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to validate extensions in list"); + goto out; + } + + dev = loader_create_logical_device(inst, pAllocator); + if (dev == NULL) { + res = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } + + // Copy the application enabled instance layer list into the device + if (NULL != inst->app_activated_layer_list.list) { + dev->app_activated_layer_list.capacity = inst->app_activated_layer_list.capacity; + dev->app_activated_layer_list.count = inst->app_activated_layer_list.count; + dev->app_activated_layer_list.list = + loader_device_heap_alloc(dev, inst->app_activated_layer_list.capacity, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (dev->app_activated_layer_list.list == NULL) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "vkCreateDevice: Failed to allocate application activated layer list of size %d.", + inst->app_activated_layer_list.capacity); + res = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } + memcpy(dev->app_activated_layer_list.list, inst->app_activated_layer_list.list, + sizeof(*dev->app_activated_layer_list.list) * dev->app_activated_layer_list.count); + } else { + dev->app_activated_layer_list.capacity = 0; + dev->app_activated_layer_list.count = 0; + dev->app_activated_layer_list.list = NULL; + } + + // Copy the expanded enabled instance layer list into the device + if (NULL != inst->expanded_activated_layer_list.list) { + dev->expanded_activated_layer_list.capacity = inst->expanded_activated_layer_list.capacity; + dev->expanded_activated_layer_list.count = inst->expanded_activated_layer_list.count; + dev->expanded_activated_layer_list.list = + loader_device_heap_alloc(dev, inst->expanded_activated_layer_list.capacity, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); + if (dev->expanded_activated_layer_list.list == NULL) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "vkCreateDevice: Failed to allocate expanded activated layer list of size %d.", + inst->expanded_activated_layer_list.capacity); + res = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } + memcpy(dev->expanded_activated_layer_list.list, inst->expanded_activated_layer_list.list, + sizeof(*dev->expanded_activated_layer_list.list) * dev->expanded_activated_layer_list.count); + } else { + dev->expanded_activated_layer_list.capacity = 0; + dev->expanded_activated_layer_list.count = 0; + dev->expanded_activated_layer_list.list = NULL; + } + + res = loader_create_device_chain(phys_dev, pCreateInfo, pAllocator, inst, dev); + if (res != VK_SUCCESS) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to create device chain."); + goto out; + } + + *pDevice = dev->chain_device; + + // Initialize any device extension dispatch entry's from the instance list + loader_init_dispatch_dev_ext(inst, dev); + + // Initialize WSI device extensions as part of core dispatch since loader + // has dedicated trampoline code for these + loader_init_device_extension_dispatch_table(&dev->loader_dispatch, inst->disp->layer_inst_disp.GetInstanceProcAddr, + dev->loader_dispatch.core_dispatch.GetDeviceProcAddr, inst->instance, *pDevice); + +out: + + // Failure cleanup + if (VK_SUCCESS != res) { + if (NULL != dev) { + loader_destroy_logical_device(inst, dev, pAllocator); + } + } + + if (NULL != icd_exts.list) { + loader_destroy_generic_list(inst, (struct loader_generic_list *)&icd_exts); + } + return res; +} + + // Given the list of layers to activate in the loader_instance // structure. This function will add a VkLayerInstanceCreateInfo // structure to the VkInstanceCreateInfo.pNext pointer. diff --git a/loader/loader.h b/loader/loader.h index beb8e1eb..6ba3e8a4 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -505,6 +505,9 @@ VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, c void loaderActivateInstanceLayerExtensions(struct loader_instance *inst, VkInstance created_inst); +VkResult vkLayerCreateDevice(VkInstance instance, VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, + const VkAllocationCallbacks *pAllocator, VkDevice *pDevice, PFN_vkGetInstanceProcAddr layerGIPA, PFN_vkGetDeviceProcAddr *nextGDPA); + VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst, struct loader_device *dev); diff --git a/loader/trampoline.c b/loader/trampoline.c index 39227d87..9d10d07b 100644 --- a/loader/trampoline.c +++ b/loader/trampoline.c @@ -752,117 +752,8 @@ LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkP LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { - VkResult res; - struct loader_physical_device_tramp *phys_dev = NULL; - struct loader_device *dev = NULL; - struct loader_instance *inst = NULL; - - assert(pCreateInfo->queueCreateInfoCount >= 1); - loader_platform_thread_lock_mutex(&loader_lock); - - phys_dev = (struct loader_physical_device_tramp *)physicalDevice; - inst = (struct loader_instance *)phys_dev->this_instance; - - // Get the physical device (ICD) extensions - struct loader_extension_list icd_exts; - icd_exts.list = NULL; - res = loader_init_generic_list(inst, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); - if (VK_SUCCESS != res) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to create ICD extension list"); - goto out; - } - - res = loader_add_device_extensions(inst, inst->disp->layer_inst_disp.EnumerateDeviceExtensionProperties, phys_dev->phys_dev, - "Unknown", &icd_exts); - if (res != VK_SUCCESS) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to add extensions to list"); - goto out; - } - - // Make sure requested extensions to be enabled are supported - res = loader_validate_device_extensions(phys_dev, &inst->expanded_activated_layer_list, &icd_exts, pCreateInfo); - if (res != VK_SUCCESS) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to validate extensions in list"); - goto out; - } - - dev = loader_create_logical_device(inst, pAllocator); - if (dev == NULL) { - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto out; - } - - // Copy the application enabled instance layer list into the device - if (NULL != inst->app_activated_layer_list.list) { - dev->app_activated_layer_list.capacity = inst->app_activated_layer_list.capacity; - dev->app_activated_layer_list.count = inst->app_activated_layer_list.count; - dev->app_activated_layer_list.list = - loader_device_heap_alloc(dev, inst->app_activated_layer_list.capacity, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); - if (dev->app_activated_layer_list.list == NULL) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "vkCreateDevice: Failed to allocate application activated layer list of size %d.", - inst->app_activated_layer_list.capacity); - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto out; - } - memcpy(dev->app_activated_layer_list.list, inst->app_activated_layer_list.list, - sizeof(*dev->app_activated_layer_list.list) * dev->app_activated_layer_list.count); - } else { - dev->app_activated_layer_list.capacity = 0; - dev->app_activated_layer_list.count = 0; - dev->app_activated_layer_list.list = NULL; - } - - // Copy the expanded enabled instance layer list into the device - if (NULL != inst->expanded_activated_layer_list.list) { - dev->expanded_activated_layer_list.capacity = inst->expanded_activated_layer_list.capacity; - dev->expanded_activated_layer_list.count = inst->expanded_activated_layer_list.count; - dev->expanded_activated_layer_list.list = - loader_device_heap_alloc(dev, inst->expanded_activated_layer_list.capacity, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); - if (dev->expanded_activated_layer_list.list == NULL) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "vkCreateDevice: Failed to allocate expanded activated layer list of size %d.", - inst->expanded_activated_layer_list.capacity); - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto out; - } - memcpy(dev->expanded_activated_layer_list.list, inst->expanded_activated_layer_list.list, - sizeof(*dev->expanded_activated_layer_list.list) * dev->expanded_activated_layer_list.count); - } else { - dev->expanded_activated_layer_list.capacity = 0; - dev->expanded_activated_layer_list.count = 0; - dev->expanded_activated_layer_list.list = NULL; - } - - res = loader_create_device_chain(phys_dev, pCreateInfo, pAllocator, inst, dev); - if (res != VK_SUCCESS) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "vkCreateDevice: Failed to create device chain."); - goto out; - } - - *pDevice = dev->chain_device; - - // Initialize any device extension dispatch entry's from the instance list - loader_init_dispatch_dev_ext(inst, dev); - - // Initialize WSI device extensions as part of core dispatch since loader - // has dedicated trampoline code for these - loader_init_device_extension_dispatch_table(&dev->loader_dispatch, inst->disp->layer_inst_disp.GetInstanceProcAddr, - dev->loader_dispatch.core_dispatch.GetDeviceProcAddr, inst->instance, *pDevice); - -out: - - // Failure cleanup - if (VK_SUCCESS != res) { - if (NULL != dev) { - loader_destroy_logical_device(inst, dev, pAllocator); - } - } - - if (NULL != icd_exts.list) { - loader_destroy_generic_list(inst, (struct loader_generic_list *)&icd_exts); - } + VkResult res = vkLayerCreateDevice(NULL, physicalDevice, pCreateInfo, pAllocator, pDevice, NULL, NULL); loader_platform_thread_unlock_mutex(&loader_lock); return res; } -- 2.34.1