1 /* Copyright (c) 2015-2016 The Khronos Group Inc.
2  * Copyright (c) 2015-2016 Valve Corporation
3  * Copyright (c) 2015-2016 LunarG, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and/or associated documentation files (the "Materials"), to
7  * deal in the Materials without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Materials, and to permit persons to whom the Materials
10  * are furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice(s) and this permission notice shall be included
13  * in all copies or substantial portions of the Materials.
14  *
15  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  *
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
22  * USE OR OTHER DEALINGS IN THE MATERIALS
23  *
24  * Author: Tobin Ehlis <tobin@lunarg.com>
25  */
26 
27 #pragma once
28 
29 #include "vulkan/vulkan.h"
30 #include <unordered_map>
31 
32 typedef std::unordered_map<void *, VkLayerDispatchTable *> device_table_map;
33 typedef std::unordered_map<void *, VkLayerInstanceDispatchTable *> instance_table_map;
34 VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, device_table_map &map);
35 VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa);
36 VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, instance_table_map &map);
37 VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa);
38 
39 typedef void *dispatch_key;
40 
get_dispatch_key(const void * object)41 static inline dispatch_key get_dispatch_key(const void *object) { return (dispatch_key) * (VkLayerDispatchTable **)object; }
42 
43 VkLayerDispatchTable *device_dispatch_table(void *object);
44 
45 VkLayerInstanceDispatchTable *instance_dispatch_table(void *object);
46 
47 VkLayerDispatchTable *get_dispatch_table(device_table_map &map, void *object);
48 
49 VkLayerInstanceDispatchTable *get_dispatch_table(instance_table_map &map, void *object);
50 
51 VkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func);
52 VkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func);
53 
54 void destroy_device_dispatch_table(dispatch_key key);
55 void destroy_instance_dispatch_table(dispatch_key key);
56 void destroy_dispatch_table(device_table_map &map, dispatch_key key);
57 void destroy_dispatch_table(instance_table_map &map, dispatch_key key);
58