Mark Lobodzinski | 317574e | 2016-08-29 14:21:14 -0600 | [diff] [blame] | 1 | /* |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 2 | * |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018 The Khronos Group Inc. |
| 4 | * Copyright (c) 2014-2018 Valve Corporation |
| 5 | * Copyright (c) 2014-2018 LunarG, Inc. |
Courtney Goeltzenleuchter | f821dad | 2015-12-02 14:53:22 -0700 | [diff] [blame] | 6 | * Copyright (C) 2015 Google Inc. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 7 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 13 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 20 | * |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 21 | * Author: Jon Ashburn <jon@lunarg.com> |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 22 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 23 | * Author: Mark Young <marky@lunarg.com> |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 24 | * Author: Lenny Komow <lenny@lunarg.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 25 | * |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 26 | */ |
Mark Lobodzinski | faa9081 | 2015-11-25 13:26:15 -0700 | [diff] [blame] | 27 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 28 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <stdarg.h> |
| 32 | #include <stdbool.h> |
| 33 | #include <string.h> |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 34 | #include <stddef.h> |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 35 | #if defined(__APPLE__) |
| 36 | #include <CoreFoundation/CoreFoundation.h> |
| 37 | #include <sys/param.h> |
| 38 | #endif |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 39 | #include <sys/types.h> |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 40 | #if defined(_WIN32) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 41 | #include "dirent_on_windows.h" |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 42 | #else // _WIN32 |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 43 | #include <dirent.h> |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 44 | #endif // _WIN32 |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 45 | #include "vk_loader_platform.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 46 | #include "loader.h" |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 47 | #include "gpa_helper.h" |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 48 | #include "debug_utils.h" |
Ian Elliott | 954fa34 | 2015-10-30 15:28:23 -0600 | [diff] [blame] | 49 | #include "wsi.h" |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 50 | #include "vulkan/vk_icd.h" |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 51 | #include "cJSON.h" |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 52 | #include "murmurhash.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 53 | |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 54 | #if defined(_WIN32) |
| 55 | #include <Cfgmgr32.h> |
| 56 | #include <initguid.h> |
| 57 | #include <Devpkey.h> |
| 58 | #endif |
| 59 | |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 60 | // This is a CMake generated file with #defines for any functions/includes |
| 61 | // that it found present. This is currently necessary to properly determine |
| 62 | // if secure_getenv or __secure_getenv are present |
Jamie Madill | e09268a | 2017-03-21 13:48:13 -0400 | [diff] [blame] | 63 | #if !defined(VULKAN_NON_CMAKE_BUILD) |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 64 | #include "loader_cmake_config.h" |
Jamie Madill | e09268a | 2017-03-21 13:48:13 -0400 | [diff] [blame] | 65 | #endif // !defined(VULKAN_NON_CMAKE_BUILD) |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 66 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 67 | // Generated file containing all the extension data |
| 68 | #include "vk_loader_extensions.c" |
| 69 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 70 | struct loader_struct loader = {0}; |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 71 | // TLS for instance for alloc/free callbacks |
| 72 | THREAD_LOCAL_DECL struct loader_instance *tls_instance; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 73 | |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 74 | static size_t loader_platform_combine_path(char *dest, size_t len, ...); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 75 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 76 | struct loader_phys_dev_per_icd { |
| 77 | uint32_t count; |
| 78 | VkPhysicalDevice *phys_devs; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 79 | struct loader_icd_term *this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 82 | enum loader_debug { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 83 | LOADER_INFO_BIT = 0x01, |
| 84 | LOADER_WARN_BIT = 0x02, |
| 85 | LOADER_PERF_BIT = 0x04, |
| 86 | LOADER_ERROR_BIT = 0x08, |
| 87 | LOADER_DEBUG_BIT = 0x10, |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | uint32_t g_loader_debug = 0; |
| 91 | uint32_t g_loader_log_msgs = 0; |
| 92 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 93 | // thread safety lock for accessing global data structures such as "loader" |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 94 | // all entrypoints on the instance chain need to be locked except GPA |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 95 | // additionally CreateDevice and DestroyDevice needs to be locked |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 96 | loader_platform_thread_mutex loader_lock; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 97 | loader_platform_thread_mutex loader_json_lock; |
Jon Ashburn | 6301a0f | 2015-05-29 13:15:39 -0600 | [diff] [blame] | 98 | |
Lenny Komow | 2334298 | 2018-01-19 11:22:28 -0700 | [diff] [blame] | 99 | LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_init); |
| 100 | |
Lenny Komow | 1658611 | 2018-02-13 15:58:47 -0700 | [diff] [blame] | 101 | // This loader supports Vulkan API version 1.1 |
| 102 | uint32_t loader_major_version = 1; |
| 103 | uint32_t loader_minor_version = 1; |
| 104 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 105 | void *loader_instance_heap_alloc(const struct loader_instance *instance, size_t size, VkSystemAllocationScope alloc_scope) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 106 | void *pMemory = NULL; |
| 107 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 108 | { |
| 109 | #else |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 110 | if (instance && instance->alloc_callbacks.pfnAllocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 111 | // These are internal structures, so it's best to align everything to |
| 112 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 113 | pMemory = instance->alloc_callbacks.pfnAllocation(instance->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 114 | } else { |
| 115 | #endif |
| 116 | pMemory = malloc(size); |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 117 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 118 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 119 | return pMemory; |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 120 | } |
| 121 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 122 | void loader_instance_heap_free(const struct loader_instance *instance, void *pMemory) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 123 | if (pMemory != NULL) { |
| 124 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 125 | { |
| 126 | #else |
| 127 | if (instance && instance->alloc_callbacks.pfnFree) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 128 | instance->alloc_callbacks.pfnFree(instance->alloc_callbacks.pUserData, pMemory); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 129 | } else { |
| 130 | #endif |
| 131 | free(pMemory); |
Mark Young | d077f99 | 2016-06-30 11:03:59 -0600 | [diff] [blame] | 132 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 133 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 134 | } |
| 135 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 136 | void *loader_instance_heap_realloc(const struct loader_instance *instance, void *pMemory, size_t orig_size, size_t size, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 137 | VkSystemAllocationScope alloc_scope) { |
| 138 | void *pNewMem = NULL; |
| 139 | if (pMemory == NULL || orig_size == 0) { |
| 140 | pNewMem = loader_instance_heap_alloc(instance, size, alloc_scope); |
| 141 | } else if (size == 0) { |
| 142 | loader_instance_heap_free(instance, pMemory); |
| 143 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 144 | #else |
| 145 | } else if (instance && instance->alloc_callbacks.pfnReallocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 146 | // These are internal structures, so it's best to align everything to |
| 147 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 148 | pNewMem = instance->alloc_callbacks.pfnReallocation(instance->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 149 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 150 | #endif |
| 151 | } else { |
| 152 | pNewMem = realloc(pMemory, size); |
| 153 | } |
| 154 | return pNewMem; |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 155 | } |
| 156 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 157 | void *loader_instance_tls_heap_alloc(size_t size) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 158 | return loader_instance_heap_alloc(tls_instance, size, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 159 | } |
Mark Young | 4b0b922 | 2016-06-29 18:33:53 -0600 | [diff] [blame] | 160 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 161 | void loader_instance_tls_heap_free(void *pMemory) { loader_instance_heap_free(tls_instance, pMemory); } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 162 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 163 | void *loader_device_heap_alloc(const struct loader_device *device, size_t size, VkSystemAllocationScope alloc_scope) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 164 | void *pMemory = NULL; |
| 165 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 166 | { |
| 167 | #else |
| 168 | if (device && device->alloc_callbacks.pfnAllocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 169 | // These are internal structures, so it's best to align everything to |
| 170 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 171 | pMemory = device->alloc_callbacks.pfnAllocation(device->alloc_callbacks.pUserData, size, sizeof(uint64_t), alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 172 | } else { |
| 173 | #endif |
| 174 | pMemory = malloc(size); |
| 175 | } |
| 176 | return pMemory; |
| 177 | } |
| 178 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 179 | void loader_device_heap_free(const struct loader_device *device, void *pMemory) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 180 | if (pMemory != NULL) { |
| 181 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 182 | { |
| 183 | #else |
| 184 | if (device && device->alloc_callbacks.pfnFree) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 185 | device->alloc_callbacks.pfnFree(device->alloc_callbacks.pUserData, pMemory); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 186 | } else { |
| 187 | #endif |
| 188 | free(pMemory); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 193 | void *loader_device_heap_realloc(const struct loader_device *device, void *pMemory, size_t orig_size, size_t size, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 194 | VkSystemAllocationScope alloc_scope) { |
| 195 | void *pNewMem = NULL; |
| 196 | if (pMemory == NULL || orig_size == 0) { |
| 197 | pNewMem = loader_device_heap_alloc(device, size, alloc_scope); |
| 198 | } else if (size == 0) { |
| 199 | loader_device_heap_free(device, pMemory); |
| 200 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 201 | #else |
| 202 | } else if (device && device->alloc_callbacks.pfnReallocation) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 203 | // These are internal structures, so it's best to align everything to |
| 204 | // the largest unit size which is the size of a uint64_t. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 205 | pNewMem = device->alloc_callbacks.pfnReallocation(device->alloc_callbacks.pUserData, pMemory, size, sizeof(uint64_t), |
| 206 | alloc_scope); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 207 | #endif |
| 208 | } else { |
| 209 | pNewMem = realloc(pMemory, size); |
| 210 | } |
| 211 | return pNewMem; |
| 212 | } |
| 213 | |
| 214 | // Environment variables |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 215 | #if defined(__linux__) || defined(__APPLE__) |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 216 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 217 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 218 | // No allocation of memory necessary for Linux, but we should at least touch |
| 219 | // the inst pointer to get rid of compiler warnings. |
| 220 | (void)inst; |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 221 | return getenv(name); |
| 222 | } |
| 223 | |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 224 | static inline char *loader_secure_getenv(const char *name, const struct loader_instance *inst) { |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 225 | #if defined(__APPLE__) |
| 226 | // Apple does not appear to have a secure getenv implementation. |
| 227 | // The main difference between secure getenv and getenv is that secure getenv |
| 228 | // returns NULL if the process is being run with elevated privileges by a normal user. |
| 229 | // The idea is to prevent the reading of malicious environment variables by a process |
| 230 | // that can do damage. |
| 231 | // This algorithm is derived from glibc code that sets an internal |
| 232 | // variable (__libc_enable_secure) if the process is running under setuid or setgid. |
| 233 | return geteuid() != getuid() || getegid() != getgid() ? NULL : loader_getenv(name, inst); |
| 234 | #else |
| 235 | // Linux |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 236 | #ifdef HAVE_SECURE_GETENV |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 237 | (void)inst; |
Mark Young | ba7ee02 | 2017-03-09 10:41:25 -0700 | [diff] [blame] | 238 | return secure_getenv(name); |
| 239 | #elif defined(HAVE___SECURE_GETENV) |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 240 | (void)inst; |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 241 | return __secure_getenv(name); |
| 242 | #else |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 243 | #pragma message( \ |
| 244 | "Warning: Falling back to non-secure getenv for environmental lookups! Consider" \ |
| 245 | " updating to a different libc.") |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 246 | return loader_getenv(name, inst); |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 247 | #endif |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 248 | #endif |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 249 | } |
Mark Young | f2f2a66 | 2017-03-08 10:11:52 -0700 | [diff] [blame] | 250 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 251 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 252 | // No freeing of memory necessary for Linux, but we should at least touch |
| 253 | // the val and inst pointers to get rid of compiler warnings. |
| 254 | (void)val; |
| 255 | (void)inst; |
| 256 | } |
| 257 | |
| 258 | #elif defined(WIN32) |
| 259 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 260 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 261 | char *retVal; |
| 262 | DWORD valSize; |
| 263 | |
| 264 | valSize = GetEnvironmentVariableA(name, NULL, 0); |
| 265 | |
| 266 | // valSize DOES include the null terminator, so for any set variable |
| 267 | // will always be at least 1. If it's 0, the variable wasn't set. |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 268 | if (valSize == 0) return NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 269 | |
| 270 | // Allocate the space necessary for the registry entry |
| 271 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnAllocation) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 272 | retVal = (char *)inst->alloc_callbacks.pfnAllocation(inst->alloc_callbacks.pUserData, valSize, sizeof(char *), |
| 273 | VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 274 | } else { |
| 275 | retVal = (char *)malloc(valSize); |
| 276 | } |
| 277 | |
| 278 | if (NULL != retVal) { |
| 279 | GetEnvironmentVariableA(name, retVal, valSize); |
| 280 | } |
| 281 | |
| 282 | return retVal; |
| 283 | } |
| 284 | |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 285 | static inline char *loader_secure_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 286 | // No secure version for Windows as far as I know |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 287 | return loader_getenv(name, inst); |
| 288 | } |
| 289 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 290 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 291 | if (NULL != inst && NULL != inst->alloc_callbacks.pfnFree) { |
| 292 | inst->alloc_callbacks.pfnFree(inst->alloc_callbacks.pUserData, val); |
| 293 | } else { |
| 294 | free((void *)val); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | #else |
| 299 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 300 | static inline char *loader_getenv(const char *name, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 301 | // stub func |
| 302 | (void)inst; |
| 303 | (void)name; |
| 304 | return NULL; |
| 305 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 306 | static inline void loader_free_getenv(char *val, const struct loader_instance *inst) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 307 | // stub func |
| 308 | (void)val; |
| 309 | (void)inst; |
| 310 | } |
| 311 | |
| 312 | #endif |
| 313 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 314 | void loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...) { |
Jon Ashburn | 86723b0 | 2015-07-31 15:47:59 -0600 | [diff] [blame] | 315 | char msg[512]; |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 316 | char cmd_line_msg[512]; |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 317 | size_t cmd_line_size = sizeof(cmd_line_msg); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 318 | va_list ap; |
| 319 | int ret; |
| 320 | |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 321 | va_start(ap, format); |
| 322 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 323 | if ((ret >= (int)sizeof(msg)) || ret < 0) { |
| 324 | msg[sizeof(msg) - 1] = '\0'; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 325 | } |
| 326 | va_end(ap); |
| 327 | |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 328 | if (inst) { |
Lenny Komow | 281033b | 2018-02-13 17:35:28 -0700 | [diff] [blame] | 329 | VkDebugUtilsMessageSeverityFlagBitsEXT severity = 0; |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 330 | VkDebugUtilsMessageTypeFlagsEXT type; |
| 331 | VkDebugUtilsMessengerCallbackDataEXT callback_data; |
| 332 | VkDebugUtilsObjectNameInfoEXT object_name; |
| 333 | |
| 334 | if ((msg_type & LOADER_INFO_BIT) != 0) { |
| 335 | severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT; |
| 336 | } else if ((msg_type & LOADER_WARN_BIT) != 0) { |
| 337 | severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT; |
| 338 | } else if ((msg_type & LOADER_ERROR_BIT) != 0) { |
| 339 | severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; |
| 340 | } else if ((msg_type & LOADER_DEBUG_BIT) != 0) { |
| 341 | severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT; |
| 342 | } |
| 343 | |
| 344 | if ((msg_type & LOADER_PERF_BIT) != 0) { |
| 345 | type = VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT; |
| 346 | } else { |
| 347 | type = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT; |
| 348 | } |
| 349 | |
| 350 | callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT; |
| 351 | callback_data.pNext = NULL; |
| 352 | callback_data.flags = 0; |
| 353 | callback_data.pMessageIdName = "Loader Message"; |
| 354 | callback_data.messageIdNumber = 0; |
| 355 | callback_data.pMessage = msg; |
| 356 | callback_data.queueLabelCount = 0; |
| 357 | callback_data.pQueueLabels = NULL; |
| 358 | callback_data.cmdBufLabelCount = 0; |
| 359 | callback_data.pCmdBufLabels = NULL; |
| 360 | callback_data.objectCount = 1; |
| 361 | callback_data.pObjects = &object_name; |
| 362 | object_name.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; |
| 363 | object_name.pNext = NULL; |
| 364 | object_name.objectType = VK_OBJECT_TYPE_INSTANCE; |
| 365 | object_name.objectHandle = (uint64_t)(uintptr_t)inst; |
| 366 | object_name.pObjectName = NULL; |
| 367 | |
| 368 | util_SubmitDebugUtilsMessageEXT(inst, severity, type, &callback_data); |
Courtney Goeltzenleuchter | 7347739 | 2015-12-03 13:48:01 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | if (!(msg_type & g_loader_log_msgs)) { |
| 372 | return; |
| 373 | } |
| 374 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 375 | cmd_line_msg[0] = '\0'; |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 376 | cmd_line_size -= 1; |
| 377 | size_t original_size = cmd_line_size; |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 378 | |
| 379 | va_start(ap, format); |
| 380 | if ((msg_type & LOADER_INFO_BIT) != 0) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 381 | strncat(cmd_line_msg, "INFO", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 382 | cmd_line_size -= 4; |
| 383 | } |
| 384 | if ((msg_type & LOADER_WARN_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 385 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 386 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 387 | cmd_line_size -= 3; |
| 388 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 389 | strncat(cmd_line_msg, "WARNING", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 390 | cmd_line_size -= 7; |
| 391 | } |
| 392 | if ((msg_type & LOADER_PERF_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 393 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 394 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 395 | cmd_line_size -= 3; |
| 396 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 397 | strncat(cmd_line_msg, "PERF", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 398 | cmd_line_size -= 4; |
| 399 | } |
| 400 | if ((msg_type & LOADER_ERROR_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 401 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 402 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 403 | cmd_line_size -= 3; |
| 404 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 405 | strncat(cmd_line_msg, "ERROR", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 406 | cmd_line_size -= 5; |
| 407 | } |
| 408 | if ((msg_type & LOADER_DEBUG_BIT) != 0) { |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 409 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 410 | strncat(cmd_line_msg, " | ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 411 | cmd_line_size -= 3; |
| 412 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 413 | strncat(cmd_line_msg, "DEBUG", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 414 | cmd_line_size -= 5; |
| 415 | } |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 416 | if (cmd_line_size != original_size) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 417 | strncat(cmd_line_msg, ": ", cmd_line_size); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 418 | cmd_line_size -= 2; |
| 419 | } |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 420 | |
| 421 | if (0 < cmd_line_size) { |
| 422 | // If the message is too long, trim it down |
| 423 | if (strlen(msg) > cmd_line_size) { |
| 424 | msg[cmd_line_size - 1] = '\0'; |
| 425 | } |
| 426 | strncat(cmd_line_msg, msg, cmd_line_size); |
| 427 | } else { |
| 428 | // Shouldn't get here, but check to make sure if we've already overrun |
| 429 | // the string boundary |
| 430 | assert(false); |
| 431 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 432 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 433 | #if defined(WIN32) |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 434 | OutputDebugString(cmd_line_msg); |
mschott | b9cdb78 | 2015-07-22 14:11:29 +0200 | [diff] [blame] | 435 | OutputDebugString("\n"); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 436 | #endif |
Mark Young | 5de3af7 | 2017-04-25 08:08:29 -0600 | [diff] [blame] | 437 | |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 438 | fputs(cmd_line_msg, stderr); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 439 | fputc('\n', stderr); |
| 440 | } |
| 441 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 442 | VKAPI_ATTR VkResult VKAPI_CALL vkSetInstanceDispatch(VkInstance instance, void *object) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 443 | struct loader_instance *inst = loader_get_instance(instance); |
| 444 | if (!inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 445 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 446 | "vkSetInstanceDispatch: Can not retrieve Instance " |
| 447 | "dispatch table."); |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 448 | return VK_ERROR_INITIALIZATION_FAILED; |
| 449 | } |
| 450 | loader_set_dispatch(object, inst->disp); |
| 451 | return VK_SUCCESS; |
| 452 | } |
| 453 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 454 | VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceDispatch(VkDevice device, void *object) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 455 | struct loader_device *dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 456 | struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, NULL); |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 457 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 458 | if (NULL == icd_term) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 459 | return VK_ERROR_INITIALIZATION_FAILED; |
| 460 | } |
| 461 | loader_set_dispatch(object, &dev->loader_dispatch); |
| 462 | return VK_SUCCESS; |
| 463 | } |
| 464 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 465 | #if defined(_WIN32) |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 466 | |
| 467 | // Append the JSON path data to the list and allocate/grow the list if it's not large enough. |
| 468 | // Function returns true if filename was appended to reg_data list. |
| 469 | // Caller should free reg_data. |
| 470 | static bool loaderAddJsonEntry(const struct loader_instance *inst, |
| 471 | char **reg_data, // list of JSON files |
| 472 | PDWORD total_size, // size of reg_data |
| 473 | LPCTSTR key_name, // key name - used for debug prints - i.e. VulkanDriverName |
| 474 | DWORD key_type, // key data type |
| 475 | LPSTR json_path, // JSON string to add to the list reg_data |
| 476 | DWORD json_size, // size in bytes of json_path |
| 477 | VkResult *result) { |
| 478 | if (NULL == *reg_data) { |
| 479 | *reg_data = loader_instance_heap_alloc(inst, *total_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 480 | if (NULL == *reg_data) { |
| 481 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 482 | "loaderAddJsonEntry: Failed to allocate space for registry data for key %s", json_path); |
| 483 | *result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 484 | return false; |
| 485 | } |
| 486 | *reg_data[0] = '\0'; |
| 487 | } else if (strlen(*reg_data) + json_size + 1 > *total_size) { |
| 488 | void *new_ptr = |
| 489 | loader_instance_heap_realloc(inst, *reg_data, *total_size, *total_size * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 490 | if (NULL == new_ptr) { |
| 491 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 492 | "loaderAddJsonEntry: Failed to reallocate space for registry value of size %d for key %s", *total_size * 2, |
| 493 | json_path); |
| 494 | *result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 495 | return false; |
| 496 | } |
| 497 | *reg_data = new_ptr; |
| 498 | *total_size *= 2; |
| 499 | } |
| 500 | |
| 501 | for (char *curr_filename = json_path; curr_filename[0] != '\0'; curr_filename += strlen(curr_filename) + 1) { |
| 502 | if (strlen(*reg_data) == 0) { |
| 503 | (void)snprintf(*reg_data, json_size + 1, "%s", curr_filename); |
| 504 | } else { |
| 505 | (void)snprintf(*reg_data + strlen(*reg_data), json_size + 2, "%c%s", PATH_SEPARATOR, curr_filename); |
| 506 | } |
| 507 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "%s: Located json file \"%s\" from PnP registry: %s", __FUNCTION__, |
| 508 | curr_filename, key_name); |
| 509 | |
| 510 | if (key_type == REG_SZ) { |
| 511 | break; |
| 512 | } |
| 513 | } |
| 514 | return true; |
| 515 | } |
| 516 | |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 517 | // Find the list of registry files (names VulkanDriverName/VulkanDriverNameWow) in hkr. |
| 518 | // |
| 519 | // This function looks for filename in given device handle, filename is then added to return list |
| 520 | // function return true if filename was appended to reg_data list |
| 521 | // If error occures result is updated with failure reason |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 522 | bool loaderGetDeviceRegistryEntry(const struct loader_instance *inst, char **reg_data, PDWORD total_size, DEVINST dev_id, LPCTSTR value_name, VkResult *result) |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 523 | { |
| 524 | HKEY hkrKey = INVALID_HANDLE_VALUE; |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 525 | DWORD requiredSize, data_type; |
| 526 | char *manifest_path = NULL; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 527 | bool found = false; |
| 528 | |
| 529 | if (NULL == total_size || NULL == reg_data) { |
| 530 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 531 | return false; |
| 532 | } |
| 533 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 534 | CONFIGRET status = CM_Open_DevNode_Key(dev_id, KEY_QUERY_VALUE, 0, RegDisposition_OpenExisting, &hkrKey, CM_REGISTRY_SOFTWARE); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 535 | if (status != CR_SUCCESS) { |
| 536 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 537 | "loaderGetDeviceRegistryEntry: Failed to open registry key for DeviceID(%d)", dev_id); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 538 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 539 | return false; |
| 540 | } |
| 541 | |
| 542 | // query value |
| 543 | LSTATUS ret = RegQueryValueEx( |
| 544 | hkrKey, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 545 | value_name, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 546 | NULL, |
| 547 | NULL, |
| 548 | NULL, |
| 549 | &requiredSize); |
| 550 | |
| 551 | if (ret != ERROR_SUCCESS) { |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 552 | if (ret == ERROR_FILE_NOT_FOUND) { |
| 553 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 554 | "loaderGetDeviceRegistryEntry: Device ID(%d) Does not contain a value for \"%s\"", dev_id, value_name); |
| 555 | } else { |
| 556 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 557 | "loaderGetDeviceRegistryEntry: DeviceID(%d) Failed to obtain %s size", dev_id, value_name); |
| 558 | } |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 559 | goto out; |
| 560 | } |
| 561 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 562 | manifest_path = loader_instance_heap_alloc(inst, requiredSize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 563 | if (manifest_path == NULL) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 564 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 565 | "loaderGetDeviceRegistryEntry: Failed to allocate space for DriverName."); |
| 566 | *result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 567 | goto out; |
| 568 | } |
| 569 | |
| 570 | ret = RegQueryValueEx( |
| 571 | hkrKey, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 572 | value_name, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 573 | NULL, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 574 | &data_type, |
Jamie Madill | a11ae0b | 2017-11-08 14:48:32 -0500 | [diff] [blame] | 575 | (BYTE *)manifest_path, |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 576 | &requiredSize |
| 577 | ); |
| 578 | |
| 579 | if (ret != ERROR_SUCCESS) { |
| 580 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 581 | "loaderGetDeviceRegistryEntry: DeviceID(%d) Failed to obtain %s", value_name); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 582 | |
| 583 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 584 | goto out; |
| 585 | } |
| 586 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 587 | if (data_type != REG_SZ && data_type != REG_MULTI_SZ) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 588 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 589 | "loaderGetDeviceRegistryEntry: Invalid %s data type. Expected REG_SZ or REG_MULTI_SZ.", value_name); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 590 | *result = VK_ERROR_INITIALIZATION_FAILED; |
| 591 | goto out; |
| 592 | } |
| 593 | |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 594 | found = loaderAddJsonEntry(inst, reg_data, total_size, value_name, data_type, manifest_path, requiredSize, result); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 595 | |
| 596 | out: |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 597 | if (manifest_path != NULL) { |
| 598 | loader_instance_heap_free(inst, manifest_path); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 599 | } |
| 600 | RegCloseKey(hkrKey); |
| 601 | return found; |
| 602 | } |
| 603 | |
| 604 | // Find the list of registry files (names VulkanDriverName/VulkanDriverNameWow) in hkr . |
| 605 | // |
| 606 | // This function looks for display devices and childish software components |
| 607 | // for a list of files which are added to a returned list (function return |
| 608 | // value). |
| 609 | // Function return is a string with a ';' separated list of filenames. |
| 610 | // Function return is NULL if no valid name/value pairs are found in the key, |
| 611 | // or the key is not found. |
| 612 | // |
| 613 | // *reg_data contains a string list of filenames as pointer. |
| 614 | // When done using the returned string list, the caller should free the pointer. |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 615 | VkResult loaderGetDeviceRegistryFiles(const struct loader_instance *inst, char **reg_data, PDWORD reg_data_size, LPCTSTR value_name) { |
Slawomir Cygan | ad34df2 | 2018-01-25 13:51:17 +0100 | [diff] [blame] | 616 | static const wchar_t *softwareComponentGUID = L"{5c4c3332-344d-483c-8739-259e934c9cc8}"; |
| 617 | static const wchar_t *displayGUID = L"{4d36e968-e325-11ce-bfc1-08002be10318}"; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 618 | const ULONG flags = CM_GETIDLIST_FILTER_CLASS | CM_GETIDLIST_FILTER_PRESENT; |
Slawomir Cygan | ad34df2 | 2018-01-25 13:51:17 +0100 | [diff] [blame] | 619 | |
| 620 | wchar_t childGuid[MAX_GUID_STRING_LEN + 2]; // +2 for brackets {} |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 621 | ULONG childGuidSize = sizeof(childGuid); |
| 622 | |
| 623 | DEVINST devID = 0, childID = 0; |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 624 | wchar_t *pDeviceNames = NULL; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 625 | ULONG deviceNamesSize = 0; |
| 626 | VkResult result = VK_SUCCESS; |
| 627 | bool found = false; |
| 628 | |
| 629 | if (NULL == reg_data) { |
| 630 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 631 | return result; |
| 632 | } |
| 633 | |
| 634 | // if after obtaining the DeviceNameSize, new device is added start over |
| 635 | do { |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 636 | CM_Get_Device_ID_List_SizeW(&deviceNamesSize, displayGUID, flags); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 637 | |
| 638 | if (pDeviceNames != NULL) { |
| 639 | loader_instance_heap_free(inst, pDeviceNames); |
| 640 | } |
| 641 | |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 642 | pDeviceNames = loader_instance_heap_alloc(inst, deviceNamesSize * sizeof(wchar_t), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 643 | if (pDeviceNames == NULL) { |
| 644 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 645 | "loaderGetDeviceRegistryFiles: Failed to allocate space for display device names."); |
| 646 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
Slawomir Cygan | 018bfd5 | 2017-08-25 10:54:03 +0200 | [diff] [blame] | 647 | return result; |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 648 | } |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 649 | } while (CM_Get_Device_ID_ListW(displayGUID, pDeviceNames, deviceNamesSize, flags) == CR_BUFFER_SMALL); |
| 650 | |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 651 | if (pDeviceNames) { |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 652 | for (wchar_t *deviceName = pDeviceNames; *deviceName; deviceName += wcslen(deviceName) + 1) { |
| 653 | CONFIGRET status = CM_Locate_DevNodeW(&devID, deviceName, CM_LOCATE_DEVNODE_NORMAL); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 654 | if (CR_SUCCESS != status) { |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 655 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loaderGetDeviceRegistryFiles: failed to open DevNode %s", |
| 656 | deviceName); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 657 | continue; |
| 658 | } |
| 659 | ULONG ulStatus, ulProblem; |
| 660 | status = CM_Get_DevNode_Status(&ulStatus, &ulProblem, devID, 0); |
| 661 | |
| 662 | if (CR_SUCCESS != status) |
| 663 | { |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 664 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loaderGetDeviceRegistryFiles: failed to probe device status %s", |
| 665 | deviceName); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 666 | continue; |
| 667 | } |
| 668 | if ((ulStatus & DN_HAS_PROBLEM) && (ulProblem == CM_PROB_NEED_RESTART || ulProblem == DN_NEED_RESTART)) |
| 669 | { |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 670 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 671 | "loaderGetDeviceRegistryFiles: device %s is pending reboot, skipping ...", deviceName); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 672 | continue; |
| 673 | } |
| 674 | |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 675 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "loaderGetDeviceRegistryFiles: opening device %s", deviceName); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 676 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 677 | if (loaderGetDeviceRegistryEntry(inst, reg_data, reg_data_size, devID, value_name, &result)) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 678 | found = true; |
| 679 | continue; |
| 680 | } |
Igor Ostrowski | 2153273 | 2017-10-06 18:26:23 +0200 | [diff] [blame] | 681 | else if (result == VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 682 | break; |
| 683 | } |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 684 | |
| 685 | status = CM_Get_Child(&childID, devID, 0); |
| 686 | if (status != CR_SUCCESS) { |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 687 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 688 | "loaderGetDeviceRegistryFiles: unable to open child-device error:%d", status); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 689 | continue; |
| 690 | } |
| 691 | |
| 692 | do { |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 693 | wchar_t buffer[MAX_DEVICE_ID_LEN]; |
| 694 | CM_Get_Device_IDW(childID, buffer, MAX_DEVICE_ID_LEN, 0); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 695 | |
Lenny Komow | e17a12a | 2017-08-10 09:25:49 -0600 | [diff] [blame] | 696 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 697 | "loaderGetDeviceRegistryFiles: Opening child device %d - %s", childID, buffer); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 698 | |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 699 | status = CM_Get_DevNode_Registry_PropertyW(childID, CM_DRP_CLASSGUID, NULL, &childGuid, &childGuidSize, 0); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 700 | if (status != CR_SUCCESS) { |
| 701 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 702 | "loaderGetDeviceRegistryFiles: unable to obtain GUID for:%d error:%d", childID, status); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 703 | |
| 704 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 705 | continue; |
| 706 | } |
| 707 | |
Slawomir Cygan | a589d42 | 2018-01-25 13:48:54 +0100 | [diff] [blame] | 708 | if (wcscmp(childGuid, softwareComponentGUID) != 0) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 709 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 710 | "loaderGetDeviceRegistryFiles: GUID for %d is not SoftwareComponent skipping", childID); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 711 | continue; |
| 712 | } |
| 713 | |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 714 | if (loaderGetDeviceRegistryEntry(inst, reg_data, reg_data_size, childID, value_name, &result)) { |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 715 | found = true; |
| 716 | break; // check next-display-device |
| 717 | } |
| 718 | |
| 719 | } while (CM_Get_Sibling(&childID, childID, 0) == CR_SUCCESS); |
| 720 | } |
| 721 | |
| 722 | loader_instance_heap_free(inst, pDeviceNames); |
| 723 | } |
| 724 | |
| 725 | if (!found && result != VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 726 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 727 | } |
| 728 | |
| 729 | return result; |
| 730 | } |
| 731 | |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 732 | static char *loader_get_next_path(char *path); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 733 | |
| 734 | // Find the list of registry files (names within a key) in key "location". |
| 735 | // |
| 736 | // This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as |
| 737 | // given in "location" |
| 738 | // for a list or name/values which are added to a returned list (function return |
| 739 | // value). |
| 740 | // The DWORD values within the key must be 0 or they are skipped. |
| 741 | // Function return is a string with a ';' separated list of filenames. |
| 742 | // Function return is NULL if no valid name/value pairs are found in the key, |
| 743 | // or the key is not found. |
| 744 | // |
| 745 | // *reg_data contains a string list of filenames as pointer. |
| 746 | // When done using the returned string list, the caller should free the pointer. |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 747 | VkResult loaderGetRegistryFiles(const struct loader_instance *inst, char *location, bool use_secondary_hive, char **reg_data, PDWORD reg_data_size) { |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 748 | LONG rtn_value; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 749 | HKEY hive = DEFAULT_VK_REGISTRY_HIVE, key; |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 750 | DWORD access_flags; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 751 | char name[2048]; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 752 | char *loc = location; |
| 753 | char *next; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 754 | DWORD idx; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 755 | DWORD name_size = sizeof(name); |
| 756 | DWORD value; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 757 | DWORD value_size = sizeof(value); |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 758 | VkResult result = VK_SUCCESS; |
| 759 | bool found = false; |
| 760 | |
| 761 | if (NULL == reg_data) { |
| 762 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 763 | goto out; |
| 764 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 765 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 766 | while (*loc) { |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 767 | next = loader_get_next_path(loc); |
Piers Daniell | 524ec73 | 2015-11-05 16:58:26 -0700 | [diff] [blame] | 768 | access_flags = KEY_QUERY_VALUE; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 769 | rtn_value = RegOpenKeyEx(hive, loc, 0, access_flags, &key); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 770 | if (ERROR_SUCCESS == rtn_value) { |
| 771 | idx = 0; |
| 772 | while ((rtn_value = RegEnumValue(key, idx++, name, &name_size, NULL, NULL, (LPBYTE)&value, &value_size)) == |
| 773 | ERROR_SUCCESS) { |
| 774 | if (value_size == sizeof(value) && value == 0) { |
| 775 | if (NULL == *reg_data) { |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 776 | *reg_data = loader_instance_heap_alloc(inst, *reg_data_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 777 | if (NULL == *reg_data) { |
| 778 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 779 | "loaderGetRegistryFiles: Failed to allocate space for registry data for key %s", name); |
Slawomir Cygan | e583032 | 2018-01-16 17:17:07 +0100 | [diff] [blame] | 780 | RegCloseKey(key); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 781 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 782 | goto out; |
| 783 | } |
| 784 | *reg_data[0] = '\0'; |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 785 | } else if (strlen(*reg_data) + name_size + 1 > *reg_data_size) { |
| 786 | void *new_ptr = loader_instance_heap_realloc(inst, *reg_data, *reg_data_size, *reg_data_size * 2, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 787 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 788 | if (NULL == new_ptr) { |
| 789 | loader_log( |
| 790 | inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 791 | "loaderGetRegistryFiles: Failed to reallocate space for registry value of size %d for key %s", |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 792 | *reg_data_size * 2, name); |
Slawomir Cygan | e583032 | 2018-01-16 17:17:07 +0100 | [diff] [blame] | 793 | RegCloseKey(key); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 794 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 795 | goto out; |
| 796 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 797 | *reg_data = new_ptr; |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 798 | *reg_data_size *= 2; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 799 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 800 | loader_log( |
| 801 | inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Located json file \"%s\" from registry \"%s\\%s\"", name, |
| 802 | hive == DEFAULT_VK_REGISTRY_HIVE ? DEFAULT_VK_REGISTRY_HIVE_STR : SECONDARY_VK_REGISTRY_HIVE_STR, location); |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 803 | if (strlen(*reg_data) == 0) { |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 804 | // The list is emtpy. Add the first entry. |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 805 | (void)snprintf(*reg_data, name_size + 1, "%s", name); |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 806 | found = true; |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 807 | } else { |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 808 | // At this point the reg_data variable contains other JSON paths, likely from the PNP/device section |
| 809 | // of the registry that we want to have precendence over this non-device specific section of the registry. |
| 810 | // To make sure we avoid enumerating old JSON files/drivers that might be present in the non-device specific |
| 811 | // area of the registry when a newer device specific JSON file is present, do a check before adding. |
| 812 | // Find the file name, without path, of the JSON file found in the non-device specific registry location. |
| 813 | // If the same JSON file name is already found in the list, don't add it again. |
| 814 | bool foundDuplicate = false; |
| 815 | char *pLastSlashName = strrchr(name, '\\'); |
| 816 | if (pLastSlashName != NULL) { |
| 817 | char *foundMatch = strstr(*reg_data, pLastSlashName + 1); |
| 818 | if (foundMatch != NULL) { |
| 819 | foundDuplicate = true; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | if (foundDuplicate == false) { |
| 824 | // Add the new entry to the list. |
| 825 | (void)snprintf(*reg_data + strlen(*reg_data), name_size + 2, "%c%s", PATH_SEPARATOR, name); |
| 826 | found = true; |
| 827 | } else { |
| 828 | loader_log( |
| 829 | inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 830 | "Skipping adding of json file \"%s\" from registry \"%s\\%s\" to the list due to duplication", name, |
| 831 | hive == DEFAULT_VK_REGISTRY_HIVE ? DEFAULT_VK_REGISTRY_HIVE_STR : SECONDARY_VK_REGISTRY_HIVE_STR, |
| 832 | location); |
| 833 | } |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 834 | } |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 835 | } |
| 836 | name_size = 2048; |
| 837 | } |
Slawomir Cygan | e583032 | 2018-01-16 17:17:07 +0100 | [diff] [blame] | 838 | RegCloseKey(key); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 839 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 840 | |
Lenny Komow | da849dc | 2017-03-01 17:22:29 -0700 | [diff] [blame] | 841 | // Advance the location - if the next location is in the secondary hive, then reset the locations and advance the hive |
| 842 | if (use_secondary_hive && (hive == DEFAULT_VK_REGISTRY_HIVE) && (*next == '\0')) { |
| 843 | loc = location; |
| 844 | hive = SECONDARY_VK_REGISTRY_HIVE; |
| 845 | } else { |
| 846 | loc = next; |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 847 | } |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 848 | } |
Tony Barbour | ea96890 | 2015-07-29 14:26:21 -0600 | [diff] [blame] | 849 | |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 850 | if (!found && result != VK_ERROR_OUT_OF_HOST_MEMORY) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 851 | result = VK_ERROR_INITIALIZATION_FAILED; |
| 852 | } |
| 853 | |
| 854 | out: |
| 855 | |
| 856 | return result; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 859 | #endif // WIN32 |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 860 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 861 | // Combine path elements, separating each element with the platform-specific |
| 862 | // directory separator, and save the combined string to a destination buffer, |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 863 | // not exceeding the given length. Path elements are given as variable args, |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 864 | // with a NULL element terminating the list. |
| 865 | // |
| 866 | // \returns the total length of the combined string, not including an ASCII |
| 867 | // NUL termination character. This length may exceed the available storage: |
| 868 | // in this case, the written string will be truncated to avoid a buffer |
| 869 | // overrun, and the return value will greater than or equal to the storage |
| 870 | // size. A NULL argument may be provided as the destination buffer in order |
| 871 | // to determine the required string length without actually writing a string. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 872 | static size_t loader_platform_combine_path(char *dest, size_t len, ...) { |
Courtney Goeltzenleuchter | 0ef13a0 | 2015-12-16 16:19:46 -0700 | [diff] [blame] | 873 | size_t required_len = 0; |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 874 | va_list ap; |
| 875 | const char *component; |
| 876 | |
| 877 | va_start(ap, len); |
| 878 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 879 | while ((component = va_arg(ap, const char *))) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 880 | if (required_len > 0) { |
| 881 | // This path element is not the first non-empty element; prepend |
| 882 | // a directory separator if space allows |
| 883 | if (dest && required_len + 1 < len) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 884 | (void)snprintf(dest + required_len, len - required_len, "%c", DIRECTORY_SYMBOL); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 885 | } |
| 886 | required_len++; |
| 887 | } |
| 888 | |
| 889 | if (dest && required_len < len) { |
| 890 | strncpy(dest + required_len, component, len - required_len); |
| 891 | } |
| 892 | required_len += strlen(component); |
| 893 | } |
| 894 | |
| 895 | va_end(ap); |
| 896 | |
| 897 | // strncpy(3) won't add a NUL terminating byte in the event of truncation. |
| 898 | if (dest && required_len >= len) { |
| 899 | dest[len - 1] = '\0'; |
| 900 | } |
| 901 | |
| 902 | return required_len; |
| 903 | } |
| 904 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 905 | // Given string of three part form "maj.min.pat" convert to a vulkan version number. |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 906 | static uint32_t loader_make_version(char *vers_str) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 907 | uint32_t vers = 0, major = 0, minor = 0, patch = 0; |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 908 | char *vers_tok; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 909 | |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 910 | if (!vers_str) { |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 911 | return vers; |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 912 | } |
Mark Young | 60861ac | 2016-09-02 11:39:26 -0600 | [diff] [blame] | 913 | |
| 914 | vers_tok = strtok(vers_str, ".\"\n\r"); |
| 915 | if (NULL != vers_tok) { |
| 916 | major = (uint16_t)atoi(vers_tok); |
| 917 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 918 | if (NULL != vers_tok) { |
| 919 | minor = (uint16_t)atoi(vers_tok); |
| 920 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 921 | if (NULL != vers_tok) { |
| 922 | patch = (uint16_t)atoi(vers_tok); |
| 923 | } |
| 924 | } |
| 925 | } |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 926 | |
| 927 | return VK_MAKE_VERSION(major, minor, patch); |
Jon Ashburn | c7237a7 | 2015-08-03 09:08:46 -0600 | [diff] [blame] | 928 | } |
| 929 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 930 | bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2) { |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 931 | return strcmp(op1->extensionName, op2->extensionName) == 0 ? true : false; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 932 | } |
| 933 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 934 | // Search the given ext_array for an extension matching the given vk_ext_prop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 935 | bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 936 | const VkExtensionProperties *ext_array) { |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 937 | for (uint32_t i = 0; i < count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 938 | if (compare_vk_extension_properties(vk_ext_prop, &ext_array[i])) return true; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 939 | } |
| 940 | return false; |
| 941 | } |
| 942 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 943 | // Search the given ext_list for an extension matching the given vk_ext_prop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 944 | bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 945 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 946 | if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) return true; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 947 | } |
| 948 | return false; |
| 949 | } |
| 950 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 951 | // Search the given ext_list for a device extension matching the given ext_prop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 952 | bool has_vk_dev_ext_property(const VkExtensionProperties *ext_prop, const struct loader_device_extension_list *ext_list) { |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 953 | for (uint32_t i = 0; i < ext_list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 954 | if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) return true; |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 955 | } |
| 956 | return false; |
| 957 | } |
| 958 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 959 | // Search the given layer list for a layer matching the given layer name |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 960 | static struct loader_layer_properties *loader_get_layer_property(const char *name, const struct loader_layer_list *layer_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 961 | for (uint32_t i = 0; i < layer_list->count; i++) { |
| 962 | const VkLayerProperties *item = &layer_list->list[i].info; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 963 | if (strcmp(name, item->layerName) == 0) return &layer_list->list[i]; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 964 | } |
| 965 | return NULL; |
| 966 | } |
| 967 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 968 | // Get the next unused layer property in the list. Init the property to zero. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 969 | static struct loader_layer_properties *loader_get_next_layer_property(const struct loader_instance *inst, |
| 970 | struct loader_layer_list *layer_list) { |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 971 | if (layer_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 972 | layer_list->list = |
| 973 | loader_instance_heap_alloc(inst, sizeof(struct loader_layer_properties) * 64, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 974 | if (layer_list->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 975 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 976 | "loader_get_next_layer_property: Out of memory can " |
| 977 | "not add any layer properties to list"); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 978 | return NULL; |
| 979 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 980 | memset(layer_list->list, 0, sizeof(struct loader_layer_properties) * 64); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 981 | layer_list->capacity = sizeof(struct loader_layer_properties) * 64; |
| 982 | } |
| 983 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 984 | // Ensure enough room to add an entry |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 985 | if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > layer_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 986 | void *new_ptr = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2, |
| 987 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 988 | if (NULL == new_ptr) { |
| 989 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_next_layer_property: realloc failed for layer list"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 990 | return NULL; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 991 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 992 | layer_list->list = new_ptr; |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 993 | layer_list->capacity *= 2; |
| 994 | } |
| 995 | |
| 996 | layer_list->count++; |
| 997 | return &(layer_list->list[layer_list->count - 1]); |
| 998 | } |
| 999 | |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 1000 | // Remove all layer properties entries from the list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1001 | void loader_delete_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_list) { |
Cort Stratton | 6974a13 | 2017-11-28 12:11:05 -0800 | [diff] [blame] | 1002 | uint32_t i, j, k; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1003 | struct loader_device_extension_list *dev_ext_list; |
Cort Stratton | 6974a13 | 2017-11-28 12:11:05 -0800 | [diff] [blame] | 1004 | struct loader_dev_ext_props *ext_props; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1005 | if (!layer_list) return; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 1006 | |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1007 | for (i = 0; i < layer_list->count; i++) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1008 | if (NULL != layer_list->list[i].component_layer_names) { |
| 1009 | loader_instance_heap_free(inst, layer_list->list[i].component_layer_names); |
| 1010 | layer_list->list[i].component_layer_names = NULL; |
| 1011 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1012 | loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_list->list[i].instance_extension_list); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1013 | dev_ext_list = &layer_list->list[i].device_extension_list; |
Cort Stratton | 6974a13 | 2017-11-28 12:11:05 -0800 | [diff] [blame] | 1014 | if (dev_ext_list->capacity > 0 && NULL != dev_ext_list->list) { |
| 1015 | for (j = 0; j < dev_ext_list->count; j++) { |
| 1016 | ext_props = &dev_ext_list->list[j]; |
| 1017 | if (ext_props->entrypoint_count > 0) { |
| 1018 | for (k = 0; k < ext_props->entrypoint_count; k++) { |
| 1019 | loader_instance_heap_free(inst, ext_props->entrypoints[k]); |
| 1020 | } |
| 1021 | loader_instance_heap_free(inst, ext_props->entrypoints); |
| 1022 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1023 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1024 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1025 | loader_destroy_generic_list(inst, (struct loader_generic_list *)dev_ext_list); |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1026 | } |
| 1027 | layer_list->count = 0; |
| 1028 | |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 1029 | if (layer_list->capacity > 0) { |
| 1030 | layer_list->capacity = 0; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1031 | loader_instance_heap_free(inst, layer_list->list); |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 1032 | } |
Jon Ashburn | e13ecc9 | 2015-08-03 17:19:30 -0600 | [diff] [blame] | 1033 | } |
| 1034 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1035 | static VkResult loader_add_instance_extensions(const struct loader_instance *inst, |
| 1036 | const PFN_vkEnumerateInstanceExtensionProperties fp_get_props, const char *lib_name, |
| 1037 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 1038 | uint32_t i, count = 0; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1039 | VkExtensionProperties *ext_props; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1040 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1041 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 1042 | if (!fp_get_props) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1043 | // No EnumerateInstanceExtensionProperties defined |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1044 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 1045 | } |
| 1046 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1047 | res = fp_get_props(NULL, &count, NULL); |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1048 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1049 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1050 | "loader_add_instance_extensions: Error getting Instance " |
| 1051 | "extension count from %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1052 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1053 | goto out; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1054 | } |
Jon Ashburn | 953bb3c | 2015-06-10 16:11:42 -0600 | [diff] [blame] | 1055 | |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 1056 | if (count == 0) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1057 | // No ExtensionProperties to report |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1058 | goto out; |
Courtney Goeltzenleuchter | 5c6cf47 | 2015-07-06 22:28:18 -0600 | [diff] [blame] | 1059 | } |
| 1060 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1061 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1062 | if (NULL == ext_props) { |
| 1063 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1064 | goto out; |
| 1065 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1066 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1067 | res = fp_get_props(NULL, &count, ext_props); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1068 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1069 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1070 | "loader_add_instance_extensions: Error getting Instance " |
| 1071 | "extensions from %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1072 | lib_name); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1073 | goto out; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1074 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1075 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1076 | for (i = 0; i < count; i++) { |
Courtney Goeltzenleuchter | 5304373 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 1077 | char spec_version[64]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1078 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1079 | bool ext_unsupported = wsi_unsupported_instance_extension(&ext_props[i]); |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 1080 | if (!ext_unsupported) { |
Mark Young | 02df1a8 | 2017-04-18 19:52:18 -0600 | [diff] [blame] | 1081 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_VERSION_MAJOR(ext_props[i].specVersion), |
| 1082 | VK_VERSION_MINOR(ext_props[i].specVersion), VK_VERSION_PATCH(ext_props[i].specVersion)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1083 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Instance Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 1084 | lib_name, spec_version); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 1085 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1086 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
| 1087 | if (res != VK_SUCCESS) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1088 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1089 | "loader_add_instance_extensions: Failed to add %s " |
| 1090 | "to Instance extension list", |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1091 | lib_name); |
| 1092 | goto out; |
| 1093 | } |
Jon Ashburn | 6fa520f | 2016-03-25 12:49:35 -0600 | [diff] [blame] | 1094 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1095 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 1096 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1097 | out: |
| 1098 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1099 | } |
| 1100 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1101 | // Initialize ext_list with the physical device extensions. |
| 1102 | // The extension properties are passed as inputs in count and ext_props. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1103 | static VkResult loader_init_device_extensions(const struct loader_instance *inst, struct loader_physical_device_term *phys_dev_term, |
| 1104 | uint32_t count, VkExtensionProperties *ext_props, |
| 1105 | struct loader_extension_list *ext_list) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1106 | VkResult res; |
| 1107 | uint32_t i; |
| 1108 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1109 | res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1110 | if (VK_SUCCESS != res) { |
| 1111 | return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | for (i = 0; i < count; i++) { |
| 1115 | char spec_version[64]; |
Mark Young | 02df1a8 | 2017-04-18 19:52:18 -0600 | [diff] [blame] | 1116 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_VERSION_MAJOR(ext_props[i].specVersion), |
| 1117 | VK_VERSION_MINOR(ext_props[i].specVersion), VK_VERSION_PATCH(ext_props[i].specVersion)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1118 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 1119 | phys_dev_term->this_icd_term->scanned_icd->lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1120 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1121 | if (res != VK_SUCCESS) return res; |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | return VK_SUCCESS; |
| 1125 | } |
| 1126 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1127 | VkResult loader_add_device_extensions(const struct loader_instance *inst, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1128 | PFN_vkEnumerateDeviceExtensionProperties fpEnumerateDeviceExtensionProperties, |
| 1129 | VkPhysicalDevice physical_device, const char *lib_name, |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 1130 | struct loader_extension_list *ext_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1131 | uint32_t i, count; |
| 1132 | VkResult res; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1133 | VkExtensionProperties *ext_props; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1134 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1135 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, NULL); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1136 | if (res == VK_SUCCESS && count > 0) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1137 | ext_props = loader_stack_alloc(count * sizeof(VkExtensionProperties)); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1138 | if (!ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1139 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1140 | "loader_add_device_extensions: Failed to allocate space" |
| 1141 | " for device extension properties."); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1142 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1143 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1144 | res = fpEnumerateDeviceExtensionProperties(physical_device, NULL, &count, ext_props); |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1145 | if (res != VK_SUCCESS) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1146 | return res; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 1147 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1148 | for (i = 0; i < count; i++) { |
| 1149 | char spec_version[64]; |
Mark Young | 02df1a8 | 2017-04-18 19:52:18 -0600 | [diff] [blame] | 1150 | (void)snprintf(spec_version, sizeof(spec_version), "%d.%d.%d", VK_VERSION_MAJOR(ext_props[i].specVersion), |
| 1151 | VK_VERSION_MINOR(ext_props[i].specVersion), VK_VERSION_PATCH(ext_props[i].specVersion)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1152 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Device Extension: %s (%s) version %s", ext_props[i].extensionName, |
| 1153 | lib_name, spec_version); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1154 | res = loader_add_to_ext_list(inst, ext_list, 1, &ext_props[i]); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1155 | if (res != VK_SUCCESS) { |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1156 | return res; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1157 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1158 | } |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1159 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1160 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1161 | "loader_add_device_extensions: Error getting physical " |
| 1162 | "device extension info count from library %s", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1163 | lib_name); |
Jon Ashburn | 00eb6c0 | 2015-11-02 17:40:01 -0700 | [diff] [blame] | 1164 | return res; |
| 1165 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1166 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1167 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1168 | } |
| 1169 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1170 | VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size) { |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 1171 | size_t capacity = 32 * element_size; |
| 1172 | list_info->count = 0; |
| 1173 | list_info->capacity = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1174 | list_info->list = loader_instance_heap_alloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 1175 | if (list_info->list == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1176 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1177 | "loader_init_generic_list: Failed to allocate space " |
| 1178 | "for generic list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1179 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1180 | } |
Mark Young | 84ba048 | 2016-09-02 11:45:00 -0600 | [diff] [blame] | 1181 | memset(list_info->list, 0, capacity); |
| 1182 | list_info->capacity = capacity; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1183 | return VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1184 | } |
| 1185 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1186 | void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1187 | loader_instance_heap_free(inst, list->list); |
Jon Ashburn | 6e6a216 | 2015-12-10 08:51:10 -0700 | [diff] [blame] | 1188 | list->count = 0; |
| 1189 | list->capacity = 0; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1190 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1191 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1192 | // Append non-duplicate extension properties defined in props to the given ext_list. |
| 1193 | // Return - Vk_SUCCESS on success |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1194 | VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list, |
| 1195 | uint32_t prop_list_count, const VkExtensionProperties *props) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1196 | uint32_t i; |
| 1197 | const VkExtensionProperties *cur_ext; |
| 1198 | |
| 1199 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1200 | VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1201 | if (VK_SUCCESS != res) { |
| 1202 | return res; |
| 1203 | } |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1204 | } |
| 1205 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1206 | for (i = 0; i < prop_list_count; i++) { |
| 1207 | cur_ext = &props[i]; |
| 1208 | |
| 1209 | // look for duplicates |
| 1210 | if (has_vk_extension_property(cur_ext, ext_list)) { |
| 1211 | continue; |
| 1212 | } |
| 1213 | |
| 1214 | // add to list at end |
| 1215 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1216 | if (ext_list->count * sizeof(VkExtensionProperties) >= ext_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1217 | void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1218 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1219 | if (new_ptr == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1220 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1221 | "loader_add_to_ext_list: Failed to reallocate " |
| 1222 | "space for extension list"); |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1223 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1224 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1225 | ext_list->list = new_ptr; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1226 | |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1227 | // double capacity |
| 1228 | ext_list->capacity *= 2; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1229 | } |
| 1230 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1231 | memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(VkExtensionProperties)); |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1232 | ext_list->count++; |
| 1233 | } |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 1234 | return VK_SUCCESS; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 1235 | } |
| 1236 | |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 1237 | // Append one extension property defined in props with entrypoints defined in entries to the given |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1238 | // ext_list. Do not append if a duplicate. |
| 1239 | // Return - Vk_SUCCESS on success |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1240 | VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct loader_device_extension_list *ext_list, |
| 1241 | const VkExtensionProperties *props, uint32_t entry_count, char **entrys) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1242 | uint32_t idx; |
| 1243 | if (ext_list->list == NULL || ext_list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1244 | VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(struct loader_dev_ext_props)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1245 | if (VK_SUCCESS != res) { |
| 1246 | return res; |
| 1247 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Jon Ashburn | b872696 | 2016-04-08 15:03:35 -0600 | [diff] [blame] | 1250 | // look for duplicates |
| 1251 | if (has_vk_dev_ext_property(props, ext_list)) { |
| 1252 | return VK_SUCCESS; |
| 1253 | } |
| 1254 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1255 | idx = ext_list->count; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1256 | // add to list at end |
| 1257 | // check for enough capacity |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1258 | if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1259 | void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2, |
| 1260 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1261 | |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1262 | if (NULL == new_ptr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1263 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1264 | "loader_add_to_dev_ext_list: Failed to reallocate space for device extension list"); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1265 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1266 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1267 | ext_list->list = new_ptr; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1268 | |
| 1269 | // double capacity |
| 1270 | ext_list->capacity *= 2; |
| 1271 | } |
| 1272 | |
GabrÃel Arthúr Pétursson | 7151014 | 2017-06-03 01:38:49 +0000 | [diff] [blame] | 1273 | memcpy(&ext_list->list[idx].props, props, sizeof(*props)); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1274 | ext_list->list[idx].entrypoint_count = entry_count; |
Mark Young | 3f7a3b3 | 2017-06-26 14:03:08 -0600 | [diff] [blame] | 1275 | if (entry_count == 0) { |
| 1276 | ext_list->list[idx].entrypoints = NULL; |
| 1277 | } else { |
| 1278 | ext_list->list[idx].entrypoints = |
| 1279 | loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1280 | if (ext_list->list[idx].entrypoints == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1281 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1282 | "loader_add_to_dev_ext_list: Failed to allocate space " |
Mark Young | 3f7a3b3 | 2017-06-26 14:03:08 -0600 | [diff] [blame] | 1283 | "for device extension entrypoint list in list %d", |
| 1284 | idx); |
| 1285 | ext_list->list[idx].entrypoint_count = 0; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1286 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1287 | } |
Mark Young | 3f7a3b3 | 2017-06-26 14:03:08 -0600 | [diff] [blame] | 1288 | for (uint32_t i = 0; i < entry_count; i++) { |
| 1289 | ext_list->list[idx].entrypoints[i] = |
| 1290 | loader_instance_heap_alloc(inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1291 | if (ext_list->list[idx].entrypoints[i] == NULL) { |
| 1292 | for (uint32_t j = 0; j < i; j++) { |
| 1293 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints[j]); |
| 1294 | } |
| 1295 | loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); |
| 1296 | ext_list->list[idx].entrypoint_count = 0; |
| 1297 | ext_list->list[idx].entrypoints = NULL; |
| 1298 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1299 | "loader_add_to_dev_ext_list: Failed to allocate space " |
| 1300 | "for device extension entrypoint %d name", |
| 1301 | i); |
| 1302 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1303 | } |
| 1304 | strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); |
| 1305 | } |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1306 | } |
| 1307 | ext_list->count++; |
| 1308 | |
| 1309 | return VK_SUCCESS; |
| 1310 | } |
| 1311 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1312 | // Prototype of loader_add_meta_layer function since we use it in the loader_add_implicit_layer, but can also |
| 1313 | // call loader_add_implicit_layer from loader_add_meta_layer. |
| 1314 | bool loader_add_meta_layer(const struct loader_instance *inst, const struct loader_layer_properties *prop, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1315 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 1316 | const struct loader_layer_list *source_list); |
| 1317 | |
| 1318 | // Search the given layer list for a list matching the given VkLayerProperties |
| 1319 | bool has_vk_layer_property(const VkLayerProperties *vk_layer_prop, const struct loader_layer_list *list) { |
| 1320 | for (uint32_t i = 0; i < list->count; i++) { |
| 1321 | if (strcmp(vk_layer_prop->layerName, list->list[i].info.layerName) == 0) return true; |
| 1322 | } |
| 1323 | return false; |
| 1324 | } |
| 1325 | |
| 1326 | // Search the given layer list for a layer matching the given name |
| 1327 | bool has_layer_name(const char *name, const struct loader_layer_list *list) { |
| 1328 | for (uint32_t i = 0; i < list->count; i++) { |
| 1329 | if (strcmp(name, list->list[i].info.layerName) == 0) return true; |
| 1330 | } |
| 1331 | return false; |
| 1332 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1333 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1334 | // Search the given search_list for any layers in the props list. Add these to the |
| 1335 | // output layer_list. Don't add duplicates to the output layer_list. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1336 | static VkResult loader_add_layer_names_to_list(const struct loader_instance *inst, struct loader_layer_list *output_list, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1337 | struct loader_layer_list *expanded_output_list, uint32_t name_count, |
| 1338 | const char *const *names, const struct loader_layer_list *source_list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1339 | struct loader_layer_properties *layer_prop; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1340 | VkResult err = VK_SUCCESS; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1341 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1342 | for (uint32_t i = 0; i < name_count; i++) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1343 | const char *source_name = names[i]; |
| 1344 | layer_prop = loader_get_layer_property(source_name, source_list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1345 | if (NULL == layer_prop) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1346 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1347 | "loader_add_layer_names_to_list: Unable to find layer" |
| 1348 | " %s", |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1349 | source_name); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 1350 | err = VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1351 | continue; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1352 | } |
| 1353 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1354 | // If not a meta-layer, simply add it. |
| 1355 | if (0 == (layer_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1356 | if (!has_vk_layer_property(&layer_prop->info, output_list)) { |
| 1357 | loader_add_to_layer_list(inst, output_list, 1, layer_prop); |
| 1358 | } |
| 1359 | if (!has_vk_layer_property(&layer_prop->info, expanded_output_list)) { |
| 1360 | loader_add_to_layer_list(inst, expanded_output_list, 1, layer_prop); |
| 1361 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1362 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1363 | if (!has_vk_layer_property(&layer_prop->info, output_list) || |
| 1364 | !has_vk_layer_property(&layer_prop->info, expanded_output_list)) { |
| 1365 | loader_add_meta_layer(inst, layer_prop, output_list, expanded_output_list, source_list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1366 | } |
| 1367 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1368 | } |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 1369 | |
| 1370 | return err; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1371 | } |
| 1372 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1373 | // Manage lists of VkLayerProperties |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1374 | static bool loader_init_layer_list(const struct loader_instance *inst, struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1375 | list->capacity = 32 * sizeof(struct loader_layer_properties); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1376 | list->list = loader_instance_heap_alloc(inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1377 | if (list->list == NULL) { |
| 1378 | return false; |
| 1379 | } |
| 1380 | memset(list->list, 0, list->capacity); |
| 1381 | list->count = 0; |
| 1382 | return true; |
| 1383 | } |
| 1384 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1385 | void loader_destroy_layer_list(const struct loader_instance *inst, struct loader_device *device, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1386 | struct loader_layer_list *layer_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1387 | if (device) { |
| 1388 | loader_device_heap_free(device, layer_list->list); |
| 1389 | } else { |
| 1390 | loader_instance_heap_free(inst, layer_list->list); |
| 1391 | } |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1392 | layer_list->count = 0; |
| 1393 | layer_list->capacity = 0; |
| 1394 | } |
| 1395 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1396 | // Append non-duplicate layer properties defined in prop_list to the given layer_info list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1397 | VkResult loader_add_to_layer_list(const struct loader_instance *inst, struct loader_layer_list *list, uint32_t prop_list_count, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1398 | const struct loader_layer_properties *props) { |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1399 | uint32_t i; |
Lenny Komow | 397f9d4 | 2017-10-25 15:26:15 -0600 | [diff] [blame] | 1400 | uint16_t layer_api_major_version; |
| 1401 | uint16_t layer_api_minor_version; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1402 | struct loader_layer_properties *layer; |
| 1403 | |
| 1404 | if (list->list == NULL || list->capacity == 0) { |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 1405 | loader_init_layer_list(inst, list); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1406 | } |
| 1407 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1408 | if (list->list == NULL) return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1409 | |
| 1410 | for (i = 0; i < prop_list_count; i++) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1411 | layer = (struct loader_layer_properties *)&props[i]; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1412 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1413 | // Look for duplicates, and skip |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1414 | if (has_vk_layer_property(&layer->info, list)) { |
| 1415 | continue; |
| 1416 | } |
| 1417 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1418 | // Check for enough capacity |
| 1419 | if (((list->count + 1) * sizeof(struct loader_layer_properties)) >= list->capacity) { |
| 1420 | size_t new_capacity = list->capacity * 2; |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1421 | void *new_ptr = |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1422 | loader_instance_heap_realloc(inst, list->list, list->capacity, new_capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1423 | if (NULL == new_ptr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1424 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1425 | "loader_add_to_layer_list: Realloc failed for when attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1426 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1427 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1428 | list->list = new_ptr; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1429 | list->capacity = new_capacity; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1430 | } |
| 1431 | |
Lenny Komow | 397f9d4 | 2017-10-25 15:26:15 -0600 | [diff] [blame] | 1432 | // Verify that the layer api version is at least that of the application's request, if not, throw a warning since |
| 1433 | // undefined behavior could occur. |
| 1434 | layer_api_major_version = VK_VERSION_MAJOR(props[i].info.specVersion); |
| 1435 | layer_api_minor_version = VK_VERSION_MINOR(props[i].info.specVersion); |
| 1436 | if (inst->app_api_major_version > layer_api_major_version || |
| 1437 | (inst->app_api_major_version == layer_api_major_version && inst->app_api_minor_version > layer_api_minor_version)) { |
| 1438 | loader_log( |
| 1439 | inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1440 | "loader_add_to_layer_list: Explicit layer %s is using an old API version %d.%d versus application requested %d.%d", |
| 1441 | props[i].info.layerName, layer_api_major_version, layer_api_minor_version, inst->app_api_major_version,- inst->app_api_minor_version); |
| 1442 | } |
| 1443 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1444 | memcpy(&list->list[list->count], layer, sizeof(struct loader_layer_properties)); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1445 | list->count++; |
| 1446 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1447 | |
| 1448 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1449 | } |
| 1450 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1451 | // Check the individual implicit layer for the enable/disable environment variable settings. Only add it after |
| 1452 | // every check has passed indicating it should be used. |
| 1453 | static void loader_add_implicit_layer(const struct loader_instance *inst, const struct loader_layer_properties *prop, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1454 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 1455 | const struct loader_layer_list *source_list) { |
Jean-Francois Roy | bd7ceab | 2017-07-06 14:10:13 -0700 | [diff] [blame] | 1456 | bool enable = loader_is_implicit_layer_enabled(inst, prop); |
Lenny Komow | 397f9d4 | 2017-10-25 15:26:15 -0600 | [diff] [blame] | 1457 | |
| 1458 | // If the implicit layer is supposed to be enable, make sure the layer supports at least the same API version |
| 1459 | // that the application is asking (i.e. layer's API >= app's API). If it's not, disable this layer. |
| 1460 | if (enable) { |
| 1461 | uint16_t layer_api_major_version = VK_VERSION_MAJOR(prop->info.specVersion); |
| 1462 | uint16_t layer_api_minor_version = VK_VERSION_MINOR(prop->info.specVersion); |
| 1463 | if (inst->app_api_major_version > layer_api_major_version || |
| 1464 | (inst->app_api_major_version == layer_api_major_version && inst->app_api_minor_version > layer_api_minor_version)) { |
| 1465 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 1466 | "loader_add_implicit_layer: Disabling implicit layer %s for using an old API version %d.%d versus " |
| 1467 | "application requested %d.%d", |
| 1468 | prop->info.layerName, layer_api_major_version, layer_api_minor_version, inst->app_api_major_version, |
| 1469 | inst->app_api_minor_version); |
| 1470 | enable = false; |
| 1471 | } |
| 1472 | } |
| 1473 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1474 | if (enable) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1475 | if (0 == (prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) { |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1476 | if (NULL != target_list && !has_vk_layer_property(&prop->info, target_list)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1477 | loader_add_to_layer_list(inst, target_list, 1, prop); |
| 1478 | } |
| 1479 | if (NULL != expanded_target_list && !has_vk_layer_property(&prop->info, expanded_target_list)) { |
| 1480 | loader_add_to_layer_list(inst, expanded_target_list, 1, prop); |
| 1481 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1482 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1483 | if (!has_vk_layer_property(&prop->info, target_list) || |
| 1484 | (NULL != expanded_target_list && !has_vk_layer_property(&prop->info, expanded_target_list))) { |
| 1485 | loader_add_meta_layer(inst, prop, target_list, expanded_target_list, source_list); |
| 1486 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | // Add the component layers of a meta-layer to the active list of layers |
| 1492 | bool loader_add_meta_layer(const struct loader_instance *inst, const struct loader_layer_properties *prop, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1493 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 1494 | const struct loader_layer_list *source_list) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1495 | bool found = true; |
| 1496 | |
| 1497 | // We need to add all the individual component layers |
| 1498 | for (uint32_t comp_layer = 0; comp_layer < prop->num_component_layers; comp_layer++) { |
| 1499 | bool found_comp = false; |
| 1500 | const struct loader_layer_properties *search_prop = |
| 1501 | loader_get_layer_property(prop->component_layer_names[comp_layer], source_list); |
| 1502 | if (search_prop != NULL) { |
| 1503 | found_comp = true; |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1504 | |
| 1505 | // If the component layer is itself an implicit layer, we need to do the implicit layer enable |
| 1506 | // checks |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1507 | if (0 == (search_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1508 | loader_add_implicit_layer(inst, search_prop, target_list, expanded_target_list, source_list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1509 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1510 | if (NULL != expanded_target_list && !has_vk_layer_property(&search_prop->info, expanded_target_list)) { |
| 1511 | loader_add_to_layer_list(inst, expanded_target_list, 1, search_prop); |
| 1512 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | if (!found_comp) { |
| 1516 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1517 | "loader_add_meta_layer: Failed to find layer name %s component layer " |
| 1518 | "%s to activate", |
| 1519 | search_prop->info.layerName, prop->component_layer_names[comp_layer]); |
| 1520 | found = false; |
| 1521 | } |
| 1522 | } |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1523 | |
| 1524 | // Add this layer to the overall target list (not the expanded one) |
| 1525 | if (found && !has_vk_layer_property(&prop->info, target_list)) { |
| 1526 | loader_add_to_layer_list(inst, target_list, 1, prop); |
| 1527 | } |
| 1528 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1529 | return found; |
| 1530 | } |
| 1531 | |
| 1532 | // Search the source_list for any layer with a name that matches the given name and a type |
| 1533 | // that matches the given type. Add all matching layers to the target_list. |
| 1534 | // Do not add if found loader_layer_properties is already on the target_list. |
| 1535 | void loader_find_layer_name_add_list(const struct loader_instance *inst, const char *name, const enum layer_type_flags type_flags, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1536 | const struct loader_layer_list *source_list, struct loader_layer_list *target_list, |
| 1537 | struct loader_layer_list *expanded_target_list) { |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1538 | bool found = false; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1539 | for (uint32_t i = 0; i < source_list->count; i++) { |
| 1540 | struct loader_layer_properties *source_prop = &source_list->list[i]; |
| 1541 | if (0 == strcmp(source_prop->info.layerName, name) && (source_prop->type_flags & type_flags) == type_flags) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1542 | // If not a meta-layer, simply add it. |
| 1543 | if (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) { |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1544 | if (NULL != target_list && !has_vk_layer_property(&source_prop->info, target_list) && |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1545 | VK_SUCCESS == loader_add_to_layer_list(inst, target_list, 1, source_prop)) { |
| 1546 | found = true; |
| 1547 | } |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 1548 | if (NULL != expanded_target_list && !has_vk_layer_property(&source_prop->info, expanded_target_list) && |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1549 | VK_SUCCESS == loader_add_to_layer_list(inst, expanded_target_list, 1, source_prop)) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1550 | found = true; |
| 1551 | } |
| 1552 | } else { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1553 | found = loader_add_meta_layer(inst, source_prop, target_list, expanded_target_list, source_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1554 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1555 | } |
| 1556 | } |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1557 | if (!found) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1558 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1559 | "loader_find_layer_name_add_list: Failed to find layer name %s to activate", name); |
Jon Ashburn | 56151d6 | 2015-10-05 09:03:21 -0600 | [diff] [blame] | 1560 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1561 | } |
| 1562 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1563 | static VkExtensionProperties *get_extension_property(const char *name, const struct loader_extension_list *list) { |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1564 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1565 | if (strcmp(name, list->list[i].extensionName) == 0) return &list->list[i]; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1566 | } |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 1567 | return NULL; |
Jon Ashburn | fc2e38c | 2015-04-14 09:15:32 -0600 | [diff] [blame] | 1568 | } |
| 1569 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1570 | static VkExtensionProperties *get_dev_extension_property(const char *name, const struct loader_device_extension_list *list) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1571 | for (uint32_t i = 0; i < list->count; i++) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1572 | if (strcmp(name, list->list[i].props.extensionName) == 0) return &list->list[i].props; |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 1573 | } |
| 1574 | return NULL; |
| 1575 | } |
| 1576 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1577 | // For Instance extensions implemented within the loader (i.e. DEBUG_REPORT |
| 1578 | // the extension must provide two entry points for the loader to use: |
| 1579 | // - "trampoline" entry point - this is the address returned by GetProcAddr |
| 1580 | // and will always do what's necessary to support a |
| 1581 | // global call. |
| 1582 | // - "terminator" function - this function will be put at the end of the |
| 1583 | // instance chain and will contain the necessary logic |
| 1584 | // to call / process the extension for the appropriate |
| 1585 | // ICDs that are available. |
| 1586 | // There is no generic mechanism for including these functions, the references |
| 1587 | // must be placed into the appropriate loader entry points. |
| 1588 | // GetInstanceProcAddr: call extension GetInstanceProcAddr to check for GetProcAddr |
| 1589 | // requests |
| 1590 | // loader_coalesce_extensions(void) - add extension records to the list of global |
| 1591 | // extension available to the app. |
| 1592 | // instance_disp - add function pointer for terminator function |
| 1593 | // to this array. |
| 1594 | // The extension itself should be in a separate file that will be linked directly |
| 1595 | // with the loader. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1596 | VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, |
| 1597 | struct loader_extension_list *inst_exts) { |
Jon Ashburn | 5c6a46f | 2015-08-14 14:49:22 -0600 | [diff] [blame] | 1598 | struct loader_extension_list icd_exts; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1599 | VkResult res = VK_SUCCESS; |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1600 | char *env_value; |
| 1601 | bool filter_extensions = true; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1602 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1603 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Build ICD instance extension list"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1604 | |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1605 | // Check if a user wants to disable the instance extension filtering behavior |
| 1606 | env_value = loader_getenv("VK_LOADER_DISABLE_INST_EXT_FILTER", inst); |
| 1607 | if (NULL != env_value && atoi(env_value) != 0) { |
| 1608 | filter_extensions = false; |
| 1609 | } |
| 1610 | loader_free_getenv(env_value, inst); |
| 1611 | |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1612 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1613 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1614 | res = loader_init_generic_list(inst, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1615 | if (VK_SUCCESS != res) { |
| 1616 | goto out; |
| 1617 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1618 | res = loader_add_instance_extensions(inst, icd_tramp_list->scanned_list[i].EnumerateInstanceExtensionProperties, |
| 1619 | icd_tramp_list->scanned_list[i].lib_name, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1620 | if (VK_SUCCESS == res) { |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1621 | if (filter_extensions) { |
| 1622 | // Remove any extensions not recognized by the loader |
| 1623 | for (int32_t j = 0; j < (int32_t)icd_exts.count; j++) { |
| 1624 | // See if the extension is in the list of supported extensions |
| 1625 | bool found = false; |
| 1626 | for (uint32_t k = 0; LOADER_INSTANCE_EXTENSIONS[k] != NULL; k++) { |
| 1627 | if (strcmp(icd_exts.list[j].extensionName, LOADER_INSTANCE_EXTENSIONS[k]) == 0) { |
| 1628 | found = true; |
| 1629 | break; |
| 1630 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1631 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1632 | |
Mark Young | 2b2ece7 | 2017-02-10 11:19:02 -0700 | [diff] [blame] | 1633 | // If it isn't in the list, remove it |
| 1634 | if (!found) { |
| 1635 | for (uint32_t k = j + 1; k < icd_exts.count; k++) { |
| 1636 | icd_exts.list[k - 1] = icd_exts.list[k]; |
| 1637 | } |
| 1638 | --icd_exts.count; |
| 1639 | --j; |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1640 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 1641 | } |
| 1642 | } |
| 1643 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1644 | res = loader_add_to_ext_list(inst, inst_exts, icd_exts.count, icd_exts.list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1645 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1646 | loader_destroy_generic_list(inst, (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1647 | if (VK_SUCCESS != res) { |
| 1648 | goto out; |
| 1649 | } |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1650 | }; |
| 1651 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1652 | // Traverse loader's extensions, adding non-duplicate extensions to the list |
Mark Young | 6ba8abe | 2017-11-09 10:37:04 -0700 | [diff] [blame] | 1653 | debug_utils_AddInstanceExtensions(inst, inst_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1654 | |
| 1655 | out: |
| 1656 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1657 | } |
| 1658 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1659 | struct loader_icd_term *loader_get_icd_and_device(const VkDevice device, struct loader_device **found_dev, uint32_t *icd_index) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1660 | *found_dev = NULL; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1661 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
Lenny Komow | 2716731 | 2017-03-31 13:43:35 -0600 | [diff] [blame] | 1662 | uint32_t index = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1663 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term; icd_term = icd_term->next) { |
| 1664 | for (struct loader_device *dev = icd_term->logical_device_list; dev; dev = dev->next) |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 1665 | // Value comparison of device prevents object wrapping by layers |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1666 | if (loader_get_dispatch(dev->icd_device) == loader_get_dispatch(device) || |
| 1667 | loader_get_dispatch(dev->chain_device) == loader_get_dispatch(device)) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1668 | *found_dev = dev; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1669 | if (NULL != icd_index) { |
| 1670 | *icd_index = index; |
| 1671 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1672 | return icd_term; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1673 | } |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 1674 | index++; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | return NULL; |
| 1678 | } |
| 1679 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1680 | void loader_destroy_logical_device(const struct loader_instance *inst, struct loader_device *dev, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1681 | const VkAllocationCallbacks *pAllocator) { |
| 1682 | if (pAllocator) { |
| 1683 | dev->alloc_callbacks = *pAllocator; |
| 1684 | } |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 1685 | if (NULL != dev->expanded_activated_layer_list.list) { |
| 1686 | loader_deactivate_layers(inst, dev, &dev->expanded_activated_layer_list); |
| 1687 | } |
| 1688 | if (NULL != dev->app_activated_layer_list.list) { |
| 1689 | loader_destroy_layer_list(inst, dev, &dev->app_activated_layer_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1690 | } |
| 1691 | loader_device_heap_free(dev, dev); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1692 | } |
| 1693 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1694 | struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1695 | struct loader_device *new_dev; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1696 | #if (DEBUG_DISABLE_APP_ALLOCATORS == 1) |
| 1697 | { |
| 1698 | #else |
| 1699 | if (pAllocator) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1700 | new_dev = (struct loader_device *)pAllocator->pfnAllocation(pAllocator->pUserData, sizeof(struct loader_device), |
| 1701 | sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1702 | } else { |
| 1703 | #endif |
| 1704 | new_dev = (struct loader_device *)malloc(sizeof(struct loader_device)); |
| 1705 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1706 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1707 | if (!new_dev) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1708 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1709 | "loader_create_logical_device: Failed to alloc struct " |
| 1710 | "loader_device"); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1711 | return NULL; |
| 1712 | } |
| 1713 | |
| 1714 | memset(new_dev, 0, sizeof(struct loader_device)); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1715 | if (pAllocator) { |
| 1716 | new_dev->alloc_callbacks = *pAllocator; |
| 1717 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1718 | |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1719 | return new_dev; |
| 1720 | } |
| 1721 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1722 | void loader_add_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term, struct loader_device *dev) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1723 | dev->next = icd_term->logical_device_list; |
| 1724 | icd_term->logical_device_list = dev; |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 1725 | } |
| 1726 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1727 | void loader_remove_logical_device(const struct loader_instance *inst, struct loader_icd_term *icd_term, |
| 1728 | struct loader_device *found_dev, const VkAllocationCallbacks *pAllocator) { |
Jon Ashburn | 781a7ae | 2015-11-19 15:43:26 -0700 | [diff] [blame] | 1729 | struct loader_device *dev, *prev_dev; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1730 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1731 | if (!icd_term || !found_dev) return; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1732 | |
| 1733 | prev_dev = NULL; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1734 | dev = icd_term->logical_device_list; |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1735 | while (dev && dev != found_dev) { |
| 1736 | prev_dev = dev; |
| 1737 | dev = dev->next; |
| 1738 | } |
| 1739 | |
| 1740 | if (prev_dev) |
| 1741 | prev_dev->next = found_dev->next; |
| 1742 | else |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1743 | icd_term->logical_device_list = found_dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1744 | loader_destroy_logical_device(inst, found_dev, pAllocator); |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1745 | } |
| 1746 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1747 | static void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1748 | const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1749 | ptr_inst->total_icd_count--; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1750 | for (struct loader_device *dev = icd_term->logical_device_list; dev;) { |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1751 | struct loader_device *next_dev = dev->next; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1752 | loader_destroy_logical_device(ptr_inst, dev, pAllocator); |
Courtney Goeltzenleuchter | 1f157ac | 2015-06-14 19:57:15 -0600 | [diff] [blame] | 1753 | dev = next_dev; |
| 1754 | } |
Jon Ashburn | dc6fcad | 2015-06-10 10:06:06 -0600 | [diff] [blame] | 1755 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1756 | loader_instance_heap_free(ptr_inst, icd_term); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1757 | } |
| 1758 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1759 | static struct loader_icd_term *loader_icd_create(const struct loader_instance *inst) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1760 | struct loader_icd_term *icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1761 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1762 | icd_term = loader_instance_heap_alloc(inst, sizeof(struct loader_icd_term), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1763 | if (!icd_term) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1764 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1765 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1766 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1767 | memset(icd_term, 0, sizeof(struct loader_icd_term)); |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 1768 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1769 | return icd_term; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1770 | } |
| 1771 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1772 | static struct loader_icd_term *loader_icd_add(struct loader_instance *ptr_inst, const struct loader_scanned_icd *scanned_icd) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1773 | struct loader_icd_term *icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1774 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1775 | icd_term = loader_icd_create(ptr_inst); |
| 1776 | if (!icd_term) { |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1777 | return NULL; |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 1778 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1779 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1780 | icd_term->scanned_icd = scanned_icd; |
| 1781 | icd_term->this_instance = ptr_inst; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 1782 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1783 | // Prepend to the list |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1784 | icd_term->next = ptr_inst->icd_terms; |
| 1785 | ptr_inst->icd_terms = icd_term; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1786 | ptr_inst->total_icd_count++; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1787 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1788 | return icd_term; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1789 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1790 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1791 | // Determine the ICD interface version to use. |
| 1792 | // @param icd |
| 1793 | // @param pVersion Output parameter indicating which version to use or 0 if |
| 1794 | // the negotiation API is not supported by the ICD |
| 1795 | // @return bool indicating true if the selected interface version is supported |
| 1796 | // by the loader, false indicates the version is not supported |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1797 | bool loader_get_icd_interface_version(PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version, uint32_t *pVersion) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1798 | if (fp_negotiate_icd_version == NULL) { |
| 1799 | // ICD does not support the negotiation API, it supports version 0 or 1 |
| 1800 | // calling code must determine if it is version 0 or 1 |
| 1801 | *pVersion = 0; |
| 1802 | } else { |
| 1803 | // ICD supports the negotiation API, so call it with the loader's |
| 1804 | // latest version supported |
| 1805 | *pVersion = CURRENT_LOADER_ICD_INTERFACE_VERSION; |
| 1806 | VkResult result = fp_negotiate_icd_version(pVersion); |
| 1807 | |
| 1808 | if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { |
| 1809 | // ICD no longer supports the loader's latest interface version so |
| 1810 | // fail loading the ICD |
| 1811 | return false; |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | #if MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION > 0 |
| 1816 | if (*pVersion < MIN_SUPPORTED_LOADER_ICD_INTERFACE_VERSION) { |
| 1817 | // Loader no longer supports the ICD's latest interface version so fail |
| 1818 | // loading the ICD |
| 1819 | return false; |
| 1820 | } |
| 1821 | #endif |
| 1822 | return true; |
| 1823 | } |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 1824 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1825 | void loader_scanned_icd_clear(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 1826 | if (0 != icd_tramp_list->capacity) { |
| 1827 | for (uint32_t i = 0; i < icd_tramp_list->count; i++) { |
| 1828 | loader_platform_close_library(icd_tramp_list->scanned_list[i].handle); |
| 1829 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list[i].lib_name); |
| 1830 | } |
| 1831 | loader_instance_heap_free(inst, icd_tramp_list->scanned_list); |
| 1832 | icd_tramp_list->capacity = 0; |
| 1833 | icd_tramp_list->count = 0; |
| 1834 | icd_tramp_list->scanned_list = NULL; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1835 | } |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1836 | } |
| 1837 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1838 | static VkResult loader_scanned_icd_init(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1839 | VkResult err = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1840 | loader_scanned_icd_clear(inst, icd_tramp_list); |
| 1841 | icd_tramp_list->capacity = 8 * sizeof(struct loader_scanned_icd); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1842 | icd_tramp_list->scanned_list = loader_instance_heap_alloc(inst, icd_tramp_list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1843 | if (NULL == icd_tramp_list->scanned_list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1844 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1845 | "loader_scanned_icd_init: Realloc failed for layer list when " |
| 1846 | "attempting to add new layer"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1847 | err = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 1848 | } |
| 1849 | return err; |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1850 | } |
| 1851 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1852 | static VkResult loader_scanned_icd_add(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list, |
| 1853 | const char *filename, uint32_t api_version) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1854 | loader_platform_dl_handle handle; |
Tony Barbour | 1d2cd3f | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 1855 | PFN_vkCreateInstance fp_create_inst; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1856 | PFN_vkEnumerateInstanceExtensionProperties fp_get_inst_ext_props; |
Jon Ashburn | c624c88 | 2015-07-16 10:17:29 -0600 | [diff] [blame] | 1857 | PFN_vkGetInstanceProcAddr fp_get_proc_addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1858 | PFN_GetPhysicalDeviceProcAddr fp_get_phys_dev_proc_addr = NULL; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1859 | PFN_vkNegotiateLoaderICDInterfaceVersion fp_negotiate_icd_version; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1860 | struct loader_scanned_icd *new_scanned_icd; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1861 | uint32_t interface_vers; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1862 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1863 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1864 | // TODO implement smarter opening/closing of libraries. For now this |
| 1865 | // function leaves libraries open and the scanned_icd_clear closes them |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1866 | handle = loader_platform_open_library(filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1867 | if (NULL == handle) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1868 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, loader_platform_open_library_error(filename)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1869 | goto out; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1872 | // Get and settle on an ICD interface version |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1873 | fp_negotiate_icd_version = loader_platform_get_proc_address(handle, "vk_icdNegotiateLoaderICDInterfaceVersion"); |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1874 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1875 | if (!loader_get_icd_interface_version(fp_negotiate_icd_version, &interface_vers)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1876 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1877 | "loader_scanned_icd_add: ICD %s doesn't support interface" |
| 1878 | " version compatible with loader, skip this ICD.", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1879 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1880 | goto out; |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1881 | } |
| 1882 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1883 | fp_get_proc_addr = loader_platform_get_proc_address(handle, "vk_icdGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1884 | if (NULL == fp_get_proc_addr) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1885 | assert(interface_vers == 0); |
| 1886 | // Use deprecated interface from version 0 |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1887 | fp_get_proc_addr = loader_platform_get_proc_address(handle, "vkGetInstanceProcAddr"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1888 | if (NULL == fp_get_proc_addr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1889 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 1890 | "loader_scanned_icd_add: Attempt to retrieve either " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1891 | "\'vkGetInstanceProcAddr\' or " |
| 1892 | "\'vk_icdGetInstanceProcAddr\' from ICD %s failed.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1893 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1894 | goto out; |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1895 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1896 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 1897 | "loader_scanned_icd_add: Using deprecated ICD " |
| 1898 | "interface of \'vkGetInstanceProcAddr\' instead of " |
| 1899 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1900 | filename); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1901 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1902 | fp_create_inst = loader_platform_get_proc_address(handle, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1903 | if (NULL == fp_create_inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1904 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1905 | "loader_scanned_icd_add: Failed querying " |
| 1906 | "\'vkCreateInstance\' via dlsym/loadlibrary for " |
| 1907 | "ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1908 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1909 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1910 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1911 | fp_get_inst_ext_props = loader_platform_get_proc_address(handle, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1912 | if (NULL == fp_get_inst_ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1913 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1914 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1915 | "InstanceExtensionProperties\' via dlsym/loadlibrary " |
| 1916 | "for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1917 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1918 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1919 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1920 | } else { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1921 | // Use newer interface version 1 or later |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1922 | if (interface_vers == 0) { |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1923 | interface_vers = 1; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1924 | } |
Jon Ashburn | 17b4c86 | 2016-04-25 11:09:37 -0600 | [diff] [blame] | 1925 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1926 | fp_create_inst = (PFN_vkCreateInstance)fp_get_proc_addr(NULL, "vkCreateInstance"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1927 | if (NULL == fp_create_inst) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1928 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1929 | "loader_scanned_icd_add: Could not get " |
| 1930 | "\'vkCreateInstance\' via \'vk_icdGetInstanceProcAddr\'" |
| 1931 | " for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1932 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1933 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1934 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1935 | fp_get_inst_ext_props = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1936 | (PFN_vkEnumerateInstanceExtensionProperties)fp_get_proc_addr(NULL, "vkEnumerateInstanceExtensionProperties"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 1937 | if (NULL == fp_get_inst_ext_props) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1938 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 1939 | "loader_scanned_icd_add: Could not get \'vkEnumerate" |
| 1940 | "InstanceExtensionProperties\' via " |
| 1941 | "\'vk_icdGetInstanceProcAddr\' for ICD %s", |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1942 | filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1943 | goto out; |
Jon Ashburn | 69a5f7a | 2016-01-11 14:41:35 -0700 | [diff] [blame] | 1944 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1945 | fp_get_phys_dev_proc_addr = loader_platform_get_proc_address(handle, "vk_icdGetPhysicalDeviceProcAddr"); |
Jon Ashburn | fd4d09d | 2016-01-07 09:44:27 -0700 | [diff] [blame] | 1946 | } |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1947 | |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 1948 | // check for enough capacity |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1949 | if ((icd_tramp_list->count * sizeof(struct loader_scanned_icd)) >= icd_tramp_list->capacity) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1950 | void *new_ptr = loader_instance_heap_realloc(inst, icd_tramp_list->scanned_list, icd_tramp_list->capacity, |
| 1951 | icd_tramp_list->capacity * 2, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 1952 | if (NULL == new_ptr) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1953 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1954 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1955 | "loader_scanned_icd_add: Realloc failed on icd library list for ICD %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1956 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1957 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 1958 | icd_tramp_list->scanned_list = new_ptr; |
| 1959 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1960 | // double capacity |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1961 | icd_tramp_list->capacity *= 2; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1964 | new_scanned_icd = &(icd_tramp_list->scanned_list[icd_tramp_list->count]); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1965 | new_scanned_icd->handle = handle; |
| 1966 | new_scanned_icd->api_version = api_version; |
| 1967 | new_scanned_icd->GetInstanceProcAddr = fp_get_proc_addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 1968 | new_scanned_icd->GetPhysicalDeviceProcAddr = fp_get_phys_dev_proc_addr; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1969 | new_scanned_icd->EnumerateInstanceExtensionProperties = fp_get_inst_ext_props; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1970 | new_scanned_icd->CreateInstance = fp_create_inst; |
| 1971 | new_scanned_icd->interface_version = interface_vers; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1972 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1973 | new_scanned_icd->lib_name = (char *)loader_instance_heap_alloc(inst, strlen(filename) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1974 | if (NULL == new_scanned_icd->lib_name) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 1975 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_scanned_icd_add: Out of memory can't add ICD %s", filename); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1976 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1977 | goto out; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1978 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 1979 | strcpy(new_scanned_icd->lib_name, filename); |
| 1980 | icd_tramp_list->count++; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 1981 | |
| 1982 | out: |
| 1983 | |
| 1984 | return res; |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1985 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1986 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 1987 | static void loader_debug_init(void) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1988 | char *env, *orig; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1989 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1990 | if (g_loader_debug > 0) return; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1991 | |
| 1992 | g_loader_debug = 0; |
| 1993 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 1994 | // Parse comma-separated debug options |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1995 | orig = env = loader_getenv("VK_LOADER_DEBUG", NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1996 | while (env) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 1997 | char *p = strchr(env, ','); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 1998 | size_t len; |
| 1999 | |
| 2000 | if (p) |
| 2001 | len = p - env; |
| 2002 | else |
| 2003 | len = strlen(env); |
| 2004 | |
| 2005 | if (len > 0) { |
Michael Worcester | 25c73e7 | 2015-12-10 18:06:24 +0000 | [diff] [blame] | 2006 | if (strncmp(env, "all", len) == 0) { |
| 2007 | g_loader_debug = ~0u; |
| 2008 | g_loader_log_msgs = ~0u; |
| 2009 | } else if (strncmp(env, "warn", len) == 0) { |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2010 | g_loader_debug |= LOADER_WARN_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2011 | g_loader_log_msgs |= VK_DEBUG_REPORT_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2012 | } else if (strncmp(env, "info", len) == 0) { |
| 2013 | g_loader_debug |= LOADER_INFO_BIT; |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 2014 | g_loader_log_msgs |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2015 | } else if (strncmp(env, "perf", len) == 0) { |
| 2016 | g_loader_debug |= LOADER_PERF_BIT; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2017 | g_loader_log_msgs |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2018 | } else if (strncmp(env, "error", len) == 0) { |
| 2019 | g_loader_debug |= LOADER_ERROR_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2020 | g_loader_log_msgs |= VK_DEBUG_REPORT_ERROR_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2021 | } else if (strncmp(env, "debug", len) == 0) { |
| 2022 | g_loader_debug |= LOADER_DEBUG_BIT; |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 2023 | g_loader_log_msgs |= VK_DEBUG_REPORT_DEBUG_BIT_EXT; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2024 | } |
| 2025 | } |
| 2026 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2027 | if (!p) break; |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2028 | |
| 2029 | env = p + 1; |
| 2030 | } |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 2031 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2032 | loader_free_getenv(orig, NULL); |
Courtney Goeltzenleuchter | 880a2a7 | 2015-06-08 15:11:18 -0600 | [diff] [blame] | 2033 | } |
| 2034 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2035 | void loader_initialize(void) { |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2036 | // initialize mutexs |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2037 | loader_platform_thread_create_mutex(&loader_lock); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 2038 | loader_platform_thread_create_mutex(&loader_json_lock); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2039 | |
| 2040 | // initialize logging |
| 2041 | loader_debug_init(); |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 2042 | |
| 2043 | // initial cJSON to use alloc callbacks |
| 2044 | cJSON_Hooks alloc_fns = { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2045 | .malloc_fn = loader_instance_tls_heap_alloc, .free_fn = loader_instance_tls_heap_free, |
Jon Ashburn | 87d6aa9 | 2015-08-28 15:19:27 -0600 | [diff] [blame] | 2046 | }; |
| 2047 | cJSON_InitHooks(&alloc_fns); |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 2048 | } |
| 2049 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2050 | struct loader_manifest_files { |
| 2051 | uint32_t count; |
| 2052 | char **filename_list; |
| 2053 | }; |
| 2054 | |
Lenny Komow | 158e9d9 | 2018-01-15 15:43:36 -0700 | [diff] [blame] | 2055 | void loader_release() { |
| 2056 | // release mutexs |
| 2057 | loader_platform_thread_delete_mutex(&loader_lock); |
| 2058 | loader_platform_thread_delete_mutex(&loader_json_lock); |
| 2059 | } |
| 2060 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2061 | // Get next file or dirname given a string list or registry key path |
| 2062 | // |
| 2063 | // \returns |
| 2064 | // A pointer to first char in the next path. |
| 2065 | // The next path (or NULL) in the list is returned in next_path. |
| 2066 | // Note: input string is modified in some cases. PASS IN A COPY! |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2067 | static char *loader_get_next_path(char *path) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2068 | uint32_t len; |
| 2069 | char *next; |
| 2070 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2071 | if (path == NULL) return NULL; |
Frank Henigman | 5717310 | 2016-11-24 22:15:20 -0500 | [diff] [blame] | 2072 | next = strchr(path, PATH_SEPARATOR); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2073 | if (next == NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2074 | len = (uint32_t)strlen(path); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2075 | next = path + len; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2076 | } else { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2077 | *next = '\0'; |
| 2078 | next++; |
| 2079 | } |
| 2080 | |
| 2081 | return next; |
| 2082 | } |
| 2083 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2084 | // Given a path which is absolute or relative, expand the path if relative or |
| 2085 | // leave the path unmodified if absolute. The base path to prepend to relative |
| 2086 | // paths is given in rel_base. |
| 2087 | // |
| 2088 | // @return - A string in out_fullpath of the full absolute path |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2089 | static void loader_expand_path(const char *path, const char *rel_base, size_t out_size, char *out_fullpath) { |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2090 | if (loader_platform_is_path_absolute(path)) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2091 | // do not prepend a base to an absolute path |
| 2092 | rel_base = ""; |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2093 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2094 | |
| 2095 | loader_platform_combine_path(out_fullpath, out_size, rel_base, path, NULL); |
Jon Ashburn | 1531517 | 2015-07-07 15:06:25 -0600 | [diff] [blame] | 2096 | } |
| 2097 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2098 | // Given a filename (file) and a list of paths (dir), try to find an existing |
| 2099 | // file in the paths. If filename already is a path then no searching in the given paths. |
| 2100 | // |
| 2101 | // @return - A string in out_fullpath of either the full path or file. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2102 | static void loader_get_fullpath(const char *file, const char *dirs, size_t out_size, char *out_fullpath) { |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2103 | if (!loader_platform_is_path(file) && *dirs) { |
| 2104 | char *dirs_copy, *dir, *next_dir; |
| 2105 | |
| 2106 | dirs_copy = loader_stack_alloc(strlen(dirs) + 1); |
| 2107 | strcpy(dirs_copy, dirs); |
| 2108 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2109 | // find if file exists after prepending paths in given list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2110 | for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); dir = next_dir) { |
| 2111 | loader_platform_combine_path(out_fullpath, out_size, dir, file, NULL); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2112 | if (loader_platform_file_exists(out_fullpath)) { |
| 2113 | return; |
| 2114 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2115 | } |
| 2116 | } |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 2117 | |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 2118 | (void)snprintf(out_fullpath, out_size, "%s", file); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2119 | } |
| 2120 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2121 | // Read a JSON file into a buffer. |
| 2122 | // |
| 2123 | // @return - A pointer to a cJSON object representing the JSON parse tree. |
| 2124 | // This returned buffer should be freed by caller. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2125 | static VkResult loader_get_json(const struct loader_instance *inst, const char *filename, cJSON **json) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2126 | FILE *file = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2127 | char *json_buf; |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 2128 | size_t len; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2129 | VkResult res = VK_SUCCESS; |
| 2130 | |
| 2131 | if (NULL == json) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2132 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Received invalid JSON file"); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2133 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 2134 | goto out; |
| 2135 | } |
| 2136 | |
| 2137 | *json = NULL; |
| 2138 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2139 | file = fopen(filename, "rb"); |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2140 | if (!file) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2141 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Failed to open JSON file %s", filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2142 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2143 | goto out; |
Jon Ashburn | aa4ea47 | 2015-08-27 08:30:50 -0600 | [diff] [blame] | 2144 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2145 | fseek(file, 0, SEEK_END); |
| 2146 | len = ftell(file); |
| 2147 | fseek(file, 0, SEEK_SET); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2148 | json_buf = (char *)loader_stack_alloc(len + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2149 | if (json_buf == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2150 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2151 | "loader_get_json: Failed to allocate space for " |
| 2152 | "JSON file %s buffer of length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2153 | filename, len); |
| 2154 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2155 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2156 | } |
| 2157 | if (fread(json_buf, sizeof(char), len, file) != len) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2158 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_get_json: Failed to read JSON file %s.", filename); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2159 | res = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2160 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2161 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2162 | json_buf[len] = '\0'; |
| 2163 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2164 | // Parse text from file |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2165 | *json = cJSON_Parse(json_buf); |
| 2166 | if (*json == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2167 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2168 | "loader_get_json: Failed to parse JSON file %s, " |
| 2169 | "this is usually because something ran out of " |
| 2170 | "memory.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2171 | filename); |
| 2172 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 2173 | goto out; |
| 2174 | } |
| 2175 | |
| 2176 | out: |
| 2177 | if (NULL != file) { |
| 2178 | fclose(file); |
| 2179 | } |
| 2180 | |
| 2181 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 2182 | } |
| 2183 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2184 | // Do a deep copy of the loader_layer_properties structure. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2185 | VkResult loader_copy_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *dst, |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2186 | struct loader_layer_properties *src) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2187 | uint32_t cnt, i; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2188 | memcpy(dst, src, sizeof(*src)); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2189 | dst->instance_extension_list.list = loader_instance_heap_alloc( |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2190 | inst, sizeof(VkExtensionProperties) * src->instance_extension_list.count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2191 | if (NULL == dst->instance_extension_list.list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2192 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2193 | "loader_copy_layer_properties: Failed to allocate space " |
| 2194 | "for instance extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2195 | src->instance_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2196 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2197 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2198 | dst->instance_extension_list.capacity = sizeof(VkExtensionProperties) * src->instance_extension_list.count; |
| 2199 | memcpy(dst->instance_extension_list.list, src->instance_extension_list.list, dst->instance_extension_list.capacity); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2200 | dst->device_extension_list.list = loader_instance_heap_alloc( |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2201 | inst, sizeof(struct loader_dev_ext_props) * src->device_extension_list.count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2202 | if (NULL == dst->device_extension_list.list) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2203 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2204 | "loader_copy_layer_properties: Failed to allocate space " |
| 2205 | "for device extension list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2206 | src->device_extension_list.count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2207 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2208 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2209 | memset(dst->device_extension_list.list, 0, sizeof(struct loader_dev_ext_props) * src->device_extension_list.count); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2210 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2211 | dst->device_extension_list.capacity = sizeof(struct loader_dev_ext_props) * src->device_extension_list.count; |
| 2212 | memcpy(dst->device_extension_list.list, src->device_extension_list.list, dst->device_extension_list.capacity); |
| 2213 | if (src->device_extension_list.count > 0 && src->device_extension_list.list->entrypoint_count > 0) { |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2214 | cnt = src->device_extension_list.list->entrypoint_count; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2215 | dst->device_extension_list.list->entrypoints = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2216 | loader_instance_heap_alloc(inst, sizeof(char *) * cnt, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2217 | if (NULL == dst->device_extension_list.list->entrypoints) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2218 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2219 | "loader_copy_layer_properties: Failed to allocate space " |
| 2220 | "for device extension entrypoint list of size %d.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2221 | cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2222 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2223 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2224 | memset(dst->device_extension_list.list->entrypoints, 0, sizeof(char *) * cnt); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2225 | |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2226 | for (i = 0; i < cnt; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2227 | dst->device_extension_list.list->entrypoints[i] = loader_instance_heap_alloc( |
| 2228 | inst, strlen(src->device_extension_list.list->entrypoints[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2229 | if (NULL == dst->device_extension_list.list->entrypoints[i]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2230 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2231 | "loader_copy_layer_properties: Failed to " |
| 2232 | "allocate space for device extension entrypoint " |
| 2233 | "%d name of length", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 2234 | i); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2235 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2236 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2237 | strcpy(dst->device_extension_list.list->entrypoints[i], src->device_extension_list.list->entrypoints[i]); |
Jon Ashburn | 39fbd4e | 2015-12-10 18:17:34 -0700 | [diff] [blame] | 2238 | } |
| 2239 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2240 | |
| 2241 | return VK_SUCCESS; |
Jon Ashburn | 3d00233 | 2015-08-20 16:35:30 -0600 | [diff] [blame] | 2242 | } |
| 2243 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2244 | static bool loader_find_layer_name_list(const char *name, const struct loader_layer_list *layer_list) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2245 | if (NULL == layer_list) { |
| 2246 | return false; |
| 2247 | } |
| 2248 | for (uint32_t j = 0; j < layer_list->count; j++) { |
| 2249 | if (!strcmp(name, layer_list->list[j].info.layerName)) { |
| 2250 | return true; |
| 2251 | } |
| 2252 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2253 | return false; |
| 2254 | } |
| 2255 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2256 | bool loader_find_layer_name_array(const char *name, uint32_t layer_count, const char layer_list[][VK_MAX_EXTENSION_NAME_SIZE]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2257 | if (!layer_list) return false; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2258 | for (uint32_t j = 0; j < layer_count; j++) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2259 | if (!strcmp(name, layer_list[j])) return true; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2260 | return false; |
| 2261 | } |
| 2262 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2263 | const char *std_validation_str = "VK_LAYER_LUNARG_standard_validation"; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2264 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2265 | // Adds the legacy VK_LAYER_LUNARG_standard_validation as a meta-layer if it |
| 2266 | // fails to find it in the list already. This is usually an indication that a |
| 2267 | // newer loader is being used with an older layer set. |
| 2268 | static bool loader_add_legacy_std_val_layer(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list) { |
| 2269 | uint32_t i; |
| 2270 | bool success = true; |
| 2271 | struct loader_layer_properties *props = loader_get_next_layer_property(inst, layer_instance_list); |
| 2272 | const char std_validation_names[6][VK_MAX_EXTENSION_NAME_SIZE] = { |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 2273 | "VK_LAYER_GOOGLE_threading", "VK_LAYER_LUNARG_parameter_validation", "VK_LAYER_LUNARG_object_tracker", |
| 2274 | "VK_LAYER_LUNARG_core_validation", "VK_LAYER_GOOGLE_unique_objects"}; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2275 | uint32_t layer_count = sizeof(std_validation_names) / sizeof(std_validation_names[0]); |
| 2276 | |
| 2277 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2278 | "Adding VK_LAYER_LUNARG_standard_validation using the loader legacy path. This is" |
| 2279 | " not an error."); |
| 2280 | |
| 2281 | if (NULL == props) { |
| 2282 | goto out; |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2283 | } |
Jon Ashburn | 7148344 | 2016-02-11 18:59:43 -0700 | [diff] [blame] | 2284 | |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2285 | memset(props, 0, sizeof(struct loader_layer_properties)); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2286 | props->type_flags = VK_LAYER_TYPE_FLAG_INSTANCE_LAYER | VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER | VK_LAYER_TYPE_FLAG_META_LAYER; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2287 | strncpy(props->info.description, "LunarG Standard Validation Layer", sizeof(props->info.description)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2288 | props->info.implementationVersion = 1; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2289 | strncpy(props->info.layerName, std_validation_str, sizeof(props->info.layerName)); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2290 | props->info.specVersion = VK_MAKE_VERSION(1, 0, VK_HEADER_VERSION); |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2291 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2292 | props->component_layer_names = |
| 2293 | loader_instance_heap_alloc(inst, sizeof(char[MAX_STRING_SIZE]) * layer_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2294 | if (NULL == props->component_layer_names) { |
| 2295 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2296 | "Failed to allocate space for legacy VK_LAYER_LUNARG_standard_validation" |
| 2297 | " meta-layer component_layers information."); |
| 2298 | success = false; |
| 2299 | goto out; |
| 2300 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2301 | for (i = 0; i < layer_count; i++) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2302 | strncpy(props->component_layer_names[i], std_validation_names[i], MAX_STRING_SIZE - 1); |
| 2303 | props->component_layer_names[i][MAX_STRING_SIZE - 1] = '\0'; |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2304 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2305 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2306 | out: |
| 2307 | |
| 2308 | if (!success && NULL != props && NULL != props->component_layer_names) { |
| 2309 | loader_instance_heap_free(inst, props->component_layer_names); |
| 2310 | props->component_layer_names = NULL; |
| 2311 | } |
| 2312 | |
| 2313 | return success; |
| 2314 | } |
| 2315 | |
| 2316 | // Verify that all component layers in a meta-layer are valid. |
| 2317 | static bool verify_meta_layer_comp_layers(const struct loader_instance *inst, struct loader_layer_properties *prop, |
| 2318 | struct loader_layer_list *instance_layers) { |
| 2319 | bool success = true; |
Mark Young | c82a062 | 2017-05-05 11:17:17 -0600 | [diff] [blame] | 2320 | const uint32_t expected_major = VK_VERSION_MAJOR(prop->info.specVersion); |
| 2321 | const uint32_t expected_minor = VK_VERSION_MINOR(prop->info.specVersion); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2322 | |
| 2323 | for (uint32_t comp_layer = 0; comp_layer < prop->num_component_layers; comp_layer++) { |
| 2324 | if (!loader_find_layer_name_list(prop->component_layer_names[comp_layer], instance_layers)) { |
| 2325 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2326 | "Meta-layer %s can't find component layer %s at index %d." |
| 2327 | " Skipping this layer.", |
| 2328 | prop->info.layerName, prop->component_layer_names[comp_layer], comp_layer); |
| 2329 | success = false; |
| 2330 | break; |
| 2331 | } else { |
| 2332 | struct loader_layer_properties *comp_prop = |
| 2333 | loader_get_layer_property(prop->component_layer_names[comp_layer], instance_layers); |
| 2334 | if (comp_prop == NULL) { |
| 2335 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2336 | "Meta-layer %s can't find property for component layer %s at index %d." |
| 2337 | " Skipping this layer.", |
| 2338 | prop->info.layerName, prop->component_layer_names[comp_layer], comp_layer); |
| 2339 | success = false; |
| 2340 | break; |
| 2341 | } |
| 2342 | |
| 2343 | // Check the version of each layer, they need to at least match MAJOR and MINOR |
Mark Young | c82a062 | 2017-05-05 11:17:17 -0600 | [diff] [blame] | 2344 | uint32_t cur_major = VK_VERSION_MAJOR(comp_prop->info.specVersion); |
| 2345 | uint32_t cur_minor = VK_VERSION_MINOR(comp_prop->info.specVersion); |
| 2346 | if (cur_major != expected_major || cur_minor != expected_minor) { |
| 2347 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2348 | "Meta-layer uses API version %d.%d, but component layer %d uses API " |
| 2349 | "version %d.%d. Skipping this layer.", |
| 2350 | expected_major, expected_minor, comp_layer, cur_major, cur_minor); |
| 2351 | success = false; |
| 2352 | break; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | // Make sure the layer isn't using it's own name |
| 2356 | if (!strcmp(prop->info.layerName, prop->component_layer_names[comp_layer])) { |
| 2357 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2358 | "Meta-layer %s lists itself in its component layer list at index %d." |
| 2359 | " Skipping this layer.", |
| 2360 | prop->info.layerName, comp_layer); |
| 2361 | success = false; |
| 2362 | break; |
| 2363 | } |
| 2364 | if (comp_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) { |
| 2365 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 2366 | "verify_meta_layer_comp_layers: Adding meta-layer %s which also contains meta-layer %s", |
| 2367 | prop->info.layerName, comp_prop->info.layerName); |
| 2368 | |
| 2369 | // Make sure if the layer is using a meta-layer in its component list that we also verify that. |
| 2370 | if (!verify_meta_layer_comp_layers(inst, comp_prop, instance_layers)) { |
| 2371 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2372 | "Meta-layer %s component layer %s can not find all component layers." |
| 2373 | " Skipping this layer.", |
| 2374 | prop->info.layerName, prop->component_layer_names[comp_layer]); |
| 2375 | success = false; |
| 2376 | break; |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | // Add any instance and device extensions from component layers to this layer |
| 2381 | // list, so that anyone querying extensions will only need to look at the meta-layer |
| 2382 | for (uint32_t ext = 0; ext < comp_prop->instance_extension_list.count; ext++) { |
| 2383 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Meta-layer %s component layer %s adding instance extension %s", |
| 2384 | prop->info.layerName, prop->component_layer_names[comp_layer], |
| 2385 | comp_prop->instance_extension_list.list[ext].extensionName); |
| 2386 | if (!has_vk_extension_property(&comp_prop->instance_extension_list.list[ext], &prop->instance_extension_list)) { |
| 2387 | loader_add_to_ext_list(inst, &prop->instance_extension_list, 1, &comp_prop->instance_extension_list.list[ext]); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | for (uint32_t ext = 0; ext < comp_prop->device_extension_list.count; ext++) { |
| 2392 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Meta-layer %s component layer %s adding device extension %s", |
| 2393 | prop->info.layerName, prop->component_layer_names[comp_layer], |
| 2394 | comp_prop->device_extension_list.list[ext].props.extensionName); |
| 2395 | if (!has_vk_dev_ext_property(&comp_prop->device_extension_list.list[ext].props, &prop->device_extension_list)) { |
| 2396 | loader_add_to_dev_ext_list(inst, &prop->device_extension_list, |
| 2397 | &comp_prop->device_extension_list.list[ext].props, 0, NULL); |
| 2398 | } |
| 2399 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2400 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2401 | } |
| 2402 | if (success) { |
| 2403 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Meta-layer %s all %d component layers appear to be valid.", |
| 2404 | prop->info.layerName, prop->num_component_layers); |
| 2405 | } |
| 2406 | return success; |
| 2407 | } |
| 2408 | |
| 2409 | // Verify that all meta-layers in a layer list are valid. |
| 2410 | static void verify_all_meta_layers(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Mark Young | 697317f | 2017-05-09 10:31:12 -0600 | [diff] [blame] | 2411 | for (int32_t i = 0; i < (int32_t)instance_layers->count; i++) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2412 | struct loader_layer_properties *prop = &instance_layers->list[i]; |
| 2413 | |
| 2414 | // If this is a meta-layer, make sure it is valid |
| 2415 | if ((prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) && !verify_meta_layer_comp_layers(inst, prop, instance_layers)) { |
| 2416 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
| 2417 | "Removing meta-layer %s from instance layer list since it appears invalid.", prop->info.layerName); |
| 2418 | |
| 2419 | // Delete the component layers |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2420 | loader_instance_heap_free(inst, prop->component_layer_names); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2421 | |
Mark Young | 70ede4c | 2017-05-09 15:23:33 -0600 | [diff] [blame] | 2422 | // Remove the current invalid meta-layer from the layer list. Use memmove since we are |
| 2423 | // overlapping the source and destination addresses. |
| 2424 | memmove(&instance_layers->list[i], &instance_layers->list[i + 1], |
| 2425 | sizeof(struct loader_layer_properties) * (instance_layers->count - 1 - i)); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2426 | |
Mark Young | 70ede4c | 2017-05-09 15:23:33 -0600 | [diff] [blame] | 2427 | // Decrement the count (because we now have one less) and decrement the loop index since we need to |
| 2428 | // re-check this index. |
| 2429 | instance_layers->count--; |
Mark Young | 697317f | 2017-05-09 10:31:12 -0600 | [diff] [blame] | 2430 | i--; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2431 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 2432 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2435 | // This structure is used to store the json file version |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 2436 | // in a more manageable way. |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2437 | typedef struct { |
| 2438 | uint16_t major; |
| 2439 | uint16_t minor; |
| 2440 | uint16_t patch; |
| 2441 | } layer_json_version; |
| 2442 | |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 2443 | static inline bool is_valid_layer_json_version(const layer_json_version *layer_json) { |
| 2444 | // Supported versions are: 1.0.0, 1.0.1, 1.1.0, 1.1.1, and 1.1.2. |
| 2445 | if ((layer_json->major == 1 && layer_json->minor == 1 && layer_json->patch < 3) || |
| 2446 | (layer_json->major == 1 && layer_json->minor == 0 && layer_json->patch < 2)) { |
| 2447 | return true; |
| 2448 | } |
| 2449 | return false; |
| 2450 | } |
| 2451 | |
| 2452 | static inline bool layer_json_supports_layers_tag(const layer_json_version *layer_json) { |
| 2453 | // Supported versions started in 1.0.1, so anything newer |
| 2454 | if ((layer_json->major > 1 || layer_json->minor > 0 || layer_json->patch > 1)) { |
| 2455 | return true; |
| 2456 | } |
| 2457 | return false; |
| 2458 | } |
| 2459 | |
| 2460 | static inline bool layer_json_supports_pre_instance_tag(const layer_json_version *layer_json) { |
| 2461 | // Supported versions started in 1.1.2, so anything newer |
| 2462 | return layer_json->major > 1 || layer_json->minor > 1 || (layer_json->minor == 1 && layer_json->patch > 1); |
| 2463 | } |
| 2464 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2465 | static VkResult loader_read_json_layer(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, |
| 2466 | cJSON *layer_node, layer_json_version version, cJSON *item, cJSON *disable_environment, |
| 2467 | bool is_implicit, char *filename) { |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2468 | char *temp; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2469 | char *name, *type, *library_path_str, *api_version; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2470 | char *implementation_version, *description; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2471 | cJSON *ext_item, *library_path, *component_layers; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2472 | VkExtensionProperties ext_prop; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2473 | VkResult result = VK_ERROR_INITIALIZATION_FAILED; |
| 2474 | struct loader_layer_properties *props = NULL; |
| 2475 | int i, j; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2476 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2477 | // The following are required in the "layer" object: |
| 2478 | // (required) "name" |
| 2479 | // (required) "type" |
Nekotekina | d431e13 | 2017-06-11 13:13:07 +0300 | [diff] [blame] | 2480 | // (required) "library_path" |
| 2481 | // (required) "api_version" |
| 2482 | // (required) "implementation_version" |
| 2483 | // (required) "description" |
| 2484 | // (required for implicit layers) "disable_environment" |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2485 | #define GET_JSON_OBJECT(node, var) \ |
| 2486 | { \ |
| 2487 | var = cJSON_GetObjectItem(node, #var); \ |
| 2488 | if (var == NULL) { \ |
| 2489 | layer_node = layer_node->next; \ |
| 2490 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2491 | "Didn't find required layer object %s in manifest " \ |
| 2492 | "JSON file, skipping this layer", \ |
| 2493 | #var); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2494 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2495 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2496 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2497 | #define GET_JSON_ITEM(node, var) \ |
| 2498 | { \ |
| 2499 | item = cJSON_GetObjectItem(node, #var); \ |
| 2500 | if (item == NULL) { \ |
| 2501 | layer_node = layer_node->next; \ |
| 2502 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2503 | "Didn't find required layer value %s in manifest JSON " \ |
| 2504 | "file, skipping this layer", \ |
| 2505 | #var); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2506 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2507 | } \ |
| 2508 | temp = cJSON_Print(item); \ |
| 2509 | if (temp == NULL) { \ |
| 2510 | layer_node = layer_node->next; \ |
| 2511 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, \ |
| 2512 | "Problem accessing layer value %s in manifest JSON " \ |
| 2513 | "file, skipping this layer", \ |
| 2514 | #var); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2515 | result = VK_ERROR_OUT_OF_HOST_MEMORY; \ |
| 2516 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2517 | } \ |
| 2518 | temp[strlen(temp) - 1] = '\0'; \ |
| 2519 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2520 | strcpy(var, &temp[1]); \ |
| 2521 | cJSON_Free(temp); \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2522 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2523 | GET_JSON_ITEM(layer_node, name) |
| 2524 | GET_JSON_ITEM(layer_node, type) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2525 | GET_JSON_ITEM(layer_node, api_version) |
| 2526 | GET_JSON_ITEM(layer_node, implementation_version) |
| 2527 | GET_JSON_ITEM(layer_node, description) |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2528 | |
| 2529 | // Add list entry |
| 2530 | if (!strcmp(type, "DEVICE")) { |
| 2531 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Device layers are deprecated skipping this layer"); |
| 2532 | layer_node = layer_node->next; |
| 2533 | goto out; |
| 2534 | } |
| 2535 | |
| 2536 | // Allow either GLOBAL or INSTANCE type interchangeably to handle |
| 2537 | // layers that must work with older loaders |
| 2538 | if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) { |
| 2539 | if (layer_instance_list == NULL) { |
| 2540 | layer_node = layer_node->next; |
| 2541 | goto out; |
| 2542 | } |
| 2543 | props = loader_get_next_layer_property(inst, layer_instance_list); |
| 2544 | if (NULL == props) { |
| 2545 | // Error already triggered in loader_get_next_layer_property. |
| 2546 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2547 | goto out; |
| 2548 | } |
| 2549 | props->type_flags = VK_LAYER_TYPE_FLAG_INSTANCE_LAYER; |
| 2550 | if (!is_implicit) { |
| 2551 | props->type_flags |= VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER; |
| 2552 | } |
| 2553 | } else { |
| 2554 | layer_node = layer_node->next; |
| 2555 | goto out; |
| 2556 | } |
| 2557 | |
| 2558 | // Library path no longer required unless component_layers is also not defined |
| 2559 | library_path = cJSON_GetObjectItem(layer_node, "library_path"); |
| 2560 | component_layers = cJSON_GetObjectItem(layer_node, "component_layers"); |
| 2561 | if (NULL != library_path) { |
| 2562 | if (NULL != component_layers) { |
| 2563 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2564 | "Indicating meta-layer-specific component_layers, but also " |
| 2565 | "defining layer library path. Both are not compatible, so " |
| 2566 | "skipping this layer"); |
| 2567 | goto out; |
| 2568 | } |
| 2569 | props->num_component_layers = 0; |
| 2570 | props->component_layer_names = NULL; |
| 2571 | |
| 2572 | temp = cJSON_Print(library_path); |
| 2573 | if (NULL == temp) { |
| 2574 | layer_node = layer_node->next; |
| 2575 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2576 | "Problem accessing layer value library_path in manifest JSON " |
| 2577 | "file, skipping this layer"); |
| 2578 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2579 | goto out; |
| 2580 | } |
| 2581 | temp[strlen(temp) - 1] = '\0'; |
| 2582 | library_path_str = loader_stack_alloc(strlen(temp) + 1); |
| 2583 | strcpy(library_path_str, &temp[1]); |
| 2584 | cJSON_Free(temp); |
| 2585 | |
| 2586 | char *fullpath = props->lib_name; |
| 2587 | char *rel_base; |
| 2588 | if (NULL != library_path_str) { |
| 2589 | if (loader_platform_is_path(library_path_str)) { |
| 2590 | // A relative or absolute path |
| 2591 | char *name_copy = loader_stack_alloc(strlen(filename) + 1); |
| 2592 | strcpy(name_copy, filename); |
| 2593 | rel_base = loader_platform_dirname(name_copy); |
| 2594 | loader_expand_path(library_path_str, rel_base, MAX_STRING_SIZE, fullpath); |
| 2595 | } else { |
| 2596 | // A filename which is assumed in a system directory |
| 2597 | loader_get_fullpath(library_path_str, DEFAULT_VK_LAYERS_PATH, MAX_STRING_SIZE, fullpath); |
| 2598 | } |
| 2599 | } |
| 2600 | } else if (NULL != component_layers) { |
| 2601 | if (version.major == 1 && (version.minor < 1 || version.patch < 1)) { |
| 2602 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2603 | "Indicating meta-layer-specific component_layers, but using older " |
| 2604 | "JSON file version."); |
| 2605 | } |
| 2606 | int count = cJSON_GetArraySize(component_layers); |
| 2607 | props->num_component_layers = count; |
| 2608 | |
| 2609 | // Allocate buffer for layer names |
| 2610 | props->component_layer_names = |
| 2611 | loader_instance_heap_alloc(inst, sizeof(char[MAX_STRING_SIZE]) * count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 2612 | if (NULL == props->component_layer_names) { |
| 2613 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2614 | goto out; |
| 2615 | } |
| 2616 | |
| 2617 | // Copy the component layers into the array |
| 2618 | for (i = 0; i < count; i++) { |
| 2619 | cJSON *comp_layer = cJSON_GetArrayItem(component_layers, i); |
| 2620 | if (NULL != comp_layer) { |
| 2621 | temp = cJSON_Print(comp_layer); |
| 2622 | if (NULL == temp) { |
| 2623 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2624 | goto out; |
| 2625 | } |
| 2626 | temp[strlen(temp) - 1] = '\0'; |
| 2627 | strncpy(props->component_layer_names[i], temp + 1, MAX_STRING_SIZE - 1); |
| 2628 | props->component_layer_names[i][MAX_STRING_SIZE - 1] = '\0'; |
| 2629 | cJSON_Free(temp); |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | // This is now, officially, a meta-layer |
| 2634 | props->type_flags |= VK_LAYER_TYPE_FLAG_META_LAYER; |
| 2635 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Encountered meta-layer %s", name); |
| 2636 | |
| 2637 | // Make sure we set up other things so we head down the correct branches below |
| 2638 | library_path_str = NULL; |
| 2639 | } else { |
| 2640 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2641 | "Layer missing both library_path and component_layers fields. One or the " |
| 2642 | "other MUST be defined. Skipping this layer"); |
| 2643 | goto out; |
| 2644 | } |
| 2645 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2646 | if (is_implicit) { |
| 2647 | GET_JSON_OBJECT(layer_node, disable_environment) |
| 2648 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2649 | #undef GET_JSON_ITEM |
| 2650 | #undef GET_JSON_OBJECT |
| 2651 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2652 | strncpy(props->info.layerName, name, sizeof(props->info.layerName)); |
| 2653 | props->info.layerName[sizeof(props->info.layerName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2654 | props->info.specVersion = loader_make_version(api_version); |
| 2655 | props->info.implementationVersion = atoi(implementation_version); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2656 | strncpy((char *)props->info.description, description, sizeof(props->info.description)); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2657 | props->info.description[sizeof(props->info.description) - 1] = '\0'; |
| 2658 | if (is_implicit) { |
| 2659 | if (!disable_environment || !disable_environment->child) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2660 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2661 | "Didn't find required layer child value disable_environment" |
| 2662 | "in manifest JSON file, skipping this layer"); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2663 | layer_node = layer_node->next; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2664 | goto out; |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2665 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2666 | strncpy(props->disable_env_var.name, disable_environment->child->string, sizeof(props->disable_env_var.name)); |
| 2667 | props->disable_env_var.name[sizeof(props->disable_env_var.name) - 1] = '\0'; |
| 2668 | strncpy(props->disable_env_var.value, disable_environment->child->valuestring, sizeof(props->disable_env_var.value)); |
| 2669 | props->disable_env_var.value[sizeof(props->disable_env_var.value) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2670 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2671 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2672 | // Now get all optional items and objects and put in list: |
| 2673 | // functions |
| 2674 | // instance_extensions |
| 2675 | // device_extensions |
| 2676 | // enable_environment (implicit layers only) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2677 | #define GET_JSON_OBJECT(node, var) \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2678 | { var = cJSON_GetObjectItem(node, #var); } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2679 | #define GET_JSON_ITEM(node, var) \ |
| 2680 | { \ |
| 2681 | item = cJSON_GetObjectItem(node, #var); \ |
| 2682 | if (item != NULL) { \ |
| 2683 | temp = cJSON_Print(item); \ |
| 2684 | if (temp != NULL) { \ |
| 2685 | temp[strlen(temp) - 1] = '\0'; \ |
| 2686 | var = loader_stack_alloc(strlen(temp) + 1); \ |
| 2687 | strcpy(var, &temp[1]); \ |
| 2688 | cJSON_Free(temp); \ |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2689 | } else { \ |
| 2690 | result = VK_ERROR_OUT_OF_HOST_MEMORY; \ |
| 2691 | goto out; \ |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2692 | } \ |
| 2693 | } \ |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 2694 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2695 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2696 | cJSON *instance_extensions, *device_extensions, *functions, *enable_environment; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2697 | cJSON *entrypoints = NULL; |
| 2698 | char *vkGetInstanceProcAddr = NULL; |
| 2699 | char *vkGetDeviceProcAddr = NULL; |
| 2700 | char *vkNegotiateLoaderLayerInterfaceVersion = NULL; |
| 2701 | char *spec_version = NULL; |
| 2702 | char **entry_array = NULL; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2703 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2704 | // Layer interface functions |
| 2705 | // vkGetInstanceProcAddr |
| 2706 | // vkGetDeviceProcAddr |
| 2707 | // vkNegotiateLoaderLayerInterfaceVersion (starting with JSON file 1.1.0) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2708 | GET_JSON_OBJECT(layer_node, functions) |
| 2709 | if (functions != NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2710 | if (version.major > 1 || version.minor >= 1) { |
| 2711 | GET_JSON_ITEM(functions, vkNegotiateLoaderLayerInterfaceVersion) |
| 2712 | if (vkNegotiateLoaderLayerInterfaceVersion != NULL) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2713 | strncpy(props->functions.str_negotiate_interface, vkNegotiateLoaderLayerInterfaceVersion, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2714 | sizeof(props->functions.str_negotiate_interface)); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2715 | props->functions.str_negotiate_interface[sizeof(props->functions.str_negotiate_interface) - 1] = '\0'; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2716 | } else { |
| 2717 | props->functions.str_negotiate_interface[0] = '\0'; |
| 2718 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2719 | GET_JSON_ITEM(functions, vkGetInstanceProcAddr) |
| 2720 | GET_JSON_ITEM(functions, vkGetDeviceProcAddr) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2721 | if (vkGetInstanceProcAddr != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2722 | strncpy(props->functions.str_gipa, vkGetInstanceProcAddr, sizeof(props->functions.str_gipa)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2723 | if (version.major > 1 || version.minor >= 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2724 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2725 | "Indicating layer-specific vkGetInstanceProcAddr " |
| 2726 | "function is deprecated starting with JSON file " |
| 2727 | "version 1.1.0. Instead, use the new " |
| 2728 | "vkNegotiateLayerInterfaceVersion function to " |
| 2729 | "return the GetInstanceProcAddr function for this" |
| 2730 | "layer"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2731 | } |
| 2732 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2733 | props->functions.str_gipa[sizeof(props->functions.str_gipa) - 1] = '\0'; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2734 | if (vkGetDeviceProcAddr != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2735 | strncpy(props->functions.str_gdpa, vkGetDeviceProcAddr, sizeof(props->functions.str_gdpa)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2736 | if (version.major > 1 || version.minor >= 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2737 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2738 | "Indicating layer-specific vkGetDeviceProcAddr " |
| 2739 | "function is deprecated starting with JSON file " |
| 2740 | "version 1.1.0. Instead, use the new " |
| 2741 | "vkNegotiateLayerInterfaceVersion function to " |
| 2742 | "return the GetDeviceProcAddr function for this" |
| 2743 | "layer"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2744 | } |
| 2745 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2746 | props->functions.str_gdpa[sizeof(props->functions.str_gdpa) - 1] = '\0'; |
| 2747 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2748 | |
| 2749 | // instance_extensions |
| 2750 | // array of { |
| 2751 | // name |
| 2752 | // spec_version |
| 2753 | // } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2754 | GET_JSON_OBJECT(layer_node, instance_extensions) |
| 2755 | if (instance_extensions != NULL) { |
| 2756 | int count = cJSON_GetArraySize(instance_extensions); |
| 2757 | for (i = 0; i < count; i++) { |
| 2758 | ext_item = cJSON_GetArrayItem(instance_extensions, i); |
| 2759 | GET_JSON_ITEM(ext_item, name) |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2760 | if (name != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2761 | strncpy(ext_prop.extensionName, name, sizeof(ext_prop.extensionName)); |
| 2762 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2763 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2764 | GET_JSON_ITEM(ext_item, spec_version) |
| 2765 | if (NULL != spec_version) { |
| 2766 | ext_prop.specVersion = atoi(spec_version); |
| 2767 | } else { |
| 2768 | ext_prop.specVersion = 0; |
| 2769 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2770 | bool ext_unsupported = wsi_unsupported_instance_extension(&ext_prop); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2771 | if (!ext_unsupported) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2772 | loader_add_to_ext_list(inst, &props->instance_extension_list, 1, &ext_prop); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 2773 | } |
Jon Ashburn | fb8ac01 | 2015-08-12 16:39:32 -0600 | [diff] [blame] | 2774 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2775 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2776 | |
| 2777 | // device_extensions |
| 2778 | // array of { |
| 2779 | // name |
| 2780 | // spec_version |
| 2781 | // entrypoints |
| 2782 | // } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2783 | GET_JSON_OBJECT(layer_node, device_extensions) |
| 2784 | if (device_extensions != NULL) { |
| 2785 | int count = cJSON_GetArraySize(device_extensions); |
| 2786 | for (i = 0; i < count; i++) { |
| 2787 | ext_item = cJSON_GetArrayItem(device_extensions, i); |
| 2788 | GET_JSON_ITEM(ext_item, name) |
| 2789 | GET_JSON_ITEM(ext_item, spec_version) |
| 2790 | if (name != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2791 | strncpy(ext_prop.extensionName, name, sizeof(ext_prop.extensionName)); |
| 2792 | ext_prop.extensionName[sizeof(ext_prop.extensionName) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2793 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2794 | if (NULL != spec_version) { |
| 2795 | ext_prop.specVersion = atoi(spec_version); |
| 2796 | } else { |
| 2797 | ext_prop.specVersion = 0; |
| 2798 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2799 | // entrypoints = cJSON_GetObjectItem(ext_item, "entrypoints"); |
| 2800 | GET_JSON_OBJECT(ext_item, entrypoints) |
| 2801 | int entry_count; |
| 2802 | if (entrypoints == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2803 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, 0, NULL); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2804 | continue; |
| 2805 | } |
| 2806 | entry_count = cJSON_GetArraySize(entrypoints); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2807 | if (entry_count) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2808 | entry_array = (char **)loader_stack_alloc(sizeof(char *) * entry_count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2809 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2810 | for (j = 0; j < entry_count; j++) { |
| 2811 | ext_item = cJSON_GetArrayItem(entrypoints, j); |
| 2812 | if (ext_item != NULL) { |
| 2813 | temp = cJSON_Print(ext_item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2814 | if (NULL == temp) { |
| 2815 | entry_array[j] = NULL; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2816 | result = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 2817 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2818 | } |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2819 | temp[strlen(temp) - 1] = '\0'; |
| 2820 | entry_array[j] = loader_stack_alloc(strlen(temp) + 1); |
| 2821 | strcpy(entry_array[j], &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2822 | cJSON_Free(temp); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2823 | } |
| 2824 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2825 | loader_add_to_dev_ext_list(inst, &props->device_extension_list, &ext_prop, entry_count, entry_array); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | if (is_implicit) { |
| 2829 | GET_JSON_OBJECT(layer_node, enable_environment) |
| 2830 | |
| 2831 | // enable_environment is optional |
| 2832 | if (enable_environment) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2833 | strncpy(props->enable_env_var.name, enable_environment->child->string, sizeof(props->enable_env_var.name)); |
| 2834 | props->enable_env_var.name[sizeof(props->enable_env_var.name) - 1] = '\0'; |
| 2835 | strncpy(props->enable_env_var.value, enable_environment->child->valuestring, sizeof(props->enable_env_var.value)); |
| 2836 | props->enable_env_var.value[sizeof(props->enable_env_var.value) - 1] = '\0'; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2837 | } |
| 2838 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2839 | |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 2840 | // Read in the pre-instance stuff |
| 2841 | cJSON *pre_instance = cJSON_GetObjectItem(layer_node, "pre_instance_functions"); |
| 2842 | if (pre_instance) { |
| 2843 | if (!layer_json_supports_pre_instance_tag(&version)) { |
| 2844 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 2845 | "Found pre_instance_functions section in layer from \"%s\". " |
| 2846 | "This section is only valid in manifest version 1.1.2 or later. The section will be ignored", |
| 2847 | filename); |
| 2848 | } else if (!is_implicit) { |
| 2849 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2850 | "Found pre_instance_functions section in explicit layer from " |
| 2851 | "\"%s\". This section is only valid in implicit layers. The section will be ignored", |
| 2852 | filename); |
| 2853 | } else { |
| 2854 | cJSON *inst_ext_json = cJSON_GetObjectItem(pre_instance, "vkEnumerateInstanceExtensionProperties"); |
| 2855 | if (inst_ext_json) { |
| 2856 | char *inst_ext_name = cJSON_Print(inst_ext_json); |
| 2857 | size_t len = strlen(inst_ext_name) >= MAX_STRING_SIZE ? MAX_STRING_SIZE - 3 : strlen(inst_ext_name) - 2; |
| 2858 | strncpy(props->pre_instance_functions.enumerate_instance_extension_properties, inst_ext_name + 1, len); |
| 2859 | props->pre_instance_functions.enumerate_instance_extension_properties[len] = '\0'; |
| 2860 | cJSON_Free(inst_ext_name); |
| 2861 | } |
| 2862 | |
| 2863 | cJSON *inst_layer_json = cJSON_GetObjectItem(pre_instance, "vkEnumerateInstanceLayerProperties"); |
| 2864 | if (inst_layer_json) { |
| 2865 | char *inst_layer_name = cJSON_Print(inst_layer_json); |
| 2866 | size_t len = strlen(inst_layer_name) >= MAX_STRING_SIZE ? MAX_STRING_SIZE - 3 : strlen(inst_layer_name) - 2; |
| 2867 | strncpy(props->pre_instance_functions.enumerate_instance_layer_properties, inst_layer_name + 1, len); |
| 2868 | props->pre_instance_functions.enumerate_instance_layer_properties[len] = '\0'; |
| 2869 | cJSON_Free(inst_layer_name); |
| 2870 | } |
Lenny Komow | 1658611 | 2018-02-13 15:58:47 -0700 | [diff] [blame] | 2871 | |
| 2872 | cJSON *inst_version_json = cJSON_GetObjectItem(pre_instance, "vkEnumerateInstanceVersion"); |
| 2873 | if (inst_version_json) { |
| 2874 | char *inst_version_name = cJSON_Print(inst_version_json); |
| 2875 | size_t len = strlen(inst_version_name) >= MAX_STRING_SIZE ? MAX_STRING_SIZE - 3 : strlen(inst_version_name) - 2; |
| 2876 | strncpy(props->pre_instance_functions.enumerate_instance_version, inst_version_name + 1, len); |
| 2877 | props->pre_instance_functions.enumerate_instance_version[len] = '\0'; |
| 2878 | cJSON_Free(inst_version_name); |
| 2879 | } |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 2880 | } |
| 2881 | } |
| 2882 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2883 | result = VK_SUCCESS; |
| 2884 | |
| 2885 | out: |
| 2886 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 2887 | #undef GET_JSON_ITEM |
| 2888 | #undef GET_JSON_OBJECT |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2889 | |
| 2890 | if (VK_SUCCESS != result && NULL != props) { |
| 2891 | props->num_component_layers = 0; |
| 2892 | if (NULL != props->component_layer_names) { |
| 2893 | loader_instance_heap_free(inst, props->component_layer_names); |
| 2894 | } |
| 2895 | props->component_layer_names = NULL; |
| 2896 | } |
| 2897 | |
| 2898 | return result; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2899 | } |
| 2900 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 2901 | // Given a cJSON struct (json) of the top level JSON object from layer manifest |
| 2902 | // file, add entry to the layer_list. Fill out the layer_properties in this list |
| 2903 | // entry from the input cJSON object. |
| 2904 | // |
| 2905 | // \returns |
| 2906 | // void |
| 2907 | // layer_list has a new entry and initialized accordingly. |
| 2908 | // If the json input object does not have all the required fields no entry |
| 2909 | // is added to the list. |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2910 | static VkResult loader_add_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, |
| 2911 | cJSON *json, bool is_implicit, char *filename) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2912 | // The following Fields in layer manifest file that are required: |
Nekotekina | d431e13 | 2017-06-11 13:13:07 +0300 | [diff] [blame] | 2913 | // - "file_format_version" |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2914 | // - If more than one "layer" object are used, then the "layers" array is |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 2915 | // required |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2916 | VkResult result = VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2917 | cJSON *item, *layers_node, *layer_node; |
Mike Stroyan | 8190821 | 2017-03-14 13:09:12 -0600 | [diff] [blame] | 2918 | layer_json_version json_version = {0, 0, 0}; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2919 | char *vers_tok; |
| 2920 | cJSON *disable_environment = NULL; |
| 2921 | item = cJSON_GetObjectItem(json, "file_format_version"); |
| 2922 | if (item == NULL) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2923 | goto out; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2924 | } |
| 2925 | char *file_vers = cJSON_PrintUnformatted(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2926 | if (NULL == file_vers) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2927 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2928 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2929 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found manifest file %s, version %s", filename, file_vers); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2930 | // Get the major/minor/and patch as integers for easier comparison |
| 2931 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 2932 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2933 | json_version.major = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2934 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2935 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2936 | json_version.minor = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2937 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 2938 | if (NULL != vers_tok) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2939 | json_version.patch = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2943 | |
| 2944 | if (!is_valid_layer_json_version(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2945 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2946 | "loader_add_layer_properties: %s invalid layer " |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2947 | "manifest file version %d.%d.%d. May cause errors.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 2948 | filename, json_version.major, json_version.minor, json_version.patch); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2949 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 2950 | cJSON_Free(file_vers); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2951 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2952 | // If "layers" is present, read in the array of layer objects |
| 2953 | layers_node = cJSON_GetObjectItem(json, "layers"); |
| 2954 | if (layers_node != NULL) { |
| 2955 | int numItems = cJSON_GetArraySize(layers_node); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2956 | if (!layer_json_supports_layers_tag(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2957 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2958 | "loader_add_layer_properties: \'layers\' tag not " |
| 2959 | "supported until file version 1.0.1, but %s is " |
| 2960 | "reporting version %s", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2961 | filename, file_vers); |
| 2962 | } |
| 2963 | for (int curLayer = 0; curLayer < numItems; curLayer++) { |
| 2964 | layer_node = cJSON_GetArrayItem(layers_node, curLayer); |
| 2965 | if (layer_node == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2966 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2967 | "loader_add_layer_properties: Can not find " |
| 2968 | "\'layers\' array element %d object in manifest " |
| 2969 | "JSON file %s. Skipping this file", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2970 | curLayer, filename); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2971 | goto out; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2972 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2973 | result = loader_read_json_layer(inst, layer_instance_list, layer_node, json_version, item, disable_environment, |
| 2974 | is_implicit, filename); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2975 | } |
| 2976 | } else { |
| 2977 | // Otherwise, try to read in individual layers |
| 2978 | layer_node = cJSON_GetObjectItem(json, "layer"); |
| 2979 | if (layer_node == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2980 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 2981 | "loader_add_layer_properties: Can not find \'layer\' " |
| 2982 | "object in manifest JSON file %s. Skipping this file.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2983 | filename); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 2984 | goto out; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 2985 | } |
| 2986 | // Loop through all "layer" objects in the file to get a count of them |
| 2987 | // first. |
| 2988 | uint16_t layer_count = 0; |
| 2989 | cJSON *tempNode = layer_node; |
| 2990 | do { |
| 2991 | tempNode = tempNode->next; |
| 2992 | layer_count++; |
| 2993 | } while (tempNode != NULL); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 2994 | |
| 2995 | // Throw a warning if we encounter multiple "layer" objects in file |
| 2996 | // versions newer than 1.0.0. Having multiple objects with the same |
| 2997 | // name at the same level is actually a JSON standard violation. |
| 2998 | if (layer_count > 1 && layer_json_supports_layers_tag(&json_version)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2999 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3000 | "loader_add_layer_properties: Multiple \'layer\' nodes" |
| 3001 | " are deprecated starting in file version \"1.0.1\". " |
| 3002 | "Please use \'layers\' : [] array instead in %s.", |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3003 | filename); |
| 3004 | } else { |
| 3005 | do { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3006 | result = loader_read_json_layer(inst, layer_instance_list, layer_node, json_version, item, disable_environment, |
| 3007 | is_implicit, filename); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3008 | layer_node = layer_node->next; |
| 3009 | } while (layer_node != NULL); |
| 3010 | } |
| 3011 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3012 | |
| 3013 | out: |
| 3014 | |
| 3015 | return result; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3016 | } |
| 3017 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3018 | // Find the Vulkan library manifest files. |
| 3019 | // |
| 3020 | // This function scans the "location" or "env_override" directories/files |
| 3021 | // for a list of JSON manifest files. If env_override is non-NULL |
| 3022 | // and has a valid value. Then the location is ignored. Otherwise |
| 3023 | // location is used to look for manifest files. The location |
| 3024 | // is interpreted as Registry path on Windows and a directory path(s) |
| 3025 | // on Linux. "home_location" is an additional directory in the users home |
| 3026 | // directory to look at. It is expanded into the dir path |
| 3027 | // $XDG_DATA_HOME/home_location or $HOME/.local/share/home_location depending |
| 3028 | // on environment variables. This "home_location" is only used on Linux. |
| 3029 | // |
| 3030 | // \returns |
| 3031 | // VKResult |
| 3032 | // A string list of manifest files to be opened in out_files param. |
| 3033 | // List has a pointer to string for each manifest filename. |
| 3034 | // When done using the list in out_files, pointers should be freed. |
| 3035 | // Location or override string lists can be either files or directories as |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3036 | // follows: |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3037 | // | location | override |
| 3038 | // -------------------------------- |
| 3039 | // Win ICD | files | files |
| 3040 | // Win Layer | files | dirs |
| 3041 | // Linux ICD | dirs | files |
| 3042 | // Linux Layer| dirs | dirs |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3043 | static VkResult loader_get_manifest_files(const struct loader_instance *inst, const char *env_override, const char *source_override, |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3044 | bool is_layer, bool warn_if_not_present, const char *location, |
| 3045 | const char *relative_location, struct loader_manifest_files *out_files) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3046 | const char *override = NULL; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3047 | char *override_getenv = NULL; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3048 | char *loc, *orig_loc = NULL; |
| 3049 | char *reg = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3050 | char *file, *next_file, *name; |
| 3051 | size_t alloced_count = 64; |
| 3052 | char full_path[2048]; |
| 3053 | DIR *sysdir = NULL; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3054 | bool list_is_dirs = false; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3055 | struct dirent *dent; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3056 | VkResult res = VK_SUCCESS; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3057 | |
| 3058 | out_files->count = 0; |
| 3059 | out_files->filename_list = NULL; |
| 3060 | |
Jamie Madill | 00c3c91 | 2016-04-06 18:26:46 -0400 | [diff] [blame] | 3061 | if (source_override != NULL) { |
| 3062 | override = source_override; |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3063 | } else if (env_override != NULL) { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3064 | #if !defined(_WIN32) |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3065 | if (geteuid() != getuid() || getegid() != getgid()) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3066 | // Don't allow setuid apps to use the env var: |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3067 | env_override = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3068 | } |
| 3069 | #endif |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3070 | if (env_override != NULL) { |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 3071 | override = override_getenv = loader_secure_getenv(env_override, inst); |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3072 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3073 | } |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 3074 | #if !defined(_WIN32) |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3075 | if (relative_location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 3076 | #else |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3077 | relative_location = NULL; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3078 | if (location == NULL) { |
Jon Ashburn | b682221 | 2016-02-16 15:34:16 -0700 | [diff] [blame] | 3079 | #endif |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3080 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3081 | "loader_get_manifest_files: Can not get manifest files with " |
| 3082 | "NULL location, env_override=%s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3083 | (env_override != NULL) ? env_override : ""); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3084 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3085 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3086 | } |
| 3087 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3088 | #if defined(_WIN32) |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3089 | list_is_dirs = (is_layer && override != NULL) ? true : false; |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3090 | #else |
| 3091 | list_is_dirs = (override == NULL || is_layer) ? true : false; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3092 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3093 | // Make a copy of the input we are using so it is not modified |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3094 | // Also handle getting the location(s) from registry on Windows |
| 3095 | if (override == NULL) { |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3096 | size_t loc_size = 0; |
| 3097 | #if !defined(_WIN32) |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 3098 | const char *xdgconfdirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst); |
| 3099 | const char *xdgdatadirs = loader_secure_getenv("XDG_DATA_DIRS", inst); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3100 | if (xdgconfdirs == NULL || xdgconfdirs[0] == '\0') xdgconfdirs = FALLBACK_CONFIG_DIRS; |
| 3101 | if (xdgdatadirs == NULL || xdgdatadirs[0] == '\0') xdgdatadirs = FALLBACK_DATA_DIRS; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3102 | const size_t rel_size = strlen(relative_location); |
| 3103 | // Leave space for trailing separators |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3104 | loc_size += strlen(xdgconfdirs) + strlen(xdgdatadirs) + 2 * rel_size + 2; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3105 | for (const char *x = xdgconfdirs; *x; ++x) |
| 3106 | if (*x == PATH_SEPARATOR) loc_size += rel_size; |
| 3107 | for (const char *x = xdgdatadirs; *x; ++x) |
| 3108 | if (*x == PATH_SEPARATOR) loc_size += rel_size; |
| 3109 | loc_size += strlen(SYSCONFDIR) + rel_size + 1; |
| 3110 | #if defined(EXTRASYSCONFDIR) |
| 3111 | loc_size += strlen(EXTRASYSCONFDIR) + rel_size + 1; |
| 3112 | #endif |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 3113 | #if defined(__APPLE__) |
| 3114 | // For bundle path |
| 3115 | loc_size += MAXPATHLEN; |
| 3116 | #endif |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3117 | #else |
| 3118 | loc_size += strlen(location) + 1; |
| 3119 | #endif |
| 3120 | loc = loader_stack_alloc(loc_size); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3121 | if (loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3122 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3123 | "loader_get_manifest_files: Failed to allocate " |
| 3124 | "%d bytes for manifest file location.", |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3125 | loc_size); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3126 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3127 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3128 | } |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3129 | char *loc_write = loc; |
| 3130 | #if !defined(_WIN32) |
| 3131 | const char *loc_read; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3132 | size_t start, stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3133 | |
Karl Schultz | 2e5ed33 | 2017-12-12 10:33:01 -0500 | [diff] [blame] | 3134 | #if defined(__APPLE__) |
| 3135 | // Add the bundle's Resources dir to the beginning of the search path. |
| 3136 | // Looks for manifests in the bundle first, before any system directories. |
| 3137 | CFBundleRef main_bundle = CFBundleGetMainBundle(); |
| 3138 | if (NULL != main_bundle) { |
| 3139 | CFURLRef ref = CFBundleCopyResourcesDirectoryURL(main_bundle); |
| 3140 | if (NULL != ref) { |
| 3141 | if (CFURLGetFileSystemRepresentation(ref, TRUE, (UInt8 *)loc_write, loc_size)) { |
| 3142 | loc_write += strlen(loc_write); |
| 3143 | memcpy(loc_write, relative_location, rel_size); |
| 3144 | loc_write += rel_size; |
| 3145 | *loc_write++ = PATH_SEPARATOR; |
| 3146 | } |
| 3147 | CFRelease(ref); |
| 3148 | } |
| 3149 | } |
| 3150 | #endif |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3151 | loc_read = &xdgconfdirs[0]; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3152 | start = 0; |
| 3153 | while (loc_read[start] != '\0') { |
| 3154 | while (loc_read[start] == PATH_SEPARATOR) { |
| 3155 | start++; |
| 3156 | } |
| 3157 | stop = start; |
| 3158 | while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') { |
| 3159 | stop++; |
| 3160 | } |
| 3161 | const size_t s = stop - start; |
| 3162 | if (s) { |
| 3163 | memcpy(loc_write, &loc_read[start], s); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3164 | loc_write += s; |
| 3165 | memcpy(loc_write, relative_location, rel_size); |
| 3166 | loc_write += rel_size; |
| 3167 | *loc_write++ = PATH_SEPARATOR; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3168 | start = stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | memcpy(loc_write, SYSCONFDIR, strlen(SYSCONFDIR)); |
| 3173 | loc_write += strlen(SYSCONFDIR); |
| 3174 | memcpy(loc_write, relative_location, rel_size); |
| 3175 | loc_write += rel_size; |
| 3176 | *loc_write++ = PATH_SEPARATOR; |
| 3177 | |
| 3178 | #if defined(EXTRASYSCONFDIR) |
| 3179 | memcpy(loc_write, EXTRASYSCONFDIR, strlen(EXTRASYSCONFDIR)); |
| 3180 | loc_write += strlen(EXTRASYSCONFDIR); |
| 3181 | memcpy(loc_write, relative_location, rel_size); |
| 3182 | loc_write += rel_size; |
| 3183 | *loc_write++ = PATH_SEPARATOR; |
| 3184 | #endif |
| 3185 | |
| 3186 | loc_read = &xdgdatadirs[0]; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3187 | start = 0; |
| 3188 | while (loc_read[start] != '\0') { |
| 3189 | while (loc_read[start] == PATH_SEPARATOR) { |
| 3190 | start++; |
| 3191 | } |
| 3192 | stop = start; |
| 3193 | while (loc_read[stop] != PATH_SEPARATOR && loc_read[stop] != '\0') { |
| 3194 | stop++; |
| 3195 | } |
| 3196 | const size_t s = stop - start; |
| 3197 | if (s) { |
| 3198 | memcpy(loc_write, &loc_read[start], s); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3199 | loc_write += s; |
| 3200 | memcpy(loc_write, relative_location, rel_size); |
| 3201 | loc_write += rel_size; |
| 3202 | *loc_write++ = PATH_SEPARATOR; |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3203 | start = stop; |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3204 | } |
| 3205 | } |
Karl Schultz | 52f5daa | 2017-02-12 12:34:03 -0700 | [diff] [blame] | 3206 | |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3207 | --loc_write; |
| 3208 | #else |
| 3209 | memcpy(loc_write, location, strlen(location)); |
| 3210 | loc_write += strlen(location); |
| 3211 | #endif |
| 3212 | assert(loc_write - loc < (ptrdiff_t)loc_size); |
| 3213 | *loc_write = '\0'; |
| 3214 | |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3215 | #if defined(_WIN32) |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3216 | VkResult regHKR_result = VK_SUCCESS; |
| 3217 | |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 3218 | DWORD reg_size = 4096; |
| 3219 | |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 3220 | // These calls look at the PNP/Device section of the registry. |
Lenny Komow | f7c0938 | 2017-08-31 16:35:08 -0600 | [diff] [blame] | 3221 | if (!strncmp(loc, DEFAULT_VK_DRIVERS_INFO, sizeof(DEFAULT_VK_DRIVERS_INFO))) { |
| 3222 | regHKR_result = loaderGetDeviceRegistryFiles(inst, ®, ®_size, LoaderPnpDriverRegistry()); |
| 3223 | } else if (!strncmp(loc, DEFAULT_VK_ELAYERS_INFO, sizeof(DEFAULT_VK_ELAYERS_INFO))) { |
| 3224 | regHKR_result = loaderGetDeviceRegistryFiles(inst, ®, ®_size, LoaderPnpELayerRegistry()); |
| 3225 | } else if (!strncmp(loc, DEFAULT_VK_ILAYERS_INFO, sizeof(DEFAULT_VK_ILAYERS_INFO))) { |
| 3226 | regHKR_result = loaderGetDeviceRegistryFiles(inst, ®, ®_size, LoaderPnpILayerRegistry()); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3227 | } |
| 3228 | |
Norbert Garnys | 7dc9a59 | 2018-02-13 16:32:03 +0100 | [diff] [blame] | 3229 | // This call looks into the Khronos non-device specific section of the registry. |
Slawomir Cygan | 8f9f255 | 2017-08-09 11:36:52 +0200 | [diff] [blame] | 3230 | VkResult reg_result = loaderGetRegistryFiles(inst, loc, is_layer, ®, ®_size); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3231 | |
| 3232 | if ((VK_SUCCESS != reg_result && VK_SUCCESS != regHKR_result) || NULL == reg) { |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3233 | if (!is_layer) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3234 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3235 | "loader_get_manifest_files: Registry lookup failed " |
| 3236 | "to get ICD manifest files. Possibly missing Vulkan" |
| 3237 | " driver?"); |
Slawomir Cygan | 9a2fa0e | 2017-07-03 16:47:52 +0200 | [diff] [blame] | 3238 | if (VK_SUCCESS == regHKR_result || VK_ERROR_OUT_OF_HOST_MEMORY == regHKR_result) { |
| 3239 | res = regHKR_result; |
| 3240 | } else if (VK_SUCCESS == reg_result || VK_ERROR_OUT_OF_HOST_MEMORY == reg_result) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3241 | res = reg_result; |
| 3242 | } else { |
| 3243 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 3244 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3245 | } else { |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3246 | if (warn_if_not_present) { |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3247 | // This is only a warning for layers |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3248 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3249 | "loader_get_manifest_files: Registry lookup failed " |
| 3250 | "to get layer manifest files."); |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3251 | } |
Mark Young | 2c84c0c | 2017-01-13 10:27:03 -0700 | [diff] [blame] | 3252 | if (reg_result == VK_ERROR_OUT_OF_HOST_MEMORY) { |
| 3253 | res = reg_result; |
| 3254 | } else { |
| 3255 | // Return success for now since it's not critical for layers |
| 3256 | res = VK_SUCCESS; |
| 3257 | } |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 3258 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3259 | goto out; |
Jon Ashburn | 24265ac | 2015-07-31 09:33:21 -0600 | [diff] [blame] | 3260 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3261 | orig_loc = loc; |
| 3262 | loc = reg; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3263 | #endif |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3264 | } else { |
Courtney Goeltzenleuchter | 7f5aafc | 2015-07-05 11:28:29 -0600 | [diff] [blame] | 3265 | loc = loader_stack_alloc(strlen(override) + 1); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3266 | if (loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3267 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3268 | "loader_get_manifest_files: Failed to allocate space for " |
| 3269 | "override environment variable of length %d", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3270 | strlen(override) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3271 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3272 | goto out; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3273 | } |
| 3274 | strcpy(loc, override); |
| 3275 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3276 | |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 3277 | // Print out the paths being searched if debugging is enabled |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3278 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following paths for manifest files: %s\n", loc); |
Liam Middlebrook | 9b14e89 | 2015-07-23 18:32:20 -0700 | [diff] [blame] | 3279 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3280 | file = loc; |
| 3281 | while (*file) { |
| 3282 | next_file = loader_get_next_path(file); |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3283 | if (list_is_dirs) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3284 | sysdir = opendir(file); |
| 3285 | name = NULL; |
| 3286 | if (sysdir) { |
| 3287 | dent = readdir(sysdir); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3288 | if (dent == NULL) break; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3289 | name = &(dent->d_name[0]); |
| 3290 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 3291 | name = full_path; |
| 3292 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3293 | } else { |
Johannes van Waveren | 9bd80501 | 2015-10-28 11:45:00 -0500 | [diff] [blame] | 3294 | #if defined(_WIN32) |
| 3295 | name = file; |
| 3296 | #else |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3297 | // only Linux has relative paths |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3298 | char *dir; |
| 3299 | // make a copy of location so it isn't modified |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 3300 | dir = loader_stack_alloc(strlen(loc) + 1); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3301 | if (dir == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3302 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3303 | "loader_get_manifest_files: Failed to allocate " |
| 3304 | "space for relative location path length %d", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3305 | strlen(loc) + 1); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3306 | goto out; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3307 | } |
Jason Ekstrand | cc7550e | 2015-10-10 08:33:37 -0700 | [diff] [blame] | 3308 | strcpy(dir, loc); |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3309 | |
| 3310 | loader_get_fullpath(file, dir, sizeof(full_path), full_path); |
| 3311 | |
| 3312 | name = full_path; |
Jon Ashburn | ffad94d | 2015-06-30 14:46:22 -0700 | [diff] [blame] | 3313 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3314 | } |
| 3315 | while (name) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3316 | // Look for files ending with ".json" suffix |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3317 | uint32_t nlen = (uint32_t)strlen(name); |
| 3318 | const char *suf = name + nlen - 5; |
Lenny Komow | 408e0bd | 2017-08-09 16:01:59 -0600 | [diff] [blame] | 3319 | |
| 3320 | // Check if the file is already present |
| 3321 | bool file_already_loaded = false; |
| 3322 | for (uint32_t i = 0; i < out_files->count; ++i) { |
| 3323 | if (!strcmp(out_files->filename_list[i], name)) { |
| 3324 | file_already_loaded = true; |
| 3325 | } |
| 3326 | } |
| 3327 | |
| 3328 | if (!file_already_loaded && (nlen > 5) && !strncmp(suf, ".json", 5)) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3329 | if (out_files->count == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3330 | out_files->filename_list = |
| 3331 | loader_instance_heap_alloc(inst, alloced_count * sizeof(char *), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3332 | if (NULL == out_files->filename_list) { |
| 3333 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3334 | "loader_get_manifest_files: Failed to allocate space for manifest file name list"); |
| 3335 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3336 | goto out; |
| 3337 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3338 | } else if (out_files->count == alloced_count) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3339 | void *new_ptr = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3340 | loader_instance_heap_realloc(inst, out_files->filename_list, alloced_count * sizeof(char *), |
| 3341 | alloced_count * sizeof(char *) * 2, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 3342 | if (NULL == new_ptr) { |
| 3343 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3344 | "loader_get_manifest_files: Failed to reallocate space for manifest file name list"); |
| 3345 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3346 | goto out; |
| 3347 | } |
| 3348 | out_files->filename_list = new_ptr; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3349 | alloced_count *= 2; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3350 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3351 | out_files->filename_list[out_files->count] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3352 | loader_instance_heap_alloc(inst, strlen(name) + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3353 | if (out_files->filename_list[out_files->count] == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3354 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3355 | "loader_get_manifest_files: Failed to allocate " |
| 3356 | "space for manifest file %d list", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3357 | out_files->count); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3358 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3359 | goto out; |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3360 | } |
| 3361 | strcpy(out_files->filename_list[out_files->count], name); |
| 3362 | out_files->count++; |
Lenny Komow | 408e0bd | 2017-08-09 16:01:59 -0600 | [diff] [blame] | 3363 | } else if(file_already_loaded) { |
| 3364 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3365 | "Skipping manifest file %s - The file has already been read once", name); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3366 | } else if (!list_is_dirs) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3367 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "Skipping manifest file %s, file name must end in .json", |
| 3368 | name); |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3369 | } |
| 3370 | if (list_is_dirs) { |
| 3371 | dent = readdir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3372 | if (dent == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3373 | break; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3374 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3375 | name = &(dent->d_name[0]); |
| 3376 | loader_get_fullpath(name, file, sizeof(full_path), full_path); |
| 3377 | name = full_path; |
| 3378 | } else { |
| 3379 | break; |
| 3380 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3381 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3382 | if (sysdir) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3383 | closedir(sysdir); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3384 | sysdir = NULL; |
| 3385 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3386 | file = next_file; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3387 | #if !defined(_WIN32) |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3388 | if (relative_location != NULL && (next_file == NULL || *next_file == '\0') && override == NULL) { |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 3389 | char *xdgdatahome = loader_secure_getenv("XDG_DATA_HOME", inst); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3390 | size_t len; |
| 3391 | if (xdgdatahome != NULL) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3392 | size_t alloc_len = strlen(xdgdatahome) + 2 + strlen(relative_location); |
| 3393 | char *home_loc = loader_stack_alloc(alloc_len); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3394 | if (home_loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3395 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3396 | "loader_get_manifest_files: Failed to allocate " |
| 3397 | "space for manifest file XDG Home location"); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3398 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3399 | goto out; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3400 | } |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3401 | strcpy(home_loc, xdgdatahome); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3402 | // Add directory separator if needed |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3403 | if (relative_location[0] != DIRECTORY_SYMBOL) { |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3404 | len = strlen(home_loc); |
| 3405 | home_loc[len] = DIRECTORY_SYMBOL; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 3406 | home_loc[len + 1] = '\0'; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3407 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3408 | strncat(home_loc, relative_location, alloc_len); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3409 | file = home_loc; |
| 3410 | next_file = loader_get_next_path(file); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3411 | relative_location = NULL; |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3412 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3413 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following path for manifest files: %s\n", |
| 3414 | home_loc); |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3415 | list_is_dirs = true; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3416 | |
| 3417 | } else { |
Mark Young | d8c6b69 | 2017-03-09 11:39:41 -0700 | [diff] [blame] | 3418 | char *home = loader_secure_getenv("HOME", inst); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3419 | if (home != NULL) { |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3420 | size_t alloc_len = strlen(home) + 16 + strlen(relative_location); |
| 3421 | char *home_loc = loader_stack_alloc(alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3422 | if (home_loc == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3423 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3424 | "loader_get_manifest_files: Failed to allocate " |
| 3425 | "space for manifest file Home location"); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3426 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3427 | goto out; |
| 3428 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3429 | strncpy(home_loc, home, alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3430 | |
| 3431 | len = strlen(home); |
| 3432 | if (home[len] != DIRECTORY_SYMBOL) { |
| 3433 | home_loc[len] = DIRECTORY_SYMBOL; |
| 3434 | home_loc[len + 1] = '\0'; |
| 3435 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3436 | strncat(home_loc, ".local/share", alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3437 | |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3438 | if (relative_location[0] != DIRECTORY_SYMBOL) { |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3439 | len = strlen(home_loc); |
| 3440 | home_loc[len] = DIRECTORY_SYMBOL; |
| 3441 | home_loc[len + 1] = '\0'; |
| 3442 | } |
Mark Young | 6ef95f4 | 2017-02-17 09:02:23 -0700 | [diff] [blame] | 3443 | strncat(home_loc, relative_location, alloc_len); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3444 | file = home_loc; |
| 3445 | next_file = loader_get_next_path(file); |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3446 | relative_location = NULL; |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3447 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3448 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following path for manifest files: %s\n", |
| 3449 | home_loc); |
John Drinkwater | 9ac3f4f | 2016-08-01 17:00:00 +0100 | [diff] [blame] | 3450 | list_is_dirs = true; |
| 3451 | } else { |
| 3452 | // without knowing HOME, we just.. give up |
| 3453 | } |
Jon Ashburn | 67e262e | 2016-02-18 12:45:39 -0700 | [diff] [blame] | 3454 | } |
| 3455 | } |
| 3456 | #endif |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3457 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3458 | |
| 3459 | out: |
| 3460 | if (VK_SUCCESS != res && NULL != out_files->filename_list) { |
| 3461 | for (uint32_t remove = 0; remove < out_files->count; remove++) { |
| 3462 | loader_instance_heap_free(inst, out_files->filename_list[remove]); |
| 3463 | } |
| 3464 | loader_instance_heap_free(inst, out_files->filename_list); |
| 3465 | out_files->count = 0; |
| 3466 | out_files->filename_list = NULL; |
| 3467 | } |
| 3468 | |
| 3469 | if (NULL != sysdir) { |
| 3470 | closedir(sysdir); |
| 3471 | } |
| 3472 | |
Frank Henigman | b1c27cb | 2016-11-24 20:02:09 -0500 | [diff] [blame] | 3473 | if (override_getenv != NULL) { |
| 3474 | loader_free_getenv(override_getenv, inst); |
| 3475 | } |
| 3476 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3477 | if (NULL != reg && reg != orig_loc) { |
| 3478 | loader_instance_heap_free(inst, reg); |
| 3479 | } |
| 3480 | return res; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3481 | } |
| 3482 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3483 | void loader_init_icd_lib_list() {} |
Jon Ashburn | 8810c5f | 2015-08-18 18:04:47 -0600 | [diff] [blame] | 3484 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3485 | void loader_destroy_icd_lib_list() {} |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3486 | |
| 3487 | // Try to find the Vulkan ICD driver(s). |
| 3488 | // |
| 3489 | // This function scans the default system loader path(s) or path |
| 3490 | // specified by the \c VK_ICD_FILENAMES environment variable in |
| 3491 | // order to find loadable VK ICDs manifest files. From these |
| 3492 | // manifest files it finds the ICD libraries. |
| 3493 | // |
| 3494 | // \returns |
| 3495 | // Vulkan result |
| 3496 | // (on result == VK_SUCCESS) a list of icds that were discovered |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3497 | VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3498 | char *file_str; |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3499 | uint16_t file_major_vers = 0; |
| 3500 | uint16_t file_minor_vers = 0; |
| 3501 | uint16_t file_patch_vers = 0; |
| 3502 | char *vers_tok; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3503 | struct loader_manifest_files manifest_files; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3504 | VkResult res = VK_SUCCESS; |
| 3505 | bool lockedMutex = false; |
| 3506 | cJSON *json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3507 | uint32_t num_good_icds = 0; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3508 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3509 | memset(&manifest_files, 0, sizeof(struct loader_manifest_files)); |
| 3510 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 3511 | res = loader_scanned_icd_init(inst, icd_tramp_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3512 | if (VK_SUCCESS != res) { |
| 3513 | goto out; |
| 3514 | } |
| 3515 | |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3516 | // Get a list of manifest files for ICDs |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3517 | res = loader_get_manifest_files(inst, "VK_ICD_FILENAMES", NULL, false, true, DEFAULT_VK_DRIVERS_INFO, RELATIVE_VK_DRIVERS_INFO, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3518 | &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3519 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
| 3520 | goto out; |
| 3521 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3522 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3523 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3524 | lockedMutex = true; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3525 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3526 | file_str = manifest_files.filename_list[i]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3527 | if (file_str == NULL) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3528 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3529 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3530 | |
Mark Young | dcd5f7e | 2017-04-25 10:35:54 -0600 | [diff] [blame] | 3531 | VkResult temp_res = loader_get_json(inst, file_str, &json); |
| 3532 | if (NULL == json || temp_res != VK_SUCCESS) { |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3533 | if (NULL != json) { |
| 3534 | cJSON_Delete(json); |
| 3535 | json = NULL; |
| 3536 | } |
Mark Young | dcd5f7e | 2017-04-25 10:35:54 -0600 | [diff] [blame] | 3537 | // If we haven't already found an ICD, copy this result to |
| 3538 | // the returned result. |
| 3539 | if (num_good_icds == 0) { |
| 3540 | res = temp_res; |
| 3541 | } |
| 3542 | if (temp_res == VK_ERROR_OUT_OF_HOST_MEMORY) { |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3543 | break; |
| 3544 | } else { |
| 3545 | continue; |
| 3546 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3547 | } |
Mark Young | dcd5f7e | 2017-04-25 10:35:54 -0600 | [diff] [blame] | 3548 | res = temp_res; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3549 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3550 | cJSON *item, *itemICD; |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3551 | item = cJSON_GetObjectItem(json, "file_format_version"); |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3552 | if (item == NULL) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3553 | if (num_good_icds == 0) { |
| 3554 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 3555 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3556 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3557 | "loader_icd_scan: ICD JSON %s does not have a" |
| 3558 | " \'file_format_version\' field. Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3559 | file_str); |
Derrick Owens | 62e16ef | 2016-09-09 15:49:07 -0400 | [diff] [blame] | 3560 | cJSON_Delete(json); |
| 3561 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3562 | continue; |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3563 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3564 | |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3565 | char *file_vers = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3566 | if (NULL == file_vers) { |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3567 | // Only reason the print can fail is if there was an allocation issue |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3568 | if (num_good_icds == 0) { |
| 3569 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3570 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3571 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3572 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3573 | " \'file_format_version\' field. Skipping ICD JSON", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3574 | file_str); |
Derrick Owens | cd92b8b | 2016-09-09 15:45:13 -0400 | [diff] [blame] | 3575 | cJSON_Delete(json); |
| 3576 | json = NULL; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3577 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3578 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3579 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Found ICD manifest file %s, version %s", file_str, file_vers); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3580 | |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3581 | // Get the major/minor/and patch as integers for easier comparison |
| 3582 | vers_tok = strtok(file_vers, ".\"\n\r"); |
| 3583 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3584 | file_major_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3585 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3586 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3587 | file_minor_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3588 | vers_tok = strtok(NULL, ".\"\n\r"); |
| 3589 | if (NULL != vers_tok) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3590 | file_patch_vers = (uint16_t)atoi(vers_tok); |
Mark Young | c3a6d2e | 2016-06-13 14:49:53 -0600 | [diff] [blame] | 3591 | } |
| 3592 | } |
| 3593 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3594 | |
| 3595 | if (file_major_vers != 1 || file_minor_vers != 0 || file_patch_vers > 1) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3596 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3597 | "loader_icd_scan: Unexpected manifest file version " |
| 3598 | "(expected 1.0.0 or 1.0.1), may cause errors"); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3599 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3600 | cJSON_Free(file_vers); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3601 | |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3602 | itemICD = cJSON_GetObjectItem(json, "ICD"); |
| 3603 | if (itemICD != NULL) { |
| 3604 | item = cJSON_GetObjectItem(itemICD, "library_path"); |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3605 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3606 | char *temp = cJSON_Print(item); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3607 | if (!temp || strlen(temp) == 0) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3608 | if (num_good_icds == 0) { |
| 3609 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3610 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3611 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3612 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3613 | " \'library_path\' field. Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3614 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3615 | cJSON_Free(temp); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3616 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3617 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3618 | continue; |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3619 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3620 | // strip out extra quotes |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3621 | temp[strlen(temp) - 1] = '\0'; |
| 3622 | char *library_path = loader_stack_alloc(strlen(temp) + 1); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3623 | if (NULL == library_path) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3624 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3625 | "loader_icd_scan: Failed to allocate space for " |
| 3626 | "ICD JSON %s \'library_path\' value. Skipping " |
| 3627 | "ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3628 | file_str); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3629 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3630 | cJSON_Free(temp); |
| 3631 | cJSON_Delete(json); |
| 3632 | json = NULL; |
| 3633 | goto out; |
| 3634 | } |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3635 | strcpy(library_path, &temp[1]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3636 | cJSON_Free(temp); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3637 | if (strlen(library_path) == 0) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3638 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3639 | "loader_icd_scan: ICD JSON %s \'library_path\'" |
| 3640 | " field is empty. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3641 | file_str); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3642 | cJSON_Delete(json); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3643 | json = NULL; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3644 | continue; |
| 3645 | } |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3646 | char fullpath[MAX_STRING_SIZE]; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3647 | // Print out the paths being searched if debugging is enabled |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3648 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching for ICD drivers named %s, using default dir %s", |
| 3649 | library_path, DEFAULT_VK_DRIVERS_PATH); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3650 | if (loader_platform_is_path(library_path)) { |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3651 | // a relative or absolute path |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3652 | char *name_copy = loader_stack_alloc(strlen(file_str) + 1); |
| 3653 | char *rel_base; |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3654 | strcpy(name_copy, file_str); |
| 3655 | rel_base = loader_platform_dirname(name_copy); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3656 | loader_expand_path(library_path, rel_base, sizeof(fullpath), fullpath); |
Daniel Dadap | 00b4aba | 2015-09-30 11:50:51 -0500 | [diff] [blame] | 3657 | } else { |
Jamie Madill | 2fcbd15 | 2016-04-27 16:33:23 -0400 | [diff] [blame] | 3658 | // a filename which is assumed in a system directory |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3659 | loader_get_fullpath(library_path, DEFAULT_VK_DRIVERS_PATH, sizeof(fullpath), fullpath); |
Jon Ashburn | 8625130 | 2015-08-25 16:48:24 -0600 | [diff] [blame] | 3660 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3661 | |
| 3662 | uint32_t vers = 0; |
| 3663 | item = cJSON_GetObjectItem(itemICD, "api_version"); |
| 3664 | if (item != NULL) { |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3665 | temp = cJSON_Print(item); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3666 | if (NULL == temp) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3667 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3668 | "loader_icd_scan: Failed retrieving ICD JSON %s" |
| 3669 | " \'api_version\' field. Skipping ICD JSON.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3670 | file_str); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3671 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3672 | // Only reason the print can fail is if there was an |
| 3673 | // allocation issue |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3674 | if (num_good_icds == 0) { |
| 3675 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 3676 | } |
| 3677 | |
| 3678 | cJSON_Free(temp); |
| 3679 | cJSON_Delete(json); |
| 3680 | json = NULL; |
| 3681 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3682 | } |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3683 | vers = loader_make_version(temp); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3684 | cJSON_Free(temp); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3685 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3686 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3687 | "loader_icd_scan: ICD JSON %s does not have an" |
| 3688 | " \'api_version\' field.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3689 | file_str); |
Jon Ashburn | 005617f | 2015-11-17 17:35:40 -0700 | [diff] [blame] | 3690 | } |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3691 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3692 | res = loader_scanned_icd_add(inst, icd_tramp_list, fullpath, vers); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3693 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3694 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 3695 | "loader_icd_scan: Failed to add ICD JSON %s. " |
| 3696 | " Skipping ICD JSON.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3697 | fullpath); |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3698 | cJSON_Delete(json); |
| 3699 | json = NULL; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3700 | continue; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3701 | } |
| 3702 | num_good_icds++; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3703 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3704 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3705 | "loader_icd_scan: Failed to find \'library_path\' " |
| 3706 | "object in ICD JSON file %s. Skipping ICD JSON.", |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3707 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3708 | } |
| 3709 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3710 | loader_log(inst, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 3711 | "loader_icd_scan: Can not find \'ICD\' object in ICD JSON " |
| 3712 | "file %s. Skipping ICD JSON", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3713 | file_str); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3714 | } |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3715 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3716 | cJSON_Delete(json); |
| 3717 | json = NULL; |
| 3718 | } |
| 3719 | |
| 3720 | out: |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 3721 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3722 | if (NULL != json) { |
Jon Ashburn | 2077e38 | 2015-06-29 11:25:34 -0600 | [diff] [blame] | 3723 | cJSON_Delete(json); |
| 3724 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3725 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3726 | if (NULL != manifest_files.filename_list) { |
| 3727 | for (uint32_t i = 0; i < manifest_files.count; i++) { |
| 3728 | if (NULL != manifest_files.filename_list[i]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3729 | loader_instance_heap_free(inst, manifest_files.filename_list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | loader_instance_heap_free(inst, manifest_files.filename_list); |
| 3733 | } |
| 3734 | if (lockedMutex) { |
| 3735 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3736 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 3737 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3738 | return res; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 3739 | } |
| 3740 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3741 | void loader_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3742 | char *file_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3743 | struct loader_manifest_files manifest_files[2]; // [0] = explicit, [1] = implicit |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3744 | cJSON *json; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3745 | uint32_t implicit; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3746 | bool lockedMutex = false; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3747 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3748 | memset(manifest_files, 0, sizeof(struct loader_manifest_files) * 2); |
| 3749 | |
| 3750 | // Get a list of manifest files for explicit layers |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3751 | if (VK_SUCCESS != loader_get_manifest_files(inst, LAYERS_PATH_ENV, LAYERS_SOURCE_PATH, true, true, DEFAULT_VK_ELAYERS_INFO, |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3752 | RELATIVE_VK_ELAYERS_INFO, &manifest_files[0])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3753 | goto out; |
| 3754 | } |
| 3755 | |
| 3756 | // Get a list of manifest files for any implicit layers |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 3757 | // Pass NULL for environment variable override - implicit layers are not |
| 3758 | // overridden by LAYERS_PATH_ENV |
Benjamin Saunders | 31a4801 | 2017-01-29 14:49:54 -0800 | [diff] [blame] | 3759 | if (VK_SUCCESS != loader_get_manifest_files(inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, RELATIVE_VK_ILAYERS_INFO, |
Mark Young | f8c2010 | 2016-11-07 16:26:17 -0700 | [diff] [blame] | 3760 | &manifest_files[1])) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3761 | goto out; |
| 3762 | } |
Jon Ashburn | 90c6a0e | 2015-06-04 15:30:58 -0600 | [diff] [blame] | 3763 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3764 | // Make sure we have at least one layer, if not, go ahead and return |
| 3765 | if (manifest_files[0].count == 0 && manifest_files[1].count == 0) { |
| 3766 | goto out; |
| 3767 | } |
| 3768 | |
| 3769 | // cleanup any previously scanned libraries |
Jon Ashburn | e39a4f8 | 2015-08-28 13:38:21 -0600 | [diff] [blame] | 3770 | loader_delete_layer_properties(inst, instance_layers); |
Jon Ashburn | b2ef137 | 2015-07-16 17:19:31 -0600 | [diff] [blame] | 3771 | |
Jon Ashburn | 6461ef2 | 2015-09-22 13:11:00 -0600 | [diff] [blame] | 3772 | loader_platform_thread_lock_mutex(&loader_json_lock); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3773 | lockedMutex = true; |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3774 | for (implicit = 0; implicit < 2; implicit++) { |
Jamie Madill | 970ebcf | 2016-07-06 11:19:42 -0400 | [diff] [blame] | 3775 | for (uint32_t i = 0; i < manifest_files[implicit].count; i++) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3776 | file_str = manifest_files[implicit].filename_list[i]; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3777 | if (file_str == NULL) continue; |
Courtney Goeltzenleuchter | a9e4af4 | 2015-06-01 14:49:17 -0600 | [diff] [blame] | 3778 | |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3779 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3780 | VkResult res = loader_get_json(inst, file_str, &json); |
| 3781 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3782 | break; |
| 3783 | } else if (VK_SUCCESS != res || NULL == json) { |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3784 | continue; |
| 3785 | } |
| 3786 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3787 | VkResult local_res = loader_add_layer_properties(inst, instance_layers, json, (implicit == 1), file_str); |
Jon Ashburn | 075ce43 | 2015-12-17 17:38:24 -0700 | [diff] [blame] | 3788 | cJSON_Delete(json); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3789 | |
Lenny Komow | 9a73b66 | 2018-02-13 10:30:02 -0700 | [diff] [blame] | 3790 | // If the error is anything other than out of memory we still want to try to load the other layers |
| 3791 | if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3792 | goto out; |
| 3793 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3794 | } |
Jon Ashburn | 2d0c4bb | 2015-07-06 15:40:35 -0600 | [diff] [blame] | 3795 | } |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3796 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3797 | // See if "VK_LAYER_LUNARG_standard_validation" already in list. |
| 3798 | bool found_std_val = false; |
| 3799 | for (uint32_t i = 0; i < instance_layers->count; i++) { |
| 3800 | struct loader_layer_properties *props = &instance_layers->list[i]; |
| 3801 | if (strcmp(props->info.layerName, std_validation_str) == 0) { |
| 3802 | found_std_val = true; |
| 3803 | break; |
| 3804 | } |
| 3805 | } |
| 3806 | |
| 3807 | // If we didn't find the VK_LAYER_LUNARG_standard_validation meta-layer in |
| 3808 | // the list, then we need to add it manually. This is likely because we're |
| 3809 | // dealing with a new loader, but an old layer folder. |
| 3810 | if (!found_std_val && !loader_add_legacy_std_val_layer(inst, instance_layers)) { |
| 3811 | goto out; |
| 3812 | } |
| 3813 | |
| 3814 | // Verify any meta-layers in the list are valid and all the component layers are |
| 3815 | // actually present in the available layer list |
| 3816 | verify_all_meta_layers(inst, instance_layers); |
Jon Ashburn | 86a527a | 2016-02-10 20:59:26 -0700 | [diff] [blame] | 3817 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3818 | out: |
| 3819 | |
| 3820 | for (uint32_t manFile = 0; manFile < 2; manFile++) { |
| 3821 | if (NULL != manifest_files[manFile].filename_list) { |
| 3822 | for (uint32_t i = 0; i < manifest_files[manFile].count; i++) { |
| 3823 | if (NULL != manifest_files[manFile].filename_list[i]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3824 | loader_instance_heap_free(inst, manifest_files[manFile].filename_list[i]); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3825 | } |
| 3826 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3827 | loader_instance_heap_free(inst, manifest_files[manFile].filename_list); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3828 | } |
| 3829 | } |
| 3830 | if (lockedMutex) { |
| 3831 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3832 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 3833 | } |
| 3834 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3835 | void loader_implicit_layer_scan(const struct loader_instance *inst, struct loader_layer_list *instance_layers) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3836 | char *file_str; |
| 3837 | struct loader_manifest_files manifest_files; |
| 3838 | cJSON *json; |
| 3839 | uint32_t i; |
| 3840 | |
| 3841 | // Pass NULL for environment variable override - implicit layers are not |
| 3842 | // overridden by LAYERS_PATH_ENV |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3843 | VkResult res = loader_get_manifest_files(inst, NULL, NULL, true, false, DEFAULT_VK_ILAYERS_INFO, RELATIVE_VK_ILAYERS_INFO, |
| 3844 | &manifest_files); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3845 | if (VK_SUCCESS != res || manifest_files.count == 0) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3846 | return; |
| 3847 | } |
| 3848 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3849 | // Cleanup any previously scanned libraries |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3850 | loader_delete_layer_properties(inst, instance_layers); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3851 | |
| 3852 | loader_platform_thread_lock_mutex(&loader_json_lock); |
| 3853 | |
| 3854 | for (i = 0; i < manifest_files.count; i++) { |
| 3855 | file_str = manifest_files.filename_list[i]; |
| 3856 | if (file_str == NULL) { |
| 3857 | continue; |
| 3858 | } |
| 3859 | |
| 3860 | // parse file into JSON struct |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 3861 | res = loader_get_json(inst, file_str, &json); |
| 3862 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3863 | break; |
| 3864 | } else if (VK_SUCCESS != res || NULL == json) { |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3865 | continue; |
| 3866 | } |
| 3867 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3868 | res = loader_add_layer_properties(inst, instance_layers, json, true, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3869 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3870 | loader_instance_heap_free(inst, file_str); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3871 | cJSON_Delete(json); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 3872 | |
| 3873 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 3874 | break; |
| 3875 | } |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3876 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 3877 | loader_instance_heap_free(inst, manifest_files.filename_list); |
Jeremy Hayes | 3e2bd5a | 2016-04-01 11:40:26 -0600 | [diff] [blame] | 3878 | loader_platform_thread_unlock_mutex(&loader_json_lock); |
| 3879 | } |
| 3880 | |
Jean-Francois Roy | bd7ceab | 2017-07-06 14:10:13 -0700 | [diff] [blame] | 3881 | // Check if an implicit layer should be enabled. |
| 3882 | bool loader_is_implicit_layer_enabled(const struct loader_instance *inst, const struct loader_layer_properties *prop) { |
| 3883 | bool enable = false; |
| 3884 | char *env_value = NULL; |
| 3885 | |
| 3886 | // if no enable_environment variable is specified, this implicit layer |
| 3887 | // should always be enabled. Otherwise check if the variable is set |
| 3888 | if (prop->enable_env_var.name[0] == 0) { |
| 3889 | enable = true; |
| 3890 | } else { |
| 3891 | env_value = loader_secure_getenv(prop->enable_env_var.name, inst); |
| 3892 | if (env_value && !strcmp(prop->enable_env_var.value, env_value)) enable = true; |
| 3893 | loader_free_getenv(env_value, inst); |
| 3894 | } |
| 3895 | |
| 3896 | // disable_environment has priority, i.e. if both enable and disable |
| 3897 | // environment variables are set, the layer is disabled. Implicit |
| 3898 | // layers are required to have a disable_environment variables |
| 3899 | env_value = loader_secure_getenv(prop->disable_env_var.name, inst); |
| 3900 | if (env_value && !strcmp(prop->disable_env_var.value, env_value)) enable = false; |
| 3901 | loader_free_getenv(env_value, inst); |
| 3902 | |
| 3903 | return enable; |
| 3904 | } |
| 3905 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3906 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpdpa_instance_internal(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3907 | // inst is not wrapped |
| 3908 | if (inst == VK_NULL_HANDLE) { |
| 3909 | return NULL; |
| 3910 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3911 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3912 | void *addr; |
| 3913 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3914 | if (disp_table == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3915 | |
| 3916 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3917 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3918 | if (found_name) { |
| 3919 | return addr; |
| 3920 | } |
| 3921 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3922 | if (loader_phys_dev_ext_gpa(loader_get_instance(inst), pName, true, NULL, &addr)) return addr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3923 | |
| 3924 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3925 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpdpa_instance_internal() unrecognized name %s", pName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3926 | return NULL; |
| 3927 | } |
| 3928 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3929 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpdpa_instance_terminator(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3930 | // inst is not wrapped |
| 3931 | if (inst == VK_NULL_HANDLE) { |
| 3932 | return NULL; |
| 3933 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3934 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3935 | void *addr; |
| 3936 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3937 | if (disp_table == NULL) return NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3938 | |
| 3939 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3940 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3941 | if (found_name) { |
| 3942 | return addr; |
| 3943 | } |
| 3944 | |
| 3945 | // Get the terminator, but don't perform checking since it should already |
| 3946 | // have been setup if we get here. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3947 | if (loader_phys_dev_ext_gpa(loader_get_instance(inst), pName, false, NULL, &addr)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3948 | return addr; |
| 3949 | } |
| 3950 | |
| 3951 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3952 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpdpa_instance_terminator() unrecognized name %s", pName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3953 | return NULL; |
| 3954 | } |
| 3955 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3956 | static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpa_instance_internal(VkInstance inst, const char *pName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 3957 | if (!strcmp(pName, "vkGetInstanceProcAddr")) { |
| 3958 | return (PFN_vkVoidFunction)loader_gpa_instance_internal; |
| 3959 | } |
| 3960 | if (!strcmp(pName, "vk_layerGetPhysicalDeviceProcAddr")) { |
| 3961 | return (PFN_vkVoidFunction)loader_gpdpa_instance_terminator; |
| 3962 | } |
| 3963 | if (!strcmp(pName, "vkCreateInstance")) { |
| 3964 | return (PFN_vkVoidFunction)terminator_CreateInstance; |
| 3965 | } |
| 3966 | if (!strcmp(pName, "vkCreateDevice")) { |
| 3967 | return (PFN_vkVoidFunction)terminator_CreateDevice; |
| 3968 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 3969 | |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3970 | // inst is not wrapped |
| 3971 | if (inst == VK_NULL_HANDLE) { |
| 3972 | return NULL; |
| 3973 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3974 | VkLayerInstanceDispatchTable *disp_table = *(VkLayerInstanceDispatchTable **)inst; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3975 | void *addr; |
| 3976 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3977 | if (disp_table == NULL) return NULL; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3978 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3979 | bool found_name; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3980 | addr = loader_lookup_instance_dispatch_table(disp_table, pName, &found_name); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3981 | if (found_name) { |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 3982 | return addr; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3983 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 3984 | |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3985 | // Don't call down the chain, this would be an infinite loop |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3986 | loader_log(NULL, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, "loader_gpa_instance_internal() unrecognized name %s", pName); |
Jon Ashburn | c7d3e73 | 2016-03-08 09:30:30 -0700 | [diff] [blame] | 3987 | return NULL; |
Jon Ashburn | 3d526cb | 2015-04-13 18:10:06 -0600 | [diff] [blame] | 3988 | } |
| 3989 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3990 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL loader_gpa_device_internal(VkDevice device, const char *pName) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 3991 | struct loader_device *dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 3992 | struct loader_icd_term *icd_term = loader_get_icd_and_device(device, &dev, NULL); |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 3993 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 3994 | // Return this function if a layer above here is asking for the vkGetDeviceProcAddr. |
| 3995 | // This is so we can properly intercept any device commands needing a terminator. |
| 3996 | if (!strcmp(pName, "vkGetDeviceProcAddr")) { |
| 3997 | return (PFN_vkVoidFunction)loader_gpa_device_internal; |
| 3998 | } |
| 3999 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4000 | // NOTE: Device Funcs needing Trampoline/Terminator. |
| 4001 | // Overrides for device functions needing a trampoline and |
| 4002 | // a terminator because certain device entry-points still need to go |
| 4003 | // through a terminator before hitting the ICD. This could be for |
| 4004 | // several reasons, but the main one is currently unwrapping an |
| 4005 | // object before passing the appropriate info along to the ICD. |
| 4006 | // This is why we also have to override the direct ICD call to |
| 4007 | // vkGetDeviceProcAddr to intercept those calls. |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4008 | PFN_vkVoidFunction addr = get_extension_device_proc_terminator(pName); |
| 4009 | if (NULL != addr) { |
| 4010 | return addr; |
Mark Young | 16573c7 | 2016-06-28 10:52:43 -0600 | [diff] [blame] | 4011 | } |
| 4012 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4013 | return icd_term->dispatch.GetDeviceProcAddr(device, pName); |
Piers Daniell | 295fe40 | 2016-03-29 11:51:11 -0600 | [diff] [blame] | 4014 | } |
| 4015 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4016 | // Initialize device_ext dispatch table entry as follows: |
| 4017 | // If dev == NULL find all logical devices created within this instance and |
| 4018 | // init the entry (given by idx) in the ext dispatch table. |
| 4019 | // If dev != NULL only initialize the entry in the given dev's dispatch table. |
| 4020 | // The initialization value is gotten by calling down the device chain with |
| 4021 | // GDPA. |
| 4022 | // If GDPA returns NULL then don't initialize the dispatch table entry. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4023 | static void loader_init_dispatch_dev_ext_entry(struct loader_instance *inst, struct loader_device *dev, uint32_t idx, |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4024 | const char *funcName) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4025 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4026 | { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4027 | void *gdpa_value; |
| 4028 | if (dev != NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4029 | gdpa_value = dev->loader_dispatch.core_dispatch.GetDeviceProcAddr(dev->chain_device, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4030 | if (gdpa_value != NULL) dev->loader_dispatch.ext_dispatch.dev_ext[idx] = (PFN_vkDevExt)gdpa_value; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4031 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4032 | for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4033 | struct loader_device *ldev = icd_term->logical_device_list; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 4034 | while (ldev) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4035 | gdpa_value = ldev->loader_dispatch.core_dispatch.GetDeviceProcAddr(ldev->chain_device, funcName); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4036 | if (gdpa_value != NULL) ldev->loader_dispatch.ext_dispatch.dev_ext[idx] = (PFN_vkDevExt)gdpa_value; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 4037 | ldev = ldev->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4038 | } |
| 4039 | } |
| 4040 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4043 | // Find all dev extension in the hash table and initialize the dispatch table |
| 4044 | // for dev for each of those extension entrypoints found in hash table. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4045 | void loader_init_dispatch_dev_ext(struct loader_instance *inst, struct loader_device *dev) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4046 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
| 4047 | if (inst->dev_ext_disp_hash[i].func_name != NULL) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4048 | loader_init_dispatch_dev_ext_entry(inst, dev, i, inst->dev_ext_disp_hash[i].func_name); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4049 | } |
| 4050 | } |
| 4051 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4052 | static bool loader_check_icds_for_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4053 | struct loader_icd_term *icd_term; |
| 4054 | icd_term = inst->icd_terms; |
| 4055 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4056 | if (icd_term->scanned_icd->GetInstanceProcAddr(icd_term->instance, funcName)) |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4057 | // this icd supports funcName |
| 4058 | return true; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 4059 | icd_term = icd_term->next; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | return false; |
| 4063 | } |
| 4064 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4065 | static bool loader_check_layer_list_for_dev_ext_address(const struct loader_layer_list *const layers, const char *funcName) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 4066 | // Iterate over the layers. |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4067 | for (uint32_t layer = 0; layer < layers->count; ++layer) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 4068 | // Iterate over the extensions. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4069 | const struct loader_device_extension_list *const extensions = &(layers->list[layer].device_extension_list); |
| 4070 | for (uint32_t extension = 0; extension < extensions->count; ++extension) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 4071 | // Iterate over the entry points. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4072 | const struct loader_dev_ext_props *const property = &(extensions->list[extension]); |
| 4073 | for (uint32_t entry = 0; entry < property->entrypoint_count; ++entry) { |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4074 | if (strcmp(property->entrypoints[entry], funcName) == 0) { |
Jeremy Hayes | 1eb1f62 | 2016-03-03 16:03:03 -0700 | [diff] [blame] | 4075 | return true; |
| 4076 | } |
| 4077 | } |
| 4078 | } |
| 4079 | } |
| 4080 | |
| 4081 | return false; |
| 4082 | } |
| 4083 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4084 | static void loader_free_dev_ext_table(struct loader_instance *inst) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4085 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
| 4086 | loader_instance_heap_free(inst, inst->dev_ext_disp_hash[i].func_name); |
| 4087 | loader_instance_heap_free(inst, inst->dev_ext_disp_hash[i].list.index); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4088 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4089 | memset(inst->dev_ext_disp_hash, 0, sizeof(inst->dev_ext_disp_hash)); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4092 | static bool loader_add_dev_ext_table(struct loader_instance *inst, uint32_t *ptr_idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4093 | uint32_t i; |
| 4094 | uint32_t idx = *ptr_idx; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4095 | struct loader_dispatch_hash_list *list = &inst->dev_ext_disp_hash[idx].list; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4096 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4097 | if (!inst->dev_ext_disp_hash[idx].func_name) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4098 | // no entry here at this idx, so use it |
| 4099 | assert(list->capacity == 0); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4100 | inst->dev_ext_disp_hash[idx].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4101 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4102 | if (inst->dev_ext_disp_hash[idx].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4103 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4104 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 4105 | "for func_name %s", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4106 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4107 | return false; |
| 4108 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4109 | strncpy(inst->dev_ext_disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4110 | return true; |
| 4111 | } |
| 4112 | |
| 4113 | // check for enough capacity |
| 4114 | if (list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4115 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4116 | if (list->index == NULL) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4117 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_dev_ext_table: Failed to allocate memory for list index", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4118 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4119 | return false; |
| 4120 | } |
| 4121 | list->capacity = 8 * sizeof(*(list->index)); |
| 4122 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4123 | void *new_ptr = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, |
| 4124 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4125 | if (NULL == new_ptr) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4126 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4127 | "loader_add_dev_ext_table: Failed to reallocate memory for list index", funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4128 | return false; |
| 4129 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4130 | list->index = new_ptr; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4131 | list->capacity *= 2; |
| 4132 | } |
| 4133 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4134 | // find an unused index in the hash table and use it |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4135 | i = (idx + 1) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4136 | do { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4137 | if (!inst->dev_ext_disp_hash[i].func_name) { |
| 4138 | assert(inst->dev_ext_disp_hash[i].list.capacity == 0); |
| 4139 | inst->dev_ext_disp_hash[i].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4140 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4141 | if (inst->dev_ext_disp_hash[i].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4142 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4143 | "loader_add_dev_ext_table: Failed to allocate memory " |
| 4144 | "for func_name %s", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4145 | funcName); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4146 | return false; |
| 4147 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4148 | strncpy(inst->dev_ext_disp_hash[i].func_name, funcName, strlen(funcName) + 1); |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4149 | list->index[list->count] = i; |
| 4150 | list->count++; |
| 4151 | *ptr_idx = i; |
| 4152 | return true; |
| 4153 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4154 | i = (i + 1) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4155 | } while (i != idx); |
| 4156 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4157 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4158 | "loader_add_dev_ext_table: Could not insert into hash table; is " |
| 4159 | "it full?"); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 4160 | |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4161 | return false; |
| 4162 | } |
| 4163 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4164 | static bool loader_name_in_dev_ext_table(struct loader_instance *inst, uint32_t *idx, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4165 | uint32_t alt_idx; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4166 | if (inst->dev_ext_disp_hash[*idx].func_name && !strcmp(inst->dev_ext_disp_hash[*idx].func_name, funcName)) return true; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4167 | |
| 4168 | // funcName wasn't at the primary spot in the hash table |
| 4169 | // search the list of secondary locations (shallow search, not deep search) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4170 | for (uint32_t i = 0; i < inst->dev_ext_disp_hash[*idx].list.count; i++) { |
| 4171 | alt_idx = inst->dev_ext_disp_hash[*idx].list.index[i]; |
| 4172 | if (!strcmp(inst->dev_ext_disp_hash[*idx].func_name, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4173 | *idx = alt_idx; |
| 4174 | return true; |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | return false; |
| 4179 | } |
| 4180 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4181 | // This function returns generic trampoline code address for unknown entry |
| 4182 | // points. |
| 4183 | // Presumably, these unknown entry points (as given by funcName) are device |
| 4184 | // extension entrypoints. A hash table is used to keep a list of unknown entry |
| 4185 | // points and their mapping to the device extension dispatch table |
| 4186 | // (struct loader_dev_ext_dispatch_table). |
| 4187 | // \returns |
| 4188 | // For a given entry point string (funcName), if an existing mapping is found |
| 4189 | // the |
| 4190 | // trampoline address for that mapping is returned. Otherwise, this unknown |
| 4191 | // entry point |
| 4192 | // has not been seen yet. Next check if a layer or ICD supports it. If so then |
| 4193 | // a |
| 4194 | // new entry in the hash table is initialized and that trampoline address for |
| 4195 | // the new entry is returned. Null is returned if the hash table is full or |
| 4196 | // if no discovered layer or ICD returns a non-NULL GetProcAddr for it. |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4197 | void *loader_dev_ext_gpa(struct loader_instance *inst, const char *funcName) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4198 | uint32_t idx; |
| 4199 | uint32_t seed = 0; |
| 4200 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4201 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_UNKNOWN_EXTS; |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4202 | |
| 4203 | if (loader_name_in_dev_ext_table(inst, &idx, funcName)) |
| 4204 | // found funcName already in hash |
| 4205 | return loader_get_dev_ext_trampoline(idx); |
| 4206 | |
| 4207 | // Check if funcName is supported in either ICDs or a layer library |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4208 | if (!loader_check_icds_for_dev_ext_address(inst, funcName) && |
Lenny Komow | b1685e0 | 2017-08-29 16:08:39 -0600 | [diff] [blame] | 4209 | !loader_check_layer_list_for_dev_ext_address(&inst->app_activated_layer_list, funcName)) { |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4210 | // if support found in layers continue on |
| 4211 | return NULL; |
| 4212 | } |
| 4213 | |
| 4214 | if (loader_add_dev_ext_table(inst, &idx, funcName)) { |
| 4215 | // successfully added new table entry |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4216 | // init any dev dispatch table entries as needed |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 4217 | loader_init_dispatch_dev_ext_entry(inst, NULL, idx, funcName); |
| 4218 | return loader_get_dev_ext_trampoline(idx); |
| 4219 | } |
| 4220 | |
| 4221 | return NULL; |
| 4222 | } |
| 4223 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4224 | static bool loader_check_icds_for_phys_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4225 | struct loader_icd_term *icd_term; |
| 4226 | icd_term = inst->icd_terms; |
| 4227 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4228 | if (icd_term->scanned_icd->interface_version >= MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION && |
| 4229 | icd_term->scanned_icd->GetPhysicalDeviceProcAddr(icd_term->instance, funcName)) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4230 | // this icd supports funcName |
| 4231 | return true; |
| 4232 | icd_term = icd_term->next; |
| 4233 | } |
| 4234 | |
| 4235 | return false; |
| 4236 | } |
| 4237 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4238 | static bool loader_check_layer_list_for_phys_dev_ext_address(struct loader_instance *inst, const char *funcName) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4239 | struct loader_layer_properties *layer_prop_list = inst->expanded_activated_layer_list.list; |
| 4240 | for (uint32_t layer = 0; layer < inst->expanded_activated_layer_list.count; ++layer) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4241 | // If this layer supports the vk_layerGetPhysicalDeviceProcAddr, then call |
| 4242 | // it and see if it returns a valid pointer for this function name. |
| 4243 | if (layer_prop_list[layer].interface_version > 1) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4244 | const struct loader_layer_functions *const functions = &(layer_prop_list[layer].functions); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4245 | if (NULL != functions->get_physical_device_proc_addr && |
Tony Barbour | 55bd539 | 2017-05-17 12:17:18 -0600 | [diff] [blame] | 4246 | NULL != functions->get_physical_device_proc_addr((VkInstance)inst->instance, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4247 | return true; |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | |
| 4252 | return false; |
| 4253 | } |
| 4254 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4255 | static void loader_free_phys_dev_ext_table(struct loader_instance *inst) { |
| 4256 | for (uint32_t i = 0; i < MAX_NUM_UNKNOWN_EXTS; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4257 | loader_instance_heap_free(inst, inst->phys_dev_ext_disp_hash[i].func_name); |
| 4258 | loader_instance_heap_free(inst, inst->phys_dev_ext_disp_hash[i].list.index); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4259 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4260 | memset(inst->phys_dev_ext_disp_hash, 0, sizeof(inst->phys_dev_ext_disp_hash)); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4261 | } |
| 4262 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4263 | static bool loader_add_phys_dev_ext_table(struct loader_instance *inst, uint32_t *ptr_idx, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4264 | uint32_t i; |
| 4265 | uint32_t idx = *ptr_idx; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4266 | struct loader_dispatch_hash_list *list = &inst->phys_dev_ext_disp_hash[idx].list; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4267 | |
| 4268 | if (!inst->phys_dev_ext_disp_hash[idx].func_name) { |
| 4269 | // no entry here at this idx, so use it |
| 4270 | assert(list->capacity == 0); |
| 4271 | inst->phys_dev_ext_disp_hash[idx].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4272 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4273 | if (inst->phys_dev_ext_disp_hash[idx].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4274 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4275 | "loader_add_phys_dev_ext_table() can't allocate memory for " |
| 4276 | "func_name"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4277 | return false; |
| 4278 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4279 | strncpy(inst->phys_dev_ext_disp_hash[idx].func_name, funcName, strlen(funcName) + 1); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4280 | return true; |
| 4281 | } |
| 4282 | |
| 4283 | // check for enough capacity |
| 4284 | if (list->capacity == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4285 | list->index = loader_instance_heap_alloc(inst, 8 * sizeof(*(list->index)), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4286 | if (list->index == NULL) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4287 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't allocate list memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4288 | return false; |
| 4289 | } |
| 4290 | list->capacity = 8 * sizeof(*(list->index)); |
| 4291 | } else if (list->capacity < (list->count + 1) * sizeof(*(list->index))) { |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4292 | void *new_ptr = loader_instance_heap_realloc(inst, list->index, list->capacity, list->capacity * 2, |
| 4293 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 4294 | if (NULL == new_ptr) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4295 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_phys_dev_ext_table() can't reallocate list memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4296 | return false; |
| 4297 | } |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 4298 | list->index = new_ptr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4299 | list->capacity *= 2; |
| 4300 | } |
| 4301 | |
| 4302 | // find an unused index in the hash table and use it |
| 4303 | i = (idx + 1) % MAX_NUM_UNKNOWN_EXTS; |
| 4304 | do { |
| 4305 | if (!inst->phys_dev_ext_disp_hash[i].func_name) { |
| 4306 | assert(inst->phys_dev_ext_disp_hash[i].list.capacity == 0); |
| 4307 | inst->phys_dev_ext_disp_hash[i].func_name = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4308 | (char *)loader_instance_heap_alloc(inst, strlen(funcName) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4309 | if (inst->phys_dev_ext_disp_hash[i].func_name == NULL) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4310 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4311 | "loader_add_dev_ext_table() can't reallocate " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4312 | "func_name memory"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4313 | return false; |
| 4314 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4315 | strncpy(inst->phys_dev_ext_disp_hash[i].func_name, funcName, strlen(funcName) + 1); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4316 | list->index[list->count] = i; |
| 4317 | list->count++; |
| 4318 | *ptr_idx = i; |
| 4319 | return true; |
| 4320 | } |
| 4321 | i = (i + 1) % MAX_NUM_UNKNOWN_EXTS; |
| 4322 | } while (i != idx); |
| 4323 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4324 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4325 | "loader_add_phys_dev_ext_table() couldn't insert into hash table; is " |
| 4326 | "it full?"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4327 | return false; |
| 4328 | } |
| 4329 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4330 | static bool loader_name_in_phys_dev_ext_table(struct loader_instance *inst, uint32_t *idx, const char *funcName) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4331 | uint32_t alt_idx; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4332 | if (inst->phys_dev_ext_disp_hash[*idx].func_name && !strcmp(inst->phys_dev_ext_disp_hash[*idx].func_name, funcName)) |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4333 | return true; |
| 4334 | |
| 4335 | // funcName wasn't at the primary spot in the hash table |
| 4336 | // search the list of secondary locations (shallow search, not deep search) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4337 | for (uint32_t i = 0; i < inst->phys_dev_ext_disp_hash[*idx].list.count; i++) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4338 | alt_idx = inst->phys_dev_ext_disp_hash[*idx].list.index[i]; |
| 4339 | if (!strcmp(inst->phys_dev_ext_disp_hash[*idx].func_name, funcName)) { |
| 4340 | *idx = alt_idx; |
| 4341 | return true; |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | return false; |
| 4346 | } |
| 4347 | |
| 4348 | // This function returns a generic trampoline and/or terminator function |
| 4349 | // address for any unknown physical device extension commands. A hash |
| 4350 | // table is used to keep a list of unknown entry points and their |
| 4351 | // mapping to the physical device extension dispatch table (struct |
| 4352 | // loader_phys_dev_ext_dispatch_table). |
| 4353 | // For a given entry point string (funcName), if an existing mapping is |
| 4354 | // found, then the trampoline address for that mapping is returned in |
| 4355 | // tramp_addr (if it is not NULL) and the terminator address for that |
| 4356 | // mapping is returned in term_addr (if it is not NULL). Otherwise, |
| 4357 | // this unknown entry point has not been seen yet. |
| 4358 | // If it has not been seen before, and perform_checking is 'true', |
| 4359 | // check if a layer or and ICD supports it. If so then a new entry in |
| 4360 | // the hash table is initialized and the trampoline and/or terminator |
| 4361 | // addresses are returned. |
| 4362 | // Null is returned if the hash table is full or if no discovered layer or |
| 4363 | // ICD returns a non-NULL GetProcAddr for it. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4364 | bool loader_phys_dev_ext_gpa(struct loader_instance *inst, const char *funcName, bool perform_checking, void **tramp_addr, |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4365 | void **term_addr) { |
| 4366 | uint32_t idx; |
| 4367 | uint32_t seed = 0; |
| 4368 | bool success = false; |
| 4369 | |
| 4370 | if (inst == NULL) { |
| 4371 | goto out; |
| 4372 | } |
| 4373 | |
| 4374 | if (NULL != tramp_addr) { |
| 4375 | *tramp_addr = NULL; |
| 4376 | } |
| 4377 | if (NULL != term_addr) { |
| 4378 | *term_addr = NULL; |
| 4379 | } |
| 4380 | |
| 4381 | // We should always check to see if any ICD supports it. |
| 4382 | if (!loader_check_icds_for_phys_dev_ext_address(inst, funcName)) { |
| 4383 | // If we're not checking layers, or we are and it's not in a layer, just |
| 4384 | // return |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4385 | if (!perform_checking || !loader_check_layer_list_for_phys_dev_ext_address(inst, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4386 | goto out; |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | idx = murmurhash(funcName, strlen(funcName), seed) % MAX_NUM_UNKNOWN_EXTS; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4391 | if (perform_checking && !loader_name_in_phys_dev_ext_table(inst, &idx, funcName)) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4392 | uint32_t i; |
| 4393 | bool added = false; |
| 4394 | |
| 4395 | // Only need to add first one to get index in Instance. Others will use |
| 4396 | // the same index. |
| 4397 | if (!added && loader_add_phys_dev_ext_table(inst, &idx, funcName)) { |
| 4398 | added = true; |
| 4399 | } |
| 4400 | |
| 4401 | // Setup the ICD function pointers |
| 4402 | struct loader_icd_term *icd_term = inst->icd_terms; |
| 4403 | while (NULL != icd_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4404 | if (MIN_PHYS_DEV_EXTENSION_ICD_INTERFACE_VERSION <= icd_term->scanned_icd->interface_version && |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4405 | NULL != icd_term->scanned_icd->GetPhysicalDeviceProcAddr) { |
| 4406 | icd_term->phys_dev_ext[idx] = |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4407 | (PFN_PhysDevExt)icd_term->scanned_icd->GetPhysicalDeviceProcAddr(icd_term->instance, funcName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4408 | |
| 4409 | // Make sure we set the instance dispatch to point to the |
| 4410 | // loader's terminator now since we can at least handle it |
| 4411 | // in one ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4412 | inst->disp->phys_dev_ext[idx] = loader_get_phys_dev_ext_termin(idx); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4413 | } else { |
| 4414 | icd_term->phys_dev_ext[idx] = NULL; |
| 4415 | } |
| 4416 | |
| 4417 | icd_term = icd_term->next; |
| 4418 | } |
| 4419 | |
| 4420 | // Now, search for the first layer attached and query using it to get |
| 4421 | // the first entry point. |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4422 | for (i = 0; i < inst->expanded_activated_layer_list.count; i++) { |
| 4423 | struct loader_layer_properties *layer_prop = &inst->expanded_activated_layer_list.list[i]; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4424 | if (layer_prop->interface_version > 1 && NULL != layer_prop->functions.get_physical_device_proc_addr) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4425 | inst->disp->phys_dev_ext[idx] = |
Tony Barbour | 55bd539 | 2017-05-17 12:17:18 -0600 | [diff] [blame] | 4426 | (PFN_PhysDevExt)layer_prop->functions.get_physical_device_proc_addr((VkInstance)inst->instance, funcName); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4427 | if (NULL != inst->disp->phys_dev_ext[idx]) { |
| 4428 | break; |
| 4429 | } |
| 4430 | } |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | if (NULL != tramp_addr) { |
| 4435 | *tramp_addr = loader_get_phys_dev_ext_tramp(idx); |
| 4436 | } |
| 4437 | |
| 4438 | if (NULL != term_addr) { |
| 4439 | *term_addr = loader_get_phys_dev_ext_termin(idx); |
| 4440 | } |
| 4441 | |
| 4442 | success = true; |
| 4443 | |
| 4444 | out: |
| 4445 | return success; |
| 4446 | } |
| 4447 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4448 | struct loader_instance *loader_get_instance(const VkInstance instance) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4449 | // look up the loader_instance in our list by comparing dispatch tables, as |
| 4450 | // there is no guarantee the instance is still a loader_instance* after any |
| 4451 | // layers which wrap the instance object. |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 4452 | const VkLayerInstanceDispatchTable *disp; |
| 4453 | struct loader_instance *ptr_instance = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4454 | disp = loader_get_instance_layer_dispatch(instance); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4455 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4456 | if (&inst->disp->layer_inst_disp == disp) { |
Jon Ashburn | e0e6457 | 2015-09-30 12:56:42 -0600 | [diff] [blame] | 4457 | ptr_instance = inst; |
| 4458 | break; |
| 4459 | } |
| 4460 | } |
| 4461 | return ptr_instance; |
| 4462 | } |
| 4463 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4464 | static loader_platform_dl_handle loader_open_layer_lib(const struct loader_instance *inst, const char *chain_type, |
| 4465 | struct loader_layer_properties *prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4466 | if ((prop->lib_handle = loader_platform_open_library(prop->lib_name)) == NULL) { |
Mark Young | b986b5f | 2017-05-16 09:48:55 -0600 | [diff] [blame] | 4467 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, loader_platform_open_library_error(prop->lib_name)); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4468 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4469 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Loading layer library %s", prop->lib_name); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4470 | } |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4471 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4472 | return prop->lib_handle; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4473 | } |
| 4474 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4475 | static void loader_close_layer_lib(const struct loader_instance *inst, struct loader_layer_properties *prop) { |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4476 | if (prop->lib_handle) { |
| 4477 | loader_platform_close_library(prop->lib_handle); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4478 | loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Unloading layer library %s", prop->lib_name); |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4479 | prop->lib_handle = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4480 | } |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4481 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4482 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4483 | void loader_deactivate_layers(const struct loader_instance *instance, struct loader_device *device, |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4484 | struct loader_layer_list *list) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4485 | // Delete instance list of enabled layers and close any layer libraries |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4486 | for (uint32_t i = 0; i < list->count; i++) { |
| 4487 | struct loader_layer_properties *layer_prop = &list->list[i]; |
Courtney Goeltzenleuchter | 80bfd0e | 2015-12-17 09:51:22 -0700 | [diff] [blame] | 4488 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4489 | loader_close_layer_lib(instance, layer_prop); |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4490 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 4491 | loader_destroy_layer_list(instance, device, list); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4494 | // Go through the search_list and find any layers which match type. If layer |
| 4495 | // type match is found in then add it to ext_list. |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4496 | static void loader_add_implicit_layers(const struct loader_instance *inst, struct loader_layer_list *target_list, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4497 | struct loader_layer_list *expanded_target_list, |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4498 | const struct loader_layer_list *source_list) { |
| 4499 | for (uint32_t src_layer = 0; src_layer < source_list->count; src_layer++) { |
| 4500 | const struct loader_layer_properties *prop = &source_list->list[src_layer]; |
| 4501 | if (0 == (prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER)) { |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4502 | loader_add_implicit_layer(inst, prop, target_list, expanded_target_list, source_list); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4503 | } |
| 4504 | } |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4505 | } |
| 4506 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4507 | // Get the layer name(s) from the env_name environment variable. If layer is found in |
| 4508 | // search_list then add it to layer_list. But only add it to layer_list if type_flags matches. |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 4509 | static void loader_add_env_layers(const struct loader_instance *inst, const enum layer_type_flags type_flags, const char *env_name, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4510 | struct loader_layer_list *target_list, struct loader_layer_list *expanded_target_list, |
| 4511 | const struct loader_layer_list *source_list) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4512 | char *next, *name; |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4513 | char *layer_env = loader_secure_getenv(env_name, inst); |
| 4514 | if (layer_env == NULL) { |
| 4515 | goto out; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 4516 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4517 | name = loader_stack_alloc(strlen(layer_env) + 1); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4518 | if (name == NULL) { |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4519 | goto out; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 4520 | } |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4521 | strcpy(name, layer_env); |
Jon Ashburn | 38a497f | 2016-01-04 14:01:38 -0700 | [diff] [blame] | 4522 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4523 | while (name && *name) { |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4524 | next = loader_get_next_path(name); |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4525 | loader_find_layer_name_add_list(inst, name, type_flags, source_list, target_list, expanded_target_list); |
Jon Ashburn | eb6d568 | 2015-07-02 14:10:53 -0600 | [diff] [blame] | 4526 | name = next; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 4527 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4528 | |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4529 | out: |
| 4530 | |
| 4531 | if (layer_env != NULL) { |
| 4532 | loader_free_getenv(layer_env, inst); |
| 4533 | } |
| 4534 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4535 | return; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4536 | } |
| 4537 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4538 | VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo, |
| 4539 | const struct loader_layer_list *instance_layers) { |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4540 | VkResult err; |
| 4541 | |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4542 | assert(inst && "Cannot have null instance"); |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4543 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4544 | if (!loader_init_layer_list(inst, &inst->app_activated_layer_list)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4545 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4546 | "loader_enable_instance_layers: Failed to initialize" |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4547 | " application version of the layer list"); |
| 4548 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4549 | } |
| 4550 | |
| 4551 | if (!loader_init_layer_list(inst, &inst->expanded_activated_layer_list)) { |
| 4552 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4553 | "loader_enable_instance_layers: Failed to initialize" |
| 4554 | " expanded version of the layer list"); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4555 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 4556 | } |
| 4557 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4558 | // Add any implicit layers first |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4559 | loader_add_implicit_layers(inst, &inst->app_activated_layer_list, &inst->expanded_activated_layer_list, instance_layers); |
Jon Ashburn | 0c26e71 | 2015-07-02 16:10:32 -0600 | [diff] [blame] | 4560 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4561 | // Add any layers specified via environment variable next |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 4562 | loader_add_env_layers(inst, VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER, ENABLED_LAYERS_ENV, &inst->app_activated_layer_list, |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4563 | &inst->expanded_activated_layer_list, instance_layers); |
Jon Ashburn | bd6c488 | 2015-07-02 12:59:25 -0600 | [diff] [blame] | 4564 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4565 | // Add layers specified by the application |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4566 | err = loader_add_layer_names_to_list(inst, &inst->app_activated_layer_list, &inst->expanded_activated_layer_list, |
| 4567 | pCreateInfo->enabledLayerCount, pCreateInfo->ppEnabledLayerNames, instance_layers); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 4568 | |
| 4569 | return err; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4570 | } |
| 4571 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4572 | // Determine the layer interface version to use. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4573 | bool loader_get_layer_interface_version(PFN_vkNegotiateLoaderLayerInterfaceVersion fp_negotiate_layer_version, |
| 4574 | VkNegotiateLayerInterface *interface_struct) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4575 | memset(interface_struct, 0, sizeof(VkNegotiateLayerInterface)); |
Mark Young | 21aa6d6 | 2017-03-29 13:39:27 -0600 | [diff] [blame] | 4576 | interface_struct->sType = LAYER_NEGOTIATE_INTERFACE_STRUCT; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4577 | interface_struct->loaderLayerInterfaceVersion = 1; |
| 4578 | |
| 4579 | if (fp_negotiate_layer_version != NULL) { |
| 4580 | // Layer supports the negotiation API, so call it with the loader's |
| 4581 | // latest version supported |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4582 | interface_struct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4583 | VkResult result = fp_negotiate_layer_version(interface_struct); |
| 4584 | |
| 4585 | if (result != VK_SUCCESS) { |
| 4586 | // Layer no longer supports the loader's latest interface version so |
| 4587 | // fail loading the Layer |
| 4588 | return false; |
| 4589 | } |
| 4590 | } |
| 4591 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4592 | if (interface_struct->loaderLayerInterfaceVersion < MIN_SUPPORTED_LOADER_LAYER_INTERFACE_VERSION) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4593 | // Loader no longer supports the layer's latest interface version so |
| 4594 | // fail loading the layer |
| 4595 | return false; |
| 4596 | } |
| 4597 | |
| 4598 | return true; |
| 4599 | } |
| 4600 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4601 | // Given the list of layers to activate in the loader_instance |
| 4602 | // structure. This function will add a VkLayerInstanceCreateInfo |
| 4603 | // structure to the VkInstanceCreateInfo.pNext pointer. |
| 4604 | // Each activated layer will have it's own VkLayerInstanceLink |
| 4605 | // structure that tells the layer what Get*ProcAddr to call to |
| 4606 | // get function pointers to the next layer down. |
| 4607 | // Once the chain info has been created this function will |
| 4608 | // execute the CreateInstance call chain. Each layer will |
| 4609 | // then have an opportunity in it's CreateInstance function |
| 4610 | // to setup it's dispatch table when the lower layer returns |
| 4611 | // successfully. |
| 4612 | // Each layer can wrap or not-wrap the returned VkInstance object |
| 4613 | // as it sees fit. |
| 4614 | // The instance chain is terminated by a loader function |
| 4615 | // that will call CreateInstance on all available ICD's and |
| 4616 | // cache those VkInstance objects for future use. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4617 | VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 4618 | struct loader_instance *inst, VkInstance *created_instance) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4619 | uint32_t activated_layers = 0; |
| 4620 | VkLayerInstanceCreateInfo chain_info; |
| 4621 | VkLayerInstanceLink *layer_instance_link_info = NULL; |
| 4622 | VkInstanceCreateInfo loader_create_info; |
| 4623 | VkResult res; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4624 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4625 | PFN_vkGetInstanceProcAddr next_gipa = loader_gpa_instance_internal; |
| 4626 | PFN_vkGetInstanceProcAddr cur_gipa = loader_gpa_instance_internal; |
| 4627 | PFN_GetPhysicalDeviceProcAddr next_gpdpa = loader_gpdpa_instance_internal; |
| 4628 | PFN_GetPhysicalDeviceProcAddr cur_gpdpa = loader_gpdpa_instance_internal; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4629 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4630 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkInstanceCreateInfo)); |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4631 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4632 | if (inst->expanded_activated_layer_list.count > 0) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4633 | chain_info.u.pLayerInfo = NULL; |
| 4634 | chain_info.pNext = pCreateInfo->pNext; |
| 4635 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
| 4636 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4637 | loader_create_info.pNext = &chain_info; |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 4638 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4639 | layer_instance_link_info = loader_stack_alloc(sizeof(VkLayerInstanceLink) * inst->expanded_activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4640 | if (!layer_instance_link_info) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4641 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4642 | "loader_create_instance_chain: Failed to alloc Instance" |
| 4643 | " objects for layer"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4644 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4645 | } |
| 4646 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4647 | // Create instance chain of enabled layers |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4648 | for (int32_t i = inst->expanded_activated_layer_list.count - 1; i >= 0; i--) { |
| 4649 | struct loader_layer_properties *layer_prop = &inst->expanded_activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4650 | loader_platform_dl_handle lib_handle; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4651 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4652 | lib_handle = loader_open_layer_lib(inst, "instance", layer_prop); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4653 | if (!lib_handle) { |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4654 | continue; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | if (NULL == layer_prop->functions.negotiate_layer_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4658 | PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_interface = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4659 | bool functions_in_interface = false; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4660 | if (strlen(layer_prop->functions.str_negotiate_interface) == 0) { |
| 4661 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4662 | lib_handle, "vkNegotiateLoaderLayerInterfaceVersion"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4663 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4664 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4665 | lib_handle, layer_prop->functions.str_negotiate_interface); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | // If we can negotiate an interface version, then we can also |
| 4669 | // get everything we need from the one function call, so try |
| 4670 | // that first, and see if we can get all the function pointers |
| 4671 | // necessary from that one call. |
| 4672 | if (NULL != negotiate_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4673 | layer_prop->functions.negotiate_layer_interface = negotiate_interface; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4674 | |
| 4675 | VkNegotiateLayerInterface interface_struct; |
| 4676 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4677 | if (loader_get_layer_interface_version(negotiate_interface, &interface_struct)) { |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4678 | // Go ahead and set the properties version to the |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4679 | // correct value. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4680 | layer_prop->interface_version = interface_struct.loaderLayerInterfaceVersion; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4681 | |
| 4682 | // If the interface is 2 or newer, we have access to the |
| 4683 | // new GetPhysicalDeviceProcAddr function, so grab it, |
| 4684 | // and the other necessary functions, from the |
| 4685 | // structure. |
| 4686 | if (interface_struct.loaderLayerInterfaceVersion > 1) { |
| 4687 | cur_gipa = interface_struct.pfnGetInstanceProcAddr; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4688 | cur_gpdpa = interface_struct.pfnGetPhysicalDeviceProcAddr; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4689 | if (cur_gipa != NULL) { |
| 4690 | // We've set the functions, so make sure we |
| 4691 | // don't do the unnecessary calls later. |
| 4692 | functions_in_interface = true; |
| 4693 | } |
| 4694 | } |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | if (!functions_in_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4699 | if ((cur_gipa = layer_prop->functions.get_instance_proc_addr) == NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4700 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4701 | cur_gipa = |
| 4702 | (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
| 4703 | layer_prop->functions.get_instance_proc_addr = cur_gipa; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4704 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4705 | cur_gipa = (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, |
| 4706 | layer_prop->functions.str_gipa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | if (NULL == cur_gipa) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4710 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4711 | "loader_create_instance_chain: Failed to" |
| 4712 | " find \'vkGetInstanceProcAddr\' in " |
| 4713 | "layer %s", |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4714 | layer_prop->lib_name); |
| 4715 | continue; |
| 4716 | } |
| 4717 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4718 | } |
| 4719 | } |
| 4720 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4721 | layer_instance_link_info[activated_layers].pNext = chain_info.u.pLayerInfo; |
| 4722 | layer_instance_link_info[activated_layers].pfnNextGetInstanceProcAddr = next_gipa; |
| 4723 | layer_instance_link_info[activated_layers].pfnNextGetPhysicalDeviceProcAddr = next_gpdpa; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4724 | next_gipa = cur_gipa; |
| 4725 | if (layer_prop->interface_version > 1 && cur_gpdpa != NULL) { |
| 4726 | layer_prop->functions.get_physical_device_proc_addr = cur_gpdpa; |
| 4727 | next_gpdpa = cur_gpdpa; |
| 4728 | } |
| 4729 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4730 | chain_info.u.pLayerInfo = &layer_instance_link_info[activated_layers]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4731 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4732 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Insert instance layer %s (%s)", layer_prop->info.layerName, |
| 4733 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4734 | |
| 4735 | activated_layers++; |
| 4736 | } |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4737 | } |
| 4738 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4739 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)next_gipa(*created_instance, "vkCreateInstance"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4740 | if (fpCreateInstance) { |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4741 | VkLayerInstanceCreateInfo create_info_disp; |
| 4742 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4743 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4744 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
Jon Ashburn | c3c5877 | 2016-03-29 11:16:01 -0600 | [diff] [blame] | 4745 | |
| 4746 | create_info_disp.u.pfnSetInstanceLoaderData = vkSetInstanceDispatch; |
| 4747 | |
| 4748 | create_info_disp.pNext = loader_create_info.pNext; |
| 4749 | loader_create_info.pNext = &create_info_disp; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4750 | res = fpCreateInstance(&loader_create_info, pAllocator, created_instance); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4751 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4752 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4753 | "loader_create_instance_chain: Failed to find " |
| 4754 | "\'vkCreateInstance\'"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4755 | // Couldn't find CreateInstance function! |
| 4756 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 4757 | } |
| 4758 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4759 | if (res == VK_SUCCESS) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4760 | loader_init_instance_core_dispatch_table(&inst->disp->layer_inst_disp, next_gipa, *created_instance); |
Jon Ashburn | 4e8c416 | 2016-03-08 15:21:30 -0700 | [diff] [blame] | 4761 | inst->instance = *created_instance; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | return res; |
Jon Ashburn | 27cd584 | 2015-05-12 17:26:48 -0600 | [diff] [blame] | 4765 | } |
| 4766 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4767 | void loader_activate_instance_layer_extensions(struct loader_instance *inst, VkInstance created_inst) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4768 | loader_init_instance_extension_dispatch_table(&inst->disp->layer_inst_disp, inst->disp->layer_inst_disp.GetInstanceProcAddr, |
| 4769 | created_inst); |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 4770 | } |
| 4771 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4772 | VkResult loader_create_device_chain(const struct loader_physical_device_tramp *pd, const VkDeviceCreateInfo *pCreateInfo, |
| 4773 | const VkAllocationCallbacks *pAllocator, const struct loader_instance *inst, |
| 4774 | struct loader_device *dev) { |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4775 | uint32_t activated_layers = 0; |
| 4776 | VkLayerDeviceLink *layer_device_link_info; |
| 4777 | VkLayerDeviceCreateInfo chain_info; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4778 | VkDeviceCreateInfo loader_create_info; |
| 4779 | VkResult res; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4780 | |
Jamie Madill | 3512787 | 2017-03-15 16:17:46 -0400 | [diff] [blame] | 4781 | PFN_vkGetDeviceProcAddr fpGDPA = NULL, nextGDPA = loader_gpa_device_internal; |
| 4782 | PFN_vkGetInstanceProcAddr fpGIPA = NULL, nextGIPA = loader_gpa_instance_internal; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4783 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4784 | memcpy(&loader_create_info, pCreateInfo, sizeof(VkDeviceCreateInfo)); |
| 4785 | |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 4786 | // Before we continue, we need to find out if the KHR_device_group extension is in the enabled list. If it is, we then |
| 4787 | // need to look for the corresponding VkDeviceGroupDeviceCreateInfoKHR struct in the device list. This is because we |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4788 | // need to replace all the incoming physical device values (which are really loader trampoline physical device values) |
| 4789 | // with the layer/ICD version. |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 4790 | { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4791 | struct VkStructureHeader *pNext = (struct VkStructureHeader *)loader_create_info.pNext; |
| 4792 | struct VkStructureHeader *pPrev = (struct VkStructureHeader *)&loader_create_info; |
| 4793 | while (NULL != pNext) { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 4794 | if (VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO == pNext->sType) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 4795 | VkDeviceGroupDeviceCreateInfoKHR *cur_struct = (VkDeviceGroupDeviceCreateInfoKHR *)pNext; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4796 | if (0 < cur_struct->physicalDeviceCount && NULL != cur_struct->pPhysicalDevices) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 4797 | VkDeviceGroupDeviceCreateInfoKHR *temp_struct = loader_stack_alloc(sizeof(VkDeviceGroupDeviceCreateInfoKHR)); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4798 | VkPhysicalDevice *phys_dev_array = NULL; |
| 4799 | if (NULL == temp_struct) { |
| 4800 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4801 | } |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 4802 | memcpy(temp_struct, cur_struct, sizeof(VkDeviceGroupDeviceCreateInfoKHR)); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4803 | phys_dev_array = loader_stack_alloc(sizeof(VkPhysicalDevice) * cur_struct->physicalDeviceCount); |
| 4804 | if (NULL == phys_dev_array) { |
| 4805 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 4806 | } |
| 4807 | |
| 4808 | // Before calling down, replace the incoming physical device values (which are really loader trampoline |
| 4809 | // physical devices) with the next layer (or possibly even the terminator) physical device values. |
| 4810 | struct loader_physical_device_tramp *cur_tramp; |
| 4811 | for (uint32_t phys_dev = 0; phys_dev < cur_struct->physicalDeviceCount; phys_dev++) { |
| 4812 | cur_tramp = (struct loader_physical_device_tramp *)cur_struct->pPhysicalDevices[phys_dev]; |
| 4813 | phys_dev_array[phys_dev] = cur_tramp->phys_dev; |
| 4814 | } |
| 4815 | temp_struct->pPhysicalDevices = phys_dev_array; |
| 4816 | |
| 4817 | // Replace the old struct in the pNext chain with this one. |
| 4818 | pPrev->pNext = (const void *)temp_struct; |
| 4819 | pNext = (struct VkStructureHeader *)(temp_struct); |
| 4820 | } |
| 4821 | break; |
| 4822 | } |
| 4823 | |
| 4824 | pPrev = pNext; |
| 4825 | pNext = (struct VkStructureHeader *)(pPrev->pNext); |
| 4826 | } |
| 4827 | } |
| 4828 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4829 | layer_device_link_info = loader_stack_alloc(sizeof(VkLayerDeviceLink) * dev->expanded_activated_layer_list.count); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4830 | if (!layer_device_link_info) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4831 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4832 | "loader_create_device_chain: Failed to alloc Device objects" |
| 4833 | " for layer. Skipping Layer."); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4834 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
David Pinedo | a0a8a24 | 2015-06-24 15:29:18 -0600 | [diff] [blame] | 4835 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4836 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4837 | if (dev->expanded_activated_layer_list.count > 0) { |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4838 | chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
| 4839 | chain_info.function = VK_LAYER_LINK_INFO; |
| 4840 | chain_info.u.pLayerInfo = NULL; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4841 | chain_info.pNext = loader_create_info.pNext; |
Jon Ashburn | 72690f2 | 2016-03-29 12:52:13 -0600 | [diff] [blame] | 4842 | loader_create_info.pNext = &chain_info; |
| 4843 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4844 | // Create instance chain of enabled layers |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 4845 | for (int32_t i = dev->expanded_activated_layer_list.count - 1; i >= 0; i--) { |
| 4846 | struct loader_layer_properties *layer_prop = &dev->expanded_activated_layer_list.list[i]; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4847 | loader_platform_dl_handle lib_handle; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4848 | bool functions_in_interface = false; |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 4849 | |
Jon Ashburn | 4dc1d8a | 2016-04-20 13:21:17 -0600 | [diff] [blame] | 4850 | lib_handle = loader_open_layer_lib(inst, "device", layer_prop); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4851 | if (!lib_handle) { |
Courtney Goeltzenleuchter | 524b7e3 | 2016-01-14 16:06:06 -0700 | [diff] [blame] | 4852 | continue; |
Jon Ashburn | 21c21ee | 2015-09-09 11:29:24 -0600 | [diff] [blame] | 4853 | } |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4854 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4855 | // If we can negotiate an interface version, then we can also get everything we need from the one function |
| 4856 | // call, so try that first, and see if we can get all the function pointers necessary from that one call. |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4857 | if (NULL == layer_prop->functions.negotiate_layer_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4858 | PFN_vkNegotiateLoaderLayerInterfaceVersion negotiate_interface = NULL; |
| 4859 | if (strlen(layer_prop->functions.str_negotiate_interface) == 0) { |
| 4860 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4861 | lib_handle, "vkNegotiateLoaderLayerInterfaceVersion"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4862 | } else { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4863 | negotiate_interface = (PFN_vkNegotiateLoaderLayerInterfaceVersion)loader_platform_get_proc_address( |
| 4864 | lib_handle, layer_prop->functions.str_negotiate_interface); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4865 | } |
| 4866 | |
| 4867 | if (NULL != negotiate_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4868 | layer_prop->functions.negotiate_layer_interface = negotiate_interface; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4869 | |
| 4870 | VkNegotiateLayerInterface interface_struct; |
| 4871 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4872 | if (loader_get_layer_interface_version(negotiate_interface, &interface_struct)) { |
Mark Young | dee312c | 2017-03-08 13:38:35 -0700 | [diff] [blame] | 4873 | // Go ahead and set the properties version to the correct value. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4874 | layer_prop->interface_version = interface_struct.loaderLayerInterfaceVersion; |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4875 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 4876 | // If the interface is 2 or newer, we have access to the new GetPhysicalDeviceProcAddr |
| 4877 | // function, so grab it, and the other necessary functions, from the structure. |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4878 | if (interface_struct.loaderLayerInterfaceVersion > 1) { |
| 4879 | fpGIPA = interface_struct.pfnGetInstanceProcAddr; |
| 4880 | fpGDPA = interface_struct.pfnGetDeviceProcAddr; |
| 4881 | if (fpGIPA != NULL && fpGDPA) { |
| 4882 | // We've set the functions, so make sure we |
| 4883 | // don't do the unnecessary calls later. |
| 4884 | functions_in_interface = true; |
| 4885 | } |
| 4886 | } |
| 4887 | } |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4888 | } |
| 4889 | } |
| 4890 | |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4891 | if (!functions_in_interface) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4892 | if ((fpGIPA = layer_prop->functions.get_instance_proc_addr) == NULL) { |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4893 | if (strlen(layer_prop->functions.str_gipa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4894 | fpGIPA = (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetInstanceProcAddr"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4895 | layer_prop->functions.get_instance_proc_addr = fpGIPA; |
| 4896 | } else |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4897 | fpGIPA = |
| 4898 | (PFN_vkGetInstanceProcAddr)loader_platform_get_proc_address(lib_handle, layer_prop->functions.str_gipa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4899 | if (!fpGIPA) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4900 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4901 | "loader_create_device_chain: Failed to find " |
| 4902 | "\'vkGetInstanceProcAddr\' in layer %s. Skipping" |
| 4903 | " layer.", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4904 | layer_prop->lib_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4905 | continue; |
| 4906 | } |
| 4907 | } |
| 4908 | if ((fpGDPA = layer_prop->functions.get_device_proc_addr) == NULL) { |
| 4909 | if (strlen(layer_prop->functions.str_gdpa) == 0) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4910 | fpGDPA = (PFN_vkGetDeviceProcAddr)loader_platform_get_proc_address(lib_handle, "vkGetDeviceProcAddr"); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4911 | layer_prop->functions.get_device_proc_addr = fpGDPA; |
| 4912 | } else |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4913 | fpGDPA = |
| 4914 | (PFN_vkGetDeviceProcAddr)loader_platform_get_proc_address(lib_handle, layer_prop->functions.str_gdpa); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4915 | if (!fpGDPA) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4916 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Failed to find vkGetDeviceProcAddr in layer %s", |
| 4917 | layer_prop->lib_name); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 4918 | continue; |
| 4919 | } |
| 4920 | } |
| 4921 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4922 | layer_device_link_info[activated_layers].pNext = chain_info.u.pLayerInfo; |
| 4923 | layer_device_link_info[activated_layers].pfnNextGetInstanceProcAddr = nextGIPA; |
| 4924 | layer_device_link_info[activated_layers].pfnNextGetDeviceProcAddr = nextGDPA; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4925 | chain_info.u.pLayerInfo = &layer_device_link_info[activated_layers]; |
| 4926 | nextGIPA = fpGIPA; |
| 4927 | nextGDPA = fpGDPA; |
| 4928 | |
Lenny Komow | 7ddd432 | 2017-10-16 15:03:37 -0600 | [diff] [blame] | 4929 | loader_log(inst, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, "Inserted device layer %s (%s)", layer_prop->info.layerName, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4930 | layer_prop->lib_name); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4931 | |
| 4932 | activated_layers++; |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4933 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4934 | } |
| 4935 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4936 | VkDevice created_device = (VkDevice)dev; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4937 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)nextGIPA(inst->instance, "vkCreateDevice"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4938 | if (fpCreateDevice) { |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4939 | VkLayerDeviceCreateInfo create_info_disp; |
| 4940 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 4941 | create_info_disp.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; |
Jon Ashburn | ed8f231 | 2016-03-31 10:52:22 -0600 | [diff] [blame] | 4942 | create_info_disp.function = VK_LOADER_DATA_CALLBACK; |
| 4943 | |
| 4944 | create_info_disp.u.pfnSetDeviceLoaderData = vkSetDeviceDispatch; |
| 4945 | |
| 4946 | create_info_disp.pNext = loader_create_info.pNext; |
| 4947 | loader_create_info.pNext = &create_info_disp; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4948 | res = fpCreateDevice(pd->phys_dev, &loader_create_info, pAllocator, &created_device); |
Piers Daniell | efbbfc1 | 2016-04-05 17:28:06 -0600 | [diff] [blame] | 4949 | if (res != VK_SUCCESS) { |
| 4950 | return res; |
| 4951 | } |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4952 | dev->chain_device = created_device; |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4953 | } else { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4954 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4955 | "loader_create_device_chain: Failed to find \'vkCreateDevice\' " |
| 4956 | "in layer %s"); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4957 | // Couldn't find CreateDevice function! |
| 4958 | return VK_ERROR_INITIALIZATION_FAILED; |
| 4959 | } |
Jon Ashburn | 94e7049 | 2015-06-10 10:13:10 -0600 | [diff] [blame] | 4960 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 4961 | // Initialize device dispatch table |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4962 | loader_init_device_dispatch_table(&dev->loader_dispatch, nextGDPA, dev->chain_device); |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 4963 | |
| 4964 | return res; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 4965 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 4966 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4967 | VkResult loader_validate_layers(const struct loader_instance *inst, const uint32_t layer_count, |
| 4968 | const char *const *ppEnabledLayerNames, const struct loader_layer_list *list) { |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4969 | struct loader_layer_properties *prop; |
| 4970 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 4971 | for (uint32_t i = 0; i < layer_count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4972 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4973 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4974 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 4975 | "loader_validate_layers: Device ppEnabledLayerNames " |
| 4976 | "contains string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 4977 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 4978 | } |
| 4979 | |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 4980 | prop = loader_get_layer_property(ppEnabledLayerNames[i], list); |
Mark Young | f2079b9 | 2017-05-02 10:49:46 -0600 | [diff] [blame] | 4981 | if (NULL == prop) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 4982 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 4983 | "loader_validate_layers: Layer %d does not exist in the list of available layers", i); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 4984 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4985 | } |
| 4986 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 4987 | return VK_SUCCESS; |
| 4988 | } |
| 4989 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 4990 | VkResult loader_validate_instance_extensions(const struct loader_instance *inst, const struct loader_extension_list *icd_exts, |
| 4991 | const struct loader_layer_list *instance_layers, |
| 4992 | const VkInstanceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 4993 | VkExtensionProperties *extension_prop; |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 4994 | char *env_value; |
| 4995 | bool check_if_known = true; |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 4996 | VkResult res = VK_SUCCESS; |
| 4997 | |
| 4998 | struct loader_layer_list active_layers; |
| 4999 | struct loader_layer_list expanded_layers; |
| 5000 | memset(&active_layers, 0, sizeof(active_layers)); |
| 5001 | memset(&expanded_layers, 0, sizeof(expanded_layers)); |
| 5002 | if (!loader_init_layer_list(inst, &active_layers)) { |
| 5003 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5004 | goto out; |
| 5005 | } |
| 5006 | if (!loader_init_layer_list(inst, &expanded_layers)) { |
| 5007 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5008 | goto out; |
| 5009 | } |
| 5010 | |
| 5011 | // Build the lists of active layers (including metalayers) and expanded layers (with metalayers resolved to their components) |
| 5012 | loader_add_implicit_layers(inst, &active_layers, &expanded_layers, instance_layers); |
| 5013 | loader_add_env_layers(inst, VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER, ENABLED_LAYERS_ENV, &active_layers, &expanded_layers, |
| 5014 | instance_layers); |
| 5015 | res = loader_add_layer_names_to_list(inst, &active_layers, &expanded_layers, pCreateInfo->enabledLayerCount, |
| 5016 | pCreateInfo->ppEnabledLayerNames, instance_layers); |
| 5017 | if (VK_SUCCESS != res) { |
| 5018 | goto out; |
| 5019 | } |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5020 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5021 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5022 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5023 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5024 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5025 | "loader_validate_instance_extensions: Instance ppEnabledExtensionNames contains " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5026 | "string that is too long or is badly formed"); |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 5027 | res = VK_ERROR_EXTENSION_NOT_PRESENT; |
| 5028 | goto out; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5031 | // Check if a user wants to disable the instance extension filtering behavior |
| 5032 | env_value = loader_getenv("VK_LOADER_DISABLE_INST_EXT_FILTER", inst); |
| 5033 | if (NULL != env_value && atoi(env_value) != 0) { |
| 5034 | check_if_known = false; |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 5035 | } |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5036 | loader_free_getenv(env_value, inst); |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 5037 | |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5038 | if (check_if_known) { |
| 5039 | // See if the extension is in the list of supported extensions |
| 5040 | bool found = false; |
| 5041 | for (uint32_t j = 0; LOADER_INSTANCE_EXTENSIONS[j] != NULL; j++) { |
| 5042 | if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], LOADER_INSTANCE_EXTENSIONS[j]) == 0) { |
| 5043 | found = true; |
| 5044 | break; |
| 5045 | } |
| 5046 | } |
| 5047 | |
| 5048 | // If it isn't in the list, return an error |
| 5049 | if (!found) { |
| 5050 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5051 | "loader_validate_instance_extensions: Extension %s not found in list of known instance extensions.", |
| 5052 | pCreateInfo->ppEnabledExtensionNames[i]); |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 5053 | res = VK_ERROR_EXTENSION_NOT_PRESENT; |
| 5054 | goto out; |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5055 | } |
Lenny Komow | 4053b81 | 2016-12-29 16:27:28 -0700 | [diff] [blame] | 5056 | } |
| 5057 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5058 | extension_prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5059 | |
| 5060 | if (extension_prop) { |
| 5061 | continue; |
| 5062 | } |
| 5063 | |
| 5064 | extension_prop = NULL; |
| 5065 | |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 5066 | // Not in global list, search expanded layer extension list |
| 5067 | for (uint32_t j = 0; NULL == extension_prop && j < expanded_layers.count; ++j) { |
| 5068 | extension_prop = |
| 5069 | get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], &expanded_layers.list[j].instance_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5073 | // Didn't find extension name in any of the global layers, error out |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5074 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5075 | "loader_validate_instance_extensions: Instance extension %s not supported by available ICDs or enabled " |
| 5076 | "layers.", |
| 5077 | pCreateInfo->ppEnabledExtensionNames[i]); |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 5078 | res = VK_ERROR_EXTENSION_NOT_PRESENT; |
| 5079 | goto out; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5080 | } |
| 5081 | } |
Lenny Komow | 3b95839 | 2018-01-17 13:53:59 -0700 | [diff] [blame] | 5082 | |
| 5083 | out: |
| 5084 | loader_destroy_layer_list(inst, NULL, &active_layers); |
| 5085 | loader_destroy_layer_list(inst, NULL, &expanded_layers); |
| 5086 | return res; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5087 | } |
| 5088 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5089 | VkResult loader_validate_device_extensions(struct loader_physical_device_tramp *phys_dev, |
| 5090 | const struct loader_layer_list *activated_device_layers, |
| 5091 | const struct loader_extension_list *icd_exts, const VkDeviceCreateInfo *pCreateInfo) { |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 5092 | VkExtensionProperties *extension_prop; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5093 | struct loader_layer_properties *layer_prop; |
| 5094 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5095 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5096 | VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, pCreateInfo->ppEnabledExtensionNames[i]); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5097 | if (result != VK_STRING_ERROR_NONE) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5098 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5099 | "loader_validate_device_extensions: Device ppEnabledExtensionNames contains " |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5100 | "string that is too long or is badly formed"); |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 5101 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
| 5102 | } |
| 5103 | |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5104 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5105 | extension_prop = get_extension_property(extension_name, icd_exts); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5106 | |
| 5107 | if (extension_prop) { |
| 5108 | continue; |
| 5109 | } |
| 5110 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5111 | // Not in global list, search activated layer extension lists |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5112 | for (uint32_t j = 0; j < activated_device_layers->count; j++) { |
| 5113 | layer_prop = &activated_device_layers->list[j]; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5114 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5115 | extension_prop = get_dev_extension_property(extension_name, &layer_prop->device_extension_list); |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5116 | if (extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5117 | // Found the extension in one of the layers enabled by the app. |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5118 | break; |
| 5119 | } |
| 5120 | } |
| 5121 | |
| 5122 | if (!extension_prop) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5123 | // Didn't find extension name in any of the device layers, error out |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5124 | loader_log(phys_dev->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5125 | "loader_validate_device_extensions: Device extension %s not supported by selected physical device " |
| 5126 | "or enabled layers.", |
| 5127 | pCreateInfo->ppEnabledExtensionNames[i]); |
Courtney Goeltzenleuchter | 55659b7 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 5128 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 366b27a | 2015-07-06 20:14:18 -0600 | [diff] [blame] | 5129 | } |
| 5130 | } |
Courtney Goeltzenleuchter | 3b8c5ff | 2015-07-06 17:45:08 -0600 | [diff] [blame] | 5131 | return VK_SUCCESS; |
| 5132 | } |
| 5133 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5134 | // Terminator functions for the Instance chain |
| 5135 | // All named terminator_<Vulakn API name> |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5136 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, |
| 5137 | const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5138 | struct loader_icd_term *icd_term; |
Jon Ashburn | 5c042ea | 2015-08-04 11:14:18 -0600 | [diff] [blame] | 5139 | VkExtensionProperties *prop; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5140 | char **filtered_extension_names = NULL; |
| 5141 | VkInstanceCreateInfo icd_create_info; |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 5142 | VkResult res = VK_SUCCESS; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5143 | bool one_icd_successful = false; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5144 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 5145 | struct loader_instance *ptr_instance = (struct loader_instance *)*pInstance; |
Tony Barbour | 3c78ff4 | 2015-12-04 13:24:39 -0700 | [diff] [blame] | 5146 | memcpy(&icd_create_info, pCreateInfo, sizeof(icd_create_info)); |
| 5147 | |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 5148 | icd_create_info.enabledLayerCount = 0; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5149 | icd_create_info.ppEnabledLayerNames = NULL; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5150 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5151 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
| 5152 | // No ICD will advertise support for layers. An ICD library could |
| 5153 | // support a layer, but it would be independent of the actual ICD, |
| 5154 | // just in the same library. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5155 | filtered_extension_names = loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5156 | if (!filtered_extension_names) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5157 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | 48cea0c | 2017-05-26 14:39:54 -0600 | [diff] [blame] | 5158 | "terminator_CreateInstance: Failed create extension name array for %d extensions", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5159 | pCreateInfo->enabledExtensionCount); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5160 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5161 | goto out; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5162 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5163 | icd_create_info.ppEnabledExtensionNames = (const char *const *)filtered_extension_names; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5164 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5165 | for (uint32_t i = 0; i < ptr_instance->icd_tramp_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5166 | icd_term = loader_icd_add(ptr_instance, &ptr_instance->icd_tramp_list.scanned_list[i]); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5167 | if (NULL == icd_term) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5168 | loader_log(ptr_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | c8b807a | 2017-07-14 17:11:31 -0600 | [diff] [blame] | 5169 | "terminator_CreateInstance: Failed to add ICD %d to ICD trampoline list.", i); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5170 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5171 | goto out; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5172 | } |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5173 | |
Lenny Komow | a44cc85 | 2017-09-12 22:54:21 -0600 | [diff] [blame] | 5174 | // If any error happens after here, we need to remove the ICD from the list, |
| 5175 | // because we've already added it, but haven't validated it |
| 5176 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5177 | icd_create_info.enabledExtensionCount = 0; |
| 5178 | struct loader_extension_list icd_exts; |
Courtney Goeltzenleuchter | 746db73 | 2015-07-06 17:42:01 -0600 | [diff] [blame] | 5179 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5180 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Build ICD instance extension list"); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5181 | // traverse scanned icd list adding non-duplicate extensions to the list |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5182 | res = loader_init_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5183 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 5184 | // If out of memory, bail immediately. |
| 5185 | goto out; |
| 5186 | } else if (VK_SUCCESS != res) { |
Mark Young | 7e47129 | 2016-09-06 09:53:45 -0600 | [diff] [blame] | 5187 | // Something bad happened with this ICD, so free it and try the |
| 5188 | // next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5189 | ptr_instance->icd_terms = icd_term->next; |
| 5190 | icd_term->next = NULL; |
| 5191 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5192 | continue; |
| 5193 | } |
| 5194 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5195 | res = loader_add_instance_extensions(ptr_instance, icd_term->scanned_icd->EnumerateInstanceExtensionProperties, |
| 5196 | icd_term->scanned_icd->lib_name, &icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 5197 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5198 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 5199 | if (VK_ERROR_OUT_OF_HOST_MEMORY == res) { |
| 5200 | // If out of memory, bail immediately. |
| 5201 | goto out; |
| 5202 | } else { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5203 | // Something bad happened with this ICD, so free it and try the next. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5204 | ptr_instance->icd_terms = icd_term->next; |
| 5205 | icd_term->next = NULL; |
| 5206 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | db13a2a | 2016-09-06 13:53:03 -0600 | [diff] [blame] | 5207 | continue; |
| 5208 | } |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5209 | } |
Courtney Goeltzenleuchter | 36eeb74 | 2015-12-21 16:41:47 -0700 | [diff] [blame] | 5210 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5211 | for (uint32_t j = 0; j < pCreateInfo->enabledExtensionCount; j++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5212 | prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[j], &icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5213 | if (prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5214 | filtered_extension_names[icd_create_info.enabledExtensionCount] = (char *)pCreateInfo->ppEnabledExtensionNames[j]; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5215 | icd_create_info.enabledExtensionCount++; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5216 | } |
| 5217 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5218 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5219 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5220 | |
Lenny Komow | e12b336 | 2017-11-03 13:14:32 -0600 | [diff] [blame] | 5221 | // Get the driver version from vkEnumerateInstanceVersion |
| 5222 | uint32_t icd_version = VK_API_VERSION_1_0; |
| 5223 | PFN_vkEnumerateInstanceVersion icd_enumerate_instance_version = (PFN_vkEnumerateInstanceVersion) |
Lenny Komow | d74b368 | 2017-11-07 10:42:19 -0700 | [diff] [blame] | 5224 | icd_term->scanned_icd->GetInstanceProcAddr(NULL, "vkEnumerateInstanceVersion"); |
Lenny Komow | e12b336 | 2017-11-03 13:14:32 -0600 | [diff] [blame] | 5225 | VkResult icd_result = VK_SUCCESS; |
| 5226 | if (icd_enumerate_instance_version != NULL) { |
| 5227 | icd_result = icd_enumerate_instance_version(&icd_version); |
| 5228 | if (icd_result != VK_SUCCESS) { |
| 5229 | icd_version = VK_API_VERSION_1_0; |
| 5230 | loader_log(ptr_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "terminator_CreateInstance: ICD \"%s\" " |
| 5231 | "vkEnumerateInstanceVersion returned error. The ICD will be treated as a 1.0 ICD", |
| 5232 | icd_term->scanned_icd->lib_name); |
| 5233 | } |
| 5234 | } |
| 5235 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5236 | // Create an instance, substituting the version to 1.0 if necessary |
Lenny Komow | 838df73 | 2017-10-11 13:39:33 -0600 | [diff] [blame] | 5237 | VkApplicationInfo icd_app_info; |
Lenny Komow | 05c419b | 2017-10-11 09:20:52 -0600 | [diff] [blame] | 5238 | uint32_t requested_version = pCreateInfo == NULL || pCreateInfo->pApplicationInfo == NULL ? VK_API_VERSION_1_0 : pCreateInfo->pApplicationInfo->apiVersion; |
Lenny Komow | e12b336 | 2017-11-03 13:14:32 -0600 | [diff] [blame] | 5239 | if (requested_version > icd_version) { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5240 | if (icd_create_info.pApplicationInfo == NULL) { |
| 5241 | memset(&icd_app_info, 0, sizeof(icd_app_info)); |
| 5242 | } else { |
| 5243 | memcpy(&icd_app_info, icd_create_info.pApplicationInfo, sizeof(icd_app_info)); |
| 5244 | } |
| 5245 | icd_app_info.apiVersion = icd_term->scanned_icd->api_version; |
| 5246 | icd_create_info.pApplicationInfo = &icd_app_info; |
| 5247 | } |
Lenny Komow | e12b336 | 2017-11-03 13:14:32 -0600 | [diff] [blame] | 5248 | icd_result = ptr_instance->icd_tramp_list.scanned_list[i].CreateInstance(&icd_create_info, pAllocator, &(icd_term->instance)); |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5249 | if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_result) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5250 | // If out of memory, bail immediately. |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5251 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5252 | goto out; |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5253 | } else if (VK_SUCCESS != icd_result) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5254 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 5255 | "terminator_CreateInstance: Failed to CreateInstance in " |
| 5256 | "ICD %d. Skipping ICD.", |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5257 | i); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5258 | ptr_instance->icd_terms = icd_term->next; |
| 5259 | icd_term->next = NULL; |
| 5260 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5261 | continue; |
| 5262 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5263 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5264 | if (!loader_icd_init_entries(icd_term, icd_term->instance, |
| 5265 | ptr_instance->icd_tramp_list.scanned_list[i].GetInstanceProcAddr)) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5266 | loader_log(ptr_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 5267 | "terminator_CreateInstance: Failed to CreateInstance and find " |
| 5268 | "entrypoints with ICD. Skipping ICD."); |
Lenny Komow | a44cc85 | 2017-09-12 22:54:21 -0600 | [diff] [blame] | 5269 | ptr_instance->icd_terms = icd_term->next; |
| 5270 | icd_term->next = NULL; |
| 5271 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5272 | continue; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5273 | } |
Mark Young | 8b4edb5 | 2016-11-11 09:31:55 -0700 | [diff] [blame] | 5274 | |
| 5275 | // If we made it this far, at least one ICD was successful |
| 5276 | one_icd_successful = true; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5277 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5278 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5279 | // If no ICDs were added to instance list and res is unchanged from it's initial value, the loader was unable to |
| 5280 | // find a suitable ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5281 | if (VK_SUCCESS == res && (ptr_instance->icd_terms == NULL || !one_icd_successful)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5282 | res = VK_ERROR_INCOMPATIBLE_DRIVER; |
| 5283 | } |
| 5284 | |
| 5285 | out: |
| 5286 | |
| 5287 | if (VK_SUCCESS != res) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5288 | while (NULL != ptr_instance->icd_terms) { |
| 5289 | icd_term = ptr_instance->icd_terms; |
| 5290 | ptr_instance->icd_terms = icd_term->next; |
| 5291 | if (NULL != icd_term->instance) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5292 | icd_term->dispatch.DestroyInstance(icd_term->instance, pAllocator); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5293 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5294 | loader_icd_destroy(ptr_instance, icd_term, pAllocator); |
Courtney Goeltzenleuchter | 40caf0b | 2015-07-06 09:06:34 -0600 | [diff] [blame] | 5295 | } |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 5296 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5297 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5298 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5299 | } |
| 5300 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5301 | VKAPI_ATTR void VKAPI_CALL terminator_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
Courtney Goeltzenleuchter | deceded | 2015-06-08 15:04:02 -0600 | [diff] [blame] | 5302 | struct loader_instance *ptr_instance = loader_instance(instance); |
Karl Schultz | e2ef9e6 | 2017-01-13 14:01:35 -0700 | [diff] [blame] | 5303 | if (NULL == ptr_instance) { |
| 5304 | return; |
| 5305 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5306 | struct loader_icd_term *icd_terms = ptr_instance->icd_terms; |
| 5307 | struct loader_icd_term *next_icd_term; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5308 | |
| 5309 | // Remove this instance from the list of instances: |
| 5310 | struct loader_instance *prev = NULL; |
| 5311 | struct loader_instance *next = loader.instances; |
| 5312 | while (next != NULL) { |
| 5313 | if (next == ptr_instance) { |
| 5314 | // Remove this instance from the list: |
| 5315 | if (prev) |
| 5316 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 5317 | else |
| 5318 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5319 | break; |
| 5320 | } |
| 5321 | prev = next; |
| 5322 | next = next->next; |
| 5323 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5324 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5325 | while (NULL != icd_terms) { |
| 5326 | if (icd_terms->instance) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5327 | icd_terms->dispatch.DestroyInstance(icd_terms->instance, pAllocator); |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 5328 | } |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5329 | next_icd_term = icd_terms->next; |
| 5330 | icd_terms->instance = VK_NULL_HANDLE; |
| 5331 | loader_icd_destroy(ptr_instance, icd_terms, pAllocator); |
Jon Ashburn | a6fd261 | 2015-06-16 14:43:19 -0600 | [diff] [blame] | 5332 | |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5333 | icd_terms = next_icd_term; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 5334 | } |
Jon Ashburn | 491cd04 | 2016-05-16 14:01:18 -0600 | [diff] [blame] | 5335 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5336 | loader_delete_layer_properties(ptr_instance, &ptr_instance->instance_layer_list); |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5337 | loader_scanned_icd_clear(ptr_instance, &ptr_instance->icd_tramp_list); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5338 | loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 5339 | if (NULL != ptr_instance->phys_devs_term) { |
Mark Young | 0193d65 | 2016-12-28 16:10:10 -0700 | [diff] [blame] | 5340 | for (uint32_t i = 0; i < ptr_instance->phys_dev_count_term; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5341 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term[i]); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 5342 | } |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5343 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_devs_term); |
Lenny Komow | 8a1f8a5 | 2016-12-20 15:35:11 -0700 | [diff] [blame] | 5344 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5345 | if (NULL != ptr_instance->phys_dev_groups_term) { |
| 5346 | for (uint32_t i = 0; i < ptr_instance->phys_dev_group_count_term; i++) { |
| 5347 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_dev_groups_term[i]); |
| 5348 | } |
| 5349 | loader_instance_heap_free(ptr_instance, ptr_instance->phys_dev_groups_term); |
| 5350 | } |
Jon Ashburn | fc1031e | 2015-11-17 15:31:02 -0700 | [diff] [blame] | 5351 | loader_free_dev_ext_table(ptr_instance); |
Mark Young | 3938987 | 2017-01-19 21:10:49 -0700 | [diff] [blame] | 5352 | loader_free_phys_dev_ext_table(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5353 | } |
| 5354 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5355 | VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, |
| 5356 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5357 | VkResult res = VK_SUCCESS; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5358 | struct loader_physical_device_term *phys_dev_term; |
| 5359 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 5360 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5361 | |
Jon Ashburn | cc407a2 | 2016-04-15 09:25:03 -0600 | [diff] [blame] | 5362 | struct loader_device *dev = (struct loader_device *)*pDevice; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5363 | PFN_vkCreateDevice fpCreateDevice = icd_term->dispatch.CreateDevice; |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5364 | struct loader_extension_list icd_exts; |
| 5365 | |
Joey Bzdek | c2536de | 2017-10-23 17:13:33 -0600 | [diff] [blame] | 5366 | struct VkStructureHeader *caller_dgci_container = NULL; |
Mike Schuchardt | 51390c5 | 2018-02-06 16:56:31 -0700 | [diff] [blame] | 5367 | VkDeviceGroupDeviceCreateInfoKHR *caller_dgci = NULL; |
Joey Bzdek | c2536de | 2017-10-23 17:13:33 -0600 | [diff] [blame] | 5368 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 5369 | dev->phys_dev_term = phys_dev_term; |
| 5370 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5371 | icd_exts.list = NULL; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5372 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5373 | if (fpCreateDevice == NULL) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5374 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5375 | "terminator_CreateDevice: No vkCreateDevice command exposed " |
| 5376 | "by ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5377 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5378 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5379 | goto out; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5380 | } |
| 5381 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5382 | VkDeviceCreateInfo localCreateInfo; |
| 5383 | memcpy(&localCreateInfo, pCreateInfo, sizeof(localCreateInfo)); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5384 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5385 | // NOTE: Need to filter the extensions to only those supported by the ICD. |
Mark Young | e1ea901 | 2017-03-09 14:17:40 -0700 | [diff] [blame] | 5386 | // No ICD will advertise support for layers. An ICD library could support a layer, |
| 5387 | // but it would be independent of the actual ICD, just in the same library. |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5388 | char **filtered_extension_names = NULL; |
Mark Young | e1ea901 | 2017-03-09 14:17:40 -0700 | [diff] [blame] | 5389 | if (0 < pCreateInfo->enabledExtensionCount) { |
| 5390 | filtered_extension_names = loader_stack_alloc(pCreateInfo->enabledExtensionCount * sizeof(char *)); |
| 5391 | if (NULL == filtered_extension_names) { |
| 5392 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5393 | "terminator_CreateDevice: Failed to create extension name " |
| 5394 | "storage for %d extensions %d", |
| 5395 | pCreateInfo->enabledExtensionCount); |
| 5396 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5397 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5398 | } |
| 5399 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5400 | localCreateInfo.enabledLayerCount = 0; |
| 5401 | localCreateInfo.ppEnabledLayerNames = NULL; |
| 5402 | |
| 5403 | localCreateInfo.enabledExtensionCount = 0; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5404 | localCreateInfo.ppEnabledExtensionNames = (const char *const *)filtered_extension_names; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5405 | |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5406 | // Get the physical device (ICD) extensions |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5407 | res = loader_init_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts, sizeof(VkExtensionProperties)); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5408 | if (VK_SUCCESS != res) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5409 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5412 | res = loader_add_device_extensions(icd_term->this_instance, icd_term->dispatch.EnumerateDeviceExtensionProperties, |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5413 | phys_dev_term->phys_dev, icd_term->scanned_icd->lib_name, &icd_exts); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5414 | if (res != VK_SUCCESS) { |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5415 | goto out; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5416 | } |
| 5417 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5418 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 5419 | const char *extension_name = pCreateInfo->ppEnabledExtensionNames[i]; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5420 | VkExtensionProperties *prop = get_extension_property(extension_name, &icd_exts); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5421 | if (prop) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5422 | filtered_extension_names[localCreateInfo.enabledExtensionCount] = (char *)extension_name; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5423 | localCreateInfo.enabledExtensionCount++; |
Mark Young | 9a3ddd4 | 2016-10-21 16:25:47 -0600 | [diff] [blame] | 5424 | } else { |
Lenny Komow | 8314e54 | 2018-01-03 10:37:54 -0700 | [diff] [blame] | 5425 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5426 | "vkCreateDevice extension %s not available for " |
| 5427 | "devices associated with ICD %s", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5428 | extension_name, icd_term->scanned_icd->lib_name); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5429 | } |
| 5430 | } |
| 5431 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5432 | // Before we continue, If KHX_device_group is the list of enabled and viable extensions, then we then need to look for the |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5433 | // corresponding VkDeviceGroupDeviceCreateInfo struct in the device list and replace all the physical device values (which |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5434 | // are really loader physical device terminator values) with the ICD versions. |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5435 | //if (icd_term->this_instance->enabled_known_extensions.khr_device_group_creation == 1) { |
| 5436 | { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5437 | struct VkStructureHeader *pNext = (struct VkStructureHeader *)localCreateInfo.pNext; |
| 5438 | struct VkStructureHeader *pPrev = (struct VkStructureHeader *)&localCreateInfo; |
| 5439 | while (NULL != pNext) { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5440 | if (VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO == pNext->sType) { |
| 5441 | VkDeviceGroupDeviceCreateInfo *cur_struct = (VkDeviceGroupDeviceCreateInfo *)pNext; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5442 | if (0 < cur_struct->physicalDeviceCount && NULL != cur_struct->pPhysicalDevices) { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5443 | VkDeviceGroupDeviceCreateInfo *temp_struct = loader_stack_alloc(sizeof(VkDeviceGroupDeviceCreateInfo)); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5444 | VkPhysicalDevice *phys_dev_array = NULL; |
| 5445 | if (NULL == temp_struct) { |
| 5446 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5447 | } |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5448 | memcpy(temp_struct, cur_struct, sizeof(VkDeviceGroupDeviceCreateInfo)); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5449 | phys_dev_array = loader_stack_alloc(sizeof(VkPhysicalDevice) * cur_struct->physicalDeviceCount); |
| 5450 | if (NULL == phys_dev_array) { |
| 5451 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5452 | } |
| 5453 | |
| 5454 | // Before calling down, replace the incoming physical device values (which are really loader terminator |
| 5455 | // physical devices) with the ICDs physical device values. |
| 5456 | struct loader_physical_device_term *cur_term; |
| 5457 | for (uint32_t phys_dev = 0; phys_dev < cur_struct->physicalDeviceCount; phys_dev++) { |
| 5458 | cur_term = (struct loader_physical_device_term *)cur_struct->pPhysicalDevices[phys_dev]; |
| 5459 | phys_dev_array[phys_dev] = cur_term->phys_dev; |
| 5460 | } |
| 5461 | temp_struct->pPhysicalDevices = phys_dev_array; |
| 5462 | |
Joey Bzdek | c2536de | 2017-10-23 17:13:33 -0600 | [diff] [blame] | 5463 | // Keep track of pointers to restore pNext chain before returning |
| 5464 | caller_dgci_container = pPrev; |
| 5465 | caller_dgci = cur_struct; |
| 5466 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5467 | // Replace the old struct in the pNext chain with this one. |
| 5468 | pPrev->pNext = (const void *)temp_struct; |
| 5469 | pNext = (struct VkStructureHeader *)(temp_struct); |
| 5470 | } |
| 5471 | break; |
| 5472 | } |
| 5473 | |
| 5474 | pPrev = pNext; |
| 5475 | pNext = (struct VkStructureHeader *)(pPrev->pNext); |
| 5476 | } |
| 5477 | } |
| 5478 | |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5479 | // Handle loader emulation for structs that are not supported by the ICD: |
| 5480 | // Presently, the emulation leaves the pNext chain alone. This means that the ICD will receive items in the chain which |
| 5481 | // are not recognized by the ICD. If this causes the ICD to fail, then the items would have to be removed here. The current |
| 5482 | // implementation does not remove them because copying the pNext chain would be impossible if the loader does not recognize |
| 5483 | // the any of the struct types, as the loader would not know the size to allocate and copy. |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5484 | //if (icd_term->dispatch.GetPhysicalDeviceFeatures2 == NULL && icd_term->dispatch.GetPhysicalDeviceFeatures2KHR == NULL) { |
| 5485 | { |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5486 | const void *pNext = localCreateInfo.pNext; |
| 5487 | while (pNext != NULL) { |
| 5488 | switch (*(VkStructureType *)pNext) { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5489 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2: { |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5490 | const VkPhysicalDeviceFeatures2KHR *features = pNext; |
| 5491 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5492 | if (icd_term->dispatch.GetPhysicalDeviceFeatures2 == NULL && icd_term->dispatch.GetPhysicalDeviceFeatures2KHR == NULL) { |
| 5493 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 5494 | "vkCreateDevice: Emulating handling of VkPhysicalDeviceFeatures2 in pNext chain for ICD \"%s\"", |
| 5495 | icd_term->scanned_icd->lib_name); |
| 5496 | |
| 5497 | // Verify that VK_KHR_get_physical_device_properties2 is enabled |
| 5498 | if (icd_term->this_instance->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 5499 | localCreateInfo.pEnabledFeatures = &features->features; |
| 5500 | } |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5501 | } |
| 5502 | |
| 5503 | // Leave this item in the pNext chain for now |
| 5504 | |
| 5505 | pNext = features->pNext; |
| 5506 | break; |
| 5507 | } |
| 5508 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5509 | case VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO: { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5510 | const VkDeviceGroupDeviceCreateInfoKHR *group_info = pNext; |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5511 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5512 | if (icd_term->dispatch.EnumeratePhysicalDeviceGroups == NULL && icd_term->dispatch.EnumeratePhysicalDeviceGroupsKHR == NULL) { |
| 5513 | loader_log( |
| 5514 | icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
| 5515 | "vkCreateDevice: Emulating handling of VkPhysicalDeviceGroupProperties in pNext chain for ICD \"%s\"", |
| 5516 | icd_term->scanned_icd->lib_name); |
| 5517 | |
| 5518 | // The group must contain only this one device, since physical device groups aren't actually supported |
| 5519 | if (group_info->physicalDeviceCount != 1) { |
| 5520 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5521 | "vkCreateDevice: Emulation failed to create device from device group info"); |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 5522 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5523 | goto out; |
| 5524 | } |
Lenny Komow | 34d78d2 | 2017-05-24 15:47:15 -0600 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | // Nothing needs to be done here because we're leaving the item in the pNext chain and because the spec states |
| 5528 | // that the physicalDevice argument must be included in the device group, and we've already checked that it is |
| 5529 | |
| 5530 | pNext = group_info->pNext; |
| 5531 | break; |
| 5532 | } |
| 5533 | |
| 5534 | // Multiview properties are also allowed, but since VK_KHX_multiview is a device extension, we'll just let the ICD |
| 5535 | // handle that error when the user enables the extension here |
| 5536 | default: { |
| 5537 | const struct VkStructureHeader *header = pNext; |
| 5538 | pNext = header->pNext; |
| 5539 | break; |
| 5540 | } |
| 5541 | } |
| 5542 | } |
| 5543 | } |
| 5544 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5545 | res = fpCreateDevice(phys_dev_term->phys_dev, &localCreateInfo, pAllocator, &dev->icd_device); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5546 | if (res != VK_SUCCESS) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5547 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5548 | "terminator_CreateDevice: Failed in ICD %s vkCreateDevice" |
| 5549 | "call", |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5550 | icd_term->scanned_icd->lib_name); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5551 | goto out; |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
Mark Young | 65cb366 | 2016-11-07 13:27:02 -0700 | [diff] [blame] | 5554 | *pDevice = dev->icd_device; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5555 | loader_add_logical_device(icd_term->this_instance, icd_term, dev); |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5556 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5557 | // Init dispatch pointer in new device object |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5558 | loader_init_dispatch(*pDevice, &dev->loader_dispatch); |
| 5559 | |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5560 | out: |
| 5561 | if (NULL != icd_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5562 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 0ad8313 | 2016-06-30 13:02:42 -0600 | [diff] [blame] | 5563 | } |
| 5564 | |
Joey Bzdek | c2536de | 2017-10-23 17:13:33 -0600 | [diff] [blame] | 5565 | // Restore pNext pointer to old VkDeviceGroupDeviceCreateInfoKHX |
| 5566 | // in the chain to maintain consistency for the caller. |
| 5567 | if (caller_dgci_container != NULL) { |
| 5568 | caller_dgci_container->pNext = caller_dgci; |
| 5569 | } |
| 5570 | |
Jon Ashburn | 1530c34 | 2016-02-26 13:14:27 -0700 | [diff] [blame] | 5571 | return res; |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5572 | } |
| 5573 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5574 | VkResult setupLoaderTrampPhysDevs(VkInstance instance) { |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5575 | VkResult res = VK_SUCCESS; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5576 | VkPhysicalDevice *local_phys_devs = NULL; |
| 5577 | struct loader_instance *inst; |
| 5578 | uint32_t total_count = 0; |
| 5579 | struct loader_physical_device_tramp **new_phys_devs = NULL; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 5580 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5581 | inst = loader_get_instance(instance); |
| 5582 | if (NULL == inst) { |
| 5583 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5584 | goto out; |
| 5585 | } |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5586 | |
Mark Young | bb3a29c | 2017-05-19 12:29:43 -0600 | [diff] [blame] | 5587 | // Query how many GPUs there |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5588 | res = inst->disp->layer_inst_disp.EnumeratePhysicalDevices(instance, &total_count, NULL); |
| 5589 | if (res != VK_SUCCESS) { |
| 5590 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5591 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 5592 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
| 5593 | "loader to get count."); |
| 5594 | goto out; |
| 5595 | } |
| 5596 | |
| 5597 | // Really use what the total GPU count is since Optimus and other layers may mess |
| 5598 | // the count up. |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5599 | total_count = inst->total_gpu_count; |
| 5600 | |
| 5601 | // Create an array for the new physical devices, which will be stored |
| 5602 | // in the instance for the trampoline code. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5603 | new_phys_devs = (struct loader_physical_device_tramp **)loader_instance_heap_alloc( |
| 5604 | inst, total_count * sizeof(struct loader_physical_device_tramp *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5605 | if (NULL == new_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5606 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5607 | "setupLoaderTrampPhysDevs: Failed to allocate new physical device" |
| 5608 | " array of size %d", |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5609 | total_count); |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5610 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5611 | goto out; |
| 5612 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5613 | memset(new_phys_devs, 0, total_count * sizeof(struct loader_physical_device_tramp *)); |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5614 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5615 | // Create a temporary array (on the stack) to keep track of the |
| 5616 | // returned VkPhysicalDevice values. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5617 | local_phys_devs = loader_stack_alloc(sizeof(VkPhysicalDevice) * total_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5618 | if (NULL == local_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5619 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5620 | "setupLoaderTrampPhysDevs: Failed to allocate local " |
| 5621 | "physical device array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5622 | total_count); |
| 5623 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5624 | goto out; |
| 5625 | } |
| 5626 | memset(local_phys_devs, 0, sizeof(VkPhysicalDevice) * total_count); |
| 5627 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5628 | res = inst->disp->layer_inst_disp.EnumeratePhysicalDevices(instance, &total_count, local_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5629 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5630 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5631 | "setupLoaderTrampPhysDevs: Failed during dispatch call " |
| 5632 | "of \'vkEnumeratePhysicalDevices\' to lower layers or " |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5633 | "loader to get content."); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5634 | goto out; |
| 5635 | } |
| 5636 | |
| 5637 | // Copy or create everything to fill the new array of physical devices |
| 5638 | for (uint32_t new_idx = 0; new_idx < total_count; new_idx++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5639 | // Check if this physical device is already in the old buffer |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5640 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_count_tramp; old_idx++) { |
| 5641 | if (local_phys_devs[new_idx] == inst->phys_devs_tramp[old_idx]->phys_dev) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5642 | new_phys_devs[new_idx] = inst->phys_devs_tramp[old_idx]; |
| 5643 | break; |
| 5644 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5645 | } |
| 5646 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5647 | // If this physical device isn't in the old buffer, create it |
| 5648 | if (NULL == new_phys_devs[new_idx]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5649 | new_phys_devs[new_idx] = (struct loader_physical_device_tramp *)loader_instance_heap_alloc( |
| 5650 | inst, sizeof(struct loader_physical_device_tramp), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5651 | if (NULL == new_phys_devs[new_idx]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5652 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5653 | "setupLoaderTrampPhysDevs: Failed to allocate " |
| 5654 | "physical device trampoline object %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5655 | new_idx); |
| 5656 | total_count = new_idx; |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5657 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5658 | goto out; |
| 5659 | } |
| 5660 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5661 | // Initialize the new physicalDevice object |
| 5662 | loader_set_dispatch((void *)new_phys_devs[new_idx], inst->disp); |
| 5663 | new_phys_devs[new_idx]->this_instance = inst; |
| 5664 | new_phys_devs[new_idx]->phys_dev = local_phys_devs[new_idx]; |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5665 | } |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 5666 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5667 | |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 5668 | out: |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5669 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5670 | if (VK_SUCCESS != res) { |
| 5671 | if (NULL != new_phys_devs) { |
| 5672 | for (uint32_t i = 0; i < total_count; i++) { |
| 5673 | loader_instance_heap_free(inst, new_phys_devs[i]); |
Lenny Komow | a5e0112 | 2016-12-22 15:29:43 -0700 | [diff] [blame] | 5674 | } |
| 5675 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5676 | } |
| 5677 | total_count = 0; |
| 5678 | } else { |
| 5679 | // Free everything that didn't carry over to the new array of |
| 5680 | // physical devices |
| 5681 | if (NULL != inst->phys_devs_tramp) { |
| 5682 | for (uint32_t i = 0; i < inst->phys_dev_count_tramp; i++) { |
| 5683 | bool found = false; |
| 5684 | for (uint32_t j = 0; j < total_count; j++) { |
| 5685 | if (inst->phys_devs_tramp[i] == new_phys_devs[j]) { |
| 5686 | found = true; |
| 5687 | break; |
| 5688 | } |
| 5689 | } |
| 5690 | if (!found) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5691 | loader_instance_heap_free(inst, inst->phys_devs_tramp[i]); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5692 | } |
| 5693 | } |
| 5694 | loader_instance_heap_free(inst, inst->phys_devs_tramp); |
| 5695 | } |
Mark Young | d8382d7 | 2016-12-23 16:59:58 -0700 | [diff] [blame] | 5696 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5697 | // Swap in the new physical device list |
| 5698 | inst->phys_dev_count_tramp = total_count; |
| 5699 | inst->phys_devs_tramp = new_phys_devs; |
| 5700 | } |
| 5701 | |
| 5702 | return res; |
| 5703 | } |
| 5704 | |
| 5705 | VkResult setupLoaderTermPhysDevs(struct loader_instance *inst) { |
| 5706 | VkResult res = VK_SUCCESS; |
| 5707 | struct loader_icd_term *icd_term; |
| 5708 | struct loader_phys_dev_per_icd *icd_phys_dev_array = NULL; |
| 5709 | struct loader_physical_device_term **new_phys_devs = NULL; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5710 | |
| 5711 | inst->total_gpu_count = 0; |
| 5712 | |
| 5713 | // Allocate something to store the physical device characteristics |
| 5714 | // that we read from each ICD. |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5715 | icd_phys_dev_array = |
| 5716 | (struct loader_phys_dev_per_icd *)loader_stack_alloc(sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5717 | if (NULL == icd_phys_dev_array) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5718 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5719 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 5720 | "ICD Physical device info array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5721 | inst->total_gpu_count); |
| 5722 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5723 | goto out; |
| 5724 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5725 | memset(icd_phys_dev_array, 0, sizeof(struct loader_phys_dev_per_icd) * inst->total_icd_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5726 | icd_term = inst->icd_terms; |
| 5727 | |
| 5728 | // For each ICD, query the number of physical devices, and then get an |
| 5729 | // internal value for those physical devices. |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5730 | for (uint32_t icd_idx = 0; NULL != icd_term; icd_term = icd_term->next, icd_idx++) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5731 | res = icd_term->dispatch.EnumeratePhysicalDevices(icd_term->instance, &icd_phys_dev_array[icd_idx].count, NULL); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5732 | if (VK_SUCCESS != res) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5733 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5734 | "setupLoaderTermPhysDevs: Call to " |
| 5735 | "ICD %d's \'vkEnumeratePhysicalDevices\' failed with" |
| 5736 | " error 0x%08x", |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5737 | icd_idx, res); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5738 | goto out; |
| 5739 | } |
| 5740 | |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5741 | icd_phys_dev_array[icd_idx].phys_devs = |
| 5742 | (VkPhysicalDevice *)loader_stack_alloc(icd_phys_dev_array[icd_idx].count * sizeof(VkPhysicalDevice)); |
| 5743 | if (NULL == icd_phys_dev_array[icd_idx].phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5744 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5745 | "setupLoaderTermPhysDevs: Failed to allocate temporary " |
| 5746 | "ICD Physical device array for ICD %d of size %d", |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5747 | icd_idx, inst->total_gpu_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5748 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5749 | goto out; |
| 5750 | } |
| 5751 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5752 | res = icd_term->dispatch.EnumeratePhysicalDevices(icd_term->instance, &(icd_phys_dev_array[icd_idx].count), |
| 5753 | icd_phys_dev_array[icd_idx].phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5754 | if (VK_SUCCESS != res) { |
| 5755 | goto out; |
| 5756 | } |
Karl Schultz | 47dd59d | 2017-01-20 13:19:20 -0700 | [diff] [blame] | 5757 | inst->total_gpu_count += icd_phys_dev_array[icd_idx].count; |
| 5758 | icd_phys_dev_array[icd_idx].this_icd_term = icd_term; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | if (0 == inst->total_gpu_count) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5762 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5763 | "setupLoaderTermPhysDevs: Failed to detect any valid" |
| 5764 | " GPUs in the current config"); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5765 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 5766 | goto out; |
| 5767 | } |
| 5768 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5769 | new_phys_devs = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term *) * inst->total_gpu_count, |
| 5770 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5771 | if (NULL == new_phys_devs) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5772 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5773 | "setupLoaderTermPhysDevs: Failed to allocate new physical" |
| 5774 | " device array of size %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5775 | inst->total_gpu_count); |
| 5776 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5777 | goto out; |
| 5778 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5779 | memset(new_phys_devs, 0, sizeof(struct loader_physical_device_term *) * inst->total_gpu_count); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5780 | |
| 5781 | // Copy or create everything to fill the new array of physical devices |
| 5782 | uint32_t idx = 0; |
| 5783 | for (uint32_t icd_idx = 0; icd_idx < inst->total_icd_count; icd_idx++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5784 | for (uint32_t pd_idx = 0; pd_idx < icd_phys_dev_array[icd_idx].count; pd_idx++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5785 | // Check if this physical device is already in the old buffer |
| 5786 | if (NULL != inst->phys_devs_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5787 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_count_term; old_idx++) { |
| 5788 | if (icd_phys_dev_array[icd_idx].phys_devs[pd_idx] == inst->phys_devs_term[old_idx]->phys_dev) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5789 | new_phys_devs[idx] = inst->phys_devs_term[old_idx]; |
| 5790 | break; |
| 5791 | } |
| 5792 | } |
| 5793 | } |
| 5794 | // If this physical device isn't in the old buffer, then we |
| 5795 | // need to create it. |
| 5796 | if (NULL == new_phys_devs[idx]) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5797 | new_phys_devs[idx] = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term), |
| 5798 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5799 | if (NULL == new_phys_devs[idx]) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 5800 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5801 | "setupLoaderTermPhysDevs: Failed to allocate " |
| 5802 | "physical device terminator object %d", |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5803 | idx); |
| 5804 | inst->total_gpu_count = idx; |
| 5805 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5806 | goto out; |
| 5807 | } |
| 5808 | |
| 5809 | loader_set_dispatch((void *)new_phys_devs[idx], inst->disp); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5810 | new_phys_devs[idx]->this_icd_term = icd_phys_dev_array[icd_idx].this_icd_term; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5811 | new_phys_devs[idx]->icd_index = (uint8_t)(icd_idx); |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5812 | new_phys_devs[idx]->phys_dev = icd_phys_dev_array[icd_idx].phys_devs[pd_idx]; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5813 | } |
| 5814 | idx++; |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | out: |
| 5819 | |
| 5820 | if (VK_SUCCESS != res) { |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5821 | if (NULL != new_phys_devs) { |
| 5822 | // We've encountered an error, so we should free the new buffers. |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5823 | for (uint32_t i = 0; i < inst->total_gpu_count; i++) { |
| 5824 | loader_instance_heap_free(inst, new_phys_devs[i]); |
| 5825 | } |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5826 | loader_instance_heap_free(inst, new_phys_devs); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5827 | } |
Mark Young | 156e855 | 2017-02-03 16:27:42 -0700 | [diff] [blame] | 5828 | inst->total_gpu_count = 0; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5829 | } else { |
| 5830 | // Free everything that didn't carry over to the new array of |
| 5831 | // physical devices. Everything else will have been copied over |
| 5832 | // to the new array. |
| 5833 | if (NULL != inst->phys_devs_term) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5834 | for (uint32_t cur_pd = 0; cur_pd < inst->phys_dev_count_term; cur_pd++) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5835 | bool found = false; |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5836 | for (uint32_t new_pd_idx = 0; new_pd_idx < inst->total_gpu_count; new_pd_idx++) { |
| 5837 | if (inst->phys_devs_term[cur_pd] == new_phys_devs[new_pd_idx]) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5838 | found = true; |
| 5839 | break; |
| 5840 | } |
| 5841 | } |
| 5842 | if (!found) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5843 | loader_instance_heap_free(inst, inst->phys_devs_term[cur_pd]); |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5844 | } |
| 5845 | } |
| 5846 | loader_instance_heap_free(inst, inst->phys_devs_term); |
| 5847 | } |
| 5848 | |
| 5849 | // Swap out old and new devices list |
| 5850 | inst->phys_dev_count_term = inst->total_gpu_count; |
| 5851 | inst->phys_devs_term = new_phys_devs; |
| 5852 | } |
| 5853 | |
| 5854 | return res; |
| 5855 | } |
| 5856 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5857 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, |
| 5858 | VkPhysicalDevice *pPhysicalDevices) { |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5859 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 5860 | VkResult res = VK_SUCCESS; |
| 5861 | |
Mark Young | d66edd5 | 2017-03-10 17:31:18 -0700 | [diff] [blame] | 5862 | // Always call the setup loader terminator physical devices because they may |
| 5863 | // have changed at any point. |
| 5864 | res = setupLoaderTermPhysDevs(inst); |
| 5865 | if (VK_SUCCESS != res) { |
| 5866 | goto out; |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | uint32_t copy_count = inst->total_gpu_count; |
| 5870 | if (NULL != pPhysicalDevices) { |
| 5871 | if (copy_count > *pPhysicalDeviceCount) { |
| 5872 | copy_count = *pPhysicalDeviceCount; |
| 5873 | res = VK_INCOMPLETE; |
| 5874 | } |
| 5875 | |
| 5876 | for (uint32_t i = 0; i < copy_count; i++) { |
| 5877 | pPhysicalDevices[i] = (VkPhysicalDevice)inst->phys_devs_term[i]; |
Jon Ashburn | 014438f | 2016-03-01 19:51:07 -0700 | [diff] [blame] | 5878 | } |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 5879 | } |
Mark Young | 559d750 | 2016-09-26 11:38:46 -0600 | [diff] [blame] | 5880 | |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 5881 | *pPhysicalDeviceCount = copy_count; |
| 5882 | |
Mark Young | 6267ae6 | 2017-01-12 12:27:19 -0700 | [diff] [blame] | 5883 | out: |
| 5884 | |
Jon Ashburn | 24cd4be | 2015-11-01 14:04:06 -0700 | [diff] [blame] | 5885 | return res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 5886 | } |
| 5887 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5888 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, |
| 5889 | VkPhysicalDeviceProperties *pProperties) { |
| 5890 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5891 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5892 | if (NULL != icd_term->dispatch.GetPhysicalDeviceProperties) { |
| 5893 | icd_term->dispatch.GetPhysicalDeviceProperties(phys_dev_term->phys_dev, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5894 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5895 | } |
| 5896 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5897 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, |
| 5898 | uint32_t *pQueueFamilyPropertyCount, |
| 5899 | VkQueueFamilyProperties *pProperties) { |
| 5900 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5901 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5902 | if (NULL != icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties) { |
| 5903 | icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5904 | } |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 5905 | } |
| 5906 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5907 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, |
| 5908 | VkPhysicalDeviceMemoryProperties *pProperties) { |
| 5909 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5910 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5911 | if (NULL != icd_term->dispatch.GetPhysicalDeviceMemoryProperties) { |
| 5912 | icd_term->dispatch.GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5913 | } |
Jon Ashburn | 3da71f2 | 2015-05-14 12:43:38 -0600 | [diff] [blame] | 5914 | } |
| 5915 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5916 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, |
| 5917 | VkPhysicalDeviceFeatures *pFeatures) { |
| 5918 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5919 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5920 | if (NULL != icd_term->dispatch.GetPhysicalDeviceFeatures) { |
| 5921 | icd_term->dispatch.GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, pFeatures); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5922 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5923 | } |
| 5924 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5925 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5926 | VkFormatProperties *pFormatInfo) { |
| 5927 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5928 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5929 | if (NULL != icd_term->dispatch.GetPhysicalDeviceFormatProperties) { |
| 5930 | icd_term->dispatch.GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, format, pFormatInfo); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5931 | } |
Chris Forbes | bc0bb77 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 5932 | } |
| 5933 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5934 | VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5935 | VkImageType type, VkImageTiling tiling, |
| 5936 | VkImageUsageFlags usage, VkImageCreateFlags flags, |
| 5937 | VkImageFormatProperties *pImageFormatProperties) { |
| 5938 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5939 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5940 | if (NULL == icd_term->dispatch.GetPhysicalDeviceImageFormatProperties) { |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5941 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 5942 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 5943 | "terminator. This means a layer improperly continued."); |
Chia-I Wu | 1724104 | 2015-10-31 00:31:16 +0800 | [diff] [blame] | 5944 | return VK_ERROR_INITIALIZATION_FAILED; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5945 | } |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5946 | return icd_term->dispatch.GetPhysicalDeviceImageFormatProperties(phys_dev_term->phys_dev, format, type, tiling, usage, flags, |
| 5947 | pImageFormatProperties); |
Jon Ashburn | 754864f | 2015-07-23 18:49:07 -0600 | [diff] [blame] | 5948 | } |
| 5949 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5950 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, |
| 5951 | VkImageType type, VkSampleCountFlagBits samples, |
| 5952 | VkImageUsageFlags usage, VkImageTiling tiling, |
| 5953 | uint32_t *pNumProperties, |
| 5954 | VkSparseImageFormatProperties *pProperties) { |
| 5955 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5956 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5957 | if (NULL != icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties) { |
| 5958 | icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties(phys_dev_term->phys_dev, format, type, samples, usage, |
| 5959 | tiling, pNumProperties, pProperties); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 5960 | } |
Mark Lobodzinski | 16e8bef | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 5961 | } |
| 5962 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5963 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 5964 | const char *pLayerName, uint32_t *pPropertyCount, |
| 5965 | VkExtensionProperties *pProperties) { |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5966 | struct loader_physical_device_term *phys_dev_term; |
Courtney Goeltzenleuchter | 499b3ba | 2015-02-27 15:19:33 -0700 | [diff] [blame] | 5967 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5968 | struct loader_layer_list implicit_layer_list = {0}; |
| 5969 | struct loader_extension_list all_exts = {0}; |
| 5970 | struct loader_extension_list icd_exts = {0}; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5971 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5972 | assert(pLayerName == NULL || strlen(pLayerName) == 0); |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 5973 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5974 | // Any layer or trampoline wrapping should be removed at this point in time can just cast to the expected |
| 5975 | // type for VkPhysicalDevice. |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5976 | phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5977 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5978 | // This case is during the call down the instance chain with pLayerName == NULL |
Mark Young | 0153e0b | 2016-11-03 14:27:13 -0600 | [diff] [blame] | 5979 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5980 | uint32_t icd_ext_count = *pPropertyCount; |
| 5981 | VkResult res; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5982 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5983 | // Get the available device extensions |
| 5984 | res = icd_term->dispatch.EnumerateDeviceExtensionProperties(phys_dev_term->phys_dev, NULL, &icd_ext_count, pProperties); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5985 | if (res != VK_SUCCESS) { |
| 5986 | goto out; |
| 5987 | } |
Jon Ashburn | 23d36b1 | 2016-02-02 17:47:28 -0700 | [diff] [blame] | 5988 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5989 | if (!loader_init_layer_list(icd_term->this_instance, &implicit_layer_list)) { |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 5990 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 5991 | goto out; |
| 5992 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 5993 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 5994 | loader_add_implicit_layers(icd_term->this_instance, &implicit_layer_list, NULL, &icd_term->this_instance->instance_layer_list); |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5995 | // We need to determine which implicit layers are active, and then add their extensions. This can't be cached as |
| 5996 | // it depends on results of environment variables (which can change). |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 5997 | if (pProperties != NULL) { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 5998 | // Initialize dev_extension list within the physicalDevice object |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 5999 | res = loader_init_device_extensions(icd_term->this_instance, phys_dev_term, icd_ext_count, pProperties, &icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6000 | if (res != VK_SUCCESS) { |
| 6001 | goto out; |
| 6002 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 6003 | |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 6004 | // We need to determine which implicit layers are active, and then add their extensions. This can't be cached as |
| 6005 | // it depends on results of environment variables (which can change). |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6006 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, icd_exts.count, icd_exts.list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6007 | if (res != VK_SUCCESS) { |
| 6008 | goto out; |
| 6009 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 6010 | |
Mark Young | 283fe1c | 2017-05-04 12:16:35 -0600 | [diff] [blame] | 6011 | loader_add_implicit_layers(icd_term->this_instance, &implicit_layer_list, NULL, |
| 6012 | &icd_term->this_instance->instance_layer_list); |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 6013 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6014 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6015 | for (uint32_t j = 0; j < implicit_layer_list.list[i].device_extension_list.count; j++) { |
| 6016 | res = loader_add_to_ext_list(icd_term->this_instance, &all_exts, 1, |
| 6017 | &implicit_layer_list.list[i].device_extension_list.list[j].props); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6018 | if (res != VK_SUCCESS) { |
| 6019 | goto out; |
| 6020 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 6021 | } |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 6022 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6023 | uint32_t capacity = *pPropertyCount; |
| 6024 | VkExtensionProperties *props = pProperties; |
Jon Ashburn | 471f44c | 2016-01-13 12:51:43 -0700 | [diff] [blame] | 6025 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6026 | for (uint32_t i = 0; i < all_exts.count && i < capacity; i++) { |
| 6027 | props[i] = all_exts.list[i]; |
| 6028 | } |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 6029 | |
| 6030 | // Wasn't enough space for the extensions, we did partial copy now return VK_INCOMPLETE |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6031 | if (capacity < all_exts.count) { |
| 6032 | res = VK_INCOMPLETE; |
| 6033 | } else { |
| 6034 | *pPropertyCount = all_exts.count; |
| 6035 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6036 | } else { |
Mark Young | 0f183a8 | 2017-02-28 09:58:04 -0700 | [diff] [blame] | 6037 | // Just return the count; need to add in the count of implicit layer extensions |
| 6038 | // don't worry about duplicates being added in the count |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6039 | *pPropertyCount = icd_ext_count; |
| 6040 | |
| 6041 | for (uint32_t i = 0; i < implicit_layer_list.count; i++) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6042 | *pPropertyCount += implicit_layer_list.list[i].device_extension_list.count; |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6043 | } |
| 6044 | res = VK_SUCCESS; |
Jon Ashburn | b82c185 | 2015-08-11 14:49:54 -0600 | [diff] [blame] | 6045 | } |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6046 | |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6047 | out: |
| 6048 | |
| 6049 | if (NULL != implicit_layer_list.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6050 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&implicit_layer_list); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6051 | } |
| 6052 | if (NULL != all_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6053 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&all_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6054 | } |
| 6055 | if (NULL != icd_exts.list) { |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6056 | loader_destroy_generic_list(icd_term->this_instance, (struct loader_generic_list *)&icd_exts); |
Mark Young | 3a58779 | 2016-08-19 15:25:08 -0600 | [diff] [blame] | 6057 | } |
| 6058 | |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6059 | return res; |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 6060 | } |
| 6061 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 6062 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, |
| 6063 | VkLayerProperties *pProperties) { |
| 6064 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 6065 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 6066 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6067 | "Encountered the vkEnumerateDeviceLayerProperties " |
| 6068 | "terminator. This means a layer improperly continued."); |
Mark Young | b639931 | 2017-01-10 14:22:15 -0700 | [diff] [blame] | 6069 | // Should never get here this call isn't dispatched down the chain |
Jon Ashburn | dc5d920 | 2016-02-29 13:00:51 -0700 | [diff] [blame] | 6070 | return VK_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 6071 | } |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6072 | |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 6073 | VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6074 | VkStringErrorFlags result = VK_STRING_ERROR_NONE; |
Karl Schultz | 2558bd3 | 2016-02-24 14:39:39 -0700 | [diff] [blame] | 6075 | int num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 6076 | int i, j; |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6077 | |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 6078 | for (i = 0; i <= max_length; i++) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6079 | if (utf8[i] == 0) { |
| 6080 | break; |
Courtney Goeltzenleuchter | 7a3486d | 2016-12-21 16:24:34 -0700 | [diff] [blame] | 6081 | } else if (i == max_length) { |
| 6082 | result |= VK_STRING_ERROR_LENGTH; |
| 6083 | break; |
Mark Lobodzinski | 36b4de2 | 2016-02-12 11:30:14 -0700 | [diff] [blame] | 6084 | } else if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6085 | num_char_bytes = 0; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 6086 | } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6087 | num_char_bytes = 1; |
Jon Ashburn | f2b4e38 | 2016-02-10 20:50:19 -0700 | [diff] [blame] | 6088 | } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) { |
Mark Lobodzinski | e9f09ef | 2016-02-02 18:53:34 -0700 | [diff] [blame] | 6089 | num_char_bytes = 2; |
| 6090 | } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) { |
| 6091 | num_char_bytes = 3; |
| 6092 | } else { |
| 6093 | result = VK_STRING_ERROR_BAD_DATA; |
| 6094 | } |
| 6095 | |
| 6096 | // Validate the following num_char_bytes of data |
| 6097 | for (j = 0; (j < num_char_bytes) && (i < max_length); j++) { |
| 6098 | if (++i == max_length) { |
| 6099 | result |= VK_STRING_ERROR_LENGTH; |
| 6100 | break; |
| 6101 | } |
| 6102 | if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) { |
| 6103 | result |= VK_STRING_ERROR_BAD_DATA; |
| 6104 | } |
| 6105 | } |
| 6106 | } |
| 6107 | return result; |
| 6108 | } |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 6109 | |
| 6110 | VKAPI_ATTR VkResult VKAPI_CALL |
Lenny Komow | 1658611 | 2018-02-13 15:58:47 -0700 | [diff] [blame] | 6111 | terminator_EnumerateInstanceVersion(const VkEnumerateInstanceVersionChain *chain, uint32_t* pApiVersion) { |
| 6112 | // NOTE: The Vulkan WG doesn't want us checking pApiVersion for NULL, but instead |
| 6113 | // prefers us crashing. |
| 6114 | *pApiVersion = VK_MAKE_VERSION(loader_major_version, loader_minor_version, 0); |
| 6115 | return VK_SUCCESS; |
| 6116 | } |
| 6117 | |
| 6118 | VKAPI_ATTR VkResult VKAPI_CALL |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 6119 | terminator_EnumerateInstanceExtensionProperties(const VkEnumerateInstanceExtensionPropertiesChain *chain, const char *pLayerName, |
| 6120 | uint32_t *pPropertyCount, VkExtensionProperties *pProperties) { |
| 6121 | struct loader_extension_list *global_ext_list = NULL; |
| 6122 | struct loader_layer_list instance_layers; |
| 6123 | struct loader_extension_list local_ext_list; |
| 6124 | struct loader_icd_tramp_list icd_tramp_list; |
| 6125 | uint32_t copy_size; |
| 6126 | VkResult res = VK_SUCCESS; |
| 6127 | |
| 6128 | // tls_instance = NULL; |
| 6129 | memset(&local_ext_list, 0, sizeof(local_ext_list)); |
| 6130 | memset(&instance_layers, 0, sizeof(instance_layers)); |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 6131 | |
| 6132 | // Get layer libraries if needed |
| 6133 | if (pLayerName && strlen(pLayerName) != 0) { |
| 6134 | if (vk_string_validate(MaxLoaderStringLength, pLayerName) != VK_STRING_ERROR_NONE) { |
| 6135 | assert(VK_FALSE && |
| 6136 | "vkEnumerateInstanceExtensionProperties: " |
| 6137 | "pLayerName is too long or is badly formed"); |
| 6138 | res = VK_ERROR_EXTENSION_NOT_PRESENT; |
| 6139 | goto out; |
| 6140 | } |
| 6141 | |
| 6142 | loader_layer_scan(NULL, &instance_layers); |
| 6143 | for (uint32_t i = 0; i < instance_layers.count; i++) { |
| 6144 | struct loader_layer_properties *props = &instance_layers.list[i]; |
| 6145 | if (strcmp(props->info.layerName, pLayerName) == 0) { |
| 6146 | global_ext_list = &props->instance_extension_list; |
| 6147 | break; |
| 6148 | } |
| 6149 | } |
| 6150 | } else { |
| 6151 | // Scan/discover all ICD libraries |
| 6152 | memset(&icd_tramp_list, 0, sizeof(icd_tramp_list)); |
| 6153 | res = loader_icd_scan(NULL, &icd_tramp_list); |
| 6154 | if (VK_SUCCESS != res) { |
| 6155 | goto out; |
| 6156 | } |
| 6157 | // Get extensions from all ICD's, merge so no duplicates |
| 6158 | res = loader_get_icd_loader_instance_extensions(NULL, &icd_tramp_list, &local_ext_list); |
| 6159 | if (VK_SUCCESS != res) { |
| 6160 | goto out; |
| 6161 | } |
| 6162 | loader_scanned_icd_clear(NULL, &icd_tramp_list); |
| 6163 | |
| 6164 | // Append enabled implicit layers. |
| 6165 | loader_implicit_layer_scan(NULL, &instance_layers); |
| 6166 | for (uint32_t i = 0; i < instance_layers.count; i++) { |
| 6167 | if (!loader_is_implicit_layer_enabled(NULL, &instance_layers.list[i])) { |
| 6168 | continue; |
| 6169 | } |
| 6170 | struct loader_extension_list *ext_list = &instance_layers.list[i].instance_extension_list; |
| 6171 | loader_add_to_ext_list(NULL, &local_ext_list, ext_list->count, ext_list->list); |
| 6172 | } |
| 6173 | |
| 6174 | global_ext_list = &local_ext_list; |
| 6175 | } |
| 6176 | |
| 6177 | if (global_ext_list == NULL) { |
| 6178 | res = VK_ERROR_LAYER_NOT_PRESENT; |
| 6179 | goto out; |
| 6180 | } |
| 6181 | |
| 6182 | if (pProperties == NULL) { |
| 6183 | *pPropertyCount = global_ext_list->count; |
| 6184 | goto out; |
| 6185 | } |
| 6186 | |
| 6187 | copy_size = *pPropertyCount < global_ext_list->count ? *pPropertyCount : global_ext_list->count; |
| 6188 | for (uint32_t i = 0; i < copy_size; i++) { |
| 6189 | memcpy(&pProperties[i], &global_ext_list->list[i], sizeof(VkExtensionProperties)); |
| 6190 | } |
| 6191 | *pPropertyCount = copy_size; |
| 6192 | |
| 6193 | if (copy_size < global_ext_list->count) { |
| 6194 | res = VK_INCOMPLETE; |
| 6195 | goto out; |
| 6196 | } |
| 6197 | |
| 6198 | out: |
| 6199 | |
| 6200 | loader_destroy_generic_list(NULL, (struct loader_generic_list *)&local_ext_list); |
| 6201 | loader_delete_layer_properties(NULL, &instance_layers); |
| 6202 | return res; |
| 6203 | } |
| 6204 | |
| 6205 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateInstanceLayerProperties(const VkEnumerateInstanceLayerPropertiesChain *chain, |
| 6206 | uint32_t *pPropertyCount, |
| 6207 | VkLayerProperties *pProperties) { |
| 6208 | VkResult result = VK_SUCCESS; |
| 6209 | struct loader_layer_list instance_layer_list; |
| 6210 | tls_instance = NULL; |
| 6211 | |
Lenny Komow | 2334298 | 2018-01-19 11:22:28 -0700 | [diff] [blame] | 6212 | LOADER_PLATFORM_THREAD_ONCE(&once_init, loader_initialize); |
| 6213 | |
Lenny Komow | 3cf3ac7 | 2017-12-19 16:38:37 -0700 | [diff] [blame] | 6214 | uint32_t copy_size; |
| 6215 | |
| 6216 | // Get layer libraries |
| 6217 | memset(&instance_layer_list, 0, sizeof(instance_layer_list)); |
| 6218 | loader_layer_scan(NULL, &instance_layer_list); |
| 6219 | |
| 6220 | if (pProperties == NULL) { |
| 6221 | *pPropertyCount = instance_layer_list.count; |
| 6222 | goto out; |
| 6223 | } |
| 6224 | |
| 6225 | copy_size = (*pPropertyCount < instance_layer_list.count) ? *pPropertyCount : instance_layer_list.count; |
| 6226 | for (uint32_t i = 0; i < copy_size; i++) { |
| 6227 | memcpy(&pProperties[i], &instance_layer_list.list[i].info, sizeof(VkLayerProperties)); |
| 6228 | } |
| 6229 | |
| 6230 | *pPropertyCount = copy_size; |
| 6231 | |
| 6232 | if (copy_size < instance_layer_list.count) { |
| 6233 | result = VK_INCOMPLETE; |
| 6234 | goto out; |
| 6235 | } |
| 6236 | |
| 6237 | out: |
| 6238 | |
| 6239 | loader_delete_layer_properties(NULL, &instance_layer_list); |
| 6240 | return result; |
| 6241 | } |
Lenny Komow | 158e9d9 | 2018-01-15 15:43:36 -0700 | [diff] [blame] | 6242 | |
Lenny Komow | 2334298 | 2018-01-19 11:22:28 -0700 | [diff] [blame] | 6243 | #if defined(_WIN32) && defined(LOADER_DYNAMIC_LIB) |
Lenny Komow | 158e9d9 | 2018-01-15 15:43:36 -0700 | [diff] [blame] | 6244 | BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { |
| 6245 | switch (reason) { |
| 6246 | case DLL_PROCESS_ATTACH: |
| 6247 | loader_initialize(); |
| 6248 | break; |
| 6249 | case DLL_PROCESS_DETACH: |
| 6250 | if (NULL == reserved) { |
| 6251 | loader_release(); |
| 6252 | } |
| 6253 | break; |
| 6254 | default: |
| 6255 | // Do nothing |
| 6256 | break; |
| 6257 | } |
| 6258 | return TRUE; |
| 6259 | } |
Lenny Komow | 2334298 | 2018-01-19 11:22:28 -0700 | [diff] [blame] | 6260 | #elif !defined(_WIN32) |
Lenny Komow | 158e9d9 | 2018-01-15 15:43:36 -0700 | [diff] [blame] | 6261 | __attribute__((constructor)) void loader_init_library() { loader_initialize(); } |
| 6262 | |
| 6263 | __attribute__((destructor)) void loader_free_library() { loader_release(); } |
| 6264 | #endif |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6265 | |
| 6266 | // ---- Vulkan Core 1.1 terminators |
| 6267 | |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6268 | VkResult setupLoaderTermPhysDevGroups(struct loader_instance *inst) { |
| 6269 | VkResult res = VK_SUCCESS; |
| 6270 | struct loader_icd_term *icd_term; |
| 6271 | uint32_t total_count = 0; |
| 6272 | uint32_t cur_icd_group_count = 0; |
| 6273 | VkPhysicalDeviceGroupPropertiesKHR **new_phys_dev_groups = NULL; |
| 6274 | VkPhysicalDeviceGroupPropertiesKHR *local_phys_dev_groups = NULL; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6275 | PFN_vkEnumeratePhysicalDeviceGroups fpEnumeratePhysicalDeviceGroups = NULL; |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6276 | |
| 6277 | if (0 == inst->phys_dev_count_term) { |
| 6278 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6279 | "setupLoaderTermPhysDevGroups: Loader failed to setup physical " |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6280 | "device terminator info before calling \'EnumeratePhysicalDeviceGroups\'."); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6281 | assert(false); |
| 6282 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 6283 | goto out; |
| 6284 | } |
| 6285 | |
| 6286 | // For each ICD, query the number of physical device groups, and then get an |
| 6287 | // internal value for those physical devices. |
| 6288 | icd_term = inst->icd_terms; |
| 6289 | for (uint32_t icd_idx = 0; NULL != icd_term; icd_term = icd_term->next, icd_idx++) { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6290 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6291 | if (inst->enabled_known_extensions.khr_device_group_creation) { |
| 6292 | fpEnumeratePhysicalDeviceGroups = icd_term->dispatch.EnumeratePhysicalDeviceGroupsKHR; |
| 6293 | } else { |
| 6294 | fpEnumeratePhysicalDeviceGroups = icd_term->dispatch.EnumeratePhysicalDeviceGroups; |
| 6295 | } |
| 6296 | |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6297 | cur_icd_group_count = 0; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6298 | if (NULL == fpEnumeratePhysicalDeviceGroups) { |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6299 | // Treat each ICD's GPU as it's own group if the extension isn't supported |
| 6300 | res = icd_term->dispatch.EnumeratePhysicalDevices(icd_term->instance, &cur_icd_group_count, NULL); |
| 6301 | if (res != VK_SUCCESS) { |
| 6302 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6303 | "setupLoaderTermPhysDevGroups: Failed during dispatch call of " |
| 6304 | "\'EnumeratePhysicalDevices\' to ICD %d to get plain phys dev count.", |
| 6305 | icd_idx); |
| 6306 | goto out; |
| 6307 | } |
| 6308 | } else { |
| 6309 | // Query the actual group info |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6310 | res = fpEnumeratePhysicalDeviceGroups(icd_term->instance, &cur_icd_group_count, NULL); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6311 | if (res != VK_SUCCESS) { |
| 6312 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6313 | "setupLoaderTermPhysDevGroups: Failed during dispatch call of " |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6314 | "\'EnumeratePhysicalDeviceGroups\' to ICD %d to get count.", |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6315 | icd_idx); |
| 6316 | goto out; |
| 6317 | } |
| 6318 | } |
| 6319 | total_count += cur_icd_group_count; |
| 6320 | } |
| 6321 | |
| 6322 | // Create an array for the new physical device groups, which will be stored |
| 6323 | // in the instance for the Terminator code. |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6324 | new_phys_dev_groups = (VkPhysicalDeviceGroupProperties **)loader_instance_heap_alloc( |
| 6325 | inst, total_count * sizeof(VkPhysicalDeviceGroupProperties *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6326 | if (NULL == new_phys_dev_groups) { |
| 6327 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6328 | "setupLoaderTermPhysDevGroups: Failed to allocate new physical device" |
| 6329 | " group array of size %d", |
| 6330 | total_count); |
| 6331 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 6332 | goto out; |
| 6333 | } |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6334 | memset(new_phys_dev_groups, 0, total_count * sizeof(VkPhysicalDeviceGroupProperties *)); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6335 | |
| 6336 | // Create a temporary array (on the stack) to keep track of the |
| 6337 | // returned VkPhysicalDevice values. |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6338 | local_phys_dev_groups = loader_stack_alloc(sizeof(VkPhysicalDeviceGroupProperties) * total_count); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6339 | if (NULL == local_phys_dev_groups) { |
| 6340 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6341 | "setupLoaderTermPhysDevGroups: Failed to allocate local " |
| 6342 | "physical device group array of size %d", |
| 6343 | total_count); |
| 6344 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 6345 | goto out; |
| 6346 | } |
| 6347 | // Initialize the memory to something valid |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6348 | memset(local_phys_dev_groups, 0, sizeof(VkPhysicalDeviceGroupProperties) * total_count); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6349 | for (uint32_t group = 0; group < total_count; group++) { |
| 6350 | local_phys_dev_groups[group].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES_KHR; |
| 6351 | local_phys_dev_groups[group].pNext = NULL; |
| 6352 | local_phys_dev_groups[group].subsetAllocation = false; |
| 6353 | } |
| 6354 | |
| 6355 | cur_icd_group_count = 0; |
| 6356 | icd_term = inst->icd_terms; |
| 6357 | for (uint32_t icd_idx = 0; NULL != icd_term; icd_term = icd_term->next, icd_idx++) { |
| 6358 | uint32_t count_this_time = total_count - cur_icd_group_count; |
| 6359 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6360 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6361 | if (inst->enabled_known_extensions.khr_device_group_creation) { |
| 6362 | fpEnumeratePhysicalDeviceGroups = icd_term->dispatch.EnumeratePhysicalDeviceGroupsKHR; |
| 6363 | } else { |
| 6364 | fpEnumeratePhysicalDeviceGroups = icd_term->dispatch.EnumeratePhysicalDeviceGroups; |
| 6365 | } |
| 6366 | |
| 6367 | if (NULL == fpEnumeratePhysicalDeviceGroups) { |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6368 | VkPhysicalDevice* phys_dev_array = loader_stack_alloc(sizeof(VkPhysicalDevice) * count_this_time); |
| 6369 | if (NULL == phys_dev_array) { |
| 6370 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6371 | "setupLoaderTermPhysDevGroups: Failed to allocate local " |
| 6372 | "physical device array of size %d", |
| 6373 | count_this_time); |
| 6374 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 6375 | goto out; |
| 6376 | } |
| 6377 | |
| 6378 | res = icd_term->dispatch.EnumeratePhysicalDevices(icd_term->instance, &count_this_time, phys_dev_array); |
| 6379 | if (res != VK_SUCCESS) { |
| 6380 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6381 | "setupLoaderTermPhysDevGroups: Failed during dispatch call of " |
| 6382 | "\'EnumeratePhysicalDevices\' to ICD %d to get plain phys dev count.", |
| 6383 | icd_idx); |
| 6384 | goto out; |
| 6385 | } |
| 6386 | |
| 6387 | // Add each GPU as it's own group |
| 6388 | for (uint32_t indiv_gpu = 0; indiv_gpu < count_this_time; indiv_gpu++) { |
| 6389 | local_phys_dev_groups[indiv_gpu + cur_icd_group_count].physicalDeviceCount = 1; |
| 6390 | local_phys_dev_groups[indiv_gpu + cur_icd_group_count].physicalDevices[0] = phys_dev_array[indiv_gpu]; |
| 6391 | } |
| 6392 | |
| 6393 | } else { |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6394 | res = fpEnumeratePhysicalDeviceGroups(icd_term->instance, &count_this_time, &local_phys_dev_groups[cur_icd_group_count]); |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6395 | if (VK_SUCCESS != res) { |
| 6396 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6397 | "setupLoaderTermPhysDevGroups: Failed during dispatch call of " |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6398 | "\'EnumeratePhysicalDeviceGroups\' to ICD %d to get content.", |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6399 | icd_idx); |
| 6400 | goto out; |
| 6401 | } |
| 6402 | } |
| 6403 | |
| 6404 | cur_icd_group_count += count_this_time; |
| 6405 | } |
| 6406 | |
| 6407 | // Replace all the physical device IDs with the proper loader values |
| 6408 | for (uint32_t group = 0; group < total_count; group++) { |
| 6409 | for (uint32_t group_gpu = 0; group_gpu < local_phys_dev_groups[group].physicalDeviceCount; group_gpu++) { |
| 6410 | bool found = false; |
| 6411 | for (uint32_t term_gpu = 0; term_gpu < inst->phys_dev_count_term; term_gpu++) { |
| 6412 | if (local_phys_dev_groups[group].physicalDevices[group_gpu] == inst->phys_devs_term[term_gpu]->phys_dev) { |
| 6413 | local_phys_dev_groups[group].physicalDevices[group_gpu] = (VkPhysicalDevice)inst->phys_devs_term[term_gpu]; |
| 6414 | found = true; |
| 6415 | break; |
| 6416 | } |
| 6417 | } |
| 6418 | if (!found) { |
| 6419 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6420 | "setupLoaderTermPhysDevGroups: Failed to find GPU %d in group %d" |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6421 | " returned by \'EnumeratePhysicalDeviceGroups\' in list returned" |
Lenny Komow | 76f0f73 | 2017-10-02 15:58:17 -0600 | [diff] [blame] | 6422 | " by \'EnumeratePhysicalDevices\'", group_gpu, group); |
| 6423 | res = VK_ERROR_INITIALIZATION_FAILED; |
| 6424 | goto out; |
| 6425 | } |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | // Copy or create everything to fill the new array of physical device groups |
| 6430 | for (uint32_t new_idx = 0; new_idx < total_count; new_idx++) { |
| 6431 | // Check if this physical device group with the same contents is already in the old buffer |
| 6432 | for (uint32_t old_idx = 0; old_idx < inst->phys_dev_group_count_term; old_idx++) { |
| 6433 | if (local_phys_dev_groups[new_idx].physicalDeviceCount == inst->phys_dev_groups_term[old_idx]->physicalDeviceCount) { |
| 6434 | bool found_all_gpus = true; |
| 6435 | for (uint32_t old_gpu = 0; old_gpu < inst->phys_dev_groups_term[old_idx]->physicalDeviceCount; old_gpu++) { |
| 6436 | bool found_gpu = false; |
| 6437 | for (uint32_t new_gpu = 0; new_gpu < local_phys_dev_groups[new_idx].physicalDeviceCount; new_gpu++) { |
| 6438 | if (local_phys_dev_groups[new_idx].physicalDevices[new_gpu] == inst->phys_dev_groups_term[old_idx]->physicalDevices[old_gpu]) { |
| 6439 | found_gpu = true; |
| 6440 | break; |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | if (!found_gpu) { |
| 6445 | found_all_gpus = false; |
| 6446 | break; |
| 6447 | } |
| 6448 | } |
| 6449 | if (!found_all_gpus) { |
| 6450 | continue; |
| 6451 | } else { |
| 6452 | new_phys_dev_groups[new_idx] = inst->phys_dev_groups_term[old_idx]; |
| 6453 | break; |
| 6454 | } |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | // If this physical device group isn't in the old buffer, create it |
| 6459 | if (NULL == new_phys_dev_groups[new_idx]) { |
| 6460 | new_phys_dev_groups[new_idx] = (VkPhysicalDeviceGroupPropertiesKHR *)loader_instance_heap_alloc( |
| 6461 | inst, sizeof(VkPhysicalDeviceGroupPropertiesKHR), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
| 6462 | if (NULL == new_phys_dev_groups[new_idx]) { |
| 6463 | loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
| 6464 | "setupLoaderTermPhysDevGroups: Failed to allocate " |
| 6465 | "physical device group Terminator object %d", |
| 6466 | new_idx); |
| 6467 | total_count = new_idx; |
| 6468 | res = VK_ERROR_OUT_OF_HOST_MEMORY; |
| 6469 | goto out; |
| 6470 | } |
| 6471 | memcpy(new_phys_dev_groups[new_idx], &local_phys_dev_groups[new_idx], |
| 6472 | sizeof(VkPhysicalDeviceGroupPropertiesKHR)); |
| 6473 | } |
| 6474 | } |
| 6475 | |
| 6476 | out: |
| 6477 | |
| 6478 | if (VK_SUCCESS != res) { |
| 6479 | if (NULL != new_phys_dev_groups) { |
| 6480 | for (uint32_t i = 0; i < total_count; i++) { |
| 6481 | loader_instance_heap_free(inst, new_phys_dev_groups[i]); |
| 6482 | } |
| 6483 | loader_instance_heap_free(inst, new_phys_dev_groups); |
| 6484 | } |
| 6485 | total_count = 0; |
| 6486 | } else { |
| 6487 | // Free everything that didn't carry over to the new array of |
| 6488 | // physical device groups |
| 6489 | if (NULL != inst->phys_dev_groups_term) { |
| 6490 | for (uint32_t i = 0; i < inst->phys_dev_group_count_term; i++) { |
| 6491 | bool found = false; |
| 6492 | for (uint32_t j = 0; j < total_count; j++) { |
| 6493 | if (inst->phys_dev_groups_term[i] == new_phys_dev_groups[j]) { |
| 6494 | found = true; |
| 6495 | break; |
| 6496 | } |
| 6497 | } |
| 6498 | if (!found) { |
| 6499 | loader_instance_heap_free(inst, inst->phys_dev_groups_term[i]); |
| 6500 | } |
| 6501 | } |
| 6502 | loader_instance_heap_free(inst, inst->phys_dev_groups_term); |
| 6503 | } |
| 6504 | |
| 6505 | // Swap in the new physical device group list |
| 6506 | inst->phys_dev_group_count_term = total_count; |
| 6507 | inst->phys_dev_groups_term = new_phys_dev_groups; |
| 6508 | } |
| 6509 | |
| 6510 | return res; |
| 6511 | } |
| 6512 | |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6513 | VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDeviceGroups( |
| 6514 | VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, |
| 6515 | VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) { |
| 6516 | struct loader_instance *inst = (struct loader_instance *)instance; |
| 6517 | VkResult res = VK_SUCCESS; |
| 6518 | |
| 6519 | // Always call the setup loader terminator physical device groups because they may |
| 6520 | // have changed at any point. |
| 6521 | res = setupLoaderTermPhysDevGroups(inst); |
| 6522 | if (VK_SUCCESS != res) { |
| 6523 | goto out; |
| 6524 | } |
| 6525 | |
| 6526 | uint32_t copy_count = inst->phys_dev_group_count_term; |
| 6527 | if (NULL != pPhysicalDeviceGroupProperties) { |
| 6528 | if (copy_count > *pPhysicalDeviceGroupCount) { |
| 6529 | copy_count = *pPhysicalDeviceGroupCount; |
| 6530 | res = VK_INCOMPLETE; |
| 6531 | } |
| 6532 | |
| 6533 | for (uint32_t i = 0; i < copy_count; i++) { |
| 6534 | memcpy(&pPhysicalDeviceGroupProperties[i], inst->phys_dev_groups_term[i], |
| 6535 | sizeof(VkPhysicalDeviceGroupPropertiesKHR)); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | *pPhysicalDeviceGroupCount = copy_count; |
| 6540 | |
| 6541 | out: |
| 6542 | |
| 6543 | return res; |
| 6544 | } |
| 6545 | |
| 6546 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, |
| 6547 | VkPhysicalDeviceFeatures2 *pFeatures) { |
| 6548 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6549 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6550 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6551 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6552 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6553 | PFN_vkGetPhysicalDeviceFeatures2 fpGetPhysicalDeviceFeatures2 = NULL; |
| 6554 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6555 | fpGetPhysicalDeviceFeatures2 = icd_term->dispatch.GetPhysicalDeviceFeatures2KHR; |
| 6556 | } else { |
| 6557 | fpGetPhysicalDeviceFeatures2 = icd_term->dispatch.GetPhysicalDeviceFeatures2; |
| 6558 | } |
| 6559 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6560 | if (fpGetPhysicalDeviceFeatures2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6561 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6562 | fpGetPhysicalDeviceFeatures2(phys_dev_term->phys_dev, pFeatures); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6563 | } else { |
| 6564 | // Emulate the call |
| 6565 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6566 | "vkGetPhysicalDeviceFeatures2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceFeatures", |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6567 | icd_term->scanned_icd->lib_name); |
| 6568 | |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6569 | // Write to the VkPhysicalDeviceFeatures2 struct |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6570 | icd_term->dispatch.GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, &pFeatures->features); |
| 6571 | |
| 6572 | void *pNext = pFeatures->pNext; |
| 6573 | while (pNext != NULL) { |
| 6574 | switch (*(VkStructureType *)pNext) { |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6575 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6576 | // Skip the check if VK_KHR_multiview is enabled because it's a device extension |
| 6577 | // Write to the VkPhysicalDeviceMultiviewFeaturesKHR struct |
| 6578 | VkPhysicalDeviceMultiviewFeaturesKHR *multiview_features = pNext; |
| 6579 | multiview_features->multiview = VK_FALSE; |
| 6580 | multiview_features->multiviewGeometryShader = VK_FALSE; |
| 6581 | multiview_features->multiviewTessellationShader = VK_FALSE; |
| 6582 | |
| 6583 | pNext = multiview_features->pNext; |
| 6584 | break; |
| 6585 | } |
| 6586 | default: { |
| 6587 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6588 | "vkGetPhysicalDeviceFeatures2: Emulation found unrecognized structure type in pFeatures->pNext - " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6589 | "this struct will be ignored"); |
| 6590 | |
| 6591 | struct VkStructureHeader *header = pNext; |
| 6592 | pNext = (void *)header->pNext; |
| 6593 | break; |
| 6594 | } |
| 6595 | } |
| 6596 | } |
| 6597 | } |
| 6598 | } |
| 6599 | |
| 6600 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, |
| 6601 | VkPhysicalDeviceProperties2 *pProperties) { |
| 6602 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6603 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6604 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6605 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6606 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6607 | PFN_vkGetPhysicalDeviceProperties2 fpGetPhysicalDeviceProperties2 = NULL; |
| 6608 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6609 | fpGetPhysicalDeviceProperties2 = icd_term->dispatch.GetPhysicalDeviceProperties2KHR; |
| 6610 | } else { |
| 6611 | fpGetPhysicalDeviceProperties2 = icd_term->dispatch.GetPhysicalDeviceProperties2; |
| 6612 | } |
| 6613 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6614 | if (fpGetPhysicalDeviceProperties2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6615 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6616 | fpGetPhysicalDeviceProperties2(phys_dev_term->phys_dev, pProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6617 | } else { |
| 6618 | // Emulate the call |
| 6619 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6620 | "vkGetPhysicalDeviceProperties2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceProperties", |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6621 | icd_term->scanned_icd->lib_name); |
| 6622 | |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6623 | // Write to the VkPhysicalDeviceProperties2 struct |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6624 | icd_term->dispatch.GetPhysicalDeviceProperties(phys_dev_term->phys_dev, &pProperties->properties); |
| 6625 | |
| 6626 | void *pNext = pProperties->pNext; |
| 6627 | while (pNext != NULL) { |
| 6628 | switch (*(VkStructureType *)pNext) { |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6629 | case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6630 | VkPhysicalDeviceIDPropertiesKHR *id_properties = pNext; |
| 6631 | |
| 6632 | // Verify that "VK_KHR_external_memory_capabilities" is enabled |
| 6633 | if (icd_term->this_instance->enabled_known_extensions.khr_external_memory_capabilities) { |
| 6634 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6635 | "vkGetPhysicalDeviceProperties2: Emulation cannot generate unique IDs for struct " |
| 6636 | "VkPhysicalDeviceIDProperties - setting IDs to zero instead"); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6637 | |
| 6638 | // Write to the VkPhysicalDeviceIDPropertiesKHR struct |
| 6639 | memset(id_properties->deviceUUID, 0, VK_UUID_SIZE); |
| 6640 | memset(id_properties->driverUUID, 0, VK_UUID_SIZE); |
| 6641 | id_properties->deviceLUIDValid = VK_FALSE; |
| 6642 | } |
| 6643 | |
| 6644 | pNext = id_properties->pNext; |
| 6645 | break; |
| 6646 | } |
| 6647 | default: { |
| 6648 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
| 6649 | "vkGetPhysicalDeviceProperties2KHR: Emulation found unrecognized structure type in " |
| 6650 | "pProperties->pNext - this struct will be ignored"); |
| 6651 | |
| 6652 | struct VkStructureHeader *header = pNext; |
| 6653 | pNext = (void *)header->pNext; |
| 6654 | break; |
| 6655 | } |
| 6656 | } |
| 6657 | } |
| 6658 | } |
| 6659 | } |
| 6660 | |
| 6661 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format, |
| 6662 | VkFormatProperties2 *pFormatProperties) { |
| 6663 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6664 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6665 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6666 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6667 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6668 | PFN_vkGetPhysicalDeviceFormatProperties2 fpGetPhysicalDeviceFormatProperties2 = NULL; |
| 6669 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6670 | fpGetPhysicalDeviceFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceFormatProperties2KHR; |
| 6671 | } else { |
| 6672 | fpGetPhysicalDeviceFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceFormatProperties2; |
| 6673 | } |
| 6674 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6675 | if (fpGetPhysicalDeviceFormatProperties2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6676 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6677 | fpGetPhysicalDeviceFormatProperties2(phys_dev_term->phys_dev, format, pFormatProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6678 | } else { |
| 6679 | // Emulate the call |
| 6680 | loader_log( |
| 6681 | icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6682 | "vkGetPhysicalDeviceFormatProperties2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceFormatProperties", |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6683 | icd_term->scanned_icd->lib_name); |
| 6684 | |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6685 | // Write to the VkFormatProperties2 struct |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6686 | icd_term->dispatch.GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, format, &pFormatProperties->formatProperties); |
| 6687 | |
| 6688 | if (pFormatProperties->pNext != NULL) { |
| 6689 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6690 | "vkGetPhysicalDeviceFormatProperties2: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6691 | "pFormatProperties->pNext - this struct will be ignored"); |
| 6692 | } |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceImageFormatProperties2( |
| 6697 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2KHR *pImageFormatInfo, |
| 6698 | VkImageFormatProperties2KHR *pImageFormatProperties) { |
| 6699 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6700 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6701 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6702 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6703 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6704 | PFN_vkGetPhysicalDeviceImageFormatProperties2 fpGetPhysicalDeviceImageFormatProperties2 = NULL; |
| 6705 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6706 | fpGetPhysicalDeviceImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceImageFormatProperties2KHR; |
| 6707 | } else { |
| 6708 | fpGetPhysicalDeviceImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceImageFormatProperties2; |
| 6709 | } |
| 6710 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6711 | if (fpGetPhysicalDeviceImageFormatProperties2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6712 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6713 | return fpGetPhysicalDeviceImageFormatProperties2(phys_dev_term->phys_dev, pImageFormatInfo, pImageFormatProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6714 | } else { |
| 6715 | // Emulate the call |
| 6716 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6717 | "vkGetPhysicalDeviceImageFormatProperties2: Emulating call in ICD \"%s\" using " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6718 | "vkGetPhysicalDeviceImageFormatProperties", |
| 6719 | icd_term->scanned_icd->lib_name); |
| 6720 | |
| 6721 | // If there is more info in either pNext, then this is unsupported |
| 6722 | if (pImageFormatInfo->pNext != NULL || pImageFormatProperties->pNext != NULL) { |
| 6723 | return VK_ERROR_FORMAT_NOT_SUPPORTED; |
| 6724 | } |
| 6725 | |
| 6726 | // Write to the VkImageFormatProperties2KHR struct |
| 6727 | return icd_term->dispatch.GetPhysicalDeviceImageFormatProperties( |
| 6728 | phys_dev_term->phys_dev, pImageFormatInfo->format, pImageFormatInfo->type, pImageFormatInfo->tiling, |
| 6729 | pImageFormatInfo->usage, pImageFormatInfo->flags, &pImageFormatProperties->imageFormatProperties); |
| 6730 | } |
| 6731 | } |
| 6732 | |
| 6733 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties2( |
| 6734 | VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties) { |
| 6735 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6736 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6737 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6738 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6739 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6740 | PFN_vkGetPhysicalDeviceQueueFamilyProperties2 fpGetPhysicalDeviceQueueFamilyProperties2 = NULL; |
| 6741 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6742 | fpGetPhysicalDeviceQueueFamilyProperties2 = icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties2KHR; |
| 6743 | } else { |
| 6744 | fpGetPhysicalDeviceQueueFamilyProperties2 = icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties2; |
| 6745 | } |
| 6746 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6747 | if (fpGetPhysicalDeviceQueueFamilyProperties2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6748 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6749 | fpGetPhysicalDeviceQueueFamilyProperties2(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pQueueFamilyProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6750 | } else { |
| 6751 | // Emulate the call |
| 6752 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6753 | "vkGetPhysicalDeviceQueueFamilyProperties2: Emulating call in ICD \"%s\" using " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6754 | "vkGetPhysicalDeviceQueueFamilyProperties", |
| 6755 | icd_term->scanned_icd->lib_name); |
| 6756 | |
| 6757 | if (pQueueFamilyProperties == NULL || *pQueueFamilyPropertyCount == 0) { |
| 6758 | // Write to pQueueFamilyPropertyCount |
| 6759 | icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, NULL); |
| 6760 | } else { |
| 6761 | // Allocate a temporary array for the output of the old function |
| 6762 | VkQueueFamilyProperties *properties = loader_stack_alloc(*pQueueFamilyPropertyCount * sizeof(VkQueueFamilyProperties)); |
| 6763 | if (properties == NULL) { |
| 6764 | *pQueueFamilyPropertyCount = 0; |
| 6765 | loader_log( |
| 6766 | icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6767 | "vkGetPhysicalDeviceQueueFamilyProperties2: Out of memory - Failed to allocate array for loader emulation."); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6768 | return; |
| 6769 | } |
| 6770 | |
| 6771 | icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, |
| 6772 | properties); |
| 6773 | for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) { |
| 6774 | // Write to the VkQueueFamilyProperties2KHR struct |
| 6775 | memcpy(&pQueueFamilyProperties[i].queueFamilyProperties, &properties[i], sizeof(VkQueueFamilyProperties)); |
| 6776 | |
| 6777 | if (pQueueFamilyProperties[i].pNext != NULL) { |
| 6778 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6779 | "vkGetPhysicalDeviceQueueFamilyProperties2: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6780 | "pQueueFamilyProperties[%d].pNext - this struct will be ignored", |
| 6781 | i); |
| 6782 | } |
| 6783 | } |
| 6784 | } |
| 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties2( |
| 6789 | VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2 *pMemoryProperties) { |
| 6790 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6791 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6792 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6793 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6794 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6795 | PFN_vkGetPhysicalDeviceMemoryProperties2 fpGetPhysicalDeviceMemoryProperties2 = NULL; |
| 6796 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6797 | fpGetPhysicalDeviceMemoryProperties2 = icd_term->dispatch.GetPhysicalDeviceMemoryProperties2KHR; |
| 6798 | } else { |
| 6799 | fpGetPhysicalDeviceMemoryProperties2 = icd_term->dispatch.GetPhysicalDeviceMemoryProperties2; |
| 6800 | } |
| 6801 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6802 | if (fpGetPhysicalDeviceMemoryProperties2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6803 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6804 | fpGetPhysicalDeviceMemoryProperties2(phys_dev_term->phys_dev, pMemoryProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6805 | } else { |
| 6806 | // Emulate the call |
| 6807 | loader_log( |
| 6808 | icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6809 | "vkGetPhysicalDeviceMemoryProperties2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceMemoryProperties", |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6810 | icd_term->scanned_icd->lib_name); |
| 6811 | |
| 6812 | // Write to the VkPhysicalDeviceMemoryProperties2 struct |
| 6813 | icd_term->dispatch.GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, &pMemoryProperties->memoryProperties); |
| 6814 | |
| 6815 | if (pMemoryProperties->pNext != NULL) { |
| 6816 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6817 | "vkGetPhysicalDeviceMemoryProperties2: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6818 | "pMemoryProperties->pNext - this struct will be ignored"); |
| 6819 | } |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceSparseImageFormatProperties2( |
| 6824 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2KHR *pFormatInfo, uint32_t *pPropertyCount, |
| 6825 | VkSparseImageFormatProperties2KHR *pProperties) { |
| 6826 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6827 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6828 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6829 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6830 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6831 | PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 fpGetPhysicalDeviceSparseImageFormatProperties2 = NULL; |
| 6832 | if (inst != NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
| 6833 | fpGetPhysicalDeviceSparseImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties2KHR; |
| 6834 | } else { |
| 6835 | fpGetPhysicalDeviceSparseImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties2; |
| 6836 | } |
| 6837 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6838 | if (fpGetPhysicalDeviceSparseImageFormatProperties2 != NULL || !inst->enabled_known_extensions.khr_get_physical_device_properties2) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6839 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6840 | fpGetPhysicalDeviceSparseImageFormatProperties2(phys_dev_term->phys_dev, pFormatInfo, pPropertyCount, pProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6841 | } else { |
| 6842 | // Emulate the call |
| 6843 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6844 | "vkGetPhysicalDeviceSparseImageFormatProperties2: Emulating call in ICD \"%s\" using " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6845 | "vkGetPhysicalDeviceSparseImageFormatProperties", |
| 6846 | icd_term->scanned_icd->lib_name); |
| 6847 | |
| 6848 | if (pFormatInfo->pNext != NULL) { |
| 6849 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6850 | "vkGetPhysicalDeviceSparseImageFormatProperties2: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6851 | "pFormatInfo->pNext - this struct will be ignored"); |
| 6852 | } |
| 6853 | |
| 6854 | if (pProperties == NULL || *pPropertyCount == 0) { |
| 6855 | // Write to pPropertyCount |
| 6856 | icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties( |
| 6857 | phys_dev_term->phys_dev, pFormatInfo->format, pFormatInfo->type, pFormatInfo->samples, pFormatInfo->usage, |
| 6858 | pFormatInfo->tiling, pPropertyCount, NULL); |
| 6859 | } else { |
| 6860 | // Allocate a temporary array for the output of the old function |
| 6861 | VkSparseImageFormatProperties *properties = |
| 6862 | loader_stack_alloc(*pPropertyCount * sizeof(VkSparseImageMemoryRequirements)); |
| 6863 | if (properties == NULL) { |
| 6864 | *pPropertyCount = 0; |
| 6865 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6866 | "vkGetPhysicalDeviceSparseImageFormatProperties2: Out of memory - Failed to allocate array for " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6867 | "loader emulation."); |
| 6868 | return; |
| 6869 | } |
| 6870 | |
| 6871 | icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties( |
| 6872 | phys_dev_term->phys_dev, pFormatInfo->format, pFormatInfo->type, pFormatInfo->samples, pFormatInfo->usage, |
| 6873 | pFormatInfo->tiling, pPropertyCount, properties); |
| 6874 | for (uint32_t i = 0; i < *pPropertyCount; ++i) { |
| 6875 | // Write to the VkSparseImageFormatProperties2KHR struct |
| 6876 | memcpy(&pProperties[i].properties, &properties[i], sizeof(VkSparseImageFormatProperties)); |
| 6877 | |
| 6878 | if (pProperties[i].pNext != NULL) { |
| 6879 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6880 | "vkGetPhysicalDeviceSparseImageFormatProperties2: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6881 | "pProperties[%d].pNext - this struct will be ignored", |
| 6882 | i); |
| 6883 | } |
| 6884 | } |
| 6885 | } |
| 6886 | } |
| 6887 | } |
| 6888 | |
| 6889 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceExternalBufferProperties( |
| 6890 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, |
| 6891 | VkExternalBufferProperties *pExternalBufferProperties) { |
| 6892 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6893 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6894 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6895 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6896 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6897 | PFN_vkGetPhysicalDeviceExternalBufferProperties fpGetPhysicalDeviceExternalBufferProperties = NULL; |
| 6898 | if (inst != NULL && inst->enabled_known_extensions.khr_external_memory_capabilities) { |
| 6899 | fpGetPhysicalDeviceExternalBufferProperties = icd_term->dispatch.GetPhysicalDeviceExternalBufferPropertiesKHR; |
| 6900 | } else { |
| 6901 | fpGetPhysicalDeviceExternalBufferProperties = icd_term->dispatch.GetPhysicalDeviceExternalBufferProperties; |
| 6902 | } |
| 6903 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6904 | if (fpGetPhysicalDeviceExternalBufferProperties || !inst->enabled_known_extensions.khr_external_memory_capabilities) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6905 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6906 | fpGetPhysicalDeviceExternalBufferProperties(phys_dev_term->phys_dev, pExternalBufferInfo, pExternalBufferProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6907 | } else { |
| 6908 | // Emulate the call |
| 6909 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6910 | "vkGetPhysicalDeviceExternalBufferProperties: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6911 | |
| 6912 | if (pExternalBufferInfo->pNext != NULL) { |
| 6913 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6914 | "vkGetPhysicalDeviceExternalBufferProperties: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6915 | "pExternalBufferInfo->pNext - this struct will be ignored"); |
| 6916 | } |
| 6917 | |
| 6918 | // Fill in everything being unsupported |
| 6919 | memset(&pExternalBufferProperties->externalMemoryProperties, 0, sizeof(VkExternalMemoryPropertiesKHR)); |
| 6920 | |
| 6921 | if (pExternalBufferProperties->pNext != NULL) { |
| 6922 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6923 | "vkGetPhysicalDeviceExternalBufferProperties: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6924 | "pExternalBufferProperties->pNext - this struct will be ignored"); |
| 6925 | } |
| 6926 | } |
| 6927 | } |
| 6928 | |
| 6929 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceExternalSemaphoreProperties( |
| 6930 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo *pExternalSemaphoreInfo, |
| 6931 | VkExternalSemaphoreProperties *pExternalSemaphoreProperties) { |
| 6932 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6933 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6934 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6935 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6936 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6937 | PFN_vkGetPhysicalDeviceExternalSemaphoreProperties fpGetPhysicalDeviceExternalSemaphoreProperties = NULL; |
| 6938 | if (inst != NULL && inst->enabled_known_extensions.khr_external_semaphore_capabilities) { |
| 6939 | fpGetPhysicalDeviceExternalSemaphoreProperties = icd_term->dispatch.GetPhysicalDeviceExternalSemaphorePropertiesKHR; |
| 6940 | } else { |
| 6941 | fpGetPhysicalDeviceExternalSemaphoreProperties = icd_term->dispatch.GetPhysicalDeviceExternalSemaphoreProperties; |
| 6942 | } |
| 6943 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6944 | if (fpGetPhysicalDeviceExternalSemaphoreProperties != NULL || !inst->enabled_known_extensions.khr_external_semaphore_capabilities) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6945 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6946 | fpGetPhysicalDeviceExternalSemaphoreProperties(phys_dev_term->phys_dev, pExternalSemaphoreInfo, pExternalSemaphoreProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6947 | } else { |
| 6948 | // Emulate the call |
| 6949 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6950 | "vkGetPhysicalDeviceExternalSemaphoreProperties: Emulating call in ICD \"%s\"", |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6951 | icd_term->scanned_icd->lib_name); |
| 6952 | |
| 6953 | if (pExternalSemaphoreInfo->pNext != NULL) { |
| 6954 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6955 | "vkGetPhysicalDeviceExternalSemaphoreProperties: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6956 | "pExternalSemaphoreInfo->pNext - this struct will be ignored"); |
| 6957 | } |
| 6958 | |
| 6959 | // Fill in everything being unsupported |
| 6960 | pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0; |
| 6961 | pExternalSemaphoreProperties->compatibleHandleTypes = 0; |
| 6962 | pExternalSemaphoreProperties->externalSemaphoreFeatures = 0; |
| 6963 | |
| 6964 | if (pExternalSemaphoreProperties->pNext != NULL) { |
| 6965 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6966 | "vkGetPhysicalDeviceExternalSemaphoreProperties: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6967 | "pExternalSemaphoreProperties->pNext - this struct will be ignored"); |
| 6968 | } |
| 6969 | } |
| 6970 | } |
| 6971 | |
| 6972 | VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceExternalFenceProperties( |
| 6973 | VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo, |
| 6974 | VkExternalFenceProperties *pExternalFenceProperties) { |
| 6975 | struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice; |
| 6976 | struct loader_icd_term *icd_term = phys_dev_term->this_icd_term; |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6977 | const struct loader_instance *inst = icd_term->this_instance; |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6978 | |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6979 | // Get the function pointer to use to call into the ICD. This could be the core or KHR version |
| 6980 | PFN_vkGetPhysicalDeviceExternalFenceProperties fpGetPhysicalDeviceExternalFenceProperties = NULL; |
| 6981 | if (inst != NULL && inst->enabled_known_extensions.khr_external_fence_capabilities) { |
| 6982 | fpGetPhysicalDeviceExternalFenceProperties = icd_term->dispatch.GetPhysicalDeviceExternalFencePropertiesKHR; |
| 6983 | } else { |
| 6984 | fpGetPhysicalDeviceExternalFenceProperties = icd_term->dispatch.GetPhysicalDeviceExternalFenceProperties; |
| 6985 | } |
| 6986 | |
Lenny Komow | 88dc89b | 2017-11-03 14:37:11 -0600 | [diff] [blame] | 6987 | if (fpGetPhysicalDeviceExternalFenceProperties != NULL || !inst->enabled_known_extensions.khr_external_fence_capabilities) { |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6988 | // Pass the call to the driver |
Lenny Komow | a152485 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6989 | fpGetPhysicalDeviceExternalFenceProperties(phys_dev_term->phys_dev, pExternalFenceInfo, pExternalFenceProperties); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6990 | } else { |
| 6991 | // Emulate the call |
| 6992 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6993 | "vkGetPhysicalDeviceExternalFenceProperties: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name); |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6994 | |
| 6995 | if (pExternalFenceInfo->pNext != NULL) { |
| 6996 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 6997 | "vkGetPhysicalDeviceExternalFenceProperties: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 6998 | "pExternalFenceInfo->pNext - this struct will be ignored"); |
| 6999 | } |
| 7000 | |
| 7001 | // Fill in everything being unsupported |
| 7002 | pExternalFenceProperties->exportFromImportedHandleTypes = 0; |
| 7003 | pExternalFenceProperties->compatibleHandleTypes = 0; |
| 7004 | pExternalFenceProperties->externalFenceFeatures = 0; |
| 7005 | |
| 7006 | if (pExternalFenceProperties->pNext != NULL) { |
| 7007 | loader_log(icd_term->this_instance, VK_DEBUG_REPORT_WARNING_BIT_EXT, 0, |
Lenny Komow | 802a965 | 2017-10-03 13:59:21 -0600 | [diff] [blame] | 7008 | "vkGetPhysicalDeviceExternalFenceProperties: Emulation found unrecognized structure type in " |
Lenny Komow | 82e15e0 | 2017-10-02 15:08:53 -0600 | [diff] [blame] | 7009 | "pExternalFenceProperties->pNext - this struct will be ignored"); |
| 7010 | } |
| 7011 | } |
| 7012 | } |