Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2016 Valve Corporation |
| 4 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 19 | */ |
| 20 | |
| 21 | #define _GNU_SOURCE |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include "vk_loader_platform.h" |
| 26 | #include "loader.h" |
| 27 | #include "extensions.h" |
| 28 | #include <vulkan/vk_icd.h> |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 29 | #include "wsi.h" |
| 30 | |
| 31 | // Definitions for the VK_EXT_debug_marker extension commands which |
| 32 | // need to have a terminator function |
| 33 | |
| 34 | VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectTagEXT( |
| 35 | VkDevice device, VkDebugMarkerObjectTagInfoEXT *pTagInfo) { |
| 36 | const VkLayerDispatchTable *disp = loader_get_dispatch(device); |
| 37 | // If this is a physical device, we have to replace it with the proper one |
| 38 | // for the next call. |
| 39 | if (pTagInfo->objectType == |
| 40 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 41 | struct loader_physical_device_tramp *phys_dev_tramp = |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 42 | (struct loader_physical_device_tramp *)(uintptr_t)pTagInfo->object; |
| 43 | pTagInfo->object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 44 | } |
| 45 | return disp->DebugMarkerSetObjectTagEXT(device, pTagInfo); |
| 46 | } |
| 47 | |
| 48 | VKAPI_ATTR VkResult VKAPI_CALL terminator_DebugMarkerSetObjectTagEXT( |
| 49 | VkDevice device, VkDebugMarkerObjectTagInfoEXT *pTagInfo) { |
| 50 | uint32_t icd_index = 0; |
| 51 | struct loader_device *dev; |
| 52 | struct loader_icd_term *icd_term = |
| 53 | loader_get_icd_and_device(device, &dev, &icd_index); |
| 54 | // If this is a physical device, we have to replace it with the proper one |
| 55 | // for the next call. |
| 56 | if (pTagInfo->objectType == |
| 57 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 58 | struct loader_physical_device_term *phys_dev_term = |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 59 | (struct loader_physical_device_term *)(uintptr_t)pTagInfo->object; |
| 60 | pTagInfo->object = (uint64_t)(uintptr_t)phys_dev_term->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 61 | |
| 62 | // If this is a KHR_surface, and the ICD has created its own, we have to |
| 63 | // replace it with the proper one for the next call. |
| 64 | } else if (pTagInfo->objectType == |
| 65 | VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) { |
| 66 | if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) { |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 67 | VkIcdSurface *icd_surface = |
| 68 | (VkIcdSurface *)(uintptr_t)pTagInfo->object; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 69 | if (NULL != icd_surface->real_icd_surfaces) { |
| 70 | pTagInfo->object = |
| 71 | (uint64_t)icd_surface->real_icd_surfaces[icd_index]; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | assert(icd_term != NULL && icd_term->DebugMarkerSetObjectTagEXT && |
| 76 | "loader: null DebugMarkerSetObjectTagEXT ICD pointer"); |
| 77 | return icd_term->DebugMarkerSetObjectTagEXT(device, pTagInfo); |
| 78 | } |
| 79 | |
| 80 | VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT( |
| 81 | VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
| 82 | const VkLayerDispatchTable *disp = loader_get_dispatch(device); |
| 83 | // If this is a physical device, we have to replace it with the proper one |
| 84 | // for the next call. |
| 85 | if (pNameInfo->objectType == |
| 86 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 87 | struct loader_physical_device_tramp *phys_dev_tramp = |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 88 | (struct loader_physical_device_tramp *)(uintptr_t)pNameInfo->object; |
| 89 | pNameInfo->object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 90 | } |
| 91 | return disp->DebugMarkerSetObjectNameEXT(device, pNameInfo); |
| 92 | } |
| 93 | |
| 94 | VKAPI_ATTR VkResult VKAPI_CALL terminator_DebugMarkerSetObjectNameEXT( |
| 95 | VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
| 96 | uint32_t icd_index = 0; |
| 97 | struct loader_device *dev; |
| 98 | struct loader_icd_term *icd_term = |
| 99 | loader_get_icd_and_device(device, &dev, &icd_index); |
| 100 | // If this is a physical device, we have to replace it with the proper one |
| 101 | // for the next call. |
| 102 | if (pNameInfo->objectType == |
| 103 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 104 | struct loader_physical_device_term *phys_dev_term = |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 105 | (struct loader_physical_device_term *)(uintptr_t)pNameInfo->object; |
| 106 | pNameInfo->object = (uint64_t)(uintptr_t)phys_dev_term->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 107 | |
| 108 | // If this is a KHR_surface, and the ICD has created its own, we have to |
| 109 | // replace it with the proper one for the next call. |
| 110 | } else if (pNameInfo->objectType == |
| 111 | VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) { |
| 112 | if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) { |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 113 | VkIcdSurface *icd_surface = |
| 114 | (VkIcdSurface *)(uintptr_t)pNameInfo->object; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 115 | if (NULL != icd_surface->real_icd_surfaces) { |
| 116 | pNameInfo->object = |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame^] | 117 | (uint64_t)( |
| 118 | uintptr_t)icd_surface->real_icd_surfaces[icd_index]; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | } |
| 122 | assert(icd_term != NULL && icd_term->DebugMarkerSetObjectNameEXT && |
| 123 | "loader: null DebugMarkerSetObjectNameEXT ICD pointer"); |
| 124 | return icd_term->DebugMarkerSetObjectNameEXT(device, pNameInfo); |
| 125 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 126 | |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 127 | // Definitions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 128 | |
| 129 | LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 130 | vkGetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 131 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 132 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 133 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 134 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 135 | const VkLayerInstanceDispatchTable *disp; |
| 136 | VkPhysicalDevice unwrapped_phys_dev = |
| 137 | loader_unwrap_physical_device(physicalDevice); |
| 138 | disp = loader_get_instance_dispatch(physicalDevice); |
| 139 | |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 140 | return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 141 | unwrapped_phys_dev, format, type, tiling, usage, flags, |
| 142 | externalHandleType, pExternalImageFormatProperties); |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | VKAPI_ATTR VkResult VKAPI_CALL |
| 146 | terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 147 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 148 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 149 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 150 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 151 | struct loader_physical_device_term *phys_dev_term = |
| 152 | (struct loader_physical_device_term *)physicalDevice; |
| 153 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 154 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 155 | if (!icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV) { |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 156 | if (externalHandleType) { |
| 157 | return VK_ERROR_FORMAT_NOT_SUPPORTED; |
| 158 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 159 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 160 | if (!icd_term->GetPhysicalDeviceImageFormatProperties) { |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 161 | return VK_ERROR_INITIALIZATION_FAILED; |
| 162 | } |
| 163 | |
| 164 | pExternalImageFormatProperties->externalMemoryFeatures = 0; |
| 165 | pExternalImageFormatProperties->exportFromImportedHandleTypes = 0; |
| 166 | pExternalImageFormatProperties->compatibleHandleTypes = 0; |
| 167 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 168 | return icd_term->GetPhysicalDeviceImageFormatProperties( |
| 169 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 170 | &pExternalImageFormatProperties->imageFormatProperties); |
| 171 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 172 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 173 | return icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 174 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 175 | externalHandleType, pExternalImageFormatProperties); |
| 176 | } |
| 177 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 178 | // Definitions for the VK_AMD_draw_indirect_count extension |
| 179 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 180 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD( |
| 181 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 182 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 183 | uint32_t stride) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 184 | const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer); |
| 185 | disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, |
| 186 | countBufferOffset, maxDrawCount, stride); |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD( |
| 190 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 191 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 192 | uint32_t stride) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 193 | const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer); |
| 194 | disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, |
| 195 | countBuffer, countBufferOffset, |
| 196 | maxDrawCount, stride); |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 197 | } |
| 198 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 199 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 200 | |
| 201 | // Definitions for the VK_NV_external_memory_win32 extension |
| 202 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 203 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( |
| 204 | VkDevice device, VkDeviceMemory memory, |
| 205 | VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 206 | const VkLayerDispatchTable *disp = loader_get_dispatch(device); |
| 207 | return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle); |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 211 | |
| 212 | // GPA helpers for non-KHR extensions |
| 213 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 214 | bool extension_instance_gpa(struct loader_instance *ptr_instance, |
| 215 | const char *name, void **addr) { |
| 216 | *addr = NULL; |
| 217 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 218 | // Definitions for the VK_EXT_debug_marker extension commands which |
| 219 | // need to have a terminator function. Since these are device |
| 220 | // commands, we always need to return a valid value for them. |
| 221 | |
| 222 | if (!strcmp("vkDebugMarkerSetObjectTagEXT", name)) { |
| 223 | *addr = (void *)vkDebugMarkerSetObjectTagEXT; |
| 224 | return true; |
| 225 | } |
| 226 | if (!strcmp("vkDebugMarkerSetObjectNameEXT", name)) { |
| 227 | *addr = (void *)vkDebugMarkerSetObjectNameEXT; |
| 228 | return true; |
| 229 | } |
| 230 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 231 | // Functions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 232 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 233 | if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 234 | *addr = (ptr_instance->enabled_known_extensions |
| 235 | .nv_external_memory_capabilities == 1) |
| 236 | ? (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV |
| 237 | : NULL; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 238 | return true; |
| 239 | } |
| 240 | |
Mark Young | 3ea0ff5 | 2016-09-09 07:26:48 -0600 | [diff] [blame] | 241 | // Functions for the VK_AMD_draw_indirect_count extension |
| 242 | |
| 243 | if (!strcmp("vkCmdDrawIndirectCountAMD", name)) { |
| 244 | *addr = (void *)vkCmdDrawIndirectCountAMD; |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) { |
| 249 | *addr = (void *)vkCmdDrawIndexedIndirectCountAMD; |
| 250 | return true; |
| 251 | } |
| 252 | |
| 253 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 254 | |
| 255 | // Functions for the VK_NV_external_memory_win32 extension |
| 256 | |
| 257 | if (!strcmp("vkGetMemoryWin32HandleNV", name)) { |
| 258 | *addr = (void *)vkGetMemoryWin32HandleNV; |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 263 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 264 | return false; |
| 265 | } |
| 266 | |
| 267 | void extensions_create_instance(struct loader_instance *ptr_instance, |
| 268 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 269 | ptr_instance->enabled_known_extensions.nv_external_memory_capabilities = 0; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 270 | |
| 271 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 272 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 273 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 274 | ptr_instance->enabled_known_extensions |
| 275 | .nv_external_memory_capabilities = 1; |
| 276 | return; |
| 277 | } |
| 278 | } |
| 279 | } |