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