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> |
| 29 | |
| 30 | // Definitions for the VK_NV_external_memory_capabilities extension |
| 31 | |
| 32 | static const VkExtensionProperties |
| 33 | nv_external_memory_capabilities_extension_info = { |
| 34 | .extensionName = VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, |
| 35 | .specVersion = VK_NV_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION, |
| 36 | }; |
| 37 | |
| 38 | LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 39 | vkGetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 40 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 41 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 42 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 43 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
| 44 | |
| 45 | const VkLayerInstanceDispatchTable *disp; |
| 46 | VkPhysicalDevice unwrapped_phys_dev = |
| 47 | loader_unwrap_physical_device(physicalDevice); |
| 48 | disp = loader_get_instance_dispatch(physicalDevice); |
| 49 | |
| 50 | return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 51 | unwrapped_phys_dev, format, type, tiling, usage, flags, |
| 52 | externalHandleType, pExternalImageFormatProperties); |
| 53 | } |
| 54 | |
| 55 | VKAPI_ATTR VkResult VKAPI_CALL |
| 56 | terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 57 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 58 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 59 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 60 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 61 | struct loader_physical_device *phys_dev = |
| 62 | (struct loader_physical_device *)physicalDevice; |
| 63 | struct loader_icd *icd = phys_dev->this_icd; |
| 64 | |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame^] | 65 | if (!icd->GetPhysicalDeviceExternalImageFormatPropertiesNV) { |
| 66 | if (externalHandleType) { |
| 67 | return VK_ERROR_FORMAT_NOT_SUPPORTED; |
| 68 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 69 | |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame^] | 70 | if (!icd->GetPhysicalDeviceImageFormatProperties) { |
| 71 | return VK_ERROR_INITIALIZATION_FAILED; |
| 72 | } |
| 73 | |
| 74 | pExternalImageFormatProperties->externalMemoryFeatures = 0; |
| 75 | pExternalImageFormatProperties->exportFromImportedHandleTypes = 0; |
| 76 | pExternalImageFormatProperties->compatibleHandleTypes = 0; |
| 77 | |
| 78 | return icd->GetPhysicalDeviceImageFormatProperties( |
| 79 | phys_dev->phys_dev, format, type, tiling, usage, flags, |
| 80 | &pExternalImageFormatProperties->imageFormatProperties); |
| 81 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 82 | |
| 83 | return icd->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 84 | phys_dev->phys_dev, format, type, tiling, usage, flags, |
| 85 | externalHandleType, pExternalImageFormatProperties); |
| 86 | } |
| 87 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 88 | // Definitions for the VK_AMD_draw_indirect_count extension |
| 89 | |
| 90 | static const VkExtensionProperties amd_draw_indirect_count_extension_info = { |
| 91 | .extensionName = VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_EXTENSION_NAME, |
| 92 | .specVersion = VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_SPEC_VERSION, |
| 93 | }; |
| 94 | |
| 95 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD( |
| 96 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 97 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 98 | uint32_t stride) { |
| 99 | const VkLayerDispatchTable *disp; |
| 100 | |
| 101 | disp = loader_get_dispatch(commandBuffer); |
| 102 | disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, |
| 103 | countBufferOffset, maxDrawCount, stride); |
| 104 | } |
| 105 | |
| 106 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD( |
| 107 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 108 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 109 | uint32_t stride) { |
| 110 | const VkLayerDispatchTable *disp; |
| 111 | |
| 112 | disp = loader_get_dispatch(commandBuffer); |
| 113 | disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, |
| 114 | countBuffer, countBufferOffset, |
| 115 | maxDrawCount, stride); |
| 116 | } |
| 117 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 118 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 119 | |
| 120 | // Definitions for the VK_NV_external_memory_win32 extension |
| 121 | |
| 122 | static const VkExtensionProperties nv_external_memory_win32_extension_info = { |
| 123 | .extensionName = VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, |
| 124 | .specVersion = VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION, |
| 125 | }; |
| 126 | |
| 127 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( |
| 128 | VkDevice device, VkDeviceMemory memory, |
| 129 | VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) { |
| 130 | const VkLayerDispatchTable *disp; |
| 131 | |
| 132 | disp = loader_get_dispatch(device); |
| 133 | return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle); |
| 134 | } |
| 135 | |
| 136 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 137 | |
| 138 | // GPA helpers for non-KHR extensions |
| 139 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 140 | bool extension_instance_gpa(struct loader_instance *ptr_instance, |
| 141 | const char *name, void **addr) { |
| 142 | *addr = NULL; |
| 143 | |
| 144 | // Functions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 145 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 146 | if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) { |
| 147 | *addr = (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV; |
| 148 | return true; |
| 149 | } |
| 150 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 151 | // Functions for the VK_AMD_draw_indirect_count extension |
| 152 | |
| 153 | if (!strcmp("vkCmdDrawIndirectCountAMD", name)) { |
| 154 | *addr = (void *)vkCmdDrawIndirectCountAMD; |
| 155 | return true; |
| 156 | } |
| 157 | |
| 158 | if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) { |
| 159 | *addr = (void *)vkCmdDrawIndexedIndirectCountAMD; |
| 160 | return true; |
| 161 | } |
| 162 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 163 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 164 | |
| 165 | // Functions for the VK_NV_external_memory_win32 extension |
| 166 | |
| 167 | if (!strcmp("vkGetMemoryWin32HandleNV", name)) { |
| 168 | *addr = (void *)vkGetMemoryWin32HandleNV; |
| 169 | return true; |
| 170 | } |
| 171 | |
| 172 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 173 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 174 | return false; |
| 175 | } |
| 176 | |
| 177 | void extensions_create_instance(struct loader_instance *ptr_instance, |
| 178 | const VkInstanceCreateInfo *pCreateInfo) { |
| 179 | |
| 180 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 181 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 182 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) { |
| 183 | // Nothing to do; |
| 184 | return; |
| 185 | } |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 186 | |
| 187 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 188 | VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_EXTENSION_NAME) == 0) { |
| 189 | // Nothing to do; |
| 190 | return; |
| 191 | } |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 192 | |
| 193 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 194 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 195 | VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME) == 0) { |
| 196 | // Nothing to do; |
| 197 | return; |
| 198 | } |
| 199 | #endif // VK_USE_PLATFORM_WIN32_KHR |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 200 | } |
| 201 | } |