Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2015 Valve Corporation |
| 4 | * |
| 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 | * |
| 23 | * Author: Ian Elliott <ian@lunarg.com> |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 24 | * Author: Ian Elliott <ianelliott@google.com> |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 25 | */ |
| 26 | |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 27 | // FIXME/TODO: DEVELOP A BETTER APPROACH FOR SETTING THE DEFAULT VALUES FOR |
| 28 | // THESE PLATFORM-SPECIFIC MACROS APPROPRIATELY: |
| 29 | #ifdef _WIN32 |
| 30 | // The Win32 default is to support the WIN32 platform: |
| 31 | #ifndef VK_USE_PLATFORM_WIN32_KHR |
| 32 | #define VK_USE_PLATFORM_WIN32_KHR |
| 33 | #endif |
| 34 | #else // _WIN32 (i.e. Linux) |
| 35 | // The Linux default is to support the XCB platform: |
| 36 | #if (!defined(VK_USE_PLATFORM_MIR_KHR) && \ |
| 37 | !defined(VK_USE_PLATFORM_WAYLAND_KHR) && \ |
| 38 | !defined(VK_USE_PLATFORM_XCB_KHR) && \ |
| 39 | !defined(VK_USE_PLATFORM_XLIB_KHR)) |
| 40 | #define VK_USE_PLATFORM_XCB_KHR |
| 41 | #endif |
| 42 | #endif // _WIN32 |
| 43 | |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 44 | //#define _ISOC11_SOURCE /* for aligned_alloc() */ |
| 45 | #define _GNU_SOURCE |
| 46 | #include <stdlib.h> |
| 47 | #include <string.h> |
| 48 | #include "vk_loader_platform.h" |
| 49 | #include "loader.h" |
| 50 | #include "wsi.h" |
| 51 | |
| 52 | static const VkExtensionProperties wsi_surface_extension_info = { |
| 53 | .extensionName = VK_KHR_SURFACE_EXTENSION_NAME, |
| 54 | .specVersion = VK_KHR_SURFACE_REVISION, |
| 55 | }; |
| 56 | |
| 57 | #ifdef _WIN32 |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 58 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 59 | static const VkExtensionProperties wsi_win32_surface_extension_info = { |
| 60 | .extensionName = VK_KHR_WIN32_SURFACE_EXTENSION_NAME, |
| 61 | .specVersion = VK_KHR_WIN32_SURFACE_REVISION, |
| 62 | }; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 63 | #endif/ VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 64 | #else // _WIN32 |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 65 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 66 | static const VkExtensionProperties wsi_mir_surface_extension_info = { |
| 67 | .extensionName = VK_KHR_MIR_SURFACE_EXTENSION_NAME, |
| 68 | .specVersion = VK_KHR_MIR_SURFACE_REVISION, |
| 69 | }; |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 70 | #endif // VK_USE_PLATFORM_MIR_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 71 | |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 72 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 73 | static const VkExtensionProperties wsi_wayland_surface_extension_info = { |
| 74 | .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, |
| 75 | .specVersion = VK_KHR_WAYLAND_SURFACE_REVISION, |
| 76 | }; |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 77 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 78 | |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 79 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 80 | static const VkExtensionProperties wsi_xcb_surface_extension_info = { |
| 81 | .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME, |
| 82 | .specVersion = VK_KHR_XCB_SURFACE_REVISION, |
| 83 | }; |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 84 | #endif // VK_USE_PLATFORM_XCB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 85 | |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 86 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 87 | static const VkExtensionProperties wsi_xlib_surface_extension_info = { |
| 88 | .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_NAME, |
| 89 | .specVersion = VK_KHR_XLIB_SURFACE_REVISION, |
| 90 | }; |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 91 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 92 | #endif // _WIN32 |
| 93 | |
| 94 | void wsi_add_instance_extensions( |
| 95 | const struct loader_instance *inst, |
| 96 | struct loader_extension_list *ext_list) |
| 97 | { |
| 98 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_surface_extension_info); |
| 99 | #ifdef _WIN32 |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 100 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 101 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_win32_surface_extension_info); |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 102 | #endif/ VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 103 | #else // _WIN32 |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 104 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 105 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_mir_surface_extension_info); |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 106 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 107 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 108 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_wayland_surface_extension_info); |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 109 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 110 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 111 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_xcb_surface_extension_info); |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 112 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 113 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 114 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_xlib_surface_extension_info); |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 115 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 116 | #endif // _WIN32 |
| 117 | } |
| 118 | |
| 119 | void wsi_create_instance( |
| 120 | struct loader_instance *ptr_instance, |
| 121 | const VkInstanceCreateInfo *pCreateInfo) |
| 122 | { |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 123 | ptr_instance->wsi_surface_enabled = false; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 124 | #ifdef _WIN32 |
| 125 | ptr_instance->wsi_surface_enabled = true; |
| 126 | #else // _WIN32 |
| 127 | ptr_instance->wsi_mir_surface_enabled = false; |
| 128 | ptr_instance->wsi_wayland_surface_enabled = false; |
| 129 | ptr_instance->wsi_xcb_surface_enabled = false; |
| 130 | ptr_instance->wsi_xlib_surface_enabled = false; |
| 131 | #endif // _WIN32 |
| 132 | ptr_instance->wsi_swapchain_enabled = false; |
| 133 | |
| 134 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) { |
| 135 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) { |
| 136 | ptr_instance->wsi_surface_enabled = true; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 137 | continue; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 138 | } |
| 139 | #ifdef _WIN32 |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 140 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 141 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) { |
| 142 | ptr_instance->wsi_surface_enabled = true; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 143 | continue; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 144 | } |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 145 | #endif/ VK_USE_PLATFORM_WIN32_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 146 | #else // _WIN32 |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 147 | #ifdef VK_USE_PLATFORM_MIR_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 148 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) { |
| 149 | ptr_instance->wsi_mir_surface_enabled = true; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 150 | continue; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 151 | } |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 152 | #endif // VK_USE_PLATFORM_MIR_KHR |
| 153 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 154 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) { |
| 155 | ptr_instance->wsi_wayland_surface_enabled = true; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 156 | continue; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 157 | } |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 158 | #endif // VK_USE_PLATFORM_WAYLAND_KHR |
| 159 | #ifdef VK_USE_PLATFORM_XCB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 160 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) { |
| 161 | ptr_instance->wsi_xcb_surface_enabled = true; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 162 | continue; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 163 | } |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 164 | #endif // VK_USE_PLATFORM_XCB_KHR |
| 165 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 166 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) { |
| 167 | ptr_instance->wsi_xlib_surface_enabled = true; |
Ian Elliott | b184974 | 2015-11-19 11:58:08 -0700 | [diff] [blame] | 168 | continue; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 169 | } |
Ian Elliott | 5fb891a | 2015-10-30 17:45:05 -0600 | [diff] [blame] | 170 | #endif // VK_USE_PLATFORM_XLIB_KHR |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 171 | #endif // _WIN32 |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * This is the trampoline entrypoint |
| 177 | * for GetPhysicalDeviceSurfaceSupportKHR |
| 178 | */ |
Ian Elliott | f3be00f | 2015-11-19 12:37:51 -0700 | [diff] [blame^] | 179 | LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR( |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 180 | VkPhysicalDevice physicalDevice, |
| 181 | uint32_t queueFamilyIndex, |
| 182 | VkSurfaceKHR surface, |
| 183 | VkBool32* pSupported) |
| 184 | { |
| 185 | const VkLayerInstanceDispatchTable *disp; |
| 186 | disp = loader_get_instance_dispatch(physicalDevice); |
| 187 | VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR( |
| 188 | physicalDevice, |
| 189 | queueFamilyIndex, |
| 190 | surface, |
| 191 | pSupported); |
| 192 | return res; |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * This is the instance chain terminator function |
| 197 | * for GetPhysicalDeviceSurfaceSupportKHR |
| 198 | */ |
| 199 | VKAPI_ATTR VkResult VKAPI_CALL loader_GetPhysicalDeviceSurfaceSupportKHR( |
| 200 | VkPhysicalDevice physicalDevice, |
| 201 | uint32_t queueFamilyIndex, |
| 202 | VkSurfaceKHR surface, |
| 203 | VkBool32* pSupported) |
| 204 | { |
| 205 | struct loader_physical_device *phys_dev = (struct loader_physical_device *) physicalDevice; |
| 206 | struct loader_icd *icd = phys_dev->this_icd; |
| 207 | |
| 208 | assert(pSupported && "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported"); |
| 209 | *pSupported = false; |
| 210 | |
| 211 | assert(icd->GetPhysicalDeviceSurfaceSupportKHR && "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer"); |
| 212 | |
| 213 | return icd->GetPhysicalDeviceSurfaceSupportKHR(phys_dev->phys_dev, |
| 214 | queueFamilyIndex, |
| 215 | surface, |
| 216 | pSupported); |
| 217 | } |
| 218 | |
| 219 | bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, |
| 220 | const char* name, void **addr) |
| 221 | { |
| 222 | *addr = NULL; |
| 223 | |
| 224 | if (!strcmp("vkGetPhysicalDeviceSurfaceSupportKHR", name)) { |
Ian Elliott | f3be00f | 2015-11-19 12:37:51 -0700 | [diff] [blame^] | 225 | *addr = ptr_instance->wsi_surface_enabled ? (void *) vkGetPhysicalDeviceSurfaceSupportKHR : NULL; |
Ian Elliott | 54cea23 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 226 | return true; |
| 227 | } |
| 228 | return false; |
| 229 | } |