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 <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4847>
This commit is contained in:
parent
9623debf48
commit
e7458f19e1
|
@ -22,21 +22,72 @@
|
|||
*/
|
||||
|
||||
#include "freedreno_uuid.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue