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 | |
| 37 | static const struct loader_extension_property wsi_swapchain_extension_info = { |
| 38 | .info = { |
| 39 | .extName = VK_WSI_SWAPCHAIN_EXTENSION_NAME, |
| 40 | .specVersion = VK_WSI_SWAPCHAIN_REVISION, |
| 41 | }, |
| 42 | .origin = VK_EXTENSION_ORIGIN_LOADER, |
| 43 | }; |
| 44 | |
| 45 | void wsi_swapchain_add_instance_extensions( |
| 46 | struct loader_extension_list *ext_list) |
| 47 | { |
| 48 | loader_add_to_ext_list(ext_list, 1, &wsi_swapchain_extension_info); |
| 49 | } |
| 50 | |
| 51 | void wsi_swapchain_create_instance( |
| 52 | struct loader_instance *ptr_instance, |
| 53 | const VkInstanceCreateInfo *pCreateInfo) |
| 54 | { |
| 55 | ptr_instance->wsi_swapchain_enabled = false; |
| 56 | |
| 57 | for (uint32_t i = 0; i < pCreateInfo->extensionCount; i++) { |
| 58 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_SWAPCHAIN_EXTENSION_NAME) == 0) { |
| 59 | ptr_instance->wsi_swapchain_enabled = true; |
| 60 | return; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * This is the trampoline entrypoint |
| 67 | * for GetPhysicalDeviceSurfaceSupportWSI |
| 68 | */ |
| 69 | VkResult wsi_swapchain_GetPhysicalDeviceSurfaceSupportWSI( |
| 70 | VkPhysicalDevice physicalDevice, |
| 71 | uint32_t queueNodeIndex, |
| 72 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 73 | VkBool32* pSupported) |
| 74 | { |
| 75 | const VkLayerInstanceDispatchTable *disp; |
| 76 | // TBD/TODO: DO WE NEED TO DO LOCKING FOR THIS FUNCTION? |
| 77 | disp = loader_get_instance_dispatch(physicalDevice); |
| 78 | loader_platform_thread_lock_mutex(&loader_lock); |
| 79 | VkResult res = disp->GetPhysicalDeviceSurfaceSupportWSI( |
| 80 | physicalDevice, |
| 81 | queueNodeIndex, |
| 82 | pSurfaceDescription, |
| 83 | pSupported); |
| 84 | loader_platform_thread_unlock_mutex(&loader_lock); |
| 85 | return res; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * This is the instance chain terminator function |
| 90 | * for GetPhysicalDeviceSurfaceSupportWSI |
| 91 | */ |
Dan Ginsburg | 78556e8 | 2015-07-23 13:15:00 -0400 | [diff] [blame] | 92 | VkResult VKAPI loader_GetPhysicalDeviceSurfaceSupportWSI( |
Ian Elliott | d3ef02f | 2015-07-06 14:36:13 -0600 | [diff] [blame] | 93 | VkPhysicalDevice physicalDevice, |
| 94 | uint32_t queueNodeIndex, |
| 95 | const VkSurfaceDescriptionWSI* pSurfaceDescription, |
| 96 | VkBool32* pSupported) |
| 97 | { |
| 98 | uint32_t gpu_index; |
| 99 | struct loader_icd *icd = loader_get_icd(physicalDevice, &gpu_index); |
| 100 | VkResult res = VK_ERROR_UNAVAILABLE; |
| 101 | *pSupported = false; |
| 102 | |
| 103 | if (icd->GetPhysicalDeviceSurfaceSupportWSI) { |
| 104 | res = icd->GetPhysicalDeviceSurfaceSupportWSI(physicalDevice, |
| 105 | queueNodeIndex, |
| 106 | pSurfaceDescription, |
| 107 | pSupported); |
| 108 | } |
| 109 | |
| 110 | return res; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | void *wsi_swapchain_GetInstanceProcAddr( |
| 115 | struct loader_instance *ptr_instance, |
| 116 | const char* pName) |
| 117 | { |
| 118 | if (ptr_instance == VK_NULL_HANDLE || !ptr_instance->wsi_swapchain_enabled) { |
| 119 | return NULL; |
| 120 | } |
| 121 | |
| 122 | if (!strcmp(pName, "vkGetPhysicalDeviceSurfaceSupportWSI")) { |
| 123 | return (void*) wsi_swapchain_GetPhysicalDeviceSurfaceSupportWSI; |
| 124 | } |
| 125 | |
| 126 | return NULL; |
| 127 | } |