blob: ba9a58a1a3d89faa6d1dafd54053a9ded0132329 [file] [log] [blame]
Ian Elliott54cea232015-10-30 15:28:23 -06001/*
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 Elliottb1849742015-11-19 11:58:08 -070024 * Author: Ian Elliott <ianelliott@google.com>
Ian Elliott54cea232015-10-30 15:28:23 -060025 */
26
Ian Elliottb1849742015-11-19 11:58:08 -070027// 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 Elliott54cea232015-10-30 15:28:23 -060044//#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
52static 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 Elliottb1849742015-11-19 11:58:08 -070058#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060059static const VkExtensionProperties wsi_win32_surface_extension_info = {
60 .extensionName = VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
61 .specVersion = VK_KHR_WIN32_SURFACE_REVISION,
62};
Ian Elliottb1849742015-11-19 11:58:08 -070063#endif/ VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060064#else // _WIN32
Ian Elliott5fb891a2015-10-30 17:45:05 -060065#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060066static const VkExtensionProperties wsi_mir_surface_extension_info = {
67 .extensionName = VK_KHR_MIR_SURFACE_EXTENSION_NAME,
68 .specVersion = VK_KHR_MIR_SURFACE_REVISION,
69};
Ian Elliott5fb891a2015-10-30 17:45:05 -060070#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060071
Ian Elliott5fb891a2015-10-30 17:45:05 -060072#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060073static const VkExtensionProperties wsi_wayland_surface_extension_info = {
74 .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
75 .specVersion = VK_KHR_WAYLAND_SURFACE_REVISION,
76};
Ian Elliott5fb891a2015-10-30 17:45:05 -060077#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060078
Ian Elliott5fb891a2015-10-30 17:45:05 -060079#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060080static const VkExtensionProperties wsi_xcb_surface_extension_info = {
81 .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME,
82 .specVersion = VK_KHR_XCB_SURFACE_REVISION,
83};
Ian Elliott5fb891a2015-10-30 17:45:05 -060084#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060085
Ian Elliott5fb891a2015-10-30 17:45:05 -060086#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060087static const VkExtensionProperties wsi_xlib_surface_extension_info = {
88 .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
89 .specVersion = VK_KHR_XLIB_SURFACE_REVISION,
90};
Ian Elliott5fb891a2015-10-30 17:45:05 -060091#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -060092#endif // _WIN32
93
94void 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 Elliottb1849742015-11-19 11:58:08 -0700100#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600101 loader_add_to_ext_list(inst, ext_list, 1, &wsi_win32_surface_extension_info);
Ian Elliottb1849742015-11-19 11:58:08 -0700102#endif/ VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600103#else // _WIN32
Ian Elliott5fb891a2015-10-30 17:45:05 -0600104#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600105 loader_add_to_ext_list(inst, ext_list, 1, &wsi_mir_surface_extension_info);
Ian Elliott5fb891a2015-10-30 17:45:05 -0600106#endif // VK_USE_PLATFORM_MIR_KHR
107#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600108 loader_add_to_ext_list(inst, ext_list, 1, &wsi_wayland_surface_extension_info);
Ian Elliott5fb891a2015-10-30 17:45:05 -0600109#endif // VK_USE_PLATFORM_WAYLAND_KHR
110#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600111 loader_add_to_ext_list(inst, ext_list, 1, &wsi_xcb_surface_extension_info);
Ian Elliott5fb891a2015-10-30 17:45:05 -0600112#endif // VK_USE_PLATFORM_XCB_KHR
113#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600114 loader_add_to_ext_list(inst, ext_list, 1, &wsi_xlib_surface_extension_info);
Ian Elliott5fb891a2015-10-30 17:45:05 -0600115#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600116#endif // _WIN32
117}
118
119void wsi_create_instance(
120 struct loader_instance *ptr_instance,
121 const VkInstanceCreateInfo *pCreateInfo)
122{
Ian Elliott5fb891a2015-10-30 17:45:05 -0600123 ptr_instance->wsi_surface_enabled = false;
Ian Elliott54cea232015-10-30 15:28:23 -0600124#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 Elliottb1849742015-11-19 11:58:08 -0700137 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600138 }
139#ifdef _WIN32
Ian Elliottb1849742015-11-19 11:58:08 -0700140#ifdef VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600141 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
142 ptr_instance->wsi_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700143 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600144 }
Ian Elliottb1849742015-11-19 11:58:08 -0700145#endif/ VK_USE_PLATFORM_WIN32_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600146#else // _WIN32
Ian Elliott5fb891a2015-10-30 17:45:05 -0600147#ifdef VK_USE_PLATFORM_MIR_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600148 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MIR_SURFACE_EXTENSION_NAME) == 0) {
149 ptr_instance->wsi_mir_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700150 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600151 }
Ian Elliott5fb891a2015-10-30 17:45:05 -0600152#endif // VK_USE_PLATFORM_MIR_KHR
153#ifdef VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600154 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) == 0) {
155 ptr_instance->wsi_wayland_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700156 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600157 }
Ian Elliott5fb891a2015-10-30 17:45:05 -0600158#endif // VK_USE_PLATFORM_WAYLAND_KHR
159#ifdef VK_USE_PLATFORM_XCB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600160 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XCB_SURFACE_EXTENSION_NAME) == 0) {
161 ptr_instance->wsi_xcb_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700162 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600163 }
Ian Elliott5fb891a2015-10-30 17:45:05 -0600164#endif // VK_USE_PLATFORM_XCB_KHR
165#ifdef VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600166 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_XLIB_SURFACE_EXTENSION_NAME) == 0) {
167 ptr_instance->wsi_xlib_surface_enabled = true;
Ian Elliottb1849742015-11-19 11:58:08 -0700168 continue;
Ian Elliott54cea232015-10-30 15:28:23 -0600169 }
Ian Elliott5fb891a2015-10-30 17:45:05 -0600170#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott54cea232015-10-30 15:28:23 -0600171#endif // _WIN32
172 }
173}
174
175/*
176 * This is the trampoline entrypoint
177 * for GetPhysicalDeviceSurfaceSupportKHR
178 */
Ian Elliottf3be00f2015-11-19 12:37:51 -0700179LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott54cea232015-10-30 15:28:23 -0600180 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 */
199VKAPI_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
219bool 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 Elliottf3be00f2015-11-19 12:37:51 -0700225 *addr = ptr_instance->wsi_surface_enabled ? (void *) vkGetPhysicalDeviceSurfaceSupportKHR : NULL;
Ian Elliott54cea232015-10-30 15:28:23 -0600226 return true;
227 }
228 return false;
229}