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 */ |
Jon Ashburn | ba4a195 | 2015-06-16 12:44:51 -0600 | [diff] [blame^] | 36 | /* TODO make this a device extension with NO trampoline code */ |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 37 | |
| 38 | VkResult wsi_lunarg_CreateSwapChainWSI( |
| 39 | VkDevice device, |
| 40 | const VkSwapChainCreateInfoWSI* pCreateInfo, |
| 41 | VkSwapChainWSI* pSwapChain) |
| 42 | { |
| 43 | const VkLayerDispatchTable *disp; |
| 44 | VkResult res; |
| 45 | |
| 46 | disp = loader_get_dispatch(device); |
| 47 | |
| 48 | res = disp->CreateSwapChainWSI(device, pCreateInfo, pSwapChain); |
| 49 | if (res == VK_SUCCESS) { |
| 50 | loader_init_dispatch(*pSwapChain, disp); |
| 51 | } |
| 52 | |
| 53 | return res; |
| 54 | } |
| 55 | |
| 56 | VkResult wsi_lunarg_DestroySwapChainWSI( |
| 57 | VkSwapChainWSI swapChain) |
| 58 | { |
| 59 | const VkLayerDispatchTable *disp; |
| 60 | |
| 61 | disp = loader_get_dispatch(swapChain); |
| 62 | |
| 63 | return disp->DestroySwapChainWSI(swapChain); |
| 64 | } |
| 65 | |
| 66 | static VkResult wsi_lunarg_GetSwapChainInfoWSI( |
| 67 | VkSwapChainWSI swapChain, |
| 68 | VkSwapChainInfoTypeWSI infoType, |
| 69 | size_t* pDataSize, |
| 70 | void* pData) |
| 71 | { |
| 72 | const VkLayerDispatchTable *disp; |
| 73 | |
| 74 | disp = loader_get_dispatch(swapChain); |
| 75 | |
| 76 | return disp->GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData); |
| 77 | } |
| 78 | |
| 79 | static VkResult wsi_lunarg_QueuePresentWSI( |
| 80 | VkQueue queue, |
| 81 | const VkPresentInfoWSI* pPresentInfo) |
| 82 | { |
| 83 | const VkLayerDispatchTable *disp; |
| 84 | |
| 85 | disp = loader_get_dispatch(queue); |
| 86 | |
| 87 | return disp->QueuePresentWSI(queue, pPresentInfo); |
| 88 | } |
| 89 | |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 90 | /************ extension enablement ***************/ |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 91 | #define WSI_LUNARG_EXT_ARRAY_SIZE 1 |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 92 | static const struct loader_extension_property wsi_lunarg_extension_info = { |
| 93 | .info = { |
| 94 | .sType = VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES, |
| 95 | .name = VK_WSI_LUNARG_EXTENSION_NAME, |
| 96 | .version = VK_WSI_LUNARG_REVISION, |
| 97 | .description = "loader: LunarG WSI extension", |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 98 | }, |
| 99 | .origin = VK_EXTENSION_ORIGIN_LOADER, |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 100 | }; |
| 101 | |
Jon Ashburn | a445e09 | 2015-05-26 13:57:35 -0600 | [diff] [blame] | 102 | void wsi_lunarg_add_instance_extensions( |
| 103 | struct loader_extension_list *ext_list) |
| 104 | { |
| 105 | loader_add_to_ext_list(ext_list, 1, &wsi_lunarg_extension_info); |
| 106 | } |
| 107 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 108 | void wsi_lunarg_create_instance( |
| 109 | struct loader_instance *ptr_instance) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 110 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 111 | ptr_instance->wsi_lunarg_enabled = has_vk_extension_property( |
| 112 | &wsi_lunarg_extension_info.info, |
| 113 | &ptr_instance->enabled_instance_extensions); |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void *wsi_lunarg_GetInstanceProcAddr( |
| 117 | VkInstance instance, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 118 | const char* pName) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 119 | { |
| 120 | if (instance == VK_NULL_HANDLE) |
| 121 | return NULL; |
| 122 | |
Jon Ashburn | ba4a195 | 2015-06-16 12:44:51 -0600 | [diff] [blame^] | 123 | /* since one of these entrypoints must be loader handled will report all */ |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 124 | if (!strcmp(pName, "vkCreateSwapChainWSI")) |
| 125 | return (void*) wsi_lunarg_CreateSwapChainWSI; |
| 126 | if (!strcmp(pName, "vkDestroySwapChainWSI")) |
| 127 | return (void*) wsi_lunarg_DestroySwapChainWSI; |
| 128 | if (!strcmp(pName, "vkGetSwapChainInfoWSI")) |
| 129 | return (void*) wsi_lunarg_GetSwapChainInfoWSI; |
| 130 | if (!strcmp(pName, "vkQueuePresentWSI")) |
| 131 | return (void*) wsi_lunarg_QueuePresentWSI; |
| 132 | |
| 133 | return NULL; |
| 134 | } |
| 135 | |
| 136 | void *wsi_lunarg_GetDeviceProcAddr( |
| 137 | VkDevice device, |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 138 | const char* name) |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 139 | { |
| 140 | if (device == VK_NULL_HANDLE) |
| 141 | return NULL; |
| 142 | |
Jon Ashburn | cedc15f | 2015-05-21 18:13:33 -0600 | [diff] [blame] | 143 | /* only handle device entrypoints that are loader special cases */ |
| 144 | if (!strcmp(name, "vkCreateSwapChainWSI")) |
| 145 | return (void*) wsi_lunarg_CreateSwapChainWSI; |
| 146 | |
| 147 | return NULL; |
| 148 | } |