xrt: Add xrt_uuid_t

This commit is contained in:
Jakob Bornecrantz 2022-05-01 09:33:37 +01:00
parent 428e46617a
commit 91facd10f1
7 changed files with 61 additions and 39 deletions

View file

@ -721,15 +721,14 @@ compositor_init_vulkan(struct comp_compositor *c)
}
// clang-format off
static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceUUID) == XRT_GPU_UUID_SIZE, "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.selected_gpu_deviceUUID) == XRT_GPU_UUID_SIZE, "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceUUID) == ARRAY_SIZE(c->settings.client_gpu_deviceUUID), "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.selected_gpu_deviceUUID) == ARRAY_SIZE(c->settings.selected_gpu_deviceUUID), "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceUUID.data) == XRT_UUID_SIZE, "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.selected_gpu_deviceUUID.data) == XRT_UUID_SIZE, "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceUUID.data) == ARRAY_SIZE(c->settings.client_gpu_deviceUUID.data), "array size mismatch");
static_assert(ARRAY_SIZE(vk_res.selected_gpu_deviceUUID.data) == ARRAY_SIZE(c->settings.selected_gpu_deviceUUID.data), "array size mismatch");
// clang-format on
memcpy(c->settings.client_gpu_deviceUUID, vk_res.client_gpu_deviceUUID, XRT_GPU_UUID_SIZE);
memcpy(c->settings.selected_gpu_deviceUUID, vk_res.selected_gpu_deviceUUID, XRT_GPU_UUID_SIZE);
c->settings.client_gpu_deviceUUID = vk_res.client_gpu_deviceUUID;
c->settings.selected_gpu_deviceUUID = vk_res.selected_gpu_deviceUUID;
c->settings.client_gpu_index = vk_res.client_gpu_index;
c->settings.selected_gpu_index = vk_res.selected_gpu_index;
@ -1194,11 +1193,8 @@ xrt_gfx_provider_create_system(struct xrt_device *xdev, struct xrt_system_compos
// Required by OpenXR spec.
sys_info->max_layers = 16;
memcpy(sys_info->compositor_vk_deviceUUID, c->settings.selected_gpu_deviceUUID, XRT_GPU_UUID_SIZE);
memcpy(sys_info->client_vk_deviceUUID, c->settings.client_gpu_deviceUUID, XRT_GPU_UUID_SIZE);
sys_info->compositor_vk_deviceUUID = c->settings.selected_gpu_deviceUUID;
sys_info->client_vk_deviceUUID = c->settings.client_gpu_deviceUUID;
// clang-format off
sys_info->views[0].recommended.width_pixels = w0;

View file

@ -112,12 +112,11 @@ struct comp_settings
int client_gpu_index;
//! Vulkan device UUID selected by comp_settings_check_vulkan_caps,
//! valid across Vulkan instances
uint8_t selected_gpu_deviceUUID[XRT_GPU_UUID_SIZE];
//! Vulkan device UUID selected by comp_settings_check_vulkan_caps, valid across Vulkan instances
xrt_uuid_t selected_gpu_deviceUUID;
//! Vulkan device UUID to suggest to clients
uint8_t client_gpu_deviceUUID[XRT_GPU_UUID_SIZE];
xrt_uuid_t client_gpu_deviceUUID;
//! Try to choose the mode with this index for direct mode
int desired_mode;

View file

@ -26,18 +26,18 @@
#define VK_ERROR_RET(VK, FUNC, MSG, RET) VK_ERROR(VK, FUNC ": %s\n\t" MSG, vk_result_string(RET))
#define UUID_STR_SIZE (XRT_GPU_UUID_SIZE * 3 + 1)
#define UUID_STR_SIZE (XRT_UUID_SIZE * 3 + 1)
static void
snprint_uuid(char *str, size_t size, uint8_t uuid[XRT_GPU_UUID_SIZE])
snprint_uuid(char *str, size_t size, xrt_uuid_t *uuid)
{
for (size_t i = 0, offset = 0; i < XRT_GPU_UUID_SIZE && offset < size; i++, offset += 3) {
snprintf(str + offset, size - offset, "%02x ", uuid[i]);
for (size_t i = 0, offset = 0; i < ARRAY_SIZE(uuid->data) && offset < size; i++, offset += 3) {
snprintf(str + offset, size - offset, "%02x ", uuid->data[i]);
}
}
static bool
get_device_uuid(struct vk_bundle *vk, int gpu_index, uint8_t *uuid)
get_device_uuid(struct vk_bundle *vk, int gpu_index, xrt_uuid_t *uuid)
{
VkPhysicalDeviceIDProperties pdidp = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
@ -59,7 +59,7 @@ get_device_uuid(struct vk_bundle *vk, int gpu_index, uint8_t *uuid)
}
vk->vkGetPhysicalDeviceProperties2(phys[gpu_index], &pdp2);
memcpy(uuid, pdidp.deviceUUID, XRT_GPU_UUID_SIZE);
memcpy(uuid->data, pdidp.deviceUUID, ARRAY_SIZE(uuid->data));
return true;
}
@ -75,9 +75,10 @@ fill_in_results(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_arg
// Store physical device UUID for compositor in settings
if (vk_res->selected_gpu_index >= 0) {
if (get_device_uuid(vk, vk_res->selected_gpu_index, vk_res->selected_gpu_deviceUUID)) {
if (get_device_uuid(vk, vk_res->selected_gpu_index, &vk_res->selected_gpu_deviceUUID)) {
char uuid_str[UUID_STR_SIZE] = {0};
snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), vk_res->selected_gpu_deviceUUID);
snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), &vk_res->selected_gpu_deviceUUID);
VK_DEBUG(vk, "Selected %d with uuid: %s", vk_res->selected_gpu_index, uuid_str);
} else {
VK_ERROR(vk, "Failed to get device %d uuid", vk_res->selected_gpu_index);
@ -91,9 +92,10 @@ fill_in_results(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_arg
// Store physical device UUID suggested to clients in settings
if (vk_res->client_gpu_index >= 0) {
if (get_device_uuid(vk, vk_res->client_gpu_index, vk_res->client_gpu_deviceUUID)) {
if (get_device_uuid(vk, vk_res->client_gpu_index, &vk_res->client_gpu_deviceUUID)) {
char uuid_str[UUID_STR_SIZE] = {0};
snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), vk_res->client_gpu_deviceUUID);
snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), &vk_res->client_gpu_deviceUUID);
// Trailing space above, means 'to' should be right next to '%s'.
VK_DEBUG(vk, "Suggest %d with uuid: %sto clients", vk_res->client_gpu_index, uuid_str);
} else {

View file

@ -71,10 +71,10 @@ struct comp_vulkan_results
int client_gpu_index;
//! Selected Vulkan device UUID.
uint8_t selected_gpu_deviceUUID[XRT_GPU_UUID_SIZE];
xrt_uuid_t selected_gpu_deviceUUID;
//! Selected Vulkan device UUID to suggest to clients.
uint8_t client_gpu_deviceUUID[XRT_GPU_UUID_SIZE];
xrt_uuid_t client_gpu_deviceUUID;
};
/*!

View file

@ -1718,10 +1718,10 @@ struct xrt_system_compositor_info
float refresh_rates[1];
//! The vk device as used by the compositor, never changes.
uint8_t compositor_vk_deviceUUID[XRT_GPU_UUID_SIZE];
xrt_uuid_t compositor_vk_deviceUUID;
//! The vk device suggested for Vulkan clients, never changes.
uint8_t client_vk_deviceUUID[XRT_GPU_UUID_SIZE];
xrt_uuid_t client_vk_deviceUUID;
};
struct xrt_system_compositor;

View file

@ -20,8 +20,29 @@
extern "C" {
#endif
//! internal define for VK_UUID_SIZE
#define XRT_GPU_UUID_SIZE 16
/*!
* Internal define for VK_UUID_SIZE and XR_UUID_SIZE_EXT.
*
* @ingroup xrt_iface
*/
#define XRT_UUID_SIZE 16
/*!
* To transport UUIDs between different APIs.
*
* @ingroup xrt_iface
*/
struct xrt_uuid
{
uint8_t data[XRT_UUID_SIZE];
};
/*!
* Typedef for @ref xrt_uuid.
*
* @ingroup xrt_iface
*/
typedef struct xrt_uuid xrt_uuid_t;
/*!
* A base class for reference counted objects.

View file

@ -33,13 +33,13 @@
#define GET_PROC(name) PFN_##name name = (PFN_##name)getProc(vkInstance, #name)
#define UUID_STR_SIZE (XRT_GPU_UUID_SIZE * 3 + 1)
#define UUID_STR_SIZE (XRT_UUID_SIZE * 3 + 1)
static void
snprint_uuid(char *str, size_t size, uint8_t uuid[XRT_GPU_UUID_SIZE])
snprint_uuid(char *str, size_t size, const xrt_uuid_t *uuid)
{
for (size_t i = 0, offset = 0; i < XRT_GPU_UUID_SIZE && offset < size; i++, offset += 3) {
snprintf(str + offset, size - offset, "%02x ", uuid[i]);
for (size_t i = 0, offset = 0; i < ARRAY_SIZE(uuid->data) && offset < size; i++, offset += 3) {
snprintf(str + offset, size - offset, "%02x ", uuid->data[i]);
}
}
@ -439,7 +439,7 @@ oxr_vk_get_physical_device(struct oxr_logger *log,
}
char suggested_uuid_str[UUID_STR_SIZE] = {0};
snprint_uuid(suggested_uuid_str, ARRAY_SIZE(suggested_uuid_str), sys->xsysc->info.client_vk_deviceUUID);
snprint_uuid(suggested_uuid_str, ARRAY_SIZE(suggested_uuid_str), &sys->xsysc->info.client_vk_deviceUUID);
enum u_logging_level log_level = debug_get_log_option_compositor_log();
int gpu_index = -1;
@ -451,13 +451,17 @@ oxr_vk_get_physical_device(struct oxr_logger *log,
vkGetPhysicalDeviceProperties2(phys[i], &pdp2);
// These should always be true
static_assert(VK_UUID_SIZE == XRT_UUID_SIZE, "uuid sizes mismatch");
static_assert(ARRAY_SIZE(pdidp.deviceUUID) == XRT_UUID_SIZE, "array size mismatch");
char uuid_str[UUID_STR_SIZE] = {0};
if (log_level <= U_LOGGING_DEBUG) {
snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), pdidp.deviceUUID);
snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), (xrt_uuid_t *)pdidp.deviceUUID);
oxr_log(log, "GPU: #%d, uuid: %s", i, uuid_str);
}
if (memcmp(pdidp.deviceUUID, sys->xsysc->info.client_vk_deviceUUID, XRT_GPU_UUID_SIZE) == 0) {
if (memcmp(pdidp.deviceUUID, sys->xsysc->info.client_vk_deviceUUID.data, XRT_UUID_SIZE) == 0) {
gpu_index = i;
if (log_level <= U_LOGGING_DEBUG) {
oxr_log(log, "Using GPU #%d with uuid %s suggested by runtime", gpu_index, uuid_str);