From c6d5a62bb9b46ed2f768ba78e51f3b080ed82fc8 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 28 Apr 2016 14:38:57 +0800 Subject: device_limits: add intercept_core_device_command It returns the function pointers for all intercepted core device commands. Call intercept_core_device_command from GetDeviceProcAddr. Assert that device is valid in GetDeviceProcAddr. --- layers/device_limits.cpp | 66 +++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 29 deletions(-) (limited to 'layers/device_limits.cpp') diff --git a/layers/device_limits.cpp b/layers/device_limits.cpp index ba721272..74743e07 100644 --- a/layers/device_limits.cpp +++ b/layers/device_limits.cpp @@ -680,37 +680,16 @@ EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pCount, pProperties); } +static PFN_vkVoidFunction +intercept_core_device_command(const char *name); + VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice dev, const char *funcName) { - if (!strcmp(funcName, "vkGetDeviceProcAddr")) - return (PFN_vkVoidFunction)GetDeviceProcAddr; - if (!strcmp(funcName, "vkDestroyDevice")) - return (PFN_vkVoidFunction)DestroyDevice; - if (!strcmp(funcName, "vkGetDeviceQueue")) - return (PFN_vkVoidFunction)GetDeviceQueue; - if (!strcmp(funcName, "vkCreateRenderPass")) - return (PFN_vkVoidFunction)CreateRenderPass; - if (!strcmp(funcName, "vkCreateCommandPool")) - return (PFN_vkVoidFunction)CreateCommandPool; - if (!strcmp(funcName, "vkDestroyCommandPool")) - return (PFN_vkVoidFunction)DestroyCommandPool; - if (!strcmp(funcName, "vkResetCommandPool")) - return (PFN_vkVoidFunction)ResetCommandPool; - if (!strcmp(funcName, "vkAllocateCommandBuffers")) - return (PFN_vkVoidFunction)AllocateCommandBuffers; - if (!strcmp(funcName, "vkFreeCommandBuffers")) - return (PFN_vkVoidFunction)FreeCommandBuffers; - if (!strcmp(funcName, "vkBeginCommandBuffer")) - return (PFN_vkVoidFunction)BeginCommandBuffer; - if (!strcmp(funcName, "vkCmdUpdateBuffer")) - return (PFN_vkVoidFunction)CmdUpdateBuffer; - if (!strcmp(funcName, "vkUpdateDescriptorSets")) - return (PFN_vkVoidFunction)UpdateDescriptorSets; - if (!strcmp(funcName, "vkCmdFillBuffer")) - return (PFN_vkVoidFunction)CmdFillBuffer; - - if (dev == NULL) - return NULL; + PFN_vkVoidFunction proc = intercept_core_device_command(funcName); + if (proc) + return proc; + + assert(dev); layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map); VkLayerDispatchTable *pTable = my_data->device_dispatch_table; @@ -778,6 +757,35 @@ GetInstanceProcAddr(VkInstance instance, const char *funcName) { } } +static PFN_vkVoidFunction +intercept_core_device_command(const char *name) { + static const struct { + const char *name; + PFN_vkVoidFunction proc; + } core_device_commands[] = { + { "vkGetDeviceProcAddr", reinterpret_cast(GetDeviceProcAddr) }, + { "vkDestroyDevice", reinterpret_cast(DestroyDevice) }, + { "vkGetDeviceQueue", reinterpret_cast(GetDeviceQueue) }, + { "vkCreateRenderPass", reinterpret_cast(CreateRenderPass) }, + { "vkCreateCommandPool", reinterpret_cast(CreateCommandPool) }, + { "vkDestroyCommandPool", reinterpret_cast(DestroyCommandPool) }, + { "vkResetCommandPool", reinterpret_cast(ResetCommandPool) }, + { "vkAllocateCommandBuffers", reinterpret_cast(AllocateCommandBuffers) }, + { "vkFreeCommandBuffers", reinterpret_cast(FreeCommandBuffers) }, + { "vkBeginCommandBuffer", reinterpret_cast(BeginCommandBuffer) }, + { "vkCmdUpdateBuffer", reinterpret_cast(CmdUpdateBuffer) }, + { "vkUpdateDescriptorSets", reinterpret_cast(UpdateDescriptorSets) }, + { "vkCmdFillBuffer", reinterpret_cast(CmdFillBuffer) }, + }; + + for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) { + if (!strcmp(core_device_commands[i].name, name)) + return core_device_commands[i].proc; + } + + return nullptr; +} + } // namespace device_limits // vk_layer_logging.h expects these to be defined -- cgit v1.2.3