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) { |
| 61 | |
| 62 | struct loader_physical_device *phys_dev = |
| 63 | (struct loader_physical_device *)physicalDevice; |
| 64 | struct loader_icd *icd = phys_dev->this_icd; |
| 65 | |
| 66 | assert(icd->GetPhysicalDeviceExternalImageFormatPropertiesNV && |
| 67 | "loader: null GetPhysicalDeviceExternalImageFormatPropertiesNV ICD " |
| 68 | "pointer"); |
| 69 | |
| 70 | if (!icd->GetPhysicalDeviceExternalImageFormatPropertiesNV) |
| 71 | return VK_ERROR_INITIALIZATION_FAILED; |
| 72 | |
| 73 | return icd->GetPhysicalDeviceExternalImageFormatPropertiesNV( |
| 74 | phys_dev->phys_dev, format, type, tiling, usage, flags, |
| 75 | externalHandleType, pExternalImageFormatProperties); |
| 76 | } |
| 77 | |
| 78 | bool extension_instance_gpa(struct loader_instance *ptr_instance, |
| 79 | const char *name, void **addr) { |
| 80 | *addr = NULL; |
| 81 | |
| 82 | // Functions for the VK_NV_external_memory_capabilities extension |
| 83 | if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) { |
| 84 | *addr = (void *)vkGetPhysicalDeviceExternalImageFormatPropertiesNV; |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | void extensions_create_instance(struct loader_instance *ptr_instance, |
| 92 | const VkInstanceCreateInfo *pCreateInfo) { |
| 93 | |
| 94 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 95 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], |
| 96 | VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME) == 0) { |
| 97 | // Nothing to do; |
| 98 | return; |
| 99 | } |
| 100 | } |
| 101 | } |