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 | |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 30 | // Definitions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 31 | |
| 32 | LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL |
| 33 | vkGetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 34 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 35 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 36 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 37 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 38 | const VkLayerInstanceDispatchTable *disp; |
| 39 | VkPhysicalDevice unwrapped_phys_dev = |
| 40 | loader_unwrap_physical_device(physicalDevice); |
| 41 | disp = loader_get_instance_dispatch(physicalDevice); |
| 42 | |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 43 | return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 44 | unwrapped_phys_dev, format, type, tiling, usage, flags, |
| 45 | externalHandleType, pExternalImageFormatProperties); |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | VKAPI_ATTR VkResult VKAPI_CALL |
| 49 | terminator_GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 50 | VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, |
| 51 | VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 52 | VkExternalMemoryHandleTypeFlagsNV externalHandleType, |
| 53 | VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame^] | 54 | struct loader_physical_device_term *phys_dev_term = |
| 55 | (struct loader_physical_device_term *)physicalDevice; |
| 56 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 57 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame^] | 58 | if (!icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV) { |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 59 | if (externalHandleType) { |
| 60 | return VK_ERROR_FORMAT_NOT_SUPPORTED; |
| 61 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 62 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame^] | 63 | if (!icd_term->GetPhysicalDeviceImageFormatProperties) { |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 64 | return VK_ERROR_INITIALIZATION_FAILED; |
| 65 | } |
| 66 | |
| 67 | pExternalImageFormatProperties->externalMemoryFeatures = 0; |
| 68 | pExternalImageFormatProperties->exportFromImportedHandleTypes = 0; |
| 69 | pExternalImageFormatProperties->compatibleHandleTypes = 0; |
| 70 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame^] | 71 | return icd_term->GetPhysicalDeviceImageFormatProperties( |
| 72 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
James Jones | 389dc0c | 2016-08-18 23:41:19 +0100 | [diff] [blame] | 73 | &pExternalImageFormatProperties->imageFormatProperties); |
| 74 | } |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 75 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame^] | 76 | return icd_term->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 77 | phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 78 | externalHandleType, pExternalImageFormatProperties); |
| 79 | } |
| 80 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 81 | // Definitions for the VK_AMD_draw_indirect_count extension |
| 82 | |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 83 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD( |
| 84 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 85 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 86 | uint32_t stride) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 87 | const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer); |
| 88 | disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer, |
| 89 | countBufferOffset, maxDrawCount, stride); |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD( |
| 93 | VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, |
| 94 | VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, |
| 95 | uint32_t stride) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 96 | const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer); |
| 97 | disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset, |
| 98 | countBuffer, countBufferOffset, |
| 99 | maxDrawCount, stride); |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 100 | } |
| 101 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 102 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 103 | |
| 104 | // Definitions for the VK_NV_external_memory_win32 extension |
| 105 | |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 106 | VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( |
| 107 | VkDevice device, VkDeviceMemory memory, |
| 108 | VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) { |
Mark Young | 5210abc | 2016-09-08 18:36:32 -0600 | [diff] [blame] | 109 | const VkLayerDispatchTable *disp = loader_get_dispatch(device); |
| 110 | return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle); |
Mark Lobodzinski | 5f20852 | 2016-08-29 15:36:23 -0600 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 114 | |
| 115 | // GPA helpers for non-KHR extensions |
| 116 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 117 | bool extension_instance_gpa(struct loader_instance *ptr_instance, |
| 118 | const char *name, void **addr) { |
| 119 | *addr = NULL; |
| 120 | |
| 121 | // Functions for the VK_NV_external_memory_capabilities extension |
Mark Lobodzinski | 0853ad5 | 2016-08-29 14:54:34 -0600 | [diff] [blame] | 122 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 123 | if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 124 | *addr = (ptr_instance->enabled_known_extensions |
| 125 | .nv_external_memory_capabilities == 1) |
| 126 | ? (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV |
| 127 | : NULL; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 128 | return true; |
| 129 | } |
| 130 | |
Mark Young | 3ea0ff5 | 2016-09-09 07:26:48 -0600 | [diff] [blame] | 131 | // Functions for the VK_AMD_draw_indirect_count extension |
| 132 | |
| 133 | if (!strcmp("vkCmdDrawIndirectCountAMD", name)) { |
| 134 | *addr = (void *)vkCmdDrawIndirectCountAMD; |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) { |
| 139 | *addr = (void *)vkCmdDrawIndexedIndirectCountAMD; |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 144 | |
| 145 | // Functions for the VK_NV_external_memory_win32 extension |
| 146 | |
| 147 | if (!strcmp("vkGetMemoryWin32HandleNV", name)) { |
| 148 | *addr = (void *)vkGetMemoryWin32HandleNV; |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | #endif // VK_USE_PLATFORM_WIN32_KHR |
| 153 | |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 154 | return false; |
| 155 | } |
| 156 | |
| 157 | void extensions_create_instance(struct loader_instance *ptr_instance, |
| 158 | const VkInstanceCreateInfo *pCreateInfo) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 159 | ptr_instance->enabled_known_extensions.nv_external_memory_capabilities = 0; |
Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 160 | |
| 161 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 162 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 163 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) { |
Mark Young | 35159af | 2016-09-07 08:50:32 -0600 | [diff] [blame] | 164 | ptr_instance->enabled_known_extensions |
| 165 | .nv_external_memory_capabilities = 1; |
| 166 | return; |
| 167 | } |
| 168 | } |
| 169 | } |