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