From 15b83b3af972fe32de4b1730ef6aff110e5da49a Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Tue, 5 Mar 2019 12:19:10 +0000 Subject: [PATCH] vulkan/overlay: drop dependency on validation layer headers v2: reimplement layer chain info getters (Eric) v3: make it compile.. (Lionel) Signed-off-by: Lionel Landwerlin Reviewed-by: Eric Engestrom --- src/vulkan/overlay-layer/meson.build | 5 +- src/vulkan/overlay-layer/overlay.cpp | 51 +++++-- src/vulkan/overlay-layer/vk_layer_table.cpp | 146 -------------------- src/vulkan/overlay-layer/vk_layer_table.h | 51 ------- 4 files changed, 40 insertions(+), 213 deletions(-) delete mode 100644 src/vulkan/overlay-layer/vk_layer_table.cpp delete mode 100644 src/vulkan/overlay-layer/vk_layer_table.h diff --git a/src/vulkan/overlay-layer/meson.build b/src/vulkan/overlay-layer/meson.build index 2f0accdfcf2..ddca85fc7ca 100644 --- a/src/vulkan/overlay-layer/meson.build +++ b/src/vulkan/overlay-layer/meson.build @@ -34,14 +34,13 @@ endforeach vklayer_files = files( 'overlay.cpp', 'overlay_params.c', - 'vk_layer_table.cpp', ) vklayer_mesa_overlay = shared_library( 'VkLayer_MESA_overlay', vklayer_files, overlay_spv, - c_args : [c_vis_args, no_override_init_args], - cpp_args : [cpp_vis_args], + c_args : [c_vis_args, no_override_init_args, vulkan_wsi_args], + cpp_args : [cpp_vis_args, vulkan_wsi_args], dependencies : [libimgui_core_dep, dep_dl], include_directories : [inc_common, inc_vulkan_util], link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro']), diff --git a/src/vulkan/overlay-layer/overlay.cpp b/src/vulkan/overlay-layer/overlay.cpp index a2f6f24bdec..19a4de27997 100644 --- a/src/vulkan/overlay-layer/overlay.cpp +++ b/src/vulkan/overlay-layer/overlay.cpp @@ -26,12 +26,7 @@ #include #include -#include #include -#include -#include -#include -#include "vk_layer_table.h" #include "imgui.h" @@ -44,10 +39,11 @@ #include "util/simple_mtx.h" #include "vk_enum_to_str.h" +#include "vk_util.h" /* Mapped from VkInstace/VkPhysicalDevice */ struct instance_data { - VkLayerInstanceDispatchTable vtable; + struct vk_instance_dispatch_table vtable; VkInstance instance; struct overlay_params params; @@ -62,7 +58,7 @@ struct queue_data; struct device_data { struct instance_data *instance; - VkLayerDispatchTable vtable; + struct vk_device_dispatch_table vtable; VkPhysicalDevice physical_device; VkDevice device; @@ -201,6 +197,33 @@ static void unmap_object(void *obj) } /**/ + +static VkLayerInstanceCreateInfo *get_instance_chain_info(const VkInstanceCreateInfo *pCreateInfo, + VkLayerFunction func) +{ + vk_foreach_struct(item, pCreateInfo->pNext) { + if (item->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && + ((VkLayerInstanceCreateInfo *) item)->function == func) + return (VkLayerInstanceCreateInfo *) item; + } + unreachable("instance chain info not found"); + return NULL; +} + +static VkLayerDeviceCreateInfo *get_device_chain_info(const VkDeviceCreateInfo *pCreateInfo, + VkLayerFunction func) +{ + vk_foreach_struct(item, pCreateInfo->pNext) { + if (item->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && + ((VkLayerDeviceCreateInfo *) item)->function == func) + return (VkLayerDeviceCreateInfo *)item; + } + unreachable("device chain info not found"); + return NULL; +} + +/**/ + static struct instance_data *new_instance_data(VkInstance instance) { struct instance_data *data = rzalloc(NULL, struct instance_data); @@ -1645,7 +1668,8 @@ VKAPI_ATTR VkResult VKAPI_CALL overlay_CreateDevice( VkDevice* pDevice) { struct instance_data *instance_data = FIND_PHYSICAL_DEVICE_DATA(physicalDevice); - VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + VkLayerDeviceCreateInfo *chain_info = + get_device_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); assert(chain_info->u.pLayerInfo); PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; @@ -1663,7 +1687,7 @@ VKAPI_ATTR VkResult VKAPI_CALL overlay_CreateDevice( struct device_data *device_data = new_device_data(*pDevice, instance_data); device_data->physical_device = physicalDevice; - layer_init_device_dispatch_table(*pDevice, &device_data->vtable, fpGetDeviceProcAddr); + vk_load_device_commands(*pDevice, fpGetDeviceProcAddr, &device_data->vtable); instance_data->vtable.GetPhysicalDeviceProperties(device_data->physical_device, &device_data->properties); @@ -1688,7 +1712,8 @@ VKAPI_ATTR VkResult VKAPI_CALL overlay_CreateInstance( const VkAllocationCallbacks* pAllocator, VkInstance* pInstance) { - VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); + VkLayerInstanceCreateInfo *chain_info = + get_instance_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); assert(chain_info->u.pLayerInfo); PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = @@ -1706,9 +1731,9 @@ VKAPI_ATTR VkResult VKAPI_CALL overlay_CreateInstance( if (result != VK_SUCCESS) return result; struct instance_data *instance_data = new_instance_data(*pInstance); - layer_init_instance_dispatch_table(instance_data->instance, - &instance_data->vtable, - fpGetInstanceProcAddr); + vk_load_instance_commands(instance_data->instance, + fpGetInstanceProcAddr, + &instance_data->vtable); instance_data_map_physical_devices(instance_data, true); parse_overlay_env(&instance_data->params, getenv("VK_LAYER_MESA_OVERLAY_CONFIG")); diff --git a/src/vulkan/overlay-layer/vk_layer_table.cpp b/src/vulkan/overlay-layer/vk_layer_table.cpp deleted file mode 100644 index 0be2c0afe95..00000000000 --- a/src/vulkan/overlay-layer/vk_layer_table.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* Copyright (c) 2015-2016 The Khronos Group Inc. - * Copyright (c) 2015-2016 Valve Corporation - * Copyright (c) 2015-2016 LunarG, Inc. - * Copyright (c) 2015-2016 Google, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Author: Tobin Ehlis - */ -#include -#include -#include -#include -#include "vk_layer_table.h" -static device_table_map tableMap; -static instance_table_map tableInstanceMap; - -// Map lookup must be thread safe -VkLayerDispatchTable *device_dispatch_table(void *object) { - dispatch_key key = get_dispatch_key(object); - device_table_map::const_iterator it = tableMap.find((void *)key); - assert(it != tableMap.end() && "Not able to find device dispatch entry"); - return it->second; -} - -VkLayerInstanceDispatchTable *instance_dispatch_table(void *object) { - dispatch_key key = get_dispatch_key(object); - instance_table_map::const_iterator it = tableInstanceMap.find((void *)key); - assert(it != tableInstanceMap.end() && "Not able to find instance dispatch entry"); - return it->second; -} - -void destroy_dispatch_table(device_table_map &map, dispatch_key key) { - device_table_map::const_iterator it = map.find((void *)key); - if (it != map.end()) { - delete it->second; - map.erase(it); - } -} - -void destroy_dispatch_table(instance_table_map &map, dispatch_key key) { - instance_table_map::const_iterator it = map.find((void *)key); - if (it != map.end()) { - delete it->second; - map.erase(it); - } -} - -void destroy_device_dispatch_table(dispatch_key key) { destroy_dispatch_table(tableMap, key); } - -void destroy_instance_dispatch_table(dispatch_key key) { destroy_dispatch_table(tableInstanceMap, key); } - -VkLayerDispatchTable *get_dispatch_table(device_table_map &map, void *object) { - dispatch_key key = get_dispatch_key(object); - device_table_map::const_iterator it = map.find((void *)key); - assert(it != map.end() && "Not able to find device dispatch entry"); - return it->second; -} - -VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object) { - dispatch_key key = get_dispatch_key(object); - instance_table_map::const_iterator it = map.find((void *)key); - assert(it != map.end() && "Not able to find instance dispatch entry"); - return it->second; -} - -VkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func) { - VkLayerInstanceCreateInfo *chain_info = (VkLayerInstanceCreateInfo *)pCreateInfo->pNext; - while (chain_info && !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain_info->function == func)) { - chain_info = (VkLayerInstanceCreateInfo *)chain_info->pNext; - } - assert(chain_info != NULL); - return chain_info; -} - -VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func) { - VkLayerDeviceCreateInfo *chain_info = (VkLayerDeviceCreateInfo *)pCreateInfo->pNext; - while (chain_info && !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain_info->function == func)) { - chain_info = (VkLayerDeviceCreateInfo *)chain_info->pNext; - } - assert(chain_info != NULL); - return chain_info; -} - -/* Various dispatchable objects will use the same underlying dispatch table if they - * are created from that "parent" object. Thus use pointer to dispatch table - * as the key to these table maps. - * Instance -> PhysicalDevice - * Device -> CommandBuffer or Queue - * If use the object themselves as key to map then implies Create entrypoints have to be intercepted - * and a new key inserted into map */ -VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map) { - VkLayerInstanceDispatchTable *pTable; - dispatch_key key = get_dispatch_key(instance); - instance_table_map::const_iterator it = map.find((void *)key); - - if (it == map.end()) { - pTable = new VkLayerInstanceDispatchTable; - map[(void *)key] = pTable; - } else { - return it->second; - } - - layer_init_instance_dispatch_table(instance, pTable, gpa); - - // Setup func pointers that are required but not externally exposed. These won't be added to the instance dispatch table by - // default. - pTable->GetPhysicalDeviceProcAddr = (PFN_GetPhysicalDeviceProcAddr)gpa(instance, "vk_layerGetPhysicalDeviceProcAddr"); - - return pTable; -} - -VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa) { - return initInstanceTable(instance, gpa, tableInstanceMap); -} - -VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map) { - VkLayerDispatchTable *pTable; - dispatch_key key = get_dispatch_key(device); - device_table_map::const_iterator it = map.find((void *)key); - - if (it == map.end()) { - pTable = new VkLayerDispatchTable; - map[(void *)key] = pTable; - } else { - return it->second; - } - - layer_init_device_dispatch_table(device, pTable, gpa); - - return pTable; -} - -VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa) { - return initDeviceTable(device, gpa, tableMap); -} diff --git a/src/vulkan/overlay-layer/vk_layer_table.h b/src/vulkan/overlay-layer/vk_layer_table.h deleted file mode 100644 index 33f124b591d..00000000000 --- a/src/vulkan/overlay-layer/vk_layer_table.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (c) 2015-2016 The Khronos Group Inc. - * Copyright (c) 2015-2016 Valve Corporation - * Copyright (c) 2015-2016 LunarG, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Author: Tobin Ehlis - */ - -#pragma once - -#include -#include -#include - -typedef std::unordered_map device_table_map; -typedef std::unordered_map instance_table_map; -VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map); -VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa); -VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map); -VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa); - -typedef void *dispatch_key; - -static inline dispatch_key get_dispatch_key(const void *object) { return (dispatch_key) * (VkLayerDispatchTable **)object; } - -VkLayerDispatchTable *device_dispatch_table(void *object); - -VkLayerInstanceDispatchTable *instance_dispatch_table(void *object); - -VkLayerDispatchTable *get_dispatch_table(device_table_map &map, void *object); - -VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object); - -VkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func); -VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func); - -void destroy_device_dispatch_table(dispatch_key key); -void destroy_instance_dispatch_table(dispatch_key key); -void destroy_dispatch_table(device_table_map &map, dispatch_key key); -void destroy_dispatch_table(instance_table_map &map, dispatch_key key); -- 2.30.2