diff --git a/src/panfrost/vulkan/panvk_instance.c b/src/panfrost/vulkan/panvk_instance.c index 8045c0ad65d..c6cb9882509 100644 --- a/src/panfrost/vulkan/panvk_instance.c +++ b/src/panfrost/vulkan/panvk_instance.c @@ -9,6 +9,9 @@ * SPDX-License-Identifier: MIT */ +#include "util/build_id.h" +#include "util/mesa-sha1.h" + #include "vk_alloc.h" #include "vk_log.h" @@ -126,6 +129,19 @@ panvk_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); + const struct build_id_note *note = + build_id_find_nhdr_for_addr(panvk_CreateInstance); + if (!note) { + return vk_errorf(NULL, VK_ERROR_INITIALIZATION_FAILED, + "Failed to find build-id"); + } + + unsigned build_id_len = build_id_length(note); + if (build_id_len < SHA1_DIGEST_LENGTH) { + return vk_errorf(NULL, VK_ERROR_INITIALIZATION_FAILED, + "build-id too short. It needs to be a SHA"); + } + pAllocator = pAllocator ?: vk_default_allocator(); instance = vk_zalloc(pAllocator, sizeof(*instance), 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); @@ -163,6 +179,9 @@ panvk_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); + STATIC_ASSERT(sizeof(instance->driver_build_sha) == SHA1_DIGEST_LENGTH); + memcpy(instance->driver_build_sha, build_id_data(note), SHA1_DIGEST_LENGTH); + *pInstance = panvk_instance_to_handle(instance); return VK_SUCCESS; diff --git a/src/panfrost/vulkan/panvk_instance.h b/src/panfrost/vulkan/panvk_instance.h index 0572c3e7e70..550f6dc0a22 100644 --- a/src/panfrost/vulkan/panvk_instance.h +++ b/src/panfrost/vulkan/panvk_instance.h @@ -30,6 +30,8 @@ struct panvk_instance { enum panvk_debug_flags debug_flags; + uint8_t driver_build_sha[20]; + struct { struct pan_kmod_allocator allocator; } kmod; diff --git a/src/panfrost/vulkan/panvk_physical_device.c b/src/panfrost/vulkan/panvk_physical_device.c index 1e6e3350947..d470e8bddc6 100644 --- a/src/panfrost/vulkan/panvk_physical_device.c +++ b/src/panfrost/vulkan/panvk_physical_device.c @@ -57,19 +57,6 @@ get_cache_uuid(uint16_t family, void *uuid) return 0; } -static void -get_driver_uuid(void *uuid) -{ - memset(uuid, 0, VK_UUID_SIZE); - snprintf(uuid, VK_UUID_SIZE, "panfrost"); -} - -static void -get_device_uuid(void *uuid) -{ - memset(uuid, 0, VK_UUID_SIZE); -} - static void get_device_extensions(const struct panvk_physical_device *device, struct vk_device_extension_table *ext) @@ -231,7 +218,8 @@ get_features(const struct panvk_physical_device *device, } static void -get_device_properties(const struct panvk_physical_device *device, +get_device_properties(const struct panvk_instance *instance, + const struct panvk_physical_device *device, struct vk_properties *properties) { /* HW supports MSAA 4, 8 and 16, but we limit ourselves to MSAA 4 for now. */ @@ -585,8 +573,19 @@ get_device_properties(const struct panvk_physical_device *device, memcpy(properties->pipelineCacheUUID, device->cache_uuid, VK_UUID_SIZE); - memcpy(properties->driverUUID, device->driver_uuid, VK_UUID_SIZE); - memcpy(properties->deviceUUID, device->device_uuid, VK_UUID_SIZE); + const struct { + uint16_t vendor_id; + uint32_t device_id; + uint8_t pad[8]; + } dev_uuid = { + .vendor_id = ARM_VENDOR_ID, + .device_id = device->model->gpu_id, + }; + + STATIC_ASSERT(sizeof(dev_uuid) == VK_UUID_SIZE); + memcpy(properties->deviceUUID, &dev_uuid, VK_UUID_SIZE); + STATIC_ASSERT(sizeof(instance->driver_build_sha) >= VK_UUID_SIZE); + memcpy(properties->driverUUID, instance->driver_build_sha, VK_UUID_SIZE); snprintf(properties->driverName, VK_MAX_DRIVER_NAME_SIZE, "panvk"); snprintf(properties->driverInfo, VK_MAX_DRIVER_INFO_SIZE, @@ -687,9 +686,6 @@ panvk_physical_device_init(struct panvk_physical_device *device, vk_warn_non_conformant_implementation("panvk"); - get_driver_uuid(&device->driver_uuid); - get_device_uuid(&device->device_uuid); - device->drm_syncobj_type = vk_drm_syncobj_get_type(device->kmod.dev->fd); /* We don't support timelines in the uAPI yet and we don't want it getting * suddenly turned on by vk_drm_syncobj_get_type() without us adding panvk @@ -704,7 +700,7 @@ panvk_physical_device_init(struct panvk_physical_device *device, get_features(device, &supported_features); struct vk_properties properties; - get_device_properties(device, &properties); + get_device_properties(instance, device, &properties); struct vk_physical_device_dispatch_table dispatch_table; vk_physical_device_dispatch_table_from_entrypoints( diff --git a/src/panfrost/vulkan/panvk_physical_device.h b/src/panfrost/vulkan/panvk_physical_device.h index f3b6b5429b3..dabcad2111c 100644 --- a/src/panfrost/vulkan/panvk_physical_device.h +++ b/src/panfrost/vulkan/panvk_physical_device.h @@ -37,8 +37,6 @@ struct panvk_physical_device { } formats; char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE]; - uint8_t driver_uuid[VK_UUID_SIZE]; - uint8_t device_uuid[VK_UUID_SIZE]; uint8_t cache_uuid[VK_UUID_SIZE]; struct vk_sync_type drm_syncobj_type;