blob: fc2fc99560637492740a2191ab4cd22a01276269 [file] [log] [blame]
Ian Elliott1d73e662015-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 Ashburnc4748dc2015-08-04 11:14:18 -060037static const VkExtensionProperties wsi_swapchain_extension_info = {
Ian Elliott338dedb2015-08-21 15:09:33 -060038 .extName = VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME,
Ian Elliotta4e1c902015-09-04 14:02:04 -060039 .specVersion = VK_EXT_KHR_SWAPCHAIN_REVISION,
Ian Elliott1d73e662015-07-06 14:36:13 -060040};
41
42void wsi_swapchain_add_instance_extensions(
Jon Ashburne58f1a32015-08-28 13:38:21 -060043 const struct loader_instance *inst,
Ian Elliott1d73e662015-07-06 14:36:13 -060044 struct loader_extension_list *ext_list)
45{
Jon Ashburne58f1a32015-08-28 13:38:21 -060046 loader_add_to_ext_list(inst, ext_list, 1, &wsi_swapchain_extension_info);
Ian Elliott1d73e662015-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 Elliott338dedb2015-08-21 15:09:33 -060056 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) {
Ian Elliott1d73e662015-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 Elliott338dedb2015-08-21 15:09:33 -060065 * for GetPhysicalDeviceSurfaceSupportKHR
Ian Elliott1d73e662015-07-06 14:36:13 -060066 */
Ian Elliott338dedb2015-08-21 15:09:33 -060067VkResult wsi_swapchain_GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott1d73e662015-07-06 14:36:13 -060068 VkPhysicalDevice physicalDevice,
69 uint32_t queueNodeIndex,
Ian Elliott338dedb2015-08-21 15:09:33 -060070 const VkSurfaceDescriptionKHR* pSurfaceDescription,
Ian Elliott1d73e662015-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);
Ian Elliott329da012015-09-22 10:51:24 -060076// loader_platform_thread_lock_mutex(&loader_lock);
Ian Elliott338dedb2015-08-21 15:09:33 -060077 VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott1d73e662015-07-06 14:36:13 -060078 physicalDevice,
79 queueNodeIndex,
80 pSurfaceDescription,
81 pSupported);
Ian Elliott329da012015-09-22 10:51:24 -060082// loader_platform_thread_unlock_mutex(&loader_lock);
Ian Elliott1d73e662015-07-06 14:36:13 -060083 return res;
84}
85
86/*
87 * This is the instance chain terminator function
Ian Elliott338dedb2015-08-21 15:09:33 -060088 * for GetPhysicalDeviceSurfaceSupportKHR
Ian Elliott1d73e662015-07-06 14:36:13 -060089 */
Ian Elliott338dedb2015-08-21 15:09:33 -060090VkResult VKAPI loader_GetPhysicalDeviceSurfaceSupportKHR(
Ian Elliott1d73e662015-07-06 14:36:13 -060091 VkPhysicalDevice physicalDevice,
92 uint32_t queueNodeIndex,
Ian Elliott338dedb2015-08-21 15:09:33 -060093 const VkSurfaceDescriptionKHR* pSurfaceDescription,
Ian Elliott1d73e662015-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 Goeltzenleuchterac544f32015-09-14 18:01:17 -060098
99 assert(pSupported && "GetPhysicalDeviceSurfaceSupportKHR: Error, null pSupported");
Ian Elliott1d73e662015-07-06 14:36:13 -0600100 *pSupported = false;
101
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600102 assert(icd->GetPhysicalDeviceSurfaceSupportKHR && "loader: null GetPhysicalDeviceSurfaceSupportKHR ICD pointer");
Ian Elliott1d73e662015-07-06 14:36:13 -0600103
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -0600104 return icd->GetPhysicalDeviceSurfaceSupportKHR(physicalDevice,
105 queueNodeIndex,
106 pSurfaceDescription,
107 pSupported);
Ian Elliott1d73e662015-07-06 14:36:13 -0600108}
109
110
111void *wsi_swapchain_GetInstanceProcAddr(
112 struct loader_instance *ptr_instance,
113 const char* pName)
114{
115 if (ptr_instance == VK_NULL_HANDLE || !ptr_instance->wsi_swapchain_enabled) {
116 return NULL;
117 }
118
Ian Elliott338dedb2015-08-21 15:09:33 -0600119 if (!strcmp(pName, "vkGetPhysicalDeviceSurfaceSupportKHR")) {
120 return (void*) wsi_swapchain_GetPhysicalDeviceSurfaceSupportKHR;
Ian Elliott1d73e662015-07-06 14:36:13 -0600121 }
122
123 return NULL;
124}