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; |
| 43 | |
| 44 | disp = loader_get_instance_dispatch(display); |
| 45 | |
| 46 | return disp->GetDisplayInfoWSI(display, infoType, pDataSize, pData); |
| 47 | } |
| 48 | |
| 49 | VkResult wsi_lunarg_CreateSwapChainWSI( |
| 50 | VkDevice device, |
| 51 | const VkSwapChainCreateInfoWSI* pCreateInfo, |
| 52 | VkSwapChainWSI* pSwapChain) |
| 53 | { |
| 54 | const VkLayerDispatchTable *disp; |
| 55 | VkResult res; |
| 56 | |
| 57 | disp = loader_get_dispatch(device); |
| 58 | |
| 59 | res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain); |
| 60 | if (res == VK_SUCCESS) { |
| 61 | loader_init_dispatch(*pSwapChain, disp); |
| 62 | } |
| 63 | |
| 64 | return res; |
| 65 | } |
| 66 | |
| 67 | VkResult wsi_lunarg_DestroySwapChainWSI( |
| 68 | VkSwapChainWSI swapChain) |
| 69 | { |
| 70 | const VkLayerDispatchTable *disp; |
| 71 | |
| 72 | disp = loader_get_dispatch(swapChain); |
| 73 | |
| 74 | return disp->DestroySwapChainWSI(swapChain); |
| 75 | } |
| 76 | |
| 77 | static VkResult wsi_lunarg_GetSwapChainInfoWSI( |
| 78 | VkSwapChainWSI swapChain, |
| 79 | VkSwapChainInfoTypeWSI infoType, |
| 80 | size_t* pDataSize, |
| 81 | void* pData) |
| 82 | { |
| 83 | const VkLayerDispatchTable *disp; |
| 84 | |
| 85 | disp = loader_get_dispatch(swapChain); |
| 86 | |
| 87 | return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData); |
| 88 | } |
| 89 | |
| 90 | static VkResult wsi_lunarg_QueuePresentWSI( |
| 91 | VkQueue queue, |
| 92 | const VkPresentInfoWSI* pPresentInfo) |
| 93 | { |
| 94 | const VkLayerDispatchTable *disp; |
| 95 | |
| 96 | disp = loader_get_dispatch(queue); |
| 97 | |
| 98 | return disp->QueuePresentWSI(queue, pPresentInfo); |
| 99 | } |
| 100 | |
| 101 | /************ loader instance chain termination entrypoints ***************/ |
| 102 | VkResult loader_GetDisplayInfoWSI( |
| 103 | VkDisplayWSI display, |
| 104 | VkDisplayInfoTypeWSI infoType, |
| 105 | size_t* pDataSize, |
| 106 | void* pData) |
| 107 | { |
Courtney Goeltzenleuchter | 5c55b35 | 2015-06-10 17:52:04 -0600 | [diff] [blame] | 108 | /* 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] | 109 | // uint32_t gpu_index; |
| 110 | // 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] | 111 | VkResult res = VK_ERROR_INITIALIZATION_FAILED; |
| 112 | |
Courtney Goeltzenleuchter | ac13c6f | 2015-06-10 20:39:06 -0600 | [diff] [blame] | 113 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 114 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 115 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 116 | if (icd->GetDisplayInfoWSI) |
| 117 | res = icd->GetDisplayInfoWSI(display, infoType, pDataSize, pData); |
| 118 | } |
| 119 | } |
| 120 | } |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 121 | |
| 122 | return res; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /************ extension enablement ***************/ |
| 127 | static bool wsi_enabled = false; |
| 128 | |
| 129 | struct ext_props { |
| 130 | uint32_t version; |
| 131 | const char * const name; |
| 132 | }; |
| 133 | |
| 134 | #define WSI_LUNARG_EXT_ARRAY_SIZE 1 |
| 135 | static const struct ext_props wsi_lunarg_exts[WSI_LUNARG_EXT_ARRAY_SIZE] = { |
| 136 | {VK_WSI_LUNARG_REVISION, VK_WSI_LUNARG_EXTENSION_NAME}, |
| 137 | }; |
| 138 | |
| 139 | void wsi_lunarg_register_extensions( |
| 140 | const VkInstanceCreateInfo* pCreateInfo) |
| 141 | { |
| 142 | uint32_t i, ext_idx; |
| 143 | |
| 144 | for (i = 0; i < pCreateInfo->extensionCount; i++) { |
| 145 | for (ext_idx = 0; ext_idx < WSI_LUNARG_EXT_ARRAY_SIZE; ext_idx++) { |
| 146 | /* TODO: Should we include version number as well as extension name? */ |
| 147 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], wsi_lunarg_exts[ext_idx].name) == 0) { |
| 148 | /* Found a matching extension name, mark it enabled */ |
| 149 | wsi_enabled = true; |
| 150 | } |
| 151 | |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | } |
| 156 | |
| 157 | void *wsi_lunarg_GetInstanceProcAddr( |
| 158 | VkInstance instance, |
Jon Ashburn | d763c93 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 159 | const char* pName, |
| 160 | bool *enabled) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 161 | { |
| 162 | if (instance == VK_NULL_HANDLE) |
| 163 | return NULL; |
| 164 | |
Jon Ashburn | d763c93 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 165 | *enabled = wsi_enabled; |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 166 | |
| 167 | /* since two of these entrypoints must be loader handled will report all */ |
| 168 | if (!strcmp(pName, "vkGetDisplayInfoWSI")) |
| 169 | return (void*) wsi_lunarg_GetDisplayInfoWSI; |
| 170 | if (!strcmp(pName, "vkCreateSwapChainWSI")) |
| 171 | return (void*) wsi_lunarg_CreateSwapChainWSI; |
| 172 | if (!strcmp(pName, "vkDestroySwapChainWSI")) |
| 173 | return (void*) wsi_lunarg_DestroySwapChainWSI; |
| 174 | if (!strcmp(pName, "vkGetSwapChainInfoWSI")) |
| 175 | return (void*) wsi_lunarg_GetSwapChainInfoWSI; |
| 176 | if (!strcmp(pName, "vkQueuePresentWSI")) |
| 177 | return (void*) wsi_lunarg_QueuePresentWSI; |
| 178 | |
| 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | void *wsi_lunarg_GetDeviceProcAddr( |
| 183 | VkDevice device, |
Jon Ashburn | d763c93 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 184 | const char* name, |
| 185 | bool *enabled) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 186 | { |
| 187 | if (device == VK_NULL_HANDLE) |
| 188 | return NULL; |
| 189 | |
Jon Ashburn | d763c93 | 2015-05-22 09:51:03 -0600 | [diff] [blame] | 190 | *enabled = wsi_enabled; |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 191 | |
| 192 | /* only handle device entrypoints that are loader special cases */ |
| 193 | if (!strcmp(name, "vkCreateSwapChainWSI")) |
| 194 | return (void*) wsi_lunarg_CreateSwapChainWSI; |
| 195 | |
| 196 | return NULL; |
| 197 | } |