Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 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 | 032a2e3 | 2015-01-19 11:14:00 +0800 | [diff] [blame] | 38 | #include "instance.h" |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 39 | #include "wsi.h" |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 40 | #include "vk_debug_report_lunarg.h" |
| 41 | #include "vk_debug_marker_lunarg.h" |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 42 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 43 | static int gpu_open_primary_node(struct intel_gpu *gpu) |
| 44 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 45 | if (gpu->primary_fd_internal < 0) |
| 46 | gpu->primary_fd_internal = open(gpu->primary_node, O_RDWR); |
| 47 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 48 | return gpu->primary_fd_internal; |
| 49 | } |
| 50 | |
| 51 | static void gpu_close_primary_node(struct intel_gpu *gpu) |
| 52 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 53 | if (gpu->primary_fd_internal >= 0) { |
| 54 | close(gpu->primary_fd_internal); |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 55 | gpu->primary_fd_internal = -1; |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 56 | } |
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) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 64 | intel_log(gpu, VK_DBG_REPORT_ERROR_BIT, 0, VK_NULL_HANDLE, 0, |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 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 | 8635e91 | 2015-04-09 14:13:57 +0800 | [diff] [blame] | 117 | intel_wsi_gpu_cleanup(gpu); |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 118 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 119 | intel_gpu_cleanup_winsys(gpu); |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 120 | |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 121 | intel_free(gpu, gpu->primary_node); |
| 122 | intel_free(gpu, gpu); |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int devid_to_gen(int devid) |
| 126 | { |
| 127 | int gen; |
| 128 | |
| 129 | if (gen_is_hsw(devid)) |
| 130 | gen = INTEL_GEN(7.5); |
| 131 | else if (gen_is_ivb(devid)) |
| 132 | gen = INTEL_GEN(7); |
| 133 | else if (gen_is_snb(devid)) |
| 134 | gen = INTEL_GEN(6); |
| 135 | else |
| 136 | gen = -1; |
| 137 | |
| 138 | #ifdef INTEL_GEN_SPECIALIZED |
| 139 | if (gen != INTEL_GEN(INTEL_GEN_SPECIALIZED)) |
| 140 | gen = -1; |
| 141 | #endif |
| 142 | |
| 143 | return gen; |
| 144 | } |
| 145 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 146 | VkResult intel_gpu_create(const struct intel_instance *instance, int devid, |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 147 | const char *primary_node, const char *render_node, |
| 148 | struct intel_gpu **gpu_ret) |
| 149 | { |
| 150 | const int gen = devid_to_gen(devid); |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 151 | size_t primary_len, render_len; |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 152 | struct intel_gpu *gpu; |
| 153 | |
| 154 | if (gen < 0) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 155 | intel_log(instance, VK_DBG_REPORT_WARN_BIT, 0, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 156 | VK_NULL_HANDLE, 0, 0, "unsupported device id 0x%04x", devid); |
| 157 | return VK_ERROR_INITIALIZATION_FAILED; |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 158 | } |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 159 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 160 | gpu = intel_alloc(instance, sizeof(*gpu), 0, VK_SYSTEM_ALLOC_TYPE_API_OBJECT); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 161 | if (!gpu) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 162 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 163 | |
| 164 | memset(gpu, 0, sizeof(*gpu)); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 165 | /* there is no VK_DBG_OBJECT_GPU */ |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 166 | intel_handle_init(&gpu->handle, VK_OBJECT_TYPE_PHYSICAL_DEVICE, instance); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 167 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 168 | gpu->devid = devid; |
| 169 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 170 | primary_len = strlen(primary_node); |
| 171 | render_len = (render_node) ? strlen(render_node) : 0; |
| 172 | |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 173 | gpu->primary_node = intel_alloc(gpu, primary_len + 1 + |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 174 | ((render_len) ? (render_len + 1) : 0), 0, VK_SYSTEM_ALLOC_TYPE_INTERNAL); |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 175 | if (!gpu->primary_node) { |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 176 | intel_free(instance, gpu); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 177 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 178 | } |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 179 | |
| 180 | memcpy(gpu->primary_node, primary_node, primary_len + 1); |
| 181 | |
| 182 | if (render_node) { |
| 183 | gpu->render_node = gpu->primary_node + primary_len + 1; |
| 184 | memcpy(gpu->render_node, render_node, render_len + 1); |
BogDan Vatra | 80f8061 | 2015-04-30 19:28:26 +0300 | [diff] [blame] | 185 | } else { |
| 186 | gpu->render_node = gpu->primary_node; |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 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 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 215 | return VK_SUCCESS; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 216 | } |
| 217 | |
Mark Lobodzinski | 7dae686 | 2015-09-07 12:56:17 -0600 | [diff] [blame] | 218 | void intel_gpu_get_limits(VkPhysicalDeviceLimits *pLimits) |
| 219 | { |
| 220 | // TODO: fill out more limits |
| 221 | memset(pLimits, 0, sizeof(*pLimits)); |
| 222 | |
| 223 | // no size limit, but no bounded buffer could exceed 2GB |
| 224 | pLimits->maxBoundDescriptorSets = 1; |
| 225 | pLimits->maxComputeWorkGroupInvocations = 512; |
| 226 | |
| 227 | // incremented every 80ns |
| 228 | pLimits->timestampFrequency = 1000 * 1000 * 1000 / 80; |
| 229 | |
| 230 | // hardware is limited to 16 viewports |
| 231 | pLimits->maxViewports = INTEL_MAX_VIEWPORTS; |
| 232 | pLimits->maxColorAttachments = INTEL_MAX_RENDER_TARGETS; |
| 233 | |
| 234 | // ? |
| 235 | pLimits->maxDescriptorSets = 2; |
| 236 | pLimits->maxImageDimension1D = 8192; |
| 237 | pLimits->maxImageDimension2D = 8192; |
| 238 | pLimits->maxImageDimension3D = 8192; |
| 239 | pLimits->maxImageDimensionCube = 8192; |
| 240 | pLimits->maxImageArrayLayers = 2048; |
| 241 | pLimits->maxTexelBufferSize = 128 * 1024 * 1024; // 128M texels hard limit |
| 242 | pLimits->maxUniformBufferSize = 64 * 1024; // not hard limit |
| 243 | |
| 244 | /* HW has two per-stage resource tables: |
| 245 | * - samplers, 16 per stage on IVB; blocks of 16 on HSW+ via shader hack, as the |
| 246 | * table base ptr used by the sampler hw is under shader sw control. |
| 247 | * |
| 248 | * - binding table entries, 250 total on all gens, shared between |
| 249 | * textures, RT, images, SSBO, UBO, ... |
| 250 | * the top few indices (250-255) are used for 'stateless' access with various cache |
| 251 | * options, and for SLM access. |
| 252 | */ |
| 253 | pLimits->maxPerStageDescriptorSamplers = 16; // technically more on HSW+.. |
| 254 | pLimits->maxDescriptorSetSamplers = 16; |
| 255 | |
| 256 | pLimits->maxPerStageDescriptorUniformBuffers = 128; |
| 257 | pLimits->maxDescriptorSetUniformBuffers = 128; |
| 258 | |
| 259 | pLimits->maxPerStageDescriptorSampledImages = 128; |
| 260 | pLimits->maxDescriptorSetSampledImages = 128; |
| 261 | |
| 262 | // storage images and buffers not implemented; left at zero |
| 263 | } |
| 264 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 265 | void intel_gpu_get_props(const struct intel_gpu *gpu, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 266 | VkPhysicalDeviceProperties *props) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 267 | { |
| 268 | const char *name; |
| 269 | size_t name_len; |
| 270 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 271 | props->apiVersion = INTEL_API_VERSION; |
| 272 | props->driverVersion = INTEL_DRIVER_VERSION; |
| 273 | |
| 274 | props->vendorId = 0x8086; |
| 275 | props->deviceId = gpu->devid; |
| 276 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 277 | props->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 278 | |
| 279 | /* copy GPU name */ |
| 280 | name = gpu_get_name(gpu); |
| 281 | name_len = strlen(name); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 282 | if (name_len > sizeof(props->deviceName) - 1) |
| 283 | name_len = sizeof(props->deviceName) - 1; |
| 284 | memcpy(props->deviceName, name, name_len); |
| 285 | props->deviceName[name_len] = '\0'; |
Mark Lobodzinski | 7dae686 | 2015-09-07 12:56:17 -0600 | [diff] [blame] | 286 | |
| 287 | intel_gpu_get_limits(&props->limits); |
| 288 | |
| 289 | intel_gpu_get_sparse_properties(&props->sparseProperties); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 292 | void intel_gpu_get_queue_props(const struct intel_gpu *gpu, |
| 293 | enum intel_gpu_engine_type engine, |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 294 | VkQueueFamilyProperties *props) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 295 | { |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 296 | switch (engine) { |
| 297 | case INTEL_GPU_ENGINE_3D: |
Mark Lobodzinski | fb9f564 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 298 | props->queueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 299 | props->queueCount = 1; |
Courtney Goeltzenleuchter | 68535a6 | 2015-10-19 16:03:32 -0600 | [diff] [blame^] | 300 | props->timestampValidBits = 0; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 301 | break; |
| 302 | default: |
| 303 | assert(!"unknown engine type"); |
| 304 | return; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | void intel_gpu_get_memory_props(const struct intel_gpu *gpu, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 309 | VkPhysicalDeviceMemoryProperties *props) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 310 | { |
Mark Lobodzinski | 7234629 | 2015-07-02 16:49:40 -0600 | [diff] [blame] | 311 | memset(props, 0, sizeof(VkPhysicalDeviceMemoryProperties)); |
| 312 | props->memoryTypeCount = INTEL_MEMORY_TYPE_COUNT; |
| 313 | props->memoryHeapCount = INTEL_MEMORY_HEAP_COUNT; |
| 314 | |
| 315 | // For now, Intel will support one memory type |
| 316 | for (uint32_t i = 0; i < props->memoryTypeCount; i++) { |
| 317 | assert(props->memoryTypeCount == 1); |
| 318 | props->memoryTypes[i].propertyFlags = INTEL_MEMORY_PROPERTY_ALL; |
| 319 | props->memoryTypes[i].heapIndex = i; |
| 320 | } |
| 321 | |
| 322 | // For now, Intel will support a single heap with all available memory |
| 323 | for (uint32_t i = 0; i < props->memoryHeapCount; i++) { |
| 324 | assert(props->memoryHeapCount == 1); |
| 325 | props->memoryHeaps[0].size = INTEL_MEMORY_HEAP_SIZE; |
| 326 | } |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 327 | } |
| 328 | |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 329 | int intel_gpu_get_max_threads(const struct intel_gpu *gpu, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 330 | VkShaderStage stage) |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 331 | { |
| 332 | switch (intel_gpu_gen(gpu)) { |
| 333 | case INTEL_GEN(7.5): |
| 334 | switch (stage) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 335 | case VK_SHADER_STAGE_VERTEX: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 336 | return (gpu->gt >= 2) ? 280 : 70; |
Cody Northrop | 293d450 | 2015-05-05 09:38:03 -0600 | [diff] [blame] | 337 | case VK_SHADER_STAGE_GEOMETRY: |
| 338 | /* values from ilo_gpe_init_gs_cso_gen7 */ |
| 339 | return (gpu->gt >= 2) ? 256 : 70; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 340 | case VK_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 341 | return (gpu->gt == 3) ? 408 : |
| 342 | (gpu->gt == 2) ? 204 : 102; |
| 343 | default: |
| 344 | break; |
| 345 | } |
| 346 | break; |
| 347 | case INTEL_GEN(7): |
| 348 | switch (stage) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 349 | case VK_SHADER_STAGE_VERTEX: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 350 | return (gpu->gt == 2) ? 128 : 36; |
Cody Northrop | 293d450 | 2015-05-05 09:38:03 -0600 | [diff] [blame] | 351 | case VK_SHADER_STAGE_GEOMETRY: |
| 352 | /* values from ilo_gpe_init_gs_cso_gen7 */ |
| 353 | return (gpu->gt == 2) ? 128 : 36; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 354 | case VK_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 355 | return (gpu->gt == 2) ? 172 : 48; |
| 356 | default: |
| 357 | break; |
| 358 | } |
| 359 | break; |
| 360 | case INTEL_GEN(6): |
| 361 | switch (stage) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 362 | case VK_SHADER_STAGE_VERTEX: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 363 | return (gpu->gt == 2) ? 60 : 24; |
Cody Northrop | 293d450 | 2015-05-05 09:38:03 -0600 | [diff] [blame] | 364 | case VK_SHADER_STAGE_GEOMETRY: |
| 365 | /* values from ilo_gpe_init_gs_cso_gen6 */ |
| 366 | return (gpu->gt == 2) ? 28 : 21; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 367 | case VK_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 368 | return (gpu->gt == 2) ? 80 : 40; |
| 369 | default: |
| 370 | break; |
| 371 | } |
| 372 | break; |
| 373 | default: |
| 374 | break; |
| 375 | } |
| 376 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 377 | intel_log(gpu, VK_DBG_REPORT_ERROR_BIT, 0, VK_NULL_HANDLE, |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 378 | 0, 0, "unknown Gen or shader stage"); |
| 379 | |
| 380 | switch (stage) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 381 | case VK_SHADER_STAGE_VERTEX: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 382 | return 1; |
Cody Northrop | 293d450 | 2015-05-05 09:38:03 -0600 | [diff] [blame] | 383 | case VK_SHADER_STAGE_GEOMETRY: |
| 384 | return 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 385 | case VK_SHADER_STAGE_FRAGMENT: |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 386 | return 4; |
| 387 | default: |
| 388 | return 1; |
| 389 | } |
| 390 | } |
| 391 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 392 | int intel_gpu_get_primary_fd(struct intel_gpu *gpu) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 393 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 394 | return gpu_open_primary_node(gpu); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 395 | } |
| 396 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 397 | VkResult intel_gpu_init_winsys(struct intel_gpu *gpu) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 398 | { |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 399 | int fd; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 400 | |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 401 | assert(!gpu->winsys); |
| 402 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 403 | fd = gpu_open_render_node(gpu); |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 404 | if (fd < 0) |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 405 | return VK_ERROR_INITIALIZATION_FAILED; |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 406 | |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 407 | gpu->winsys = intel_winsys_create_for_fd(gpu->handle.instance->icd, fd); |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 408 | if (!gpu->winsys) { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 409 | intel_log(gpu, VK_DBG_REPORT_ERROR_BIT, 0, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 410 | VK_NULL_HANDLE, 0, 0, "failed to create GPU winsys"); |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 411 | gpu_close_render_node(gpu); |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 412 | return VK_ERROR_INITIALIZATION_FAILED; |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 413 | } |
| 414 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 415 | return VK_SUCCESS; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 416 | } |
| 417 | |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 418 | void intel_gpu_cleanup_winsys(struct intel_gpu *gpu) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 419 | { |
Chia-I Wu | d896593 | 2014-10-13 13:32:37 +0800 | [diff] [blame] | 420 | if (gpu->winsys) { |
| 421 | intel_winsys_destroy(gpu->winsys); |
| 422 | gpu->winsys = NULL; |
| 423 | } |
| 424 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 425 | gpu_close_primary_node(gpu); |
| 426 | gpu_close_render_node(gpu); |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 427 | } |
| 428 | |
Courtney Goeltzenleuchter | 95b7372 | 2015-06-08 18:08:35 -0600 | [diff] [blame] | 429 | enum intel_phy_dev_ext_type intel_gpu_lookup_phy_dev_extension( |
| 430 | const struct intel_gpu *gpu, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 431 | const char *ext) |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 432 | { |
Courtney Goeltzenleuchter | b426925 | 2015-07-11 10:08:36 -0600 | [diff] [blame] | 433 | uint32_t type; |
| 434 | uint32_t array_size = ARRAY_SIZE(intel_phy_dev_gpu_exts); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 435 | |
Courtney Goeltzenleuchter | b426925 | 2015-07-11 10:08:36 -0600 | [diff] [blame] | 436 | for (type = 0; type < array_size; type++) { |
Courtney Goeltzenleuchter | 95b7372 | 2015-06-08 18:08:35 -0600 | [diff] [blame] | 437 | if (compare_vk_extension_properties(&intel_phy_dev_gpu_exts[type], ext)) |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 438 | break; |
| 439 | } |
| 440 | |
Courtney Goeltzenleuchter | b426925 | 2015-07-11 10:08:36 -0600 | [diff] [blame] | 441 | assert(type < array_size || type == INTEL_PHY_DEV_EXT_INVALID); |
Chia-I Wu | 1db76e0 | 2014-09-15 14:21:14 +0800 | [diff] [blame] | 442 | |
| 443 | return type; |
Chia-I Wu | 214dac6 | 2014-08-05 11:07:40 +0800 | [diff] [blame] | 444 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 445 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 446 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties( |
| 447 | VkPhysicalDevice gpu_, |
| 448 | VkPhysicalDeviceProperties* pProperties) |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 449 | { |
Chia-I Wu | 41858c8 | 2015-04-04 16:39:25 +0800 | [diff] [blame] | 450 | struct intel_gpu *gpu = intel_gpu(gpu_); |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 451 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 452 | intel_gpu_get_props(gpu, pProperties); |
| 453 | return VK_SUCCESS; |
| 454 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 455 | |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 456 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties( |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 457 | VkPhysicalDevice gpu_, |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 458 | uint32_t* pCount, |
| 459 | VkQueueFamilyProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 460 | { |
| 461 | struct intel_gpu *gpu = intel_gpu(gpu_); |
| 462 | int engine; |
| 463 | |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 464 | if (pProperties == NULL) { |
| 465 | *pCount = INTEL_GPU_ENGINE_COUNT; |
| 466 | return VK_SUCCESS; |
| 467 | } |
| 468 | |
Cody Northrop | ef72e2a | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 469 | for (engine = 0; engine < *pCount; engine++) { |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 470 | intel_gpu_get_queue_props(gpu, engine, pProperties); |
| 471 | pProperties++; |
| 472 | } |
| 473 | return VK_SUCCESS; |
| 474 | } |
| 475 | |
| 476 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties( |
| 477 | VkPhysicalDevice gpu_, |
| 478 | VkPhysicalDeviceMemoryProperties* pProperties) |
| 479 | { |
| 480 | struct intel_gpu *gpu = intel_gpu(gpu_); |
| 481 | |
| 482 | intel_gpu_get_memory_props(gpu, pProperties); |
| 483 | return VK_SUCCESS; |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 484 | } |
| 485 | |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 486 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures( |
| 487 | VkPhysicalDevice physicalDevice, |
| 488 | VkPhysicalDeviceFeatures* pFeatures) |
| 489 | { |
| 490 | VkResult ret = VK_SUCCESS; |
| 491 | |
| 492 | /* TODO: fill out features */ |
| 493 | memset(pFeatures, 0, sizeof(*pFeatures)); |
| 494 | |
| 495 | return ret; |
| 496 | } |
| 497 | |
Mark Lobodzinski | 7dae686 | 2015-09-07 12:56:17 -0600 | [diff] [blame] | 498 | void intel_gpu_get_sparse_properties(VkPhysicalDeviceSparseProperties *pProps) |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 499 | { |
Mark Lobodzinski | 7dae686 | 2015-09-07 12:56:17 -0600 | [diff] [blame] | 500 | memset(pProps, 0, sizeof(*pProps)); |
Chris Forbes | d757630 | 2015-06-21 22:55:02 +1200 | [diff] [blame] | 501 | } |
| 502 | |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 503 | ICD_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties( |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 504 | VkPhysicalDevice physicalDevice, |
| 505 | const char* pLayerName, |
| 506 | uint32_t* pCount, |
| 507 | VkExtensionProperties* pProperties) |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 508 | { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 509 | uint32_t copy_size; |
Courtney Goeltzenleuchter | b426925 | 2015-07-11 10:08:36 -0600 | [diff] [blame] | 510 | uint32_t extension_count = ARRAY_SIZE(intel_phy_dev_gpu_exts); |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 511 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 512 | if (pProperties == NULL) { |
| 513 | *pCount = INTEL_PHY_DEV_EXT_COUNT; |
| 514 | return VK_SUCCESS; |
| 515 | } |
| 516 | |
Courtney Goeltzenleuchter | b426925 | 2015-07-11 10:08:36 -0600 | [diff] [blame] | 517 | copy_size = *pCount < extension_count ? *pCount : extension_count; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 518 | memcpy(pProperties, intel_phy_dev_gpu_exts, copy_size * sizeof(VkExtensionProperties)); |
| 519 | *pCount = copy_size; |
Courtney Goeltzenleuchter | b426925 | 2015-07-11 10:08:36 -0600 | [diff] [blame] | 520 | if (copy_size < extension_count) { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 521 | return VK_INCOMPLETE; |
| 522 | } |
| 523 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 524 | return VK_SUCCESS; |
| 525 | } |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 526 | |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 527 | ICD_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties( |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 528 | VkPhysicalDevice physicalDevice, |
| 529 | uint32_t* pCount, |
| 530 | VkLayerProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 531 | { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 532 | *pCount = 0; |
Tobin Ehlis | 0ef6ec5 | 2015-04-16 12:51:37 -0600 | [diff] [blame] | 533 | return VK_SUCCESS; |
Chia-I Wu | bec90a0 | 2014-08-06 12:33:03 +0800 | [diff] [blame] | 534 | } |
Mark Lobodzinski | 83d4e6a | 2015-07-03 15:58:09 -0600 | [diff] [blame] | 535 | |
| 536 | ICD_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties( |
| 537 | VkPhysicalDevice physicalDevice, |
| 538 | VkFormat format, |
| 539 | VkImageType type, |
| 540 | uint32_t samples, |
| 541 | VkImageUsageFlags usage, |
| 542 | VkImageTiling tiling, |
| 543 | uint32_t* pNumProperties, |
| 544 | VkSparseImageFormatProperties* pProperties) |
| 545 | { |
| 546 | *pNumProperties = 0; |
| 547 | return VK_SUCCESS; |
| 548 | } |
| 549 | |