diff options
| author | Chia-I Wu <olv@google.com> | 2016-04-28 14:38:57 +0800 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-05-05 06:42:19 -0600 |
| commit | c6d5a62bb9b46ed2f768ba78e51f3b080ed82fc8 (patch) | |
| tree | e989d5c47bae34c4fc4f310d68fdddf9e6443ec9 | |
| parent | b70bedd6ecb8be7ff9ef8100869e74531f10f477 (diff) | |
| download | usermoji-c6d5a62bb9b46ed2f768ba78e51f3b080ed82fc8.tar.xz | |
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.
| -rw-r--r-- | layers/device_limits.cpp | 66 |
1 files changed, 37 insertions, 29 deletions
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<PFN_vkVoidFunction>(GetDeviceProcAddr) }, + { "vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice) }, + { "vkGetDeviceQueue", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue) }, + { "vkCreateRenderPass", reinterpret_cast<PFN_vkVoidFunction>(CreateRenderPass) }, + { "vkCreateCommandPool", reinterpret_cast<PFN_vkVoidFunction>(CreateCommandPool) }, + { "vkDestroyCommandPool", reinterpret_cast<PFN_vkVoidFunction>(DestroyCommandPool) }, + { "vkResetCommandPool", reinterpret_cast<PFN_vkVoidFunction>(ResetCommandPool) }, + { "vkAllocateCommandBuffers", reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers) }, + { "vkFreeCommandBuffers", reinterpret_cast<PFN_vkVoidFunction>(FreeCommandBuffers) }, + { "vkBeginCommandBuffer", reinterpret_cast<PFN_vkVoidFunction>(BeginCommandBuffer) }, + { "vkCmdUpdateBuffer", reinterpret_cast<PFN_vkVoidFunction>(CmdUpdateBuffer) }, + { "vkUpdateDescriptorSets", reinterpret_cast<PFN_vkVoidFunction>(UpdateDescriptorSets) }, + { "vkCmdFillBuffer", reinterpret_cast<PFN_vkVoidFunction>(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 |
