From e9a766a8c02710bf206529f74b25f6cfb817b35d Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Wed, 7 Oct 2020 09:44:44 +0300 Subject: [PATCH] intel: split driver/device UUID generators We need Vulkan and GL to produce the same UUIDs. So move the generator from ANV to a common code that can be shared by ANV and Iris driver. v2: fix android build (Tapani) Signed-off-by: Juan A. Suarez Romero Reviewed-by: Eric Engestrom Reviewed-by: Rohan Garg Part-of: --- src/intel/Android.common.mk | 3 +- src/intel/Makefile.sources | 4 +- src/intel/common/gen_uuid.c | 73 +++++++++++++++++++++++++++++++++++ src/intel/common/gen_uuid.h | 48 +++++++++++++++++++++++ src/intel/common/meson.build | 2 + src/intel/vulkan/anv_device.c | 24 ++---------- 6 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 src/intel/common/gen_uuid.c create mode 100644 src/intel/common/gen_uuid.h diff --git a/src/intel/Android.common.mk b/src/intel/Android.common.mk index 79d9f1284a0..0e1118e6571 100644 --- a/src/intel/Android.common.mk +++ b/src/intel/Android.common.mk @@ -36,7 +36,8 @@ LOCAL_C_INCLUDES := \ $(MESA_TOP)/src/gallium/include \ $(MESA_TOP)/src/gallium/auxiliary \ $(MESA_TOP)/src/mapi \ - $(MESA_TOP)/src/mesa + $(MESA_TOP)/src/mesa \ + $(call generated-sources-dir-for,STATIC_LIBRARIES,libmesa_git_sha1,,) LOCAL_SHARED_LIBRARIES := libz liblog diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources index af92595767c..3f7f7cc9aa0 100644 --- a/src/intel/Makefile.sources +++ b/src/intel/Makefile.sources @@ -24,7 +24,9 @@ COMMON_FILES = \ common/gen_l3_config.c \ common/gen_l3_config.h \ common/gen_urb_config.c \ - common/gen_sample_positions.h + common/gen_sample_positions.h \ + common/gen_uuid.c \ + common/gen_uuid.h COMPILER_FILES = \ compiler/brw_cfg.cpp \ diff --git a/src/intel/common/gen_uuid.c b/src/intel/common/gen_uuid.c new file mode 100644 index 00000000000..d429af2d493 --- /dev/null +++ b/src/intel/common/gen_uuid.c @@ -0,0 +1,73 @@ +/* + * Copyright © 2020 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "gen_uuid.h" +#include "util/build_id.h" +#include "util/mesa-sha1.h" + +void +gen_uuid_compute_device_id(uint8_t *uuid, + const struct gen_device_info *devinfo, + const struct isl_device *isldev, + size_t size) +{ + struct mesa_sha1 sha1_ctx; + uint8_t sha1[20]; + + assert(size <= sizeof(sha1)); + + /* 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. However, on the off-chance that someone tries to use this to + * cache pre-tiled images or something of the like, we use the PCI ID and + * some bits of ISL info to ensure that this is safe. + */ + _mesa_sha1_init(&sha1_ctx); + _mesa_sha1_update(&sha1_ctx, &devinfo->chipset_id, + sizeof(devinfo->chipset_id)); + _mesa_sha1_update(&sha1_ctx, &isldev->has_bit6_swizzling, + sizeof(isldev->has_bit6_swizzling)); + _mesa_sha1_final(&sha1_ctx, sha1); + memcpy(uuid, sha1, size); +} + +void +gen_uuid_compute_driver_id(uint8_t *uuid, + const struct gen_device_info *devinfo, + size_t size) +{ + const struct build_id_note *note = + build_id_find_nhdr_for_addr(gen_uuid_compute_driver_id); + assert(note && "Failed to find build-id"); + + unsigned build_id_len = build_id_length(note); + assert(build_id_len >= size && "build-id too short"); + + /* The driver UUID is used for determining sharability of images and memory + * between two Vulkan instances in separate processes, or for + * interoperability between Vulkan and OpenGL. People who want to * share + * memory need to also check the device UUID so all this * needs to be is + * the build-id. + */ + memcpy(uuid, build_id_data(note), size); +} diff --git a/src/intel/common/gen_uuid.h b/src/intel/common/gen_uuid.h new file mode 100644 index 00000000000..577bff107e6 --- /dev/null +++ b/src/intel/common/gen_uuid.h @@ -0,0 +1,48 @@ + /* + * Copyright © 2020 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#ifndef GEN_UUID_H +#define GEN_UUID_H + +#include "dev/gen_device_info.h" +#include "isl/isl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void gen_uuid_compute_device_id(uint8_t *uuid, + const struct gen_device_info *devinfo, + const struct isl_device *isldev, + size_t size); + +void gen_uuid_compute_driver_id(uint8_t *uuid, + const struct gen_device_info *devinfo, + size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* GEN_UUID_H */ diff --git a/src/intel/common/meson.build b/src/intel/common/meson.build index 381759fcb8b..66e09672439 100644 --- a/src/intel/common/meson.build +++ b/src/intel/common/meson.build @@ -37,6 +37,8 @@ files_libintel_common = files( 'gen_l3_config.h', 'gen_urb_config.c', 'gen_sample_positions.h', + 'gen_uuid.c', + 'gen_uuid.h', ) libintel_common = static_library( diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 01f6c4a4f76..8b743a05b8d 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -45,6 +45,7 @@ #include "vk_util.h" #include "common/gen_aux_map.h" #include "common/gen_defines.h" +#include "common/gen_uuid.h" #include "compiler/glsl_types.h" #include "genxml/gen7_pack.h" @@ -253,26 +254,9 @@ anv_physical_device_init_uuids(struct anv_physical_device *device) _mesa_sha1_final(&sha1_ctx, sha1); memcpy(device->pipeline_cache_uuid, sha1, VK_UUID_SIZE); - /* The driver UUID is used for determining sharability of images and memory - * between two Vulkan instances in separate processes. People who want to - * share memory need to also check the device UUID (below) so all this - * needs to be is the build-id. - */ - memcpy(device->driver_uuid, build_id_data(note), VK_UUID_SIZE); - - /* 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. However, on the off-chance that someone tries to use this to - * cache pre-tiled images or something of the like, we use the PCI ID and - * some bits of ISL info to ensure that this is safe. - */ - _mesa_sha1_init(&sha1_ctx); - _mesa_sha1_update(&sha1_ctx, &device->info.chipset_id, - sizeof(device->info.chipset_id)); - _mesa_sha1_update(&sha1_ctx, &device->isl_dev.has_bit6_swizzling, - sizeof(device->isl_dev.has_bit6_swizzling)); - _mesa_sha1_final(&sha1_ctx, sha1); - memcpy(device->device_uuid, sha1, VK_UUID_SIZE); + gen_uuid_compute_driver_id(device->driver_uuid, &device->info, VK_UUID_SIZE); + gen_uuid_compute_device_id(device->device_uuid, &device->info, + &device->isl_dev, VK_UUID_SIZE); return VK_SUCCESS; }