blob: 955ea7d62aff0c96999a1d846b258009902110b1 [file] [log] [blame]
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06001/*
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentine03107b42015-12-11 10:49:51 -08004 * Copyright (C) 2015 Google Inc.
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060024 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
25 * Author: Jon Ashburn <jon@lunarg.com>
26 *
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060027 */
28
29#ifndef GENERIC_H
30#define GENERIC_H
David Pinedo9316d3b2015-11-06 12:54:48 -070031#include "vulkan/vk_layer.h"
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060032
33/*
34 * This file contains static functions for the generated layer Generic
35 */
36
Jon Ashburn3a278b72015-10-06 17:05:21 -060037// The following is for logging error messages:
38struct layer_data {
39 debug_report_data *report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070040 VkDebugReportCallbackEXT logging_callback;
Jon Ashburn3a278b72015-10-06 17:05:21 -060041
42 layer_data() :
43 report_data(nullptr),
Michael Lentine13803dc2015-11-04 14:35:12 -080044 logging_callback(VK_NULL_HANDLE)
Jon Ashburn3a278b72015-10-06 17:05:21 -060045 {};
46};
47
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -060048static const VkLayerProperties globalLayerProps[] = {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060049 {
Michael Lentine03107b42015-12-11 10:49:51 -080050 "VK_LAYER_LUNARG_generic",
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060051 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080052 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060053 "layer: Generic",
54 }
55};
56
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -060057static const VkLayerProperties deviceLayerProps[] = {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060058 {
Michael Lentine03107b42015-12-11 10:49:51 -080059 "VK_LAYER_LUNARG_generic",
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060060 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080061 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060062 "layer: Generic",
63 }
64};
65
Jon Ashburn6785fe72015-09-17 15:28:12 -060066struct devExts {
67 bool wsi_enabled;
68};
69struct instExts {
70 bool wsi_enabled;
71};
72static std::unordered_map<void *, struct devExts> deviceExtMap;
73static std::unordered_map<void *, struct instExts> instanceExtMap;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060074
Jon Ashburn6785fe72015-09-17 15:28:12 -060075static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
76{
77 uint32_t i;
78 VkLayerDispatchTable *pDisp = device_dispatch_table(device);
79 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
Jon Ashburn6785fe72015-09-17 15:28:12 -060080 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
81 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
82 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
83 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
84 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
85
86 deviceExtMap[pDisp].wsi_enabled = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +080087 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -070088 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
Jon Ashburn6785fe72015-09-17 15:28:12 -060089 deviceExtMap[pDisp].wsi_enabled = true;
90
91 }
92}
93
94static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
95{
96 uint32_t i;
97 VkLayerInstanceDispatchTable *pDisp = instance_dispatch_table(instance);
98 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
99 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott05846062015-11-20 14:13:17 -0700100 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
101 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
102 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Jon Ashburn6785fe72015-09-17 15:28:12 -0600103 instanceExtMap[pDisp].wsi_enabled = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800104 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -0700105 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0)
Jon Ashburn6785fe72015-09-17 15:28:12 -0600106 instanceExtMap[pDisp].wsi_enabled = true;
107
108 }
109}
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600110#endif // GENERIC_H
111