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); |
Mark Young | a095cca | 2016-12-02 15:02:52 -0700 | [diff] [blame] | 54 | if (NULL != icd_term && NULL != icd_term->DebugMarkerSetObjectTagEXT) { |
| 55 | // If this is a physical device, we have to replace it with the proper |
| 56 | // one for the next call. |
| 57 | if (pTagInfo->objectType == |
| 58 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 59 | struct loader_physical_device_term *phys_dev_term = |
| 60 | (struct loader_physical_device_term *)(uintptr_t) |
| 61 | pTagInfo->object; |
| 62 | pTagInfo->object = (uint64_t)(uintptr_t)phys_dev_term->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 63 | |
Mark Young | a095cca | 2016-12-02 15:02:52 -0700 | [diff] [blame] | 64 | // If this is a KHR_surface, and the ICD has created its own, we |
| 65 | // have to replace it with the proper one for the next call. |
| 66 | } else if (pTagInfo->objectType == |
| 67 | VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) { |
| 68 | if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) { |
| 69 | VkIcdSurface *icd_surface = |
| 70 | (VkIcdSurface *)(uintptr_t)pTagInfo->object; |
| 71 | if (NULL != icd_surface->real_icd_surfaces) { |
| 72 | pTagInfo->object = |
| 73 | (uint64_t)icd_surface->real_icd_surfaces[icd_index]; |
| 74 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
Mark Young | a095cca | 2016-12-02 15:02:52 -0700 | [diff] [blame] | 77 | return icd_term->DebugMarkerSetObjectTagEXT(device, pTagInfo); |
| 78 | } else { |
| 79 | return VK_SUCCESS; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 80 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT( |
| 84 | VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
| 85 | const VkLayerDispatchTable *disp = loader_get_dispatch(device); |
| 86 | // If this is a physical device, we have to replace it with the proper one |
| 87 | // for the next call. |
| 88 | if (pNameInfo->objectType == |
| 89 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 90 | struct loader_physical_device_tramp *phys_dev_tramp = |
Karl Schultz | 9497129 | 2016-11-19 09:02:27 -0700 | [diff] [blame] | 91 | (struct loader_physical_device_tramp *)(uintptr_t)pNameInfo->object; |
| 92 | pNameInfo->object = (uint64_t)(uintptr_t)phys_dev_tramp->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 93 | } |
| 94 | return disp->DebugMarkerSetObjectNameEXT(device, pNameInfo); |
| 95 | } |
| 96 | |
| 97 | VKAPI_ATTR VkResult VKAPI_CALL terminator_DebugMarkerSetObjectNameEXT( |
| 98 | VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) { |
| 99 | uint32_t icd_index = 0; |
| 100 | struct loader_device *dev; |
| 101 | struct loader_icd_term *icd_term = |
| 102 | loader_get_icd_and_device(device, &dev, &icd_index); |
Mark Young | a095cca | 2016-12-02 15:02:52 -0700 | [diff] [blame] | 103 | if (NULL != icd_term && NULL != icd_term->DebugMarkerSetObjectNameEXT) { |
| 104 | // If this is a physical device, we have to replace it with the proper |
| 105 | // one for the next call. |
| 106 | if (pNameInfo->objectType == |
| 107 | VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { |
| 108 | struct loader_physical_device_term *phys_dev_term = |
| 109 | (struct loader_physical_device_term *)(uintptr_t) |
| 110 | pNameInfo->object; |
| 111 | pNameInfo->object = (uint64_t)(uintptr_t)phys_dev_term->phys_dev; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 112 | |
Mark Young | a095cca | 2016-12-02 15:02:52 -0700 | [diff] [blame] | 113 | // If this is a KHR_surface, and the ICD has created its own, we |
| 114 | // have to replace it with the proper one for the next call. |
| 115 | } else if (pNameInfo->objectType == |
| 116 | VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) { |
| 117 | if (NULL != icd_term && NULL != icd_term->CreateSwapchainKHR) { |
| 118 | VkIcdSurface *icd_surface = |
| 119 | (VkIcdSurface *)(uintptr_t)pNameInfo->object; |
| 120 | if (NULL != icd_surface->real_icd_surfaces) { |
| 121 | pNameInfo->object = |
| 122 | (uint64_t)( |
| 123 | uintptr_t)icd_surface->real_icd_surfaces[icd_index]; |
| 124 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
Mark Young | a095cca | 2016-12-02 15:02:52 -0700 | [diff] [blame] | 127 | return icd_term->DebugMarkerSetObjectNameEXT(device, pNameInfo); |
| 128 | } else { |
| 129 | return VK_SUCCESS; |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 130 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 131 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 132 | |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 133 | // Definitions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 134 | |
| 135 | LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 136 | vkGetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 137 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 138 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 139 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 140 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 141 | const VkLayerInstanceDispatchTable *disp; |
| 142 | VkPhysicalDevice unwrapped_phys_dev = |
| 143 | loader_unwrap_physical_device(physicalDevice); |
| 144 | disp = loader_get_instance_dispatch(physicalDevice); |
| 145 | |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 146 | return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 147 | unwrapped_phys_dev, format, type, tiling, usage, flags, |
| 148 | externalHandleType, pExternalImageFormatProperties); |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | VKAPI_ATTR VkResult VKAPI_CALL |
| 152 | terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 153 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 154 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 155 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 156 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 157 | struct loader_physical_device_term *phys_dev_term = |
| 158 | (struct loader_physical_device_term *)physicalDevice; |
| 159 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 160 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 161 | if (!icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV) { |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 162 | if (externalHandleType) { |
| 163 | return VK_ERROR_FORMAT_NOT_SUPPORTED; |
| 164 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 165 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 166 | if (!icd_term->GetPhysicalDeviceImageFormatProperties) { |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 167 | return VK_ERROR_INITIALIZATION_FAILED; |
| 168 | } |
| 169 | |
| 170 | pExternalImageFormatProperties->externalMemoryFeatures = 0; |
| 171 | pExternalImageFormatProperties->exportFromImportedHandleTypes = 0; |
| 172 | pExternalImageFormatProperties->compatibleHandleTypes = 0; |
| 173 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 174 | return icd_term->GetPhysicalDeviceImageFormatProperties( |
| 175 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 176 | &pExternalImageFormatProperties->imageFormatProperties); |
| 177 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 178 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 179 | return icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 180 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 181 | externalHandleType, pExternalImageFormatProperties); |
| 182 | } |
| 183 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 184 | // Definitions for the VK_AMD_draw_indirect_count extension |
| 185 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 186 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD( |
| 187 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 188 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 189 | uint32_t stride) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 190 | const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer); |
| 191 | disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, |
| 192 | countBufferOffset, maxDrawCount, stride); |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD( |
| 196 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 197 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 198 | uint32_t stride) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 199 | const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer); |
| 200 | disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, |
| 201 | countBuffer, countBufferOffset, |
| 202 | maxDrawCount, stride); |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 203 | } |
| 204 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 205 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 206 | |
| 207 | // Definitions for the VK_NV_external_memory_win32 extension |
| 208 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 209 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( |
| 210 | VkDevice device, VkDeviceMemory memory, |
| 211 | VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 212 | const VkLayerDispatchTable *disp = loader_get_dispatch(device); |
| 213 | return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle); |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 217 | |
| 218 | // GPA helpers for non-KHR extensions |
| 219 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 220 | bool extension_instance_gpa(struct loader_instance *ptr_instance, |
| 221 | const char *name, void **addr) { |
| 222 | *addr = NULL; |
| 223 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 224 | // Definitions for the VK_EXT_debug_marker extension commands which |
| 225 | // need to have a terminator function. Since these are device |
| 226 | // commands, we always need to return a valid value for them. |
| 227 | |
| 228 | if (!strcmp("vkDebugMarkerSetObjectTagEXT", name)) { |
| 229 | *addr = (void *)vkDebugMarkerSetObjectTagEXT; |
| 230 | return true; |
| 231 | } |
| 232 | if (!strcmp("vkDebugMarkerSetObjectNameEXT", name)) { |
| 233 | *addr = (void *)vkDebugMarkerSetObjectNameEXT; |
| 234 | return true; |
| 235 | } |
| 236 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 237 | // Functions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 238 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 239 | if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 240 | *addr = (ptr_instance->enabled_known_extensions |
| 241 | .nv_external_memory_capabilities == 1) |
| 242 | ? (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV |
| 243 | : NULL; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 244 | return true; |
| 245 | } |
| 246 | |
Mark Young | 3ea0ff5 | 2016-09-09 07:26:48 -0600 | [diff] [blame] | 247 | // Functions for the VK_AMD_draw_indirect_count extension |
| 248 | |
| 249 | if (!strcmp("vkCmdDrawIndirectCountAMD", name)) { |
| 250 | *addr = (void *)vkCmdDrawIndirectCountAMD; |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) { |
| 255 | *addr = (void *)vkCmdDrawIndexedIndirectCountAMD; |
| 256 | return true; |
| 257 | } |
| 258 | |
| 259 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 260 | |
| 261 | // Functions for the VK_NV_external_memory_win32 extension |
| 262 | |
| 263 | if (!strcmp("vkGetMemoryWin32HandleNV", name)) { |
| 264 | *addr = (void *)vkGetMemoryWin32HandleNV; |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 269 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 270 | return false; |
| 271 | } |
| 272 | |
| 273 | void extensions_create_instance(struct loader_instance *ptr_instance, |
| 274 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 275 | ptr_instance->enabled_known_extensions.nv_external_memory_capabilities = 0; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 276 | |
| 277 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 278 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 279 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 280 | ptr_instance->enabled_known_extensions |
| 281 | .nv_external_memory_capabilities = 1; |
| 282 | return; |
| 283 | } |
| 284 | } |
| 285 | } |