From a1de4b2dffb98222ca59f4a70c301d22bb4c089e Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Fri, 8 Jan 2016 12:18:43 -0700 Subject: loader: implement new layer init method New layer init method requires the construction of Link information for CreateInstance and CreateDevice that is accessible to layers via the CreateInfo.pNext pointer. The layer can then use the Get*ProcAddr from the Link structure to initialize their dispatch table if the call down the chain returns successfully. This removes the need to do special initialization work at Get*ProcAddr time. Layer Get*ProcAddr now return their internal function pointers regardless of the value of instance or device. Only need to have valid instance & device when looking up extensions or when passing the request down the chain. This mechanism allows us to remove object wrapping used by the loader previously. Also simplifies the dispatch table setup. Conflicts: layers/device_limits.cpp layers/draw_state.cpp loader/loader.c loader/trampoline.c --- layers/object_tracker.h | 79 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 21 deletions(-) (limited to 'layers/object_tracker.h') diff --git a/layers/object_tracker.h b/layers/object_tracker.h index de44f0e2..4622c189 100644 --- a/layers/object_tracker.h +++ b/layers/object_tracker.h @@ -29,6 +29,7 @@ #include "vulkan/vk_layer.h" #include "vk_layer_extension_utils.h" #include "vk_enum_string_helper.h" +#include "vk_layer_table.h" // Object Tracker ERROR codes typedef enum _OBJECT_TRACK_ERROR @@ -689,22 +690,38 @@ explicit_CreateInstance( const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { + VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); - VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, *pInstance); - VkResult result = pInstanceTable->CreateInstance(pCreateInfo, pAllocator, pInstance); + assert(chain_info->u.pLayerInfo); + PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; + PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance"); + if (fpCreateInstance == NULL) { + return VK_ERROR_INITIALIZATION_FAILED; + } - if (result == VK_SUCCESS) { - layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); - my_data->report_data = debug_report_create_instance( - pInstanceTable, - *pInstance, - pCreateInfo->enabledExtensionCount, - pCreateInfo->ppEnabledExtensionNames); - createInstanceRegisterExtensions(pCreateInfo, *pInstance); - - initObjectTracker(my_data, pAllocator); - create_instance(*pInstance, *pInstance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT); + // Advance the link info for the next element on the chain + chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; + + VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); + if (result != VK_SUCCESS) { + return result; } + + layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map); + initInstanceTable(*pInstance, fpGetInstanceProcAddr, object_tracker_instance_table_map); + VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, *pInstance); + + my_data->report_data = debug_report_create_instance( + pInstanceTable, + *pInstance, + pCreateInfo->enabledExtensionCount, + pCreateInfo->ppEnabledExtensionNames); + + initObjectTracker(my_data, pAllocator); + createInstanceRegisterExtensions(pCreateInfo, *pInstance); + + create_instance(*pInstance, *pInstance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT); + return result; } @@ -730,16 +747,36 @@ explicit_CreateDevice( VkDevice *pDevice) { loader_platform_thread_lock_mutex(&objLock); - VkLayerDispatchTable *pDeviceTable = get_dispatch_table(object_tracker_device_table_map, *pDevice); - VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice); - if (result == VK_SUCCESS) { - layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); - layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); - my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); - create_device(*pDevice, *pDevice, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT); - createDeviceRegisterExtensions(pCreateInfo, *pDevice); + VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + + assert(chain_info->u.pLayerInfo); + PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; + PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; + PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice"); + if (fpCreateDevice == NULL) { + loader_platform_thread_unlock_mutex(&objLock); + return VK_ERROR_INITIALIZATION_FAILED; + } + + // Advance the link info for the next element on the chain + chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; + + VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); + if (result != VK_SUCCESS) { + loader_platform_thread_unlock_mutex(&objLock); + return result; } + layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map); + layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map); + my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice); + + initDeviceTable(*pDevice, fpGetDeviceProcAddr, object_tracker_device_table_map); + + createDeviceRegisterExtensions(pCreateInfo, *pDevice); + + create_device(*pDevice, *pDevice, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT); + loader_platform_thread_unlock_mutex(&objLock); return result; } -- cgit v1.2.3