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 | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 26 | * Jon Ashburn <jon@lunarg.com> |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 27 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 28 | */ |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 29 | #define _GNU_SOURCE |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <stdarg.h> |
| 33 | #include <stdbool.h> |
| 34 | #include <string.h> |
| 35 | |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 36 | #include <sys/types.h> |
| 37 | #include <dirent.h> |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 38 | #include <unistd.h> |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 39 | #include <dlfcn.h> |
| 40 | #include <pthread.h> |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 41 | #include <assert.h> |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 42 | #include "loader.h" |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 43 | |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 44 | typedef XGL_VOID (* SetDispatchType)(XGL_LAYER_DISPATCH_TABLE * disp, XGL_BOOL debug); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 45 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 46 | struct loader_layers { |
| 47 | void *lib_handle; |
| 48 | char lib_name[1024]; |
| 49 | }; |
| 50 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 51 | struct loader_icd { |
| 52 | void *handle; |
| 53 | |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 54 | XGL_LAYER_DISPATCH_TABLE *loader_dispatch; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 55 | XGL_UINT layer_count[XGL_MAX_PHYSICAL_GPUS]; |
| 56 | struct loader_layers layer_libs[XGL_MAX_PHYSICAL_GPUS][MAX_LAYER_LIBRARIES]; |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 57 | XGL_BASE_LAYER_OBJECT *wrappedGpus[XGL_MAX_PHYSICAL_GPUS]; |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 58 | XGL_UINT gpu_count; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 59 | XGL_BASE_LAYER_OBJECT *gpus; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 60 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 61 | GetProcAddrType GetProcAddr; |
| 62 | InitAndEnumerateGpusType InitAndEnumerateGpus; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 63 | SetDispatchType SetDispatch; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 64 | |
| 65 | struct loader_icd *next; |
| 66 | }; |
| 67 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 68 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 69 | struct loader_msg_callback { |
| 70 | XGL_DBG_MSG_CALLBACK_FUNCTION func; |
| 71 | XGL_VOID *data; |
| 72 | |
| 73 | struct loader_msg_callback *next; |
| 74 | }; |
| 75 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 76 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 77 | static struct { |
| 78 | bool scanned; |
| 79 | struct loader_icd *icds; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 80 | bool layer_scanned; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 81 | char layer_dirs[4096]; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 82 | unsigned int scanned_layer_count; |
| 83 | char *scanned_layer_names[MAX_LAYER_LIBRARIES]; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 84 | struct loader_msg_callback *msg_callbacks; |
| 85 | |
| 86 | bool debug_echo_enable; |
| 87 | bool break_on_error; |
| 88 | bool break_on_warning; |
| 89 | } loader; |
| 90 | |
| 91 | static XGL_RESULT loader_msg_callback_add(XGL_DBG_MSG_CALLBACK_FUNCTION func, |
| 92 | XGL_VOID *data) |
| 93 | { |
| 94 | struct loader_msg_callback *cb; |
| 95 | |
| 96 | cb = malloc(sizeof(*cb)); |
| 97 | if (!cb) |
| 98 | return XGL_ERROR_OUT_OF_MEMORY; |
| 99 | |
| 100 | cb->func = func; |
| 101 | cb->data = data; |
| 102 | |
| 103 | cb->next = loader.msg_callbacks; |
| 104 | loader.msg_callbacks = cb; |
| 105 | |
| 106 | return XGL_SUCCESS; |
| 107 | } |
| 108 | |
| 109 | static XGL_RESULT loader_msg_callback_remove(XGL_DBG_MSG_CALLBACK_FUNCTION func) |
| 110 | { |
| 111 | struct loader_msg_callback *cb = loader.msg_callbacks; |
| 112 | |
| 113 | /* |
| 114 | * Find the first match (last registered). |
| 115 | * |
| 116 | * XXX What if the same callback function is registered more than once? |
| 117 | */ |
| 118 | while (cb) { |
| 119 | if (cb->func == func) { |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | cb = cb->next; |
| 124 | } |
| 125 | |
| 126 | if (!cb) |
| 127 | return XGL_ERROR_INVALID_POINTER; |
| 128 | |
| 129 | free(cb); |
| 130 | |
| 131 | return XGL_SUCCESS; |
| 132 | } |
| 133 | |
| 134 | static void loader_msg_callback_clear(void) |
| 135 | { |
| 136 | struct loader_msg_callback *cb = loader.msg_callbacks; |
| 137 | |
| 138 | while (cb) { |
| 139 | struct loader_msg_callback *next = cb->next; |
| 140 | free(cb); |
| 141 | cb = next; |
| 142 | } |
| 143 | |
| 144 | loader.msg_callbacks = NULL; |
| 145 | } |
| 146 | |
| 147 | static void loader_log(XGL_DBG_MSG_TYPE msg_type, XGL_INT msg_code, |
| 148 | const char *format, ...) |
| 149 | { |
| 150 | const struct loader_msg_callback *cb = loader.msg_callbacks; |
| 151 | char msg[256]; |
| 152 | va_list ap; |
| 153 | int ret; |
| 154 | |
| 155 | va_start(ap, format); |
| 156 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
| 157 | if (ret >= sizeof(msg) || ret < 0) { |
| 158 | msg[sizeof(msg) - 1] = '\0'; |
| 159 | } |
| 160 | va_end(ap); |
| 161 | |
| 162 | if (loader.debug_echo_enable || !cb) { |
| 163 | fputs(msg, stderr); |
| 164 | fputc('\n', stderr); |
| 165 | } |
| 166 | |
| 167 | while (cb) { |
| 168 | cb->func(msg_type, XGL_VALIDATION_LEVEL_0, XGL_NULL_HANDLE, 0, |
| 169 | msg_code, (const XGL_CHAR *) msg, cb->data); |
| 170 | cb = cb->next; |
| 171 | } |
| 172 | |
| 173 | switch (msg_type) { |
| 174 | case XGL_DBG_MSG_ERROR: |
| 175 | if (loader.break_on_error) { |
| 176 | exit(1); |
| 177 | } |
| 178 | /* fall through */ |
| 179 | case XGL_DBG_MSG_WARNING: |
| 180 | if (loader.break_on_warning) { |
| 181 | exit(1); |
| 182 | } |
| 183 | break; |
| 184 | default: |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static void |
| 190 | loader_icd_destroy(struct loader_icd *icd) |
| 191 | { |
| 192 | dlclose(icd->handle); |
| 193 | free(icd); |
| 194 | } |
| 195 | |
| 196 | static struct loader_icd * |
| 197 | loader_icd_create(const char *filename) |
| 198 | { |
| 199 | struct loader_icd *icd; |
| 200 | |
| 201 | icd = malloc(sizeof(*icd)); |
| 202 | if (!icd) |
| 203 | return NULL; |
| 204 | |
Courtney Goeltzenleuchter | 6f92816 | 2014-10-28 10:29:27 -0600 | [diff] [blame] | 205 | memset(icd, 0, sizeof(*icd)); |
| 206 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 207 | icd->handle = dlopen(filename, RTLD_LAZY | RTLD_LOCAL); |
| 208 | if (!icd->handle) { |
| 209 | loader_log(XGL_DBG_MSG_WARNING, 0, dlerror()); |
| 210 | free(icd); |
| 211 | return NULL; |
| 212 | } |
| 213 | |
| 214 | #define LOOKUP(icd, func) do { \ |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 215 | icd->func = (func## Type) dlsym(icd->handle, "xgl" #func); \ |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 216 | if (!icd->func) { \ |
| 217 | loader_log(XGL_DBG_MSG_WARNING, 0, dlerror()); \ |
| 218 | loader_icd_destroy(icd); \ |
| 219 | return NULL; \ |
| 220 | } \ |
| 221 | } while (0) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 222 | LOOKUP(icd, GetProcAddr); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 223 | LOOKUP(icd, InitAndEnumerateGpus); |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 224 | LOOKUP(icd, SetDispatch); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 225 | #undef LOOKUP |
| 226 | |
| 227 | return icd; |
| 228 | } |
| 229 | |
| 230 | static XGL_RESULT loader_icd_register_msg_callbacks(const struct loader_icd *icd) |
| 231 | { |
| 232 | const struct loader_msg_callback *cb = loader.msg_callbacks; |
| 233 | XGL_RESULT res; |
| 234 | |
| 235 | while (cb) { |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 236 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) { |
| 237 | res = (icd->loader_dispatch + i)->DbgRegisterMsgCallback(cb->func, cb->data); |
| 238 | if (res != XGL_SUCCESS) { |
| 239 | break; |
| 240 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 241 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 242 | cb = cb->next; |
| 243 | } |
| 244 | |
| 245 | /* roll back on errors */ |
| 246 | if (cb) { |
| 247 | const struct loader_msg_callback *tmp = loader.msg_callbacks; |
| 248 | |
| 249 | while (tmp != cb) { |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 250 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) { |
| 251 | (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(cb->func); |
| 252 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 253 | tmp = tmp->next; |
| 254 | } |
| 255 | |
| 256 | return res; |
| 257 | } |
| 258 | |
| 259 | return XGL_SUCCESS; |
| 260 | } |
| 261 | |
| 262 | static XGL_RESULT loader_icd_set_global_options(const struct loader_icd *icd) |
| 263 | { |
| 264 | #define SETB(icd, opt, val) do { \ |
| 265 | if (val) { \ |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 266 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) { \ |
| 267 | const XGL_RESULT res = \ |
| 268 | (icd->loader_dispatch + i)->DbgSetGlobalOption(opt, sizeof(val), &val); \ |
| 269 | if (res != XGL_SUCCESS) \ |
| 270 | return res; \ |
| 271 | } \ |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 272 | } \ |
| 273 | } while (0) |
| 274 | SETB(icd, XGL_DBG_OPTION_DEBUG_ECHO_ENABLE, loader.debug_echo_enable); |
| 275 | SETB(icd, XGL_DBG_OPTION_BREAK_ON_ERROR, loader.break_on_error); |
| 276 | SETB(icd, XGL_DBG_OPTION_BREAK_ON_WARNING, loader.break_on_warning); |
| 277 | #undef SETB |
| 278 | |
| 279 | return XGL_SUCCESS; |
| 280 | } |
| 281 | |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 282 | static struct loader_icd *loader_icd_add(const char *filename) |
| 283 | { |
| 284 | struct loader_icd *icd; |
| 285 | |
| 286 | icd = loader_icd_create(filename); |
| 287 | if (!icd) |
| 288 | return NULL; |
| 289 | |
| 290 | if (loader_icd_set_global_options(icd) != XGL_SUCCESS || |
| 291 | loader_icd_register_msg_callbacks(icd) != XGL_SUCCESS) { |
| 292 | loader_log(XGL_DBG_MSG_WARNING, 0, |
| 293 | "%s ignored: failed to migrate settings", filename); |
| 294 | loader_icd_destroy(icd); |
| 295 | } |
| 296 | |
| 297 | /* prepend to the list */ |
| 298 | icd->next = loader.icds; |
| 299 | loader.icds = icd; |
| 300 | |
| 301 | return icd; |
| 302 | } |
| 303 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 304 | #ifndef DEFAULT_XGL_DRIVERS_PATH |
| 305 | // TODO: Is this a good default location? |
| 306 | // Need to search for both 32bit and 64bit ICDs |
| 307 | #define DEFAULT_XGL_DRIVERS_PATH "/usr/lib/i386-linux-gnu/xgl:/usr/lib/x86_64-linux-gnu/xgl" |
| 308 | #endif |
| 309 | |
| 310 | /** |
| 311 | * Try to \c loader_icd_scan XGL driver(s). |
| 312 | * |
| 313 | * This function scans the default system path or path |
| 314 | * specified by the \c LIBXGL_DRIVERS_PATH environment variable in |
| 315 | * order to find loadable XGL ICDs with the name of libXGL_*. |
| 316 | * |
| 317 | * \returns |
| 318 | * void; but side effect is to set loader_icd_scanned to true |
| 319 | */ |
| 320 | static void loader_icd_scan(void) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 321 | { |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 322 | const char *libPaths, *p, *next; |
| 323 | DIR *sysdir; |
| 324 | struct dirent *dent; |
| 325 | char icd_library[1024]; |
Jon Ashburn | 0f45b2a | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 326 | char path[1024]; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 327 | int len; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 328 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 329 | libPaths = NULL; |
| 330 | if (geteuid() == getuid()) { |
| 331 | /* don't allow setuid apps to use LIBXGL_DRIVERS_PATH */ |
| 332 | libPaths = getenv("LIBXGL_DRIVERS_PATH"); |
| 333 | } |
| 334 | if (libPaths == NULL) |
| 335 | libPaths = DEFAULT_XGL_DRIVERS_PATH; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 336 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 337 | for (p = libPaths; *p; p = next) { |
| 338 | next = strchr(p, ':'); |
| 339 | if (next == NULL) { |
| 340 | len = strlen(p); |
| 341 | next = p + len; |
| 342 | } |
| 343 | else { |
| 344 | len = next - p; |
Jon Ashburn | 0f45b2a | 2014-10-03 16:31:35 -0600 | [diff] [blame] | 345 | sprintf(path, "%.*s", (len > sizeof(path) - 1) ? (int) sizeof(path) - 1 : len, p); |
| 346 | p = path; |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 347 | next++; |
| 348 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 349 | |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 350 | sysdir = opendir(p); |
| 351 | if (sysdir) { |
| 352 | dent = readdir(sysdir); |
| 353 | while (dent) { |
| 354 | /* look for ICDs starting with "libXGL_" */ |
| 355 | if (!strncmp(dent->d_name, "libXGL_", 7)) { |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 356 | snprintf(icd_library, 1024, "%s/%s",p,dent->d_name); |
Chia-I Wu | 894a117 | 2014-08-04 11:18:20 +0800 | [diff] [blame] | 357 | loader_icd_add(icd_library); |
Courtney Goeltzenleuchter | 4af9bd1 | 2014-08-01 14:18:11 -0600 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | dent = readdir(sysdir); |
| 361 | } |
| 362 | closedir(sysdir); |
| 363 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* we have nothing to log anymore */ |
| 367 | loader_msg_callback_clear(); |
| 368 | |
| 369 | loader.scanned = true; |
| 370 | } |
| 371 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 372 | #ifndef DEFAULT_XGL_LAYERS_PATH |
| 373 | // TODO: Is this a good default locations |
| 374 | #define DEFAULT_XGL_LAYERS_PATH ".:/usr/lib/i386-linux-gnu/xgl:/usr/lib/x86_64-linux-gnu/xgl" |
| 375 | #endif |
| 376 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 377 | static void layer_lib_scan(const char * libInPaths, const bool useDefaultDirs) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 378 | { |
| 379 | const char *p, *next; |
| 380 | char *libPaths = &loader.layer_dirs[0]; |
| 381 | DIR *curdir; |
| 382 | struct dirent *dent; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 383 | int len, i; |
| 384 | char temp_str[1024]; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 385 | |
| 386 | if (libInPaths){ |
| 387 | strncpy(libPaths, libInPaths, sizeof(loader.layer_dirs)); |
| 388 | } |
| 389 | else { |
| 390 | *libPaths = '\0'; |
| 391 | } |
| 392 | |
| 393 | /* cleanup any previously scanned libraries */ |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 394 | for (i = 0; i < loader.scanned_layer_count; i++) { |
| 395 | if (loader.scanned_layer_names[i] != NULL) |
| 396 | free(loader.scanned_layer_names[i]); |
| 397 | loader.scanned_layer_names[i] = NULL; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 398 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 399 | loader.scanned_layer_count = 0; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 400 | |
| 401 | if (useDefaultDirs) |
| 402 | strncat(libPaths, DEFAULT_XGL_LAYERS_PATH, sizeof(loader.layer_dirs) - sizeof(DEFAULT_XGL_LAYERS_PATH)); |
| 403 | |
| 404 | for (p = libPaths; *p; p = next) { |
| 405 | next = strchr(p, ':'); |
| 406 | if (next == NULL) { |
| 407 | len = strlen(p); |
| 408 | next = p + len; |
| 409 | } |
| 410 | else { |
| 411 | len = next - p; |
| 412 | *(char *) next = '\0'; |
| 413 | next++; |
| 414 | } |
| 415 | |
| 416 | curdir = opendir(p); |
| 417 | if (curdir) { |
| 418 | dent = readdir(curdir); |
| 419 | while (dent) { |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 420 | /* look for wrappers starting with "libXGLlayer" */ |
| 421 | if (!strncmp(dent->d_name, "libXGLLayer", strlen("libXGLLayer"))) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 422 | void * handle; |
| 423 | snprintf(temp_str, sizeof(temp_str), "%s/%s",p,dent->d_name); |
| 424 | if ((handle = dlopen((const char *) temp_str, RTLD_LAZY)) == NULL) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 425 | continue; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 426 | if (loader.scanned_layer_count == MAX_LAYER_LIBRARIES) { |
| 427 | loader_log(XGL_DBG_MSG_ERROR, 0, "%s ignored: max layer libraries exceed", temp_str); |
| 428 | break; |
| 429 | } |
| 430 | if ((loader.scanned_layer_names[loader.scanned_layer_count] = malloc(strlen(temp_str) + 1)) == NULL) { |
| 431 | loader_log(XGL_DBG_MSG_ERROR, 0, "%s ignored: out of memory", temp_str); |
| 432 | break; |
| 433 | } |
| 434 | strcpy(loader.scanned_layer_names[loader.scanned_layer_count], temp_str); |
| 435 | loader.scanned_layer_count++; |
| 436 | dlclose(handle); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | dent = readdir(curdir); |
| 440 | } |
| 441 | closedir(curdir); |
| 442 | } |
| 443 | } |
| 444 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 445 | loader.layer_scanned = true; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 446 | } |
| 447 | |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 448 | static void loader_init_dispatch_table(XGL_LAYER_DISPATCH_TABLE *tab, GetProcAddrType fpGPA, XGL_PHYSICAL_GPU gpu) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 449 | { |
| 450 | tab->GetProcAddr = fpGPA; |
| 451 | tab->InitAndEnumerateGpus = fpGPA(gpu, (const XGL_CHAR *) "xglInitAndEnumerateGpus"); |
| 452 | tab->GetGpuInfo = fpGPA(gpu, (const XGL_CHAR *) "xglGetGpuInfo"); |
| 453 | tab->CreateDevice = fpGPA(gpu, (const XGL_CHAR *) "xglCreateDevice"); |
| 454 | tab->DestroyDevice = fpGPA(gpu, (const XGL_CHAR *) "xglDestroyDevice"); |
| 455 | tab->GetExtensionSupport = fpGPA(gpu, (const XGL_CHAR *) "xglGetExtensionSupport"); |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 456 | tab->EnumerateLayers = fpGPA(gpu, (const XGL_CHAR *) "xglEnumerateLayers"); |
| 457 | if (tab->EnumerateLayers == NULL) |
| 458 | tab->EnumerateLayers = xglEnumerateLayers; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 459 | tab->GetDeviceQueue = fpGPA(gpu, (const XGL_CHAR *) "xglGetDeviceQueue"); |
| 460 | tab->QueueSubmit = fpGPA(gpu, (const XGL_CHAR *) "xglQueueSubmit"); |
| 461 | tab->QueueSetGlobalMemReferences = fpGPA(gpu, (const XGL_CHAR *) "xglQueueSetGlobalMemReferences"); |
| 462 | tab->QueueWaitIdle = fpGPA(gpu, (const XGL_CHAR *) "xglQueueWaitIdle"); |
| 463 | tab->DeviceWaitIdle = fpGPA(gpu, (const XGL_CHAR *) "xglDeviceWaitIdle"); |
| 464 | tab->GetMemoryHeapCount = fpGPA(gpu, (const XGL_CHAR *) "xglGetMemoryHeapCount"); |
| 465 | tab->GetMemoryHeapInfo = fpGPA(gpu, (const XGL_CHAR *) "xglGetMemoryHeapInfo"); |
| 466 | tab->AllocMemory = fpGPA(gpu, (const XGL_CHAR *) "xglAllocMemory"); |
| 467 | tab->FreeMemory = fpGPA(gpu, (const XGL_CHAR *) "xglFreeMemory"); |
| 468 | tab->SetMemoryPriority = fpGPA(gpu, (const XGL_CHAR *) "xglSetMemoryPriority"); |
| 469 | tab->MapMemory = fpGPA(gpu, (const XGL_CHAR *) "xglMapMemory"); |
| 470 | tab->UnmapMemory = fpGPA(gpu, (const XGL_CHAR *) "xglUnmapMemory"); |
| 471 | tab->PinSystemMemory = fpGPA(gpu, (const XGL_CHAR *) "xglPinSystemMemory"); |
| 472 | tab->RemapVirtualMemoryPages = fpGPA(gpu, (const XGL_CHAR *) "xglRemapVirtualMemoryPages"); |
| 473 | tab->GetMultiGpuCompatibility = fpGPA(gpu, (const XGL_CHAR *) "xglGetMultiGpuCompatibility"); |
| 474 | tab->OpenSharedMemory = fpGPA(gpu, (const XGL_CHAR *) "xglOpenSharedMemory"); |
| 475 | tab->OpenSharedQueueSemaphore = fpGPA(gpu, (const XGL_CHAR *) "xglOpenSharedQueueSemaphore"); |
| 476 | tab->OpenPeerMemory = fpGPA(gpu, (const XGL_CHAR *) "xglOpenPeerMemory"); |
| 477 | tab->OpenPeerImage = fpGPA(gpu, (const XGL_CHAR *) "xglOpenPeerImage"); |
| 478 | tab->DestroyObject = fpGPA(gpu, (const XGL_CHAR *) "xglDestroyObject"); |
| 479 | tab->GetObjectInfo = fpGPA(gpu, (const XGL_CHAR *) "xglGetObjectInfo"); |
| 480 | tab->BindObjectMemory = fpGPA(gpu, (const XGL_CHAR *) "xglBindObjectMemory"); |
| 481 | tab->CreateFence = fpGPA(gpu, (const XGL_CHAR *) "xglCreateFence"); |
| 482 | tab->GetFenceStatus = fpGPA(gpu, (const XGL_CHAR *) "xglGetFenceStatus"); |
| 483 | tab->WaitForFences = fpGPA(gpu, (const XGL_CHAR *) "xglWaitForFences"); |
| 484 | tab->CreateQueueSemaphore = fpGPA(gpu, (const XGL_CHAR *) "xglCreateQueueSemaphore"); |
| 485 | tab->SignalQueueSemaphore = fpGPA(gpu, (const XGL_CHAR *) "xglSignalQueueSemaphore"); |
| 486 | tab->WaitQueueSemaphore = fpGPA(gpu, (const XGL_CHAR *) "xglWaitQueueSemaphore"); |
| 487 | tab->CreateEvent = fpGPA(gpu, (const XGL_CHAR *) "xglCreateEvent"); |
| 488 | tab->GetEventStatus = fpGPA(gpu, (const XGL_CHAR *) "xglGetEventStatus"); |
| 489 | tab->SetEvent = fpGPA(gpu, (const XGL_CHAR *) "xglSetEvent"); |
| 490 | tab->ResetEvent = fpGPA(gpu, (const XGL_CHAR *) "xglResetEvent"); |
| 491 | tab->CreateQueryPool = fpGPA(gpu, (const XGL_CHAR *) "xglCreateQueryPool"); |
| 492 | tab->GetQueryPoolResults = fpGPA(gpu, (const XGL_CHAR *) "xglGetQueryPoolResults"); |
| 493 | tab->GetFormatInfo = fpGPA(gpu, (const XGL_CHAR *) "xglGetFormatInfo"); |
| 494 | tab->CreateImage = fpGPA(gpu, (const XGL_CHAR *) "xglCreateImage"); |
| 495 | tab->GetImageSubresourceInfo = fpGPA(gpu, (const XGL_CHAR *) "xglGetImageSubresourceInfo"); |
| 496 | tab->CreateImageView = fpGPA(gpu, (const XGL_CHAR *) "xglCreateImageView"); |
| 497 | tab->CreateColorAttachmentView = fpGPA(gpu, (const XGL_CHAR *) "xglCreateColorAttachmentView"); |
| 498 | tab->CreateDepthStencilView = fpGPA(gpu, (const XGL_CHAR *) "xglCreateDepthStencilView"); |
| 499 | tab->CreateShader = fpGPA(gpu, (const XGL_CHAR *) "xglCreateShader"); |
| 500 | tab->CreateGraphicsPipeline = fpGPA(gpu, (const XGL_CHAR *) "xglCreateGraphicsPipeline"); |
| 501 | tab->CreateComputePipeline = fpGPA(gpu, (const XGL_CHAR *) "xglCreateComputePipeline"); |
| 502 | tab->StorePipeline = fpGPA(gpu, (const XGL_CHAR *) "xglStorePipeline"); |
| 503 | tab->LoadPipeline = fpGPA(gpu, (const XGL_CHAR *) "xglLoadPipeline"); |
| 504 | tab->CreatePipelineDelta = fpGPA(gpu, (const XGL_CHAR *) "xglCreatePipelineDelta"); |
| 505 | tab->CreateSampler = fpGPA(gpu, (const XGL_CHAR *) "xglCreateSampler"); |
| 506 | tab->CreateDescriptorSet = fpGPA(gpu, (const XGL_CHAR *) "xglCreateDescriptorSet"); |
| 507 | tab->BeginDescriptorSetUpdate = fpGPA(gpu, (const XGL_CHAR *) "xglBeginDescriptorSetUpdate"); |
| 508 | tab->EndDescriptorSetUpdate = fpGPA(gpu, (const XGL_CHAR *) "xglEndDescriptorSetUpdate"); |
| 509 | tab->AttachSamplerDescriptors = fpGPA(gpu, (const XGL_CHAR *) "xglAttachSamplerDescriptors"); |
| 510 | tab->AttachImageViewDescriptors = fpGPA(gpu, (const XGL_CHAR *) "xglAttachImageViewDescriptors"); |
| 511 | tab->AttachMemoryViewDescriptors = fpGPA(gpu, (const XGL_CHAR *) "xglAttachMemoryViewDescriptors"); |
| 512 | tab->AttachNestedDescriptors = fpGPA(gpu, (const XGL_CHAR *) "xglAttachNestedDescriptors"); |
| 513 | tab->ClearDescriptorSetSlots = fpGPA(gpu, (const XGL_CHAR *) "xglClearDescriptorSetSlots"); |
| 514 | tab->CreateViewportState = fpGPA(gpu, (const XGL_CHAR *) "xglCreateViewportState"); |
| 515 | tab->CreateRasterState = fpGPA(gpu, (const XGL_CHAR *) "xglCreateRasterState"); |
| 516 | tab->CreateMsaaState = fpGPA(gpu, (const XGL_CHAR *) "xglCreateMsaaState"); |
| 517 | tab->CreateColorBlendState = fpGPA(gpu, (const XGL_CHAR *) "xglCreateColorBlendState"); |
| 518 | tab->CreateDepthStencilState = fpGPA(gpu, (const XGL_CHAR *) "xglCreateDepthStencilState"); |
| 519 | tab->CreateCommandBuffer = fpGPA(gpu, (const XGL_CHAR *) "xglCreateCommandBuffer"); |
| 520 | tab->BeginCommandBuffer = fpGPA(gpu, (const XGL_CHAR *) "xglBeginCommandBuffer"); |
| 521 | tab->EndCommandBuffer = fpGPA(gpu, (const XGL_CHAR *) "xglEndCommandBuffer"); |
| 522 | tab->ResetCommandBuffer = fpGPA(gpu, (const XGL_CHAR *) "xglResetCommandBuffer"); |
| 523 | tab->CmdBindPipeline = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindPipeline"); |
| 524 | tab->CmdBindPipelineDelta = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindPipelineDelta"); |
| 525 | tab->CmdBindStateObject = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindStateObject"); |
| 526 | tab->CmdBindDescriptorSet = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindDescriptorSet"); |
| 527 | tab->CmdBindDynamicMemoryView = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindDynamicMemoryView"); |
Chia-I Wu | 3b04af5 | 2014-11-08 10:48:20 +0800 | [diff] [blame] | 528 | tab->CmdBindVertexData = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindVertexData"); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 529 | tab->CmdBindIndexData = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindIndexData"); |
| 530 | tab->CmdBindAttachments = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBindAttachments"); |
| 531 | tab->CmdPrepareMemoryRegions = fpGPA(gpu, (const XGL_CHAR *) "xglCmdPrepareMemoryRegions"); |
| 532 | tab->CmdPrepareImages = fpGPA(gpu, (const XGL_CHAR *) "xglCmdPrepareImages"); |
| 533 | tab->CmdDraw = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDraw"); |
| 534 | tab->CmdDrawIndexed = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDrawIndexed"); |
| 535 | tab->CmdDrawIndirect = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDrawIndirect"); |
| 536 | tab->CmdDrawIndexedIndirect = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDrawIndexedIndirect"); |
| 537 | tab->CmdDispatch = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDispatch"); |
| 538 | tab->CmdDispatchIndirect = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDispatchIndirect"); |
| 539 | tab->CmdCopyMemory = fpGPA(gpu, (const XGL_CHAR *) "xglCmdCopyMemory"); |
| 540 | tab->CmdCopyImage = fpGPA(gpu, (const XGL_CHAR *) "xglCmdCopyImage"); |
| 541 | tab->CmdCopyMemoryToImage = fpGPA(gpu, (const XGL_CHAR *) "xglCmdCopyMemoryToImage"); |
| 542 | tab->CmdCopyImageToMemory = fpGPA(gpu, (const XGL_CHAR *) "xglCmdCopyImageToMemory"); |
| 543 | tab->CmdCloneImageData = fpGPA(gpu, (const XGL_CHAR *) "xglCmdCloneImageData"); |
| 544 | tab->CmdUpdateMemory = fpGPA(gpu, (const XGL_CHAR *) "xglCmdUpdateMemory"); |
| 545 | tab->CmdFillMemory = fpGPA(gpu, (const XGL_CHAR *) "xglCmdFillMemory"); |
| 546 | tab->CmdClearColorImage = fpGPA(gpu, (const XGL_CHAR *) "xglCmdClearColorImage"); |
| 547 | tab->CmdClearColorImageRaw = fpGPA(gpu, (const XGL_CHAR *) "xglCmdClearColorImageRaw"); |
| 548 | tab->CmdClearDepthStencil = fpGPA(gpu, (const XGL_CHAR *) "xglCmdClearDepthStencil"); |
| 549 | tab->CmdResolveImage = fpGPA(gpu, (const XGL_CHAR *) "xglCmdResolveImage"); |
| 550 | tab->CmdSetEvent = fpGPA(gpu, (const XGL_CHAR *) "xglCmdSetEvent"); |
| 551 | tab->CmdResetEvent = fpGPA(gpu, (const XGL_CHAR *) "xglCmdResetEvent"); |
| 552 | tab->CmdMemoryAtomic = fpGPA(gpu, (const XGL_CHAR *) "xglCmdMemoryAtomic"); |
| 553 | tab->CmdBeginQuery = fpGPA(gpu, (const XGL_CHAR *) "xglCmdBeginQuery"); |
| 554 | tab->CmdEndQuery = fpGPA(gpu, (const XGL_CHAR *) "xglCmdEndQuery"); |
| 555 | tab->CmdResetQueryPool = fpGPA(gpu, (const XGL_CHAR *) "xglCmdResetQueryPool"); |
| 556 | tab->CmdWriteTimestamp = fpGPA(gpu, (const XGL_CHAR *) "xglCmdWriteTimestamp"); |
| 557 | tab->CmdInitAtomicCounters = fpGPA(gpu, (const XGL_CHAR *) "xglCmdInitAtomicCounters"); |
| 558 | tab->CmdLoadAtomicCounters = fpGPA(gpu, (const XGL_CHAR *) "xglCmdLoadAtomicCounters"); |
| 559 | tab->CmdSaveAtomicCounters = fpGPA(gpu, (const XGL_CHAR *) "xglCmdSaveAtomicCounters"); |
| 560 | tab->DbgSetValidationLevel = fpGPA(gpu, (const XGL_CHAR *) "xglDbgSetValidationLevel"); |
| 561 | tab->DbgRegisterMsgCallback = fpGPA(gpu, (const XGL_CHAR *) "xglDbgRegisterMsgCallback"); |
| 562 | tab->DbgUnregisterMsgCallback = fpGPA(gpu, (const XGL_CHAR *) "xglDbgUnregisterMsgCallback"); |
| 563 | tab->DbgSetMessageFilter = fpGPA(gpu, (const XGL_CHAR *) "xglDbgSetMessageFilter"); |
| 564 | tab->DbgSetObjectTag = fpGPA(gpu, (const XGL_CHAR *) "xglDbgSetObjectTag"); |
| 565 | tab->DbgSetGlobalOption = fpGPA(gpu, (const XGL_CHAR *) "xglDbgSetGlobalOption"); |
| 566 | tab->DbgSetDeviceOption = fpGPA(gpu, (const XGL_CHAR *) "xglDbgSetDeviceOption"); |
| 567 | tab->CmdDbgMarkerBegin = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDbgMarkerBegin"); |
| 568 | tab->CmdDbgMarkerEnd = fpGPA(gpu, (const XGL_CHAR *) "xglCmdDbgMarkerEnd"); |
| 569 | tab->WsiX11AssociateConnection = fpGPA(gpu, (const XGL_CHAR *) "xglWsiX11AssociateConnection"); |
| 570 | tab->WsiX11GetMSC = fpGPA(gpu, (const XGL_CHAR *) "xglWsiX11GetMSC"); |
| 571 | tab->WsiX11CreatePresentableImage = fpGPA(gpu, (const XGL_CHAR *) "xglWsiX11CreatePresentableImage"); |
| 572 | tab->WsiX11QueuePresent = fpGPA(gpu, (const XGL_CHAR *) "xglWsiX11QueuePresent"); |
| 573 | } |
| 574 | |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 575 | static struct loader_icd * loader_get_icd(const XGL_BASE_LAYER_OBJECT *gpu, XGL_UINT *gpu_index) |
| 576 | { |
| 577 | for (struct loader_icd * icd = loader.icds; icd; icd = icd->next) { |
| 578 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 579 | if ((icd->gpus + i) == gpu || (icd->gpus +i)->baseObject == gpu->baseObject) { |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 580 | *gpu_index = i; |
| 581 | return icd; |
| 582 | } |
| 583 | } |
| 584 | return NULL; |
| 585 | } |
| 586 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 587 | static bool loader_layers_activated(const struct loader_icd *icd, const XGL_UINT gpu_index) |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 588 | { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 589 | if (icd->layer_count[gpu_index]) |
| 590 | return true; |
| 591 | else |
| 592 | return false; |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 593 | } |
| 594 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 595 | static void loader_init_layer_libs(struct loader_icd *icd, XGL_UINT gpu_index, XGL_CHAR ** ppLayerNames, XGL_UINT count) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 596 | { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 597 | if (!icd) |
| 598 | return; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 599 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 600 | struct loader_layers *obj; |
| 601 | bool foundLib; |
| 602 | for (XGL_UINT i = 0; i < count; i++) { |
| 603 | foundLib = false; |
| 604 | for (XGL_UINT j = 0; j < icd->layer_count[gpu_index]; j++) { |
| 605 | if (icd->layer_libs[gpu_index][j].lib_handle && !strcmp(icd->layer_libs[gpu_index][j].lib_name, (char *) ppLayerNames[i])) { |
| 606 | foundLib = true; |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | if (!foundLib) { |
| 611 | obj = &(icd->layer_libs[gpu_index][i]); |
| 612 | strncpy(obj->lib_name, (char *) ppLayerNames[i], sizeof(obj->lib_name) - 1); |
| 613 | obj->lib_name[sizeof(obj->lib_name) - 1] = '\0'; |
| 614 | if ((obj->lib_handle = dlopen(obj->lib_name, RTLD_LAZY | RTLD_DEEPBIND)) == NULL) { |
| 615 | loader_log(XGL_DBG_MSG_ERROR, 0, "Failed to open layer library %s got error %d", obj->lib_name, dlerror()); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 616 | continue; |
| 617 | } else { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 618 | loader_log(XGL_DBG_MSG_UNKNOWN, 0, "Inserting layer lib %s", obj->lib_name); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 619 | } |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 620 | free(ppLayerNames[i]); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 621 | icd->layer_count[gpu_index]++; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 622 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 623 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 624 | } |
| 625 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 626 | static XGL_UINT loader_get_layer_env(XGL_CHAR * *ppLayerNames) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 627 | { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 628 | const char *layerEnv; |
| 629 | XGL_UINT len, count = 0; |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 630 | char *p, *pOrig, *next, *name; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 631 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 632 | layerEnv = getenv("LIBXGL_LAYER_LIBS"); |
Jon Ashburn | 4fbcb03 | 2014-10-23 10:29:09 -0600 | [diff] [blame] | 633 | if (!layerEnv) |
| 634 | return 0; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 635 | p = malloc(strlen(layerEnv) + 1); |
| 636 | if (!p) |
| 637 | return 0; |
| 638 | strcpy(p, layerEnv); |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 639 | pOrig = p; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 640 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 641 | while (p && *p && count < MAX_LAYER_LIBRARIES) { |
| 642 | bool foundScanned = false; |
| 643 | unsigned int j; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 644 | next = strchr(p, ':'); |
| 645 | if (next == NULL) { |
| 646 | len = strlen(p); |
| 647 | next = p + len; |
| 648 | } |
| 649 | else { |
| 650 | len = next - p; |
| 651 | *(char *) next = '\0'; |
| 652 | next++; |
| 653 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 654 | name = basename(p); |
| 655 | for (j = 0; j < loader.scanned_layer_count; j++) { |
| 656 | if (!strcmp(basename(loader.scanned_layer_names[j]), name)) { |
| 657 | foundScanned = true; |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | if (!foundScanned) { |
| 662 | p = next; |
| 663 | continue; |
| 664 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 665 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 666 | //copy to convert any dir path differences between scanned and base names |
| 667 | len = strlen(loader.scanned_layer_names[j]); |
| 668 | ppLayerNames[count] = malloc(len + 1); |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 669 | if (!ppLayerNames[count]) { |
| 670 | free(pOrig); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 671 | return count; |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 672 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 673 | strncpy((char *) ppLayerNames[count], loader.scanned_layer_names[j], len); |
| 674 | ppLayerNames[count][len] = '\0'; |
| 675 | count++; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 676 | p = next; |
| 677 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 678 | }; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 679 | |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 680 | free(pOrig); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 681 | return count; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 682 | } |
| 683 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 684 | static XGL_UINT loader_get_layer_libs(const XGL_DEVICE_CREATE_INFO* pCreateInfo, XGL_CHAR *** ppLayerNames) |
| 685 | { |
| 686 | static XGL_CHAR *layerNames[MAX_LAYER_LIBRARIES]; |
| 687 | |
| 688 | *ppLayerNames = &layerNames[0]; |
| 689 | if (!pCreateInfo) { |
| 690 | return loader_get_layer_env(layerNames); |
| 691 | } |
| 692 | |
| 693 | XGL_LAYER_CREATE_INFO *pCi = (XGL_LAYER_CREATE_INFO *) pCreateInfo->pNext; |
| 694 | |
| 695 | while (pCi) { |
| 696 | if (pCi->sType == XGL_STRUCTURE_TYPE_LAYER_CREATE_INFO) { |
| 697 | const char *name; |
| 698 | XGL_UINT len; |
| 699 | unsigned int j; |
| 700 | for (XGL_UINT i = 0; i < pCi->layerCount; i++) { |
| 701 | bool foundScanned = false; |
| 702 | name = (const char *) *(pCi->ppActiveLayerNames + i); |
| 703 | for (j = 0; j < loader.scanned_layer_count; j++) { |
| 704 | if (!strcmp(basename(loader.scanned_layer_names[j]), basename(name))) { |
| 705 | foundScanned = true; |
| 706 | break; |
| 707 | } |
| 708 | } |
| 709 | if (!foundScanned) |
| 710 | return loader_get_layer_env(layerNames); |
| 711 | //copy to convert any dir path differences between scanned and base names |
| 712 | len = strlen(loader.scanned_layer_names[j]); |
| 713 | layerNames[i] = malloc(len + 1); |
| 714 | if (!layerNames[i]) |
| 715 | return i; |
| 716 | strncpy((char *) layerNames[i], loader.scanned_layer_names[j], len); |
| 717 | layerNames[i][len] = '\0'; |
| 718 | } |
| 719 | return pCi->layerCount; |
| 720 | } |
| 721 | pCi = pCi->pNext; |
| 722 | } |
| 723 | return loader_get_layer_env(layerNames); |
| 724 | } |
| 725 | |
| 726 | static void loader_deactivate_layer() |
| 727 | { |
| 728 | struct loader_icd *icd; |
| 729 | struct loader_layers *libs; |
| 730 | |
| 731 | for (icd = loader.icds; icd; icd = icd->next) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 732 | if (icd->gpus) |
| 733 | free(icd->gpus); |
| 734 | icd->gpus = NULL; |
| 735 | if (icd->loader_dispatch) |
| 736 | free(icd->loader_dispatch); |
| 737 | icd->loader_dispatch = NULL; |
| 738 | icd->SetDispatch(NULL, true); |
| 739 | for (XGL_UINT j = 0; j < icd->gpu_count; j++) { |
| 740 | if (icd->layer_count[j] > 0) { |
| 741 | for (XGL_UINT i = 0; i < icd->layer_count[j]; i++) { |
| 742 | libs = &(icd->layer_libs[j][i]); |
| 743 | if (libs->lib_handle) |
| 744 | dlclose(libs->lib_handle); |
| 745 | libs->lib_handle = NULL; |
| 746 | } |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 747 | if (icd->wrappedGpus[j]) |
| 748 | free(icd->wrappedGpus[j]); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 749 | } |
| 750 | icd->layer_count[j] = 0; |
| 751 | } |
| 752 | icd->gpu_count = 0; |
| 753 | } |
| 754 | } |
| 755 | |
Jon Ashburn | 1005333 | 2014-11-17 10:17:37 -0700 | [diff] [blame^] | 756 | extern XGL_UINT loader_activate_layers(XGL_PHYSICAL_GPU gpu, const XGL_DEVICE_CREATE_INFO* pCreateInfo) |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 757 | { |
| 758 | XGL_UINT gpu_index; |
| 759 | XGL_UINT count; |
| 760 | XGL_CHAR ** ppLayerNames; |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 761 | struct loader_icd *icd = loader_get_icd((const XGL_BASE_LAYER_OBJECT *) gpu, &gpu_index); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 762 | |
| 763 | if (!icd) |
| 764 | return 0; |
| 765 | assert(gpu_index < XGL_MAX_PHYSICAL_GPUS); |
| 766 | |
| 767 | /* activate any layer libraries */ |
| 768 | if (!loader_layers_activated(icd, gpu_index)) { |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 769 | XGL_BASE_LAYER_OBJECT *gpuObj = (XGL_BASE_LAYER_OBJECT *) gpu; |
| 770 | XGL_BASE_LAYER_OBJECT *nextGpuObj, *baseObj = gpuObj->baseObject; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 771 | GetProcAddrType nextGPA = xglGetProcAddr; |
| 772 | |
| 773 | count = loader_get_layer_libs(pCreateInfo, &ppLayerNames); |
| 774 | if (!count) |
| 775 | return 0; |
| 776 | loader_init_layer_libs(icd, gpu_index, ppLayerNames, count); |
| 777 | |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 778 | icd->wrappedGpus[gpu_index] = malloc(sizeof(XGL_BASE_LAYER_OBJECT) * icd->layer_count[gpu_index]); |
| 779 | if (! icd->wrappedGpus[gpu_index]) |
| 780 | loader_log(XGL_DBG_MSG_ERROR, 0, "Failed to malloc Gpu objects for layer"); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 781 | for (XGL_INT i = icd->layer_count[gpu_index] - 1; i >= 0; i--) { |
Jon Ashburn | b4d0053 | 2014-10-22 21:15:26 -0600 | [diff] [blame] | 782 | nextGpuObj = (icd->wrappedGpus[gpu_index] + i); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 783 | nextGpuObj->pGPA = nextGPA; |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 784 | nextGpuObj->baseObject = baseObj; |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 785 | nextGpuObj->nextObject = gpuObj; |
| 786 | gpuObj = nextGpuObj; |
| 787 | |
| 788 | nextGPA = dlsym(icd->layer_libs[gpu_index][i].lib_handle, "xglGetProcAddr"); |
| 789 | if (!nextGPA) { |
| 790 | loader_log(XGL_DBG_MSG_ERROR, 0, "Failed to find xglGetProcAddr in layer %s", icd->layer_libs[gpu_index][i].lib_name); |
| 791 | continue; |
| 792 | } |
| 793 | |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 794 | if (i == 0) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 795 | loader_init_dispatch_table(icd->loader_dispatch + gpu_index, nextGPA, gpuObj); |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 796 | //Insert the new wrapped objects into the list with loader object at head |
| 797 | ((XGL_BASE_LAYER_OBJECT *) gpu)->nextObject = gpuObj; |
| 798 | ((XGL_BASE_LAYER_OBJECT *) gpu)->pGPA = nextGPA; |
| 799 | gpuObj = icd->wrappedGpus[gpu_index] + icd->layer_count[gpu_index] - 1; |
| 800 | gpuObj->nextObject = baseObj; |
| 801 | gpuObj->pGPA = icd->GetProcAddr; |
| 802 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 803 | |
| 804 | } |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 805 | } |
| 806 | else { |
| 807 | //make sure requested Layers matches currently activated Layers |
| 808 | count = loader_get_layer_libs(pCreateInfo, &ppLayerNames); |
| 809 | for (XGL_UINT i = 0; i < count; i++) { |
| 810 | if (strcmp(icd->layer_libs[gpu_index][i].lib_name, (char *) *(ppLayerNames + i))) { |
| 811 | loader_log(XGL_DBG_MSG_ERROR, 0, "Layers activated != Layers requested"); |
| 812 | break; |
| 813 | } |
| 814 | } |
| 815 | if (count != icd->layer_count[gpu_index]) { |
| 816 | loader_log(XGL_DBG_MSG_ERROR, 0, "Number of Layers activated!= number requested"); |
| 817 | } |
| 818 | } |
| 819 | return icd->layer_count[gpu_index]; |
| 820 | } |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 821 | |
Jon Ashburn | 2173494 | 2014-10-17 15:31:22 -0600 | [diff] [blame] | 822 | LOADER_EXPORT XGL_VOID * XGLAPI xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const XGL_CHAR * pName) { |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 823 | |
| 824 | if (gpu == NULL) |
| 825 | return NULL; |
Jon Ashburn | 8eecd42 | 2014-10-22 12:42:13 -0600 | [diff] [blame] | 826 | XGL_BASE_LAYER_OBJECT* gpuw = (XGL_BASE_LAYER_OBJECT *) gpu; |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 827 | XGL_LAYER_DISPATCH_TABLE * disp_table = * (XGL_LAYER_DISPATCH_TABLE **) gpuw->baseObject; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 828 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 829 | if (disp_table == NULL) |
| 830 | return NULL; |
| 831 | |
| 832 | if (!strncmp("xglGetProcAddr", (const char *) pName, sizeof("xglGetProcAddr"))) |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 833 | return disp_table->GetProcAddr; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 834 | else if (!strncmp("xglInitAndEnumerateGpus", (const char *) pName, sizeof("xglInitAndEnumerateGpus"))) |
| 835 | return disp_table->InitAndEnumerateGpus; |
| 836 | else if (!strncmp("xglGetGpuInfo", (const char *) pName, sizeof ("xglGetGpuInfo"))) |
| 837 | return disp_table->GetGpuInfo; |
| 838 | else if (!strncmp("xglCreateDevice", (const char *) pName, sizeof ("xglCreateDevice"))) |
| 839 | return disp_table->CreateDevice; |
| 840 | else if (!strncmp("xglDestroyDevice", (const char *) pName, sizeof ("xglDestroyDevice"))) |
| 841 | return disp_table->DestroyDevice; |
| 842 | else if (!strncmp("xglGetExtensionSupport", (const char *) pName, sizeof ("xglGetExtensionSupport"))) |
| 843 | return disp_table->GetExtensionSupport; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 844 | else if (!strncmp("xglEnumerateLayers", (const char *) pName, sizeof ("xglEnumerateLayers"))) |
| 845 | return disp_table->EnumerateLayers; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 846 | else if (!strncmp("xglGetDeviceQueue", (const char *) pName, sizeof ("xglGetDeviceQueue"))) |
| 847 | return disp_table->GetDeviceQueue; |
| 848 | else if (!strncmp("xglQueueSubmit", (const char *) pName, sizeof ("xglQueueSubmit"))) |
| 849 | return disp_table->QueueSubmit; |
| 850 | else if (!strncmp("xglQueueSetGlobalMemReferences", (const char *) pName, sizeof ("xglQueueSetGlobalMemReferences"))) |
| 851 | return disp_table->QueueSetGlobalMemReferences; |
| 852 | else if (!strncmp("xglQueueWaitIdle", (const char *) pName, sizeof ("xglQueueWaitIdle"))) |
| 853 | return disp_table->QueueWaitIdle; |
| 854 | else if (!strncmp("xglDeviceWaitIdle", (const char *) pName, sizeof ("xglDeviceWaitIdle"))) |
| 855 | return disp_table->DeviceWaitIdle; |
| 856 | else if (!strncmp("xglGetMemoryHeapCount", (const char *) pName, sizeof ("xglGetMemoryHeapCount"))) |
| 857 | return disp_table->GetMemoryHeapCount; |
| 858 | else if (!strncmp("xglGetMemoryHeapInfo", (const char *) pName, sizeof ("xglGetMemoryHeapInfo"))) |
| 859 | return disp_table->GetMemoryHeapInfo; |
| 860 | else if (!strncmp("xglAllocMemory", (const char *) pName, sizeof ("xglAllocMemory"))) |
| 861 | return disp_table->AllocMemory; |
| 862 | else if (!strncmp("xglFreeMemory", (const char *) pName, sizeof ("xglFreeMemory"))) |
| 863 | return disp_table->FreeMemory; |
| 864 | else if (!strncmp("xglSetMemoryPriority", (const char *) pName, sizeof ("xglSetMemoryPriority"))) |
| 865 | return disp_table->SetMemoryPriority; |
| 866 | else if (!strncmp("xglMapMemory", (const char *) pName, sizeof ("xglMapMemory"))) |
| 867 | return disp_table->MapMemory; |
| 868 | else if (!strncmp("xglUnmapMemory", (const char *) pName, sizeof ("xglUnmapMemory"))) |
| 869 | return disp_table->UnmapMemory; |
| 870 | else if (!strncmp("xglPinSystemMemory", (const char *) pName, sizeof ("xglPinSystemMemory"))) |
| 871 | return disp_table->PinSystemMemory; |
| 872 | else if (!strncmp("xglRemapVirtualMemoryPages", (const char *) pName, sizeof ("xglRemapVirtualMemoryPages"))) |
| 873 | return disp_table->RemapVirtualMemoryPages; |
| 874 | else if (!strncmp("xglGetMultiGpuCompatibility", (const char *) pName, sizeof ("xglGetMultiGpuCompatibility"))) |
| 875 | return disp_table->GetMultiGpuCompatibility; |
| 876 | else if (!strncmp("xglOpenSharedMemory", (const char *) pName, sizeof ("xglOpenSharedMemory"))) |
| 877 | return disp_table->OpenSharedMemory; |
| 878 | else if (!strncmp("xglOpenSharedQueueSemaphore", (const char *) pName, sizeof ("xglOpenSharedQueueSemaphore"))) |
| 879 | return disp_table->OpenSharedQueueSemaphore; |
| 880 | else if (!strncmp("xglOpenPeerMemory", (const char *) pName, sizeof ("xglOpenPeerMemory"))) |
| 881 | return disp_table->OpenPeerMemory; |
| 882 | else if (!strncmp("xglOpenPeerImage", (const char *) pName, sizeof ("xglOpenPeerImage"))) |
| 883 | return disp_table->OpenPeerImage; |
| 884 | else if (!strncmp("xglDestroyObject", (const char *) pName, sizeof ("xglDestroyObject"))) |
| 885 | return disp_table->DestroyObject; |
| 886 | else if (!strncmp("xglGetObjectInfo", (const char *) pName, sizeof ("xglGetObjectInfo"))) |
| 887 | return disp_table->GetObjectInfo; |
| 888 | else if (!strncmp("xglBindObjectMemory", (const char *) pName, sizeof ("xglBindObjectMemory"))) |
| 889 | return disp_table->BindObjectMemory; |
| 890 | else if (!strncmp("xglCreateFence", (const char *) pName, sizeof ("xgllCreateFence"))) |
| 891 | return disp_table->CreateFence; |
| 892 | else if (!strncmp("xglGetFenceStatus", (const char *) pName, sizeof ("xglGetFenceStatus"))) |
| 893 | return disp_table->GetFenceStatus; |
| 894 | else if (!strncmp("xglWaitForFences", (const char *) pName, sizeof ("xglWaitForFences"))) |
| 895 | return disp_table->WaitForFences; |
| 896 | else if (!strncmp("xglCreateQueueSemaphore", (const char *) pName, sizeof ("xgllCreateQueueSemaphore"))) |
| 897 | return disp_table->CreateQueueSemaphore; |
| 898 | else if (!strncmp("xglSignalQueueSemaphore", (const char *) pName, sizeof ("xglSignalQueueSemaphore"))) |
| 899 | return disp_table->SignalQueueSemaphore; |
| 900 | else if (!strncmp("xglWaitQueueSemaphore", (const char *) pName, sizeof ("xglWaitQueueSemaphore"))) |
| 901 | return disp_table->WaitQueueSemaphore; |
| 902 | else if (!strncmp("xglCreateEvent", (const char *) pName, sizeof ("xgllCreateEvent"))) |
| 903 | return disp_table->CreateEvent; |
| 904 | else if (!strncmp("xglGetEventStatus", (const char *) pName, sizeof ("xglGetEventStatus"))) |
| 905 | return disp_table->GetEventStatus; |
| 906 | else if (!strncmp("xglSetEvent", (const char *) pName, sizeof ("xglSetEvent"))) |
| 907 | return disp_table->SetEvent; |
| 908 | else if (!strncmp("xglResetEvent", (const char *) pName, sizeof ("xgllResetEvent"))) |
| 909 | return disp_table->ResetEvent; |
| 910 | else if (!strncmp("xglCreateQueryPool", (const char *) pName, sizeof ("xglCreateQueryPool"))) |
| 911 | return disp_table->CreateQueryPool; |
| 912 | else if (!strncmp("xglGetQueryPoolResults", (const char *) pName, sizeof ("xglGetQueryPoolResults"))) |
| 913 | return disp_table->GetQueryPoolResults; |
| 914 | else if (!strncmp("xglGetFormatInfo", (const char *) pName, sizeof ("xglGetFormatInfo"))) |
| 915 | return disp_table->GetFormatInfo; |
| 916 | else if (!strncmp("xglCreateImage", (const char *) pName, sizeof ("xglCreateImage"))) |
| 917 | return disp_table->CreateImage; |
| 918 | else if (!strncmp("xglGetImageSubresourceInfo", (const char *) pName, sizeof ("xglGetImageSubresourceInfo"))) |
| 919 | return disp_table->GetImageSubresourceInfo; |
| 920 | else if (!strncmp("xglCreateImageView", (const char *) pName, sizeof ("xglCreateImageView"))) |
| 921 | return disp_table->CreateImageView; |
| 922 | else if (!strncmp("xglCreateColorAttachmentView", (const char *) pName, sizeof ("xglCreateColorAttachmentView"))) |
| 923 | return disp_table->CreateColorAttachmentView; |
| 924 | else if (!strncmp("xglCreateDepthStencilView", (const char *) pName, sizeof ("xglCreateDepthStencilView"))) |
| 925 | return disp_table->CreateDepthStencilView; |
| 926 | else if (!strncmp("xglCreateShader", (const char *) pName, sizeof ("xglCreateShader"))) |
| 927 | return disp_table->CreateShader; |
| 928 | else if (!strncmp("xglCreateGraphicsPipeline", (const char *) pName, sizeof ("xglCreateGraphicsPipeline"))) |
| 929 | return disp_table->CreateGraphicsPipeline; |
| 930 | else if (!strncmp("xglCreateComputePipeline", (const char *) pName, sizeof ("xglCreateComputePipeline"))) |
| 931 | return disp_table->CreateComputePipeline; |
| 932 | else if (!strncmp("xglStorePipeline", (const char *) pName, sizeof ("xglStorePipeline"))) |
| 933 | return disp_table->StorePipeline; |
| 934 | else if (!strncmp("xglLoadPipeline", (const char *) pName, sizeof ("xglLoadPipeline"))) |
| 935 | return disp_table->LoadPipeline; |
| 936 | else if (!strncmp("xglCreatePipelineDelta", (const char *) pName, sizeof ("xglCreatePipelineDelta"))) |
| 937 | return disp_table->CreatePipelineDelta; |
| 938 | else if (!strncmp("xglCreateSampler", (const char *) pName, sizeof ("xglCreateSampler"))) |
| 939 | return disp_table->CreateSampler; |
| 940 | else if (!strncmp("xglCreateDescriptorSet", (const char *) pName, sizeof ("xglCreateDescriptorSet"))) |
| 941 | return disp_table->CreateDescriptorSet; |
| 942 | else if (!strncmp("xglBeginDescriptorSetUpdate", (const char *) pName, sizeof ("xglBeginDescriptorSetUpdate"))) |
| 943 | return disp_table->BeginDescriptorSetUpdate; |
| 944 | else if (!strncmp("xglEndDescriptorSetUpdate", (const char *) pName, sizeof ("xglEndDescriptorSetUpdate"))) |
| 945 | return disp_table->EndDescriptorSetUpdate; |
| 946 | else if (!strncmp("xglAttachSamplerDescriptors", (const char *) pName, sizeof ("xglAttachSamplerDescriptors"))) |
| 947 | return disp_table->AttachSamplerDescriptors; |
| 948 | else if (!strncmp("xglAttachImageViewDescriptors", (const char *) pName, sizeof ("xglAttachImageViewDescriptors"))) |
| 949 | return disp_table->AttachImageViewDescriptors; |
| 950 | else if (!strncmp("xglAttachMemoryViewDescriptors", (const char *) pName, sizeof ("xglAttachMemoryViewDescriptors"))) |
| 951 | return disp_table->AttachMemoryViewDescriptors; |
| 952 | else if (!strncmp("xglAttachNestedDescriptors", (const char *) pName, sizeof ("xglAttachNestedDescriptors"))) |
| 953 | return disp_table->AttachNestedDescriptors; |
| 954 | else if (!strncmp("xglClearDescriptorSetSlots", (const char *) pName, sizeof ("xglClearDescriptorSetSlots"))) |
| 955 | return disp_table->ClearDescriptorSetSlots; |
| 956 | else if (!strncmp("xglCreateViewportState", (const char *) pName, sizeof ("xglCreateViewportState"))) |
| 957 | return disp_table->CreateViewportState; |
| 958 | else if (!strncmp("xglCreateRasterState", (const char *) pName, sizeof ("xglCreateRasterState"))) |
| 959 | return disp_table->CreateRasterState; |
| 960 | else if (!strncmp("xglCreateMsaaState", (const char *) pName, sizeof ("xglCreateMsaaState"))) |
| 961 | return disp_table->CreateMsaaState; |
| 962 | else if (!strncmp("xglCreateColorBlendState", (const char *) pName, sizeof ("xglCreateColorBlendState"))) |
| 963 | return disp_table->CreateColorBlendState; |
| 964 | else if (!strncmp("xglCreateDepthStencilState", (const char *) pName, sizeof ("xglCreateDepthStencilState"))) |
| 965 | return disp_table->CreateDepthStencilState; |
| 966 | else if (!strncmp("xglCreateCommandBuffer", (const char *) pName, sizeof ("xglCreateCommandBuffer"))) |
| 967 | return disp_table->CreateCommandBuffer; |
| 968 | else if (!strncmp("xglBeginCommandBuffer", (const char *) pName, sizeof ("xglBeginCommandBuffer"))) |
| 969 | return disp_table->BeginCommandBuffer; |
| 970 | else if (!strncmp("xglEndCommandBuffer", (const char *) pName, sizeof ("xglEndCommandBuffer"))) |
| 971 | return disp_table->EndCommandBuffer; |
| 972 | else if (!strncmp("xglResetCommandBuffer", (const char *) pName, sizeof ("xglResetCommandBuffer"))) |
| 973 | return disp_table->ResetCommandBuffer; |
| 974 | else if (!strncmp("xglCmdBindPipeline", (const char *) pName, sizeof ("xglCmdBindPipeline"))) |
| 975 | return disp_table->CmdBindPipeline; |
| 976 | else if (!strncmp("xglCmdBindPipelineDelta", (const char *) pName, sizeof ("xglCmdBindPipelineDelta"))) |
| 977 | return disp_table->CmdBindPipelineDelta; |
| 978 | else if (!strncmp("xglCmdBindStateObject", (const char *) pName, sizeof ("xglCmdBindStateObject"))) |
| 979 | return disp_table->CmdBindStateObject; |
| 980 | else if (!strncmp("xglCmdBindDescriptorSet", (const char *) pName, sizeof ("xglCmdBindDescriptorSet"))) |
| 981 | return disp_table->CmdBindDescriptorSet; |
| 982 | else if (!strncmp("xglCmdBindDynamicMemoryView", (const char *) pName, sizeof ("xglCmdBindDynamicMemoryView"))) |
| 983 | return disp_table->CmdBindDynamicMemoryView; |
Chia-I Wu | 3b04af5 | 2014-11-08 10:48:20 +0800 | [diff] [blame] | 984 | else if (!strncmp("xglCmdBindVertexData", (const char *) pName, sizeof ("xglCmdBindVertexData"))) |
| 985 | return disp_table->CmdBindVertexData; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 986 | else if (!strncmp("xglCmdBindIndexData", (const char *) pName, sizeof ("xglCmdBindIndexData"))) |
| 987 | return disp_table->CmdBindIndexData; |
| 988 | else if (!strncmp("xglCmdBindAttachments", (const char *) pName, sizeof ("xglCmdBindAttachments"))) |
| 989 | return disp_table->CmdBindAttachments; |
| 990 | else if (!strncmp("xglCmdPrepareMemoryRegions", (const char *) pName, sizeof ("xglCmdPrepareMemoryRegions"))) |
| 991 | return disp_table->CmdPrepareMemoryRegions; |
| 992 | else if (!strncmp("xglCmdPrepareImages", (const char *) pName, sizeof ("xglCmdPrepareImages"))) |
| 993 | return disp_table->CmdPrepareImages; |
| 994 | else if (!strncmp("xglCmdDraw", (const char *) pName, sizeof ("xglCmdDraw"))) |
| 995 | return disp_table->CmdDraw; |
| 996 | else if (!strncmp("xglCmdDrawIndexed", (const char *) pName, sizeof ("xglCmdDrawIndexed"))) |
| 997 | return disp_table->CmdDrawIndexed; |
| 998 | else if (!strncmp("xglCmdDrawIndirect", (const char *) pName, sizeof ("xglCmdDrawIndirect"))) |
| 999 | return disp_table->CmdDrawIndirect; |
| 1000 | else if (!strncmp("xglCmdDrawIndexedIndirect", (const char *) pName, sizeof ("xglCmdDrawIndexedIndirect"))) |
| 1001 | return disp_table->CmdDrawIndexedIndirect; |
| 1002 | else if (!strncmp("xglCmdDispatch", (const char *) pName, sizeof ("xglCmdDispatch"))) |
| 1003 | return disp_table->CmdDispatch; |
| 1004 | else if (!strncmp("xglCmdDispatchIndirect", (const char *) pName, sizeof ("xglCmdDispatchIndirect"))) |
| 1005 | return disp_table->CmdDispatchIndirect; |
| 1006 | else if (!strncmp("xglCmdCopyMemory", (const char *) pName, sizeof ("xglCmdCopyMemory"))) |
| 1007 | return disp_table->CmdCopyMemory; |
| 1008 | else if (!strncmp("xglCmdCopyImage", (const char *) pName, sizeof ("xglCmdCopyImage"))) |
| 1009 | return disp_table->CmdCopyImage; |
| 1010 | else if (!strncmp("xglCmdCopyMemoryToImage", (const char *) pName, sizeof ("xglCmdCopyMemoryToImage"))) |
| 1011 | return disp_table->CmdCopyMemoryToImage; |
| 1012 | else if (!strncmp("xglCmdCopyImageToMemory", (const char *) pName, sizeof ("xglCmdCopyImageToMemory"))) |
| 1013 | return disp_table->CmdCopyImageToMemory; |
| 1014 | else if (!strncmp("xglCmdCloneImageData", (const char *) pName, sizeof ("xglCmdCloneImageData"))) |
| 1015 | return disp_table->CmdCloneImageData; |
| 1016 | else if (!strncmp("xglCmdUpdateMemory", (const char *) pName, sizeof ("xglCmdUpdateMemory"))) |
| 1017 | return disp_table->CmdUpdateMemory; |
| 1018 | else if (!strncmp("xglCmdFillMemory", (const char *) pName, sizeof ("xglCmdFillMemory"))) |
| 1019 | return disp_table->CmdFillMemory; |
| 1020 | else if (!strncmp("xglCmdClearColorImage", (const char *) pName, sizeof ("xglCmdClearColorImage"))) |
| 1021 | return disp_table->CmdClearColorImage; |
| 1022 | else if (!strncmp("xglCmdClearColorImageRaw", (const char *) pName, sizeof ("xglCmdClearColorImageRaw"))) |
| 1023 | return disp_table->CmdClearColorImageRaw; |
| 1024 | else if (!strncmp("xglCmdClearDepthStencil", (const char *) pName, sizeof ("xglCmdClearDepthStencil"))) |
| 1025 | return disp_table->CmdClearDepthStencil; |
| 1026 | else if (!strncmp("xglCmdResolveImage", (const char *) pName, sizeof ("xglCmdResolveImage"))) |
| 1027 | return disp_table->CmdResolveImage; |
| 1028 | else if (!strncmp("xglCmdSetEvent", (const char *) pName, sizeof ("xglCmdSetEvent"))) |
| 1029 | return disp_table->CmdSetEvent; |
| 1030 | else if (!strncmp("xglCmdResetEvent", (const char *) pName, sizeof ("xglCmdResetEvent"))) |
| 1031 | return disp_table->CmdResetEvent; |
| 1032 | else if (!strncmp("xglCmdMemoryAtomic", (const char *) pName, sizeof ("xglCmdMemoryAtomic"))) |
| 1033 | return disp_table->CmdMemoryAtomic; |
| 1034 | else if (!strncmp("xglCmdBeginQuery", (const char *) pName, sizeof ("xglCmdBeginQuery"))) |
| 1035 | return disp_table->CmdBeginQuery; |
| 1036 | else if (!strncmp("xglCmdEndQuery", (const char *) pName, sizeof ("xglCmdEndQuery"))) |
| 1037 | return disp_table->CmdEndQuery; |
| 1038 | else if (!strncmp("xglCmdResetQueryPool", (const char *) pName, sizeof ("xglCmdResetQueryPool"))) |
| 1039 | return disp_table->CmdResetQueryPool; |
| 1040 | else if (!strncmp("xglCmdWriteTimestamp", (const char *) pName, sizeof ("xglCmdWriteTimestamp"))) |
| 1041 | return disp_table->CmdWriteTimestamp; |
| 1042 | else if (!strncmp("xglCmdInitAtomicCounters", (const char *) pName, sizeof ("xglCmdInitAtomicCounters"))) |
| 1043 | return disp_table->CmdInitAtomicCounters; |
| 1044 | else if (!strncmp("xglCmdLoadAtomicCounters", (const char *) pName, sizeof ("xglCmdLoadAtomicCounters"))) |
| 1045 | return disp_table->CmdLoadAtomicCounters; |
| 1046 | else if (!strncmp("xglCmdSaveAtomicCounters", (const char *) pName, sizeof ("xglCmdSaveAtomicCounters"))) |
| 1047 | return disp_table->CmdSaveAtomicCounters; |
| 1048 | else if (!strncmp("xglDbgSetValidationLevel", (const char *) pName, sizeof ("xglDbgSetValidationLevel"))) |
| 1049 | return disp_table->DbgSetValidationLevel; |
| 1050 | else if (!strncmp("xglDbgRegisterMsgCallback", (const char *) pName, sizeof ("xglDbgRegisterMsgCallback"))) |
| 1051 | return disp_table->DbgRegisterMsgCallback; |
| 1052 | else if (!strncmp("xglDbgUnregisterMsgCallback", (const char *) pName, sizeof ("xglDbgUnregisterMsgCallback"))) |
| 1053 | return disp_table->DbgUnregisterMsgCallback; |
| 1054 | else if (!strncmp("xglDbgSetMessageFilter", (const char *) pName, sizeof ("xglDbgSetMessageFilter"))) |
| 1055 | return disp_table->DbgSetMessageFilter; |
| 1056 | else if (!strncmp("xglDbgSetObjectTag", (const char *) pName, sizeof ("xglDbgSetObjectTag"))) |
| 1057 | return disp_table->DbgSetObjectTag; |
| 1058 | else if (!strncmp("xglDbgSetGlobalOption", (const char *) pName, sizeof ("xglDbgSetGlobalOption"))) |
| 1059 | return disp_table->DbgSetGlobalOption; |
| 1060 | else if (!strncmp("xglDbgSetDeviceOption", (const char *) pName, sizeof ("xglDbgSetDeviceOption"))) |
| 1061 | return disp_table->DbgSetDeviceOption; |
| 1062 | else if (!strncmp("xglCmdDbgMarkerBegin", (const char *) pName, sizeof ("xglCmdDbgMarkerBegin"))) |
| 1063 | return disp_table->CmdDbgMarkerBegin; |
| 1064 | else if (!strncmp("xglCmdDbgMarkerEnd", (const char *) pName, sizeof ("xglCmdDbgMarkerEnd"))) |
| 1065 | return disp_table->CmdDbgMarkerEnd; |
| 1066 | else if (!strncmp("xglWsiX11AssociateConnection", (const char *) pName, sizeof("xglWsiX11AssociateConnection"))) |
| 1067 | return disp_table->WsiX11AssociateConnection; |
| 1068 | else if (!strncmp("xglWsiX11GetMSC", (const char *) pName, sizeof("xglWsiX11GetMSC"))) |
| 1069 | return disp_table->WsiX11GetMSC; |
| 1070 | else if (!strncmp("xglWsiX11CreatePresentableImage", (const char *) pName, sizeof("xglWsiX11CreatePresentableImage"))) |
| 1071 | return disp_table->WsiX11CreatePresentableImage; |
| 1072 | else if (!strncmp("xglWsiX11QueuePresent", (const char *) pName, sizeof("xglWsiX11QueuePresent"))) |
| 1073 | return disp_table->WsiX11QueuePresent; |
| 1074 | else { |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1075 | if (disp_table->GetProcAddr == NULL) |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1076 | return NULL; |
Jon Ashburn | 3e7c080 | 2014-10-24 15:48:55 -0600 | [diff] [blame] | 1077 | return disp_table->GetProcAddr(gpuw->nextObject, pName); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 1081 | LOADER_EXPORT XGL_RESULT XGLAPI xglInitAndEnumerateGpus(const XGL_APPLICATION_INFO* pAppInfo, const XGL_ALLOC_CALLBACKS* pAllocCb, XGL_UINT maxGpus, XGL_UINT* pGpuCount, XGL_PHYSICAL_GPU* pGpus) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1082 | { |
| 1083 | static pthread_once_t once = PTHREAD_ONCE_INIT; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1084 | struct loader_icd *icd; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1085 | XGL_UINT count = 0; |
| 1086 | XGL_RESULT res; |
| 1087 | |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1088 | // cleanup any prior layer initializations |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 1089 | loader_deactivate_layer(); |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1090 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1091 | pthread_once(&once, loader_icd_scan); |
| 1092 | |
| 1093 | if (!loader.icds) |
| 1094 | return XGL_ERROR_UNAVAILABLE; |
| 1095 | |
| 1096 | icd = loader.icds; |
| 1097 | while (icd) { |
| 1098 | XGL_PHYSICAL_GPU gpus[XGL_MAX_PHYSICAL_GPUS]; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1099 | XGL_BASE_LAYER_OBJECT * wrappedGpus; |
| 1100 | GetProcAddrType getProcAddr = icd->GetProcAddr; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1101 | XGL_UINT n, max = maxGpus - count; |
| 1102 | |
| 1103 | if (max > XGL_MAX_PHYSICAL_GPUS) { |
| 1104 | max = XGL_MAX_PHYSICAL_GPUS; |
| 1105 | } |
| 1106 | |
| 1107 | res = icd->InitAndEnumerateGpus(pAppInfo, pAllocCb, max, &n, gpus); |
Chia-I Wu | 74916ed | 2014-08-06 12:17:04 +0800 | [diff] [blame] | 1108 | if (res == XGL_SUCCESS && n) { |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1109 | wrappedGpus = (XGL_BASE_LAYER_OBJECT*) malloc(n * sizeof(XGL_BASE_LAYER_OBJECT)); |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1110 | icd->gpus = wrappedGpus; |
Jon Ashburn | b55278a | 2014-10-17 15:09:07 -0600 | [diff] [blame] | 1111 | icd->gpu_count = n; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1112 | icd->loader_dispatch = (XGL_LAYER_DISPATCH_TABLE *) malloc(n * sizeof(XGL_LAYER_DISPATCH_TABLE)); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1113 | for (int i = 0; i < n; i++) { |
| 1114 | (wrappedGpus + i)->baseObject = gpus[i]; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1115 | (wrappedGpus + i)->pGPA = getProcAddr; |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1116 | (wrappedGpus + i)->nextObject = gpus[i]; |
| 1117 | memcpy(pGpus + count, &wrappedGpus, sizeof(*pGpus)); |
Jon Ashburn | 8eecd42 | 2014-10-22 12:42:13 -0600 | [diff] [blame] | 1118 | loader_init_dispatch_table(icd->loader_dispatch + i, getProcAddr, gpus[i]); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1119 | const XGL_LAYER_DISPATCH_TABLE * *disp = (const XGL_LAYER_DISPATCH_TABLE * *) gpus[i]; |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 1120 | *disp = icd->loader_dispatch + i; |
| 1121 | icd->SetDispatch(icd->loader_dispatch + i, true); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1122 | } |
| 1123 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1124 | count += n; |
| 1125 | |
| 1126 | if (count >= maxGpus) { |
| 1127 | break; |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | icd = icd->next; |
| 1132 | } |
| 1133 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1134 | /* get layer libraries */ |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1135 | if (!loader.layer_scanned) |
| 1136 | layer_lib_scan(NULL, true); |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 1137 | |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1138 | *pGpuCount = count; |
| 1139 | |
| 1140 | return (count > 0) ? XGL_SUCCESS : res; |
| 1141 | } |
| 1142 | |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1143 | LOADER_EXPORT XGL_RESULT XGLAPI xglEnumerateLayers(XGL_PHYSICAL_GPU gpu, XGL_SIZE maxLayerCount, XGL_SIZE maxStringSize, XGL_CHAR* const* pOutLayers, XGL_SIZE* pOutLayerCount) |
| 1144 | { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1145 | XGL_SIZE count = loader.scanned_layer_count; |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1146 | // TODO handle layers per GPU, multiple icds |
| 1147 | |
| 1148 | if (pOutLayerCount == NULL) |
| 1149 | return XGL_ERROR_INVALID_POINTER; |
| 1150 | |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1151 | if (maxLayerCount < loader.scanned_layer_count) |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1152 | count = maxLayerCount; |
| 1153 | *pOutLayerCount = count; |
| 1154 | |
| 1155 | if (pOutLayers == NULL) |
| 1156 | return XGL_SUCCESS; |
| 1157 | for (XGL_SIZE i = 0; i < count; i++) { |
Jon Ashburn | 183dfd0 | 2014-10-22 18:13:16 -0600 | [diff] [blame] | 1158 | strncpy((char *) (pOutLayers[i]), loader.scanned_layer_names[i], maxStringSize); |
Jon Ashburn | 96f28fc | 2014-10-15 15:30:23 -0600 | [diff] [blame] | 1159 | if (maxStringSize > 0) |
| 1160 | pOutLayers[i][maxStringSize - 1] = '\0'; |
| 1161 | } |
| 1162 | return XGL_SUCCESS; |
| 1163 | } |
| 1164 | |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 1165 | LOADER_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, XGL_VOID* pUserData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1166 | { |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1167 | const struct loader_icd *icd; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1168 | XGL_RESULT res; |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1169 | XGL_UINT gpu_idx; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1170 | |
| 1171 | if (!loader.scanned) { |
| 1172 | return loader_msg_callback_add(pfnMsgCallback, pUserData); |
| 1173 | } |
| 1174 | |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1175 | for (icd = loader.icds; icd; icd = icd->next) { |
| 1176 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) { |
| 1177 | res = (icd->loader_dispatch + i)->DbgRegisterMsgCallback(pfnMsgCallback, pUserData); |
| 1178 | if (res != XGL_SUCCESS) { |
| 1179 | gpu_idx = i; |
| 1180 | break; |
| 1181 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1182 | } |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1183 | if (res != XGL_SUCCESS) |
| 1184 | break; |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /* roll back on errors */ |
| 1188 | if (icd) { |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1189 | for (const struct loader_icd * tmp = loader.icds; tmp != icd; tmp = tmp->next) { |
| 1190 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) |
| 1191 | (tmp->loader_dispatch + i)->DbgUnregisterMsgCallback(pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1192 | } |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1193 | /* and gpus on current icd */ |
| 1194 | for (XGL_UINT i = 0; i < gpu_idx; i++) |
| 1195 | (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(pfnMsgCallback); |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1196 | |
| 1197 | return res; |
| 1198 | } |
| 1199 | |
| 1200 | return XGL_SUCCESS; |
| 1201 | } |
| 1202 | |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 1203 | LOADER_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1204 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1205 | XGL_RESULT res = XGL_SUCCESS; |
| 1206 | |
| 1207 | if (!loader.scanned) { |
| 1208 | return loader_msg_callback_remove(pfnMsgCallback); |
| 1209 | } |
| 1210 | |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1211 | for (const struct loader_icd * icd = loader.icds; icd; icd = icd->next) { |
| 1212 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) { |
| 1213 | XGL_RESULT r = (icd->loader_dispatch + i)->DbgUnregisterMsgCallback(pfnMsgCallback); |
| 1214 | if (r != XGL_SUCCESS) { |
| 1215 | res = r; |
| 1216 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1217 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1218 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1219 | return res; |
| 1220 | } |
| 1221 | |
Chia-I Wu | 468e3c3 | 2014-08-04 08:03:57 +0800 | [diff] [blame] | 1222 | LOADER_EXPORT XGL_RESULT XGLAPI xglDbgSetGlobalOption(XGL_DBG_GLOBAL_OPTION dbgOption, XGL_SIZE dataSize, const XGL_VOID* pData) |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1223 | { |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1224 | XGL_RESULT res = XGL_SUCCESS; |
| 1225 | |
| 1226 | if (!loader.scanned) { |
| 1227 | if (dataSize == 0) |
| 1228 | return XGL_ERROR_INVALID_VALUE; |
| 1229 | |
| 1230 | switch (dbgOption) { |
| 1231 | case XGL_DBG_OPTION_DEBUG_ECHO_ENABLE: |
| 1232 | loader.debug_echo_enable = *((const bool *) pData); |
| 1233 | break; |
| 1234 | case XGL_DBG_OPTION_BREAK_ON_ERROR: |
| 1235 | loader.break_on_error = *((const bool *) pData); |
| 1236 | break; |
| 1237 | case XGL_DBG_OPTION_BREAK_ON_WARNING: |
| 1238 | loader.break_on_warning = *((const bool *) pData); |
| 1239 | break; |
| 1240 | default: |
| 1241 | res = XGL_ERROR_INVALID_VALUE; |
| 1242 | break; |
| 1243 | } |
| 1244 | |
| 1245 | return res; |
| 1246 | } |
| 1247 | |
Jon Ashburn | 406a0fe | 2014-11-14 09:52:42 -0700 | [diff] [blame] | 1248 | for (const struct loader_icd * icd = loader.icds; icd; icd = icd->next) { |
| 1249 | for (XGL_UINT i = 0; i < icd->gpu_count; i++) { |
| 1250 | XGL_RESULT r = (icd->loader_dispatch + i)->DbgSetGlobalOption(dbgOption, dataSize, pData); |
| 1251 | /* unfortunately we cannot roll back */ |
| 1252 | if (r != XGL_SUCCESS) { |
| 1253 | res = r; |
| 1254 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1255 | } |
Chia-I Wu | 5f72d0f | 2014-08-01 11:21:23 +0800 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | return res; |
| 1259 | } |