blob: 6b5fc075a8aa13e9c221e8d1d8333bb745eb6d4c [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
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS 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. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
24 * Author: Jon Ashburn <jon@lunarg.com>
25 *
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060026 */
27
28#ifndef GENERIC_H
29#define GENERIC_H
David Pinedo9316d3b2015-11-06 12:54:48 -070030#include "vulkan/vk_layer.h"
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060031
32/*
33 * This file contains static functions for the generated layer Generic
34 */
35
Jon Ashburn3a278b72015-10-06 17:05:21 -060036// The following is for logging error messages:
37struct layer_data {
38 debug_report_data *report_data;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070039 VkDebugReportCallbackEXT logging_callback;
Jon Ashburn3a278b72015-10-06 17:05:21 -060040
41 layer_data() :
42 report_data(nullptr),
Michael Lentine13803dc2015-11-04 14:35:12 -080043 logging_callback(VK_NULL_HANDLE)
Jon Ashburn3a278b72015-10-06 17:05:21 -060044 {};
45};
46
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -060047static const VkLayerProperties globalLayerProps[] = {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060048 {
49 "Generic",
50 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080051 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060052 "layer: Generic",
53 }
54};
55
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -060056static const VkLayerProperties deviceLayerProps[] = {
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060057 {
58 "Generic",
59 VK_API_VERSION, // specVersion
Chia-I Wu3432a0c2015-10-27 18:04:07 +080060 VK_MAKE_VERSION(0, 1, 0), // implementationVersion
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060061 "layer: Generic",
62 }
63};
64
Jon Ashburn6785fe72015-09-17 15:28:12 -060065struct devExts {
66 bool wsi_enabled;
67};
68struct instExts {
69 bool wsi_enabled;
70};
71static std::unordered_map<void *, struct devExts> deviceExtMap;
72static std::unordered_map<void *, struct instExts> instanceExtMap;
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -060073
Jon Ashburn6785fe72015-09-17 15:28:12 -060074static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
75{
76 uint32_t i;
77 VkLayerDispatchTable *pDisp = device_dispatch_table(device);
78 PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
Jon Ashburn6785fe72015-09-17 15:28:12 -060079 pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
80 pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
81 pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
82 pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
83 pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
84
85 deviceExtMap[pDisp].wsi_enabled = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +080086 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -070087 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
Jon Ashburn6785fe72015-09-17 15:28:12 -060088 deviceExtMap[pDisp].wsi_enabled = true;
89
90 }
91}
92
93static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
94{
95 uint32_t i;
96 VkLayerInstanceDispatchTable *pDisp = instance_dispatch_table(instance);
97 PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
98 pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
Ian Elliott05846062015-11-20 14:13:17 -070099 pDisp->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
100 pDisp->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
101 pDisp->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
Jon Ashburn6785fe72015-09-17 15:28:12 -0600102 instanceExtMap[pDisp].wsi_enabled = false;
Chia-I Wud50a7d72015-10-26 20:48:51 +0800103 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Ian Elliott05846062015-11-20 14:13:17 -0700104 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0)
Jon Ashburn6785fe72015-09-17 15:28:12 -0600105 instanceExtMap[pDisp].wsi_enabled = true;
106
107 }
108}
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600109#endif // GENERIC_H
110