The open source OpenXR runtime
0
fork

Configure Feed

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

c/util: Use enumeration helpers

+36 -19
+36 -19
src/xrt/compositor/util/comp_vulkan.c
··· 1 - // Copyright 2019-2021, Collabora, Ltd. 1 + // Copyright 2019-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file ··· 45 45 } 46 46 47 47 static bool 48 - get_device_uuid(struct vk_bundle *vk, int gpu_index, xrt_uuid_t *uuid) 48 + get_device_id_props(struct vk_bundle *vk, int gpu_index, VkPhysicalDeviceIDProperties *out_id_props) 49 49 { 50 50 VkPhysicalDeviceIDProperties pdidp = { 51 51 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, ··· 56 56 .pNext = &pdidp, 57 57 }; 58 58 59 - VkPhysicalDevice phys[16]; 60 - uint32_t gpu_count = ARRAY_SIZE(phys); 59 + VkPhysicalDevice *phys = NULL; 60 + uint32_t gpu_count = 0; 61 61 VkResult ret; 62 62 63 - ret = vk->vkEnumeratePhysicalDevices(vk->instance, &gpu_count, phys); 63 + ret = vk_enumerate_physical_devices( // 64 + vk, // vk_bundle 65 + &gpu_count, // out_physical_device_count 66 + &phys); // out_physical_devices 64 67 if (ret != VK_SUCCESS) { 65 - VK_ERROR_RET(vk, "vkEnumeratePhysicalDevices", "Failed to enumerate physical devices.", ret); 68 + VK_ERROR_RET(vk, "vk_enumerate_physical_devices", "Failed to enumerate physical devices.", ret); 69 + return false; 70 + } 71 + if (gpu_count == 0) { 72 + VK_ERROR(vk, "vk_enumerate_physical_devices: Returned zero physical devices!"); 66 73 return false; 67 74 } 68 75 69 76 vk->vkGetPhysicalDeviceProperties2(phys[gpu_index], &pdp2); 77 + free(phys); 78 + 79 + *out_id_props = pdidp; 80 + 81 + return true; 82 + } 83 + 84 + static bool 85 + get_device_uuid(struct vk_bundle *vk, int gpu_index, xrt_uuid_t *uuid) 86 + { 87 + VkPhysicalDeviceIDProperties pdidp = { 88 + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, 89 + }; 90 + 91 + if (!get_device_id_props(vk, gpu_index, &pdidp)) { 92 + VK_ERROR(vk, "get_device_id_props: false"); 93 + return false; 94 + } 95 + 70 96 memcpy(uuid->data, pdidp.deviceUUID, ARRAY_SIZE(uuid->data)); 71 97 72 98 return true; ··· 79 105 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, 80 106 }; 81 107 82 - VkPhysicalDeviceProperties2 pdp2 = { 83 - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, 84 - .pNext = &pdidp, 85 - }; 86 - 87 - VkPhysicalDevice phys[16]; 88 - uint32_t gpu_count = ARRAY_SIZE(phys); 89 - VkResult ret; 90 - 91 - ret = vk->vkEnumeratePhysicalDevices(vk->instance, &gpu_count, phys); 92 - if (ret != VK_SUCCESS) { 93 - VK_ERROR_RET(vk, "vkEnumeratePhysicalDevices", "Failed to enumerate physical devices.", ret); 108 + if (!get_device_id_props(vk, gpu_index, &pdidp)) { 109 + VK_ERROR(vk, "get_device_id_props: false"); 94 110 return false; 95 111 } 96 112 97 - vk->vkGetPhysicalDeviceProperties2(phys[gpu_index], &pdp2); 113 + // Is the LUID even valid? 98 114 if (pdidp.deviceLUIDValid != VK_TRUE) { 99 115 return false; 100 116 } 117 + 101 118 memcpy(luid->data, pdidp.deviceLUID, ARRAY_SIZE(luid->data)); 102 119 103 120 return true;