From: Chia-I Wu Date: Thu, 28 Apr 2016 06:38:57 +0000 (+0800) Subject: device_limits: refactor GetInstanceProcAddr X-Git-Tag: upstream/1.1.92~3183 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef783c346c9597abc2555dbe9b7e6444472cbabd;p=platform%2Fupstream%2FVulkan-Tools.git device_limits: refactor GetInstanceProcAddr Split command intercepting out to intercept_core_instance_command. --- diff --git a/layers/device_limits.cpp b/layers/device_limits.cpp index d5ad798..4f464c7 100644 --- a/layers/device_limits.cpp +++ b/layers/device_limits.cpp @@ -681,6 +681,9 @@ EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, } static PFN_vkVoidFunction +intercept_core_instance_command(const char *name); + +static PFN_vkVoidFunction intercept_core_device_command(const char *name); VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL @@ -702,43 +705,13 @@ GetDeviceProcAddr(VkDevice dev, const char *funcName) { VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { + PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); + if (proc) + return proc; + PFN_vkVoidFunction fptr; layer_data *my_data; - if (!strcmp(funcName, "vkGetInstanceProcAddr")) - return (PFN_vkVoidFunction)GetInstanceProcAddr; - if (!strcmp(funcName, "vkGetDeviceProcAddr")) - return (PFN_vkVoidFunction)GetDeviceProcAddr; - if (!strcmp(funcName, "vkCreateInstance")) - return (PFN_vkVoidFunction)CreateInstance; - if (!strcmp(funcName, "vkDestroyInstance")) - return (PFN_vkVoidFunction)DestroyInstance; - if (!strcmp(funcName, "vkCreateDevice")) - return (PFN_vkVoidFunction)CreateDevice; - if (!strcmp(funcName, "vkEnumeratePhysicalDevices")) - return (PFN_vkVoidFunction)EnumeratePhysicalDevices; - if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures")) - return (PFN_vkVoidFunction)GetPhysicalDeviceFeatures; - if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties")) - return (PFN_vkVoidFunction)GetPhysicalDeviceFormatProperties; - if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties")) - return (PFN_vkVoidFunction)GetPhysicalDeviceImageFormatProperties; - if (!strcmp(funcName, "vkGetPhysicalDeviceProperties")) - return (PFN_vkVoidFunction)GetPhysicalDeviceProperties; - if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties")) - return (PFN_vkVoidFunction)GetPhysicalDeviceQueueFamilyProperties; - if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties")) - return (PFN_vkVoidFunction)GetPhysicalDeviceMemoryProperties; - if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties")) - return (PFN_vkVoidFunction)GetPhysicalDeviceSparseImageFormatProperties; - if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties")) - return (PFN_vkVoidFunction)vkEnumerateInstanceLayerProperties; - if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties")) - return (PFN_vkVoidFunction)vkEnumerateDeviceLayerProperties; - if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties")) - return (PFN_vkVoidFunction)vkEnumerateInstanceExtensionProperties; - if (!strcmp(funcName, "vkEnumerateInstanceDeviceProperties")) - return (PFN_vkVoidFunction)EnumerateDeviceExtensionProperties; if (!instance) return NULL; @@ -758,6 +731,39 @@ GetInstanceProcAddr(VkInstance instance, const char *funcName) { } static PFN_vkVoidFunction +intercept_core_instance_command(const char *name) { + static const struct { + const char *name; + PFN_vkVoidFunction proc; + } core_instance_commands[] = { + { "vkGetInstanceProcAddr", reinterpret_cast(GetInstanceProcAddr) }, + { "vkGetDeviceProcAddr", reinterpret_cast(GetDeviceProcAddr) }, + { "vkCreateInstance", reinterpret_cast(CreateInstance) }, + { "vkDestroyInstance", reinterpret_cast(DestroyInstance) }, + { "vkCreateDevice", reinterpret_cast(CreateDevice) }, + { "vkEnumeratePhysicalDevices", reinterpret_cast(EnumeratePhysicalDevices) }, + { "vkGetPhysicalDeviceFeatures", reinterpret_cast(GetPhysicalDeviceFeatures) }, + { "vkGetPhysicalDeviceFormatProperties", reinterpret_cast(GetPhysicalDeviceFormatProperties) }, + { "vkGetPhysicalDeviceImageFormatProperties", reinterpret_cast(GetPhysicalDeviceImageFormatProperties) }, + { "vkGetPhysicalDeviceProperties", reinterpret_cast(GetPhysicalDeviceProperties) }, + { "vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast(GetPhysicalDeviceQueueFamilyProperties) }, + { "vkGetPhysicalDeviceMemoryProperties", reinterpret_cast(GetPhysicalDeviceMemoryProperties) }, + { "vkGetPhysicalDeviceSparseImageFormatProperties", reinterpret_cast(GetPhysicalDeviceSparseImageFormatProperties) }, + { "vkEnumerateInstanceLayerProperties", reinterpret_cast(vkEnumerateInstanceLayerProperties) }, + { "vkEnumerateDeviceLayerProperties", reinterpret_cast(vkEnumerateDeviceLayerProperties) }, + { "vkEnumerateInstanceExtensionProperties", reinterpret_cast(vkEnumerateInstanceExtensionProperties) }, + { "vkEnumerateInstanceDeviceProperties", reinterpret_cast(EnumerateDeviceExtensionProperties) }, + }; + + for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) { + if (!strcmp(core_instance_commands[i].name, name)) + return core_instance_commands[i].proc; + } + + return nullptr; +} + +static PFN_vkVoidFunction intercept_core_device_command(const char *name) { static const struct { const char *name;