Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +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> |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <fcntl.h> |
| 32 | #include <unistd.h> |
| 33 | |
| 34 | #include "genhw/genhw.h" |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 35 | #include "kmd/winsys.h" |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 36 | #include "queue.h" |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 37 | #include "gpu.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 38 | #include "wsi_x11.h" |
| 39 | |
| 40 | static struct intel_gpu *intel_gpus; |
| 41 | |
Chia-I Wu | 1076a87 | 2015-01-18 16:02:55 +0800 | [diff] [blame^] | 42 | static const char * const intel_gpu_exts[INTEL_EXT_COUNT] = { |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 43 | #ifdef ENABLE_WSI_X11 |
| 44 | [INTEL_EXT_WSI_X11] = "XGL_WSI_X11", |
| 45 | #endif |
| 46 | }; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 47 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 48 | static int gpu_open_primary_node(struct intel_gpu *gpu) |
| 49 | { |
| 50 | /* cannot not open gpu->primary_node directly */ |
| 51 | return gpu->primary_fd_internal; |
| 52 | } |
| 53 | |
| 54 | static void gpu_close_primary_node(struct intel_gpu *gpu) |
| 55 | { |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 56 | if (gpu->primary_fd_internal >= 0) |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 57 | gpu->primary_fd_internal = -1; |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static int gpu_open_render_node(struct intel_gpu *gpu) |
| 61 | { |
| 62 | if (gpu->render_fd_internal < 0 && gpu->render_node) { |
| 63 | gpu->render_fd_internal = open(gpu->render_node, O_RDWR); |
| 64 | if (gpu->render_fd_internal < 0) { |
| 65 | icd_log(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, NULL, 0, |
| 66 | 0, "failed to open %s", gpu->render_node); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return gpu->render_fd_internal; |
| 71 | } |
| 72 | |
| 73 | static void gpu_close_render_node(struct intel_gpu *gpu) |
| 74 | { |
| 75 | if (gpu->render_fd_internal >= 0) { |
| 76 | close(gpu->render_fd_internal); |
| 77 | gpu->render_fd_internal = -1; |
| 78 | } |
| 79 | } |
| 80 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 81 | static const char *gpu_get_name(const struct intel_gpu *gpu) |
| 82 | { |
| 83 | const char *name = NULL; |
| 84 | |
| 85 | if (gen_is_hsw(gpu->devid)) { |
| 86 | if (gen_is_desktop(gpu->devid)) |
| 87 | name = "Intel(R) Haswell Desktop"; |
| 88 | else if (gen_is_mobile(gpu->devid)) |
| 89 | name = "Intel(R) Haswell Mobile"; |
| 90 | else if (gen_is_server(gpu->devid)) |
| 91 | name = "Intel(R) Haswell Server"; |
| 92 | } |
| 93 | else if (gen_is_ivb(gpu->devid)) { |
| 94 | if (gen_is_desktop(gpu->devid)) |
| 95 | name = "Intel(R) Ivybridge Desktop"; |
| 96 | else if (gen_is_mobile(gpu->devid)) |
| 97 | name = "Intel(R) Ivybridge Mobile"; |
| 98 | else if (gen_is_server(gpu->devid)) |
| 99 | name = "Intel(R) Ivybridge Server"; |
| 100 | } |
| 101 | else if (gen_is_snb(gpu->devid)) { |
| 102 | if (gen_is_desktop(gpu->devid)) |
| 103 | name = "Intel(R) Sandybridge Desktop"; |
| 104 | else if (gen_is_mobile(gpu->devid)) |
| 105 | name = "Intel(R) Sandybridge Mobile"; |
| 106 | else if (gen_is_server(gpu->devid)) |
| 107 | name = "Intel(R) Sandybridge Server"; |
| 108 | } |
| 109 | |
| 110 | if (!name) |
| 111 | name = "Unknown Intel Chipset"; |
| 112 | |
| 113 | return name; |
| 114 | } |
| 115 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 116 | static struct intel_gpu *gpu_create(int gen, int devid, |
| 117 | const char *primary_node, |
| 118 | const char *render_node) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 119 | { |
| 120 | struct intel_gpu *gpu; |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 121 | size_t primary_len, render_len; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 122 | |
| 123 | gpu = icd_alloc(sizeof(*gpu), 0, XGL_SYSTEM_ALLOC_API_OBJECT); |
| 124 | if (!gpu) |
| 125 | return NULL; |
| 126 | |
| 127 | memset(gpu, 0, sizeof(*gpu)); |
| 128 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 129 | gpu->devid = devid; |
| 130 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 131 | primary_len = strlen(primary_node); |
| 132 | render_len = (render_node) ? strlen(render_node) : 0; |
| 133 | |
| 134 | gpu->primary_node = icd_alloc(primary_len + 1 + |
| 135 | ((render_len) ? (render_len + 1) : 0), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 136 | if (!gpu->primary_node) { |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 137 | icd_free(gpu); |
| 138 | return NULL; |
| 139 | } |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 140 | |
| 141 | memcpy(gpu->primary_node, primary_node, primary_len + 1); |
| 142 | |
| 143 | if (render_node) { |
| 144 | gpu->render_node = gpu->primary_node + primary_len + 1; |
| 145 | memcpy(gpu->render_node, render_node, render_len + 1); |
| 146 | } |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 147 | |
| 148 | gpu->gen_opaque = gen; |
| 149 | |
Chia-I Wu | 960f195 | 2014-08-28 23:27:10 +0800 | [diff] [blame] | 150 | switch (intel_gpu_gen(gpu)) { |
| 151 | case INTEL_GEN(7.5): |
| 152 | gpu->gt = gen_get_hsw_gt(devid); |
| 153 | break; |
| 154 | case INTEL_GEN(7): |
| 155 | gpu->gt = gen_get_ivb_gt(devid); |
| 156 | break; |
| 157 | case INTEL_GEN(6): |
| 158 | gpu->gt = gen_get_snb_gt(devid); |
| 159 | break; |
| 160 | } |
| 161 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 162 | /* 8192 dwords */ |
Chia-I Wu | d6109bb | 2014-08-21 09:12:19 +0800 | [diff] [blame] | 163 | gpu->max_batch_buffer_size = sizeof(uint32_t) * 8192; |
| 164 | |
| 165 | /* the winsys is prepared for one reloc every two dwords, then minus 2 */ |
| 166 | gpu->batch_buffer_reloc_count = |
| 167 | gpu->max_batch_buffer_size / sizeof(uint32_t) / 2 - 2; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 168 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 169 | gpu->primary_fd_internal = -1; |
| 170 | gpu->render_fd_internal = -1; |
| 171 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 172 | return gpu; |
| 173 | } |
| 174 | |
| 175 | static void gpu_destroy(struct intel_gpu *gpu) |
| 176 | { |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 177 | intel_gpu_close(gpu); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 178 | |
| 179 | #ifdef ENABLE_WSI_X11 |
| 180 | if (gpu->x11) |
| 181 | intel_wsi_x11_destroy(gpu->x11); |
| 182 | #endif |
| 183 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 184 | icd_free(gpu->primary_node); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 185 | icd_free(gpu); |
| 186 | } |
| 187 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 188 | /** |
| 189 | * Return true if \p gpu is a valid intel_gpu. |
| 190 | */ |
| 191 | bool intel_gpu_is_valid(const struct intel_gpu *gpu) |
| 192 | { |
| 193 | const struct intel_gpu *iter = intel_gpus; |
| 194 | |
| 195 | while (iter) { |
| 196 | if (iter == gpu) |
| 197 | return true; |
| 198 | iter = iter->next; |
| 199 | } |
| 200 | |
| 201 | return false; |
| 202 | } |
| 203 | |
| 204 | static int devid_to_gen(int devid) |
| 205 | { |
| 206 | int gen; |
| 207 | |
| 208 | if (gen_is_hsw(devid)) |
| 209 | gen = INTEL_GEN(7.5); |
| 210 | else if (gen_is_ivb(devid)) |
| 211 | gen = INTEL_GEN(7); |
| 212 | else if (gen_is_snb(devid)) |
| 213 | gen = INTEL_GEN(6); |
| 214 | else |
| 215 | gen = -1; |
| 216 | |
Chia-I Wu | bfce58e | 2014-08-28 23:23:33 +0800 | [diff] [blame] | 217 | #ifdef INTEL_GEN_SPECIALIZED |
| 218 | if (gen != INTEL_GEN(INTEL_GEN_SPECIALIZED)) |
| 219 | gen = -1; |
| 220 | #endif |
| 221 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 222 | return gen; |
| 223 | } |
| 224 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 225 | XGL_RESULT intel_gpu_add(int devid, const char *primary_node, |
| 226 | const char *render_node, struct intel_gpu **gpu_ret) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 227 | { |
| 228 | const int gen = devid_to_gen(devid); |
| 229 | struct intel_gpu *gpu; |
| 230 | |
| 231 | if (gen < 0) { |
| 232 | icd_log(XGL_DBG_MSG_WARNING, XGL_VALIDATION_LEVEL_0, XGL_NULL_HANDLE, |
| 233 | 0, 0, "unsupported device id 0x%04x", devid); |
| 234 | return XGL_ERROR_INITIALIZATION_FAILED; |
| 235 | } |
| 236 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 237 | gpu = gpu_create(gen, devid, primary_node, render_node); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 238 | if (!gpu) |
| 239 | return XGL_ERROR_OUT_OF_MEMORY; |
| 240 | |
| 241 | gpu->next = intel_gpus; |
| 242 | intel_gpus = gpu; |
| 243 | |
| 244 | *gpu_ret = gpu; |
| 245 | |
| 246 | return XGL_SUCCESS; |
| 247 | } |
| 248 | |
| 249 | void intel_gpu_remove_all(void) |
| 250 | { |
| 251 | struct intel_gpu *gpu = intel_gpus; |
| 252 | |
| 253 | while (gpu) { |
| 254 | struct intel_gpu *next = gpu->next; |
| 255 | |
| 256 | gpu_destroy(gpu); |
| 257 | gpu = next; |
| 258 | } |
| 259 | |
| 260 | intel_gpus = NULL; |
| 261 | } |
| 262 | |
| 263 | struct intel_gpu *intel_gpu_get_list(void) |
| 264 | { |
| 265 | return intel_gpus; |
| 266 | } |
| 267 | |
| 268 | void intel_gpu_get_props(const struct intel_gpu *gpu, |
| 269 | XGL_PHYSICAL_GPU_PROPERTIES *props) |
| 270 | { |
| 271 | const char *name; |
| 272 | size_t name_len; |
| 273 | |
| 274 | props->structSize = sizeof(*props); |
| 275 | |
| 276 | props->apiVersion = INTEL_API_VERSION; |
| 277 | props->driverVersion = INTEL_DRIVER_VERSION; |
| 278 | |
| 279 | props->vendorId = 0x8086; |
| 280 | props->deviceId = gpu->devid; |
| 281 | |
| 282 | props->gpuType = XGL_GPU_TYPE_INTEGRATED; |
| 283 | |
| 284 | /* copy GPU name */ |
| 285 | name = gpu_get_name(gpu); |
| 286 | name_len = strlen(name); |
| 287 | if (name_len > sizeof(props->gpuName) - 1) |
| 288 | name_len = sizeof(props->gpuName) - 1; |
| 289 | memcpy(props->gpuName, name, name_len); |
| 290 | props->gpuName[name_len] = '\0'; |
| 291 | |
Chia-I Wu | d6109bb | 2014-08-21 09:12:19 +0800 | [diff] [blame] | 292 | props->maxMemRefsPerSubmission = gpu->batch_buffer_reloc_count; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 293 | |
| 294 | props->virtualMemPageSize = 4096; |
| 295 | |
| 296 | /* no size limit, but no bounded buffer could exceed 2GB */ |
| 297 | props->maxInlineMemoryUpdateSize = 2u << 30; |
| 298 | |
| 299 | props->maxBoundDescriptorSets = 1; |
| 300 | props->maxThreadGroupSize = 512; |
| 301 | |
| 302 | /* incremented every 80ns */ |
| 303 | props->timestampFrequency = 1000 * 1000 * 1000 / 80; |
| 304 | |
| 305 | props->multiColorAttachmentClears = false; |
| 306 | } |
| 307 | |
| 308 | void intel_gpu_get_perf(const struct intel_gpu *gpu, |
| 309 | XGL_PHYSICAL_GPU_PERFORMANCE *perf) |
| 310 | { |
| 311 | /* TODO */ |
| 312 | perf->maxGpuClock = 1.0f; |
| 313 | perf->aluPerClock = 1.0f; |
| 314 | perf->texPerClock = 1.0f; |
| 315 | perf->primsPerClock = 1.0f; |
| 316 | perf->pixelsPerClock = 1.0f; |
| 317 | } |
| 318 | |
| 319 | void intel_gpu_get_queue_props(const struct intel_gpu *gpu, |
| 320 | enum intel_gpu_engine_type engine, |
| 321 | XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *props) |
| 322 | { |
| 323 | props->structSize = sizeof(*props); |
| 324 | |
| 325 | switch (engine) { |
| 326 | case INTEL_GPU_ENGINE_3D: |
| 327 | props->queueFlags = XGL_QUEUE_GRAPHICS_BIT | XGL_QUEUE_COMPUTE_BIT; |
| 328 | props->queueCount = 1; |
Chia-I Wu | ec84172 | 2014-08-25 22:36:01 +0800 | [diff] [blame] | 329 | props->maxAtomicCounters = INTEL_QUEUE_ATOMIC_COUNTER_COUNT; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 330 | props->supportsTimestamps = true; |
| 331 | break; |
| 332 | default: |
| 333 | assert(!"unknown engine type"); |
| 334 | return; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void intel_gpu_get_memory_props(const struct intel_gpu *gpu, |
| 339 | XGL_PHYSICAL_GPU_MEMORY_PROPERTIES *props) |
| 340 | { |
| 341 | props->structSize = sizeof(*props); |
| 342 | |
| 343 | props->supportsMigration = false; |
| 344 | |
| 345 | /* no kernel support yet */ |
| 346 | props->supportsVirtualMemoryRemapping = false; |
| 347 | |
Chia-I Wu | 54c0c4b | 2014-08-06 13:48:25 +0800 | [diff] [blame] | 348 | /* no winsys support for DRM_I915_GEM_USERPTR yet */ |
| 349 | props->supportsPinning = false; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 350 | } |
| 351 | |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 352 | int intel_gpu_get_max_threads(const struct intel_gpu *gpu, |
| 353 | XGL_PIPELINE_SHADER_STAGE stage) |
| 354 | { |
| 355 | switch (intel_gpu_gen(gpu)) { |
| 356 | case INTEL_GEN(7.5): |
| 357 | switch (stage) { |
| 358 | case XGL_SHADER_STAGE_VERTEX: |
| 359 | return (gpu->gt >= 2) ? 280 : 70; |
| 360 | case XGL_SHADER_STAGE_FRAGMENT: |
| 361 | return (gpu->gt == 3) ? 408 : |
| 362 | (gpu->gt == 2) ? 204 : 102; |
| 363 | default: |
| 364 | break; |
| 365 | } |
| 366 | break; |
| 367 | case INTEL_GEN(7): |
| 368 | switch (stage) { |
| 369 | case XGL_SHADER_STAGE_VERTEX: |
| 370 | return (gpu->gt == 2) ? 128 : 36; |
| 371 | case XGL_SHADER_STAGE_FRAGMENT: |
| 372 | return (gpu->gt == 2) ? 172 : 48; |
| 373 | default: |
| 374 | break; |
| 375 | } |
| 376 | break; |
| 377 | case INTEL_GEN(6): |
| 378 | switch (stage) { |
| 379 | case XGL_SHADER_STAGE_VERTEX: |
| 380 | return (gpu->gt == 2) ? 60 : 24; |
| 381 | case XGL_SHADER_STAGE_FRAGMENT: |
| 382 | return (gpu->gt == 2) ? 80 : 40; |
| 383 | default: |
| 384 | break; |
| 385 | } |
| 386 | break; |
| 387 | default: |
| 388 | break; |
| 389 | } |
| 390 | |
| 391 | icd_log(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, XGL_NULL_HANDLE, |
| 392 | 0, 0, "unknown Gen or shader stage"); |
| 393 | |
| 394 | switch (stage) { |
| 395 | case XGL_SHADER_STAGE_VERTEX: |
| 396 | return 1; |
| 397 | case XGL_SHADER_STAGE_FRAGMENT: |
| 398 | return 4; |
| 399 | default: |
| 400 | return 1; |
| 401 | } |
| 402 | } |
| 403 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 404 | void intel_gpu_associate_x11(struct intel_gpu *gpu, |
| 405 | struct intel_wsi_x11 *x11, |
| 406 | int fd) |
| 407 | { |
| 408 | #ifdef ENABLE_WSI_X11 |
| 409 | gpu->x11 = x11; |
| 410 | gpu->primary_fd_internal = fd; |
| 411 | #endif |
| 412 | } |
| 413 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 414 | XGL_RESULT intel_gpu_open(struct intel_gpu *gpu) |
| 415 | { |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 416 | int fd; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 417 | |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 418 | assert(!gpu->winsys); |
| 419 | |
| 420 | fd = gpu_open_primary_node(gpu); |
| 421 | if (fd < 0) |
| 422 | fd = gpu_open_render_node(gpu); |
| 423 | if (fd < 0) |
| 424 | return XGL_ERROR_UNKNOWN; |
| 425 | |
| 426 | gpu->winsys = intel_winsys_create_for_fd(fd); |
| 427 | if (!gpu->winsys) { |
| 428 | icd_log(XGL_DBG_MSG_ERROR, XGL_VALIDATION_LEVEL_0, XGL_NULL_HANDLE, |
| 429 | 0, 0, "failed to create GPU winsys"); |
| 430 | intel_gpu_close(gpu); |
| 431 | return XGL_ERROR_UNKNOWN; |
| 432 | } |
| 433 | |
| 434 | return XGL_SUCCESS; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void intel_gpu_close(struct intel_gpu *gpu) |
| 438 | { |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 439 | if (gpu->winsys) { |
| 440 | intel_winsys_destroy(gpu->winsys); |
| 441 | gpu->winsys = NULL; |
| 442 | } |
| 443 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 444 | gpu_close_primary_node(gpu); |
| 445 | gpu_close_render_node(gpu); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 446 | } |
| 447 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 448 | enum intel_ext_type intel_gpu_lookup_extension(const struct intel_gpu *gpu, |
| 449 | const char *ext) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 450 | { |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 451 | enum intel_ext_type type; |
| 452 | |
| 453 | for (type = 0; type < ARRAY_SIZE(intel_gpu_exts); type++) { |
| 454 | if (intel_gpu_exts[type] && strcmp(intel_gpu_exts[type], ext) == 0) |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | assert(type < INTEL_EXT_COUNT || type == INTEL_EXT_INVALID); |
| 459 | |
| 460 | return type; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 461 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 462 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 463 | ICD_EXPORT XGL_RESULT XGLAPI xglGetGpuInfo( |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 464 | XGL_PHYSICAL_GPU gpu_, |
| 465 | XGL_PHYSICAL_GPU_INFO_TYPE infoType, |
| 466 | XGL_SIZE* pDataSize, |
| 467 | XGL_VOID* pData) |
| 468 | { |
| 469 | const struct intel_gpu *gpu = intel_gpu(gpu_); |
| 470 | XGL_RESULT ret = XGL_SUCCESS; |
| 471 | |
| 472 | switch (infoType) { |
| 473 | case XGL_INFO_TYPE_PHYSICAL_GPU_PROPERTIES: |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 474 | *pDataSize = sizeof(XGL_PHYSICAL_GPU_PROPERTIES); |
Jon Ashburn | 408daec | 2014-12-05 09:23:52 -0700 | [diff] [blame] | 475 | if (pData == NULL) { |
| 476 | return ret; |
| 477 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 478 | intel_gpu_get_props(gpu, pData); |
| 479 | break; |
| 480 | |
| 481 | case XGL_INFO_TYPE_PHYSICAL_GPU_PERFORMANCE: |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 482 | *pDataSize = sizeof(XGL_PHYSICAL_GPU_PERFORMANCE); |
Jon Ashburn | 408daec | 2014-12-05 09:23:52 -0700 | [diff] [blame] | 483 | if (pData == NULL) { |
| 484 | return ret; |
| 485 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 486 | intel_gpu_get_perf(gpu, pData); |
| 487 | break; |
| 488 | |
| 489 | case XGL_INFO_TYPE_PHYSICAL_GPU_QUEUE_PROPERTIES: |
| 490 | /* |
| 491 | * XGL Programmers guide, page 33: |
| 492 | * to determine the data size an application calls |
| 493 | * xglGetGpuInfo() with a NULL data pointer. The |
| 494 | * expected data size for all queue property structures |
| 495 | * is returned in pDataSize |
| 496 | */ |
| 497 | *pDataSize = sizeof(XGL_PHYSICAL_GPU_QUEUE_PROPERTIES) * |
| 498 | INTEL_GPU_ENGINE_COUNT; |
| 499 | if (pData != NULL) { |
| 500 | XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *dst = pData; |
| 501 | int engine; |
| 502 | |
| 503 | for (engine = 0; engine < INTEL_GPU_ENGINE_COUNT; engine++) { |
| 504 | intel_gpu_get_queue_props(gpu, engine, dst); |
| 505 | dst++; |
| 506 | } |
| 507 | } |
| 508 | break; |
| 509 | |
| 510 | case XGL_INFO_TYPE_PHYSICAL_GPU_MEMORY_PROPERTIES: |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 511 | *pDataSize = sizeof(XGL_PHYSICAL_GPU_MEMORY_PROPERTIES); |
Jon Ashburn | 408daec | 2014-12-05 09:23:52 -0700 | [diff] [blame] | 512 | if (pData == NULL) { |
| 513 | return ret; |
| 514 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 515 | intel_gpu_get_memory_props(gpu, pData); |
| 516 | break; |
| 517 | |
| 518 | default: |
| 519 | ret = XGL_ERROR_INVALID_VALUE; |
| 520 | } |
| 521 | |
| 522 | return ret; |
| 523 | } |
| 524 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 525 | ICD_EXPORT XGL_RESULT XGLAPI xglGetExtensionSupport( |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 526 | XGL_PHYSICAL_GPU gpu_, |
| 527 | const XGL_CHAR* pExtName) |
| 528 | { |
| 529 | struct intel_gpu *gpu = intel_gpu(gpu_); |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 530 | const enum intel_ext_type ext = intel_gpu_lookup_extension(gpu, pExtName); |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 531 | |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 532 | return (ext != INTEL_EXT_INVALID) ? |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 533 | XGL_SUCCESS : XGL_ERROR_INVALID_EXTENSION; |
| 534 | } |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 535 | |
Chia-I Wu | 9617727 | 2015-01-03 15:27:41 +0800 | [diff] [blame] | 536 | ICD_EXPORT XGL_RESULT XGLAPI xglGetMultiGpuCompatibility( |
Chia-I Wu | 452f5e8 | 2014-08-31 12:39:05 +0800 | [diff] [blame] | 537 | XGL_PHYSICAL_GPU gpu0_, |
| 538 | XGL_PHYSICAL_GPU gpu1_, |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 539 | XGL_GPU_COMPATIBILITY_INFO* pInfo) |
| 540 | { |
Chia-I Wu | 452f5e8 | 2014-08-31 12:39:05 +0800 | [diff] [blame] | 541 | const struct intel_gpu *gpu0 = intel_gpu(gpu0_); |
| 542 | const struct intel_gpu *gpu1 = intel_gpu(gpu1_); |
| 543 | XGL_FLAGS compat = XGL_GPU_COMPAT_IQ_MATCH_BIT | |
| 544 | XGL_GPU_COMPAT_PEER_TRANSFER_BIT | |
| 545 | XGL_GPU_COMPAT_SHARED_MEMORY_BIT | |
| 546 | XGL_GPU_COMPAT_SHARED_GPU0_DISPLAY_BIT | |
| 547 | XGL_GPU_COMPAT_SHARED_GPU1_DISPLAY_BIT; |
| 548 | |
| 549 | if (intel_gpu_gen(gpu0) == intel_gpu_gen(gpu1)) |
| 550 | compat |= XGL_GPU_COMPAT_ASIC_FEATURES_BIT; |
| 551 | |
| 552 | pInfo->compatibilityFlags = compat; |
| 553 | |
| 554 | return XGL_SUCCESS; |
Chia-I Wu | 251e7d9 | 2014-08-19 13:35:42 +0800 | [diff] [blame] | 555 | } |