blob: a59f389b8224fed91a3908afbafb557ffef5fcef [file] [log] [blame]
Ian Elliottd3ef02f2015-07-06 14:36:13 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
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 *
24 * Authors:
25 * Jon Ashburn <jon@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
27 * Ian Elliott <ian@lunarg.com>
28 */
29
30#define _ISOC11_SOURCE /* for aligned_alloc() */
31#include <stdlib.h>
32#include <string.h>
33#include "vk_loader_platform.h"
34#include "loader.h"
35#include "wsi_swapchain.h"
36
Jon Ashburn5c042ea2015-08-04 11:14:18 -060037static const VkExtensionProperties wsi_swapchain_extension_info = {
Ian Elliott7e40db92015-08-21 15:09:33 -060038 .extName = VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME,
Ian Elliott4d330692015-09-04 14:02:04 -060039 .specVersion = VK_EXT_KHR_SWAPCHAIN_REVISION,
Ian Elliottd3ef02f2015-07-06 14:36:13 -060040};
41
42void wsi_swapchain_add_instance_extensions(
Jon Ashburne39a4f82015-08-28 13:38:21 -060043 const struct loader_instance *inst,
Ian Elliottd3ef02f2015-07-06 14:36:13 -060044 struct loader_extension_list *ext_list)
45{
Jon Ashburne39a4f82015-08-28 13:38:21 -060046 loader_add_to_ext_list(inst, ext_list, 1, &wsi_swapchain_extension_info);
Ian Elliottd3ef02f2015-07-06 14:36:13 -060047}
48
49void wsi_swapchain_create_instance(
50 struct loader_instance *ptr_instance,
51 const VkInstanceCreateInfo *pCreateInfo)
52{
53 ptr_instance->wsi_swapchain_enabled = false;
54
55 for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) {
Ian Elliott7e40db92015-08-21 15:09:33 -060056 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Ian Elliottd3ef02f2015-07-06 14:36:13 -060057 ptr_instance->wsi_swapchain_enabled = true;
58 return;
59 }
60 }
61}
62
63/*
64 * This is the trampoline entrypoint
Ian Elliott7e40db92015-08-21 15:09:33 -060065 * for GetPhysicalDeviceSurfaceSupportKHR
Ian Elliottd3ef02f2015-07-06 14:36:13 -060066 */
Ian Elliott7e40db92015-08-21 15:09:33 -060067VkResult wsi_swapchain_GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliottd3ef02f2015-07-06 14:36:13 -060068 VkPhysicalDevice physicalDevice,
69 uint32_t queueNodeIndex,
Ian Elliott7e40db92015-08-21 15:09:33 -060070 const VkSurfaceDescriptionKHR* pSurfaceDescription,
Ian Elliottd3ef02f2015-07-06 14:36:13 -060071 VkBool32* pSupported)
72{
73 const VkLayerInstanceDispatchTable *disp;
74// TBD/TODO: DO WE NEED TO DO LOCKING FOR THIS FUNCTION?
75 disp = loader_get_instance_dispatch(physicalDevice);
76 loader_platform_thread_lock_mutex(&loader_lock);
Ian Elliott7e40db92015-08-21 15:09:33 -060077 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliottd3ef02f2015-07-06 14:36:13 -060078 physicalDevice,
79 queueNodeIndex,
80 pSurfaceDescription,
81 pSupported);
82 loader_platform_thread_unlock_mutex(&loader_lock);
83 return res;
84}
85
86/*
87 * This is the instance chain terminator function
Ian Elliott7e40db92015-08-21 15:09:33 -060088 * for GetPhysicalDeviceSurfaceSupportKHR
Ian Elliottd3ef02f2015-07-06 14:36:13 -060089 */
Ian Elliott7e40db92015-08-21 15:09:33 -060090VkResult VKAPI loader_GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliottd3ef02f2015-07-06 14:36:13 -060091 VkPhysicalDevice physicalDevice,
92 uint32_t queueNodeIndex,
Ian Elliott7e40db92015-08-21 15:09:33 -060093 const VkSurfaceDescriptionKHR* pSurfaceDescription,
Ian Elliottd3ef02f2015-07-06 14:36:13 -060094 VkBool32* pSupported)
95{
96 uint32_t gpu_index;
97 struct loader_icd *icd = loader_get_icd(physicalDevice, &gpu_index);
Courtney Goeltzenleuchtered894072015-09-04 13:39:59 -060098 VkResult res = VK_ERROR_UNKNOWN;
Ian Elliottd3ef02f2015-07-06 14:36:13 -060099 *pSupported = false;
100
Ian Elliott7e40db92015-08-21 15:09:33 -0600101 if (icd->GetPhysicalDeviceSurfaceSupportKHR) {
102 res = icd->GetPhysicalDeviceSurfaceSupportKHR(physicalDevice,
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600103 queueNodeIndex,
104 pSurfaceDescription,
105 pSupported);
106 }
107
108 return res;
109}
110
111
112void *wsi_swapchain_GetInstanceProcAddr(
113 struct loader_instance *ptr_instance,
114 const char* pName)
115{
116 if (ptr_instance == VK_NULL_HANDLE || !ptr_instance->wsi_swapchain_enabled) {
117 return NULL;
118 }
119
Ian Elliott7e40db92015-08-21 15:09:33 -0600120 if (!strcmp(pName, "vkGetPhysicalDeviceSurfaceSupportKHR")) {
121 return (void*) wsi_swapchain_GetPhysicalDeviceSurfaceSupportKHR;
Ian Elliottd3ef02f2015-07-06 14:36:13 -0600122 }
123
124 return NULL;
125}