The open source OpenXR runtime
0
fork

Configure Feed

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

a/vk: Add enumeration helpers

+203
+1
src/xrt/auxiliary/vk/CMakeLists.txt
··· 11 11 vk_compositor_flags.c 12 12 vk_debug.c 13 13 vk_documentation.h 14 + vk_enumerate.c 14 15 vk_function_loaders.c 15 16 vk_helpers.c 16 17 vk_helpers.h
+146
src/xrt/auxiliary/vk/vk_enumerate.c
··· 1 + // Copyright 2019-2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Vulkan enumeration helpers code. 6 + * 7 + * @author Jakob Bornecrantz <jakob@collabora.com> 8 + * @ingroup aux_vk 9 + */ 10 + 11 + #include "xrt/xrt_handles.h" 12 + 13 + #include "util/u_misc.h" 14 + #include "util/u_debug.h" 15 + 16 + #include "vk/vk_helpers.h" 17 + 18 + 19 + /* 20 + * 21 + * Helpers. 22 + * 23 + */ 24 + 25 + #define CHECK_FIRST_CALL(FUNC, RET, COUNT) \ 26 + do { \ 27 + if (vk_has_error(RET, FUNC, __FILE__, __LINE__)) { \ 28 + return RET; \ 29 + } \ 30 + if (COUNT == 0) { \ 31 + goto out; \ 32 + } \ 33 + } while (false) 34 + 35 + #define CHECK_SECOND_CALL(FUNC, RET, TO_FREE) \ 36 + do { \ 37 + if (vk_has_error(RET, FUNC, __FILE__, __LINE__)) { \ 38 + free(TO_FREE); \ 39 + return RET; \ 40 + } \ 41 + } while (false) 42 + 43 + 44 + /* 45 + * 46 + * 'Exported' functions. 47 + * 48 + */ 49 + 50 + VkResult 51 + vk_enumerate_instance_extensions_properties(struct vk_bundle *vk, 52 + const char *layer_name, 53 + uint32_t *out_prop_count, 54 + VkExtensionProperties **out_props) 55 + { 56 + VkExtensionProperties *props = NULL; 57 + uint32_t prop_count = 0; 58 + VkResult ret; 59 + 60 + ret = vk->vkEnumerateInstanceExtensionProperties(layer_name, &prop_count, NULL); 61 + CHECK_FIRST_CALL("vkEnumerateInstanceExtensionProperties", ret, prop_count); 62 + 63 + props = U_TYPED_ARRAY_CALLOC(VkExtensionProperties, prop_count); 64 + ret = vk->vkEnumerateInstanceExtensionProperties(layer_name, &prop_count, props); 65 + CHECK_SECOND_CALL("vkEnumerateInstanceExtensionProperties", ret, props); 66 + 67 + out: 68 + *out_prop_count = prop_count; 69 + *out_props = props; 70 + 71 + return VK_SUCCESS; 72 + } 73 + 74 + VkResult 75 + vk_enumerate_physical_devices(struct vk_bundle *vk, 76 + uint32_t *out_physical_device_count, 77 + VkPhysicalDevice **out_physical_devices) 78 + { 79 + VkPhysicalDevice *physical_devices = NULL; 80 + uint32_t physical_device_count = 0; 81 + VkResult ret; 82 + 83 + ret = vk->vkEnumeratePhysicalDevices(vk->instance, &physical_device_count, NULL); 84 + CHECK_FIRST_CALL("vkEnumeratePhysicalDevices", ret, physical_device_count); 85 + 86 + physical_devices = U_TYPED_ARRAY_CALLOC(VkPhysicalDevice, physical_device_count); 87 + ret = vk->vkEnumeratePhysicalDevices(vk->instance, &physical_device_count, physical_devices); 88 + CHECK_SECOND_CALL("vkEnumeratePhysicalDevices", ret, physical_devices); 89 + 90 + out: 91 + *out_physical_device_count = physical_device_count; 92 + *out_physical_devices = physical_devices; 93 + 94 + return VK_SUCCESS; 95 + } 96 + 97 + VkResult 98 + vk_enumerate_physical_device_extension_properties(struct vk_bundle *vk, 99 + VkPhysicalDevice physical_device, 100 + const char *layer_name, 101 + uint32_t *out_prop_count, 102 + VkExtensionProperties **out_props) 103 + { 104 + VkExtensionProperties *props = NULL; 105 + uint32_t prop_count = 0; 106 + VkResult ret; 107 + 108 + ret = vk->vkEnumerateDeviceExtensionProperties(physical_device, layer_name, &prop_count, NULL); 109 + CHECK_FIRST_CALL("vkEnumerateDeviceExtensionProperties", ret, prop_count); 110 + 111 + props = U_TYPED_ARRAY_CALLOC(VkExtensionProperties, prop_count); 112 + ret = vk->vkEnumerateDeviceExtensionProperties(physical_device, layer_name, &prop_count, props); 113 + CHECK_SECOND_CALL("vkEnumerateDeviceExtensionProperties", ret, props); 114 + 115 + out: 116 + *out_prop_count = prop_count; 117 + *out_props = props; 118 + 119 + return VK_SUCCESS; 120 + } 121 + 122 + #ifdef VK_USE_PLATFORM_DISPLAY_KHR 123 + VkResult 124 + vk_enumerate_physical_device_display_properties(struct vk_bundle *vk, 125 + VkPhysicalDevice physical_device, 126 + uint32_t *out_prop_count, 127 + VkDisplayPropertiesKHR **out_props) 128 + { 129 + VkDisplayPropertiesKHR *props = NULL; 130 + uint32_t prop_count = 0; 131 + VkResult ret; 132 + 133 + ret = vk->vkGetPhysicalDeviceDisplayPropertiesKHR(physical_device, &prop_count, NULL); 134 + CHECK_FIRST_CALL("vkGetPhysicalDeviceDisplayPropertiesKHR", ret, prop_count); 135 + 136 + props = U_TYPED_ARRAY_CALLOC(VkDisplayPropertiesKHR, prop_count); 137 + ret = vk->vkGetPhysicalDeviceDisplayPropertiesKHR(physical_device, &prop_count, props); 138 + CHECK_SECOND_CALL("vkGetPhysicalDeviceDisplayPropertiesKHR", ret, props); 139 + 140 + out: 141 + *out_props = props; 142 + *out_prop_count = prop_count; 143 + 144 + return VK_SUCCESS; 145 + } 146 + #endif
+56
src/xrt/auxiliary/vk/vk_helpers.h
··· 612 612 613 613 /* 614 614 * 615 + * Enumeration helpers, in the vk_enumerate.c file. 616 + * 617 + */ 618 + 619 + /*! 620 + * Return the @p VkExtensionProperties of the given @p layer_name, NULL means 621 + * the "base" driver instance. 622 + * 623 + * @ingroup aux_vk 624 + */ 625 + VkResult 626 + vk_enumerate_instance_extensions_properties(struct vk_bundle *vk, 627 + const char *layer_name, 628 + uint32_t *out_prop_count, 629 + VkExtensionProperties **out_props); 630 + 631 + /*! 632 + * Enumerate the physical devices of the @VkInstance that has been opened on 633 + * the given @ref vk_bundle. 634 + * 635 + * @ingroup aux_vk 636 + */ 637 + VkResult 638 + vk_enumerate_physical_devices(struct vk_bundle *vk, 639 + uint32_t *out_physical_device_count, 640 + VkPhysicalDevice **out_physical_devices); 641 + 642 + /*! 643 + * Enumerate the extension properties of the given @p VkPhysicalDevice for the 644 + * named @p layer_name, NULL means the "base" driver physical device. 645 + * 646 + * @ingroup aux_vk 647 + */ 648 + VkResult 649 + vk_enumerate_physical_device_extension_properties(struct vk_bundle *vk, 650 + VkPhysicalDevice physical_device, 651 + const char *layer_name, 652 + uint32_t *out_prop_count, 653 + VkExtensionProperties **out_props); 654 + 655 + #if defined(VK_USE_PLATFORM_DISPLAY_KHR) || defined(XRT_DOXYGEN) 656 + /*! 657 + * Enumerate the display properties of the given @p VkPhysicalDevice. 658 + * 659 + * @ingroup aux_vk 660 + */ 661 + VkResult 662 + vk_enumerate_physical_device_display_properties(struct vk_bundle *vk, 663 + VkPhysicalDevice physical_device, 664 + uint32_t *out_prop_count, 665 + VkDisplayPropertiesKHR **out_props); 666 + #endif 667 + 668 + 669 + /* 670 + * 615 671 * Struct init functions, in the vk_function_loaders.c file. 616 672 * 617 673 */