From 38f68dc104a69dc58889d48f74d67fec5123725b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 4 May 2022 13:31:59 +0100 Subject: [PATCH] xrt: Use xrt_luid_t for deviceLUID --- src/xrt/compositor/main/comp_compositor.c | 2 +- src/xrt/compositor/main/comp_settings.h | 2 +- src/xrt/compositor/util/comp_vulkan.c | 22 +++++++++++++++------- src/xrt/compositor/util/comp_vulkan.h | 2 +- src/xrt/include/xrt/xrt_compositor.h | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index a67c75221..6744244be 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -725,7 +725,7 @@ compositor_init_vulkan(struct comp_compositor *c) 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"); - static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceLUID.data) == XRT_UUID_SIZE, "array size mismatch"); + static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceLUID.data) == XRT_LUID_SIZE, "array size mismatch"); static_assert(ARRAY_SIZE(vk_res.client_gpu_deviceLUID.data) == ARRAY_SIZE(c->settings.client_gpu_deviceLUID.data), "array size mismatch"); // clang-format on diff --git a/src/xrt/compositor/main/comp_settings.h b/src/xrt/compositor/main/comp_settings.h index c49380c10..b8d51eae8 100644 --- a/src/xrt/compositor/main/comp_settings.h +++ b/src/xrt/compositor/main/comp_settings.h @@ -119,7 +119,7 @@ struct comp_settings xrt_uuid_t client_gpu_deviceUUID; //! The Windows LUID for the GPU device suggested for D3D clients, never changes. - xrt_uuid_t client_gpu_deviceLUID; + xrt_luid_t client_gpu_deviceLUID; //! Whether @ref client_d3d_deviceLUID is valid bool client_gpu_deviceLUID_valid; diff --git a/src/xrt/compositor/util/comp_vulkan.c b/src/xrt/compositor/util/comp_vulkan.c index 39584abd4..885001813 100644 --- a/src/xrt/compositor/util/comp_vulkan.c +++ b/src/xrt/compositor/util/comp_vulkan.c @@ -28,6 +28,14 @@ #define UUID_STR_SIZE (XRT_UUID_SIZE * 3 + 1) +static void +snprint_luid(char *str, size_t size, xrt_luid_t *luid) +{ + for (size_t i = 0, offset = 0; i < ARRAY_SIZE(luid->data) && offset < size; i++, offset += 3) { + snprintf(str + offset, size - offset, "%02x ", luid->data[i]); + } +} + static void snprint_uuid(char *str, size_t size, xrt_uuid_t *uuid) { @@ -65,7 +73,7 @@ get_device_uuid(struct vk_bundle *vk, int gpu_index, xrt_uuid_t *uuid) } static bool -get_device_luid(struct vk_bundle *vk, int gpu_index, xrt_uuid_t *uuid) +get_device_luid(struct vk_bundle *vk, int gpu_index, xrt_luid_t *luid) { VkPhysicalDeviceIDProperties pdidp = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, @@ -90,7 +98,7 @@ get_device_luid(struct vk_bundle *vk, int gpu_index, xrt_uuid_t *uuid) if (pdidp.deviceLUIDValid != VK_TRUE) { return false; } - memcpy(uuid->data, pdidp.deviceLUID, ARRAY_SIZE(uuid->data)); + memcpy(luid->data, pdidp.deviceLUID, ARRAY_SIZE(luid->data)); return true; } @@ -124,16 +132,16 @@ 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)) { - char uuid_str[UUID_STR_SIZE] = {0}; - snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), &vk_res->client_gpu_deviceUUID); + char buffer[UUID_STR_SIZE] = {0}; + snprint_uuid(buffer, ARRAY_SIZE(buffer), &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); + VK_DEBUG(vk, "Suggest %d with uuid: %sto clients", vk_res->client_gpu_index, buffer); if (get_device_luid(vk, vk_res->client_gpu_index, &vk_res->client_gpu_deviceLUID)) { vk_res->client_gpu_deviceLUID_valid = true; - snprint_uuid(uuid_str, ARRAY_SIZE(uuid_str), &vk_res->client_gpu_deviceLUID); - VK_DEBUG(vk, " Device LUID: %s", uuid_str); + snprint_luid(buffer, ARRAY_SIZE(buffer), &vk_res->client_gpu_deviceLUID); + VK_DEBUG(vk, "\tDevice LUID: %s", buffer); } } else { VK_ERROR(vk, "Failed to get device %d uuid", vk_res->client_gpu_index); diff --git a/src/xrt/compositor/util/comp_vulkan.h b/src/xrt/compositor/util/comp_vulkan.h index 4e1baa83d..75630eed9 100644 --- a/src/xrt/compositor/util/comp_vulkan.h +++ b/src/xrt/compositor/util/comp_vulkan.h @@ -77,7 +77,7 @@ struct comp_vulkan_results xrt_uuid_t client_gpu_deviceUUID; //! The (Windows) LUID for the GPU device suggested for clients. - xrt_uuid_t client_gpu_deviceLUID; + xrt_luid_t client_gpu_deviceLUID; //! Whether @ref client_gpu_deviceLUID is valid (probably only on Windows) bool client_gpu_deviceLUID_valid; diff --git a/src/xrt/include/xrt/xrt_compositor.h b/src/xrt/include/xrt/xrt_compositor.h index ba055ad2f..597127624 100644 --- a/src/xrt/include/xrt/xrt_compositor.h +++ b/src/xrt/include/xrt/xrt_compositor.h @@ -1758,7 +1758,7 @@ struct xrt_system_compositor_info xrt_uuid_t client_vk_deviceUUID; //! The (Windows) LUID for the GPU device suggested for D3D clients, never changes. - xrt_uuid_t client_d3d_deviceLUID; + xrt_luid_t client_d3d_deviceLUID; //! Whether @ref client_d3d_deviceLUID is valid bool client_d3d_deviceLUID_valid;