Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 2 | * |
Courtney Goeltzenleuchter | 8a17da5 | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 3 | * Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 23 | * Author: Chia-I Wu <olv@lunarg.com> |
| 24 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 25 | * |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 28 | #include "icd-enumerate-drm.h" |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 29 | #include "gpu.h" |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 30 | #include "instance.h" |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 31 | |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 32 | static int intel_devid_override; |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 33 | int intel_debug = -1; |
| 34 | |
Courtney Goeltzenleuchter | 33a54d5 | 2015-06-09 07:50:24 -0600 | [diff] [blame] | 35 | void *intel_alloc(const void *handle, |
| 36 | size_t size, size_t alignment, |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 37 | VkSystemAllocationScope scope) |
Courtney Goeltzenleuchter | 33a54d5 | 2015-06-09 07:50:24 -0600 | [diff] [blame] | 38 | { |
| 39 | assert(intel_handle_validate(handle)); |
| 40 | return icd_instance_alloc(((const struct intel_handle *) handle)->instance->icd, |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 41 | size, alignment, scope); |
Courtney Goeltzenleuchter | 33a54d5 | 2015-06-09 07:50:24 -0600 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void intel_free(const void *handle, void *ptr) |
| 45 | { |
| 46 | assert(intel_handle_validate(handle)); |
| 47 | icd_instance_free(((const struct intel_handle *) handle)->instance->icd, ptr); |
| 48 | } |
| 49 | |
| 50 | void intel_logv(const void *handle, |
| 51 | VkFlags msg_flags, |
Tony Barbour | de4124d | 2015-07-03 10:33:54 -0600 | [diff] [blame] | 52 | VkDbgObjectType obj_type, uint64_t src_object, |
Courtney Goeltzenleuchter | 33a54d5 | 2015-06-09 07:50:24 -0600 | [diff] [blame] | 53 | size_t location, int32_t msg_code, |
| 54 | const char *format, va_list ap) |
| 55 | { |
| 56 | char msg[256]; |
| 57 | int ret; |
| 58 | |
| 59 | ret = vsnprintf(msg, sizeof(msg), format, ap); |
| 60 | if (ret >= sizeof(msg) || ret < 0) |
| 61 | msg[sizeof(msg) - 1] = '\0'; |
| 62 | |
| 63 | assert(intel_handle_validate(handle)); |
| 64 | icd_instance_log(((const struct intel_handle *) handle)->instance->icd, |
| 65 | msg_flags, |
| 66 | obj_type, src_object, /* obj_type, object */ |
| 67 | location, msg_code, /* location, msg_code */ |
| 68 | msg); |
| 69 | } |
| 70 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 71 | static void intel_debug_init(void) |
| 72 | { |
| 73 | const char *env; |
| 74 | |
| 75 | if (intel_debug >= 0) |
| 76 | return; |
| 77 | |
| 78 | intel_debug = 0; |
| 79 | |
| 80 | /* parse comma-separated debug options */ |
Courtney Goeltzenleuchter | 893f287 | 2015-07-29 09:08:22 -0600 | [diff] [blame] | 81 | env = getenv("VK_INTEL_DEBUG"); |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 82 | while (env) { |
| 83 | const char *p = strchr(env, ','); |
| 84 | size_t len; |
| 85 | |
| 86 | if (p) |
| 87 | len = p - env; |
| 88 | else |
| 89 | len = strlen(env); |
| 90 | |
Courtney Goeltzenleuchter | d9fc984 | 2014-10-13 12:58:25 -0600 | [diff] [blame] | 91 | if (len > 0) { |
| 92 | if (strncmp(env, "batch", len) == 0) { |
| 93 | intel_debug |= INTEL_DEBUG_BATCH; |
| 94 | } else if (strncmp(env, "nohw", len) == 0) { |
| 95 | intel_debug |= INTEL_DEBUG_NOHW; |
Chia-I Wu | 3fb47ce | 2014-10-28 11:19:36 +0800 | [diff] [blame] | 96 | } else if (strncmp(env, "nocache", len) == 0) { |
| 97 | intel_debug |= INTEL_DEBUG_NOCACHE; |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 98 | } else if (strncmp(env, "nohiz", len) == 0) { |
| 99 | intel_debug |= INTEL_DEBUG_NOHIZ; |
Chia-I Wu | 465fe21 | 2015-02-11 11:27:06 -0700 | [diff] [blame] | 100 | } else if (strncmp(env, "hang", len) == 0) { |
| 101 | intel_debug |= INTEL_DEBUG_HANG; |
Courtney Goeltzenleuchter | d9fc984 | 2014-10-13 12:58:25 -0600 | [diff] [blame] | 102 | } else if (strncmp(env, "0x", 2) == 0) { |
| 103 | intel_debug |= INTEL_DEBUG_NOHW; |
| 104 | intel_devid_override = strtol(env, NULL, 16); |
| 105 | } |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 106 | } |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 107 | |
| 108 | if (!p) |
| 109 | break; |
| 110 | |
| 111 | env = p + 1; |
| 112 | } |
| 113 | } |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame] | 114 | |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 115 | static void intel_instance_add_gpu(struct intel_instance *instance, |
| 116 | struct intel_gpu *gpu) |
| 117 | { |
| 118 | gpu->next = instance->gpus; |
| 119 | instance->gpus = gpu; |
| 120 | } |
| 121 | |
| 122 | static void intel_instance_remove_gpus(struct intel_instance *instance) |
| 123 | { |
| 124 | struct intel_gpu *gpu = instance->gpus; |
| 125 | |
| 126 | while (gpu) { |
| 127 | struct intel_gpu *next = gpu->next; |
| 128 | |
| 129 | intel_gpu_destroy(gpu); |
| 130 | gpu = next; |
| 131 | } |
| 132 | |
| 133 | instance->gpus = NULL; |
| 134 | } |
| 135 | |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 136 | static void intel_instance_destroy(struct intel_instance *instance) |
Jon Ashburn | fa836e0 | 2015-01-28 18:26:16 -0700 | [diff] [blame] | 137 | { |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 138 | struct icd_instance *icd = instance->icd; |
| 139 | |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 140 | intel_instance_remove_gpus(instance); |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 141 | icd_instance_free(icd, instance); |
| 142 | |
| 143 | icd_instance_destroy(icd); |
Jon Ashburn | fa836e0 | 2015-01-28 18:26:16 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 146 | static VkResult intel_instance_create( |
| 147 | const VkInstanceCreateInfo* info, |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 148 | const VkAllocationCallbacks* allocator, |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 149 | struct intel_instance **pInstance) |
Jon Ashburn | fa836e0 | 2015-01-28 18:26:16 -0700 | [diff] [blame] | 150 | { |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 151 | struct intel_instance *instance; |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 152 | struct icd_instance *icd; |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 153 | uint32_t i; |
Jon Ashburn | fa836e0 | 2015-01-28 18:26:16 -0700 | [diff] [blame] | 154 | |
| 155 | intel_debug_init(); |
| 156 | |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 157 | icd = icd_instance_create(info->pApplicationInfo, allocator); |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 158 | if (!icd) |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 159 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 160 | |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 161 | instance = icd_instance_alloc(icd, sizeof(*instance), 0, |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 162 | VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 163 | if (!instance) { |
| 164 | icd_instance_destroy(icd); |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 165 | return VK_ERROR_OUT_OF_HOST_MEMORY; |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 166 | } |
| 167 | |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 168 | memset(instance, 0, sizeof(*instance)); |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 169 | intel_handle_init(&instance->handle, VK_OBJECT_TYPE_INSTANCE, instance); |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 170 | |
Chia-I Wu | 96a41bc | 2015-02-21 14:19:23 +0800 | [diff] [blame] | 171 | instance->icd = icd; |
| 172 | |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 173 | for (i = 0; i < info->enabledExtensionNameCount; i++) { |
| 174 | const enum intel_global_ext_type ext = |
| 175 | intel_gpu_lookup_global_extension( |
| 176 | info->ppEnabledExtensionNames[i]); |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 177 | |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 178 | if (ext != INTEL_GLOBAL_EXT_INVALID) { |
| 179 | instance->global_exts[ext] = true; |
| 180 | } else { |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 181 | /* Fail create if extensions are specified that |
| 182 | * ICD cannot satisfy. Loader will filter out extensions / layers |
| 183 | * not meant by the ICD. |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 184 | */ |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 185 | icd_instance_destroy(icd); |
| 186 | intel_instance_destroy(instance); |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 187 | return VK_ERROR_EXTENSION_NOT_PRESENT; |
Courtney Goeltzenleuchter | 9ecf685 | 2015-06-09 08:22:48 -0600 | [diff] [blame] | 188 | } |
Jon Ashburn | 29669a4 | 2015-04-04 14:52:07 -0600 | [diff] [blame] | 189 | } |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * This ICD does not support any layers. |
| 193 | */ |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 194 | if (info->enabledLayerNameCount > 0) { |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 195 | icd_instance_destroy(icd); |
| 196 | intel_instance_destroy(instance); |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 197 | return VK_ERROR_LAYER_NOT_PRESENT; |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | *pInstance = instance; |
| 201 | |
| 202 | return VK_SUCCESS; |
Jon Ashburn | fa836e0 | 2015-01-28 18:26:16 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Courtney Goeltzenleuchter | 95b7372 | 2015-06-08 18:08:35 -0600 | [diff] [blame] | 205 | enum intel_global_ext_type intel_gpu_lookup_global_extension( |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 206 | const char *extensionName) |
Courtney Goeltzenleuchter | 95b7372 | 2015-06-08 18:08:35 -0600 | [diff] [blame] | 207 | { |
| 208 | enum intel_global_ext_type type; |
| 209 | |
| 210 | for (type = 0; type < ARRAY_SIZE(intel_global_exts); type++) { |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 211 | if (compare_vk_extension_properties(&intel_global_exts[type], extensionName)) |
Courtney Goeltzenleuchter | 95b7372 | 2015-06-08 18:08:35 -0600 | [diff] [blame] | 212 | break; |
| 213 | } |
| 214 | |
| 215 | assert(type < INTEL_GLOBAL_EXT_COUNT || type == INTEL_GLOBAL_EXT_INVALID); |
| 216 | |
| 217 | return type; |
| 218 | } |
| 219 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 220 | ICD_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 221 | const VkInstanceCreateInfo* pCreateInfo, |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 222 | const VkAllocationCallbacks* pAllocator, |
Courtney Goeltzenleuchter | b44d6f2 | 2015-07-05 22:09:41 -0600 | [diff] [blame] | 223 | VkInstance* pInstance) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 224 | { |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 225 | return intel_instance_create(pCreateInfo, pAllocator, |
| 226 | (struct intel_instance **) pInstance); |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 229 | ICD_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance( |
Chia-I Wu | 69f4012 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 230 | VkInstance pInstance, |
Chia-I Wu | 1f85191 | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 231 | const VkAllocationCallbacks* pAllocator) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 232 | { |
Chia-I Wu | 94ae71a | 2015-02-20 12:26:08 -0700 | [diff] [blame] | 233 | struct intel_instance *instance = intel_instance(pInstance); |
| 234 | |
| 235 | intel_instance_destroy(instance); |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 238 | ICD_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 239 | const char* pLayerName, |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 240 | uint32_t* pPropertyCount, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 241 | VkExtensionProperties* pProperties) |
Courtney Goeltzenleuchter | f0441e6 | 2015-06-09 08:20:20 -0600 | [diff] [blame] | 242 | { |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 243 | uint32_t copy_size; |
| 244 | |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 245 | if (pProperties == NULL) { |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 246 | *pPropertyCount = INTEL_GLOBAL_EXT_COUNT; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 247 | return VK_SUCCESS; |
| 248 | } |
| 249 | |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 250 | copy_size = *pPropertyCount < INTEL_GLOBAL_EXT_COUNT ? *pPropertyCount : INTEL_GLOBAL_EXT_COUNT; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 251 | memcpy(pProperties, intel_global_exts, copy_size * sizeof(VkExtensionProperties)); |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 252 | *pPropertyCount = copy_size; |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 253 | if (copy_size < INTEL_GLOBAL_EXT_COUNT) { |
| 254 | return VK_INCOMPLETE; |
| 255 | } |
| 256 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 257 | return VK_SUCCESS; |
| 258 | } |
Courtney Goeltzenleuchter | f0441e6 | 2015-06-09 08:20:20 -0600 | [diff] [blame] | 259 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 260 | ICD_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 261 | uint32_t* pPropertyCount, |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 262 | VkLayerProperties* pProperties) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 263 | { |
Chia-I Wu | 763a749 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 264 | *pPropertyCount = 0; |
Courtney Goeltzenleuchter | f0441e6 | 2015-06-09 08:20:20 -0600 | [diff] [blame] | 265 | return VK_SUCCESS; |
| 266 | } |
| 267 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 268 | ICD_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices( |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 269 | VkInstance instance_, |
| 270 | uint32_t* pPhysicalDeviceCount, |
| 271 | VkPhysicalDevice* pPhysicalDevices) |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 272 | { |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 273 | struct intel_instance *instance = intel_instance(instance_); |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 274 | struct icd_drm_device *devices, *dev; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 275 | VkResult ret; |
Jon Ashburn | 92e8013 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 276 | uint32_t count; |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 277 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 278 | if (pPhysicalDevices == NULL) { |
| 279 | *pPhysicalDeviceCount = 1; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 280 | return VK_SUCCESS; |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 283 | intel_instance_remove_gpus(instance); |
| 284 | |
Chia-I Wu | 15517d8 | 2015-02-20 13:41:57 -0700 | [diff] [blame] | 285 | devices = icd_drm_enumerate(instance->icd, 0x8086); |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 286 | |
| 287 | count = 0; |
| 288 | dev = devices; |
| 289 | while (dev) { |
| 290 | const char *primary_node, *render_node; |
| 291 | int devid; |
| 292 | struct intel_gpu *gpu; |
| 293 | |
| 294 | primary_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_LEGACY); |
| 295 | if (!primary_node) |
| 296 | continue; |
| 297 | |
| 298 | render_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER); |
| 299 | |
| 300 | devid = (intel_devid_override) ? intel_devid_override : dev->devid; |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 301 | ret = intel_gpu_create(instance, devid, |
| 302 | primary_node, render_node, &gpu); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 303 | if (ret == VK_SUCCESS) { |
Chia-I Wu | d71ff55 | 2015-02-20 12:50:12 -0700 | [diff] [blame] | 304 | intel_instance_add_gpu(instance, gpu); |
| 305 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 306 | pPhysicalDevices[count++] = (VkPhysicalDevice) gpu; |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 307 | if (count >= *pPhysicalDeviceCount) |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 308 | break; |
| 309 | } |
| 310 | |
| 311 | dev = dev->next; |
| 312 | } |
| 313 | |
Chia-I Wu | 15517d8 | 2015-02-20 13:41:57 -0700 | [diff] [blame] | 314 | icd_drm_release(instance->icd, devices); |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 315 | |
Jon Ashburn | 07b309a | 2015-04-15 11:31:12 -0600 | [diff] [blame] | 316 | *pPhysicalDeviceCount = count; |
Jon Ashburn | 5f078e9 | 2015-01-28 19:15:45 -0700 | [diff] [blame] | 317 | |
Courtney Goeltzenleuchter | ac544f3 | 2015-09-14 18:01:17 -0600 | [diff] [blame] | 318 | return VK_SUCCESS; |
Jon Ashburn | 349508d | 2015-01-26 14:51:40 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 321 | ICD_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDbgCreateMsgCallback( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 322 | VkInstance instance, |
| 323 | VkFlags msgFlags, |
| 324 | PFN_vkDbgMsgCallback pfnMsgCallback, |
| 325 | void* pUserData, |
| 326 | VkDbgMsgCallback* pMsgCallback) |
Chia-I Wu | b02558c | 2015-01-03 15:21:51 +0800 | [diff] [blame] | 327 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 328 | struct intel_instance *inst = intel_instance(instance); |
Courtney Goeltzenleuchter | 0629efa | 2015-04-13 14:59:19 -0600 | [diff] [blame] | 329 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 330 | return icd_instance_create_logger(inst->icd, msgFlags, pfnMsgCallback, pUserData, pMsgCallback); |
Chia-I Wu | b02558c | 2015-01-03 15:21:51 +0800 | [diff] [blame] | 331 | } |
| 332 | |
Chia-I Wu | af9e4fd | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 333 | ICD_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDbgDestroyMsgCallback( |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 334 | VkInstance instance, |
| 335 | VkDbgMsgCallback msgCallback) |
Chia-I Wu | b02558c | 2015-01-03 15:21:51 +0800 | [diff] [blame] | 336 | { |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 337 | struct intel_instance *inst = intel_instance(instance); |
Courtney Goeltzenleuchter | 0629efa | 2015-04-13 14:59:19 -0600 | [diff] [blame] | 338 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 339 | return icd_instance_destroy_logger(inst->icd, msgCallback); |
Chia-I Wu | b02558c | 2015-01-03 15:21:51 +0800 | [diff] [blame] | 340 | } |