Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 26 | * Jon Ashburn <jon@lunarg.com> |
Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 27 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 28 | * Ian Elliott <ian@lunarg.com> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 29 | */ |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 30 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <stdarg.h> |
| 34 | #include <stdbool.h> |
| 35 | #include <string.h> |
| 36 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 37 | #include <sys/types.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 38 | #if defined(WIN32) |
| 39 | #include "dirent_on_windows.h" |
| 40 | #else // WIN32 |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 41 | #include <dirent.h> |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 42 | #endif // WIN32 |
| 43 | #include "loader_platform.h" |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 44 | #include "table_ops.h" |
Chia-I Wu | 1930060 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 45 | #include "loader.h" |
Courtney Goeltzenleuchter | 64ca923 | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 46 | #include "xglIcd.h" |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 47 | // The following is #included again to catch certain OS-specific functions |
| 48 | // being used: |
| 49 | #include "loader_platform.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 50 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 51 | struct loader_instance { |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 52 | struct loader_icd *icds; |
| 53 | struct loader_instance *next; |
| 54 | }; |
| 55 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 56 | struct loader_layers { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 57 | loader_platform_dl_handle lib_handle; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 58 | char name[256]; |
| 59 | }; |
| 60 | |
| 61 | struct layer_name_pair { |
| 62 | char *layer_name; |
| 63 | const char *lib_name; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 64 | }; |
| 65 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 66 | struct loader_icd { |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 67 | const struct loader_scanned_icds *scanned_icds; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 68 | |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 69 | XGL_LAYER_DISPATCH_TABLE *loader_dispatch; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 70 | uint32_t layer_count[XGL_MAX_PHYSICAL_GPUS]; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 71 | struct loader_layers layer_libs[XGL_MAX_PHYSICAL_GPUS][MAX_LAYER_LIBRARIES]; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 72 | XGL_BASE_LAYER_OBJECT *wrappedGpus[XGL_MAX_PHYSICAL_GPUS]; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 73 | uint32_t gpu_count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 74 | XGL_BASE_LAYER_OBJECT *gpus; |
Jon Ashburn | df7d584 | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 75 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 76 | struct loader_icd *next; |
| 77 | }; |
| 78 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 79 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 80 | struct loader_scanned_icds { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 81 | loader_platform_dl_handle handle; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 82 | xglGetProcAddrType GetProcAddr; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 83 | xglCreateInstanceType CreateInstance; |
| 84 | xglDestroyInstanceType DestroyInstance; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 85 | xglEnumerateGpusType EnumerateGpus; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 86 | XGL_INSTANCE instance; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 87 | struct loader_scanned_icds *next; |
| 88 | }; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 89 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 90 | // Note: Since the following is a static structure, all members are initialized |
| 91 | // to zero. |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 92 | static struct { |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 93 | struct loader_instance *instances; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 94 | bool icds_scanned; |
| 95 | struct loader_scanned_icds *scanned_icd_list; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 96 | bool layer_scanned; |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 97 | char *layer_dirs; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 98 | unsigned int scanned_layer_count; |
| 99 | char *scanned_layer_names[MAX_LAYER_LIBRARIES]; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 100 | } loader; |
| 101 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 102 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 103 | #if defined(WIN32) |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 104 | char *loader_get_registry_string(const HKEY hive, |
| 105 | const LPCTSTR sub_key, |
| 106 | const char *value) |
| 107 | { |
| 108 | DWORD access_flags = KEY_QUERY_VALUE; |
| 109 | DWORD value_type; |
| 110 | HKEY key; |
| 111 | LONG rtn_value; |
| 112 | char *rtn_str = NULL; |
| 113 | size_t rtn_len = 0; |
| 114 | size_t allocated_len = 0; |
| 115 | |
| 116 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 117 | if (rtn_value != ERROR_SUCCESS) { |
| 118 | // We didn't find the key. Try the 32-bit hive (where we've seen the |
| 119 | // key end up on some people's systems): |
| 120 | access_flags |= KEY_WOW64_32KEY; |
| 121 | rtn_value = RegOpenKeyEx(hive, sub_key, 0, access_flags, &key); |
| 122 | if (rtn_value != ERROR_SUCCESS) { |
| 123 | // We still couldn't find the key, so give up: |
| 124 | return NULL; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
| 129 | (PVOID) rtn_str, &rtn_len); |
| 130 | if (rtn_value == ERROR_SUCCESS) { |
| 131 | // If we get to here, we found the key, and need to allocate memory |
| 132 | // large enough for rtn_str, and query again: |
| 133 | allocated_len = rtn_len + 4; |
| 134 | rtn_str = malloc(allocated_len); |
| 135 | rtn_value = RegQueryValueEx(key, value, NULL, &value_type, |
| 136 | (PVOID) rtn_str, &rtn_len); |
| 137 | if (rtn_value == ERROR_SUCCESS) { |
| 138 | // We added 4 extra bytes to rtn_str, so that we can ensure that |
| 139 | // the string is NULL-terminated (albeit, in a brute-force manner): |
| 140 | rtn_str[allocated_len-1] = '\0'; |
| 141 | } else { |
| 142 | // This should never occur, but in case it does, clean up: |
| 143 | free(rtn_str); |
| 144 | rtn_str = NULL; |
| 145 | } |
| 146 | } // else - shouldn't happen, but if it does, return rtn_str, which is NULL |
| 147 | |
| 148 | // Close the registry key that was opened: |
| 149 | RegCloseKey(key); |
| 150 | |
| 151 | return rtn_str; |
| 152 | } |
| 153 | |
| 154 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 155 | // For ICD developers, look in the registry, and look for an environment |
| 156 | // variable for a path(s) where to find the ICD(s): |
| 157 | static char *loader_get_registry_and_env(const char *env_var, |
| 158 | const char *registry_value) |
| 159 | { |
| 160 | char *env_str = getenv(env_var); |
| 161 | size_t env_len = (env_str == NULL) ? 0 : strlen(env_str); |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 162 | char *registry_str = NULL; |
| 163 | DWORD registry_len = 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 164 | char *rtn_str = NULL; |
| 165 | size_t rtn_len; |
| 166 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 167 | registry_str = loader_get_registry_string(HKEY_LOCAL_MACHINE, |
| 168 | "Software\\XGL", |
| 169 | registry_value); |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 170 | registry_len = (registry_str) ? strlen(registry_str) : 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 171 | |
| 172 | rtn_len = env_len + registry_len + 1; |
| 173 | if (rtn_len <= 2) { |
| 174 | // We found neither the desired registry value, nor the environment |
| 175 | // variable; return NULL: |
| 176 | return NULL; |
| 177 | } else { |
| 178 | // We found something, and so we need to allocate memory for the string |
| 179 | // to return: |
| 180 | rtn_str = malloc(rtn_len); |
| 181 | } |
| 182 | |
Ian Elliott | 5aa4ea2 | 2015-03-31 15:32:41 -0600 | [diff] [blame] | 183 | if (registry_len == 0) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 184 | // We didn't find the desired registry value, and so we must have found |
| 185 | // only the environment variable: |
| 186 | _snprintf(rtn_str, rtn_len, "%s", env_str); |
| 187 | } else if (env_str != NULL) { |
| 188 | // We found both the desired registry value and the environment |
| 189 | // variable, so concatenate them both: |
| 190 | _snprintf(rtn_str, rtn_len, "%s;%s", registry_str, env_str); |
| 191 | } else { |
| 192 | // We must have only found the desired registry value: |
| 193 | _snprintf(rtn_str, rtn_len, "%s", registry_str); |
| 194 | } |
| 195 | |
Ian Elliott | 2de26bc | 2015-04-03 13:13:01 -0600 | [diff] [blame] | 196 | if (registry_str) { |
| 197 | free(registry_str); |
| 198 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 199 | |
| 200 | return(rtn_str); |
| 201 | } |
| 202 | #endif // WIN32 |
| 203 | |
| 204 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 205 | static void loader_log(XGL_DBG_MSG_TYPE msg_type, int32_t msg_code, |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 206 | const char *format, ...) |
| 207 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 208 | char msg[256]; |
| 209 | va_list ap; |
| 210 | int ret; |
| 211 | |
| 212 | va_start(ap, format); |
| 213 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 214 | if ((ret >= (int) sizeof(msg)) || ret < 0) { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 215 | msg[sizeof(msg) - 1] = '\0'; |
| 216 | } |
| 217 | va_end(ap); |
| 218 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 219 | fputs(msg, stderr); |
| 220 | fputc('\n', stderr); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static void |
| 224 | loader_icd_destroy(struct loader_icd *icd) |
| 225 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 226 | loader_platform_close_library(icd->scanned_icds->handle); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 227 | free(icd); |
| 228 | } |
| 229 | |
| 230 | static struct loader_icd * |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 231 | loader_icd_create(const struct loader_scanned_icds *scanned) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 232 | { |
| 233 | struct loader_icd *icd; |
| 234 | |
| 235 | icd = malloc(sizeof(*icd)); |
| 236 | if (!icd) |
| 237 | return NULL; |
| 238 | |
Courtney Goeltzenleuchter | 55001bb | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 239 | memset(icd, 0, sizeof(*icd)); |
| 240 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 241 | icd->scanned_icds = scanned; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 242 | |
| 243 | return icd; |
| 244 | } |
| 245 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 246 | static struct loader_icd *loader_icd_add(struct loader_instance *ptr_inst, |
| 247 | const struct loader_scanned_icds *scanned) |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 248 | { |
| 249 | struct loader_icd *icd; |
| 250 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 251 | icd = loader_icd_create(scanned); |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 252 | if (!icd) |
| 253 | return NULL; |
| 254 | |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 255 | /* prepend to the list */ |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 256 | icd->next = ptr_inst->icds; |
| 257 | ptr_inst->icds = icd; |
Chia-I Wu | 13a61a5 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 258 | |
| 259 | return icd; |
| 260 | } |
| 261 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 262 | static void loader_scanned_icd_add(const char *filename) |
| 263 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 264 | loader_platform_dl_handle handle; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 265 | void *fp_gpa, *fp_enumerate, *fp_create_inst, *fp_destroy_inst; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 266 | struct loader_scanned_icds *new_node; |
| 267 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 268 | // Used to call: dlopen(filename, RTLD_LAZY); |
| 269 | handle = loader_platform_open_library(filename); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 270 | if (!handle) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 271 | loader_log(XGL_DBG_MSG_WARNING, 0, loader_platform_open_library_error(filename)); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
| 275 | #define LOOKUP(func_ptr, func) do { \ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 276 | func_ptr = (xgl ##func## Type) loader_platform_get_proc_address(handle, "xgl" #func); \ |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 277 | if (!func_ptr) { \ |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 278 | loader_log(XGL_DBG_MSG_WARNING, 0, loader_platform_get_proc_address_error("xgl" #func)); \ |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 279 | return; \ |
| 280 | } \ |
| 281 | } while (0) |
| 282 | |
| 283 | LOOKUP(fp_gpa, GetProcAddr); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 284 | LOOKUP(fp_create_inst, CreateInstance); |
| 285 | LOOKUP(fp_destroy_inst, DestroyInstance); |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 286 | LOOKUP(fp_enumerate, EnumerateGpus); |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 287 | #undef LOOKUP |
| 288 | |
| 289 | new_node = (struct loader_scanned_icds *) malloc(sizeof(struct loader_scanned_icds)); |
| 290 | if (!new_node) { |
| 291 | loader_log(XGL_DBG_MSG_WARNING, 0, "Out of memory can't add icd"); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | new_node->handle = handle; |
| 296 | new_node->GetProcAddr = fp_gpa; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 297 | new_node->CreateInstance = fp_create_inst; |
| 298 | new_node->DestroyInstance = fp_destroy_inst; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 299 | new_node->EnumerateGpus = fp_enumerate; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 300 | new_node->next = loader.scanned_icd_list; |
| 301 | loader.scanned_icd_list = new_node; |
| 302 | } |
| 303 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 304 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 305 | /** |
| 306 | * Try to \c loader_icd_scan XGL driver(s). |
| 307 | * |
| 308 | * This function scans the default system path or path |
| 309 | * specified by the \c LIBXGL_DRIVERS_PATH environment variable in |
| 310 | * order to find loadable XGL ICDs with the name of libXGL_*. |
| 311 | * |
| 312 | * \returns |
| 313 | * void; but side effect is to set loader_icd_scanned to true |
| 314 | */ |
| 315 | static void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 316 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 317 | const char *p, *next; |
| 318 | char *libPaths = NULL; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 319 | DIR *sysdir; |
| 320 | struct dirent *dent; |
| 321 | char icd_library[1024]; |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 322 | char path[1024]; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 323 | uint32_t len; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 324 | #if defined(WIN32) |
| 325 | bool must_free_libPaths; |
| 326 | libPaths = loader_get_registry_and_env(DRIVER_PATH_ENV, |
| 327 | DRIVER_PATH_REGISTRY_VALUE); |
| 328 | if (libPaths != NULL) { |
| 329 | must_free_libPaths = true; |
| 330 | } else { |
| 331 | must_free_libPaths = false; |
| 332 | libPaths = DEFAULT_XGL_DRIVERS_PATH; |
| 333 | } |
| 334 | #else // WIN32 |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 335 | if (geteuid() == getuid()) { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 336 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
| 337 | libPaths = getenv(DRIVER_PATH_ENV); |
| 338 | } |
| 339 | if (libPaths == NULL) { |
| 340 | libPaths = DEFAULT_XGL_DRIVERS_PATH; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 341 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 342 | #endif // WIN32 |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 343 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 344 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 345 | next = strchr(p, PATH_SEPERATOR); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 346 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 347 | len = (uint32_t) strlen(p); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 348 | next = p + len; |
| 349 | } |
| 350 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 351 | len = (uint32_t) (next - p); |
Jon Ashburn | 5cda59c | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 352 | sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p); |
| 353 | p = path; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 354 | next++; |
| 355 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 356 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 357 | // TODO/TBD: Do we want to do this on Windows, or just let Windows take |
| 358 | // care of its own search path (which it apparently has)? |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 359 | sysdir = opendir(p); |
| 360 | if (sysdir) { |
| 361 | dent = readdir(sysdir); |
| 362 | while (dent) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 363 | /* Look for ICDs starting with XGL_DRIVER_LIBRARY_PREFIX and |
| 364 | * ending with XGL_LIBRARY_SUFFIX |
| 365 | */ |
| 366 | if (!strncmp(dent->d_name, |
| 367 | XGL_DRIVER_LIBRARY_PREFIX, |
| 368 | XGL_DRIVER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 369 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 370 | const char *suf = dent->d_name + nlen - XGL_LIBRARY_SUFFIX_LEN; |
| 371 | if ((nlen > XGL_LIBRARY_SUFFIX_LEN) && |
| 372 | !strncmp(suf, |
| 373 | XGL_LIBRARY_SUFFIX, |
| 374 | XGL_LIBRARY_SUFFIX_LEN)) { |
| 375 | snprintf(icd_library, 1024, "%s" DIRECTORY_SYMBOL "%s", p,dent->d_name); |
| 376 | loader_scanned_icd_add(icd_library); |
| 377 | } |
| 378 | } |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 379 | |
| 380 | dent = readdir(sysdir); |
| 381 | } |
| 382 | closedir(sysdir); |
| 383 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 386 | #if defined(WIN32) |
| 387 | // Free any allocated memory: |
| 388 | if (must_free_libPaths) { |
| 389 | free(libPaths); |
| 390 | } |
| 391 | #endif // WIN32 |
| 392 | |
| 393 | // Note that we've scanned for ICDs: |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 394 | loader.icds_scanned = true; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 395 | } |
| 396 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 397 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 398 | static void layer_lib_scan(void) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 399 | { |
| 400 | const char *p, *next; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 401 | char *libPaths = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 402 | DIR *curdir; |
| 403 | struct dirent *dent; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 404 | size_t len, i; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 405 | char temp_str[1024]; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 406 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 407 | #if defined(WIN32) |
| 408 | bool must_free_libPaths; |
| 409 | libPaths = loader_get_registry_and_env(LAYERS_PATH_ENV, |
| 410 | LAYERS_PATH_REGISTRY_VALUE); |
| 411 | if (libPaths != NULL) { |
| 412 | must_free_libPaths = true; |
| 413 | } else { |
| 414 | must_free_libPaths = false; |
| 415 | libPaths = DEFAULT_XGL_LAYERS_PATH; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 416 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 417 | #else // WIN32 |
| 418 | if (geteuid() == getuid()) { |
| 419 | /* Don't allow setuid apps to use the DRIVER_PATH_ENV env var: */ |
Courtney Goeltzenleuchter | 66b72f9 | 2015-02-18 20:03:02 -0700 | [diff] [blame] | 420 | libPaths = getenv(LAYERS_PATH_ENV); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 421 | } |
| 422 | if (libPaths == NULL) { |
| 423 | libPaths = DEFAULT_XGL_LAYERS_PATH; |
| 424 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 425 | #endif // WIN32 |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 426 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 427 | if (libPaths == NULL) { |
| 428 | // Have no paths to search: |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 429 | return; |
| 430 | } |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 431 | len = strlen(libPaths); |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 432 | loader.layer_dirs = malloc(len+1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 433 | if (loader.layer_dirs == NULL) { |
| 434 | free(libPaths); |
Courtney Goeltzenleuchter | a66265b | 2014-12-02 18:12:51 -0700 | [diff] [blame] | 435 | return; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 436 | } |
| 437 | // Alloc passed, so we know there is enough space to hold the string, don't |
| 438 | // need strncpy |
| 439 | strcpy(loader.layer_dirs, libPaths); |
| 440 | #if defined(WIN32) |
| 441 | // Free any allocated memory: |
| 442 | if (must_free_libPaths) { |
| 443 | free(libPaths); |
| 444 | must_free_libPaths = false; |
| 445 | } |
| 446 | #endif // WIN32 |
Courtney Goeltzenleuchter | 57985ce | 2014-12-01 09:29:42 -0700 | [diff] [blame] | 447 | libPaths = loader.layer_dirs; |
| 448 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 449 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 450 | for (i = 0; i < loader.scanned_layer_count; i++) { |
| 451 | if (loader.scanned_layer_names[i] != NULL) |
| 452 | free(loader.scanned_layer_names[i]); |
| 453 | loader.scanned_layer_names[i] = NULL; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 454 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 455 | loader.scanned_layer_count = 0; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 456 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 457 | for (p = libPaths; *p; p = next) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 458 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 459 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 460 | len = (uint32_t) strlen(p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 461 | next = p + len; |
| 462 | } |
| 463 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 464 | len = (uint32_t) (next - p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 465 | *(char *) next = '\0'; |
| 466 | next++; |
| 467 | } |
| 468 | |
| 469 | curdir = opendir(p); |
| 470 | if (curdir) { |
| 471 | dent = readdir(curdir); |
| 472 | while (dent) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 473 | /* Look for layers starting with XGL_LAYER_LIBRARY_PREFIX and |
| 474 | * ending with XGL_LIBRARY_SUFFIX |
| 475 | */ |
| 476 | if (!strncmp(dent->d_name, |
| 477 | XGL_LAYER_LIBRARY_PREFIX, |
| 478 | XGL_LAYER_LIBRARY_PREFIX_LEN)) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 479 | uint32_t nlen = (uint32_t) strlen(dent->d_name); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 480 | const char *suf = dent->d_name + nlen - XGL_LIBRARY_SUFFIX_LEN; |
| 481 | if ((nlen > XGL_LIBRARY_SUFFIX_LEN) && |
| 482 | !strncmp(suf, |
| 483 | XGL_LIBRARY_SUFFIX, |
| 484 | XGL_LIBRARY_SUFFIX_LEN)) { |
| 485 | loader_platform_dl_handle handle; |
| 486 | snprintf(temp_str, sizeof(temp_str), "%s" DIRECTORY_SYMBOL "%s",p,dent->d_name); |
| 487 | // Used to call: dlopen(temp_str, RTLD_LAZY) |
| 488 | if ((handle = loader_platform_open_library(temp_str)) == NULL) { |
| 489 | dent = readdir(curdir); |
| 490 | continue; |
| 491 | } |
| 492 | if (loader.scanned_layer_count == MAX_LAYER_LIBRARIES) { |
| 493 | loader_log(XGL_DBG_MSG_ERROR, 0, "%s ignored: max layer libraries exceed", temp_str); |
| 494 | break; |
| 495 | } |
| 496 | if ((loader.scanned_layer_names[loader.scanned_layer_count] = malloc(strlen(temp_str) + 1)) == NULL) { |
| 497 | loader_log(XGL_DBG_MSG_ERROR, 0, "%s ignored: out of memory", temp_str); |
| 498 | break; |
| 499 | } |
| 500 | strcpy(loader.scanned_layer_names[loader.scanned_layer_count], temp_str); |
| 501 | loader.scanned_layer_count++; |
| 502 | loader_platform_close_library(handle); |
| 503 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | dent = readdir(curdir); |
| 507 | } |
| 508 | closedir(curdir); |
| 509 | } |
| 510 | } |
| 511 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 512 | loader.layer_scanned = true; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 513 | } |
| 514 | |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 515 | static void loader_init_dispatch_table(XGL_LAYER_DISPATCH_TABLE *tab, xglGetProcAddrType fpGPA, XGL_PHYSICAL_GPU gpu) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 516 | { |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 517 | loader_initialize_dispatch_table(tab, fpGPA, gpu); |
| 518 | |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 519 | if (tab->EnumerateLayers == NULL) |
| 520 | tab->EnumerateLayers = xglEnumerateLayers; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 521 | } |
| 522 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 523 | static struct loader_icd * loader_get_icd(const XGL_BASE_LAYER_OBJECT *gpu, uint32_t *gpu_index) |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 524 | { |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 525 | for (struct loader_instance *inst = loader.instances; inst; inst = inst->next) { |
| 526 | for (struct loader_icd *icd = inst->icds; icd; icd = icd->next) { |
| 527 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
| 528 | if ((icd->gpus + i) == gpu || (icd->gpus +i)->baseObject == |
| 529 | gpu->baseObject) { |
| 530 | *gpu_index = i; |
| 531 | return icd; |
| 532 | } |
| 533 | } |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 534 | } |
| 535 | return NULL; |
| 536 | } |
| 537 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 538 | static bool loader_layers_activated(const struct loader_icd *icd, const uint32_t gpu_index) |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 539 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 540 | if (icd->layer_count[gpu_index]) |
| 541 | return true; |
| 542 | else |
| 543 | return false; |
Jon Ashburn | 876b1ac | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 544 | } |
| 545 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 546 | static void loader_init_layer_libs(struct loader_icd *icd, uint32_t gpu_index, struct layer_name_pair * pLayerNames, uint32_t count) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 547 | { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 548 | if (!icd) |
| 549 | return; |
Jon Ashburn | df7d584 | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 550 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 551 | struct loader_layers *obj; |
| 552 | bool foundLib; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 553 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 554 | foundLib = false; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 555 | for (uint32_t j = 0; j < icd->layer_count[gpu_index]; j++) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 556 | if (icd->layer_libs[gpu_index][j].lib_handle && !strcmp(icd->layer_libs[gpu_index][j].name, (char *) pLayerNames[i].layer_name)) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 557 | foundLib = true; |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | if (!foundLib) { |
| 562 | obj = &(icd->layer_libs[gpu_index][i]); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 563 | strncpy(obj->name, (char *) pLayerNames[i].layer_name, sizeof(obj->name) - 1); |
| 564 | obj->name[sizeof(obj->name) - 1] = '\0'; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 565 | // Used to call: dlopen(pLayerNames[i].lib_name, RTLD_LAZY | RTLD_DEEPBIND) |
| 566 | if ((obj->lib_handle = loader_platform_open_library(pLayerNames[i].lib_name)) == NULL) { |
| 567 | loader_log(XGL_DBG_MSG_ERROR, 0, loader_platform_open_library_error(pLayerNames[i].lib_name)); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 568 | continue; |
| 569 | } else { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 570 | loader_log(XGL_DBG_MSG_UNKNOWN, 0, "Inserting layer %s from library %s", pLayerNames[i].layer_name, pLayerNames[i].lib_name); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 571 | } |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 572 | free(pLayerNames[i].layer_name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 573 | icd->layer_count[gpu_index]++; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 574 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 575 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 576 | } |
| 577 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 578 | static bool find_layer_name(struct loader_icd *icd, uint32_t gpu_index, const char * layer_name, const char **lib_name) |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 579 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 580 | loader_platform_dl_handle handle; |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 581 | xglEnumerateLayersType fpEnumerateLayers; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 582 | char layer_buf[16][256]; |
| 583 | char * layers[16]; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 584 | |
| 585 | for (int i = 0; i < 16; i++) |
| 586 | layers[i] = &layer_buf[i][0]; |
| 587 | |
| 588 | for (unsigned int j = 0; j < loader.scanned_layer_count; j++) { |
| 589 | *lib_name = loader.scanned_layer_names[j]; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 590 | // Used to call: dlopen(*lib_name, RTLD_LAZY) |
| 591 | if ((handle = loader_platform_open_library(*lib_name)) == NULL) |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 592 | continue; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 593 | if ((fpEnumerateLayers = (xglEnumerateLayersType) loader_platform_get_proc_address(handle, "xglEnumerateLayers")) == NULL) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 594 | char * lib_str = malloc(strlen(*lib_name) + 1 + strlen(layer_name)); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 595 | //use default layer name |
| 596 | snprintf(lib_str, strlen(*lib_name) + strlen(layer_name), |
Courtney Goeltzenleuchter | 8d095ff | 2015-04-03 14:53:08 -0600 | [diff] [blame] | 597 | XGL_LAYER_LIBRARY_PREFIX "%s" XGL_LIBRARY_SUFFIX, |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 598 | layer_name); |
| 599 | loader_platform_close_library(handle); |
| 600 | if (!strcmp(*lib_name, lib_str)) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 601 | free(lib_str); |
| 602 | return true; |
| 603 | } |
| 604 | else { |
| 605 | free(lib_str); |
| 606 | continue; |
| 607 | } |
| 608 | } |
| 609 | else { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 610 | size_t cnt; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 611 | fpEnumerateLayers(NULL, 16, 256, &cnt, layers, (char *) icd->gpus + gpu_index); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 612 | for (unsigned int i = 0; i < cnt; i++) { |
| 613 | if (!strcmp((char *) layers[i], layer_name)) { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 614 | loader_platform_close_library(handle); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 615 | return true; |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 620 | loader_platform_close_library(handle); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | return false; |
| 624 | } |
| 625 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 626 | static uint32_t loader_get_layer_env(struct loader_icd *icd, uint32_t gpu_index, struct layer_name_pair *pLayerNames) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 627 | { |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 628 | char *layerEnv; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 629 | uint32_t len, count = 0; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 630 | char *p, *pOrig, *next, *name; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 631 | |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 632 | #if defined(WIN32) |
| 633 | layerEnv = loader_get_registry_and_env(LAYER_NAMES_ENV, |
| 634 | LAYER_NAMES_REGISTRY_VALUE); |
| 635 | #else // WIN32 |
| 636 | layerEnv = getenv(LAYER_NAMES_ENV); |
| 637 | #endif // WIN32 |
| 638 | if (layerEnv == NULL) { |
Jon Ashburn | 3fb5544 | 2014-10-23 10:29:09 -0600 | [diff] [blame] | 639 | return 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 640 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 641 | p = malloc(strlen(layerEnv) + 1); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 642 | if (p == NULL) { |
| 643 | #if defined(WIN32) |
| 644 | free(layerEnv); |
| 645 | #endif // WIN32 |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 646 | return 0; |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 647 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 648 | strcpy(p, layerEnv); |
Ian Elliott | 4470a30 | 2015-02-17 10:33:47 -0700 | [diff] [blame] | 649 | #if defined(WIN32) |
| 650 | free(layerEnv); |
| 651 | #endif // WIN32 |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 652 | pOrig = p; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 653 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 654 | while (p && *p && count < MAX_LAYER_LIBRARIES) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 655 | const char *lib_name = NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 656 | next = strchr(p, PATH_SEPERATOR); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 657 | if (next == NULL) { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 658 | len = (uint32_t) strlen(p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 659 | next = p + len; |
| 660 | } |
| 661 | else { |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 662 | len = (uint32_t) (next - p); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 663 | *(char *) next = '\0'; |
| 664 | next++; |
| 665 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 666 | name = basename(p); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 667 | if (!find_layer_name(icd, gpu_index, name, &lib_name)) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 668 | p = next; |
| 669 | continue; |
| 670 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 671 | |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 672 | len = (uint32_t) strlen(name); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 673 | pLayerNames[count].layer_name = malloc(len + 1); |
| 674 | if (!pLayerNames[count].layer_name) { |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 675 | free(pOrig); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 676 | return count; |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 677 | } |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 678 | strncpy((char *) pLayerNames[count].layer_name, name, len); |
| 679 | pLayerNames[count].layer_name[len] = '\0'; |
| 680 | pLayerNames[count].lib_name = lib_name; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 681 | count++; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 682 | p = next; |
| 683 | |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 684 | }; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 685 | |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 686 | free(pOrig); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 687 | return count; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 688 | } |
| 689 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 690 | static uint32_t loader_get_layer_libs(struct loader_icd *icd, uint32_t gpu_index, const XGL_DEVICE_CREATE_INFO* pCreateInfo, struct layer_name_pair **ppLayerNames) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 691 | { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 692 | static struct layer_name_pair layerNames[MAX_LAYER_LIBRARIES]; |
Courtney Goeltzenleuchter | 89ba928 | 2015-02-17 14:21:21 -0700 | [diff] [blame] | 693 | int env_layer_count = 0; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 694 | |
| 695 | *ppLayerNames = &layerNames[0]; |
Courtney Goeltzenleuchter | 89ba928 | 2015-02-17 14:21:21 -0700 | [diff] [blame] | 696 | /* Load any layers specified in the environment first */ |
| 697 | env_layer_count = loader_get_layer_env(icd, gpu_index, layerNames); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 698 | |
Chia-I Wu | b0a2cc9 | 2015-01-28 14:00:47 +0800 | [diff] [blame] | 699 | const XGL_LAYER_CREATE_INFO *pCi = |
| 700 | (const XGL_LAYER_CREATE_INFO *) pCreateInfo->pNext; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 701 | |
| 702 | while (pCi) { |
| 703 | if (pCi->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) { |
| 704 | const char *name; |
Jon Ashburn | c0e8601 | 2015-02-18 11:29:58 -0700 | [diff] [blame] | 705 | uint32_t len, j = 0; |
Courtney Goeltzenleuchter | 89ba928 | 2015-02-17 14:21:21 -0700 | [diff] [blame] | 706 | for (uint32_t i = env_layer_count; i < (env_layer_count + pCi->layerCount); i++) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 707 | const char * lib_name = NULL; |
Jon Ashburn | c0e8601 | 2015-02-18 11:29:58 -0700 | [diff] [blame] | 708 | name = *(pCi->ppActiveLayerNames + j); |
| 709 | if (!find_layer_name(icd, gpu_index, name, &lib_name)) { |
| 710 | return i; |
| 711 | } |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 712 | len = (uint32_t) strlen(name); |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 713 | layerNames[i].layer_name = malloc(len + 1); |
| 714 | if (!layerNames[i].layer_name) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 715 | return i; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 716 | strncpy((char *) layerNames[i].layer_name, name, len); |
| 717 | layerNames[i].layer_name[len] = '\0'; |
| 718 | layerNames[i].lib_name = lib_name; |
Jon Ashburn | c0e8601 | 2015-02-18 11:29:58 -0700 | [diff] [blame] | 719 | j++; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 720 | } |
Jon Ashburn | c0e8601 | 2015-02-18 11:29:58 -0700 | [diff] [blame] | 721 | return pCi->layerCount + env_layer_count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 722 | } |
| 723 | pCi = pCi->pNext; |
| 724 | } |
Jon Ashburn | c0e8601 | 2015-02-18 11:29:58 -0700 | [diff] [blame] | 725 | return env_layer_count; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 726 | } |
| 727 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 728 | static void loader_deactivate_layer(const struct loader_instance *instance) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 729 | { |
| 730 | struct loader_icd *icd; |
| 731 | struct loader_layers *libs; |
| 732 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 733 | for (icd = instance->icds; icd; icd = icd->next) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 734 | if (icd->gpus) |
| 735 | free(icd->gpus); |
| 736 | icd->gpus = NULL; |
| 737 | if (icd->loader_dispatch) |
| 738 | free(icd->loader_dispatch); |
| 739 | icd->loader_dispatch = NULL; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 740 | for (uint32_t j = 0; j < icd->gpu_count; j++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 741 | if (icd->layer_count[j] > 0) { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 742 | for (uint32_t i = 0; i < icd->layer_count[j]; i++) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 743 | libs = &(icd->layer_libs[j][i]); |
| 744 | if (libs->lib_handle) |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 745 | loader_platform_close_library(libs->lib_handle); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 746 | libs->lib_handle = NULL; |
| 747 | } |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 748 | if (icd->wrappedGpus[j]) |
| 749 | free(icd->wrappedGpus[j]); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 750 | } |
| 751 | icd->layer_count[j] = 0; |
| 752 | } |
| 753 | icd->gpu_count = 0; |
| 754 | } |
| 755 | } |
| 756 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 757 | extern uint32_t loader_activate_layers(XGL_PHYSICAL_GPU gpu, const XGL_DEVICE_CREATE_INFO* pCreateInfo) |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 758 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 759 | uint32_t gpu_index; |
| 760 | uint32_t count; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 761 | struct layer_name_pair *pLayerNames; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 762 | struct loader_icd *icd = loader_get_icd((const XGL_BASE_LAYER_OBJECT *) gpu, &gpu_index); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 763 | |
| 764 | if (!icd) |
| 765 | return 0; |
| 766 | assert(gpu_index < XGL_MAX_PHYSICAL_GPUS); |
| 767 | |
| 768 | /* activate any layer libraries */ |
| 769 | if (!loader_layers_activated(icd, gpu_index)) { |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 770 | XGL_BASE_LAYER_OBJECT *gpuObj = (XGL_BASE_LAYER_OBJECT *) gpu; |
| 771 | XGL_BASE_LAYER_OBJECT *nextGpuObj, *baseObj = gpuObj->baseObject; |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 772 | xglGetProcAddrType nextGPA = xglGetProcAddr; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 773 | |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 774 | count = loader_get_layer_libs(icd, gpu_index, pCreateInfo, &pLayerNames); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 775 | if (!count) |
| 776 | return 0; |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 777 | loader_init_layer_libs(icd, gpu_index, pLayerNames, count); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 778 | |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 779 | icd->wrappedGpus[gpu_index] = malloc(sizeof(XGL_BASE_LAYER_OBJECT) * icd->layer_count[gpu_index]); |
| 780 | if (! icd->wrappedGpus[gpu_index]) |
| 781 | loader_log(XGL_DBG_MSG_ERROR, 0, "Failed to malloc Gpu objects for layer"); |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 782 | for (int32_t i = icd->layer_count[gpu_index] - 1; i >= 0; i--) { |
Jon Ashburn | d09bd10 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 783 | nextGpuObj = (icd->wrappedGpus[gpu_index] + i); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 784 | nextGpuObj->pGPA = nextGPA; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 785 | nextGpuObj->baseObject = baseObj; |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 786 | nextGpuObj->nextObject = gpuObj; |
| 787 | gpuObj = nextGpuObj; |
| 788 | |
Jon Ashburn | 79113cc | 2014-12-01 14:22:40 -0700 | [diff] [blame] | 789 | char funcStr[256]; |
| 790 | snprintf(funcStr, 256, "%sGetProcAddr",icd->layer_libs[gpu_index][i].name); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 791 | if ((nextGPA = (xglGetProcAddrType) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, funcStr)) == NULL) |
| 792 | nextGPA = (xglGetProcAddrType) loader_platform_get_proc_address(icd->layer_libs[gpu_index][i].lib_handle, "xglGetProcAddr"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 793 | if (!nextGPA) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 794 | loader_log(XGL_DBG_MSG_ERROR, 0, "Failed to find xglGetProcAddr in layer %s", icd->layer_libs[gpu_index][i].name); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 795 | continue; |
| 796 | } |
| 797 | |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 798 | if (i == 0) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 799 | loader_init_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, gpuObj); |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 800 | //Insert the new wrapped objects into the list with loader object at head |
| 801 | ((XGL_BASE_LAYER_OBJECT *) gpu)->nextObject = gpuObj; |
| 802 | ((XGL_BASE_LAYER_OBJECT *) gpu)->pGPA = nextGPA; |
| 803 | gpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; |
| 804 | gpuObj->nextObject = baseObj; |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 805 | gpuObj->pGPA = icd->scanned_icds->GetProcAddr; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 806 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 807 | |
| 808 | } |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 809 | } |
| 810 | else { |
| 811 | //make sure requested Layers matches currently activated Layers |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 812 | count = loader_get_layer_libs(icd, gpu_index, pCreateInfo, &pLayerNames); |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 813 | for (uint32_t i = 0; i < count; i++) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 814 | if (strcmp(icd->layer_libs[gpu_index][i].name, pLayerNames[i].layer_name)) { |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 815 | loader_log(XGL_DBG_MSG_ERROR, 0, "Layers activated != Layers requested"); |
| 816 | break; |
| 817 | } |
| 818 | } |
| 819 | if (count != icd->layer_count[gpu_index]) { |
Jon Ashburn | b835805 | 2014-11-18 09:06:04 -0700 | [diff] [blame] | 820 | loader_log(XGL_DBG_MSG_ERROR, 0, "Number of Layers activated != number requested"); |
Jon Ashburn | 6b4d70c | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | return icd->layer_count[gpu_index]; |
| 824 | } |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 825 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 826 | LOADER_EXPORT XGL_RESULT XGLAPI xglCreateInstance( |
| 827 | const XGL_APPLICATION_INFO* pAppInfo, |
| 828 | const XGL_ALLOC_CALLBACKS* pAllocCb, |
| 829 | XGL_INSTANCE* pInstance) |
| 830 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 831 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_icd); |
| 832 | static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(once_layer); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 833 | struct loader_instance *ptr_instance = NULL; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 834 | struct loader_scanned_icds *scanned_icds; |
| 835 | struct loader_icd *icd; |
Ian Elliott | 55dbc5b | 2015-02-19 15:49:03 -0700 | [diff] [blame] | 836 | XGL_RESULT res = XGL_ERROR_INITIALIZATION_FAILED; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 837 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 838 | /* Scan/discover all ICD libraries in a single-threaded manner */ |
| 839 | loader_platform_thread_once(&once_icd, loader_icd_scan); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 840 | |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 841 | /* get layer libraries in a single-threaded manner */ |
| 842 | loader_platform_thread_once(&once_layer, layer_lib_scan); |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 843 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 844 | ptr_instance = (struct loader_instance*) malloc(sizeof(struct loader_instance)); |
| 845 | if (ptr_instance == NULL) { |
| 846 | return XGL_ERROR_OUT_OF_MEMORY; |
| 847 | } |
| 848 | memset(ptr_instance, 0, sizeof(struct loader_instance)); |
| 849 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 850 | ptr_instance->next = loader.instances; |
| 851 | loader.instances = ptr_instance; |
| 852 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 853 | scanned_icds = loader.scanned_icd_list; |
| 854 | while (scanned_icds) { |
| 855 | icd = loader_icd_add(ptr_instance, scanned_icds); |
| 856 | if (icd) { |
| 857 | res = scanned_icds->CreateInstance(pAppInfo, pAllocCb, |
| 858 | &(scanned_icds->instance)); |
| 859 | if (res != XGL_SUCCESS) |
| 860 | { |
| 861 | ptr_instance->icds = ptr_instance->icds->next; |
| 862 | loader_icd_destroy(icd); |
| 863 | scanned_icds->instance = NULL; |
| 864 | loader_log(XGL_DBG_MSG_WARNING, 0, |
| 865 | "ICD ignored: failed to CreateInstance on device"); |
| 866 | } |
| 867 | } |
| 868 | scanned_icds = scanned_icds->next; |
| 869 | } |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 870 | |
Ian Elliott | eb45076 | 2015-02-05 15:19:15 -0700 | [diff] [blame] | 871 | if (ptr_instance->icds == NULL) { |
| 872 | return XGL_ERROR_INCOMPATIBLE_DRIVER; |
| 873 | } |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 874 | |
| 875 | *pInstance = (XGL_INSTANCE) ptr_instance; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 876 | return XGL_SUCCESS; |
| 877 | } |
| 878 | |
| 879 | LOADER_EXPORT XGL_RESULT XGLAPI xglDestroyInstance( |
| 880 | XGL_INSTANCE instance) |
| 881 | { |
| 882 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 883 | struct loader_scanned_icds *scanned_icds; |
| 884 | XGL_RESULT res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 885 | |
| 886 | // Remove this instance from the list of instances: |
| 887 | struct loader_instance *prev = NULL; |
| 888 | struct loader_instance *next = loader.instances; |
| 889 | while (next != NULL) { |
| 890 | if (next == ptr_instance) { |
| 891 | // Remove this instance from the list: |
| 892 | if (prev) |
| 893 | prev->next = next->next; |
Jon Ashburn | c5c4960 | 2015-02-03 09:26:59 -0700 | [diff] [blame] | 894 | else |
| 895 | loader.instances = next->next; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 896 | break; |
| 897 | } |
| 898 | prev = next; |
| 899 | next = next->next; |
| 900 | } |
| 901 | if (next == NULL) { |
| 902 | // This must be an invalid instance handle or empty list |
| 903 | return XGL_ERROR_INVALID_HANDLE; |
| 904 | } |
| 905 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 906 | // cleanup any prior layer initializations |
| 907 | loader_deactivate_layer(ptr_instance); |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 908 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 909 | scanned_icds = loader.scanned_icd_list; |
| 910 | while (scanned_icds) { |
| 911 | if (scanned_icds->instance) |
| 912 | res = scanned_icds->DestroyInstance(scanned_icds->instance); |
| 913 | if (res != XGL_SUCCESS) |
| 914 | loader_log(XGL_DBG_MSG_WARNING, 0, |
| 915 | "ICD ignored: failed to DestroyInstance on device"); |
| 916 | scanned_icds->instance = NULL; |
| 917 | scanned_icds = scanned_icds->next; |
| 918 | } |
| 919 | |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 920 | free(ptr_instance); |
| 921 | |
| 922 | return XGL_SUCCESS; |
| 923 | } |
| 924 | |
| 925 | LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateGpus( |
| 926 | |
| 927 | XGL_INSTANCE instance, |
| 928 | uint32_t maxGpus, |
| 929 | uint32_t* pGpuCount, |
| 930 | XGL_PHYSICAL_GPU* pGpus) |
| 931 | { |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 932 | struct loader_instance *ptr_instance = (struct loader_instance *) instance; |
| 933 | struct loader_icd *icd; |
Jon Ashburn | 8d66a05 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 934 | uint32_t count = 0; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 935 | XGL_RESULT res; |
| 936 | |
| 937 | //in spirit of XGL don't error check on the instance parameter |
| 938 | icd = ptr_instance->icds; |
| 939 | while (icd) { |
| 940 | XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS]; |
| 941 | XGL_BASE_LAYER_OBJECT * wrapped_gpus; |
| 942 | xglGetProcAddrType get_proc_addr = icd->scanned_icds->GetProcAddr; |
Jon Ashburn | 8d66a05 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 943 | uint32_t n, max = maxGpus - count; |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 944 | |
| 945 | if (max > XGL_MAX_PHYSICAL_GPUS) { |
| 946 | max = XGL_MAX_PHYSICAL_GPUS; |
| 947 | } |
| 948 | |
Jon Ashburn | 4688839 | 2015-01-29 15:45:51 -0700 | [diff] [blame] | 949 | res = icd->scanned_icds->EnumerateGpus(icd->scanned_icds->instance, |
| 950 | max, &n, |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 951 | gpus); |
| 952 | if (res == XGL_SUCCESS && n) { |
| 953 | wrapped_gpus = (XGL_BASE_LAYER_OBJECT*) malloc(n * |
| 954 | sizeof(XGL_BASE_LAYER_OBJECT)); |
| 955 | icd->gpus = wrapped_gpus; |
| 956 | icd->gpu_count = n; |
| 957 | icd->loader_dispatch = (XGL_LAYER_DISPATCH_TABLE *) malloc(n * |
| 958 | sizeof(XGL_LAYER_DISPATCH_TABLE)); |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 959 | for (unsigned int i = 0; i < n; i++) { |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 960 | (wrapped_gpus + i)->baseObject = gpus[i]; |
| 961 | (wrapped_gpus + i)->pGPA = get_proc_addr; |
| 962 | (wrapped_gpus + i)->nextObject = gpus[i]; |
| 963 | memcpy(pGpus + count, &wrapped_gpus, sizeof(*pGpus)); |
| 964 | loader_init_dispatch_table(icd->loader_dispatch + i, |
| 965 | get_proc_addr, gpus[i]); |
Courtney Goeltzenleuchter | 64ca923 | 2015-02-10 18:40:14 -0700 | [diff] [blame] | 966 | |
| 967 | /* Verify ICD compatibility */ |
| 968 | if (!valid_loader_magic_value(gpus[i])) { |
| 969 | loader_log(XGL_DBG_MSG_WARNING, 0, |
| 970 | "Loader: Incompatible ICD, first dword must be initialized to ICD_LOADER_MAGIC. See loader/README.md for details.\n"); |
| 971 | assert(0); |
| 972 | } |
| 973 | |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 974 | const XGL_LAYER_DISPATCH_TABLE **disp; |
| 975 | disp = (const XGL_LAYER_DISPATCH_TABLE **) gpus[i]; |
| 976 | *disp = icd->loader_dispatch + i; |
| 977 | } |
| 978 | |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 979 | count += n; |
| 980 | |
| 981 | if (count >= maxGpus) { |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | icd = icd->next; |
| 987 | } |
| 988 | |
Jon Ashburn | 4c392fb | 2015-01-28 19:57:09 -0700 | [diff] [blame] | 989 | *pGpuCount = count; |
| 990 | |
| 991 | return (count > 0) ? XGL_SUCCESS : res; |
Jon Ashburn | 1beab2d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | LOADER_EXPORT void * XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const char * pName) |
| 995 | { |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 996 | if (gpu == NULL) { |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 997 | return NULL; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 998 | } |
Jon Ashburn | 891537f | 2014-10-22 12:42:13 -0600 | [diff] [blame] | 999 | XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1000 | XGL_LAYER_DISPATCH_TABLE * disp_table = * (XGL_LAYER_DISPATCH_TABLE **) gpuw->baseObject; |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1001 | void *addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1002 | |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1003 | if (disp_table == NULL) |
| 1004 | return NULL; |
| 1005 | |
Chia-I Wu | f46b81a | 2015-01-04 11:12:47 +0800 | [diff] [blame] | 1006 | addr = loader_lookup_dispatch_table(disp_table, pName); |
| 1007 | if (addr) |
| 1008 | return addr; |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1009 | else { |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1010 | if (disp_table->GetProcAddr == NULL) |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1011 | return NULL; |
Jon Ashburn | f261001 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1012 | return disp_table->GetProcAddr(gpuw->nextObject, pName); |
Jon Ashburn | d38bfb1 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1016 | LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, size_t maxLayerCount, size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved) |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1017 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1018 | uint32_t gpu_index; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1019 | size_t count = 0; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1020 | char *lib_name; |
| 1021 | struct loader_icd *icd = loader_get_icd((const XGL_BASE_LAYER_OBJECT *) gpu, &gpu_index); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1022 | loader_platform_dl_handle handle; |
Mark Lobodzinski | 391bb6d | 2015-01-09 15:12:03 -0600 | [diff] [blame] | 1023 | xglEnumerateLayersType fpEnumerateLayers; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1024 | char layer_buf[16][256]; |
| 1025 | char * layers[16]; |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1026 | |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1027 | if (pOutLayerCount == NULL || pOutLayers == NULL) |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1028 | return XGL_ERROR_INVALID_POINTER; |
| 1029 | |
Jon Ashburn | 46d1f58 | 2015-01-28 11:01:35 -0700 | [diff] [blame] | 1030 | if (!icd) |
| 1031 | return XGL_ERROR_UNAVAILABLE; |
| 1032 | |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1033 | for (int i = 0; i < 16; i++) |
| 1034 | layers[i] = &layer_buf[i][0]; |
| 1035 | |
| 1036 | for (unsigned int j = 0; j < loader.scanned_layer_count && count < maxLayerCount; j++) { |
| 1037 | lib_name = loader.scanned_layer_names[j]; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1038 | // Used to call: dlopen(*lib_name, RTLD_LAZY) |
| 1039 | if ((handle = loader_platform_open_library(lib_name)) == NULL) |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1040 | continue; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1041 | if ((fpEnumerateLayers = loader_platform_get_proc_address(handle, "xglEnumerateLayers")) == NULL) { |
| 1042 | //use default layer name based on library name XGL_LAYER_LIBRARY_PREFIX<name>.XGL_LIBRARY_SUFFIX |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1043 | char *pEnd, *cpyStr; |
Ian Elliott | 4204584 | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 1044 | size_t siz; |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1045 | loader_platform_close_library(handle); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1046 | lib_name = basename(lib_name); |
| 1047 | pEnd = strrchr(lib_name, '.'); |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1048 | siz = (int) (pEnd - lib_name - strlen(XGL_LAYER_LIBRARY_PREFIX) + 1); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1049 | if (pEnd == NULL || siz <= 0) |
| 1050 | continue; |
| 1051 | cpyStr = malloc(siz); |
| 1052 | if (cpyStr == NULL) { |
| 1053 | free(cpyStr); |
| 1054 | continue; |
| 1055 | } |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1056 | strncpy(cpyStr, lib_name + strlen(XGL_LAYER_LIBRARY_PREFIX), siz); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1057 | cpyStr[siz - 1] = '\0'; |
| 1058 | if (siz > maxStringSize) |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1059 | siz = (int) maxStringSize; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1060 | strncpy((char *) (pOutLayers[count]), cpyStr, siz); |
| 1061 | pOutLayers[count][siz - 1] = '\0'; |
| 1062 | count++; |
| 1063 | free(cpyStr); |
| 1064 | } |
| 1065 | else { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1066 | size_t cnt; |
| 1067 | uint32_t n; |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1068 | XGL_RESULT res; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1069 | n = (uint32_t) ((maxStringSize < 256) ? maxStringSize : 256); |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1070 | res = fpEnumerateLayers(NULL, 16, n, &cnt, layers, (char *) icd->gpus + gpu_index); |
| 1071 | loader_platform_close_library(handle); |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1072 | if (res != XGL_SUCCESS) |
| 1073 | continue; |
| 1074 | if (cnt + count > maxLayerCount) |
| 1075 | cnt = maxLayerCount - count; |
Ian Elliott | 1962880 | 2015-02-04 12:06:46 -0700 | [diff] [blame] | 1076 | for (uint32_t i = (uint32_t) count; i < cnt + count; i++) { |
Jon Ashburn | 1323eb7 | 2014-12-02 13:03:09 -0700 | [diff] [blame] | 1077 | strncpy((char *) (pOutLayers[i]), (char *) layers[i - count], n); |
| 1078 | if (n > 0) |
| 1079 | pOutLayers[i - count][n - 1] = '\0'; |
| 1080 | } |
| 1081 | count += cnt; |
| 1082 | } |
| 1083 | } |
| 1084 | |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1085 | *pOutLayerCount = count; |
| 1086 | |
Jon Ashburn | f7bcf9b | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1087 | return XGL_SUCCESS; |
| 1088 | } |
| 1089 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1090 | LOADER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1091 | { |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1092 | const struct loader_icd *icd; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1093 | struct loader_instance *inst; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1094 | XGL_RESULT res; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1095 | uint32_t gpu_idx; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1096 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1097 | if (instance == XGL_NULL_HANDLE) |
| 1098 | return XGL_ERROR_INVALID_HANDLE; |
| 1099 | |
| 1100 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1101 | |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1102 | for (inst = loader.instances; inst; inst = inst->next) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1103 | if (inst == instance) |
| 1104 | break; |
| 1105 | } |
| 1106 | |
| 1107 | if (inst == XGL_NULL_HANDLE) |
| 1108 | return XGL_ERROR_INVALID_HANDLE; |
| 1109 | |
| 1110 | for (icd = inst->icds; icd; icd = icd->next) { |
| 1111 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 1112 | res = (icd->loader_dispatch + i)->DbgRegisterMsgCallback(icd->scanned_icds->instance, |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1113 | pfnMsgCallback, pUserData); |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1114 | if (res != XGL_SUCCESS) { |
| 1115 | gpu_idx = i; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1116 | break; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1117 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1118 | } |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1119 | if (res != XGL_SUCCESS) |
| 1120 | break; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1121 | } |
| 1122 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1123 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1124 | /* roll back on errors */ |
| 1125 | if (icd) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1126 | for (const struct loader_icd *tmp = inst->icds; tmp != icd; |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1127 | tmp = tmp->next) { |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1128 | for (uint32_t i = 0; i < icd->gpu_count; i++) |
| 1129 | (tmp->loader_dispatch + i)->DbgUnregisterMsgCallback(tmp->scanned_icds->instance, pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1130 | } |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1131 | /* and gpus on current icd */ |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1132 | for (uint32_t i = 0; i < gpu_idx; i++) |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1133 | (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(icd->scanned_icds->instance, pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1134 | |
| 1135 | return res; |
| 1136 | } |
| 1137 | |
| 1138 | return XGL_SUCCESS; |
| 1139 | } |
| 1140 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1141 | LOADER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_INSTANCE instance, XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1142 | { |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1143 | XGL_RESULT res = XGL_SUCCESS; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1144 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1145 | if (instance == XGL_NULL_HANDLE) |
| 1146 | return XGL_ERROR_INVALID_HANDLE; |
| 1147 | |
| 1148 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1149 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1150 | for (inst = loader.instances; inst; inst = inst->next) { |
| 1151 | if (inst == instance) |
| 1152 | break; |
| 1153 | } |
| 1154 | |
| 1155 | if (inst == XGL_NULL_HANDLE) |
| 1156 | return XGL_ERROR_INVALID_HANDLE; |
| 1157 | |
| 1158 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
| 1159 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 1160 | XGL_RESULT r; |
| 1161 | r = (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(icd->scanned_icds->instance, pfnMsgCallback); |
| 1162 | if (r != XGL_SUCCESS) { |
| 1163 | res = r; |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1164 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1165 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1166 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1167 | return res; |
| 1168 | } |
| 1169 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1170 | LOADER_EXPORT XGL_RESULT XGLAPI xglDbgSetGlobalOption(XGL_INSTANCE instance, XGL_DBG_GLOBAL_OPTION dbgOption, size_t dataSize, const void* pData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1171 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1172 | XGL_RESULT res = XGL_SUCCESS; |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1173 | struct loader_instance *inst; |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1174 | if (instance == XGL_NULL_HANDLE) |
| 1175 | return XGL_ERROR_INVALID_HANDLE; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1176 | |
Courtney Goeltzenleuchter | c80a557 | 2015-04-13 14:10:06 -0600 | [diff] [blame] | 1177 | assert(loader.icds_scanned); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1178 | |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1179 | for (inst = loader.instances; inst; inst = inst->next) { |
| 1180 | if (inst == instance) |
| 1181 | break; |
| 1182 | } |
| 1183 | |
| 1184 | if (inst == XGL_NULL_HANDLE) |
| 1185 | return XGL_ERROR_INVALID_HANDLE; |
| 1186 | for (const struct loader_icd * icd = inst->icds; icd; icd = icd->next) { |
| 1187 | for (uint32_t i = 0; i < icd->gpu_count; i++) { |
| 1188 | XGL_RESULT r; |
| 1189 | r = (icd->loader_dispatch + i)->DbgSetGlobalOption(icd->scanned_icds->instance, dbgOption, |
Jon Ashburn | 98bd454 | 2015-01-29 16:44:24 -0700 | [diff] [blame] | 1190 | dataSize, pData); |
Jon Ashburn | bb51025 | 2015-03-17 13:47:55 -0600 | [diff] [blame^] | 1191 | /* unfortunately we cannot roll back */ |
| 1192 | if (r != XGL_SUCCESS) { |
| 1193 | res = r; |
Jon Ashburn | 01e2d66 | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1194 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1195 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | return res; |
| 1199 | } |