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 /*
31 * This file is autogenerated by vkjson_generator.py. Do not edit directly.
32 */
33 namespace {
34
EnumerateExtensions(const char * layer_name,std::vector<VkExtensionProperties> * extensions)35 bool EnumerateExtensions(const char* layer_name,
36 std::vector<VkExtensionProperties>* extensions) {
37 VkResult result;
38 uint32_t count = 0;
39 result = vkEnumerateInstanceExtensionProperties(layer_name, &count, nullptr);
40 if (result != VK_SUCCESS)
41 return false;
42 extensions->resize(count);
43 result = vkEnumerateInstanceExtensionProperties(layer_name, &count,
44 extensions->data());
45 if (result != VK_SUCCESS)
46 return false;
47 return true;
48 }
49
HasExtension(const char * extension_name,const std::vector<VkExtensionProperties> & extensions)50 bool HasExtension(const char* extension_name,
51 const std::vector<VkExtensionProperties>& extensions) {
52 return std::find_if(extensions.cbegin(), extensions.cend(),
53 [extension_name](const VkExtensionProperties& extension) {
54 return strcmp(extension.extensionName,
55 extension_name) == 0;
56 }) != extensions.cend();
57 }
58 } // anonymous namespace
59
VkJsonGetDevice(VkPhysicalDevice physical_device)60 VkJsonDevice VkJsonGetDevice(VkPhysicalDevice physical_device) {
61 VkJsonDevice device;
62
63 uint32_t extension_count = 0;
64 vkEnumerateDeviceExtensionProperties(physical_device, nullptr,
65 &extension_count, nullptr);
66 if (extension_count > 0) {
67 device.extensions.resize(extension_count);
68 vkEnumerateDeviceExtensionProperties(
69 physical_device, nullptr, &extension_count, device.extensions.data());
70 }
71
72 uint32_t layer_count = 0;
73 vkEnumerateDeviceLayerProperties(physical_device, &layer_count, nullptr);
74 if (layer_count > 0) {
75 device.layers.resize(layer_count);
76 vkEnumerateDeviceLayerProperties(physical_device, &layer_count,
77 device.layers.data());
78 }
79
80 VkPhysicalDeviceProperties2 properties = {
81 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
82 nullptr,
83 {},
84 };
85
86 if (HasExtension("VK_KHR_shader_float_controls", device.extensions)) {
87 device.khr_shader_float_controls.reported = true;
88 device.khr_shader_float_controls.float_controls_properties_khr.sType =
89 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES;
90 device.khr_shader_float_controls.float_controls_properties_khr.pNext =
91 properties.pNext;
92 properties.pNext =
93 &device.khr_shader_float_controls.float_controls_properties_khr;
94 }
95
96 if (HasExtension("VK_KHR_driver_properties", device.extensions)) {
97 device.khr_driver_properties.reported = true;
98 device.khr_driver_properties.driver_properties_khr.sType =
99 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
100 device.khr_driver_properties.driver_properties_khr.pNext = properties.pNext;
101 properties.pNext = &device.khr_driver_properties.driver_properties_khr;
102 }
103
104 vkGetPhysicalDeviceProperties2(physical_device, &properties);
105 device.properties = properties.properties;
106
107 VkPhysicalDeviceFeatures2 features = {
108 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
109 nullptr,
110 {},
111 };
112
113 if (HasExtension("VK_KHR_variable_pointers", device.extensions)) {
114 device.khr_variable_pointers.reported = true;
115 device.khr_variable_pointers.variable_pointer_features_khr.sType =
116 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES;
117 device.khr_variable_pointers.variable_pointer_features_khr.pNext =
118 features.pNext;
119 features.pNext =
120 &device.khr_variable_pointers.variable_pointer_features_khr;
121 device.khr_variable_pointers.variable_pointers_features_khr.sType =
122 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES;
123 device.khr_variable_pointers.variable_pointers_features_khr.pNext =
124 features.pNext;
125 features.pNext =
126 &device.khr_variable_pointers.variable_pointers_features_khr;
127 }
128
129 if (HasExtension("VK_KHR_shader_float16_int8", device.extensions)) {
130 device.khr_shader_float16_int8.reported = true;
131 device.khr_shader_float16_int8.shader_float16_int8_features_khr.sType =
132 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES;
133 device.khr_shader_float16_int8.shader_float16_int8_features_khr.pNext =
134 features.pNext;
135 features.pNext =
136 &device.khr_shader_float16_int8.shader_float16_int8_features_khr;
137 device.khr_shader_float16_int8.float16_int8_features_khr.sType =
138 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES;
139 device.khr_shader_float16_int8.float16_int8_features_khr.pNext =
140 features.pNext;
141 features.pNext = &device.khr_shader_float16_int8.float16_int8_features_khr;
142 }
143
144 if (HasExtension("VK_EXT_image_2d_view_of_3d", device.extensions)) {
145 device.ext_image_2d_view_of_3d.reported = true;
146 device.ext_image_2d_view_of_3d.image_2d_view_of_3d_features_ext.sType =
147 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_2D_VIEW_OF_3D_FEATURES_EXT;
148 device.ext_image_2d_view_of_3d.image_2d_view_of_3d_features_ext.pNext =
149 features.pNext;
150 features.pNext =
151 &device.ext_image_2d_view_of_3d.image_2d_view_of_3d_features_ext;
152 }
153
154 if (HasExtension("VK_EXT_custom_border_color", device.extensions)) {
155 device.ext_custom_border_color.reported = true;
156 device.ext_custom_border_color.custom_border_color_features_ext.sType =
157 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_PROPERTIES_EXT;
158 device.ext_custom_border_color.custom_border_color_features_ext.pNext =
159 features.pNext;
160 features.pNext =
161 &device.ext_custom_border_color.custom_border_color_features_ext;
162 }
163
164 if (HasExtension("VK_EXT_primitive_topology_list_restart",
165 device.extensions)) {
166 device.ext_primitive_topology_list_restart.reported = true;
167 device.ext_primitive_topology_list_restart
168 .primitive_topology_list_restart_features_ext.sType =
169 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT;
170 device.ext_primitive_topology_list_restart
171 .primitive_topology_list_restart_features_ext.pNext = features.pNext;
172 features.pNext = &device.ext_primitive_topology_list_restart
173 .primitive_topology_list_restart_features_ext;
174 }
175
176 if (HasExtension("VK_EXT_provoking_vertex", device.extensions)) {
177 device.ext_provoking_vertex.reported = true;
178 device.ext_provoking_vertex.provoking_vertex_features_ext.sType =
179 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT;
180 device.ext_provoking_vertex.provoking_vertex_features_ext.pNext =
181 features.pNext;
182 features.pNext = &device.ext_provoking_vertex.provoking_vertex_features_ext;
183 }
184
185 if (HasExtension("VK_KHR_index_type_uint8", device.extensions)) {
186 device.khr_index_type_uint8.reported = true;
187 device.khr_index_type_uint8.index_type_uint8_features_khr.sType =
188 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES;
189 device.khr_index_type_uint8.index_type_uint8_features_khr.pNext =
190 features.pNext;
191 features.pNext = &device.khr_index_type_uint8.index_type_uint8_features_khr;
192 }
193
194 if (HasExtension("VK_EXT_index_type_uint8", device.extensions)) {
195 device.ext_index_type_uint8.reported = true;
196 device.ext_index_type_uint8.index_type_uint8_features_ext.sType =
197 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES;
198 device.ext_index_type_uint8.index_type_uint8_features_ext.pNext =
199 features.pNext;
200 features.pNext = &device.ext_index_type_uint8.index_type_uint8_features_ext;
201 }
202
203 if (HasExtension("VK_KHR_vertex_attribute_divisor", device.extensions)) {
204 device.khr_vertex_attribute_divisor.reported = true;
205 device.khr_vertex_attribute_divisor.vertex_attribute_divisor_features_khr
206 .sType =
207 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES;
208 device.khr_vertex_attribute_divisor.vertex_attribute_divisor_features_khr
209 .pNext = features.pNext;
210 features.pNext = &device.khr_vertex_attribute_divisor
211 .vertex_attribute_divisor_features_khr;
212 }
213
214 if (HasExtension("VK_EXT_vertex_attribute_divisor", device.extensions)) {
215 device.ext_vertex_attribute_divisor.reported = true;
216 device.ext_vertex_attribute_divisor.vertex_attribute_divisor_features_ext
217 .sType =
218 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES;
219 device.ext_vertex_attribute_divisor.vertex_attribute_divisor_features_ext
220 .pNext = features.pNext;
221 features.pNext = &device.ext_vertex_attribute_divisor
222 .vertex_attribute_divisor_features_ext;
223 }
224
225 if (HasExtension("VK_EXT_transform_feedback", device.extensions)) {
226 device.ext_transform_feedback.reported = true;
227 device.ext_transform_feedback.transform_feedback_features_ext.sType =
228 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT;
229 device.ext_transform_feedback.transform_feedback_features_ext.pNext =
230 features.pNext;
231 features.pNext =
232 &device.ext_transform_feedback.transform_feedback_features_ext;
233 }
234
235 if (HasExtension("VK_KHR_shader_subgroup_uniform_control_flow",
236 device.extensions)) {
237 device.khr_shader_subgroup_uniform_control_flow.reported = true;
238 device.khr_shader_subgroup_uniform_control_flow
239 .shader_subgroup_uniform_control_flow_features_khr.sType =
240 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_UNIFORM_CONTROL_FLOW_FEATURES_KHR;
241 device.khr_shader_subgroup_uniform_control_flow
242 .shader_subgroup_uniform_control_flow_features_khr.pNext =
243 features.pNext;
244 features.pNext = &device.khr_shader_subgroup_uniform_control_flow
245 .shader_subgroup_uniform_control_flow_features_khr;
246 }
247
248 if (HasExtension("VK_KHR_shader_subgroup_extended_types",
249 device.extensions)) {
250 device.khr_shader_subgroup_extended_types.reported = true;
251 device.khr_shader_subgroup_extended_types
252 .shader_subgroup_extended_types_features_khr.sType =
253 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES;
254 device.khr_shader_subgroup_extended_types
255 .shader_subgroup_extended_types_features_khr.pNext = features.pNext;
256 features.pNext = &device.khr_shader_subgroup_extended_types
257 .shader_subgroup_extended_types_features_khr;
258 }
259
260 if (HasExtension("VK_KHR_8bit_storage", device.extensions)) {
261 device.khr_8bit_storage.reported = true;
262 device.khr_8bit_storage.bit8_storage_features_khr.sType =
263 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES;
264 device.khr_8bit_storage.bit8_storage_features_khr.pNext = features.pNext;
265 features.pNext = &device.khr_8bit_storage.bit8_storage_features_khr;
266 }
267
268 if (HasExtension("VK_KHR_shader_integer_dot_product", device.extensions)) {
269 device.khr_shader_integer_dot_product.reported = true;
270 device.khr_shader_integer_dot_product
271 .shader_integer_dot_product_features_khr.sType =
272 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_INTEGER_DOT_PRODUCT_FEATURES;
273 device.khr_shader_integer_dot_product
274 .shader_integer_dot_product_features_khr.pNext = features.pNext;
275 features.pNext = &device.khr_shader_integer_dot_product
276 .shader_integer_dot_product_features_khr;
277 }
278
279 if (HasExtension("VK_IMG_relaxed_line_rasterization", device.extensions)) {
280 device.img_relaxed_line_rasterization.reported = true;
281 device.img_relaxed_line_rasterization
282 .relaxed_line_rasterization_features_img.sType =
283 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RELAXED_LINE_RASTERIZATION_FEATURES_IMG;
284 device.img_relaxed_line_rasterization
285 .relaxed_line_rasterization_features_img.pNext = features.pNext;
286 features.pNext = &device.img_relaxed_line_rasterization
287 .relaxed_line_rasterization_features_img;
288 }
289
290 if (HasExtension("VK_KHR_line_rasterization", device.extensions)) {
291 device.khr_line_rasterization.reported = true;
292 device.khr_line_rasterization.line_rasterization_features_khr.sType =
293 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES;
294 device.khr_line_rasterization.line_rasterization_features_khr.pNext =
295 features.pNext;
296 features.pNext =
297 &device.khr_line_rasterization.line_rasterization_features_khr;
298 }
299
300 if (HasExtension("VK_EXT_line_rasterization", device.extensions)) {
301 device.ext_line_rasterization.reported = true;
302 device.ext_line_rasterization.line_rasterization_features_ext.sType =
303 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES;
304 device.ext_line_rasterization.line_rasterization_features_ext.pNext =
305 features.pNext;
306 features.pNext =
307 &device.ext_line_rasterization.line_rasterization_features_ext;
308 }
309
310 if (HasExtension("VK_EXT_primitives_generated_query", device.extensions)) {
311 device.ext_primitives_generated_query.reported = true;
312 device.ext_primitives_generated_query
313 .primitives_generated_query_features_ext.sType =
314 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVES_GENERATED_QUERY_FEATURES_EXT;
315 device.ext_primitives_generated_query
316 .primitives_generated_query_features_ext.pNext = features.pNext;
317 features.pNext = &device.ext_primitives_generated_query
318 .primitives_generated_query_features_ext;
319 }
320
321 vkGetPhysicalDeviceFeatures2(physical_device, &features);
322 device.features = features.features;
323
324 vkGetPhysicalDeviceMemoryProperties(physical_device, &device.memory);
325
326 uint32_t queue_family_count = 0;
327 vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count,
328 nullptr);
329 if (queue_family_count > 0) {
330 device.queues.resize(queue_family_count);
331 vkGetPhysicalDeviceQueueFamilyProperties(
332 physical_device, &queue_family_count, device.queues.data());
333 }
334
335 VkFormatProperties format_properties = {};
336 for (VkFormat format = VK_FORMAT_R4G4_UNORM_PACK8;
337 // TODO(http://b/171403054): avoid hard-coding last value in the
338 // contiguous range
339 format <= VK_FORMAT_ASTC_12x12_SRGB_BLOCK;
340 format = static_cast<VkFormat>(format + 1)) {
341 vkGetPhysicalDeviceFormatProperties(physical_device, format,
342 &format_properties);
343 if (format_properties.linearTilingFeatures ||
344 format_properties.optimalTilingFeatures ||
345 format_properties.bufferFeatures) {
346 device.formats.insert(std::make_pair(format, format_properties));
347 }
348 }
349
350 if (device.properties.apiVersion >= VK_API_VERSION_1_1) {
351 for (VkFormat format = VK_FORMAT_G8B8G8R8_422_UNORM;
352 // TODO(http://b/171403054): avoid hard-coding last value in the
353 // contiguous range
354 format <= VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM;
355 format = static_cast<VkFormat>(format + 1)) {
356 vkGetPhysicalDeviceFormatProperties(physical_device, format,
357 &format_properties);
358 if (format_properties.linearTilingFeatures ||
359 format_properties.optimalTilingFeatures ||
360 format_properties.bufferFeatures) {
361 device.formats.insert(std::make_pair(format, format_properties));
362 }
363 }
364
365 device.subgroup_properties.sType =
366 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
367 device.subgroup_properties.pNext = properties.pNext;
368 properties.pNext = &device.subgroup_properties;
369
370 device.point_clipping_properties.sType =
371 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES;
372 device.point_clipping_properties.pNext = properties.pNext;
373 properties.pNext = &device.point_clipping_properties;
374
375 device.multiview_properties.sType =
376 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES;
377 device.multiview_properties.pNext = properties.pNext;
378 properties.pNext = &device.multiview_properties;
379
380 device.id_properties.sType =
381 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
382 device.id_properties.pNext = properties.pNext;
383 properties.pNext = &device.id_properties;
384
385 device.maintenance3_properties.sType =
386 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES;
387 device.maintenance3_properties.pNext = properties.pNext;
388 properties.pNext = &device.maintenance3_properties;
389
390 vkGetPhysicalDeviceProperties2(physical_device, &properties);
391
392 device.multiview_features.sType =
393 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES;
394 device.multiview_features.pNext = features.pNext;
395 features.pNext = &device.multiview_features;
396
397 device.variable_pointers_features.sType =
398 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES;
399 device.variable_pointers_features.pNext = features.pNext;
400 features.pNext = &device.variable_pointers_features;
401
402 device.protected_memory_features.sType =
403 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES;
404 device.protected_memory_features.pNext = features.pNext;
405 features.pNext = &device.protected_memory_features;
406
407 device.sampler_ycbcr_conversion_features.sType =
408 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
409 device.sampler_ycbcr_conversion_features.pNext = features.pNext;
410 features.pNext = &device.sampler_ycbcr_conversion_features;
411
412 device.shader_draw_parameter_features.sType =
413 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES;
414 device.shader_draw_parameter_features.pNext = features.pNext;
415 features.pNext = &device.shader_draw_parameter_features;
416
417 device.bit16_storage_features.sType =
418 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES;
419 device.bit16_storage_features.pNext = features.pNext;
420 features.pNext = &device.bit16_storage_features;
421
422 vkGetPhysicalDeviceFeatures2(physical_device, &features);
423
424 VkPhysicalDeviceExternalFenceInfo external_fence_info = {
425 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, nullptr,
426 VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT};
427 VkExternalFenceProperties external_fence_properties = {};
428
429 for (VkExternalFenceHandleTypeFlagBits handle_type =
430 VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT;
431 handle_type <= VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT;
432 handle_type =
433 static_cast<VkExternalFenceHandleTypeFlagBits>(handle_type << 1)) {
434 external_fence_info.handleType = handle_type;
435 vkGetPhysicalDeviceExternalFenceProperties(
436 physical_device, &external_fence_info, &external_fence_properties);
437 if (external_fence_properties.exportFromImportedHandleTypes ||
438 external_fence_properties.compatibleHandleTypes ||
439 external_fence_properties.externalFenceFeatures) {
440 device.external_fence_properties.insert(
441 std::make_pair(handle_type, external_fence_properties));
442 }
443 }
444
445 VkPhysicalDeviceExternalSemaphoreInfo external_semaphore_info = {
446 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, nullptr,
447 VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT};
448 VkExternalSemaphoreProperties external_semaphore_properties = {};
449
450 for (VkExternalSemaphoreHandleTypeFlagBits handle_type =
451 VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
452 handle_type <= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
453 handle_type = static_cast<VkExternalSemaphoreHandleTypeFlagBits>(
454 handle_type << 1)) {
455 external_semaphore_info.handleType = handle_type;
456 vkGetPhysicalDeviceExternalSemaphoreProperties(
457 physical_device, &external_semaphore_info,
458 &external_semaphore_properties);
459 if (external_semaphore_properties.exportFromImportedHandleTypes ||
460 external_semaphore_properties.compatibleHandleTypes ||
461 external_semaphore_properties.externalSemaphoreFeatures) {
462 device.external_semaphore_properties.insert(
463 std::make_pair(handle_type, external_semaphore_properties));
464 }
465 }
466 }
467
468 if (device.properties.apiVersion >= VK_API_VERSION_1_2) {
469 device.core11.properties.sType =
470 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES;
471 device.core11.properties.pNext = properties.pNext;
472 properties.pNext = &device.core11.properties;
473
474 device.core12.properties.sType =
475 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES;
476 device.core12.properties.pNext = properties.pNext;
477 properties.pNext = &device.core12.properties;
478
479 vkGetPhysicalDeviceProperties2(physical_device, &properties);
480
481 device.core11.features.sType =
482 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES;
483 device.core11.features.pNext = features.pNext;
484 features.pNext = &device.core11.features;
485
486 device.core12.features.sType =
487 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
488 device.core12.features.pNext = features.pNext;
489 features.pNext = &device.core12.features;
490
491 vkGetPhysicalDeviceFeatures2(physical_device, &features);
492 }
493
494 if (device.properties.apiVersion >= VK_API_VERSION_1_3) {
495 device.core13.properties.sType =
496 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_PROPERTIES;
497 device.core13.properties.pNext = properties.pNext;
498 properties.pNext = &device.core13.properties;
499
500 vkGetPhysicalDeviceProperties2(physical_device, &properties);
501
502 device.core13.features.sType =
503 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES;
504 device.core13.features.pNext = features.pNext;
505 features.pNext = &device.core13.features;
506
507 vkGetPhysicalDeviceFeatures2(physical_device, &features);
508 }
509
510 if (device.properties.apiVersion >= VK_API_VERSION_1_4) {
511 device.core14.properties.sType =
512 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_PROPERTIES;
513 device.core14.properties.pNext = properties.pNext;
514 properties.pNext = &device.core14.properties;
515
516 vkGetPhysicalDeviceProperties2(physical_device, &properties);
517
518 if (device.core14.properties.copySrcLayoutCount > 0 ||
519 device.core14.properties.copyDstLayoutCount > 0) {
520 if (device.core14.properties.copySrcLayoutCount > 0) {
521 device.core14.copy_src_layouts.resize(
522 device.core14.properties.copySrcLayoutCount);
523 device.core14.properties.pCopySrcLayouts =
524 device.core14.copy_src_layouts.data();
525 }
526 if (device.core14.properties.copyDstLayoutCount > 0) {
527 device.core14.copy_dst_layouts.resize(
528 device.core14.properties.copyDstLayoutCount);
529 device.core14.properties.pCopyDstLayouts =
530 device.core14.copy_dst_layouts.data();
531 }
532 vkGetPhysicalDeviceProperties2(physical_device, &properties);
533 }
534
535 device.core14.features.sType =
536 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES;
537 device.core14.features.pNext = features.pNext;
538 features.pNext = &device.core14.features;
539
540 vkGetPhysicalDeviceFeatures2(physical_device, &features);
541 }
542
543 return device;
544 }
545
VkJsonGetInstance()546 VkJsonInstance VkJsonGetInstance() {
547 VkJsonInstance instance;
548 VkResult result;
549 uint32_t count;
550
551 count = 0;
552 result = vkEnumerateInstanceLayerProperties(&count, nullptr);
553 if (result != VK_SUCCESS)
554 return VkJsonInstance();
555 if (count > 0) {
556 std::vector<VkLayerProperties> layers(count);
557 result = vkEnumerateInstanceLayerProperties(&count, layers.data());
558 if (result != VK_SUCCESS)
559 return VkJsonInstance();
560 instance.layers.reserve(count);
561 for (auto& layer : layers) {
562 instance.layers.push_back(
563 VkJsonLayer{layer, std::vector<VkExtensionProperties>()});
564 if (!EnumerateExtensions(layer.layerName,
565 &instance.layers.back().extensions))
566 return VkJsonInstance();
567 }
568 }
569
570 if (!EnumerateExtensions(nullptr, &instance.extensions))
571 return VkJsonInstance();
572
573 const VkApplicationInfo app_info = {
574 VK_STRUCTURE_TYPE_APPLICATION_INFO,
575 nullptr,
576 "vkjson_info",
577 1,
578 "",
579 0,
580 VK_API_VERSION_1_1,
581 };
582 VkInstanceCreateInfo instance_info = {
583 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
584 nullptr,
585 0,
586 &app_info,
587 0,
588 nullptr,
589 0,
590 nullptr,
591 };
592 VkInstance vkinstance;
593 result = vkCreateInstance(&instance_info, nullptr, &vkinstance);
594 if (result != VK_SUCCESS)
595 return VkJsonInstance();
596
597 count = 0;
598 result = vkEnumeratePhysicalDevices(vkinstance, &count, nullptr);
599 if (result != VK_SUCCESS) {
600 vkDestroyInstance(vkinstance, nullptr);
601 return VkJsonInstance();
602 }
603
604 std::vector<VkPhysicalDevice> devices(count, VK_NULL_HANDLE);
605 result = vkEnumeratePhysicalDevices(vkinstance, &count, devices.data());
606 if (result != VK_SUCCESS) {
607 vkDestroyInstance(vkinstance, nullptr);
608 return VkJsonInstance();
609 }
610
611 std::map<VkPhysicalDevice, uint32_t> device_map;
612 const uint32_t sz = devices.size();
613 instance.devices.reserve(sz);
614 for (uint32_t i = 0; i < sz; ++i) {
615 device_map.insert(std::make_pair(devices[i], i));
616 instance.devices.emplace_back(VkJsonGetDevice(devices[i]));
617 }
618
619 result = vkEnumerateInstanceVersion(&instance.api_version);
620 if (result != VK_SUCCESS) {
621 vkDestroyInstance(vkinstance, nullptr);
622 return VkJsonInstance();
623 }
624
625 count = 0;
626 result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count, nullptr);
627 if (result != VK_SUCCESS) {
628 vkDestroyInstance(vkinstance, nullptr);
629 return VkJsonInstance();
630 }
631
632 VkJsonDeviceGroup device_group;
633 std::vector<VkPhysicalDeviceGroupProperties> group_properties;
634 group_properties.resize(count);
635 for (auto& properties : group_properties) {
636 properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES;
637 properties.pNext = nullptr;
638 }
639 result = vkEnumeratePhysicalDeviceGroups(vkinstance, &count,
640 group_properties.data());
641 if (result != VK_SUCCESS) {
642 vkDestroyInstance(vkinstance, nullptr);
643 return VkJsonInstance();
644 }
645 for (auto properties : group_properties) {
646 device_group.properties = properties;
647 for (uint32_t i = 0; i < properties.physicalDeviceCount; ++i) {
648 device_group.device_inds.push_back(
649 device_map[properties.physicalDevices[i]]);
650 }
651 instance.device_groups.push_back(device_group);
652 }
653
654 vkDestroyInstance(vkinstance, nullptr);
655 return instance;
656 }
657