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