From 5ea6f3a8364c3ffa7483cd0919e2cc61532e75c3 Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Wed, 24 May 2017 14:42:48 -0600 Subject: layers: Clean up core_validation GPA def & handling Got rid of artificially separations in calling GetProcAddr, remove ext enable-checking at GPA-time -- this happens in CV. Change-Id: I89815c86d7f9187537efd3568edd11a9ffffa44f --- layers/core_validation.cpp | 538 +++++++++++++++++---------------------------- 1 file changed, 197 insertions(+), 341 deletions(-) (limited to 'layers/core_validation.cpp') diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 20c06c0e..0131c409 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -11574,49 +11574,211 @@ VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer c dev_data->dispatch_table.CmdPushDescriptorSetWithTemplateKHR(commandBuffer, descriptorUpdateTemplate, layout, set, pData); } -static PFN_vkVoidFunction intercept_core_instance_command(const char *name); - -static PFN_vkVoidFunction intercept_core_device_command(const char *name); - -static PFN_vkVoidFunction intercept_device_extension_command(const char *name, VkDevice device); - -static PFN_vkVoidFunction intercept_khr_swapchain_command(const char *name, VkDevice dev); - -static PFN_vkVoidFunction intercept_khr_surface_command(const char *name, VkInstance instance); - -static PFN_vkVoidFunction -intercept_extension_instance_commands(const char *name, VkInstance instance); +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName); +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName); +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName); + +// Map of all APIs to be intercepted by this layer +static const std::unordered_map name_to_funcptr_map = { + {"vkGetInstanceProcAddr", (void*)GetInstanceProcAddr}, + {"vk_layerGetPhysicalDeviceProcAddr", (void*)GetPhysicalDeviceProcAddr}, + {"vkGetDeviceProcAddr", (void*)GetDeviceProcAddr}, + {"vkCreateInstance", (void*)CreateInstance}, + {"vkCreateDevice", (void*)CreateDevice}, + {"vkEnumeratePhysicalDevices", (void*)EnumeratePhysicalDevices}, + {"vkGetPhysicalDeviceQueueFamilyProperties", (void*)GetPhysicalDeviceQueueFamilyProperties}, + {"vkDestroyInstance", (void*)DestroyInstance}, + {"vkEnumerateInstanceLayerProperties", (void*)EnumerateInstanceLayerProperties}, + {"vkEnumerateDeviceLayerProperties", (void*)EnumerateDeviceLayerProperties}, + {"vkEnumerateInstanceExtensionProperties", (void*)EnumerateInstanceExtensionProperties}, + {"vkEnumerateDeviceExtensionProperties", (void*)EnumerateDeviceExtensionProperties}, + {"vkCreateDescriptorUpdateTemplateKHR", (void*)CreateDescriptorUpdateTemplateKHR}, + {"vkDestroyDescriptorUpdateTemplateKHR", (void*)DestroyDescriptorUpdateTemplateKHR}, + {"vkUpdateDescriptorSetWithTemplateKHR", (void*)UpdateDescriptorSetWithTemplateKHR}, + {"vkCmdPushDescriptorSetWithTemplateKHR", (void*)CmdPushDescriptorSetWithTemplateKHR}, + {"vkCreateSwapchainKHR", (void*)CreateSwapchainKHR}, + {"vkDestroySwapchainKHR", (void*)DestroySwapchainKHR}, + {"vkGetSwapchainImagesKHR", (void*)GetSwapchainImagesKHR}, + {"vkAcquireNextImageKHR", (void*)AcquireNextImageKHR}, + {"vkQueuePresentKHR", (void*)QueuePresentKHR}, + {"vkQueueSubmit", (void*)QueueSubmit}, + {"vkWaitForFences", (void*)WaitForFences}, + {"vkGetFenceStatus", (void*)GetFenceStatus}, + {"vkQueueWaitIdle", (void*)QueueWaitIdle}, + {"vkDeviceWaitIdle", (void*)DeviceWaitIdle}, + {"vkGetDeviceQueue", (void*)GetDeviceQueue}, + {"vkDestroyDevice", (void*)DestroyDevice}, + {"vkDestroyFence", (void*)DestroyFence}, + {"vkResetFences", (void*)ResetFences}, + {"vkDestroySemaphore", (void*)DestroySemaphore}, + {"vkDestroyEvent", (void*)DestroyEvent}, + {"vkDestroyQueryPool", (void*)DestroyQueryPool}, + {"vkDestroyBuffer", (void*)DestroyBuffer}, + {"vkDestroyBufferView", (void*)DestroyBufferView}, + {"vkDestroyImage", (void*)DestroyImage}, + {"vkDestroyImageView", (void*)DestroyImageView}, + {"vkDestroyShaderModule", (void*)DestroyShaderModule}, + {"vkDestroyPipeline", (void*)DestroyPipeline}, + {"vkDestroyPipelineLayout", (void*)DestroyPipelineLayout}, + {"vkDestroySampler", (void*)DestroySampler}, + {"vkDestroyDescriptorSetLayout", (void*)DestroyDescriptorSetLayout}, + {"vkDestroyDescriptorPool", (void*)DestroyDescriptorPool}, + {"vkDestroyFramebuffer", (void*)DestroyFramebuffer}, + {"vkDestroyRenderPass", (void*)DestroyRenderPass}, + {"vkCreateBuffer", (void*)CreateBuffer}, + {"vkCreateBufferView", (void*)CreateBufferView}, + {"vkCreateImage", (void*)CreateImage}, + {"vkCreateImageView", (void*)CreateImageView}, + {"vkCreateFence", (void*)CreateFence}, + {"vkCreatePipelineCache", (void*)CreatePipelineCache}, + {"vkDestroyPipelineCache", (void*)DestroyPipelineCache}, + {"vkGetPipelineCacheData", (void*)GetPipelineCacheData}, + {"vkMergePipelineCaches", (void*)MergePipelineCaches}, + {"vkCreateGraphicsPipelines", (void*)CreateGraphicsPipelines}, + {"vkCreateComputePipelines", (void*)CreateComputePipelines}, + {"vkCreateSampler", (void*)CreateSampler}, + {"vkCreateDescriptorSetLayout", (void*)CreateDescriptorSetLayout}, + {"vkCreatePipelineLayout", (void*)CreatePipelineLayout}, + {"vkCreateDescriptorPool", (void*)CreateDescriptorPool}, + {"vkResetDescriptorPool", (void*)ResetDescriptorPool}, + {"vkAllocateDescriptorSets", (void*)AllocateDescriptorSets}, + {"vkFreeDescriptorSets", (void*)FreeDescriptorSets}, + {"vkUpdateDescriptorSets", (void*)UpdateDescriptorSets}, + {"vkCreateCommandPool", (void*)CreateCommandPool}, + {"vkDestroyCommandPool", (void*)DestroyCommandPool}, + {"vkResetCommandPool", (void*)ResetCommandPool}, + {"vkCreateQueryPool", (void*)CreateQueryPool}, + {"vkAllocateCommandBuffers", (void*)AllocateCommandBuffers}, + {"vkFreeCommandBuffers", (void*)FreeCommandBuffers}, + {"vkBeginCommandBuffer", (void*)BeginCommandBuffer}, + {"vkEndCommandBuffer", (void*)EndCommandBuffer}, + {"vkResetCommandBuffer", (void*)ResetCommandBuffer}, + {"vkCmdBindPipeline", (void*)CmdBindPipeline}, + {"vkCmdSetViewport", (void*)CmdSetViewport}, + {"vkCmdSetScissor", (void*)CmdSetScissor}, + {"vkCmdSetLineWidth", (void*)CmdSetLineWidth}, + {"vkCmdSetDepthBias", (void*)CmdSetDepthBias}, + {"vkCmdSetBlendConstants", (void*)CmdSetBlendConstants}, + {"vkCmdSetDepthBounds", (void*)CmdSetDepthBounds}, + {"vkCmdSetStencilCompareMask", (void*)CmdSetStencilCompareMask}, + {"vkCmdSetStencilWriteMask", (void*)CmdSetStencilWriteMask}, + {"vkCmdSetStencilReference", (void*)CmdSetStencilReference}, + {"vkCmdBindDescriptorSets", (void*)CmdBindDescriptorSets}, + {"vkCmdBindVertexBuffers", (void*)CmdBindVertexBuffers}, + {"vkCmdBindIndexBuffer", (void*)CmdBindIndexBuffer}, + {"vkCmdDraw", (void*)CmdDraw}, + {"vkCmdDrawIndexed", (void*)CmdDrawIndexed}, + {"vkCmdDrawIndirect", (void*)CmdDrawIndirect}, + {"vkCmdDrawIndexedIndirect", (void*)CmdDrawIndexedIndirect}, + {"vkCmdDispatch", (void*)CmdDispatch}, + {"vkCmdDispatchIndirect", (void*)CmdDispatchIndirect}, + {"vkCmdCopyBuffer", (void*)CmdCopyBuffer}, + {"vkCmdCopyImage", (void*)CmdCopyImage}, + {"vkCmdBlitImage", (void*)CmdBlitImage}, + {"vkCmdCopyBufferToImage", (void*)CmdCopyBufferToImage}, + {"vkCmdCopyImageToBuffer", (void*)CmdCopyImageToBuffer}, + {"vkCmdUpdateBuffer", (void*)CmdUpdateBuffer}, + {"vkCmdFillBuffer", (void*)CmdFillBuffer}, + {"vkCmdClearColorImage", (void*)CmdClearColorImage}, + {"vkCmdClearDepthStencilImage", (void*)CmdClearDepthStencilImage}, + {"vkCmdClearAttachments", (void*)CmdClearAttachments}, + {"vkCmdResolveImage", (void*)CmdResolveImage}, + {"vkGetImageSubresourceLayout", (void*)GetImageSubresourceLayout}, + {"vkCmdSetEvent", (void*)CmdSetEvent}, + {"vkCmdResetEvent", (void*)CmdResetEvent}, + {"vkCmdWaitEvents", (void*)CmdWaitEvents}, + {"vkCmdPipelineBarrier", (void*)CmdPipelineBarrier}, + {"vkCmdBeginQuery", (void*)CmdBeginQuery}, + {"vkCmdEndQuery", (void*)CmdEndQuery}, + {"vkCmdResetQueryPool", (void*)CmdResetQueryPool}, + {"vkCmdCopyQueryPoolResults", (void*)CmdCopyQueryPoolResults}, + {"vkCmdPushConstants", (void*)CmdPushConstants}, + {"vkCmdWriteTimestamp", (void*)CmdWriteTimestamp}, + {"vkCreateFramebuffer", (void*)CreateFramebuffer}, + {"vkCreateShaderModule", (void*)CreateShaderModule}, + {"vkCreateRenderPass", (void*)CreateRenderPass}, + {"vkCmdBeginRenderPass", (void*)CmdBeginRenderPass}, + {"vkCmdNextSubpass", (void*)CmdNextSubpass}, + {"vkCmdEndRenderPass", (void*)CmdEndRenderPass}, + {"vkCmdExecuteCommands", (void*)CmdExecuteCommands}, + {"vkSetEvent", (void*)SetEvent}, + {"vkMapMemory", (void*)MapMemory}, + {"vkUnmapMemory", (void*)UnmapMemory}, + {"vkFlushMappedMemoryRanges", (void*)FlushMappedMemoryRanges}, + {"vkInvalidateMappedMemoryRanges", (void*)InvalidateMappedMemoryRanges}, + {"vkAllocateMemory", (void*)AllocateMemory}, + {"vkFreeMemory", (void*)FreeMemory}, + {"vkBindBufferMemory", (void*)BindBufferMemory}, + {"vkGetBufferMemoryRequirements", (void*)GetBufferMemoryRequirements}, + {"vkGetImageMemoryRequirements", (void*)GetImageMemoryRequirements}, + {"vkGetQueryPoolResults", (void*)GetQueryPoolResults}, + {"vkBindImageMemory", (void*)BindImageMemory}, + {"vkQueueBindSparse", (void*)QueueBindSparse}, + {"vkCreateSemaphore", (void*)CreateSemaphore}, + {"vkCreateEvent", (void*)CreateEvent}, +#ifdef VK_USE_PLATFORM_ANDROID_KHR + {"vkCreateAndroidSurfaceKHR", (void*)CreateAndroidSurfaceKHR}, +#endif +#ifdef VK_USE_PLATFORM_MIR_KHR + {"vkCreateMirSurfaceKHR", (void*)CreateMirSurfaceKHR}, + {"vkGetPhysicalDeviceMirPresentationSupportKHR", (void*)GetPhysicalDeviceMirPresentationSupportKHR}, +#endif +#ifdef VK_USE_PLATFORM_WAYLAND_KHR + {"vkCreateWaylandSurfaceKHR", (void*)CreateWaylandSurfaceKHR}, + {"vkGetPhysicalDeviceWaylandPresentationSupportKHR", (void*)GetPhysicalDeviceWaylandPresentationSupportKHR}, +#endif +#ifdef VK_USE_PLATFORM_WIN32_KHR + {"vkCreateWin32SurfaceKHR", (void*)CreateWin32SurfaceKHR}, + {"vkGetPhysicalDeviceWin32PresentationSupportKHR", (void*)GetPhysicalDeviceWin32PresentationSupportKHR}, +#endif +#ifdef VK_USE_PLATFORM_XCB_KHR + {"vkCreateXcbSurfaceKHR", (void*)CreateXcbSurfaceKHR}, + {"vkGetPhysicalDeviceXcbPresentationSupportKHR", (void*)GetPhysicalDeviceXcbPresentationSupportKHR}, +#endif +#ifdef VK_USE_PLATFORM_XLIB_KHR + {"vkCreateXlibSurfaceKHR", (void*)CreateXlibSurfaceKHR}, + {"vkGetPhysicalDeviceXlibPresentationSupportKHR", (void*)GetPhysicalDeviceXlibPresentationSupportKHR}, +#endif + {"vkCreateDisplayPlaneSurfaceKHR", (void*)CreateDisplayPlaneSurfaceKHR}, + {"vkDestroySurfaceKHR", (void*)DestroySurfaceKHR}, + {"vkGetPhysicalDeviceSurfaceCapabilitiesKHR", (void*)GetPhysicalDeviceSurfaceCapabilitiesKHR}, + {"vkGetPhysicalDeviceSurfaceCapabilities2KHR", (void*)GetPhysicalDeviceSurfaceCapabilities2KHR}, + {"vkGetPhysicalDeviceSurfaceCapabilities2EXT", (void*)GetPhysicalDeviceSurfaceCapabilities2EXT}, + {"vkGetPhysicalDeviceSurfaceSupportKHR", (void*)GetPhysicalDeviceSurfaceSupportKHR}, + {"vkGetPhysicalDeviceSurfacePresentModesKHR", (void*)GetPhysicalDeviceSurfacePresentModesKHR}, + {"vkGetPhysicalDeviceSurfaceFormatsKHR", (void*)GetPhysicalDeviceSurfaceFormatsKHR}, + {"vkGetPhysicalDeviceSurfaceFormats2KHR", (void*)GetPhysicalDeviceSurfaceFormats2KHR}, + {"vkGetPhysicalDeviceQueueFamilyProperties2KHR", (void*)GetPhysicalDeviceQueueFamilyProperties2KHR}, + {"vkEnumeratePhysicalDeviceGroupsKHX", (void*)EnumeratePhysicalDeviceGroupsKHX}, + {"vkCreateDebugReportCallbackEXT", (void*)CreateDebugReportCallbackEXT}, + {"vkDestroyDebugReportCallbackEXT", (void*)DestroyDebugReportCallbackEXT}, + {"vkDebugReportMessageEXT", (void*)DebugReportMessageEXT}, +}; -VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice dev, const char *funcName) { - assert(dev); +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { + assert(device); + layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - PFN_vkVoidFunction proc = intercept_core_device_command(funcName); - if (!proc) proc = intercept_device_extension_command(funcName, dev); - if (!proc) proc = intercept_khr_swapchain_command(funcName, dev); - if (proc) return proc; + // Is API to be intercepted by this layer? + const auto &item = name_to_funcptr_map.find(funcName); + if (item != name_to_funcptr_map.end()) { + return reinterpret_cast(item->second); + } - layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(dev), layer_data_map); - auto &table = dev_data->dispatch_table; + auto &table = device_data->dispatch_table; if (!table.GetDeviceProcAddr) return nullptr; - return table.GetDeviceProcAddr(dev, funcName); + return table.GetDeviceProcAddr(device, funcName); } VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { - PFN_vkVoidFunction proc = intercept_core_instance_command(funcName); - if (!proc) proc = intercept_core_device_command(funcName); - if (!proc) proc = intercept_khr_swapchain_command(funcName, VK_NULL_HANDLE); - if (!proc) proc = intercept_khr_surface_command(funcName, instance); - if (proc) return proc; - - assert(instance); - - instance_layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); - proc = debug_report_get_instance_proc_addr(instance_data->report_data, funcName); - if (proc) return proc; - - proc = intercept_extension_instance_commands(funcName, instance); - if (proc) return proc; + instance_layer_data *instance_data; + // Is API to be intercepted by this layer? + const auto &item = name_to_funcptr_map.find(funcName); + if (item != name_to_funcptr_map.end()) { + return reinterpret_cast(item->second); + } + instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); auto &table = instance_data->dispatch_table; if (!table.GetInstanceProcAddr) return nullptr; return table.GetInstanceProcAddr(instance, funcName); @@ -11624,7 +11786,6 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { assert(instance); - instance_layer_data *instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); auto &table = instance_data->dispatch_table; @@ -11632,311 +11793,6 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance in return table.GetPhysicalDeviceProcAddr(instance, 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)}, - {"vk_layerGetPhysicalDeviceProcAddr", reinterpret_cast(GetPhysicalDeviceProcAddr)}, - {"vkGetDeviceProcAddr", reinterpret_cast(GetDeviceProcAddr)}, - {"vkCreateInstance", reinterpret_cast(CreateInstance)}, - {"vkCreateDevice", reinterpret_cast(CreateDevice)}, - {"vkEnumeratePhysicalDevices", reinterpret_cast(EnumeratePhysicalDevices)}, - {"vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast(GetPhysicalDeviceQueueFamilyProperties)}, - {"vkDestroyInstance", reinterpret_cast(DestroyInstance)}, - {"vkEnumerateInstanceLayerProperties", reinterpret_cast(EnumerateInstanceLayerProperties)}, - {"vkEnumerateDeviceLayerProperties", reinterpret_cast(EnumerateDeviceLayerProperties)}, - {"vkEnumerateInstanceExtensionProperties", reinterpret_cast(EnumerateInstanceExtensionProperties)}, - {"vkEnumerateDeviceExtensionProperties", 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; - PFN_vkVoidFunction proc; - } core_device_commands[] = { - {"vkGetDeviceProcAddr", reinterpret_cast(GetDeviceProcAddr)}, - {"vkQueueSubmit", reinterpret_cast(QueueSubmit)}, - {"vkWaitForFences", reinterpret_cast(WaitForFences)}, - {"vkGetFenceStatus", reinterpret_cast(GetFenceStatus)}, - {"vkQueueWaitIdle", reinterpret_cast(QueueWaitIdle)}, - {"vkDeviceWaitIdle", reinterpret_cast(DeviceWaitIdle)}, - {"vkGetDeviceQueue", reinterpret_cast(GetDeviceQueue)}, - {"vkDestroyInstance", reinterpret_cast(DestroyInstance)}, - {"vkDestroyDevice", reinterpret_cast(DestroyDevice)}, - {"vkDestroyFence", reinterpret_cast(DestroyFence)}, - {"vkResetFences", reinterpret_cast(ResetFences)}, - {"vkDestroySemaphore", reinterpret_cast(DestroySemaphore)}, - {"vkDestroyEvent", reinterpret_cast(DestroyEvent)}, - {"vkDestroyQueryPool", reinterpret_cast(DestroyQueryPool)}, - {"vkDestroyBuffer", reinterpret_cast(DestroyBuffer)}, - {"vkDestroyBufferView", reinterpret_cast(DestroyBufferView)}, - {"vkDestroyImage", reinterpret_cast(DestroyImage)}, - {"vkDestroyImageView", reinterpret_cast(DestroyImageView)}, - {"vkDestroyShaderModule", reinterpret_cast(DestroyShaderModule)}, - {"vkDestroyPipeline", reinterpret_cast(DestroyPipeline)}, - {"vkDestroyPipelineLayout", reinterpret_cast(DestroyPipelineLayout)}, - {"vkDestroySampler", reinterpret_cast(DestroySampler)}, - {"vkDestroyDescriptorSetLayout", reinterpret_cast(DestroyDescriptorSetLayout)}, - {"vkDestroyDescriptorPool", reinterpret_cast(DestroyDescriptorPool)}, - {"vkDestroyFramebuffer", reinterpret_cast(DestroyFramebuffer)}, - {"vkDestroyRenderPass", reinterpret_cast(DestroyRenderPass)}, - {"vkCreateBuffer", reinterpret_cast(CreateBuffer)}, - {"vkCreateBufferView", reinterpret_cast(CreateBufferView)}, - {"vkCreateImage", reinterpret_cast(CreateImage)}, - {"vkCreateImageView", reinterpret_cast(CreateImageView)}, - {"vkCreateFence", reinterpret_cast(CreateFence)}, - {"vkCreatePipelineCache", reinterpret_cast(CreatePipelineCache)}, - {"vkDestroyPipelineCache", reinterpret_cast(DestroyPipelineCache)}, - {"vkGetPipelineCacheData", reinterpret_cast(GetPipelineCacheData)}, - {"vkMergePipelineCaches", reinterpret_cast(MergePipelineCaches)}, - {"vkCreateGraphicsPipelines", reinterpret_cast(CreateGraphicsPipelines)}, - {"vkCreateComputePipelines", reinterpret_cast(CreateComputePipelines)}, - {"vkCreateSampler", reinterpret_cast(CreateSampler)}, - {"vkCreateDescriptorSetLayout", reinterpret_cast(CreateDescriptorSetLayout)}, - {"vkCreatePipelineLayout", reinterpret_cast(CreatePipelineLayout)}, - {"vkCreateDescriptorPool", reinterpret_cast(CreateDescriptorPool)}, - {"vkResetDescriptorPool", reinterpret_cast(ResetDescriptorPool)}, - {"vkAllocateDescriptorSets", reinterpret_cast(AllocateDescriptorSets)}, - {"vkFreeDescriptorSets", reinterpret_cast(FreeDescriptorSets)}, - {"vkUpdateDescriptorSets", reinterpret_cast(UpdateDescriptorSets)}, - {"vkCreateCommandPool", reinterpret_cast(CreateCommandPool)}, - {"vkDestroyCommandPool", reinterpret_cast(DestroyCommandPool)}, - {"vkResetCommandPool", reinterpret_cast(ResetCommandPool)}, - {"vkCreateQueryPool", reinterpret_cast(CreateQueryPool)}, - {"vkAllocateCommandBuffers", reinterpret_cast(AllocateCommandBuffers)}, - {"vkFreeCommandBuffers", reinterpret_cast(FreeCommandBuffers)}, - {"vkBeginCommandBuffer", reinterpret_cast(BeginCommandBuffer)}, - {"vkEndCommandBuffer", reinterpret_cast(EndCommandBuffer)}, - {"vkResetCommandBuffer", reinterpret_cast(ResetCommandBuffer)}, - {"vkCmdBindPipeline", reinterpret_cast(CmdBindPipeline)}, - {"vkCmdSetViewport", reinterpret_cast(CmdSetViewport)}, - {"vkCmdSetScissor", reinterpret_cast(CmdSetScissor)}, - {"vkCmdSetLineWidth", reinterpret_cast(CmdSetLineWidth)}, - {"vkCmdSetDepthBias", reinterpret_cast(CmdSetDepthBias)}, - {"vkCmdSetBlendConstants", reinterpret_cast(CmdSetBlendConstants)}, - {"vkCmdSetDepthBounds", reinterpret_cast(CmdSetDepthBounds)}, - {"vkCmdSetStencilCompareMask", reinterpret_cast(CmdSetStencilCompareMask)}, - {"vkCmdSetStencilWriteMask", reinterpret_cast(CmdSetStencilWriteMask)}, - {"vkCmdSetStencilReference", reinterpret_cast(CmdSetStencilReference)}, - {"vkCmdBindDescriptorSets", reinterpret_cast(CmdBindDescriptorSets)}, - {"vkCmdBindVertexBuffers", reinterpret_cast(CmdBindVertexBuffers)}, - {"vkCmdBindIndexBuffer", reinterpret_cast(CmdBindIndexBuffer)}, - {"vkCmdDraw", reinterpret_cast(CmdDraw)}, - {"vkCmdDrawIndexed", reinterpret_cast(CmdDrawIndexed)}, - {"vkCmdDrawIndirect", reinterpret_cast(CmdDrawIndirect)}, - {"vkCmdDrawIndexedIndirect", reinterpret_cast(CmdDrawIndexedIndirect)}, - {"vkCmdDispatch", reinterpret_cast(CmdDispatch)}, - {"vkCmdDispatchIndirect", reinterpret_cast(CmdDispatchIndirect)}, - {"vkCmdCopyBuffer", reinterpret_cast(CmdCopyBuffer)}, - {"vkCmdCopyImage", reinterpret_cast(CmdCopyImage)}, - {"vkCmdBlitImage", reinterpret_cast(CmdBlitImage)}, - {"vkCmdCopyBufferToImage", reinterpret_cast(CmdCopyBufferToImage)}, - {"vkCmdCopyImageToBuffer", reinterpret_cast(CmdCopyImageToBuffer)}, - {"vkCmdUpdateBuffer", reinterpret_cast(CmdUpdateBuffer)}, - {"vkCmdFillBuffer", reinterpret_cast(CmdFillBuffer)}, - {"vkCmdClearColorImage", reinterpret_cast(CmdClearColorImage)}, - {"vkCmdClearDepthStencilImage", reinterpret_cast(CmdClearDepthStencilImage)}, - {"vkCmdClearAttachments", reinterpret_cast(CmdClearAttachments)}, - {"vkCmdResolveImage", reinterpret_cast(CmdResolveImage)}, - {"vkGetImageSubresourceLayout", reinterpret_cast(GetImageSubresourceLayout) }, - {"vkCmdSetEvent", reinterpret_cast(CmdSetEvent)}, - {"vkCmdResetEvent", reinterpret_cast(CmdResetEvent)}, - {"vkCmdWaitEvents", reinterpret_cast(CmdWaitEvents)}, - {"vkCmdPipelineBarrier", reinterpret_cast(CmdPipelineBarrier)}, - {"vkCmdBeginQuery", reinterpret_cast(CmdBeginQuery)}, - {"vkCmdEndQuery", reinterpret_cast(CmdEndQuery)}, - {"vkCmdResetQueryPool", reinterpret_cast(CmdResetQueryPool)}, - {"vkCmdCopyQueryPoolResults", reinterpret_cast(CmdCopyQueryPoolResults)}, - {"vkCmdPushConstants", reinterpret_cast(CmdPushConstants)}, - {"vkCmdWriteTimestamp", reinterpret_cast(CmdWriteTimestamp)}, - {"vkCreateFramebuffer", reinterpret_cast(CreateFramebuffer)}, - {"vkCreateShaderModule", reinterpret_cast(CreateShaderModule)}, - {"vkCreateRenderPass", reinterpret_cast(CreateRenderPass)}, - {"vkCmdBeginRenderPass", reinterpret_cast(CmdBeginRenderPass)}, - {"vkCmdNextSubpass", reinterpret_cast(CmdNextSubpass)}, - {"vkCmdEndRenderPass", reinterpret_cast(CmdEndRenderPass)}, - {"vkCmdExecuteCommands", reinterpret_cast(CmdExecuteCommands)}, - {"vkSetEvent", reinterpret_cast(SetEvent)}, - {"vkMapMemory", reinterpret_cast(MapMemory)}, - {"vkUnmapMemory", reinterpret_cast(UnmapMemory)}, - {"vkFlushMappedMemoryRanges", reinterpret_cast(FlushMappedMemoryRanges)}, - {"vkInvalidateMappedMemoryRanges", reinterpret_cast(InvalidateMappedMemoryRanges)}, - {"vkAllocateMemory", reinterpret_cast(AllocateMemory)}, - {"vkFreeMemory", reinterpret_cast(FreeMemory)}, - {"vkBindBufferMemory", reinterpret_cast(BindBufferMemory)}, - {"vkGetBufferMemoryRequirements", reinterpret_cast(GetBufferMemoryRequirements)}, - {"vkGetImageMemoryRequirements", reinterpret_cast(GetImageMemoryRequirements)}, - {"vkGetQueryPoolResults", reinterpret_cast(GetQueryPoolResults)}, - {"vkBindImageMemory", reinterpret_cast(BindImageMemory)}, - {"vkQueueBindSparse", reinterpret_cast(QueueBindSparse)}, - {"vkCreateSemaphore", reinterpret_cast(CreateSemaphore)}, - {"vkCreateEvent", reinterpret_cast(CreateEvent)}, - }; - - 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; -} - -static PFN_vkVoidFunction intercept_device_extension_command(const char *name, VkDevice device) { - layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); - - const struct { - const char *name; - PFN_vkVoidFunction proc; - bool enabled; - } device_extension_commands[] = { - {"vkCreateDescriptorUpdateTemplateKHR", reinterpret_cast(CreateDescriptorUpdateTemplateKHR), - device_data->extensions.vk_khr_descriptor_update_template}, - {"vkDestroyDescriptorUpdateTemplateKHR", reinterpret_cast(DestroyDescriptorUpdateTemplateKHR), - device_data->extensions.vk_khr_descriptor_update_template}, - {"vkUpdateDescriptorSetWithTemplateKHR", reinterpret_cast(UpdateDescriptorSetWithTemplateKHR), - device_data->extensions.vk_khr_descriptor_update_template}, - {"vkCmdPushDescriptorSetWithTemplateKHR", reinterpret_cast(CmdPushDescriptorSetWithTemplateKHR), - device_data->extensions.vk_khr_descriptor_update_template}, - }; - - if (!device_data) return nullptr; - - for (size_t i = 0; i < ARRAY_SIZE(device_extension_commands); i++) { - if (!strcmp(device_extension_commands[i].name, name) && device_extension_commands[i].enabled) - return device_extension_commands[i].proc; - } - - return nullptr; -} - -static PFN_vkVoidFunction intercept_khr_swapchain_command(const char *name, VkDevice dev) { - static const struct { - const char *name; - PFN_vkVoidFunction proc; - } khr_swapchain_commands[] = { - {"vkCreateSwapchainKHR", reinterpret_cast(CreateSwapchainKHR)}, - {"vkDestroySwapchainKHR", reinterpret_cast(DestroySwapchainKHR)}, - {"vkGetSwapchainImagesKHR", reinterpret_cast(GetSwapchainImagesKHR)}, - {"vkAcquireNextImageKHR", reinterpret_cast(AcquireNextImageKHR)}, - {"vkQueuePresentKHR", reinterpret_cast(QueuePresentKHR)}, - }; - layer_data *dev_data = nullptr; - - if (dev) { - dev_data = GetLayerDataPtr(get_dispatch_key(dev), layer_data_map); - if (!dev_data->extensions.vk_khr_swapchain) return nullptr; - } - - for (size_t i = 0; i < ARRAY_SIZE(khr_swapchain_commands); i++) { - if (!strcmp(khr_swapchain_commands[i].name, name)) return khr_swapchain_commands[i].proc; - } - - if (dev_data) { - if (!dev_data->extensions.vk_khr_display_swapchain) return nullptr; - } - - if (!strcmp("vkCreateSharedSwapchainsKHR", name)) return reinterpret_cast(CreateSharedSwapchainsKHR); - - return nullptr; -} - -static PFN_vkVoidFunction intercept_khr_surface_command(const char *name, VkInstance instance) { - using E = InstanceExtensions; - static const struct { - const char *name; - PFN_vkVoidFunction proc; - bool E::*enable; - } khr_surface_commands[] = { -#ifdef VK_USE_PLATFORM_ANDROID_KHR - {"vkCreateAndroidSurfaceKHR", reinterpret_cast(CreateAndroidSurfaceKHR), &E::vk_khr_android_surface}, -#endif // VK_USE_PLATFORM_ANDROID_KHR -#ifdef VK_USE_PLATFORM_MIR_KHR - {"vkCreateMirSurfaceKHR", reinterpret_cast(CreateMirSurfaceKHR), &E::vk_khr_mir_surface}, - {"vkGetPhysicalDeviceMirPresentationSupportKHR", - reinterpret_cast(GetPhysicalDeviceMirPresentationSupportKHR), &E::vk_khr_mir_surface}, -#endif // VK_USE_PLATFORM_MIR_KHR -#ifdef VK_USE_PLATFORM_WAYLAND_KHR - {"vkCreateWaylandSurfaceKHR", reinterpret_cast(CreateWaylandSurfaceKHR), &E::vk_khr_wayland_surface}, - {"vkGetPhysicalDeviceWaylandPresentationSupportKHR", - reinterpret_cast(GetPhysicalDeviceWaylandPresentationSupportKHR), &E::vk_khr_wayland_surface}, -#endif // VK_USE_PLATFORM_WAYLAND_KHR -#ifdef VK_USE_PLATFORM_WIN32_KHR - {"vkCreateWin32SurfaceKHR", reinterpret_cast(CreateWin32SurfaceKHR), &E::vk_khr_win32_surface}, - {"vkGetPhysicalDeviceWin32PresentationSupportKHR", - reinterpret_cast(GetPhysicalDeviceWin32PresentationSupportKHR), &E::vk_khr_win32_surface}, -#endif // VK_USE_PLATFORM_WIN32_KHR -#ifdef VK_USE_PLATFORM_XCB_KHR - {"vkCreateXcbSurfaceKHR", reinterpret_cast(CreateXcbSurfaceKHR), &E::vk_khr_xcb_surface}, - {"vkGetPhysicalDeviceXcbPresentationSupportKHR", - reinterpret_cast(GetPhysicalDeviceXcbPresentationSupportKHR), &E::vk_khr_xcb_surface}, -#endif // VK_USE_PLATFORM_XCB_KHR -#ifdef VK_USE_PLATFORM_XLIB_KHR - {"vkCreateXlibSurfaceKHR", reinterpret_cast(CreateXlibSurfaceKHR), &E::vk_khr_xlib_surface}, - {"vkGetPhysicalDeviceXlibPresentationSupportKHR", - reinterpret_cast(GetPhysicalDeviceXlibPresentationSupportKHR), &E::vk_khr_xlib_surface}, -#endif // VK_USE_PLATFORM_XLIB_KHR - {"vkCreateDisplayPlaneSurfaceKHR", reinterpret_cast(CreateDisplayPlaneSurfaceKHR), &E::vk_khr_display}, - {"vkDestroySurfaceKHR", reinterpret_cast(DestroySurfaceKHR), &E::vk_khr_surface}, - {"vkGetPhysicalDeviceSurfaceCapabilitiesKHR", reinterpret_cast(GetPhysicalDeviceSurfaceCapabilitiesKHR), - &E::vk_khr_surface}, - {"vkGetPhysicalDeviceSurfaceCapabilities2KHR", - reinterpret_cast(GetPhysicalDeviceSurfaceCapabilities2KHR), &E::vk_khr_get_surface_capabilities_2}, - {"vkGetPhysicalDeviceSurfaceCapabilities2EXT", - reinterpret_cast(GetPhysicalDeviceSurfaceCapabilities2EXT), &E::vk_ext_display_surface_counter}, - {"vkGetPhysicalDeviceSurfaceSupportKHR", reinterpret_cast(GetPhysicalDeviceSurfaceSupportKHR), - &E::vk_khr_surface}, - {"vkGetPhysicalDeviceSurfacePresentModesKHR", reinterpret_cast(GetPhysicalDeviceSurfacePresentModesKHR), - &E::vk_khr_surface}, - {"vkGetPhysicalDeviceSurfaceFormatsKHR", reinterpret_cast(GetPhysicalDeviceSurfaceFormatsKHR), - &E::vk_khr_surface}, - {"vkGetPhysicalDeviceSurfaceFormats2KHR", reinterpret_cast(GetPhysicalDeviceSurfaceFormats2KHR), - &E::vk_khr_get_surface_capabilities_2}, - }; - - instance_layer_data *instance_data = nullptr; - if (instance) { - instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map); - } - - for (size_t i = 0; i < ARRAY_SIZE(khr_surface_commands); i++) { - if (!strcmp(khr_surface_commands[i].name, name)) { - if (instance_data && !(instance_data->extensions.*(khr_surface_commands[i].enable))) return nullptr; - return khr_surface_commands[i].proc; - } - } - - return nullptr; -} - -static PFN_vkVoidFunction intercept_extension_instance_commands(const char *name, VkInstance instance) { - // TODO: sort this out. - static const struct { - const char *name; - PFN_vkVoidFunction proc; - bool instance_layer_data::*enable; - } instance_extension_commands[] = { - {"vkGetPhysicalDeviceQueueFamilyProperties2KHR", - reinterpret_cast(GetPhysicalDeviceQueueFamilyProperties2KHR)}, - {"vkEnumeratePhysicalDeviceGroupsKHX", - reinterpret_cast(EnumeratePhysicalDeviceGroupsKHX)}, - }; - - for (size_t i = 0; i < ARRAY_SIZE(instance_extension_commands); i++) { - if (!strcmp(instance_extension_commands[i].name, name)) { - return instance_extension_commands[i].proc; - } - } - return nullptr; -} - } // namespace core_validation // vk_layer_logging.h expects these to be defined -- cgit v1.2.3