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; |
Yiwei Zhang | 17bf1c0 | 2020-10-19 20:14:01 -0700 | [diff] [blame] | 132 | // TODO(http://b/171403054): avoid hard-coding last value in the |
| 133 | // contiguous range |
| 134 | format <= VK_FORMAT_ASTC_12x12_SRGB_BLOCK; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 135 | format = static_cast<VkFormat>(format + 1)) { |
| 136 | vkGetPhysicalDeviceFormatProperties(physical_device, format, |
| 137 | &format_properties); |
| 138 | if (format_properties.linearTilingFeatures || |
| 139 | format_properties.optimalTilingFeatures || |
| 140 | format_properties.bufferFeatures) { |
| 141 | device.formats.insert(std::make_pair(format, format_properties)); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (device.properties.apiVersion >= VK_API_VERSION_1_1) { |
| 146 | for (VkFormat format = VK_FORMAT_G8B8G8R8_422_UNORM; |
Yiwei Zhang | 17bf1c0 | 2020-10-19 20:14:01 -0700 | [diff] [blame] | 147 | // TODO(http://b/171403054): avoid hard-coding last value in the |
| 148 | // contiguous range |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 149 | format <= VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM; |
| 150 | format = static_cast<VkFormat>(format + 1)) { |
| 151 | vkGetPhysicalDeviceFormatProperties(physical_device, format, |
| 152 | &format_properties); |
| 153 | if (format_properties.linearTilingFeatures || |
| 154 | format_properties.optimalTilingFeatures || |
| 155 | format_properties.bufferFeatures) { |
| 156 | device.formats.insert(std::make_pair(format, format_properties)); |
| 157 | } |
| 158 | } |
| 159 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 160 | device.subgroup_properties.sType = |
| 161 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 162 | device.subgroup_properties.pNext = properties.pNext; |
| 163 | properties.pNext = &device.subgroup_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 164 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 165 | device.point_clipping_properties.sType = |
| 166 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 167 | device.point_clipping_properties.pNext = properties.pNext; |
| 168 | properties.pNext = &device.point_clipping_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 169 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 170 | device.multiview_properties.sType = |
| 171 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 172 | device.multiview_properties.pNext = properties.pNext; |
| 173 | properties.pNext = &device.multiview_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 174 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 175 | device.id_properties.sType = |
| 176 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 177 | device.id_properties.pNext = properties.pNext; |
| 178 | properties.pNext = &device.id_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 179 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 180 | device.maintenance3_properties.sType = |
| 181 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 182 | device.maintenance3_properties.pNext = properties.pNext; |
| 183 | properties.pNext = &device.maintenance3_properties; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 184 | |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 185 | vkGetPhysicalDeviceProperties2(physical_device, &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 | device.bit16_storage_features.sType = |
| 188 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 189 | device.bit16_storage_features.pNext = features.pNext; |
| 190 | features.pNext = &device.bit16_storage_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 191 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 192 | device.multiview_features.sType = |
| 193 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 194 | device.multiview_features.pNext = features.pNext; |
| 195 | features.pNext = &device.multiview_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 196 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 197 | device.variable_pointer_features.sType = |
| 198 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 199 | device.variable_pointer_features.pNext = features.pNext; |
| 200 | features.pNext = &device.variable_pointer_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 201 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 202 | device.protected_memory_features.sType = |
| 203 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 204 | device.protected_memory_features.pNext = features.pNext; |
| 205 | features.pNext = &device.protected_memory_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 206 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 207 | device.sampler_ycbcr_conversion_features.sType = |
| 208 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 209 | device.sampler_ycbcr_conversion_features.pNext = features.pNext; |
| 210 | features.pNext = &device.sampler_ycbcr_conversion_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 211 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 212 | device.shader_draw_parameter_features.sType = |
| 213 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES; |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 214 | device.shader_draw_parameter_features.pNext = features.pNext; |
| 215 | features.pNext = &device.shader_draw_parameter_features; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 216 | |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 217 | vkGetPhysicalDeviceFeatures2(physical_device, &features); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 218 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 219 | VkPhysicalDeviceExternalFenceInfo external_fence_info = { |
| 220 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, nullptr, |
| 221 | VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT}; |
| 222 | VkExternalFenceProperties external_fence_properties = {}; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 223 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 224 | for (VkExternalFenceHandleTypeFlagBits handle_type = |
| 225 | VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT; |
| 226 | handle_type <= VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT; |
| 227 | handle_type = |
| 228 | static_cast<VkExternalFenceHandleTypeFlagBits>(handle_type << 1)) { |
| 229 | external_fence_info.handleType = handle_type; |
| 230 | vkGetPhysicalDeviceExternalFenceProperties( |
| 231 | physical_device, &external_fence_info, &external_fence_properties); |
| 232 | if (external_fence_properties.exportFromImportedHandleTypes || |
| 233 | external_fence_properties.compatibleHandleTypes || |
| 234 | external_fence_properties.externalFenceFeatures) { |
| 235 | device.external_fence_properties.insert( |
| 236 | std::make_pair(handle_type, external_fence_properties)); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 240 | VkPhysicalDeviceExternalSemaphoreInfo external_semaphore_info = { |
| 241 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, nullptr, |
| 242 | VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT}; |
| 243 | VkExternalSemaphoreProperties external_semaphore_properties = {}; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 244 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 245 | for (VkExternalSemaphoreHandleTypeFlagBits handle_type = |
| 246 | VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; |
| 247 | handle_type <= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
| 248 | handle_type = static_cast<VkExternalSemaphoreHandleTypeFlagBits>( |
| 249 | handle_type << 1)) { |
| 250 | external_semaphore_info.handleType = handle_type; |
| 251 | vkGetPhysicalDeviceExternalSemaphoreProperties( |
| 252 | physical_device, &external_semaphore_info, |
| 253 | &external_semaphore_properties); |
| 254 | if (external_semaphore_properties.exportFromImportedHandleTypes || |
| 255 | external_semaphore_properties.compatibleHandleTypes || |
| 256 | external_semaphore_properties.externalSemaphoreFeatures) { |
| 257 | device.external_semaphore_properties.insert( |
| 258 | std::make_pair(handle_type, external_semaphore_properties)); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
Trevor David Black | d35f0f6 | 2021-09-07 23:39:36 +0000 | [diff] [blame] | 263 | if (device.properties.apiVersion >= VK_API_VERSION_1_2) { |
| 264 | device.core12.properties.sType = |
| 265 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES; |
| 266 | device.core12.properties.pNext = properties.pNext; |
| 267 | properties.pNext = &device.core12.properties; |
| 268 | |
| 269 | vkGetPhysicalDeviceProperties2(physical_device, &properties); |
| 270 | |
| 271 | device.core12.features.sType = |
| 272 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; |
| 273 | device.core12.features.pNext = features.pNext; |
| 274 | features.pNext = &device.core12.features; |
| 275 | |
| 276 | vkGetPhysicalDeviceFeatures2(physical_device, &features); |
| 277 | } |
| 278 | |
Trevor David Black | 7988379 | 2021-11-04 23:46:31 +0000 | [diff] [blame] | 279 | if (device.properties.apiVersion >= VK_API_VERSION_1_3) { |
| 280 | device.core13.properties.sType = |
| 281 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_PROPERTIES; |
| 282 | device.core13.properties.pNext = properties.pNext; |
| 283 | properties.pNext = &device.core13.properties; |
| 284 | |
| 285 | vkGetPhysicalDeviceProperties2(physical_device, &properties); |
| 286 | |
| 287 | device.core13.features.sType = |
| 288 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES; |
| 289 | device.core13.features.pNext = features.pNext; |
| 290 | features.pNext = &device.core13.features; |
| 291 | |
| 292 | vkGetPhysicalDeviceFeatures2(physical_device, &features); |
| 293 | } |
| 294 | |
Tom Murphy | 80d9ca7 | 2024-10-17 09:52:47 +0000 | [diff] [blame] | 295 | if (device.properties.apiVersion >= VK_API_VERSION_1_4) { |
| 296 | device.core14.properties.sType = |
| 297 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_PROPERTIES; |
| 298 | device.core14.properties.pNext = properties.pNext; |
| 299 | properties.pNext = &device.core14.properties; |
| 300 | |
| 301 | vkGetPhysicalDeviceProperties2(physical_device, &properties); |
| 302 | |
| 303 | device.core14.features.sType = |
| 304 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES; |
| 305 | device.core14.features.pNext = features.pNext; |
| 306 | features.pNext = &device.core14.features; |
| 307 | |
| 308 | vkGetPhysicalDeviceFeatures2(physical_device, &features); |
| 309 | } |
| 310 | |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 311 | return device; |
| 312 | } |
| 313 | |
| 314 | VkJsonInstance VkJsonGetInstance() { |
| 315 | VkJsonInstance instance; |
| 316 | VkResult result; |
| 317 | uint32_t count; |
| 318 | |
| 319 | count = 0; |
| 320 | result = vkEnumerateInstanceLayerProperties(&count, nullptr); |
| 321 | if (result != VK_SUCCESS) |
| 322 | return VkJsonInstance(); |
| 323 | if (count > 0) { |
| 324 | std::vector<VkLayerProperties> layers(count); |
| 325 | result = vkEnumerateInstanceLayerProperties(&count, layers.data()); |
| 326 | if (result != VK_SUCCESS) |
| 327 | return VkJsonInstance(); |
| 328 | instance.layers.reserve(count); |
| 329 | for (auto& layer : layers) { |
| 330 | instance.layers.push_back(VkJsonLayer{layer, std::vector<VkExtensionProperties>()}); |
| 331 | if (!EnumerateExtensions(layer.layerName, |
| 332 | &instance.layers.back().extensions)) |
| 333 | return VkJsonInstance(); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | if (!EnumerateExtensions(nullptr, &instance.extensions)) |
| 338 | return VkJsonInstance(); |
| 339 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 340 | const VkApplicationInfo app_info = { |
| 341 | VK_STRUCTURE_TYPE_APPLICATION_INFO, |
| 342 | nullptr, |
| 343 | "vkjson_info", |
| 344 | 1, |
| 345 | "", |
| 346 | 0, |
| 347 | VK_API_VERSION_1_1, |
| 348 | }; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 349 | VkInstanceCreateInfo instance_info = { |
| 350 | VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, |
| 351 | nullptr, |
| 352 | 0, |
| 353 | &app_info, |
| 354 | 0, |
| 355 | nullptr, |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 356 | 0, |
| 357 | nullptr, |
| 358 | }; |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 359 | VkInstance vkinstance; |
| 360 | result = vkCreateInstance(&instance_info, nullptr, &vkinstance); |
| 361 | if (result != VK_SUCCESS) |
| 362 | return VkJsonInstance(); |
| 363 | |
| 364 | count = 0; |
| 365 | result = vkEnumeratePhysicalDevices(vkinstance, &count, nullptr); |
| 366 | if (result != VK_SUCCESS) { |
| 367 | vkDestroyInstance(vkinstance, nullptr); |
| 368 | return VkJsonInstance(); |
| 369 | } |
| 370 | |
| 371 | std::vector<VkPhysicalDevice> devices(count, VK_NULL_HANDLE); |
| 372 | result = vkEnumeratePhysicalDevices(vkinstance, &count, devices.data()); |
| 373 | if (result != VK_SUCCESS) { |
| 374 | vkDestroyInstance(vkinstance, nullptr); |
| 375 | return VkJsonInstance(); |
| 376 | } |
| 377 | |
| 378 | std::map<VkPhysicalDevice, uint32_t> device_map; |
| 379 | const uint32_t sz = devices.size(); |
| 380 | instance.devices.reserve(sz); |
| 381 | for (uint32_t i = 0; i < sz; ++i) { |
| 382 | device_map.insert(std::make_pair(devices[i], i)); |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 383 | instance.devices.emplace_back(VkJsonGetDevice(devices[i])); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 386 | result = vkEnumerateInstanceVersion(&instance.api_version); |
| 387 | if (result != VK_SUCCESS) { |
| 388 | vkDestroyInstance(vkinstance, nullptr); |
| 389 | return VkJsonInstance(); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 392 | count = 0; |
| 393 | result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, nullptr); |
| 394 | if (result != VK_SUCCESS) { |
| 395 | vkDestroyInstance(vkinstance, nullptr); |
| 396 | return VkJsonInstance(); |
| 397 | } |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 398 | |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 399 | VkJsonDeviceGroup device_group; |
| 400 | std::vector<VkPhysicalDeviceGroupProperties> group_properties; |
| 401 | group_properties.resize(count); |
Yiwei Zhang | 92bf330 | 2021-04-03 19:33:39 +0000 | [diff] [blame] | 402 | for (auto& properties : group_properties) { |
| 403 | properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES; |
| 404 | properties.pNext = nullptr; |
| 405 | } |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 406 | result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, |
| 407 | group_properties.data()); |
| 408 | if (result != VK_SUCCESS) { |
| 409 | vkDestroyInstance(vkinstance, nullptr); |
| 410 | return VkJsonInstance(); |
| 411 | } |
| 412 | for (auto properties : group_properties) { |
| 413 | device_group.properties = properties; |
| 414 | for (uint32_t i = 0; i < properties.physicalDeviceCount; ++i) { |
| 415 | device_group.device_inds.push_back( |
| 416 | device_map[properties.physicalDevices[i]]); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 417 | } |
Yiwei Zhang | 91fc3dc | 2020-07-05 23:33:22 -0700 | [diff] [blame] | 418 | instance.device_groups.push_back(device_group); |
Yiwei Zhang | f9a57e6 | 2018-04-05 00:17:22 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | vkDestroyInstance(vkinstance, nullptr); |
| 422 | return instance; |
| 423 | } |