Branch data Line data Source code
1 : : /* 2 : : * This file is part of libplacebo. 3 : : * 4 : : * libplacebo is free software; you can redistribute it and/or 5 : : * modify it under the terms of the GNU Lesser General Public 6 : : * License as published by the Free Software Foundation; either 7 : : * version 2.1 of the License, or (at your option) any later version. 8 : : * 9 : : * libplacebo is distributed in the hope that it will be useful, 10 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : : * GNU Lesser General Public License for more details. 13 : : * 14 : : * You should have received a copy of the GNU Lesser General Public 15 : : * License along with libplacebo. If not, see <http://www.gnu.org/licenses/>. 16 : : */ 17 : : 18 : : #include "utils.h" 19 : : 20 : : VkExternalMemoryHandleTypeFlagBitsKHR 21 : 752 : vk_mem_handle_type(enum pl_handle_type handle_type) 22 : : { 23 [ + + ]: 752 : if (!handle_type) 24 : : return 0; 25 : : 26 [ - - + + : 124 : switch (handle_type) { - - + ] 27 : : case PL_HANDLE_FD: 28 : : return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; 29 : 0 : case PL_HANDLE_WIN32: 30 : 0 : return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR; 31 : 0 : case PL_HANDLE_WIN32_KMT: 32 : 0 : return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR; 33 : 50 : case PL_HANDLE_DMA_BUF: 34 : 50 : return VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT; 35 : 38 : case PL_HANDLE_HOST_PTR: 36 : 38 : return VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT; 37 : : case PL_HANDLE_MTL_TEX: 38 : : case PL_HANDLE_IOSURFACE: 39 : : return 0; 40 : : } 41 : : 42 : 0 : pl_unreachable(); 43 : : } 44 : : 45 : : VkExternalSemaphoreHandleTypeFlagBitsKHR 46 : 7 : vk_sync_handle_type(enum pl_handle_type handle_type) 47 : : { 48 [ + + ]: 7 : if (!handle_type) 49 : : return 0; 50 : : 51 [ - - - - : 3 : switch (handle_type) { + ] 52 : : case PL_HANDLE_FD: 53 : : return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; 54 : 0 : case PL_HANDLE_WIN32: 55 : 0 : return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR; 56 : 0 : case PL_HANDLE_WIN32_KMT: 57 : 0 : return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR; 58 : : case PL_HANDLE_DMA_BUF: 59 : : case PL_HANDLE_HOST_PTR: 60 : : case PL_HANDLE_MTL_TEX: 61 : : case PL_HANDLE_IOSURFACE: 62 : : return 0; 63 : : } 64 : : 65 : 0 : pl_unreachable(); 66 : : } 67 : : 68 : 42 : bool vk_external_mem_check(struct vk_ctx *vk, 69 : : const VkExternalMemoryPropertiesKHR *props, 70 : : enum pl_handle_type handle_type, 71 : : bool import) 72 : : { 73 : 42 : VkExternalMemoryFeatureFlagsKHR flags = props->externalMemoryFeatures; 74 : 42 : VkExternalMemoryHandleTypeFlagBitsKHR vk_handle = vk_mem_handle_type(handle_type); 75 : : 76 [ + + ]: 42 : if (import) { 77 [ - + ]: 17 : if (!(flags & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR)) { 78 : 0 : PL_DEBUG(vk, "Handle type %s (0x%x) is not importable", 79 : : vk_handle_name(vk_handle), (unsigned int) handle_type); 80 : 0 : return false; 81 : : } 82 : : } else { 83 [ + + ]: 25 : if (!(flags & VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR)) { 84 : 3 : PL_DEBUG(vk, "Handle type %s (0x%x) is not exportable", 85 : : vk_handle_name(vk_handle), (unsigned int) handle_type); 86 : 3 : return false; 87 : : } 88 : : } 89 : : 90 : : return true; 91 : : } 92 : : 93 : : const enum pl_handle_type vk_mem_handle_list[] = { 94 : : PL_HANDLE_HOST_PTR, 95 : : #ifdef PL_HAVE_UNIX 96 : : PL_HANDLE_FD, 97 : : PL_HANDLE_DMA_BUF, 98 : : #endif 99 : : #ifdef PL_HAVE_WIN32 100 : : PL_HANDLE_WIN32, 101 : : PL_HANDLE_WIN32_KMT, 102 : : #endif 103 : : 0 104 : : }; 105 : : 106 : : const enum pl_handle_type vk_sync_handle_list[] = { 107 : : #ifdef PL_HAVE_UNIX 108 : : PL_HANDLE_FD, 109 : : #endif 110 : : #ifdef PL_HAVE_WIN32 111 : : PL_HANDLE_WIN32, 112 : : PL_HANDLE_WIN32_KMT, 113 : : #endif 114 : : 0 115 : : }; 116 : : 117 : 17 : const void *vk_find_struct(const void *chain, VkStructureType stype) 118 : : { 119 : : const VkBaseInStructure *in = chain; 120 [ + + ]: 61 : while (in) { 121 [ + + ]: 59 : if (in->sType == stype) 122 : 15 : return in; 123 : : 124 : 44 : in = in->pNext; 125 : : } 126 : : 127 : : return NULL; 128 : : } 129 : : 130 : 48 : void vk_link_struct(void *chain, const void *in) 131 : : { 132 [ + - ]: 48 : if (!in) 133 : : return; 134 : : 135 : : VkBaseOutStructure *out = chain; 136 [ + + ]: 61 : while (out->pNext) 137 : : out = out->pNext; 138 : : 139 : 48 : out->pNext = (void *) in; 140 : : } 141 : : 142 : 8 : void *vk_struct_memdup(void *alloc, const void *pin) 143 : : { 144 [ + - ]: 8 : if (!pin) 145 : : return NULL; 146 : : 147 : : const VkBaseInStructure *in = pin; 148 : 8 : size_t size = vk_struct_size(in->sType); 149 [ - + ]: 8 : pl_assert(size); 150 : : 151 : 8 : VkBaseOutStructure *out = pl_memdup(alloc, in, size); 152 : 8 : out->pNext = NULL; 153 : 8 : return out; 154 : : } 155 : : 156 : 10 : void *vk_chain_memdup(void *alloc, const void *pin) 157 : : { 158 [ + + ]: 10 : if (!pin) 159 : : return NULL; 160 : : 161 : : const VkBaseInStructure *in = pin; 162 : 8 : VkBaseOutStructure *out = vk_struct_memdup(alloc, in); 163 [ - + ]: 8 : pl_assert(out); 164 : : 165 : 8 : out->pNext = vk_chain_memdup(alloc, in->pNext); 166 : 8 : return out; 167 : : } 168 : : 169 : 99 : void *vk_chain_alloc(void *alloc, void *chain, VkStructureType stype) 170 : : { 171 : : for (VkBaseOutStructure *out = chain;; out = out->pNext) { 172 [ + + ]: 393 : if (out->sType == stype) 173 : 71 : return out; 174 [ + + ]: 322 : if (!out->pNext) { 175 : 28 : VkBaseOutStructure *s = pl_zalloc(alloc, vk_struct_size(stype)); 176 : 28 : s->sType = stype; 177 : 28 : out->pNext = s; 178 : 28 : return s; 179 : : } 180 : : } 181 : : }