The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/vk: Use enumeration helpers

+41 -55
+41 -55
src/xrt/auxiliary/vk/vk_bundle_init.c
··· 38 38 head->pNext = (void *)new_struct; 39 39 } 40 40 41 - static VkResult 42 - enumerate_instance_extensions_properties(struct vk_bundle *vk, 43 - VkExtensionProperties **out_props, 44 - uint32_t *out_prop_count) 45 - { 46 - VkExtensionProperties *props = NULL; 47 - uint32_t prop_count = 0; 48 - VkResult ret; 49 - 50 - ret = vk->vkEnumerateInstanceExtensionProperties(NULL, &prop_count, NULL); 51 - vk_check_error("vkEnumerateInstanceExtensionProperties", ret, false); 52 - 53 - props = U_TYPED_ARRAY_CALLOC(VkExtensionProperties, prop_count); 54 - ret = vk->vkEnumerateInstanceExtensionProperties(NULL, &prop_count, props); 55 - vk_check_error_with_free("vkEnumerateInstanceExtensionProperties", ret, false, props); 56 - 57 - *out_props = props; 58 - *out_prop_count = prop_count; 59 - 60 - return VK_SUCCESS; 61 - } 62 - 63 41 static bool 64 42 should_skip_optional_instance_ext(struct vk_bundle *vk, 65 43 struct u_string_list *required_instance_ext_list, ··· 108 86 VkResult ret; 109 87 110 88 // Two call. 111 - ret = enumerate_instance_extensions_properties(vk, &props, &prop_count); 89 + ret = vk_enumerate_instance_extensions_properties( // 90 + vk, // vk_bundle 91 + NULL, // layer_name 92 + &prop_count, // out_prop_count 93 + &props); // out_props 112 94 if (ret != VK_SUCCESS) { 113 95 return ret; // Already logged. 114 96 } ··· 152 134 VkResult ret; 153 135 154 136 // Two call. 155 - ret = enumerate_instance_extensions_properties(vk, &props, &prop_count); 137 + ret = vk_enumerate_instance_extensions_properties( // 138 + vk, // vk_bundle 139 + NULL, // layer_name 140 + &prop_count, // out_prop_count 141 + &props); // out_props 156 142 if (ret != VK_SUCCESS) { 157 143 return NULL; // Already logged. 158 144 } ··· 553 539 static VkResult 554 540 select_physical_device(struct vk_bundle *vk, int forced_index) 555 541 { 556 - VkPhysicalDevice physical_devices[16]; 557 - uint32_t gpu_count = ARRAY_SIZE(physical_devices); 542 + VkPhysicalDevice *physical_devices = NULL; 543 + uint32_t gpu_count = 0; 558 544 VkResult ret; 559 545 560 - ret = vk->vkEnumeratePhysicalDevices(vk->instance, &gpu_count, physical_devices); 546 + ret = vk_enumerate_physical_devices( // 547 + vk, // vk_bundle 548 + &gpu_count, // out_physical_device_count 549 + &physical_devices); // out_physical_devices 561 550 if (ret != VK_SUCCESS) { 562 - VK_DEBUG(vk, "vkEnumeratePhysicalDevices: %s", vk_result_string(ret)); 551 + VK_ERROR(vk, "vk_enumerate_physical_devices: %s", vk_result_string(ret)); 563 552 return ret; 564 553 } 565 - 566 554 if (gpu_count == 0) { 567 - VK_DEBUG(vk, "No physical device found!"); 568 - return VK_ERROR_DEVICE_LOST; 555 + VK_ERROR(vk, "No physical device found!"); 556 + return VK_ERROR_DEVICE_LOST; // No need to free if zero devices. 569 557 } 570 558 571 559 VK_DEBUG(vk, "Choosing Vulkan device index"); ··· 575 563 if (uint_index + 1 > gpu_count) { 576 564 VK_ERROR(vk, "Attempted to force GPU index %u, but only %u GPUs are available", uint_index, 577 565 gpu_count); 566 + free(physical_devices); 578 567 return VK_ERROR_DEVICE_LOST; 579 568 } 580 569 gpu_index = uint_index; ··· 584 573 gpu_index = select_preferred_device(vk, physical_devices, gpu_count); 585 574 } 586 575 576 + // Setup the physical device on the bundle. 587 577 vk->physical_device = physical_devices[gpu_index]; 588 578 vk->physical_device_index = gpu_index; 589 579 580 + // Free the array. 581 + free(physical_devices); 582 + physical_devices = NULL; 583 + 584 + 585 + /* 586 + * Have now selected device, get properties of it. 587 + */ 588 + 590 589 VkPhysicalDeviceProperties pdp; 591 - vk->vkGetPhysicalDeviceProperties(physical_devices[gpu_index], &pdp); 590 + vk->vkGetPhysicalDeviceProperties(vk->physical_device, &pdp); 592 591 593 592 char title[20]; 594 593 (void)snprintf(title, sizeof(title), "Selected GPU: %u\n", gpu_index); ··· 869 868 // end of GENERATED device extension code - do not modify - used by scripts 870 869 } 871 870 872 - static VkResult 873 - get_device_ext_props(struct vk_bundle *vk, 874 - VkPhysicalDevice physical_device, 875 - VkExtensionProperties **out_props, 876 - uint32_t *out_prop_count) 877 - { 878 - uint32_t prop_count = 0; 879 - VkResult res = vk->vkEnumerateDeviceExtensionProperties(physical_device, NULL, &prop_count, NULL); 880 - vk_check_error("vkEnumerateDeviceExtensionProperties", res, false); 881 - 882 - VkExtensionProperties *props = U_TYPED_ARRAY_CALLOC(VkExtensionProperties, prop_count); 883 - 884 - res = vk->vkEnumerateDeviceExtensionProperties(physical_device, NULL, &prop_count, props); 885 - vk_check_error_with_free("vkEnumerateDeviceExtensionProperties", res, false, props); 886 - 887 - // The preceding check returns on failure. 888 - *out_props = props; 889 - *out_prop_count = prop_count; 890 - 891 - return VK_SUCCESS; 892 - } 893 - 894 871 static bool 895 872 should_skip_optional_device_ext(struct vk_bundle *vk, 896 873 struct u_string_list *required_device_ext_list, ··· 921 898 { 922 899 VkExtensionProperties *props = NULL; 923 900 uint32_t prop_count = 0; 924 - if (get_device_ext_props(vk, physical_device, &props, &prop_count) != VK_SUCCESS) { 901 + VkResult ret; 902 + 903 + ret = vk_enumerate_physical_device_extension_properties( // 904 + vk, // vk_bundle 905 + physical_device, // physical_device 906 + NULL, // layer_name 907 + &prop_count, // out_prop_count 908 + &props); // out_props 909 + if (ret != VK_SUCCESS) { 910 + VK_ERROR(vk, "vk_enumerate_physical_device_extension_properties: %s", vk_result_string(ret)); 925 911 return false; 926 912 } 927 913