1 /*
2 *
3 * Copyright (C) 2015-2016 Valve Corporation
4 * Copyright (C) 2015-2016 LunarG, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Jon Ashburn <jon@lunarg.com>
19 *
20 */
21
22 #pragma once
23 #include <unordered_map>
24 #include "vulkan/vk_layer.h"
25
26 struct wrapped_phys_dev_obj {
27 VkLayerInstanceDispatchTable *loader_disp;
28 struct wrapped_inst_obj *inst; // parent instance object
29 void *obj;
30 };
31
32 struct wrapped_inst_obj {
33 VkLayerInstanceDispatchTable *loader_disp;
34 VkLayerInstanceDispatchTable layer_disp; //this layer's dispatch table
35 PFN_vkSetInstanceLoaderData pfn_inst_init;
36 struct wrapped_phys_dev_obj *ptr_phys_devs; // any enumerated phys devs
37 VkInstance obj;
38 };
39
40 struct wrapped_dev_obj {
41 VkLayerDispatchTable *disp;
42 VkLayerInstanceDispatchTable *layer_disp; // TODO use this
43 PFN_vkSetDeviceLoaderData pfn_dev_init; //TODO use this
44 void *obj;
45 };
46
unwrap_instance(const VkInstance instance,wrapped_inst_obj ** inst)47 static inline VkInstance unwrap_instance(const VkInstance instance, wrapped_inst_obj **inst) {
48 *inst = reinterpret_cast<wrapped_inst_obj *> (instance);
49 return (*inst)->obj;
50 }
51
unwrap_phys_dev(const VkPhysicalDevice physical_device,wrapped_phys_dev_obj ** phys_dev)52 static inline VkPhysicalDevice unwrap_phys_dev(const VkPhysicalDevice physical_device, wrapped_phys_dev_obj **phys_dev) {
53 *phys_dev = reinterpret_cast<wrapped_phys_dev_obj *> (physical_device);
54 return reinterpret_cast <VkPhysicalDevice> ((*phys_dev)->obj);
55 }
56
create_device_register_extensions(const VkDeviceCreateInfo * pCreateInfo,VkDevice device)57 static void create_device_register_extensions(const VkDeviceCreateInfo *pCreateInfo, VkDevice device) {
58 VkLayerDispatchTable *pDisp = device_dispatch_table(device);
59 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
60 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR)gpa(device, "vkCreateSwapchainKHR");
61 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR)gpa(device, "vkDestroySwapchainKHR");
62 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR)gpa(device, "vkGetSwapchainImagesKHR");
63 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR)gpa(device, "vkAcquireNextImageKHR");
64 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR)gpa(device, "vkQueuePresentKHR");
65 }
66