Path: blob/21.2-virgl/src/freedreno/common/freedreno_uuid.c
4565 views
/*1* Copyright © 2020 Igalia S.L.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#include "freedreno_uuid.h"2425#include <assert.h>26#include <stdio.h>27#include <string.h>2829#include "util/mesa-sha1.h"30#include "git_sha1.h"3132/* (Re)define UUID_SIZE to avoid including vulkan.h (or p_defines.h) here. */33#define UUID_SIZE 163435void36fd_get_driver_uuid(void *uuid)37{38const char *driver_id = PACKAGE_VERSION MESA_GIT_SHA1;3940/* The driver UUID is used for determining sharability of images and memory41* between two Vulkan instances in separate processes, but also to42* determining memory objects and sharability between Vulkan and OpenGL43* driver. People who want to share memory need to also check the device44* UUID.45*/46struct mesa_sha1 sha1_ctx;47_mesa_sha1_init(&sha1_ctx);4849_mesa_sha1_update(&sha1_ctx, driver_id, strlen(driver_id));5051uint8_t sha1[SHA1_DIGEST_LENGTH];52_mesa_sha1_final(&sha1_ctx, sha1);5354assert(SHA1_DIGEST_LENGTH >= UUID_SIZE);55memcpy(uuid, sha1, UUID_SIZE);56}5758void59fd_get_device_uuid(void *uuid, unsigned gpu_id)60{61struct mesa_sha1 sha1_ctx;62_mesa_sha1_init(&sha1_ctx);6364/* The device UUID uniquely identifies the given device within the machine.65* Since we never have more than one device, this doesn't need to be a real66* UUID, so we use SHA1("freedreno" + gpu_id).67*68* @TODO: Using the GPU id could be too restrictive on the off-chance that69* someone would like to use this UUID to cache pre-tiled images or something70* of the like, and use them across devices. In the future, we could allow71* that by:72* * Being a bit loose about GPU id and hash only the generation's73* 'major' number (e.g, '6' instead of '630').74*75* * Include HW specific constants that are relevant for layout resolving,76* like minimum width to enable UBWC, tile_align_w, etc.77*78* This would allow cached device memory to be safely used from HW in79* (slightly) different revisions of the same generation.80*/8182static const char *device_name = "freedreno";83_mesa_sha1_update(&sha1_ctx, device_name, strlen(device_name));8485_mesa_sha1_update(&sha1_ctx, &gpu_id, sizeof(gpu_id));8687uint8_t sha1[SHA1_DIGEST_LENGTH];88_mesa_sha1_final(&sha1_ctx, sha1);8990assert(SHA1_DIGEST_LENGTH >= UUID_SIZE);91memcpy(uuid, sha1, UUID_SIZE);92}939495