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