From e7458f19e1de7d40ff8aa72b6a141f24d33451c6 Mon Sep 17 00:00:00 2001 From: Eduardo Lima Mitev Date: Wed, 13 May 2020 12:57:43 +0200 Subject: [PATCH] freedreno/uuid: Generate meaningful device and driver UUID Device UUID becomes SHA1('freedreno' + gpu_id). Driver UUID becomes SHA1(mesa-version + git-head-sha1). v2: Don't use build_id for driver UUID since it generates different values for vulkan and gl shared objects. (Kristian) Reviewed-by: Kristian H. Kristensen Part-of: --- src/freedreno/common/freedreno_uuid.c | 59 +++++++++++++++++++++++++-- src/freedreno/common/freedreno_uuid.h | 2 +- src/freedreno/common/meson.build | 2 +- src/freedreno/vulkan/tu_device.c | 2 +- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/freedreno/common/freedreno_uuid.c b/src/freedreno/common/freedreno_uuid.c index c84c90db181..b536fd0900c 100644 --- a/src/freedreno/common/freedreno_uuid.c +++ b/src/freedreno/common/freedreno_uuid.c @@ -22,21 +22,72 @@ */ #include "freedreno_uuid.h" + +#include #include #include +#include "git_sha1.h" +#include "util/mesa-sha1.h" + /* (Re)define UUID_SIZE to avoid including vulkan.h (or p_defines.h) here. */ #define UUID_SIZE 16 void fd_get_driver_uuid(void *uuid) { - memset(uuid, 0, UUID_SIZE); - snprintf(uuid, UUID_SIZE, "freedreno"); + const char *driver_id = PACKAGE_VERSION MESA_GIT_SHA1; + + /* The driver UUID is used for determining sharability of images and memory + * between two Vulkan instances in separate processes, but also to + * determining memory objects and sharability between Vulkan and OpenGL + * driver. People who want to share memory need to also check the device + * UUID. + */ + struct mesa_sha1 sha1_ctx; + _mesa_sha1_init(&sha1_ctx); + + _mesa_sha1_update(&sha1_ctx, driver_id, strlen(driver_id)); + + uint8_t sha1[SHA1_DIGEST_LENGTH]; + _mesa_sha1_final(&sha1_ctx, sha1); + + assert(SHA1_DIGEST_LENGTH >= UUID_SIZE); + memcpy(uuid, sha1, UUID_SIZE); } void -fd_get_device_uuid(void *uuid) +fd_get_device_uuid(void *uuid, unsigned gpu_id) { - memset(uuid, 0, UUID_SIZE); + struct mesa_sha1 sha1_ctx; + _mesa_sha1_init(&sha1_ctx); + + /* The device UUID uniquely identifies the given device within the machine. + * Since we never have more than one device, this doesn't need to be a real + * UUID, so we use SHA1("freedreno" + gpu_id). + * + * @TODO: Using the GPU id could be too restrictive on the off-chance that + * someone would like to use this UUID to cache pre-tiled images or something + * of the like, and use them across devices. In the future, we could allow + * that by: + * * Being a bit loose about GPU id and hash only the generation's + * 'major' number (e.g, '6' instead of '630'). + * + * * Include HW specific constants that are relevant for layout resolving, + * like minimum width to enable UBWC, tile_align_w, etc. + * + * This would allow cached device memory to be safely used from HW in + * (slightly) different revisions of the same generation. + */ + + static const char *device_name = "freedreno"; + _mesa_sha1_update(&sha1_ctx, device_name, strlen(device_name)); + + _mesa_sha1_update(&sha1_ctx, &gpu_id, sizeof(gpu_id)); + + uint8_t sha1[SHA1_DIGEST_LENGTH]; + _mesa_sha1_final(&sha1_ctx, sha1); + + assert(SHA1_DIGEST_LENGTH >= UUID_SIZE); + memcpy(uuid, sha1, UUID_SIZE); } diff --git a/src/freedreno/common/freedreno_uuid.h b/src/freedreno/common/freedreno_uuid.h index c4f232117c8..186708caa29 100644 --- a/src/freedreno/common/freedreno_uuid.h +++ b/src/freedreno/common/freedreno_uuid.h @@ -25,6 +25,6 @@ #define __FREEDRENO_UUID_H__ void fd_get_driver_uuid(void *uuid); -void fd_get_device_uuid(void *uuid); +void fd_get_device_uuid(void *uuid, unsigned gpu_id); #endif /* __FREEDRENO_UUID_H__ */ diff --git a/src/freedreno/common/meson.build b/src/freedreno/common/meson.build index 5c83a819120..409fc917798 100644 --- a/src/freedreno/common/meson.build +++ b/src/freedreno/common/meson.build @@ -24,7 +24,7 @@ libfreedreno_common = static_library( 'freedreno_uuid.c', 'freedreno_uuid.h', ], - include_directories : [inc_freedreno], + include_directories : [inc_freedreno, inc_include, inc_src, inc_gallium], c_args : [c_vis_args, no_override_init_args], build_by_default : true, dependencies: [idep_mesautil] diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 6d1a885bebc..0902682783c 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -299,7 +299,7 @@ tu_physical_device_init(struct tu_physical_device *device, "testing use only.\n"); fd_get_driver_uuid(device->driver_uuid); - fd_get_device_uuid(device->device_uuid); + fd_get_device_uuid(device->device_uuid, device->gpu_id); tu_physical_device_get_supported_extensions(device, &device->supported_extensions); -- 2.30.2