Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 1 | /* |
| 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 Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 37 | static const VkExtensionProperties wsi_swapchain_extension_info = { |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 38 | .extName = VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME, |
Ian Elliott | 4d33069 | 2015-09-04 14:02:04 -0600 | [diff] [blame] | 39 | .specVersion = VK_EXT_KHR_SWAPCHAIN_REVISION, |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | void wsi_swapchain_add_instance_extensions( |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 43 | const struct loader_instance *inst, |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 44 | struct loader_extension_list *ext_list) |
| 45 | { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 46 | loader_add_to_ext_list(inst, ext_list, 1, &wsi_swapchain_extension_info); |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void 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 Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 56 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0) { |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 57 | ptr_instance->wsi_swapchain_enabled = true; |
| 58 | return; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * This is the trampoline entrypoint |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 65 | * for GetPhysicalDeviceSurfaceSupportKHR |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 66 | */ |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 67 | VkResult wsi_swapchain_GetPhysicalDeviceSurfaceSupportKHR( |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 68 | VkPhysicalDevice physicalDevice, |
| 69 | uint32_t queueNodeIndex, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 70 | const VkSurfaceDescriptionKHR* pSurfaceDescription, |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 71 | 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 Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 77 | VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR( |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 78 | 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 Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 88 | * for GetPhysicalDeviceSurfaceSupportKHR |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 89 | */ |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 90 | VkResult VKAPI loader_GetPhysicalDeviceSurfaceSupportKHR( |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 91 | VkPhysicalDevice physicalDevice, |
| 92 | uint32_t queueNodeIndex, |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 93 | const VkSurfaceDescriptionKHR* pSurfaceDescription, |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 94 | VkBool32* pSupported) |
| 95 | { |
| 96 | uint32_t gpu_index; |
| 97 | struct loader_icd *icd = loader_get_icd(physicalDevice, &gpu_index); |
Courtney Goeltzenleuchter | ed89407 | 2015-09-04 13:39:59 -0600 | [diff] [blame] | 98 | VkResult res = VK_ERROR_UNKNOWN; |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 99 | *pSupported = false; |
| 100 | |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 101 | if (icd->GetPhysicalDeviceSurfaceSupportKHR) { |
| 102 | res = icd->GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 103 | queueNodeIndex, |
| 104 | pSurfaceDescription, |
| 105 | pSupported); |
| 106 | } |
| 107 | |
| 108 | return res; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | void *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 Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 120 | if (!strcmp(pName, "vkGetPhysicalDeviceSurfaceSupportKHR")) { |
| 121 | return (void*) wsi_swapchain_GetPhysicalDeviceSurfaceSupportKHR; |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | return NULL; |
| 125 | } |