Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/freedreno/common/freedreno_uuid.c
4565 views
1
/*
2
* Copyright © 2020 Igalia S.L.
3
*
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:
10
*
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
13
* Software.
14
*
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
21
* SOFTWARE.
22
*/
23
24
#include "freedreno_uuid.h"
25
26
#include <assert.h>
27
#include <stdio.h>
28
#include <string.h>
29
30
#include "util/mesa-sha1.h"
31
#include "git_sha1.h"
32
33
/* (Re)define UUID_SIZE to avoid including vulkan.h (or p_defines.h) here. */
34
#define UUID_SIZE 16
35
36
void
37
fd_get_driver_uuid(void *uuid)
38
{
39
const char *driver_id = PACKAGE_VERSION MESA_GIT_SHA1;
40
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
45
* UUID.
46
*/
47
struct mesa_sha1 sha1_ctx;
48
_mesa_sha1_init(&sha1_ctx);
49
50
_mesa_sha1_update(&sha1_ctx, driver_id, strlen(driver_id));
51
52
uint8_t sha1[SHA1_DIGEST_LENGTH];
53
_mesa_sha1_final(&sha1_ctx, sha1);
54
55
assert(SHA1_DIGEST_LENGTH >= UUID_SIZE);
56
memcpy(uuid, sha1, UUID_SIZE);
57
}
58
59
void
60
fd_get_device_uuid(void *uuid, unsigned gpu_id)
61
{
62
struct mesa_sha1 sha1_ctx;
63
_mesa_sha1_init(&sha1_ctx);
64
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).
68
*
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
72
* that by:
73
* * Being a bit loose about GPU id and hash only the generation's
74
* 'major' number (e.g, '6' instead of '630').
75
*
76
* * Include HW specific constants that are relevant for layout resolving,
77
* like minimum width to enable UBWC, tile_align_w, etc.
78
*
79
* This would allow cached device memory to be safely used from HW in
80
* (slightly) different revisions of the same generation.
81
*/
82
83
static const char *device_name = "freedreno";
84
_mesa_sha1_update(&sha1_ctx, device_name, strlen(device_name));
85
86
_mesa_sha1_update(&sha1_ctx, &gpu_id, sizeof(gpu_id));
87
88
uint8_t sha1[SHA1_DIGEST_LENGTH];
89
_mesa_sha1_final(&sha1_ctx, sha1);
90
91
assert(SHA1_DIGEST_LENGTH >= UUID_SIZE);
92
memcpy(uuid, sha1, UUID_SIZE);
93
}
94
95