From: Andres Rodriguez <andre...@gmail.com>

We need vulkan and gl to produce the same UUIDs. Therefore we should
keep the mechanism to compute these in a common location to guarantee
they are updated in lockstep.

Signed-off-by: Andres Rodriguez <andre...@gmail.com>
Reviewed-by: Marek Olšák <marek.ol...@amd.com>
---
 src/amd/common/ac_gpu_info.c | 27 +++++++++++++++++++++++++++
 src/amd/common/ac_gpu_info.h |  5 +++++
 2 files changed, 32 insertions(+)

diff --git a/src/amd/common/ac_gpu_info.c b/src/amd/common/ac_gpu_info.c
index 929dfd2946..e55d864187 100644
--- a/src/amd/common/ac_gpu_info.c
+++ b/src/amd/common/ac_gpu_info.c
@@ -307,10 +307,37 @@ bool ac_query_gpu_info(int fd, amdgpu_device_handle dev,
 
        info->pte_fragment_size = alignment_info.size_local;
        info->gart_page_size = alignment_info.size_remote;
 
        if (info->chip_class == SI)
                info->gfx_ib_pad_with_type2 = TRUE;
 
        return true;
 }
 
+void ac_compute_driver_uuid(char *uuid, size_t size)
+{
+       char amd_uuid[] = "AMD-MESA-DRV";
+
+       assert(size >= sizeof(amd_uuid));
+
+       memset(uuid, 0, size);
+       strncpy(uuid, amd_uuid, size);
+}
+
+void ac_compute_device_uuid(struct radeon_info *info, char *uuid, size_t size)
+{
+       uint32_t *uint_uuid = (uint32_t*)uuid;
+
+       assert(size >= sizeof(uint32_t)*4);
+
+       /**
+        * Use the device info directly instead of using a sha1. GL/VK UUIDs
+        * are 16 byte vs 20 byte for sha1, and the truncation that would be
+        * required would get rid of part of the little entropy we have.
+        * */
+       memset(uuid, 0, size);
+       uint_uuid[0] = info->pci_domain;
+       uint_uuid[1] = info->pci_bus;
+       uint_uuid[2] = info->pci_dev;
+       uint_uuid[3] = info->pci_func;
+}
diff --git a/src/amd/common/ac_gpu_info.h b/src/amd/common/ac_gpu_info.h
index 20907c2620..06b0c77546 100644
--- a/src/amd/common/ac_gpu_info.h
+++ b/src/amd/common/ac_gpu_info.h
@@ -19,20 +19,21 @@
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  * The above copyright notice and this permission notice (including the
  * next paragraph) shall be included in all copies or substantial portions
  * of the Software.
  */
 
 #ifndef AC_GPU_INFO_H
 #define AC_GPU_INFO_H
 
+#include <stddef.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include "amd_family.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* Prior to C11 the following may trigger a typedef redeclaration warning */
 typedef struct amdgpu_device *amdgpu_device_handle;
@@ -99,15 +100,19 @@ struct radeon_info {
        uint64_t                    max_alignment; /* from addrlib */
        /* Tile modes. */
        uint32_t                    si_tile_mode_array[32];
        uint32_t                    cik_macrotile_mode_array[16];
 };
 
 bool ac_query_gpu_info(int fd, amdgpu_device_handle dev,
                       struct radeon_info *info,
                       struct amdgpu_gpu_info *amdinfo);
 
+void ac_compute_driver_uuid(char *uuid, size_t size);
+
+void ac_compute_device_uuid(struct radeon_info *info, char *uuid, size_t size);
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* AC_GPU_INFO_H */
-- 
2.13.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to