2 * Copyright © 2020 Igalia S.L.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include "freedreno_uuid.h"
31 #include "util/mesa-sha1.h"
33 /* (Re)define UUID_SIZE to avoid including vulkan.h (or p_defines.h) here. */
37 fd_get_driver_uuid(void *uuid
)
39 const char *driver_id
= PACKAGE_VERSION MESA_GIT_SHA1
;
41 /* The driver UUID is used for determining sharability of images and memory
42 * between two Vulkan instances in separate processes, but also to
43 * determining memory objects and sharability between Vulkan and OpenGL
44 * driver. People who want to share memory need to also check the device
47 struct mesa_sha1 sha1_ctx
;
48 _mesa_sha1_init(&sha1_ctx
);
50 _mesa_sha1_update(&sha1_ctx
, driver_id
, strlen(driver_id
));
52 uint8_t sha1
[SHA1_DIGEST_LENGTH
];
53 _mesa_sha1_final(&sha1_ctx
, sha1
);
55 assert(SHA1_DIGEST_LENGTH
>= UUID_SIZE
);
56 memcpy(uuid
, sha1
, UUID_SIZE
);
60 fd_get_device_uuid(void *uuid
, unsigned gpu_id
)
62 struct mesa_sha1 sha1_ctx
;
63 _mesa_sha1_init(&sha1_ctx
);
65 /* The device UUID uniquely identifies the given device within the machine.
66 * Since we never have more than one device, this doesn't need to be a real
67 * UUID, so we use SHA1("freedreno" + gpu_id).
69 * @TODO: Using the GPU id could be too restrictive on the off-chance that
70 * someone would like to use this UUID to cache pre-tiled images or something
71 * of the like, and use them across devices. In the future, we could allow
73 * * Being a bit loose about GPU id and hash only the generation's
74 * 'major' number (e.g, '6' instead of '630').
76 * * Include HW specific constants that are relevant for layout resolving,
77 * like minimum width to enable UBWC, tile_align_w, etc.
79 * This would allow cached device memory to be safely used from HW in
80 * (slightly) different revisions of the same generation.
83 static const char *device_name
= "freedreno";
84 _mesa_sha1_update(&sha1_ctx
, device_name
, strlen(device_name
));
86 _mesa_sha1_update(&sha1_ctx
, &gpu_id
, sizeof(gpu_id
));
88 uint8_t sha1
[SHA1_DIGEST_LENGTH
];
89 _mesa_sha1_final(&sha1_ctx
, sha1
);
91 assert(SHA1_DIGEST_LENGTH
>= UUID_SIZE
);
92 memcpy(uuid
, sha1
, UUID_SIZE
);