Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -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 | */ |
| 28 | |
| 29 | #include <string.h> |
| 30 | #include "loader_platform.h" |
| 31 | #include "loader.h" |
| 32 | #include "wsi_lunarg.h" |
| 33 | |
| 34 | /************ Trampoline entrypoints *******************/ |
| 35 | /* since one entrypoint is instance level will make available all entrypoints */ |
| 36 | VkResult VKAPI wsi_lunarg_GetDisplayInfoWSI( |
| 37 | VkDisplayWSI display, |
| 38 | VkDisplayInfoTypeWSI infoType, |
| 39 | size_t* pDataSize, |
| 40 | void* pData) |
| 41 | { |
| 42 | const VkLayerInstanceDispatchTable *disp; |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 43 | VkResult res; |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 44 | |
| 45 | disp = loader_get_instance_dispatch(display); |
| 46 | |
Jon Ashburn | b40f256 | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 47 | loader_platform_thread_lock_mutex(&loader_lock); |
| 48 | res = disp->GetDisplayInfoWSI(display, infoType, pDataSize, pData); |
| 49 | loader_platform_thread_unlock_mutex(&loader_lock); |
| 50 | return res; |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | VkResult wsi_lunarg_CreateSwapChainWSI( |
| 54 | VkDevice device, |
| 55 | const VkSwapChainCreateInfoWSI* pCreateInfo, |
| 56 | VkSwapChainWSI* pSwapChain) |
| 57 | { |
| 58 | const VkLayerDispatchTable *disp; |
| 59 | VkResult res; |
| 60 | |
| 61 | disp = loader_get_dispatch(device); |
| 62 | |
| 63 | res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain); |
| 64 | if (res == VK_SUCCESS) { |
| 65 | loader_init_dispatch(*pSwapChain, disp); |
| 66 | } |
| 67 | |
| 68 | return res; |
| 69 | } |
| 70 | |
| 71 | VkResult wsi_lunarg_DestroySwapChainWSI( |
| 72 | VkSwapChainWSI swapChain) |
| 73 | { |
| 74 | const VkLayerDispatchTable *disp; |
| 75 | |
| 76 | disp = loader_get_dispatch(swapChain); |
| 77 | |
| 78 | return disp->DestroySwapChainWSI(swapChain); |
| 79 | } |
| 80 | |
| 81 | static VkResult wsi_lunarg_GetSwapChainInfoWSI( |
| 82 | VkSwapChainWSI swapChain, |
| 83 | VkSwapChainInfoTypeWSI infoType, |
| 84 | size_t* pDataSize, |
| 85 | void* pData) |
| 86 | { |
| 87 | const VkLayerDispatchTable *disp; |
| 88 | |
| 89 | disp = loader_get_dispatch(swapChain); |
| 90 | |
| 91 | return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData); |
| 92 | } |
| 93 | |
| 94 | static VkResult wsi_lunarg_QueuePresentWSI( |
| 95 | VkQueue queue, |
| 96 | const VkPresentInfoWSI* pPresentInfo) |
| 97 | { |
| 98 | const VkLayerDispatchTable *disp; |
| 99 | |
| 100 | disp = loader_get_dispatch(queue); |
| 101 | |
| 102 | return disp->QueuePresentWSI(queue, pPresentInfo); |
| 103 | } |
| 104 | |
| 105 | /************ loader instance chain termination entrypoints ***************/ |
| 106 | VkResult loader_GetDisplayInfoWSI( |
| 107 | VkDisplayWSI display, |
| 108 | VkDisplayInfoTypeWSI infoType, |
| 109 | size_t* pDataSize, |
| 110 | void* pData) |
| 111 | { |
Courtney Goeltzenleuchter | 5c55b35 | 2015-06-10 17:52:04 -0600 | [diff] [blame] | 112 | /* TODO: need another way to find the icd, display is not a gpu object */ |
Courtney Goeltzenleuchter | ac13c6f | 2015-06-10 20:39:06 -0600 | [diff] [blame] | 113 | // uint32_t gpu_index; |
| 114 | // struct loader_icd *icd = loader_get_icd((VkPhysicalDevice) display, &gpu_index); //TODO fix dispaly -> PhysDev |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 115 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 116 | |
Courtney Goeltzenleuchter | ac13c6f | 2015-06-10 20:39:06 -0600 | [diff] [blame] | 117 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 118 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 119 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 120 | if (icd->GetDisplayInfoWSI) |
| 121 | res = icd->GetDisplayInfoWSI(display, infoType, pDataSize, pData); |
| 122 | } |
| 123 | } |
| 124 | } |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 125 | |
| 126 | return res; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | /************ extension enablement ***************/ |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 131 | #define WSI_LUNARG_EXT_ARRAY_SIZE 1 |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 132 | static const struct loader_extension_property wsi_lunarg_extension_info = { |
| 133 | .info = { |
| 134 | .sType = VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 135 | .name = VK_WSI_LUNARG_EXTENSION_NAME, |
| 136 | .version = VK_WSI_LUNARG_REVISION, |
| 137 | .description = "loader: LunarG WSI extension", |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 138 | }, |
| 139 | .origin = VK_EXTENSION_ORIGIN_LOADER, |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 140 | }; |
| 141 | |
Jon Ashburn | a445e09 | 2015-05-26 13:57:35 -0600 | [diff] [blame] | 142 | void wsi_lunarg_add_instance_extensions( |
| 143 | struct loader_extension_list *ext_list) |
| 144 | { |
| 145 | loader_add_to_ext_list(ext_list, 1, &wsi_lunarg_extension_info); |
| 146 | } |
| 147 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 148 | void wsi_lunarg_create_instance( |
| 149 | struct loader_instance *ptr_instance) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 150 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 151 | ptr_instance->wsi_lunarg_enabled = has_vk_extension_property( |
| 152 | &wsi_lunarg_extension_info.info, |
| 153 | &ptr_instance->enabled_instance_extensions); |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void *wsi_lunarg_GetInstanceProcAddr( |
| 157 | VkInstance instance, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 158 | const char* pName) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 159 | { |
| 160 | if (instance == VK_NULL_HANDLE) |
| 161 | return NULL; |
| 162 | |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 163 | /* since two of these entrypoints must be loader handled will report all */ |
| 164 | if (!strcmp(pName, "vkGetDisplayInfoWSI")) |
| 165 | return (void*) wsi_lunarg_GetDisplayInfoWSI; |
| 166 | if (!strcmp(pName, "vkCreateSwapChainWSI")) |
| 167 | return (void*) wsi_lunarg_CreateSwapChainWSI; |
| 168 | if (!strcmp(pName, "vkDestroySwapChainWSI")) |
| 169 | return (void*) wsi_lunarg_DestroySwapChainWSI; |
| 170 | if (!strcmp(pName, "vkGetSwapChainInfoWSI")) |
| 171 | return (void*) wsi_lunarg_GetSwapChainInfoWSI; |
| 172 | if (!strcmp(pName, "vkQueuePresentWSI")) |
| 173 | return (void*) wsi_lunarg_QueuePresentWSI; |
| 174 | |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | void *wsi_lunarg_GetDeviceProcAddr( |
| 179 | VkDevice device, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 180 | const char* name) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 181 | { |
| 182 | if (device == VK_NULL_HANDLE) |
| 183 | return NULL; |
| 184 | |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 185 | /* only handle device entrypoints that are loader special cases */ |
| 186 | if (!strcmp(name, "vkCreateSwapChainWSI")) |
| 187 | return (void*) wsi_lunarg_CreateSwapChainWSI; |
| 188 | |
| 189 | return NULL; |
| 190 | } |