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']),
#include <assert.h>
#include <vulkan/vulkan.h>
-#include <vulkan/vk_dispatch_table_helper.h>
#include <vulkan/vk_layer.h>
-#include <vulkan/vk_layer_data.h>
-#include <vulkan/vk_layer_extension_utils.h>
-#include <vulkan/vk_loader_platform.h>
-#include "vk_layer_table.h"
#include "imgui.h"
#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;
struct device_data {
struct instance_data *instance;
- VkLayerDispatchTable vtable;
+ struct vk_device_dispatch_table vtable;
VkPhysicalDevice physical_device;
VkDevice device;
}
/**/
+
+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);
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;
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);
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 =
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"));
+++ /dev/null
-/* 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 <tobin@lunarg.com>
- */
-#include <assert.h>
-#include <unordered_map>
-#include <vulkan/vk_dispatch_table_helper.h>
-#include <vulkan/vk_layer.h>
-#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);
-}
+++ /dev/null
-/* 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 <tobin@lunarg.com>
- */
-
-#pragma once
-
-#include <vulkan/vk_layer.h>
-#include <vulkan/vulkan.h>
-#include <unordered_map>
-
-typedef std::unordered_map<void *, VkLayerDispatchTable *> device_table_map;
-typedef std::unordered_map<void *, VkLayerInstanceDispatchTable *> 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);