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