| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 1 | /////////////////////////////////////////////////////////////////////////////// | 
 | 2 | // | 
 | 3 | // Copyright (c) 2015-2016 The Khronos Group Inc. | 
 | 4 | // Copyright (c) 2015-2016 Valve Corporation | 
 | 5 | // Copyright (c) 2015-2016 LunarG, Inc. | 
 | 6 | // Copyright (c) 2015-2016 Google, Inc. | 
 | 7 | // | 
 | 8 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 9 | // you may not use this file except in compliance with the License. | 
 | 10 | // You may obtain a copy of the License at | 
 | 11 | // | 
 | 12 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
 | 13 | // | 
 | 14 | // Unless required by applicable law or agreed to in writing, software | 
 | 15 | // distributed under the License is distributed on an "AS IS" BASIS, | 
 | 16 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 17 | // See the License for the specific language governing permissions and | 
 | 18 | // limitations under the License. | 
 | 19 | /////////////////////////////////////////////////////////////////////////////// | 
 | 20 |  | 
 | 21 | #ifndef VK_PROTOTYPES | 
 | 22 | #define VK_PROTOTYPES | 
 | 23 | #endif | 
 | 24 |  | 
 | 25 | #include "vkjson.h" | 
 | 26 |  | 
 | 27 | #include <algorithm> | 
 | 28 | #include <utility> | 
 | 29 |  | 
 | 30 | namespace { | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 31 |  | 
 | 32 | bool EnumerateExtensions(const char* layer_name, | 
 | 33 |                          std::vector<VkExtensionProperties>* extensions) { | 
 | 34 |   VkResult result; | 
 | 35 |   uint32_t count = 0; | 
 | 36 |   result = vkEnumerateInstanceExtensionProperties(layer_name, &count, nullptr); | 
 | 37 |   if (result != VK_SUCCESS) | 
 | 38 |     return false; | 
 | 39 |   extensions->resize(count); | 
 | 40 |   result = vkEnumerateInstanceExtensionProperties(layer_name, &count, | 
 | 41 |                                                   extensions->data()); | 
 | 42 |   if (result != VK_SUCCESS) | 
 | 43 |     return false; | 
 | 44 |   return true; | 
 | 45 | } | 
 | 46 |  | 
 | 47 | bool HasExtension(const char* extension_name, | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 48 |                   const std::vector<VkExtensionProperties>& extensions) { | 
 | 49 |   return std::find_if(extensions.cbegin(), extensions.cend(), | 
 | 50 |                       [extension_name](const VkExtensionProperties& extension) { | 
 | 51 |                         return strcmp(extension.extensionName, | 
 | 52 |                                       extension_name) == 0; | 
 | 53 |                       }) != extensions.cend(); | 
 | 54 | } | 
 | 55 | }  // anonymous namespace | 
 | 56 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 57 | VkJsonDevice VkJsonGetDevice(VkPhysicalDevice physical_device) { | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 58 |   VkJsonDevice device; | 
 | 59 |  | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 60 |   uint32_t extension_count = 0; | 
 | 61 |   vkEnumerateDeviceExtensionProperties(physical_device, nullptr, | 
 | 62 |                                        &extension_count, nullptr); | 
 | 63 |   if (extension_count > 0) { | 
 | 64 |     device.extensions.resize(extension_count); | 
 | 65 |     vkEnumerateDeviceExtensionProperties( | 
 | 66 |         physical_device, nullptr, &extension_count, device.extensions.data()); | 
 | 67 |   } | 
 | 68 |  | 
 | 69 |   uint32_t layer_count = 0; | 
 | 70 |   vkEnumerateDeviceLayerProperties(physical_device, &layer_count, nullptr); | 
 | 71 |   if (layer_count > 0) { | 
 | 72 |     device.layers.resize(layer_count); | 
 | 73 |     vkEnumerateDeviceLayerProperties(physical_device, &layer_count, | 
 | 74 |                                      device.layers.data()); | 
 | 75 |   } | 
 | 76 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 77 |   VkPhysicalDeviceProperties2 properties = { | 
 | 78 |       VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, | 
 | 79 |       nullptr, | 
 | 80 |       {}, | 
 | 81 |   }; | 
 | 82 |   if (HasExtension("VK_KHR_driver_properties", device.extensions)) { | 
 | 83 |     device.ext_driver_properties.reported = true; | 
 | 84 |     device.ext_driver_properties.driver_properties_khr.sType = | 
 | 85 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR; | 
 | 86 |     device.ext_driver_properties.driver_properties_khr.pNext = properties.pNext; | 
 | 87 |     properties.pNext = &device.ext_driver_properties.driver_properties_khr; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 88 |   } | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 89 |   vkGetPhysicalDeviceProperties2(physical_device, &properties); | 
 | 90 |   device.properties = properties.properties; | 
 | 91 |  | 
 | 92 |   VkPhysicalDeviceFeatures2 features = { | 
 | 93 |       VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, | 
 | 94 |       nullptr, | 
 | 95 |       {}, | 
 | 96 |   }; | 
 | 97 |   if (HasExtension("VK_KHR_variable_pointers", device.extensions)) { | 
 | 98 |     device.ext_variable_pointer_features.reported = true; | 
 | 99 |     device.ext_variable_pointer_features.variable_pointer_features_khr.sType = | 
 | 100 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR; | 
 | 101 |     device.ext_variable_pointer_features.variable_pointer_features_khr.pNext = | 
 | 102 |         features.pNext; | 
 | 103 |     features.pNext = | 
 | 104 |         &device.ext_variable_pointer_features.variable_pointer_features_khr; | 
 | 105 |   } | 
 | 106 |   if (HasExtension("VK_KHR_shader_float16_int8", device.extensions)) { | 
 | 107 |     device.ext_shader_float16_int8_features.reported = true; | 
 | 108 |     device.ext_shader_float16_int8_features.shader_float16_int8_features_khr | 
 | 109 |         .sType = | 
 | 110 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR; | 
 | 111 |     device.ext_shader_float16_int8_features.shader_float16_int8_features_khr | 
 | 112 |         .pNext = features.pNext; | 
 | 113 |     features.pNext = &device.ext_shader_float16_int8_features | 
 | 114 |                           .shader_float16_int8_features_khr; | 
 | 115 |   } | 
 | 116 |   vkGetPhysicalDeviceFeatures2(physical_device, &features); | 
 | 117 |   device.features = features.features; | 
 | 118 |  | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 119 |   vkGetPhysicalDeviceMemoryProperties(physical_device, &device.memory); | 
 | 120 |  | 
 | 121 |   uint32_t queue_family_count = 0; | 
 | 122 |   vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count, | 
 | 123 |                                            nullptr); | 
 | 124 |   if (queue_family_count > 0) { | 
 | 125 |     device.queues.resize(queue_family_count); | 
 | 126 |     vkGetPhysicalDeviceQueueFamilyProperties( | 
 | 127 |         physical_device, &queue_family_count, device.queues.data()); | 
 | 128 |   } | 
 | 129 |  | 
 | 130 |   VkFormatProperties format_properties = {}; | 
 | 131 |   for (VkFormat format = VK_FORMAT_R4G4_UNORM_PACK8; | 
 | 132 |        format <= VK_FORMAT_END_RANGE; | 
 | 133 |        format = static_cast<VkFormat>(format + 1)) { | 
 | 134 |     vkGetPhysicalDeviceFormatProperties(physical_device, format, | 
 | 135 |                                         &format_properties); | 
 | 136 |     if (format_properties.linearTilingFeatures || | 
 | 137 |         format_properties.optimalTilingFeatures || | 
 | 138 |         format_properties.bufferFeatures) { | 
 | 139 |       device.formats.insert(std::make_pair(format, format_properties)); | 
 | 140 |     } | 
 | 141 |   } | 
 | 142 |  | 
 | 143 |   if (device.properties.apiVersion >= VK_API_VERSION_1_1) { | 
 | 144 |     for (VkFormat format = VK_FORMAT_G8B8G8R8_422_UNORM; | 
 | 145 |          format <= VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM; | 
 | 146 |          format = static_cast<VkFormat>(format + 1)) { | 
 | 147 |       vkGetPhysicalDeviceFormatProperties(physical_device, format, | 
 | 148 |                                           &format_properties); | 
 | 149 |       if (format_properties.linearTilingFeatures || | 
 | 150 |           format_properties.optimalTilingFeatures || | 
 | 151 |           format_properties.bufferFeatures) { | 
 | 152 |         device.formats.insert(std::make_pair(format, format_properties)); | 
 | 153 |       } | 
 | 154 |     } | 
 | 155 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 156 |     VkPhysicalDeviceProperties2 properties2 = { | 
 | 157 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, | 
 | 158 |         nullptr, | 
 | 159 |         {}, | 
 | 160 |     }; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 161 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 162 |     device.subgroup_properties.sType = | 
 | 163 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES; | 
 | 164 |     device.subgroup_properties.pNext = properties2.pNext; | 
 | 165 |     properties2.pNext = &device.subgroup_properties; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 166 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 167 |     device.point_clipping_properties.sType = | 
 | 168 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES; | 
 | 169 |     device.point_clipping_properties.pNext = properties2.pNext; | 
 | 170 |     properties2.pNext = &device.point_clipping_properties; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 171 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 172 |     device.multiview_properties.sType = | 
 | 173 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES; | 
 | 174 |     device.multiview_properties.pNext = properties2.pNext; | 
 | 175 |     properties2.pNext = &device.multiview_properties; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 176 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 177 |     device.id_properties.sType = | 
 | 178 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES; | 
 | 179 |     device.id_properties.pNext = properties2.pNext; | 
 | 180 |     properties2.pNext = &device.id_properties; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 181 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 182 |     device.maintenance3_properties.sType = | 
 | 183 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES; | 
 | 184 |     device.maintenance3_properties.pNext = properties2.pNext; | 
 | 185 |     properties2.pNext = &device.maintenance3_properties; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 186 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 187 |     vkGetPhysicalDeviceProperties2(physical_device, &properties2); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 188 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 189 |     VkPhysicalDeviceFeatures2 features2 = { | 
 | 190 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, | 
 | 191 |         nullptr, | 
 | 192 |         {}, | 
 | 193 |     }; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 194 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 195 |     device.bit16_storage_features.sType = | 
 | 196 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES; | 
 | 197 |     device.bit16_storage_features.pNext = features2.pNext; | 
 | 198 |     features2.pNext = &device.bit16_storage_features; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 199 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 200 |     device.multiview_features.sType = | 
 | 201 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES; | 
 | 202 |     device.multiview_features.pNext = features2.pNext; | 
 | 203 |     features2.pNext = &device.multiview_features; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 204 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 205 |     device.variable_pointer_features.sType = | 
 | 206 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES; | 
 | 207 |     device.variable_pointer_features.pNext = features2.pNext; | 
 | 208 |     features2.pNext = &device.variable_pointer_features; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 209 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 210 |     device.protected_memory_features.sType = | 
 | 211 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES; | 
 | 212 |     device.protected_memory_features.pNext = features2.pNext; | 
 | 213 |     features2.pNext = &device.protected_memory_features; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 214 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 215 |     device.sampler_ycbcr_conversion_features.sType = | 
 | 216 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES; | 
 | 217 |     device.sampler_ycbcr_conversion_features.pNext = features2.pNext; | 
 | 218 |     features2.pNext = &device.sampler_ycbcr_conversion_features; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 219 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 220 |     device.shader_draw_parameter_features.sType = | 
 | 221 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES; | 
 | 222 |     device.shader_draw_parameter_features.pNext = features2.pNext; | 
 | 223 |     features2.pNext = &device.shader_draw_parameter_features; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 224 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 225 |     vkGetPhysicalDeviceFeatures2(physical_device, &features2); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 226 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 227 |     VkPhysicalDeviceExternalFenceInfo external_fence_info = { | 
 | 228 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, nullptr, | 
 | 229 |         VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT}; | 
 | 230 |     VkExternalFenceProperties external_fence_properties = {}; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 231 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 232 |     for (VkExternalFenceHandleTypeFlagBits handle_type = | 
 | 233 |              VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT; | 
 | 234 |          handle_type <= VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT; | 
 | 235 |          handle_type = | 
 | 236 |              static_cast<VkExternalFenceHandleTypeFlagBits>(handle_type << 1)) { | 
 | 237 |       external_fence_info.handleType = handle_type; | 
 | 238 |       vkGetPhysicalDeviceExternalFenceProperties( | 
 | 239 |           physical_device, &external_fence_info, &external_fence_properties); | 
 | 240 |       if (external_fence_properties.exportFromImportedHandleTypes || | 
 | 241 |           external_fence_properties.compatibleHandleTypes || | 
 | 242 |           external_fence_properties.externalFenceFeatures) { | 
 | 243 |         device.external_fence_properties.insert( | 
 | 244 |             std::make_pair(handle_type, external_fence_properties)); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 245 |       } | 
 | 246 |     } | 
 | 247 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 248 |     VkPhysicalDeviceExternalSemaphoreInfo external_semaphore_info = { | 
 | 249 |         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, nullptr, | 
 | 250 |         VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT}; | 
 | 251 |     VkExternalSemaphoreProperties external_semaphore_properties = {}; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 252 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 253 |     for (VkExternalSemaphoreHandleTypeFlagBits handle_type = | 
 | 254 |              VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; | 
 | 255 |          handle_type <= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; | 
 | 256 |          handle_type = static_cast<VkExternalSemaphoreHandleTypeFlagBits>( | 
 | 257 |              handle_type << 1)) { | 
 | 258 |       external_semaphore_info.handleType = handle_type; | 
 | 259 |       vkGetPhysicalDeviceExternalSemaphoreProperties( | 
 | 260 |           physical_device, &external_semaphore_info, | 
 | 261 |           &external_semaphore_properties); | 
 | 262 |       if (external_semaphore_properties.exportFromImportedHandleTypes || | 
 | 263 |           external_semaphore_properties.compatibleHandleTypes || | 
 | 264 |           external_semaphore_properties.externalSemaphoreFeatures) { | 
 | 265 |         device.external_semaphore_properties.insert( | 
 | 266 |             std::make_pair(handle_type, external_semaphore_properties)); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 267 |       } | 
 | 268 |     } | 
 | 269 |   } | 
 | 270 |  | 
 | 271 |   return device; | 
 | 272 | } | 
 | 273 |  | 
 | 274 | VkJsonInstance VkJsonGetInstance() { | 
 | 275 |   VkJsonInstance instance; | 
 | 276 |   VkResult result; | 
 | 277 |   uint32_t count; | 
 | 278 |  | 
 | 279 |   count = 0; | 
 | 280 |   result = vkEnumerateInstanceLayerProperties(&count, nullptr); | 
 | 281 |   if (result != VK_SUCCESS) | 
 | 282 |     return VkJsonInstance(); | 
 | 283 |   if (count > 0) { | 
 | 284 |     std::vector<VkLayerProperties> layers(count); | 
 | 285 |     result = vkEnumerateInstanceLayerProperties(&count, layers.data()); | 
 | 286 |     if (result != VK_SUCCESS) | 
 | 287 |       return VkJsonInstance(); | 
 | 288 |     instance.layers.reserve(count); | 
 | 289 |     for (auto& layer : layers) { | 
 | 290 |       instance.layers.push_back(VkJsonLayer{layer, std::vector<VkExtensionProperties>()}); | 
 | 291 |       if (!EnumerateExtensions(layer.layerName, | 
 | 292 |                                &instance.layers.back().extensions)) | 
 | 293 |         return VkJsonInstance(); | 
 | 294 |     } | 
 | 295 |   } | 
 | 296 |  | 
 | 297 |   if (!EnumerateExtensions(nullptr, &instance.extensions)) | 
 | 298 |     return VkJsonInstance(); | 
 | 299 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 300 |   const VkApplicationInfo app_info = { | 
 | 301 |       VK_STRUCTURE_TYPE_APPLICATION_INFO, | 
 | 302 |       nullptr, | 
 | 303 |       "vkjson_info", | 
 | 304 |       1, | 
 | 305 |       "", | 
 | 306 |       0, | 
 | 307 |       VK_API_VERSION_1_1, | 
 | 308 |   }; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 309 |   VkInstanceCreateInfo instance_info = { | 
 | 310 |       VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, | 
 | 311 |       nullptr, | 
 | 312 |       0, | 
 | 313 |       &app_info, | 
 | 314 |       0, | 
 | 315 |       nullptr, | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 316 |       0, | 
 | 317 |       nullptr, | 
 | 318 |   }; | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 319 |   VkInstance vkinstance; | 
 | 320 |   result = vkCreateInstance(&instance_info, nullptr, &vkinstance); | 
 | 321 |   if (result != VK_SUCCESS) | 
 | 322 |     return VkJsonInstance(); | 
 | 323 |  | 
 | 324 |   count = 0; | 
 | 325 |   result = vkEnumeratePhysicalDevices(vkinstance, &count, nullptr); | 
 | 326 |   if (result != VK_SUCCESS) { | 
 | 327 |     vkDestroyInstance(vkinstance, nullptr); | 
 | 328 |     return VkJsonInstance(); | 
 | 329 |   } | 
 | 330 |  | 
 | 331 |   std::vector<VkPhysicalDevice> devices(count, VK_NULL_HANDLE); | 
 | 332 |   result = vkEnumeratePhysicalDevices(vkinstance, &count, devices.data()); | 
 | 333 |   if (result != VK_SUCCESS) { | 
 | 334 |     vkDestroyInstance(vkinstance, nullptr); | 
 | 335 |     return VkJsonInstance(); | 
 | 336 |   } | 
 | 337 |  | 
 | 338 |   std::map<VkPhysicalDevice, uint32_t> device_map; | 
 | 339 |   const uint32_t sz = devices.size(); | 
 | 340 |   instance.devices.reserve(sz); | 
 | 341 |   for (uint32_t i = 0; i < sz; ++i) { | 
 | 342 |     device_map.insert(std::make_pair(devices[i], i)); | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 343 |     instance.devices.emplace_back(VkJsonGetDevice(devices[i])); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 344 |   } | 
 | 345 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 346 |   result = vkEnumerateInstanceVersion(&instance.api_version); | 
 | 347 |   if (result != VK_SUCCESS) { | 
 | 348 |     vkDestroyInstance(vkinstance, nullptr); | 
 | 349 |     return VkJsonInstance(); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 350 |   } | 
 | 351 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 352 |   count = 0; | 
 | 353 |   result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, nullptr); | 
 | 354 |   if (result != VK_SUCCESS) { | 
 | 355 |     vkDestroyInstance(vkinstance, nullptr); | 
 | 356 |     return VkJsonInstance(); | 
 | 357 |   } | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 358 |  | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 359 |   VkJsonDeviceGroup device_group; | 
 | 360 |   std::vector<VkPhysicalDeviceGroupProperties> group_properties; | 
 | 361 |   group_properties.resize(count); | 
 | 362 |   result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, | 
 | 363 |                                            group_properties.data()); | 
 | 364 |   if (result != VK_SUCCESS) { | 
 | 365 |     vkDestroyInstance(vkinstance, nullptr); | 
 | 366 |     return VkJsonInstance(); | 
 | 367 |   } | 
 | 368 |   for (auto properties : group_properties) { | 
 | 369 |     device_group.properties = properties; | 
 | 370 |     for (uint32_t i = 0; i < properties.physicalDeviceCount; ++i) { | 
 | 371 |       device_group.device_inds.push_back( | 
 | 372 |           device_map[properties.physicalDevices[i]]); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 373 |     } | 
| Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 374 |     instance.device_groups.push_back(device_group); | 
| Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 375 |   } | 
 | 376 |  | 
 | 377 |   vkDestroyInstance(vkinstance, nullptr); | 
 | 378 |   return instance; | 
 | 379 | } |